// JavaScript Document

function getxmlhttpobject(handler)
{ 
	var objXmlHttp=null

/*	if (navigator.userAgent.indexOf("Opera")>=0)
	{
		alert("This feature is not compatible with Opera") 
		return 
	}*/
	if (navigator.userAgent.indexOf("MSIE")>=0)
	{ 
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
			strName="Microsoft.XMLHTTP"
		} 
		try
		{ 
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler 
			return objXmlHttp
		} 
		catch(e)
		{ 
			alert("Error. Scripting for ActiveX might be disabled") 
			return 
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0 || navigator.userAgent.indexOf("Opera")>=0)
	{
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler 
		
		return objXmlHttp
	}
}

var xmlhttp;

function validate_career_form ( ) {
	var index = 0;
	var arValidate = new Array;
	arValidate[index++] = new Array("R", "document.frmcareer.fname", "name in general information");
	arValidate[index++] = new Array("R", "document.frmcareer.mname", "name in general information");
	arValidate[index++] = new Array("R", "document.frmcareer.lname", "name in general information");
	arValidate[index++] = new Array("R", "document.frmcareer.street", "street address in general information");
	arValidate[index++] = new Array("R", "document.frmcareer.city", "city in general information");
	arValidate[index++] = new Array("R", "document.frmcareer.state", "state in general information");
	arValidate[index++] = new Array("R", "document.frmcareer.zip", "zip in general information");
	arValidate[index++] = new Array("R", "document.frmcareer.home_phone1", "home phone number in general information");
	arValidate[index++] = new Array("R", "document.frmcareer.home_phone2", "home phone number in general information");
	arValidate[index++] = new Array("R", "document.frmcareer.work_phone1", "work phone in general information");
	arValidate[index++] = new Array("R", "document.frmcareer.work_phone2", "work phone in general information");
	arValidate[index++] = new Array("R", "document.frmcareer.call_time", "best time to call in general information");
	arValidate[index++] = new Array("R", "document.frmcareer.security_code", "security code in applicant certification and agreement");
	//end check for captcha
	if (!Isvalid(arValidate)){
		return false;
	}	
	//check for captcha using ajax
	strurl = 'checkcaptcha.php';
	xmlhttp=getxmlhttpobject(checkcaptcha);
	//Send the proper header information along with the request  
	xmlhttp.open("GET", strurl , false); //Retrive data from specified url
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
	xmlhttp.setRequestHeader("Content-length", 0);  
	xmlhttp.setRequestHeader("Connection", "close");  
	xmlhttp.send(null); //Trigger actual request with null because called with 'GET'	
	if ( document.getElementById('hdnvalid_captcha').value == 0 ) {
		alert('Please enter valid security code.');
		document.getElementById('hdnvalid_captcha').select();
		return false;
	}
	return true;	
}

function checkcaptcha ( ) {
	document.getElementById('hdnvalid_captcha').value = 0;
	if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete"){ 	
		if(xmlhttp.responseText!=""){
			if (xmlhttp.responseText != '' ) {
				if ( document.frmcareer.security_code.value == xmlhttp.responseText ) {
					document.getElementById('hdnvalid_captcha').value = 1;
				}
			}
		}
	}
}

function validate_refer_a_client ( ) {
	var index = 0;
	var arValidate = new Array;
	arValidate[index++] = new Array("R", "document.frm.admin_name", "admin name  ");
	arValidate[index++] = new Array("R", "document.frm.admin_title", "admin title ");
	arValidate[index++] = new Array("R", "document.frm.admin_org_name", "organization");
	arValidate[index++] = new Array("R", "document.frm.admin_phone1", "Phone number");
	arValidate[index++] = new Array("R", "document.frm.admin_phone2", "Phone number");
	arValidate[index++] = new Array("R", "document.frm.admin_fax", "fax");
	arValidate[index++] = new Array("R", "document.frm.admin_email", "email address");
	arValidate[index++] = new Array("R", "document.frm.patient_name", "patient name");
	arValidate[index++] = new Array("R", "document.frm.patient_phone1", "patient number");
	arValidate[index++] = new Array("R", "document.frm.patient_phone2", "patient number");
	arValidate[index++] = new Array("R", "document.frm.patient_email", "patient email");
	arValidate[index++] = new Array("R", "document.frm.patient_address", "patient address");
	arValidate[index++] = new Array("R", "document.frm.patient_detail", "patient detail");
	arValidate[index++] = new Array("R", "document.frm.security_code", "security code in applicant certification and agreement");
	//end check for captcha
	if (!Isvalid(arValidate)){
		return false;
	}	
	
	if ( document.getElementById('security_code').value.split(' ').join('') == '' ) {
		alert('Please enter security code.');
		return false;	
	}
	strurl = 'checkcaptcha.php';
	xmlhttp=getxmlhttpobject(checkcaptcha2);
	//Send the proper header information along with the request  
	xmlhttp.open("GET", strurl , false); //Retrive data from specified url
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
	xmlhttp.setRequestHeader("Content-length", 0);  
	xmlhttp.setRequestHeader("Connection", "close");  
	xmlhttp.send(null); //Trigger actual request with null because called with 'GET'	
	if ( document.getElementById('hdnvalid_captcha').value == 0 ) {
		alert('Please enter valid security code.');
		document.getElementById('hdnvalid_captcha').select();
		return false;
	}
	return true;	
}

function checkcaptcha2 ( ) {
	document.getElementById('hdnvalid_captcha').value = 0;
	if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete"){ 	
		if(xmlhttp.responseText!=""){
			if (xmlhttp.responseText != '' ) {
				if ( document.getElementById('security_code').value == xmlhttp.responseText ) {
					document.getElementById('hdnvalid_captcha').value = 1;
				}
			}
		}
	}
}

