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)*/
//call function below on key events i.e. onkeypress, onkeyup etc.
function floatValue(evt) {////46 for DOT(.)
    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;
} /*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 call ->if(isValidString(document.frmPrudential.clientName.value)==false)
	function isValidVinNo(str){
		var result	=	true;
		var iChars = "`~!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
		//if string is NULL 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 to check if field value is valid phone number for US // START*/
function isValidPhone(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;
   if(strString.length<3) 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 to check if field value is valid phone number for US // END*/
function handlePhoneChange(id){
	var id_chunk = id.split('_');
	//alert(id_chunk[1]);
	var textElement	=	document.getElementById(id);
	var newId	=	parseInt(id_chunk[1])+1;
	var newTextId	='phone_'+newId;
	
	if(textElement.value.length==3){
		document.getElementById(newTextId).focus();	
	}
}

// add prospect Validation
function checkAddFutureResidentsForm(frmName){  //               Common Java Script Files   
	var cntError = 0;
	var errorMsg = Array();
	var errorField = Array();
	//var frm = "document."+frmName;
	
	var frm = document.frmMaster;
	//alert(frm);
	if(!isValidString(frm.name.value)){
		errorMsg[cntError] = 'First Name Can Not Be Blank';
		errorField[cntError] = 'name_label';
		document.getElementById('name_label').style.color = "#F00"
		cntError++;
	}
	else{
		document.getElementById('name_label').style.color = "#999";
		
		}
	if(!isValidString(frm.lname.value)){
		errorMsg[cntError] = 'Last Name Can Not Be Blank';
		errorField[cntError] = 'lname';
		document.getElementById('lname_label').style.color = "#F00"
		cntError++;
	}
	else{
		document.getElementById('lname_label').style.color = "#999";
		
		}
	if(!isValidPhone(frm.phone_1.value) || !isValidPhone(frm.phone_2.value) || !isValidPhone(frm.phone_3.value)){
		errorMsg[cntError] = 'Phone No. Can Not Be Blank';
		errorField[cntError] = 'phone';
		document.getElementById('phone_label').style.color = "#F00"
		cntError++;
	}
	else{
		document.getElementById('phone_label').style.color = "#999";
		
		}
if(!isValidEmail(frm.email.value)){
		errorMsg[cntError] = 'Email is not in Proper format';
		errorField[cntError] = 'email';
		document.getElementById('email_label').style.color = "#F00"
		cntError++;
	}
	else{
		document.getElementById('email_label').style.color = "#999";
		
		}
	if(!isValidString(frm.vAddress.value)){
		errorMsg[cntError] = 'vAddress';
		errorField[cntError] = 'vAddress';
		document.getElementById('vAddress_label').style.color = "#F00"
		cntError++;
	}
	else{
		document.getElementById('vAddress_label').style.color = "#999";
		
		}

	if(!isValidString(frm.vCity.value)){
		errorMsg[cntError] = 'vCity';
		errorField[cntError] = 'vCity';
		document.getElementById('vCity_label').style.color = "#F00"
		cntError++;
	}
	else{
		document.getElementById('vCity_label').style.color = "#999";
		
		}
	if(!isValidZip(frm.vZip.value)){
		errorMsg[cntError] = 'Zip Code Can Not Be Empty';
		errorField[cntError] = 'vZip';
		document.getElementById('vZip_label').style.color = "#F00"
		cntError++;
	}
	else{
		document.getElementById('vZip_label').style.color = "#999";
		
		}
if(frm.iCountryId.options[frm.iCountryId.selectedIndex].value == "us"){
		if(frm.iStateId.options[frm.iStateId.selectedIndex].value == "0"){
			errorMsg[cntError] = 'iStateId';
			errorField[cntError] = 'iStateId';
			document.getElementById('iStateId_label').style.color = "#F00"
			cntError++;
		}
		else
		{
			document.getElementById('iStateId_label').style.color = "#999";
			
			}
	}
	else{
		document.getElementById('iStateId_label').style.color = "#999";
	}
	if(frm.iReferredID.options[frm.iReferredID.selectedIndex].value == "0"){
		errorMsg[cntError] = 'Please Select Marketing';
		errorField[cntError] = 'iReferredID';
		document.getElementById('iReferredID_label').style.color = "#F00"
		cntError++;
	}else{
		document.getElementById('iReferredID_label').style.color = "#999";
		
		}
	if(frm.vvc.value==""){
		errorMsg[cntError] = 'Please Enter The Code';
		errorField[cntError] = 'vvc';
		document.getElementById('vvc_label').style.color = "#F00"
		cntError++;
	}
	else
	{
		document.getElementById('vvc_label').style.color = "#999";
		
		}


	// If there are errors, then print them
	if(errorMsg.length > 0){
		//alert(errorMsg.length);
		//alert('Please Fill All The Fields With #F00 Color');
		document.getElementById("errorDiv").style.display='block';
		showErrorMsg = document.getElementById("errorInnerDiv");
		showErrorMsg.style.display='block';
		showErrorMsg.innerHTML = "";
		showErrorMsg.innerHTML = '<ul style="margin-left:20px;padding:0;">';
		showErrorMsg.innerHTML += '<div class="errorList">Please fill all the fields with red color.</div>'
		/*for(i=0;i<errorMsg.length;i++){
			showErrorMsg.innerHTML += '<div class="errorList">Please fill all the fields with #F00 color.</div>';
			showErrorMsg.innerHTML += '<div class="errorList">'+errorMsg[i]+'</div>';
			document.getElementById(errorField[i]).style.color = "#F00";
			document.getElementById(errorField[i]).style.color = "White";
		}*/
		//alert(errorMsg);
		showErrorMsg.innerHTML += '</ul>';		
		return false;
	}else{
		document.getElementById('saveMyData').disabled=true;
		document.getElementById('saveMyData').value='Processing...';
		document.frmMaster.submit();
		//return true;
	}
}


// add prospect Validation
function checkAddBrokerForm(frmName){  //               Common Java Script Files   
	//alert(frmName);exit;
	var cntError = 0;
	var errorMsg = Array();
	var errorField = Array();
	//var frm = "document."+frmName;
	var frm = document.frmadd;
	//alert(frm);
	if(!isValidString(frm.vCompanyName.value)){
		errorMsg[cntError] = 'vCompanyName';
		errorField[cntError] = 'vCompanyName';
		document.getElementById('vCompanyName_label').style.color = "#F00"
		cntError++;
	}
	else
	{
		document.getElementById('vCompanyName_label').style.color = "#999";
		
		}
		
	if(frm.eBorA.options[frm.eBorA.selectedIndex].value == "0"){
		errorMsg[cntError] = 'eBorA';
		errorField[cntError] = 'eBorA';
		document.getElementById('eBorA_label').style.color = "#F00"
		cntError++;
	}else{
		document.getElementById('eBorA_label').style.color = "#999";
		
		}		
	if(!isValidString(frm.name.value)){
		errorMsg[cntError] = 'First Name Can Not Be Blank';
		errorField[cntError] = 'name_label';
		document.getElementById('name_label').style.color = "#F00"
		cntError++;
	}else{
		document.getElementById('name_label').style.color = "#999";
		
		}
	if(!isValidString(frm.lname.value)){
		errorMsg[cntError] = 'Last Name Can Not Be Blank';
		errorField[cntError] = 'lname';
		document.getElementById('lname_label').style.color = "#F00"
		cntError++;
	}else{
		document.getElementById('lname_label').style.color = "#999";
		
		}
	if(!isValidPhone(frm.phone.value)){
		errorMsg[cntError] = 'Phone No. Can Not Be Blank';
		errorField[cntError] = 'phone';
		document.getElementById('phone_label').style.color = "#F00"
		cntError++;
	}else{
		document.getElementById('phone_label').style.color = "#999";
		
		}
	if(!isValidEmail(frm.email.value)){
		errorMsg[cntError] = 'Email is not in Proper format';
		errorField[cntError] = 'email';
		document.getElementById('email_label').style.color = "#F00"
		cntError++;
	}
	else{
		document.getElementById('email_label').style.color = "#999";
		
		}

	if(!isValidString(frm.vLicenseNum.value)){
		errorMsg[cntError] = 'LicenseNum No. Can Not Be Blank';
		errorField[cntError] = 'vLicenseNum';
		document.getElementById('vLicenseNum_label').style.color = "#F00"
		cntError++;
	}else{
		document.getElementById('vLicenseNum_label').style.color = "#999";
		
		}
	if(!isValidString(frm.vAddress.value)){
		errorMsg[cntError] = 'vAddress';
		errorField[cntError] = 'vAddress';
		document.getElementById('vAddress_label').style.color = "#F00"
		cntError++;
	}else{
		document.getElementById('vAddress_label').style.color = "#999";
		
		}

	if(!isValidString(frm.vCity.value)){
		errorMsg[cntError] = 'vCity';
		errorField[cntError] = 'vCity';
		document.getElementById('vCity_label').style.color = "#F00"
		cntError++;
	}else{
		document.getElementById('vCity_label').style.color = "#999";
		
		}
	if(!isValidZip(frm.vZip.value)){
		errorMsg[cntError] = 'Zip Code Can Not Be Empty';
		errorField[cntError] = 'vZip';
		document.getElementById('vZip_label').style.color = "#F00"
		cntError++;
	}	else{
		document.getElementById('vZip_label').style.color = "#999";
		
		}

	if(frm.iCountryId.options[frm.iCountryId.selectedIndex].value == "us")
	{
		if(frm.iStateId.options[frm.iStateId.selectedIndex].value == "0"){
			errorMsg[cntError] = 'iStateId';
			errorField[cntError] = 'iStateId';
			document.getElementById('iStateId_label').style.color = "#F00"
			cntError++;
		}
		
	}
	else{
			document.getElementById('iStateId_label').style.color = "#999";
			
		}
	if(frm.iCountryId.options[frm.iCountryId.selectedIndex].value == "0"){
		errorMsg[cntError] = 'iCountryId';
		errorField[cntError] = 'iCountryId';
		document.getElementById('iCountryId_label').style.color = "#F00"
		cntError++;
	}
	else
	{
		document.getElementById('iCountryId_label').style.color = "#999";
		
		}
	


	if(frm.iReferredID.options[frm.iReferredID.selectedIndex].value == "0"){
		errorMsg[cntError] = 'Please Select Marketing';
		errorField[cntError] = 'iReferredID';
		document.getElementById('iReferredID_label').style.color = "#F00"
		cntError++;
	}
	else
	{
		document.getElementById('iReferredID_label').style.color = "#999";
		
		}

	if(frm.vvc.value==""){
		errorMsg[cntError] = 'Please Enter The Code';
		errorField[cntError] = 'vvc';
		document.getElementById('vvc_label').style.color = "#F00"
		cntError++;
	}else{
		document.getElementById('vvc_label').style.color = "#999";
		
		}



	// If there are errors, then print them
	if(errorMsg.length > 0){
		//alert(errorMsg.length);
		//alert('Please Fill All The Fields With Red Color');
		document.getElementById("errorDiv").style.display='block';
		showErrorMsg = document.getElementById("errorInnerDiv");
		showErrorMsg.style.display='block';
		showErrorMsg.innerHTML = "";
		showErrorMsg.innerHTML += '<div class="errorList">Please fill all the fields with red color.</div>'
		/*for(i=0;i<errorMsg.length;i++){
			//showErrorMsg.innerHTML += '<div class="errorList">'+errorMsg[i]+'</div>';
			//document.getElementById(errorField[i]).style.color = "#F00";
			//document.getElementById(errorField[i]).style.color = "White";
		}*/
		//alert(errorMsg);
		showErrorMsg.innerHTML += '</ul>';		
		return false;
	}else{
		frmName.submit();
		//return true;
	}
}

function checkAddFloorPlanForm(frmName){  //               Common Java Script Files   
	//alert(frmName);exit;
	var cntError = 0;
	var errorMsg = Array();
	var errorField = Array();
	//var frm = "document."+frmName;
	var frm = document.formreg;
	
	if(frm.firstname.value==""){
		
		errorMsg[cntError] = 'First Name Can Not Be Blank';
		errorField[cntError] = 'firstname_label';
		document.getElementById('firstname_label').style.color = "#F00"
		cntError++;
	}
	else
	{
		document.getElementById('firstname_label').style.color = "#999";
		
		}
	if(frm.lastname.value==""){
		errorMsg[cntError] = 'Last Name Can Not Be Blank';
		errorField[cntError] = 'lastname';
		document.getElementById('lastname_label').style.color = "#F00"
		cntError++;
	}
	else
	{
		document.getElementById('lastname_label').style.color = "#999";
		
		}
	if(frm.phone.value==""){
		errorMsg[cntError] = 'Phone No. Can Not Be Blank';
		errorField[cntError] = 'phone';
		document.getElementById('phone_label').style.color = "#F00"
		cntError++;
	}
	else
	{
		document.getElementById('phone_label').style.color = "#999";
		
		}
		
		if(frm.phone.value!="")
		{
			if (IsPhone(frm.phone.value) == false) 
			  {
			  	errorMsg[cntError] = 'Phone No. Can Not Be Blank';
				errorField[cntError] = 'phone';
				document.getElementById('phone_label').style.color = "#F00"
				cntError++;
			  }
			  /*else
				{
					document.getElementById('phone_label').style.color = "#999";
					
					}*/
					
			if (frm.phone.value.length<10) 
			  {
			 	errorMsg[cntError] = 'Phone No. Can Not Be Blank';
				errorField[cntError] = 'phone';
				document.getElementById('phone_label').style.color = "#F00"
				cntError++;
			  }
			 /* else
				{
					document.getElementById('phone_label').style.color = "#999";
					
				}*/
			
		}
	
	
	if(!validateEmail(frm.email.value,1,1)){
		errorMsg[cntError] = 'Email is not in Proper format';
		errorField[cntError] = 'email';
		document.getElementById('email_label').style.color = "#F00"
		cntError++;
	}
	else
	{
		document.getElementById('email_label').style.color = "#999";
		
		}


	if(frm.vAddress.value==""){
		errorMsg[cntError] = 'vAddress';
		errorField[cntError] = 'vAddress';
		document.getElementById('vAddress_label').style.color = "#F00"
		cntError++;
	}
	else
	{
		document.getElementById('vAddress_label').style.color = "#999";
		
		}

	if(frm.vCity.value==""){
		errorMsg[cntError] = 'vCity';
		errorField[cntError] = 'vCity';
		document.getElementById('vCity_label').style.color = "#F00"
		cntError++;
	}
	else
	{
		document.getElementById('vCity_label').style.color = "#999";
		
		}
	if(frm.vZip.value==""){
		errorMsg[cntError] = 'Zip Code Can Not Be Empty';
		errorField[cntError] = 'vZip';
		document.getElementById('vZip_label').style.color = "#F00"
		cntError++;
	}
	else
	{
		document.getElementById('vZip_label').style.color = "#999";
		
		}
	if(frm.vZip.value!="")
			{
				if(isNaN(frm.vZip.value))
				{
					
					errorMsg[cntError] = 'Please Enter Valid Numeric Zipcode';
					errorField[cntError] = 'vZip';
					document.getElementById('vZip_label').style.color = "#F00"
					cntError++;
				}
				
				if(frm.vZip.value.length!=5)
				{   
					errorMsg[cntError] = 'Please Enter Valid 5digit Zipcode';
					errorField[cntError] = 'vZip';
					document.getElementById('vZip_label').style.color = "#F00"
					cntError++;
				}
				
			 }	
	if(frm.iCountryId.options[frm.iCountryId.selectedIndex].value == "us")
	{
		if(frm.iStateId.options[frm.iStateId.selectedIndex].value == "0"){
			errorMsg[cntError] = 'iStateId';
			errorField[cntError] = 'iStateId';
			document.getElementById('iStateId_label').style.color = "#F00"
			cntError++;
		}
		
	}
	else
		{
			document.getElementById('iStateId_label').style.color = "#999";
			
			}
	if(frm.iCountryId.options[frm.iCountryId.selectedIndex].value == "0"){
		errorMsg[cntError] = 'iCountryId';
		errorField[cntError] = 'iCountryId';
		document.getElementById('iCountryId_label').style.color = "#F00"
		cntError++;
	}
	else
	{
		document.getElementById('iCountryId_label').style.color = "#999";
		
		}
		
	if(frm.brokern.options[frm.brokern.selectedIndex].value == "0"){
		errorMsg[cntError] = 'brokern';
		errorField[cntError] = 'brokern';
		document.getElementById('brokern_label').style.color = "#F00"
		cntError++;
	}
	else
	{
		document.getElementById('brokern_label').style.color = "#999";
		
		}
	





	// If there are errors, then print them
	if(errorMsg.length > 0){
		//alert(errorMsg.length);
		alert('Please Fill All The Fields With #F00 Color');
		/*document.getElementById("errorDiv").style.display='block';
		showErrorMsg = document.getElementById("errorInnerDiv");
		showErrorMsg.style.display='block';
		showErrorMsg.innerHTML = "";*/
		//$showErrorMsg.innerHTML = '<ul style="margin-left:20px;padding:0;">';
		/*for(i=0;i<errorMsg.length;i++){
			//showErrorMsg.innerHTML += '<div class="errorList">'+errorMsg[i]+'</div>';
			//document.getElementById(errorField[i]).style.color = "#F00";
			//document.getElementById(errorField[i]).style.color = "White";
		}*/
		//alert(errorMsg);
		//$showErrorMsg.innerHTML += '</ul>';		
		return false;
	}else{
		frmName.submit();
		//return true;
	}
}

