function validateProgram1(){
    if(document.frmPrograms.City.value=='' && document.frmPrograms.state.value==''){
	  alert('You must select either a city or a state');
	  document.frmPrograms.City.focus();
	  return false;
	}
	return true;
}

function validateProgram2(){
    if(document.frmPrograms.Radius.value==''){
	  alert('You must select a mile radius');
	  document.frmPrograms.Radius.focus();
	  return false;
	}
    if(document.frmPrograms.ZipCode.value==''){
	  alert('You must enter a zip/postal code!');
	  document.frmPrograms.ZipCode.focus();
	  return false;
	}
	if(IsNumeric(document.frmPrograms.ZipCode.value) == false) {
      alert("Please enter a valid US zip/postal code, 5 characters long.");
	  document.frmPrograms.ZipCode.focus();
	  return false;
    }
	return true;
}

function validateFacility1(){
    if(document.frmFacilities.City.value=='' && document.frmFacilities.state.value=='' && document.frmFacilities.Name.value==''){
	  alert('You must select either facility name, city or a state');
	  document.frmFacilities.Name.focus();
	  return false;
	}
	return true;
}

function validateFacility2(){
    if(document.frmFacilities.Radius.value==''){
	  alert('You must select a mile radius');
	  document.frmFacilities.Radius.focus();
	  return false;
	}
    if(document.frmFacilities.ZipCode.value==''){
	  alert('You must enter a zip/postal code!');
	  document.frmFacilities.ZipCode.focus();
	  return false;
	}
	if(IsNumeric(document.frmFacilities.ZipCode.value) == false) {
      alert("Please enter a valid US zip/postal code, 5 characters long.");
	  document.frmFacilities.ZipCode.focus();
	  return false;
    }
	return true;
}

function validateRetailer1(){
    if(document.frmRetailer.city.value=='' && document.frmRetailer.state.value=='' && document.frmRetailer.name.value==''){
	  alert('You must select either facility name, city or a state');
	  document.frmRetailer.name.focus();
	  return false;
	}
	return true;
}

function validateRetailer2(){
    if(document.frmRetailer.Radius.value==''){
	  alert('You must select a mile radius');
	  document.frmRetailer.Radius.focus();
	  return false;
	}
    if(document.frmRetailer.ZipCode.value==''){
	  alert('You must enter a zip/postal code!');
	  document.frmRetailer.ZipCode.focus();
	  return false;
	}
	if(IsNumeric(document.frmRetailer.ZipCode.value) == false) {
      alert("Please enter a valid US zip/postal code, 5 characters long.");
	  document.frmRetailer.ZipCode.focus();
	  return false;
    }
	return true;
}

function validateDemo1(){
    if(document.frmDemo.city.value=='' && document.frmDemo.state.value==''){
	  alert('You must select either city or a state');
	  document.frmDemo.city.focus();
	  return false;
	}
	return true;
}

function validateDemo2(){
    if(document.frmDemo.Radius.value==''){
	  alert('You must select a mile radius');
	  document.frmDemo.Radius.focus();
	  return false;
	}
    if(document.frmDemo.ZipCode.value==''){
	  alert('You must enter a zip/postal code!');
	  document.frmDemo.ZipCode.focus();
	  return false;
	}
	if(IsNumeric(document.frmDemo.ZipCode.value) == false) {
      alert("Please enter a valid US zip/postal code, 5 characters long.");
	  document.frmDemo.ZipCode.focus();
	  return false;
    }
	return true;
}

function validateGame1(){
    if(document.frmGame.city.value=='' && document.frmGame.state.value==''){
	  alert('You must select either city or a state');
	  document.frmGame.city.focus();
	  return false;
	}
	return true;
}

function validateGame2(){
    if(document.frmGame.Radius.value==''){
	  alert('You must select a mile radius');
	  document.frmGame.Radius.focus();
	  return false;
	}
    if(document.frmGame.ZipCode.value==''){
	  alert('You must enter a zip/postal code!');
	  document.frmGame.ZipCode.focus();
	  return false;
	}
	if(IsNumeric(document.frmGame.ZipCode.value) == false) {
      alert("Please enter a valid US zip/postal code, 5 characters long.");
	  document.frmGame.ZipCode.focus();
	  return false;
    }
	return true;
}

function validateCoach1(){
    if(document.frmCoach.city.value=='' && document.frmCoach.state.value==''){
	  alert('You must select either city or a state');
	  document.frmCoach.city.focus();
	  return false;
	}
	return true;
}

function validateCoach2(){
    if(document.frmCoach.Radius.value==''){
	  alert('You must select a mile radius');
	  document.frmCoach.Radius.focus();
	  return false;
	}
    if(document.frmCoach.ZipCode.value==''){
	  alert('You must enter a zip/postal code!');
	  document.frmCoach.ZipCode.focus();
	  return false;
	}
	if(IsNumeric(document.frmCoach.ZipCode.value) == false) {
      alert("Please enter a valid US zip/postal code, 5 characters long.");
	  document.frmCoach.ZipCode.focus();
	  return false;
    }
	return true;
}

//function validateCoach(){
//  if(document.frmCoach.ZipCode.value!=''){
//    if(document.frmCoach.Radius.value==''){
//	  alert('You must enter both zip/postal code and mile radius');
//	  document.frmCoach.Radius.focus();
//	  return false;
//	}
//  }
//  if(document.frmCoach.Radius.value!=''){
//    if(document.frmCoach.ZipCode.value==''){
//	  alert('You must enter both zip/postal code and mile radius');
//	  document.frmCoach.ZipCode.focus();
//	  return false;
//	}
//  }
//  return true;
//}
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
	input.value = input.value.slice(0, len);
	input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
	if(arr[index] == ele)
	found = true;
	else
	index++;
	return found;
}

function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
	if (input.form[i] == input)index = i;
	else i++;
	return index;
	}
	return true;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
