
	var tempnumber = 0;
	function IsNumeric(strString)
	   {
		   var strValidChars = "0123456789";
		   var strChar;
		   var blnResult = true;
		
		   if (strString.length == 0) return false;
		
		   for (i = 0; i < strString.length && blnResult == true; i++)
			  {
			  strChar = strString.charAt(i);
			  if (strValidChars.indexOf(strChar) == -1)
				 {
				 blnResult = false;
				 }
			  }
		   return blnResult;
	   }
	function isValidString(strString)
	   {
		   var strValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.,-#0123456789 ";
		   var strChar;
		   var blnResult = true;
		
		   if (strString.length == 0) return false;
		
		   for (i = 0; i < strString.length && blnResult == true; i++)
			  {
			  strChar = strString.charAt(i);
			  if (strValidChars.indexOf(strChar) == -1)
				 {
				 blnResult = false;
				 }
			  }
		   return blnResult;
	   }
	
var dtCh= "/";
var minYear=2009;
var maxYear=2100;

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function isValidState(st) {
	var statelist = "wa|or|ca|ak|nv|id|ut|az|hi|mt|wy|" +
				"co|nm|nd|sd|ne|ks|ok|tx|mn|ia|mo|" +
				"ar|la|wi|il|ms|mi|in|ky|tn|al|fl|" +
				"ga|sc|nc|oh|wv|va|pa|ny|vt|me|nh|" +
				"ma|ri|ct|nj|de|md|dc|";
	if (statelist.indexOf(st.toLowerCase() + "|") > -1) {
		return true;
		}
	
	return false;

}

	function adjust_cnt(s,c){
		if ( s.checked ) {
			document.getElementById(c).value = "1";
			document.getElementById('piececount').value = 0 + parseInt(document.getElementById('piececount').value) + 1;
		} else {
			if ( document.getElementById(c).value != '0') {
				document.getElementById('piececount').value = 0 + parseInt(document.getElementById('piececount').value) - parseInt(document.getElementById(c).value);
				document.getElementById(c).value = "0";
			}
		}
	}
	function adjust_sel(s,c){
				s.style.backgroundColor='#ffffff';
		if ( s.value == "0" || s.value ==  0 ) {
			document.getElementById(c).checked = false;
		} else {
			if ( IsNumeric(s.value) && s.value != "" ) {
				if ( !document.getElementById(c).checked )
				document.getElementById(c).checked = true;
			} else {
				alert("Please only provide a number for this item count");
				s.value = "0";
				s.style.backgroundColor='#ffCCCC';
			}
		}
		if ( parseInt(s.value) != tempnumber ) {
			document.getElementById('piececount').value = 0 + parseInt(document.getElementById('piececount').value) + parseInt(s.value) - tempnumber;
		}
	}

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
 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 validateform(){
		var frm = document.quoteform;
		
		if ( parseInt(frm.piececount.value) == 0 ) {
			alert("Please choose at least one item for moving or storage");
			return false;
		}
		
		if ( !isDate(frm.mdate.value) ) {
			frm.mdate.focus();
			return false;
		}
		
		if ( !isValidString(frm.fname.value) || trim(frm.fname.value) == '') {			
			frm.fname.focus();
			alert("Please correct your first name (A-z characters only)");
			return false;
		}
		
		if ( !isValidString(frm.lname.value) || trim(frm.lname.value) == '') {
			frm.lname.focus();
			alert("Please correct your last name (A-z characters only)");
			return false;
		}
		
		if ( trim(frm.homephone.value) == '' && trim(frm.cellphone.value) == '' && trim(frm.workphone.value) == ''  ){
			frm.homephone.focus();
			alert("Please provide at least one phone number");
			return false;		
		}
		
		if ( trim(frm.homephone.value) != '' && !checkInternationalPhone(frm.homephone.value) ) {
			frm.homephone.focus();
			alert("Please provide a valid home phone number");
			return false;
		}
		if ( trim(frm.cellphone.value) != '' &&!checkInternationalPhone(frm.cellphone.value) ) {
			frm.cellphone.focus();
			alert("Please provide a valid cell phone number");
			return false;
		}
		if ( trim(frm.workphone.value) != '' &&!checkInternationalPhone(frm.workphone.value) ) {
			frm.workphone.focus();
			alert("Please provide a valid work phone number");
			return false;
		}
		
		if ( !echeck(frm.email.value) ){
			frm.email.focus();
			return false;
		}
		
		if ( !isValidString(frm.address1.value) || trim(frm.address1.value) == '' || trim(frm.address1.value).length < 7 ) {
			frm.address1.focus();
			alert("Please correct your current address");
			return false;
		}
		
		if ( !isValidString(frm.address2.value) && trim(frm.address2.value) != '') {
			frm.address2.focus();
			alert("Please correct your current address(2)");
			return false;
		}
		
		if ( !isValidString(frm.city.value) || trim(frm.city.value) == '') {
			frm.city.focus();
			alert("Please correct your current city");
			return false;
		}
		if ( !isValidState(frm.state.value) || trim(frm.state.value) == '' || trim(frm.state.value).length != 2) {
			frm.state.focus();
			alert("Please correct your current state"+isValidState(frm.state.value));
			return false;
		}
		if ( !isValidString(frm.zip.value) || trim(frm.zip.value) == '' || (trim(frm.zip.value).length != 5 && trim(frm.zip.value).length != 10 )) {
			frm.zip.focus();
			alert("Please correct your current zip code \n( 99999 or 99999-9999 format)");
			return false;
		}
		if ( frm.sm[0].checked ) {
			
			if ( !isValidString(frm.taddress1.value) || trim(frm.taddress1.value) == '' || trim(frm.taddress1.value).length < 7 ) {
				frm.taddress1.focus();
				alert("Please correct the address to where you are moving");
				return false;
			}
			
			if ( !isValidString(frm.taddress2.value) && trim(frm.taddress2.value) != '') {
				frm.taddress2.focus();
				alert("Please correct the address to where you are moving(2)");
				return false;
			}
			
			if ( !isValidString(frm.tcity.value) || trim(frm.tcity.value) == '') {
				frm.tcity.focus();
				alert("Please correct the city to where you are moving ");
				return false;
			}
			if ( !isValidState(frm.tstate.value) || trim(frm.tstate.value) == ''  ) {
				frm.tstate.focus();
				alert("Please correct the state to where you are moving");
				return false;
			}
		}
		
		return true;
	}
	