﻿function OnLoad(saddr,daddr) {
	if (document.body.clientWidth < 960) document.body.style.width = 960; 
}

function isDigit (ch) { return ((ch == "0") || (ch == "1") || (ch == "2") || (ch == "3") || (ch == "4") || (ch == "5") || (ch == "6") || (ch == "7") || (ch == "8") || (ch == "9")); }
function isEmpty(str){ return ((str == null) || (str.length == 0))}
  
function isInteger (str) { 
	var i;
    if (isEmpty(str)) {
       if (isInteger.arguments.length == 1) { return true; }
       else { return (isInteger.arguments[1] == true); } }
    for (i = 0; i < str.length; i++) {  
        var ch = str.charAt(i);
        if (!isDigit(ch)) { return false; }
    }
    return true;
}
function isZIPCode (str) {
	if (isEmpty(str)){
       if (isZIPCode.arguments.length == 1){ return true;}
       else {return (isZIPCode.arguments[1] == true);}}
   return (isInteger(str) &&  (str.length == 5));
}
    
function checkzip(form) {
	if ( form.elements['izip'].value != '' ) {
		if (!isZIPCode(form.elements['izip'].value)) {
			alert(form.elements['izip'].value+' is a invalid ZIP code. It should be 5 digit.');
			form.elements['izip'].focus();
			return false;
		} else return true;	
	}
}

function validate_email(field,alerttxt)
{
  with (field)
  {
    apos=value.indexOf("@")
    dotpos=value.lastIndexOf(".")
    if (apos<1||dotpos-apos<2)
      {alert(alerttxt);return false}
    else {return true}
  }
}

function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (isNaN(parseInt(stripped))) {
        fld.style.background = 'Yellow';
		alert("The phone number contains illegal characters.\n");
		return false
   } else if (!(stripped.length == 10)) {
//        fld.style.background = 'Yellow';
		alert("The phone number is the wrong length. Make sure you included an area code.\n");
		return false
   }
}

function validate_required(field,alerttxt) {
  with (field)  {
    if (value==null||value=="") {alert(alerttxt);return false}
    else {return true}
  }
}


function validate_form(thisform) {
  with (thisform)  {
    if (validate_required(realname,"Please specify your name!")==false)
      {realname.focus();return false;}
    if (validate_required(email,"Email must be filled out!")==false)
      {email.focus();return false;}
    if (validate_email(email,"Not a valid e-mail address!")==false)
      {email.focus();return false;}
    if (validate_required(company,"Please specify your company!")==false)
      {company.focus();return false;}
    if (validate_required(address1,"Please specify your address!")==false)
      {address1.focus();return false;}
    if (validate_required(city,"Please specify your city!")==false)
      {city.focus();return false;}
    if (validate_required(state,"Please specify your state!")==false)
      {state.focus();return false;}
    if (validate_required(zipcode,"Please specify your zipcode!")==false)
      {zipcode.focus();return false;}
    if (isZIPCode(zipcode.value)==false)
      {alert(zipcode.value+' is a invalid ZIP code. It should be 5 digit.');
		zipcode.focus();
		return false;}
    if (validate_required(phone,"Please specify your phone!")==false)
      {phone.focus();return false;}
    if (validatePhone(phone)==false)
      {phone.focus();return false;}
  }
}

