	
/*
Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

		var errZip ="";
		var errEmail="";
		function echeck(id) {
		
		//alert("ronald");
        var str = document.getElementById(id).value;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (lstr == 0 ) return "";
		if (str.indexOf(at)==-1){
		   return "\nInvalid E-mail Address";
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return "\nInvalid E-mail Address";
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   return "\nInvalid E-mail Address";
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   return "\nInvalid E-mail Address";
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   return "\nInvalid E-mail Address";
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   return "\nInvalid E-mail Address";
		 }
		
		 if (str.indexOf(" ")!=-1){
		   return "\nInvalid E-mail Address";
		 }
			return "";
	}
	
	function validateform(c) { //v4.0
		var errors='';
		var strZip ='';
		var strEmail ='';
		var lenZip ='';
		var lenEmail ='';
	  	if (c == "ressignup") {
	  		errors = errors + validateRequired("fldFName","First Name");
	  		errors = errors + validateRequired("fldLName","Last Name");
	  		errors = errors + validateRequired("fldEmail","Email Address");
	  		errors = errors + validateRequired("fldPhone","Phone Number");
	  		errors = errors + validateRequired("fldAddress","Address");
	  		errors = errors + validateRequired("fldCity","City");
	  		errors = errors + validateRequired("fldState","State");
	  		errors = errors + validateRequired("fldZip2","Zip Code");
	  		errors = errors + echeck("fldEmail");
	  		errors = errors + validatePhone("fldPhone","Phone Number");
			
			strZip = document.getElementById("fldZip2").value;
			strEmail = document.getElementById("fldEmail").value;
			
			if (document.getElementById("fldCoupon_SignUp").value != "") {
				document.getElementById("fldCouponTypeValue").value = arrCouponTypes[document.getElementById("fldCouponType_SignUp").value][0];
			}
			
			lenZip = strZip.length;
			lenEmail = strEmail.length;
			
			if (lenZip !=0 && errors == "") {
			    errZip = "";
			    validateZipOnTable(strZip);
				errors = errZip;
				
				if (errZip.indexOf("Our services") >=0) {
					<!--
					window.location = "invalidzip.php?zip=" + document.getElementById('fldZip2').value + "&email=" + document.getElementById('fldEmail').value;
					//-->
				}				
				
			}


			if (lenEmail !=0 && errors == "") {
			    errEmail = "";
				validateEmailOnTable(strEmail);
				errors = errEmail;
			}
			
			if (errors == "") {
			}
	  	}
		
		
	  if (errors != '')  {
	  	alert("Error(s) found \n" +  errors);
		return false;
		}
	  else {
			if (document.getElementById("fldOptAgree").checked) {
				errors = "";
				return true;
			} 
			else {
				alert("You must agree with our terms and conditions to proceed.");
				return false;
			}

	    
	  }
	}
	
	function validateRequired(c,caption) { 
        if (document.getElementById(c).value == "") 
			return "\n " + caption + " is required";
		else
			return "";
	}

	  function transformPhone( obj ) {
		var val = obj.value.replace( /\D/g, '' );
		if ( /^(\d{3})(\d{3})(\d{4})$/.test( val ) ) {
		  obj.value = RegExp.$1 + '-' + RegExp.$2 + '-' + RegExp.$3;
		} else id(val != '') {
		  alert( 'Invalid input: ' + obj.value );
		}
	  }

	  function validatePhone(id,caption) {
	    var obj = document.getElementById(id);
		var val = obj.value.replace( /\D/g, '' );
		if ( /^(\d{3})(\d{3})(\d{4})$/.test( val ) ) {
		  document.getElementById(id).value = RegExp.$1 + '-' + RegExp.$2 + '-' + RegExp.$3;
		  return "";
		} else {
			return "\n " + caption + " has an invalid format.";
		}
	  }
	  
//	function TrimString(sInString) {
//  		sInString = sInString.replace( /^\s+/g, "" );// strip leading
//  		return sInString.replace( /\s+$/g, "" );// strip trailing
//	}

	function validateZipOnTable(id) {
		var xmlhttp;
	
		if (window.XMLHttpRequest){
			  // code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
     			var resp = parseInt(xmlhttp.responseText);
				if (resp == 0) {
					errZip = "Our services will soon be available in your area.";
				}
				else {
					errZip = "";
				}
				
			}
	
		   }
			var param = ""
			param = "valZip.php?zip="  + id ;
			xmlhttp.open("GET",param, false);
			xmlhttp.send();
	}

	function validateEmailOnTable(id) {
		var xmlhttp;
	
		if (window.XMLHttpRequest){
			  // code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
     			var resp = parseInt(xmlhttp.responseText);
				if (resp == 0) {
					errEmail = "The email address that you entered is already used.";
				}
				else {
					errEmail = "";
				}
				
			}
	
		   }
			var param = ""
			param = "valEmail.php?email="  + id ;
			xmlhttp.open("GET",param, false);
			xmlhttp.send();
	}




