<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function check(){
	alert("name is" +document.lForm.un.value)
	alert("pass is" +document.lForm.pw.value)
}
	
function validForm(lForm){
	if(lForm.un.value == "" && lForm.pw.value == ""){
		alert("You must enter a username and a password")
		lForm.un.focus();
		return false;
	}
	if(lForm.un.value == ""){
		alert("You must enter a username")
		lForm.un.focus();
		return false;
	}
	if(lForm.pw.value == ""){
		alert("You must enter a password")
		lForm.pw.focus();
		return false;
	}
	
	return true;
}

function UploadImg(objFrm,option)
{
	if(option==1)
	{
		objFrm.uploadLogo.style.display="inline"; //set to visible
	}
	else
	{
		objFrm.uploadLogo.style.display="none"; //set to hidden
	}
}

function checkNumInsp(val)
{
	var a = document.getElementById("divNumInsp");
	if(val==1)
		a.style.display="inline";
	else
		a.style.display="none";
		
}

function checkRegisterData(objFrm,mode)
{
	/*Basic Package Required Variables*/
	if(mode == 1)
	{
		cname = objFrm.cName.value;
		city = objFrm.city.value;
		zip = objFrm.zip.value;
		fname = objFrm.fName.value;
		lname = objFrm.lName.value;
		state = objFrm.state.selectedIndex;
			
		
	   	
		
		if((cname == "") || (city =="") || (zip =="") || (fname =="") || (lname =="") || (state == ""))
		{
			alert('Please enter all the required fields');
			return false;
		}
		else
		{
			objFrm.submit();
		}
	}
	
	/*Standard Package Required Variables*/
	if(mode == 2)
	{
		cname = objFrm.cName.value;
		city = objFrm.city.value;
		zip = objFrm.zip.value;
		fname = objFrm.fName.value;
		lname = objFrm.lName.value;
		state = objFrm.state.selectedIndex;
		objFrm.filename.value = objFrm.uploadLogo.value
		if (zip.length != 5 && zip != '')
	   	{
	    	alert('Please make sure the zip code you entered is valid.');
	      	return false;
	    }
	    
		if(isNaN(zip) && zip != '') 
	   	{ 
	     	alert("Zip Code is in invalid data format.\n\nOnly numbers are allowed."); 
	     	objFrm.zip.focus(); 
	     	return (false); 
	   	}
	   	
		
		if((cname == "") || (city =="") || (zip =="") || (fname =="") || (lname =="") || (state == ""))
		{
			alert('Please enter all the required fields');
			return false;
		}
		else
		{
			objFrm.submit();
		}
	}
	
	/*Standard Plus Package Required Variables*/
	if(mode == 5)
	{
		cname = objFrm.cName.value;
		city = objFrm.city.value;
		zip = objFrm.zip.value;
		fname = objFrm.fName.value;
		lname = objFrm.lName.value;
		state = objFrm.state.selectedIndex;
		objFrm.filename.value = objFrm.uploadLogo.value
		if (zip.length != 5 && zip != '')
	   	{
	    	alert('Please make sure the zip code you entered is valid.');
	      	return false;
	    }
	    
		if(isNaN(zip) && zip != '') 
	   	{ 
	     	alert("Zip Code is in invalid data format.\n\nOnly numbers are allowed."); 
	     	objFrm.zip.focus(); 
	     	return (false); 
	   	}
	   	
		
		if((cname == "") || (city =="") || (zip =="") || (fname =="") || (lname =="") || (state == ""))
		{
			alert('Please enter all the required fields');
			return false;
		}
		else
		{
			objFrm.submit();
		}
	}
		
	/*Premium Package or Gold Package Required Variables*/
	if(mode == 3 || mode == 4)
	{
		cname = objFrm.cName.value;
		city = objFrm.city.value;
		zip = objFrm.zip.value;
		fname = objFrm.fName.value;
		lname = objFrm.lName.value;
		email = objFrm.email.value;
		pwd = objFrm.pass.value;
		pwd1 = objFrm.pass1.value;
		state = objFrm.state.selectedIndex;
		
		
	   	
		
		if((cname == "") || (city =="") || (zip =="") || (fname =="") || (lname =="") || (state == "") || (email == "") || (pwd == "") || (pwd1 == ""))
		{
			alert('Please enter all the required fields');
			return false;
		}
		
		if (pwd != pwd1)
		{
			alert('The passwords does not match');
			return false;
		}
		
		objFrm.filename.value = objFrm.uploadLogo.value
		
		objFrm.submit();
		
	}
	
}





/* This function is used for the search insepction companies function in _locate.taf */
function verifyLocateSearch(objFrm)
{
	cname = objFrm.tblCompany_companyName.value;
	city = objFrm.tblAddress_city.value;
	//state = document.frmLocInsCom.tblAddress_state[document.frmLocInsCom.tblAddress_state.selectedIndex].value;
	//state = objFrm.tblAddress_state.selectedIndex;
	zip = objFrm.tblAddress_Zip.value;
	
	if (zip.length != 5 && zip != '')
	   	{
	    	alert('Please make sure the zip code you entered is valid.');
	      	return false;
	    }
	    
	if(isNaN(zip) && zip != '') 
	   	{ 
	     	alert("Zip Code is in invalid data format.\n\nOnly numbers are allowed."); 
	     	objFrm.zip.focus(); 
	     	return (false); 
	   	}
	objFrm.submit();   	
	/*if ((cname == "") || (city == "") || (zip == "") || (state ==""))
	{
		alert('Please enter atleast one field to locate inspection companies');
	}
	else
	{
			 objFrm.submit();
	}
	*/
}


function validatePhoneNumber(elementValue){   
var phoneNumberPattern = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;   
return phoneNumberPattern.test(elementValue);   
}  


/* This function is used for the get quote function in inspectiondepot.taf */
function verifySearch(){
	cn = document.frmQuoteSearch.cname.value;	
	ph = document.frmQuoteSearch.phone.value;	
	em = document.frmQuoteSearch.email.value;	
	insp = document.frmQuoteSearch.inspectionTypeID.value;
	sf = document.frmQuoteSearch.sqrFoot.value;
	city = document.frmQuoteSearch.city.value;
	dateString = document.frmQuoteSearch.scheduleDate.value;
	zip = document.frmQuoteSearch.zip.value;

	if ((zip == '' && city != '') || (zip != '' && city == '') || (zip != '' && city != ''))
	{
		
   		if(isNaN(sf)) 
   		{ 
    	 	alert("The Square Feet is in invalid data format.\n\nOnly numbers are allowed."); 
    	 	document.frmQuoteSearch.sqrFoot.focus(); 
    	 	return (false); 
   		}
	
		if(sf < 1) 
	   	{ 
	     	alert("The Square Feet cannot be zero or less."); 
	     	document.frmQuoteSearch.sqrFoot.focus(); 
	     	return (false); 
	   	}
	   	
	   	var phoneNumber = ph.replace(/[\(\)\.\-\ ]/g, ''); 	
	    	if(isNaN(parseInt(phoneNumber))) 
   		{ 
    	 	alert("The Phone is in invalid data format.\n\nOnly numbers are allowed."); 
    	 	document.frmQuoteSearch.phone.focus(); 
    	 	return (false); 
   		}
		if(!validatePhoneNumber(phoneNumber))
		{
		alert("The Phone Number not in valid format. \n"); 
    	 	document.frmQuoteSearch.phone.focus(); 
    	 	return (false); 
		
		}
		
		 if (echeck(em)==false)
		 {				
				document.frmQuoteSearch.email.focus(); 
				return (false); 
			}
			
			   	
	   	if (dateString.length != 10)
	   	{
	    	alert('Inspection Date should be in MM/DD/YYYY format and MM and DD should contain leading zeros');
	      	return false;
	    }
		
		var now = new Date();
	   	var today = new Date(now.getYear(),now.getMonth(),now.getDate());
		var testdate = new Date(dateString.substring(6,10), dateString.substring(0,2)-1, dateString.substring(3,5));
	      
		if(cn=="" || ph=="" || em=="" || insp=="" || sf=="" || testdate < now){
			if (testdate < now)
				alert('Inspection Date should be greater than todays date');
			else
				alert("Please enter all required information");
		}
		else{
			document.frmQuoteSearch.submit();
		}
	}
	else
	{
		alert("Please enter either Zip or City"); 
     	return (false); 
	}
}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}



function verifySearch1(){

	cn = document.frmQuoteSearch.cname.value;	
	ph = document.frmQuoteSearch.phone.value;	
	em = document.frmQuoteSearch.email.value;
	insp = document.frmQuoteSearch.inspectionTypeID.value;
	sf = document.frmQuoteSearch.sqrFoot.value;
	city = document.frmQuoteSearch.city.value;
	dateString = document.frmQuoteSearch.scheduleDate.value;
	zip = document.frmQuoteSearch.zip.value;

	if ((zip == '' && city != '') || (zip != '' && city == '') || (zip != '' && city != ''))
	{
		
   		if(isNaN(sf)) 
   		{ 
    	 	alert("The Square Feet is in invalid data format.\n\nOnly numbers are allowed."); 
    	 	document.frmQuoteSearch.sqrFoot.focus(); 
    	 	return (false); 
   		}
	
		if(sf < 1) 
	   	{ 
	     	alert("The Square Feet cannot be zero or less."); 
	     	document.frmQuoteSearch.sqrFoot.focus(); 
	     	return (false); 
	   	}
	   	
	   	if (zip.length != 5 && zip != '')	
	   	{
	    	alert('Please make sure the zip code you entered is valid.');
	      	return false;
	    }
	    
	    if(isNaN(zip) && zip != '') 
	   	{ 
	     	alert("Zip Code is in invalid data format.\n\nOnly numbers are allowed."); 
	     	document.frmQuoteSearch.zip.focus(); 
	     	return (false); 
	   	}
	   	

		var phoneNumber = ph.replace(/[\(\)\.\-\ ]/g, ''); 	
	    		if(isNaN(parseInt(phoneNumber))) 
   		{ 
    	 	alert("The Phone is in invalid data format.\n\nOnly numbers are allowed."); 
    	 	document.frmQuoteSearch.phone.focus(); 
    	 	return (false); 
   		}
		
		 if (echeck(em)==false)
		 {				
				document.frmQuoteSearch.email.focus(); 
				return (false); 
			}




	   	if (dateString.length != 10)
	   	{
	    	alert('Inspection Date should be in MM/DD/YYYY format and MM and DD should contain leading zeros');
	      	return false;
	    }
		
		var now = new Date();
	   	var today = new Date(now.getYear(),now.getMonth(),now.getDate());
		var testdate = new Date(dateString.substring(6,10), dateString.substring(0,2)-1, dateString.substring(3,5));
	      
		if(cn=="" || ph=="" || em=="" || insp=="" || sf=="" || testdate < now){
			if (testdate < now)
				alert("Inspection Date should be greater than today's date");
			else
				alert("Please enter all required information");
		}
		else{
			document.frmQuoteSearch.submit();
		}
	}
	else
	{
		alert("Please enter either Zip or City"); 
     	return (false); 
	}
}



/* This function is used for _company to validate the CC*/
function isValidCCNum(cardNumber, cardType)
{
  var isValid = false;
  var ccCheckRegExp = /[^\d ]/;
  isValid = !ccCheckRegExp.test(cardNumber);

  if (isValid)
  {
    var cardNumbersOnly = cardNumber.replace(/ /g,"");
    var cardNumberLength = cardNumbersOnly.length;
    var lengthIsValid = false;
    var prefixIsValid = false;
    var prefixRegExp;

    switch(cardType)
    {
       // Mastercard: length 16, prefix 51-55, dashes optional.
      case "mastercard":
        lengthIsValid = (cardNumberLength == 16);
        prefixRegExp = /^5[1-5]/;
        break;
 		// Visa: length 16, prefix 4, dashes optional.
      case "visa":
        lengthIsValid = (cardNumberLength == 16 || cardNumberLength == 13);
        prefixRegExp = /^4/;
        break;
  	// American Express: length 15, prefix 34 or 37.
      case "amex":
        lengthIsValid = (cardNumberLength == 15);
        prefixRegExp = /^3(4|7)/;
        break;
          // Discover: length 16, prefix 6011, dashes optional. 
      case "discover":
        lengthIsValid = (cardNumberLength == 16);
        prefixRegExp = /^6011/;
        break;
      
      default:
        prefixRegExp = /^$/;
        alert("Card type not found");
    }

    prefixIsValid = prefixRegExp.test(cardNumbersOnly);
    isValid = prefixIsValid && lengthIsValid;
  }

  if (isValid)
  {
    var numberProduct;
    var numberProductDigitIndex;
    var checkSumTotal = 0;

    for (digitCounter = cardNumberLength - 1; 
      digitCounter >= 0; 
      digitCounter--)
    {
      checkSumTotal += parseInt (cardNumbersOnly.charAt(digitCounter));
      digitCounter--;
      numberProduct = String((cardNumbersOnly.charAt(digitCounter) * 2));
      for (var productDigitCounter = 0;
        productDigitCounter < numberProduct.length; 
        productDigitCounter++)
      {
        checkSumTotal += 
          parseInt(numberProduct.charAt(productDigitCounter));
      }
    }

    isValid = (checkSumTotal % 10 == 0);
  }

  return isValid;
}

/*This is to verify the CC Form Fields in _company*/
function checkCC(objFrm)
{

	objFrm.ccBtn.disabled = true;
	state = objFrm.cState.selectedIndex;
	ct = objFrm.cardType.value;

	if((isNaN(objFrm.cZip.value)) && (objFrm.cZip.value != '')) 
	{ 
	     	alert("Zip Code in invalid data format.\n\nOnly numbers are allowed."); 
	     	objFrm.ccBtn.disabled = false;
			return (false); 
	}
	
	if ((objFrm.cName.value=="")||
		(objFrm.cAdd1.value=="")||
		(objFrm.cCity.value=="")||
		(state == "")||
		(objFrm.cZip.value=="")||
		(ct == "")||
		(objFrm.CardNumber.value =="")||
		(objFrm.cardExpMonth.value=="")||
		(objFrm.cardExpYear.value=="")||
		(objFrm.cardCVV.value==""))
	{
		
		alert("Please Fill/Select All The Required Fields.")
		objFrm.ccBtn.disabled = false;
		return;
	}
	else
	{
		a = isValidCCNum(objFrm.CardNumber.value,objFrm.cardType.value)
		if (a)
		{
			objFrm.submit();
		}
		else
		{
			alert('credit card you entered is not valid. Please check the credit card number and type and try again')
			objFrm.ccBtn.disabled = false;
			return (false);
		}
	}		


}


function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}



//-->
