
function submitJobSearch() {
	showStatus(true);
	var formname = 'jobsearchform';
	var formobj = document.getElementById(formname);
		
	// get the locations
	if ( formobj.selected_states.value != '' ) {
		var fname = getLocalValue('JOB_SEARCH_STATES_N');
		var farray = formobj.selected_states.value.split(',');
		for ( var i = 0; i < farray.length; i++ ) {
			var value = farray[i];
			var cname = fname.replace('<x>', (i+1));
			var fobj = getFormElement(formname, cname);
			if ( fobj != null ) {
				fobj.value = value;
			}
		}
	}
	
	// get the job codes
	if ( formobj.selected_jobcodes.value != '' ) {
		var fname = getLocalValue('JOB_SEARCH_JOBCODES_N');
		var farray = formobj.selected_jobcodes.value.split(',');
		for ( var i = 0; i < farray.length; i++ ) {
			var value = farray[i];
			var cname = fname.replace('<x>', (i+1));
			var fobj = getFormElement(formname, cname);
			if ( fobj != null ) {
				fobj.value = value;
			}
		}
	}
	
	// get the job skills
	if ( formobj.selected_skills.value != '' ) {
		var fname = getLocalValue('JOB_SEARCH_SKILLS_N');
		var farray = formobj.selected_skills.value.split(',');
		for ( var i = 0; i < farray.length; i++ ) {
			var value = farray[i];
			var cname = fname.replace('<x>', (i+1));
			var fobj = getFormElement(formname, cname);
			if ( fobj != null ) {
				fobj.value = value;
			}
		}
	}
	
	// submit the form
	formobj.submit();
	
	showStatus(false);
}

function submitJobQuickSearch(){
	showStatus(true);
	var formname = 'quicksearch';
	var formobj = document.getElementById(formname);
	var textfld = getLocalValue('JOB_SEARCH_QUICK')
	var textarea = formobj[textfld].value.trim();
	if( textarea == ""){
		alert(getLocalValue('MSG_QUICKSEARCH_TEXT'))
		showStatus(false);
		return;
	}
	//clean the string
	textarea = unescape(textarea.replace(/\"/gi,"'"));
	textarea = textarea.replace(/\</gi,"");
	textarea = textarea.replace(/\>/gi,"");
    if( !isNaN(textarea) ){
       textarea = textarea +" ";
	}

	formobj[textfld].value = textarea;

	formobj.submit();
}

function submitHCJobSearch() {
	showStatus(true);
	var formname = 'jobsearchform';
	var formobj = document.getElementById(formname);
		
	// get the locations
	if ( formobj.selected_states.value != '' ) {
		var fname = getLocalValue('JOB_SEARCH_STATES_N');
		var farray = formobj.selected_states.value.split(',');
		for ( var i = 0; i < farray.length; i++ ) {
			var value = farray[i];
			var cname = fname.replace('<x>', (i+1));
			var fobj = getFormElement(formname, cname);
			if ( fobj != null ) {
				fobj.value = value;
			}
		}
	}
	
	// get the disciplines
	if ( formobj.selected_disc.value != '' ) {
		var fname = getLocalValue('JOB_SEARCH_DISC_N');
		var farray = formobj.selected_disc.value.split(',');
		for ( var i = 0; i < farray.length; i++ ) {
			var value = farray[i];
			var cname = fname.replace('<x>', (i+1));
			var fobj = getFormElement(formname, cname);
			if ( fobj != null ) {
				fobj.value = value;
			}
		}
	}
	
	// get the specialties
	if ( formobj.selected_spec.value != '' ) {
		var fname = getLocalValue('JOB_SEARCH_SPEC_N');
		var farray = formobj.selected_spec.value.split(',');
		for ( var i = 0; i < farray.length; i++ ) {
			var value = farray[i];
			var cname = fname.replace('<x>', (i+1));
			var fobj = getFormElement(formname, cname);
			if ( fobj != null ) {
				fobj.value = value;
			}
		}
	}
	
	// submit the form
	formobj.submit();
	showStatus(false);
}

function openJobDetails(reference, context, allowapply) {
	showStatus(true);	
	var baseurl = getGlobalValue('SITE_CONTEXT');
	//its from quick search let them link and bookmark the page
	if(context == 'quicksearch'){
		window.location.href = baseurl + '/' + context + '/jobdetails_view.jsp?reference='+reference + '&apply=' + allowapply;	
	}else{
		//They are logged in and might apply for a job by manipulating query strings.
		var fmObj = document.localvars;
			fmObj.method = "post";
			fmObj.action = baseurl + '/' + context + '/jobdetails_view.jsp';
			fmObj.reference.value = reference;
			fmObj.apply.value = allowapply;
			fmObj.submit();	
	}
}

function openHCJobDetails(reference, context, allowapply) {
	showStatus(true);	
	var baseurl = getGlobalValue('SITE_CONTEXT');
	window.location.href = baseurl + '/' + context + '/hc_jobdetails_view.jsp?reference='+reference + '&apply=' + allowapply;		
	/*
	//use this if you want to not use query strings on the site.
	var fmObj = document.localvars;
		fmObj.method = "post";
		fmObj.action = 'hc_jobdetails_view.jsp';
		fmObj.reference.value = reference;
		fmObj.apply.value = allowapply;
		fmObj.submit();	
	*/
}

function applyForJob(reference, context) {
	showStatus(true);
	var fmObj = document.localvars;		
	var baseurl = getGlobalValue('SITE_CONTEXT');
	
	fmObj.method = "post";
	if ( context == 'quicksearch' ){
		fmObj.action = baseurl + '/login/candregistration_view.jsp';
		//they are applying for the job from quicksearch
		fmObj.applyjob.value= reference
	}
	else if(context =='hcquicksearch'){
		fmObj.action = baseurl + '/login/hc_candregistration_view.jsp';
	}
	else {
		// go to the job questions
		fmObj.action = baseurl + '/' + context + '/jobquestion_view.jsp';
	}
	
	fmObj.reference.value = reference;
	fmObj.context.value = context;

	
	showStatus(false);
	
	fmObj.submit();
}

function emailfriend(){
	var formname = 'emailjob';
	var formobj = document.getElementById(formname);
	var baseurl = getGlobalValue('SITE_CONTEXT');
	// validate out going email
	if ( formobj.Friends_Name.value == '' ){
		alert(getLocalValue('MSG_JOB_EMAIL_FRIENDNAME'));
		return;
	}
	if ( formobj.Friends_Email.value == '' ){
		alert(getLocalValue('MSG_JOB_EMAIL_FRIENDEMAIL'));
		return;
	}
	if ( formobj.Your_Name.value == '' ){
		alert(getLocalValue('MSG_JOB_EMAIL_YOURNAME'));
		return;
	}
	if ( formobj.Subject.value == '' ){
		alert(getLocalValue('MSG_JOB_EMAIL_SUBJECT'));
		return;
	}
	formobj.action = baseurl+"/common/emailjob.jsp";
	formobj.submit();
		
}

// functions for find candidate match for client
function loadframe(frameID,divname, reference){
	var frameObj = document.getElementById(frameID).src='matchcandidates.jsp?reference='+reference;
	//open
	document.getElementById(divname).style.display="block";
	//open up the iframe
	parent.document.getElementById(frameID).style.frameBorder ='none';
	parent.document.getElementById(frameID).style.height = '110px';
	parent.document.getElementById(frameID).style.width = '95%';
	showStatus(true);
}

function closeframe(frameID,divname){
	var frameObj = document.getElementById(frameID).src ='';
	//close 
	document.getElementById(divname).style.display="none";
	//close up the iframe
	parent.document.getElementById(frameID).style.height = '0'
	parent.document.getElementById(frameID).style.width = '0'
}