var stdBrowser = (document.getElementById) ? true: false
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
var classArray = new Array(50,55,60,65,70,775,85,925,100,110,125,150,175,200,250,300,400,500);


/////////////////////////////////////////////
function inputFocus(elem)
{
		elem.style.background='#ddffdd'; 
		elem.select();
}
/////////////////////////////////////////////
function inputBlur(elem)
{
	elem.style.background='#ffffff';

}

/////////////////////////////////////////////
function validateZip(input) 
{

    if (input.value.length>0 && input.value.length<5) {
	alert('Please enter a five digit zip code');
	input.focus();
	input.select();
	input.style.background='#ffd0d0';
	return false;
      }
    else {
	return true;
    }

}

/////////////////////////////////////////////
function valNumInput(input,e)
{
    var i = e.keyCode;
  
    switch (i) {
      case [0,8,9,12,13]:
        break;  
      default:
   //     autoTab(input,e);
        isNum(input);
        break;
    }
}
/////////////////////////////////////////////
function isNum(input)
{
  var s=input.value;
  var j=s.length;

  for (i=0;i<j;i++)
    {
      if (s.charAt(i)<"0"||s.charAt(i)>"9") {
        input.value = s.slice(0,i);
        return false; }
    }   
  return true;
}

/////////////////////////////////////////////////////
function autoTab(input, e, toUpper) 
{
  var keyCode = (isNN) ? e.which : e.keyCode; 
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  len=input.maxLength;

  if(toUpper==1) {
	input.value=input.value.toUpperCase();
   }	

  if(input.value.length >= len && !containsElement(filter,keyCode)) {
  input.value = input.value.slice(0, len);

  var i=(getIndex(input)+1) % input.form.length;
  var j = input.form[i].readOnly;

  if (j) {
   if (document.add.elements[i+1]) {
    i++;
    }
  }

  input.form[i].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 buttonOver(elem)
{
	elem.style.background='#80b040'; 
	elem.style.color='#000000';
}
/////////////////////////////////////////////
function buttonOut(elem)
{
	elem.style.background='#006000';
	elem.style.color='#ffffff';	
}

//////////////////////////////////
function jumpToIt(sAnchor) {
	ns = (document.layers)? true:false 
	ie = (document.all)? true:false 

	if (ns) {
		window.scrollTo(0, document.anchors[sAnchor].y)
	} 
	if (ie) {
		if ('document.all.'+sAnchor) {
		eval('document.all.' + sAnchor + '.scrollIntoView()')
		}
	}
}

////////////////////////////
function popupWindow(url,w,h,x,y)
 {

	if (document.all) {
	 x = window.screenTop + x;
	 y = window.screenLeft + y;
	}
	else if (document.layers) {
	x = window.screenX + x;
	y = window.screenY + y;
	}

    var win = window.open(url,
    "_blank",
    "location=no,directories=no,resizable=yes,status=no,toolbar=no,menubar=no,scrollbars=yes,width="+w+"+,height="+h+",screenX="+x+",screenY="+y+",top="+y+",left="+x);
	if (window.focus) {
		win.focus();
		}
}

///////////////////////////
function isFloat(input)
{

	return isNum(input);

//	var s=input.value;
//	var j=s.length;
	
// if (!parseFloat(s) && (s != '') &&       (s != 0))
//      {return false;}
//  else
//   {
//      for (var i=0; i<j; i++)
//      {
//         if (s.charAt(i) != " ")
//         {
//            if (!parseFloat(s.charAt(i)) && !s.charAt(i) == '.') {

//		 	return false;
//		}
//         }
//      }
//   }

}

////////////////////////////
 function PrepaidCollect(input)
 {
	var s=input.value.toUpperCase();
   if (s != 'P' && s != 'C') {
       alert('Prepaid/Collect should contain a "P" or "C"');
       input.focus();
	input.select();
	input.style.background='#ffd0d0';
	return false;
      }
 }
////////////////////////////
 function Discount(input)
 {
	
   	if (!isFloat(input)) {
     		alert ("Discount should contain numbers only");
       		input.focus();
	}
   
	if (input.value >= 100) {
      		alert ("Discount must be less than 100 percent");
       	input.focus();
	}
 }

/////////////////////////////////////////////
function validateRateZip(input) 
{

    if (input.value.length<5) {
	alert('Please enter a five digit zip code');
	input.focus();
	input.select();
	input.style.background='#ffd0d0';
	return false;
      }
    else {
	return true;
    }

}

//////////////////////////////////////////
function valClass(elem) {
    if (elem.value.length) {
       if (!isClass(elem)) {


	var s='Please enter one of the following values for class codes:\n';
 	for (var i=0; i<classArray.length; i++) {
  		s+='\t'+classArray[i]+'\n';
		}
//           alert (return getClass());
//	alert('Invalid class code');
	alert(s);
	   	elem.focus();
		elem.select();
		elem.style.background='#ffd0d0';
           return false;
       }

       if (elem.value==400 || elem.value==500) {
          alert ('To inquire about freight class 400 or 500\nCall customer service at 1-800-782-5036');
       }
       return true;
    }
    else {
        return true;
    }
}

//////////////////////////////////////////
function isClass(elem)
  {
 for (var i=0; i<classArray.length; i++) {
  if (elem.value==classArray[i]) {
   return true;
  }
 }
 	return false;
}

//////////////////////////////////////////
//function getClass(val)
//  {
// var s='Please enter one of the following values for class codes:\n';
// for (var i=0; i<classArray.length; i++) {
//  s+='\t'+classArray[i]+'\n';
// }
// return s;
//}


