

function selectDirectHire()
{
	getObj("salary_payrate").innerHTML = 'Estimated Salary Range';
	getObj("bill_rate_req").style.display = 'none';
	getObj("location_req").style.display = 'none';
	getObj("duration_req").style.display = 'none';
	getObj("placement_fee_req").style.display = ''; 
	getObj("guarantee_terms_req").style.display = '';
	getObj("payment_terms_req").style.display = '';
	getObj("bill_rate_row").style.display = 'none';
	
}

function selectContract()
{
	getObj("salary_payrate").innerHTML = 'Estimated Pay Rate Range';
	getObj("bill_rate_req").style.display = '';
	getObj("location_req").style.display = '';
	getObj("duration_req").style.display = '';
	getObj("placement_fee_req").style.display = 'none';
	getObj("guarantee_terms_req").style.display = 'none'; 
	getObj("payment_terms_req").style.display = 'none';
	getObj("bill_rate_row").style.display = '';
}

function selectJobType( val )
{
	if( val == 192 || val == 194 )
		return selectContract();
	else
		return selectDirectHire();
}


function checkJobPostSubmit( jobTypeID )
{

	alertTXT = '';
	
	if( jobTypeID == 192 || jobTypeID == 194 )
		isContractType = true;
	else
		isContractType = false;
	
	
	if( getObj("contact_email").value.length == 0 )
	{
		//getObj("contact_email").style.borderColor = '#ff0000';
		alertTXT += "Contact email must be provided<br>";
	}
	
	if( getObj("job_title").value.length == 0 )
	{
		//getObj("job_title").style.borderColor = '#ff0000';
		alertTXT += "A job title must be provided<br>";
	}

	if( getObj("job_category1").options[getObj("job_category1").selectedIndex].value == "" )
	{
		alertTXT += "You must select a primary job category<br>";	
		//getObj("job_category1").style.borderColor = '#ff0000';
	}
	
	if( getObj("job_duration").value.length == 0 && isContractType )
	{
		//getObj("job_duration").style.borderColor = '#ff0000';
		alertTXT += "The job duration must be provided<br>";
	}
	
	if( getObj("job_duration_unit").selectedIndex == 0 && isContractType )
	{
		//getObj("job_duration_unit").style.borderColor = '#ff0000';
		alertTXT += "The job duration unit must be provided<br>";
	}
		
	if( getObj("salary_low").value.length == 0 || getObj("salary_high").value.length == 0 )
	{
		if( isContractType )
			alertTXT += "You must provide both the low and high pay rate<br>";
		else
			alertTXT += "You must provide both the low and high salary rate<br>";
			
		//getObj("salary_low").style.borderColor = '#ff0000';
		//getObj("salary_high").style.borderColor = '#ff0000';
	}
	
	if( (getObj("bill_rate").value.length == 0 || getObj("bill_rate_high").value.length == 0 ) &&
			isContractType )
	{
		alertTXT += "You must provide both the low and high bill rate<br>";
		//getObj("bill_rate").style.borderColor = '#ff0000';
		//getObj("bill_rate_high").style.borderColor = '#ff0000';
	}
	
	if( !isContractType && getObj("placement_fee").value.length == 0 )
	{
		alertTXT += "You must provide a placement fee<br>";
		//getObj("placement_fee").style.borderColor = '#ff0000';	
	}
	
	if( !isContractType && getObj("guarantee_terms").value.length == 0 )
	{
		alertTXT += "You must provide the guarantee terms<br>";	
		//getObj("guarantee_terms").style.borderColor = '#ff0000';
	}
	else if( !isContractType && getObj("guarantee_terms").value.length > 150 )
	{
		alertTXT += "The guarantee terms cannot be longer than 150 characters<br>";	
		//getObj("guarantee_terms").style.borderColor = '#ff0000';
	}

	if( !isContractType && getObj("payment_terms").value.length == 0 )
	{
		alertTXT += "You must provide the payment terms<br>";	
		//getObj("payment_terms").style.borderColor = '#ff0000';
	}
	else if( !isContractType && getObj("payment_terms").value.length > 150 )
	{
		alertTXT += "The payment terms cannot be longer than 150 characters<br>";	
		//getObj("payment_terms").style.borderColor = '#ff0000';
	}
	
	if( getObj("job_description").value.trim().length == 0 )
	{
		alertTXT += "You must provide a job description<br>";
		//getObj("description").style.borderColor = '#ff0000';
	}
	
	if( isContractType && getObj("job_city").value.length == 0 ) 
	{
		alertTXT += "You must provide the city for the job<br>";	
		//getObj("job_city").style.borderColor = '#ff0000';
	}
	
	if( isContractType && getObj("job_state").value.length == 0 ) 
	{
		alertTXT += "You must provide the state for the job<br>";	
		//getObj("job_state").style.borderColor = '#ff0000';
	}
	
	if( isContractType && getObj("job_postal_code").value.length == 0 ) 
	{
		alertTXT += "You must provide the postal code for the job<br>";	
		//getObj("job_postal_code").style.borderColor = '#ff0000';
	}
	

	if( alertTXT.length > 0 )
	{
		getObj("errorMsgs").innerHTML = "The following errors must be corrected to save this job:<br><br>" +
				alertTXT;
		
		return false;	
	}
	
	return true;
	
}

function update_openJobs()
{
	AjaxRequest.post(
		{
			'url':'/exchange/background.html',
			'parameters':{ 'update_openjobs':'true' },
			'onError': function(oResponse)
				{
					alert(oResponse.responseText);
				},
			'onSuccess': function (oResponse)
			 	{
					getObj("update_jobs_div").innerHTML = "<img src='images/buttons/jobs_refreshed.gif'>";
				}
		}
	);
}

function toggleJobStatus( jobID, jobPosNum )
{
	oldString = getObj("openCloseJob"+jobPosNum).innerHTML;
	
	if( getObj("jobStatus"+jobPosNum).value == 'O' )
	{
		newVal = 'C';
		newString = 'Open Job';
		
		if( !confirm("Are you sure you want to close this job?") )
			return false;
	}
	else if( getObj("jobStatus"+jobPosNum).value == 'C' )
	{
		newVal = 'O';
		newString = 'Close Job';
		
		if( !confirm("Are you sure you want to open this job?") )
			return false;
	}
	else
	{
		alert('unknown job status');
		return false;
	}
		
	getObj("openCloseJobLink"+jobPosNum).style.display = 'none';
	
	AjaxRequest.post(	
		{
			'url':'/exchange/background.html',
			'parameters':{ 'jobID':jobID, 'updateJobStatus':newVal },
			'onSuccess': function(oResponse)
						 {
						 	getObj("jobStatus"+jobPosNum).value = newVal;
						 	getObj("openCloseJob"+jobPosNum).innerHTML = newString;
						 	getObj("openCloseJobLink"+jobPosNum).style.display = '';
						 	
						 	if( newVal == 'O' )
						 		getObj("closedJobMsg"+jobPosNum).style.display = 'none';
						 	else
						 		getObj("closedJobMsg"+jobPosNum).style.display = '';
						 },
			'onError': function(oResponse)
						 {
						 	alert(oResponse.responseText);
						 	getObj("openCloseJobLink"+jobPosNum).style.display = '';
						 	getObj("openCloseJob"+jobPosNum).innerHTML = oldString;
						 }
		} 
	);
		
}	

function showAdditionalCandidates( jobCtr, addCands )
{
	addCandObj = getObj("additionalCandidates["+jobCtr+"]");
	addCandObjLink = getObj("additionalCandidatesLink["+jobCtr+"]");	

	if( addCandObj.style.display == "" )
	{
		addCandObj.style.display = "none";
		addCandObjLink.innerHTML = 'Show all candidates';
	}
	else
	{
		addCandObj.style.display = "";
		addCandObjLink.innerHTML = 'Hide additional candidates';
	}

}

function hideCandFromList( exCand, candNum )
{

	AjaxRequest.post(	
		{
			'url':'/exchange/background.html',
			'parameters':{ 'hideCandSub':exCand },
			'onSuccess': function(oResponse)
						 {
						 	alert('This candidate will no longer be displayed for this job');
							getObj('submittedCand' + candNum ).style.display = 'none';
						 },
			'onError': function(oResponse)
						 {
						 	alert(oResponse.responseText);

						 }
		} 
	);

}

function addToPreferredPartners( ex_vendor_id, jobPosNum )
{
	if(!ex_vendor_id)
	{
		alert("Unable to add as recruiting partner - No Vendor ID");
		return false;
	}
		
	AjaxRequest.post(	
		{
			'url':'/exchange/background.html',
			'parameters':{ 'ex_vendor_id':ex_vendor_id, 'add_recruiting_partner':true },
			'onSuccess': function(oResponse)
					 {
						tt_Hide();
						
					 	getObj("recruiting_partner"+jobPosNum).innerHTML = "<IMG SRC='/exchange/images/buttons/is_a_preferred_partner_sm.gif' BORDER=0  VSPACE=5 HSPACE=2>";
					 },
			'onError': function(oResponse)
					 {
					 	alert("Unable to add as recruiting partners - " + oResponse);
					 }
		} 
	);
}

function addToJobsWorking( ex_job_id, jobPosNum )
{
	if(!ex_job_id)
	{
		alert("Unable to add to jobs working - No ex client job ID");
		return false;
	}

	AjaxRequest.post(	
		{
			'url':'/exchange/background.html',
			'parameters':{ 'ex_job_id':ex_job_id, 'addto_jobs_working':true },
			'onSuccess': function(oResponse)
					 {
						tt_Hide();
					 	getObj("jobs_working"+jobPosNum).innerHTML = "<IMG SRC='/exchange/images/buttons/working_on_this_job.gif' BORDER=0 VSPACE=5 HSPACE=2>";
					 },
			'onError': function(oResponse)
					 {
					 	alert("Unable to add to jobs working");
					 }
		} 
	);
}

function delFromJobsWorking( ex_job_id, job_id )
{
	if(!ex_job_id)
	{
		alert("Unable to add to jobs working - No ex client job ID");
		return false;
	}

	AjaxRequest.post(	
		{
			'url':'/exchange/background.html',
			'parameters':{ 'ex_job_id':ex_job_id, 'del_from_jobs_working':true },
			'onSuccess': function(oResponse)
					 {
					 	if(job_id)
					 	{
					 		getObj('job_header_'+job_id).style.display="none";
					 		getObj('job_member_type_'+job_id).style.display="none";
					 		getObj('job_body_'+job_id).style.display="none";
					 		getObj('job_footer_'+job_id).style.display="none";
					 		getObj('job_footer_spacer_'+job_id).style.display="none";
					 	}
					 	else
					 		window.location.href = window.location.href;
					 },
			'onError': function(oResponse)
					 {
					 	alert("Unable to remove from jobs working");
					 }
		} 
	);
}
