/* * * * * * * * * * * * * * * * *  * * * * * * * * *
*		Created date:5/11/2009					    *
*		Paktolus Group India.						*
*		Author: Sandip Rajput, PHP Programmer  		*
* * * * * * * * * * * * * * * * * * * * * * * * * * */


var HOME_PATH='/';

/*--------------------Common functions used in the entire site#START#BRIJENDRA----------------*/
function isValidEmail(str) {
	if(!(/^[^a-zA-Z]/.test(str)) && (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(str))) {
		return true
	} else {
		return false
	}
 }
/*function to validate email for any form //END*/
/*function to validate & restrict user to enter only numeric values*/
//call function below on key events i.e. onkeypress, onkeyup etc.
function numericValue(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        //alert("Enter only numeric values\nThat is between 0-9\n in this field.");
        return false;
    }
    return true;
}/*END function numericValue(evt)*/
//call function below on key events i.e. onkeypress, onkeyup etc.
function phoneValue(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode!=45) {
        //alert("Enter only numeric values\nThat is between 0-9\n in this field.");
        return false;
    }
    return true;
} /*END function phoneValue(evt)*/

/*//functin to check field value contains valid string characters //STRT*/
//function call ->if(isValidString(document.frmPrudential.clientName.value)==false)
	function isValidString(str){
		var result	=	true;
		var iChars = "`~!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
		//if string is NULL return false;
		if(str.length == 0) return false;
		for (var i = 0; i < str.length; i++) {
			if (iChars.indexOf(str.charAt(i)) != -1) {
				result	=	false;
			}
		}
	 return result;
	}

/*//functin to check field value contains valid string characters// END*/

/** function below is to check if field value is a valid zip code for US // START*/
function isValidZip(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;
   if(strString.length!=5) return false;
	var totalValue	=	0;
   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
	  totalValue	+=	parseInt(strString.charAt(i));
		
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
	
      }
	if(totalValue==0) return false;
   return blnResult;
   }
/** function below is to check if field value is a valid zip code for US//END */
function showHideAnyBox(box_id){ //alert(1)
	var boxDivId	= document.getElementById(box_id);
	if(boxDivId.style.visibility=='visible')
		boxDivId.style.visibility	='hidden';
	else
		boxDivId.style.visibility	='visible';
	//alert(boxDivId.style.visibility);
}


function numericValue(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        //alert("Enter only numeric values\nThat is between 0-9\n in this field.");
        return false;
    }
    return true;
}
function phoneValue(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode!=45) {
        //alert("Enter only numeric values\nThat is between 0-9\n in this field.");
        return false;
    }
    return true;
}

function costValue(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode!=46) {
        //alert("Enter only numeric values\nThat is between 0-9\n in this field.");
        return false;
    }
    return true;
}

function sleepTimeOutDisplay(divId){
	if(eval(document.getElementById(divId))){
	document.getElementById(divId).style.display	=	'none';
	}
	}

function phoneValuetab(evt,val,name) {		
	var total=val.length
	if(name=="phone1"){
    	if(total=="3")
	    {	     	
          document.getElementById('phone2').focus();            
	    }
	}
	if(name=="phone2" ){
    	if(total=="3")
	    {	    
	      document.getElementById('phone3').focus();	 
	    }
	}
	if(name=="phone3"){
    	if(total=="4")
	    {		 
	      document.getElementById('email').focus();		  
	    }
	}	
	
	evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode!=45) {
        //alert("Enter only numeric values\nThat is between 0-9\n in this field.");
        return false;
    }
	return true;

}	


//Insurance page validation.
function insuranceValidation(frm){
	//alert(1)
	//Variabe declaration section....
	var FName 			= frm.fname;
	var LName 			= frm.lname;
	var Email 			= frm.email;
	var address 		= frm.address;
	var city 			= frm.city;
	var Phone  			= frm.phone;
	var state			=frm.state;
	var zip				=frm.zip;
	var country			=frm.country;
	var dob				=frm.dob;
	var sex				=frm.sex;
	var subscriber		=frm.subscriber;
	var groupid			=frm.group_id;
	var relation		=frm.relation;	
	var chief			=frm.chief;
	var co_specialist	=frm.co_specialist;
	var ins_comp_phone	=frm.ins_comp_phone;
	var insurance_type	=frm.insurance_type;	
	var ins_comp_name   =frm.ins_comp_name;
	

    var cntError = 0;
	var errorMsg = Array();	
	var errorField = Array();
	//var showErrorMsg = $("errorDiv");
	//var successMessageDiv =$('successMessageDiv');
	
	if(FName.value==""){
		errorMsg[cntError] = 'fname';
		errorField[cntError] = 'fname';
		$('insurance_fname_label').style.color = "#FF0000"
		cntError++;
	}else{
		$('insurance_fname_label').style.color = "";
	}
	if(LName.value==""){
		errorMsg[cntError] = 'lname';
		errorField[cntError] = 'lname';
		$('insurance_lname_label').style.color = "#FF0000"
		cntError++;
	}else{
		$('insurance_lname_label').style.color = "";
	}
	if(!isValidEmail(Email.value,1,1)){
		errorMsg[cntError] = 'email';
		errorField[cntError] = 'email';
		$('insurance_email_label').style.color = "#FF0000"
		cntError++;
	}else{
	 $('insurance_email_label').style.color = "";
	}
	
	 if(address.value =="" ){
		errorMsg[cntError] = 'address';
		errorField[cntError] = 'address';
		$('insurance_address_label').style.color = "#FF0000"
		cntError++;
	}else{
		$('insurance_address_label').style.color = "";
	}
	if(Phone.value==""){
		errorMsg[cntError] = 'phone';
		errorField[cntError] = 'phone';
		$('insurance_phone_label').style.color = "#FF0000"
		cntError++;
	}else{
		$('insurance_phone_label').style.color = "";
	}
	
	if(sex.value=='Select Sex'){
	errorMsg[cntError] = 'sex';
	errorField[cntError] = 'sex';
	$('insurance_sex_label').style.color = "#FF0000"	
	cntError++;
	}else{
		$('insurance_sex_label').style.color = "";
	}
	
	
	if(state.value=='Select State'){
		errorMsg[cntError] = 'state';
		errorField[cntError] = 'state';
		$('insurance_state_label').style.color = "#FF0000"
		cntError++;
	}else{
		$('insurance_state_label').style.color = "";
	}
	if(country.value=='Select country'){
		errorMsg[cntError] = 'country';
		errorField[cntError] = 'country';
		$('insurance_country_label').style.color = "#FF0000"
		cntError++;
	}else{
		$('insurance_country_label').style.color = "";
	}
	if(city.value==""){
		errorMsg[cntError] = 'city';
		errorField[cntError] = 'city';
		$('insurance_city_label').style.color = "#FF0000"
		cntError++;
	}else{
		$('insurance_city_label').style.color = "";
	}
		
	 if(subscriber.value =="" ){
		errorMsg[cntError] = 'subscriber';
		errorField[cntError] = 'subscriber';
		$('insurance_subid_label').style.color = "#FF0000"
		cntError++;
	}else{
		$('insurance_subid_label').style.color = "";
	}
	
	if(chief.value==""){
		errorMsg[cntError] = 'chief';
		errorField[cntError] = 'chief';
		$('insurance_chifcomp_label').style.color = "#FF0000"
		cntError++;
	}else{
		$('insurance_chifcomp_label').style.color = "";
	}
	
	if(relation.value=='Select relation'){
	errorMsg[cntError] = 'relation';
	errorField[cntError] = 'relation';
	$('insurance_relation_label').style.color = "#FF0000"	
	cntError++;
	}else{
		$('insurance_relation_label').style.color = "";
	}
	
	if(ins_comp_phone.value==""){
		errorMsg[cntError]='ins_comp_phone';
		errorField[cntError]='ins_comp_phone';
		cntError++;
		$('insurance_compPhone_label').style.color="#FF0000"
	}else{
		$('insurance_compPhone_label').style.color="";
	}
	if(zip.value==""){
		errorMsg[cntError]='zip';
		errorField[cntError]='zip';
		cntError++;
		$('insurance_zip_label').style.color="#FF0000"
	}else{
		$('insurance_zip_label').style.color="";
	}
	if(dob.value==""){
		errorMsg[cntError]='dob';
		errorField[cntError]='dob';
		cntError++;
		$('insurance_dob_label').style.color="#FF0000"
	}else{
		$('insurance_dob_label').style.color="";
	}
	if(groupid.value==""){
		errorMsg[cntError]='groupid';
		errorField[cntError]='groupid';
		cntError++;
		$('insurance_groupid_label').style.color="#FF0000"
	}else{
		$('insurance_groupid_label').style.color="";
	}
	
	if(insurance_type.value=='Select Type'){
	errorMsg[cntError] = 'insurance_type';
	errorField[cntError] = 'insurance_type';
	$('insurance_type_label').style.color = "#FF0000"	
	cntError++;
	}else{
		$('insurance_type_label').style.color = "";
	}
	if(ins_comp_name.value==""){
		errorMsg[cntError] = 'ins_comp_name';
		errorField[cntError] = 'ins_comp_name';
		$('insurance_inscompname_label').style.color = "#FF0000"	
		cntError++;
	}else{
		$('insurance_inscompname_label').style.color = "";
	}
	
	
	
	if(errorMsg.length > 0){
				window.scroll(0,500);
		        var Output = "Please fill all mandatory fields.";
        		$("insurance_errorDiv").innerHTML = Output;
				$("insurance_errorDiv").style.display="block";
				
	  return false;
	}else{
		 file	=	HOME_PATH+'process_insurance.php';
		//alert(file);
	 	var myAjax = new Ajax.Request(file, 
                                   {method: 'post', parameters: $(frm).serialize(), 
                                   onComplete: handleResponse});
		$('insurance_errorDiv').style.display	=	'none';
		window.scroll(0,0);
		 var Output = "Thank you for sending insurance information.";
        	$("insurance_succDiv").innerHTML = Output;
			$("insurance_succDiv").style.display="block";
			setTimeout("sleepTimeOutDisplay('insurance_succDiv')",10000);
		frm.reset();
		//return true;
	}
	
 }
//Contact Page validation. 
 function contactValidation(frm){
	//alert(1)
	//Variabe declaration section....
	var School = frm.school;
	var FName = frm.fname;
	var LName = frm.lname;
	var Email = frm.email;
	var Phone1 = frm.phone1;
	var Phone2 = frm.phone2;
	var Phone3 = frm.phone3;

    var cntError = 0;
	var errorMsg = Array();	
	var errorField = Array();
	
	if(FName.value==""){
		errorMsg[cntError] = 'fname';
		errorField[cntError] = 'fname';
		$('contact_fname_label').style.color = "#FF0000"
		cntError++;
	}else{
		$('contact_fname_label').style.color = "";
	}
	if(LName.value==""){
		errorMsg[cntError] = 'lname';
		errorField[cntError] = 'lname';
		$('contact_lname_label').style.color = "#FF0000"
		cntError++;
	}else{
		$('contact_lname_label').style.color = "";
	}
	if(!isValidEmail(Email.value,1,1)){
		errorMsg[cntError] = 'email';
		errorField[cntError] = 'email';
		$('contact_email_label').style.color = "#FF0000"
		cntError++;
	}else{
	 $('contact_email_label').style.color = "";
	}
	if(Phone1.value=="" ||Phone2.value=="" ||Phone3.value==""){
		errorMsg[cntError] = 'phone';
		errorField[cntError] = 'phone';
		$('contact_phone_label').style.color = "#FF0000"
		cntError++;
	}else{
		$('contact_phone_label').style.color = "";
	}
	
	if(errorMsg.length > 0){
		
		        var Output = "Please fill all mandatory fields.";
        		$("contactus_errorDiv").innerHTML = Output;
				$("contactus_errorDiv").style.display="block";
				
	  return false;
	}else{
		 file	=	HOME_PATH+'process_contactus.php';
		//alert(file);
	 	var myAjax = new Ajax.Request(file, 
                                   {method: 'post', parameters: $(frm).serialize(), 
                                   onComplete: handleResponse});
		$('contactus_errorDiv').style.display	=	'none';
		window.scroll(0,0);
		 var Output = "Thank you for contacting. One of our representative will contact you shortly.";
        	$("contactus_succDiv").innerHTML = Output;
			$("contactus_succDiv").style.display="block";
			setTimeout("sleepTimeOutDisplay('contactus_succDiv')",10000);
		frm.reset();
		//return true;
	}
}



function openPassPop(){
	$('popDiv').style.visibility='visible'; 
	}

 function handleResponse(transport){
	//alert(transport.responseText);
	var showDiv	=	$('errorDiv');
	showDiv.style.display='none';
	showDiv.innerHTML = transport.responseText;
	$('resultshere1').style.display	=	'none';
	//alert(transport.responseText);
	}


