function isNumber(inputStr) {
 for (var i = 0; i < inputStr.length; i++) {
  var oneChar = inputStr.substring(i, i + 1)
  if (oneChar < '0' || oneChar > '9') {
   return false
  }
 }
 return true
}

function clearInquiryForm()
{
 document.forms["inquiry"].reset(); 
}

function valInquiryForm(popupFlag) {
 var reqFields = new Array('Name', 'Address', 'City', 'State-Province-Region', 'zip', 'Telephone', 'Time', 'Email');
 for (var i = 0; i < reqFields.length; i++) {
  if(eval('document.forms["inquiry"].elements["' + reqFields[i] + '"].value.length')==0)
  {
   alert('Check your data, please.\nSome of required fields are empty.');
   f = eval('document.forms["inquiry"].elements["' + reqFields[i] + '"].focus()');
   return false;
  }
 }

 var r = 0;
 for (var rIndex = 0; rIndex < document.forms['inquiry'].elements['RV'].length; rIndex++) {
  if(document.forms['inquiry'].elements['RV'][rIndex].checked == true) {
   r = r + 1;
  }
 }
 if(r == 0){
  alert('One product type should be selected!');
  return false;
 }

 var tZip = document.forms['inquiry'].elements['zip'].value;
 var tLoc = document.forms['inquiry'].elements['location'].options[document.forms['inquiry'].elements['location'].selectedIndex].value.toUpperCase();

 if((tZip.length == 7)&&(tZip.indexOf(" ") == 3)&&(tLoc != 'CANADA')) {
  var q = 0;
  for (i = 0; i < tZip.length; i++) {
   if (tZip.substring(i,(i+1)) == ' ') {
     q = q + 1;
   }
  }
  if(q == 1) {
   alert('It appears that you have entered a Canadian Postal code,\nbut you have not selected Canada as the country.\nCorrect data and submit again, please.');
   return false;
  }
 }

 if(tLoc == 'USA') {
  if(tZip.length < 5) {
   alert('ZIP field was filled incorrectly.\nYou should enter 5 digits.\nCorrect data and submit again, please.');
   document.forms['inquiry'].elements['zip'].select();
   return false;
  }
  if(tZip.length > 5) {
   document.forms['inquiry'].elements['zip'].value = tZip.substring(0,5);
   alert('ZIP field was filled incorrectly.\nThe data was truncated to 5 digits.\nVerify data and submit again, please.');
   document.forms['inquiry'].elements['zip'].select();
   return false;
  }
  if(tZip.length == 5) {
   if(!isNumber(tZip)){
    alert('ZIP field was filled incorrectly.\nYou should not use letters in a USA ZIP code.\nVerify data and submit again, please.');
    document.forms['inquiry'].elements['zip'].select();
    return false;
   }
  }
 }

	if(tLoc == 'CANADA')
	{ 
		reCanZip=/^[^\d\s]\d[^\d\s] \d[^\d\s]\d$/;
		if(!reCanZip.test(tZip))
		{
			alert('Postal code field was filled incorrectly.\nYou should enter code in form \"ANA NAN\"\n(where A is alpha character and N is numeric character)\nfor a Canadian Postal code.\nCorrect data and submit again, please.');
			document.forms['inquiry'].elements['zip'].select();
			return false;
		}
	}

 if(popupFlag==1)
 {
  var obj=window.open("", "inquiry", "width=580,height=550,top=0,left=0,scrollbars=no,resize=no");
  if(obj==null || typeof(obj)=="undefined")
  {
   alert("Please disable pop-up blocker feature of your browser.");
   return false;
  }
  else
  {
   setTimeout('clearInquiryForm()', 5000);
  }
 }

 return true;
}