

function onResize()
{
  if(document.getElementById('productNav'))
  {
    document.getElementById('productNav').style.height=document.body.offsetHeight-100
  }
}


function onLoad()
{
  if(document.getElementById('productNav'))
  {
    document.getElementById('productNav').style.height=document.body.offsetHeight-100
  }
}

function showPopupBox(img, popup)
{
  if(document.curPopup)
  hideElement(document.curPopup)
  var i=findElement(img);
  if(i)
  {
    var p=findElement(popup)
    if(p)
    {
      pHt=p.children[0].children[1].height+30;
      pWd=p.children[0].children[1].width+10;
      document.curPopup=p;
      if(document.body.scrollTop)
      {
        p.style.top=document.body.scrollTop+(screen.availHeight-pHt)*.5;
      }
      else if(window.pageYOffset)
      {
        p.style.top=window.pageYOffset+(screen.availHeight-pHt)*.5;
      }
      else
      {
        p.style.top=(screen.availHeight-pHt)*.5;
      }

      p.style.left=(screen.availWidth-pWd)*.5;
      showElement(p);
    }
  }
}

function showPopupBoxRelative(img, popup)
{
  if(document.curPopup)
  hideElement(document.curPopup)
  var i=findElement(img);
  if(i)
  {
    var p=findElement(popup)
    if(p)
    {
      document.curPopup=p;
      p.style.top=getElementTop(i);
      p.style.left=i.style.left;
      showElement(p);
    }
  }
}

function validateWarrantyForm()
{
  var failmsg = "";
  failmsg = checkText(warranty_form.Product1.value);
  if (failmsg != "") {
    warranty_form.Product1.focus();
    alert(failmsg);
    return false;
  }
  failmsg = checkText(warranty_form.Product_Number1.value);
  if (failmsg != "") {
    warranty_form.Product_Number1.focus();
    alert(failmsg);
    return false;
  }
  failmsg = checkText(warranty_form.Serial_Number1.value);
  if (failmsg != "") {
    warranty_form.Serial_Number1.focus();
    alert(failmsg);
    return false;
  }
  failmsg = checkDate(warranty_form.Installation_Date1.value);
  if (failmsg != "") {
    warranty_form.Installation_Date1.focus();
    alert(failmsg);
    return false;
  }
  failmsg = checkText(warranty_form.Customer_Name.value);
  if (failmsg != "") {
    warranty_form.Customer_Name.focus();
    alert(failmsg);
    return false;
  }
  failmsg = checkText(warranty_form.Contact_Name.value);
  if (failmsg != "") {
    warranty_form.Contact_Name.focus();
    alert(failmsg);
    return false;
  }
  failmsg = checkText(warranty_form.Street_Address.value);
  if (failmsg != "") {
    warranty_form.Street_Address.focus();
    alert(failmsg);
    return false;
  }
  failmsg = checkText(warranty_form.City.value);
  if (failmsg != "") {
    warranty_form.City.focus();
    alert(failmsg);
    return false;
  }
  failmsg = checkState(warranty_form.State.selectedIndex);
  if (failmsg != "") {
    warranty_form.State.focus();
    alert(failmsg);
    return false;
  }
  failmsg = checkZip(warranty_form.Zip_Code.value);
  if (failmsg != "") {
    warranty_form.Zip_Code.focus();
    alert(failmsg);
    return false;
  }
  failmsg = checkPhone(warranty_form.Telephone.value);
  if (failmsg != "") {
    warranty_form.Telephone.focus();
    alert(failmsg);
    return false;
  }
  failmsg = checkText(warranty_form.Country.value);
  if (failmsg != "") {
    warranty_form.Country.focus();
    alert(failmsg);
    return false;
  }
  //failmsg = checkEmail(warranty_form.Email.value);
  //if (failmsg != "") {
  //  alert(failmsg);
  //  return false;
  //}
  //failmsg = checkFax(warranty_form.Fax.value);
  //if (failmsg != "") {
  //  alert(failmsg);
  //  return false;
  //}
  //failmsg = checkText(warranty_form.Sales_Person.value);
  //if (failmsg != "") {
  //  warranty_form.Sales_Person.focus();
  //  alert(failmsg);
  //  return false;
  //}
  //failmsg = checkText(warranty_form.Dealer_Rep_Name.value);
  //if (failmsg != "") {
  //  alert(failmsg);
  //  return false;
  //}
  warranty_form.submit();
}

function checkText(strng) {
  var error = "";
  if (strng == "") {
    error = "A required field is blank.\n";
  }
  return error;
}

function checkEmail (strng) {
  var error="";
  if (strng == "") {
    error = "You didn't enter an email address.\n";
  }
  var emailFilter=/^.+@.+\..{2,3}$/;
  if (!(emailFilter.test(strng))) { 
    error = "Please enter a valid email address.\n";
  }
  else
  {
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
    if (strng.match(illegalChars)) {
      error = "The email address contains illegal characters.\n";
    }
  }
  return error;    
}

function checkPhone(strng) {
  var error = "";
  if (strng == "") {
    error = "You didn't enter a phone number.\n";
  }
  var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
  if (isNaN(parseInt(stripped))) {
    error = "The phone number contains illegal characters.";
  }
  if (!(stripped.length == 10)) {
	  error = "The phone number is the wrong length. Make sure you included an area code.\n";
  } 
  return error;
}

function checkFax(strng) {
  var error = "";
  if (strng == "") {
    error = "You didn't enter a fax number.\n";
  }
  var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
  if (isNaN(parseInt(stripped))) {
    error = "The fax number contains illegal characters.";
  }
  if (!(stripped.length == 10)) {
	  error = "The fax number is the wrong length. Make sure you included an area code.\n";
  } 
  return error;
}

function checkState(choice) {
  var error = "";
  if (choice == 0) {
    error = "You didn't choose a State.\n";
  }    
  return error;
}

function checkZip(string) {
  error = "";
  var valid = "0123456789-";
  var hyphencount = 0;
  if (string.length!=5 && string.length!=10) {
    error = "Please enter your 5 digit or 5 digit+4 zip code.\n";
  }
  for (var i=0; i < string.length; i++) {
    temp = "" + string.substring(i, i+1);
    if (temp == "-") hyphencount++;
    if (valid.indexOf(temp) == "-1") {
      error = "Invalid characters in your zip code.  Please try again.";
    }
    if ((hyphencount > 1) || ((string.length==10) && ""+string.charAt(5)!="-")) {
      error = "The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.\n";
    }
  }
  return error;
}

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

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 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 checkDate(dtStr){
  var error = "";
	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){
		error = "The date format should be : mm/dd/yyyy.\n"
	}
	if (strMonth.length<1 || month<1 || month>12){
		error = "Please enter a valid month.\n"
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		error = "Please enter a valid day"
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		error = "Please enter a valid 4 digit year between "+minYear+" and "+maxYear+".\n"
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		error = "Please enter a valid date.\n"
	}
	return error;
}