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 closeNav()
	{
		var x = document.getElementsByTagName('div');
		for (var i=0;i<x.length;i++)
		{
			if (x[i].className == 'menu')
				x[i].style.display = "none";
		}
	}
  
  function clickNav(obj)
  {
  	if(obj.style.display == "none")
  	{
  		closeNav();
  		obj.style.display = "block";
  	}
  	else
  		closeNav();
  }
/*************************************************************************\
boolean isNum(String argvalue)
return true if argvalue contains only numeric characters,
else return false.
\*************************************************************************/
function isNum(argvalue) {
argvalue = argvalue.toString();

if (argvalue.length == 0)
return false;

for (var n = 0; n < argvalue.length; n++)
if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9")
return false;

return true;
}

function valNum(arg) {
	var argvalue = arg.value.toString();
	var error = 0;
	if (argvalue.length == 0)
		return true;
	for (var n = 0; n < argvalue.length; n++)
		if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9")
			error = 1;
	
	if (error == 1) {
		alert("Wrong quantity value");
		arg.value = "";
	}		
	else
		return true;
}

function GoToContinue() {
  var update = document.frmCart.update.value;
  if (update == 1){	
		var where_to= confirm("You didn't save changes to quantities. To proceed without saving changes, please hit 'OK'.");
		if (where_to== true){  	  
			document.frmCart.action = "catalog.asp";
			document.frmCart.submit();
		}
	}else{
		document.frmCart.action = "catalog.asp";
		document.frmCart.submit();
	}
					
}
	
function GoToCheckout() {
  var update = document.frmCart.update.value;
  if (update == 1){	
		var where_to= confirm("You didn't save changes to quantities. To proceed without saving changes, please hit 'OK'.");
		if (where_to== true){  	  
			document.frmCart.action = "customerinfo.asp";
			document.frmCart.submit();
		}
	}else{
	//	var where_to= confirm("You won't be able to do any changes to the order after proceeding to checkout.");
	//	if (where_to== true){  	 
			document.frmCart.action = "customerinfo.asp";
			document.frmCart.submit();
	//	}
	}
}

function GoToSave() {
  document.frmCart.clean.value = "clean";
  document.frmCart.update.value = "0";
  document.frmCart.action = "cart.asp";
  document.frmCart.submit();
}

function GoToCart() {
 
  document.frmCart.action = "cart.asp";
  document.frmCart.submit();
}	
	

function AddToCart() {
  document.frmCart.action = "catalog.asp";
  document.frmCart.submit();
}	
	
function GoToClear(){
	var where_to= confirm("This action will remove all selected items from your cart. Are you sure you want to do this?");
	if (where_to== true){
		document.frmCart.clean.value = "empty";
		document.frmCart.action = "catalog.asp";
		document.frmCart.submit();
	}else{
		return true;
	}
}

function GoToCancel(){
	var where_to= confirm("This action will remove all selected items from your cart. Are you sure you want to do this?");
	if (where_to== true){		
		document.frmCart.action = "default.asp?clean=empty";
		document.frmCart.submit();
	}else{
		return true;
	}
}

function GoToConfirmation() {
	var where_to= confirm("Please print your order for your records before submitting.");
	if (where_to== true){
		window.print();
	}		
	document.frmCart.action = "confirmation.asp";
	document.frmCart.submit();
}	

function GoToEdit(){
	document.frmCart.action = "customerinfo.asp";
	document.frmCart.submit();
}

function infoVerify(theForm){
    if(theForm.Email.value == "" || theForm.Email.value == null){
		alert("Please enter Email.");
		theForm.elements["Email"].focus();	
	}else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theForm.Email.value))){
        alert("Please enter valid Email.");
		theForm.elements["Email"].focus();   
	}else if(theForm.Name.value == "" || theForm.Name.value == null){
		alert("Please enter Name.");
		theForm.elements["Name"].focus();	 
	}else if(theForm.Company.value == "" || theForm.Company.value == null){
		alert("Please enter Company.");
		theForm.elements["Company"].focus();
	}else if(theForm.Address.value == "" || theForm.Address.value == null){
		alert("Please enter Address.");
		theForm.elements["Address"].focus();
	}else if(theForm.City.value == "" || theForm.City.value == null){
		alert("Please enter City.");
		theForm.elements["City"].focus();
	}else if(theForm.State.options[theForm.State.selectedIndex].value == "-" ){
		alert("Please select State.");
		theForm.elements["State"].focus();		
	}else if(theForm.Zip.value == "" || theForm.Zip.value == null){
		alert("Please enter Zip Code.");
		theForm.elements["Zip"].focus();
	}else if(theForm.Phone.value == "" || theForm.Phone.value == null){
		alert("Please enter Phone.");
		theForm.elements["Phone"].focus();
					
	}else{
		 theForm.ExEmail.value = "";
	     theForm.submit();
	}	
}

function exinfoVerify(theForm){
       
	if(theForm.ExEmail.value == "" || theForm.ExEmail.value == null){
		alert("Please enter Email.");
		theForm.elements["ExEmail"].focus();	
	}else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theForm.ExEmail.value))){
        alert("Please enter valid Email.");
		theForm.elements["ExEmail"].focus();   
	}else if(theForm.Name.value == "" || theForm.Name.value == null){
		alert("Please enter Name.");
		theForm.elements["Name"].focus();	 
	}else if(theForm.Company.value == "" || theForm.Company.value == null){
		alert("Please enter Company.");
		theForm.elements["Company"].focus();
	}else if(theForm.Address.value == "" || theForm.Address.value == null){
		alert("Please enter Address.");
		theForm.elements["Address"].focus();
	}else if(theForm.City.value == "" || theForm.City.value == null){
		alert("Please enter City.");
		theForm.elements["City"].focus();
	}else if(theForm.State.options[theForm.State.selectedIndex].value == "-" ){
		alert("Please select State.");
		theForm.elements["State"].focus();	
	}else if(theForm.Zip.value == "" || theForm.Zip.value == null){
		alert("Please enter Zip Code.");
		theForm.elements["Zip"].focus();
	}else if(theForm.Phone.value == "" || theForm.Phone.value == null){
		alert("Please enter Phone.");
		theForm.elements["Phone"].focus();
					
	}else{		
	     theForm.submit();
	}	
}


function exEmailVerify(theForm){
       
	if(theForm.ExEmail.value == "" || theForm.ExEmail.value == null){
		alert("Please enter Email.");
		theForm.elements["ExEmail"].focus();	
	}else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theForm.ExEmail.value))){
        alert("Please enter valid Email.");
		theForm.elements["ExEmail"].focus();   
	}else{		
	     theForm.submit();
	}	
}