function selectAll( checked, name ) {
	var select = document.getElementsByName( name )[0];
	select.disabled = checked;
	var options = select.options;
	for ( var i = 0; i < options.length; i++ ) {
		options[i].selected = checked;
	}
}

function selectLanguage( language, item ) {
	if ( item < 4 ) {
		document.getElementById( "lang" + ( item + 1 )).style.display = "";
	}
	var comment = document.getElementById( "lang_other[" + item + "]" );
	if ( language == "Other" ) {
		comment.style.visibility = "";
		comment.focus();
	} else {
		comment.style.visibility = "hidden";
	}
}

function selectSkill( item ) {
	if ( item < 4 ) {
		document.getElementById( "skill" + ( item + 1 )).style.display = "";
	}
}

function regist_chk( form ) {
/*
	var titles = document.getElementsByName( "title" );
	if ( !titles[0].value ) {
		alert( "Invalid resume title." );
		titles[0].focus();
		return false;
	}
*/
	var categories = document.getElementsByName( "category[]" );
	if ( !categories[0].value ) {
		alert( "Please select at least one Job Function category." );
		categories[0].focus();
		return false;
	}
	if ( form.objective.value == "" ) {
		alert( "Please describe your career objectives." );
		form.objective.focus();
		return false;
	}
/*
	if ( form.yearexperience.value == "" || /\D/.test( form.yearexperience.value )) {
		alert( "Invalid experience value." );
		form.yearexperience.focus();
		return false;
	}
*/
	var regionCount = 0;
	if ( form.allUS.checked ) {
		regionCount++;
	} else {
		var select = document.getElementsByName( "usRegions[]" )[0];
		var options = select.options;
		for ( var i = 0; i < options.length; i++ ) {
			if ( options[i].selected ) regionCount++;
		}
	}
	if ( form.allAsia.checked ) {
		regionCount++;
	} else {
		var select = document.getElementsByName( "asianRegions[]" )[0];
		var options = select.options;
		for ( var i = 0; i < options.length; i++ ) {
			if ( options[i].selected ) regionCount++;
		}
	}
	if ( regionCount > 6 ) {
		alert( "Please select no more than 6 areas in your regional preferences." );
		return false;
	}

	// Read paramaters from upload component sub-form.
	var uploadForms = document.getElementsByName( "dhtmlXVaultForm" );
	for ( i = 0; i < uploadForms.length; i++ ) {
		for ( j = 0; j < uploadForms[i].elements.length; j++ ) {
			form.appendChild( uploadForms[i].elements[j].cloneNode( false ));
		}
	}
	if ( form.hasDoc.value == "0" && !form.elements[ "UploadComponent[SourceFileName][0]"] ) {
		alert( "Please attach a resume document." );
		return false;
	}
	form.submit();
}

function cancelResume( type ) {
	var text = "Click OK to skip the resume submission.  You may add or edit a resume later.";
	if ( type == "skip" ) {
		if ( confirm( text )) {
			location = SYSTEM_URL + "/main/frame.php?page_mode=link&main=attendee&sub=attendee_home";
			return true;
		}
	} else {
		if ( type == "existing" ) {
			text = "Click OK to discard changes made to this resume.";
			if ( !confirm( text )) return false;
		}
		history.back()
	}
}

function removeResume() {
	var form = document.resume_form;
	if ( confirm( "Click OK to permanently remove this resume from your profile." )) {
		form.step.value = "remove";
		form.submit();
	}
}

function deactivateResume() {
	var form = document.resume_form;
	if ( confirm( "Click OK to deactivate this resume.  You can reactivate it again from your profile." )) {
		form.step.value = "deactivate";
		form.submit();
	}
}
/*
function saveResume( memberId, resumeId ) {
	var ajax = new Ajax();
	ajax.post( SYSTEM_URL + "/jobboard/resume/include/update_resumes.php", resumeStateChanged, [
		["type", "save"], 
		["memberId", encodeURI( memberId )], 
		["resumeId", encodeURI( resumeId )]
	] );
}

function saveResumeAtEvent( emsId, memberId, resumeId ) {
    var ajax = new Ajax();
    ajax.post( SYSTEM_URL + "/jobboard/resume/include/update_resumes.php", resumeStateChanged, [
        ["type", "saveSavedAtEvent"], 
        ["emsId", encodeURI( emsId )], 
        ["memberId", encodeURI( memberId )], 
        ["resumeId", encodeURI( resumeId )]
    ] );
}

function resumeStateChanged( message ) {
	alert( message );
}
*/
function removeDoc( sessionId, profileId, resumeId ) {
	if ( confirm( "Click OK to remove the document from your resume." )) {
		var ajax = new Ajax();
        ajax.post( SYSTEM_URL + "/jobboard/resume/edit_job.php", null, [
			["type", "remove_photo"],
			["sessionId", encodeURI( sessionId )],
			["profileId", encodeURI( profileId )],
			["resumeId", encodeURI( resumeId )]
		] );
		tempDocFile = "";
//		document.getElementById( "edit_job_image" ).src = SYSTEM_URL + "/images/profile/no_photo_employer.gif";
		document.getElementById( "remove_resume_doc" ).style.display = "none";
		document.getElementById( "resume_doc_link" ).style.display = "none";
		document.getElementsByName( "remove_doc" )[0].value = "1";
		duc.removeAllItems();
		document.getElementById( "hasDoc" ).value = 0;
	}
}

var tempDocFile = "";
var duc = null;

//var oldFile = null;
function createDocUploadComponent( element ) {

	preLoadImages();
	duc = new dhtmlXVaultObject();
    
	duc.setServerHandlers( FILE_SERVER + "/UploadHandler.php", 
		SYSTEM_URL + "/lib/lib.proxy.php?NBTUS_Path="+encodeURIComponent(FILE_SERVER + '/GetInfoHandler.php'), 
		SYSTEM_URL + "/lib/lib.proxy.php?NBTUS_Path="+encodeURIComponent(FILE_SERVER + '/GetIdHandler.php')
	);
	duc.setSize(350,100);													// content size of file uploading
	duc.setMaxSize(1024*1024);												// maximum file size
	duc.setMaxNumber(1);													// Maximum number of files
	var FileType = new Array("doc","pdf","docx","rtf","txt","odt");			// allowed extentions
	var container = document.getElementById( element );
	duc.setAfterUpload(													// after uploading handler for profile image
		function() { 
        
			container.src = duc.getLastUploadedTempURL(); 
			tempDocFile = duc.getLastUploadedTempFileName();
			document.getElementById( "remove_resume_doc" ).style.display = "";
			document.getElementById( "upload_resume_doc" ).style.display = "none";
		}
	);
	duc.setAfterClean(				 									// after cleaning handler
		function() { 
//			if ( oldFile ) container.src = oldFile; 
			tempDocFile = "";
		} 
	);
	duc.setImagePath( SYSTEM_URL + "/extension/dhtmlxVault/imgs/" );		// image path
	duc.setFileType(FileType);
	duc.create( "upload_resume_doc", "UploadComponent" );								// set Div object to put uploading form, set Variable name
}

function preLoadImages(){
	var imSrcAr = new Array("btn_add.gif","btn_clean.gif","btn_upload.gif","ico_file.png","ico_image.png","ico_sound.png","ico_video.png","ico_zip.png","pb_back.gif","pb_demoUload.gif","pb_empty.gif");
	var imAr = new Array(0);
	for(var i=0;i<imSrcAr.length;i++){
		imAr[imAr.length] = new Image();
		imAr[imAr.length-1].src = SYSTEM_URL + "/extension/dhtmlxVault/imgs/"+imSrcAr[i];
	}
} 

function addResumeEducation( educationId ) {
	document.add_education.educationId.value = "";
	document.add_education.school_name.value = "";
	document.add_education.major.value = "";
	document.add_education.degree.value = "";
	document.add_education.school_country.value = "US";
	document.add_education.school_desc.value = "";
	document.add_education.school_city.value = "";
	now = new Date();
	document.add_education.sch_e_month.value = now.getMonth() + 1;
	document.add_education.sch_e_year.value = now.getFullYear();
	document.add_education.sch_e_month.style.visibility = "visible";
	document.add_education.sch_e_year.style.visibility = "visible";
	document.add_education.current_school.checked = false;
	document.add_education.school_state.value = "";
	document.getElementById( "edit_sch_state" ).style.display = "";
	document.getElementById( "edit_sch_province" ).style.display = "none";
	document.getElementById( "edit_sch_region" ).style.display = "none";
	add_education_layer.ShowLayer();
}

function addResumeExperience( experienceId ) {
	document.add_experience.experienceId.value = "";
	document.add_experience.company_name.value = "";
	document.add_experience.industry.value = "";
	document.add_experience.position.value = "";
	document.add_experience.company_country.value = "US";
	document.add_experience.company_desc.value = "";
	document.add_experience.company_city.value = "";
	now = new Date();
	document.add_experience.com_s_month.value = now.getMonth() + 1;
	document.add_experience.com_s_year.value = now.getFullYear();
	document.add_experience.com_s_month.style.visibility = "visible";
	document.add_experience.com_s_year.style.visibility = "visible";
	document.add_experience.com_e_month.value = now.getMonth() + 1;
	document.add_experience.com_e_year.value = now.getFullYear();
	document.add_experience.com_e_month.style.visibility = "visible";
	document.add_experience.com_e_year.style.visibility = "visible";
	document.add_experience.current_employer.checked = false;
	document.add_experience.company_state.value = "";
	document.getElementById( "edit_cmp_state" ).style.display = "";
	document.getElementById( "edit_cmp_province" ).style.display = "none";
	document.getElementById( "edit_cmp_region" ).style.display = "none";
	add_experience_layer.ShowLayer();
}

function updateResumeEducation( profileId, sessionId, educationId ) {
	document.add_education.educationId.value = educationId;
	document.add_education.school_name.value = document.getElementById( "schoolName_" + educationId ).value;
	document.add_education.major.value = document.getElementById( "major_" + educationId ).value;
	document.add_education.degree.value = document.getElementById( "degree_" + educationId ).value;
	document.add_education.school_country.value = document.getElementById( "schoolCountryCode_" + educationId ).value;
	document.add_education.school_desc.value = document.getElementById( "schoolDesc_" + educationId ).value;
	document.add_education.school_city.value = document.getElementById( "schoolCity_" + educationId ).value;
	if ( document.getElementById( "schoolYear_" + educationId ) ) {
		document.add_education.sch_e_month.value = document.getElementById( "schoolMonth_" + educationId ).value;
		document.add_education.sch_e_year.value = document.getElementById( "schoolYear_" + educationId ).value;
		document.add_education.sch_e_month.style.visibility = "visible";
		document.add_education.sch_e_year.style.visibility = "visible";
		document.add_education.current_school.checked = false;
	} else {
		document.add_education.sch_e_month.style.visibility = "hidden";
		document.add_education.sch_e_year.style.visibility = "hidden";
		document.add_education.current_school.checked = true;
	}
	if ( document.add_education.school_country.value == "US" ) {
		document.add_education.school_state.value = document.getElementById( "schoolRegion_" + educationId ).value;
		document.getElementById( "edit_sch_state" ).style.display = "";
		document.getElementById( "edit_sch_province" ).style.display = "none";
		document.getElementById( "edit_sch_region" ).style.display = "none";
	} else if ( document.add_education.school_country.value == "CA" ) {
		document.add_education.school_province.value = document.getElementById( "schoolRegion_" + educationId ).value;
		document.getElementById( "edit_sch_state" ).style.display = "none";
		document.getElementById( "edit_sch_province" ).style.display = "";
		document.getElementById( "edit_sch_region" ).style.display = "none";
	} else {
		document.add_education.school_region.value = document.getElementById( "schoolRegion_" + educationId ).value;
		document.getElementById( "edit_sch_state" ).style.display = "none";
		document.getElementById( "edit_sch_province" ).style.display = "none";
		document.getElementById( "edit_sch_region" ).style.display = "";
	}
	add_education_layer.ShowLayer();
}

function updateResumeExperience( profileId, sessionId, experienceId ) 
{
	document.add_experience.experienceId.value = experienceId;
	document.add_experience.company_name.value = document.getElementById( "companyName_" + experienceId ).value;
	document.add_experience.industry.value = document.getElementById( "industry_" + experienceId ).value;
	document.add_experience.position.value = document.getElementById( "position_" + experienceId ).value;
	document.add_experience.company_country.value = document.getElementById( "companyCountryCode_" + experienceId ).value;
	document.add_experience.company_desc.value = document.getElementById( "companyDesc_" + experienceId ).value;
	document.add_experience.company_city.value = document.getElementById( "companyCity_" + experienceId ).value;
    
    
	document.add_experience.com_s_month.value = document.getElementById( "companyStartMonth_" + experienceId ).value;
	document.add_experience.com_s_year.value = document.getElementById( "companyStartYear_" + experienceId ).value;
	
    if ( document.getElementById( "companyEndYear_" + experienceId ) ) 
    {
		document.add_experience.com_e_month.value = document.getElementById( "companyEndMonth_" + experienceId ).value;
		document.add_experience.com_e_year.value = document.getElementById( "companyEndYear_" + experienceId ).value;
		document.add_experience.com_e_month.style.visibility = "visible";
		document.add_experience.com_e_year.style.visibility = "visible";
		document.add_experience.current_employer.checked = false;
	} 
    else 
    {
		document.add_experience.com_e_month.style.visibility = "hidden";
		document.add_experience.com_e_year.style.visibility = "hidden";
		document.add_experience.current_employer.checked = true;
	}
	
    
    if ( document.add_experience.company_country.value == "US" ) {
		document.add_experience.company_state.value = document.getElementById( "companyRegion_" + experienceId ).value;
		document.getElementById( "edit_cmp_state" ).style.display = "";
		document.getElementById( "edit_cmp_province" ).style.display = "none";
		document.getElementById( "edit_cmp_region" ).style.display = "none";
	} else if ( document.add_experience.company_country.value == "CA" ) {
		document.add_experience.company_province.value = document.getElementById( "companyRegion_" + experienceId ).value;
		document.getElementById( "edit_cmp_state" ).style.display = "none";
		document.getElementById( "edit_cmp_province" ).style.display = "";
		document.getElementById( "edit_cmp_region" ).style.display = "none";
	} else {
		document.add_experience.company_region.value = document.getElementById( "companyRegion_" + experienceId ).value;
		document.getElementById( "edit_cmp_state" ).style.display = "none";
		document.getElementById( "edit_cmp_province" ).style.display = "none";
		document.getElementById( "edit_cmp_region" ).style.display = "";
	}
	add_experience_layer.ShowLayer();
}

