// Define Form Object

obj = "document.form1."

function validate(arrFields)
{
	var FieldsArr = arrFields.split(",");
	var arrLen = FieldsArr.length;
	returnStr = "";
	
	for (i=0;i<arrLen;i++)
	{
		indFields = FieldsArr[i].split(":");
		if(eval(obj+indFields[0]+".value")=="")
		{
			returnStr = FieldsArr[i];
			break;
		}
	}
	return returnStr;
}
//Common Validate Function to Check Number Values
function validate_number(arrFields)
{
	var FieldsArr = arrFields.split(",");
	var arrLen = FieldsArr.length;
	returnStr = "";
	
	for (i=0;i<arrLen;i++)
	{
		indFields = FieldsArr[i].split(":");
		if(isNaN(eval(obj+indFields[0]+".value"))!=false)
		{
			returnStr = FieldsArr[i];
			break;
		}
	}
	return returnStr;
}




//function to check email
function chkEmail(strEmail)
{
	if(eval(obj+strEmail+".value").indexOf("@")< 1 || eval(obj+strEmail+".value").indexOf(".")< 1 || 																 eval(obj+strEmail+".value").length < 5)
		return false;
	else
		return true;	
} 

function chksameval(FidNM) {
			
val = eval(obj+FidNM+".value");				  
  thechar1 = val.substr(0,1)		
  thechar2 = val.substr(1,1)
  thechar3 = val.substr(2,1)		             
   if(thechar1 == thechar2)			     
      return false;
else
   return true;				   
  
}

function chksameval2(FidNM) {
			
val = eval(obj+FidNM+".value");				  
  thechar1 = val.substr(0,1)		
  thechar2 = val.substr(1,1)
  thechar3 = val.substr(2,1)		             
   if(thechar1 == thechar2  && thechar2 == thechar3)			     
      return false;
else
   return true;				   
  
}

function validate_addleads(){
  obj = "document.frm1."
  
  var booleanDisplay;
  
  booleanDisplay = document.getElementById("heightWeightDisplay").style.display;

  if (booleanDisplay == 'none')
  {
    arrFlds = "firstname:First Name,lastname:Last Name,address1:Address,zip:Zipcode,email:E-Mail,dayphone1:Phone Number,dayphone2:Phone Number,dayphone3:Phone Number,gender:Gender,mm:Birth Month,dd:Birth Day,yy:Birth Year";
  }
  else
  {
    arrFlds = "firstname:First Name,lastname:Last Name,address1:Address,zip:Zipcode,email:E-Mail,dayphone1:Phone Number,heigthft:Height in Feet,heigthinc:Height in Inches,weigth:Weight,dayphone2:Phone Number,dayphone3:Phone Number,gender:Gender,mm:Birth Month,dd:Birth Day,yy:Birth Year";
  }

errMsg = validate(arrFlds);
		      
  if (errMsg!="") {
	indFields = errMsg.split(":");  
	alert("The " + indFields[1] + " field can not be blank.");
	eval(obj+indFields[0]+".focus()");
	return false;
   }	

//  arrFlds = "firstname:First Name";
//  if(!chksameval("firstname")){
//	   alert("First Name can not be consecutive characters");
//               eval(obj+"firstname.focus()");
//	   return false;
//	 }
//  if(!chksameval("lastname")){
//	   alert("Last Name can not be consecutive characters");
//               eval(obj+"lastname.focus()");
//	   return false;
//	 }

 if (booleanDisplay != 'none')
 {
   if(eval(obj+"weigth.value").length < 2) {
	  alert("Weight entered is too low. Please correct");
	  eval(obj+"weigth.focus()");
	  return false;
	   }

    if(eval(obj+"weigth.value").length > 3) {
	  alert("Weight entered is too high. Please correct.");
	  eval(obj+"weigth.focus()");
	  return false;
	   }
  }

  if(eval(obj+"zip.value").length < 5) {
	  alert("Zipcode should have 5 number values");
	  eval(obj+"zip.focus()");
	  return false;
	}			  
  if(eval(obj+"dayphone1.value").length < 3) {
	alert("Phone entry must have 3 digits.");
	eval(obj+"dayphone1.focus()");
	return false;
	 }

//if(!chksameval2("dayphone1")) {
//	alert("Phone Number given is incorrect. Please correct.");
//	eval(obj+"dayphone1.focus()");
//	return false;
//	}

if(eval(obj+"dayphone2.value").length < 3) {
	alert("Phone entry must have 3 digits.");
	eval(obj+"dayphone2.focus()");
	return false;
	}
		
//if(!chksameval2("dayphone2")) {
//	alert("Phone Number given is incorrect. Please correct.");
//	eval(obj+"dayphone2.focus()");
//	return false;
//	}

if(eval(obj+"dayphone3.value").length < 4) {
	alert("Phone entry must have 4 digits.");
	eval(obj+"dayphone2.focus()");
	return false;
	}		

// if(!chksameval2("dayphone3")) {
//	alert("Phone Number given is incorrect. Please correct.");
//	eval(obj+"dayphone3.focus()");
//	return false;
//
//	}


if (eval(obj+"email.value")!= "" ) {
	if(!chkEmail("email")) {
	    	alert("Invalid E-mail Format! E-mail should be in the following format: somename@hostname.com");
	    	eval(obj+"email.focus()");
	    	eval(obj+"email.select()");
	    	return false;
		}
	}
}


function validate_addleadsDetail(){
obj = "document.frm2."
  arrFlds = "coverageamt:Coverage Amount,coverageterm:Coverage Term";
	errMsg = validate(arrFlds);
	if (errMsg!="")	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	var iscircularchecked = false;
	var iscentralnsyschecked = false;
	var ismentalhealthchecked = false;
	var isrespirorychecked = false;
	var isdigestivechecked = false;
	var isotherchecked = false;
	
	
	for(i=0;i<3;i++) {
		if (eval(obj+"CirculatorySys["+i+"].checked")) {
			iscircularchecked = true;
			break;
		}
	}
	for(i=0;i<4;i++) {
		if (eval(obj+"CentralNSys["+i+"].checked")) {
			iscentralnsyschecked = true;
			break;
		}
	}
	for(i=0;i<3;i++) {
		if (eval(obj+"MentalHealth["+i+"].checked")) {
			ismentalhealthchecked = true;
			break;
		}
	}
	
	for(i=0;i<4;i++) {
		if (eval(obj+"RespiratorySys["+i+"].checked")) {
			isrespirorychecked = true;
			break;
		}
	}
	for(i=0;i<5;i++) {
		if (eval(obj+"DigestiveSys["+i+"].checked")) {
			isdigestivechecked = true;
			break;
		}
	}
	for(i=0;i<6;i++) {
		if (eval(obj+"other["+i+"].checked")) {
			isotherchecked = true;
			break;
		}
	}
	
	
		/*
	
	 if (eval(obj+"treated.checked")) {
	 	if (iscircularchecked || iscentralnsyschecked || ismentalhealthchecked || isrespirorychecked || isdigestivechecked || isotherchecked) {
		 alert("You have selected that you have not been treated for any condition but also selected that you have been treated for a condition. Please correct and click submit!");		       
		       return false;
		}
	 }
	 else {
	 	if (!iscircularchecked && !iscentralnsyschecked && !ismentalhealthchecked && !isrespirorychecked && !isdigestivechecked && !isotherchecked) {
		 alert("Please indicate whether you have or have not been treated for any conditions!");		       
		       return false;
		}
	 
	 }
	*/
	}
	

