  var d,month,day,year,hours,minutes,seconds,parmSeparator,bottom;
  var right,pos_x,pos_y,plcmt,attribs;
  var attribs='menubar=yes,scrollbars=yes,resizable=yes,status=no,';
  var dblclick=1;

  function submit_form(action){
   if(arguments.length==1){
    document.f.SIACTN.value=action;
    document.f.submit();
   }else{
    eval("document." + arguments[1] + ".SIACTN.value=action;");
    eval("document." + arguments[1] + ".submit();");
   }
  }

  function chkDblClick(){
   if (dblclick>1){
    alert("We are processing your request, this may take a moment.");
    return false;
   }else{
    dblclick=2;
    return true;
   }
  }

  function resetDblClick(){
   dblclick=1;
  }

  function popUp(pagePU, namePU, h, w){
   d = new Date();
   month = d.getMonth();
   day = d.getDate();
   year = d.getYear();
   hours = d.getHours();
   minutes = d.getMinutes();
   seconds = d.getSeconds();

   if (pagePU.indexOf("?") == -1)
    parmSeparator = "?";
   else
    parmSeparator = "&";

   anchorPos=pagePU.indexOf("#");
   if (anchorPos == -1){
    HREFlink=pagePU;
    HREFanchor='';
   }else{
    HREFlink=pagePU.substring(0,anchorPos);
    HREFanchor=pagePU.substring(anchorPos);
   }

   pagePU = HREFlink + parmSeparator + "x="+month+day+year+hours+minutes+seconds + HREFanchor;

   if (window.screenX){
    pos_x = window.screenX + 125;
    pos_y = window.screenY + 233;
    plcmt = (',left=' + pos_x + ',top=' + pos_y);
   }else if (screen){
    bottom = screen.availHeight;
    right = screen.availWidth;
    pos_x = parseInt((right- w)/2) ;
    pos_y = parseInt((bottom - h)/2);
    plcmt = (',left=' + pos_x + ',top=' + pos_y);
   }

   myPopUp=window.open(pagePU,namePU,attribs+'width='+w+',height='+h+plcmt);
  }

  function stockMessage(p_qty,p_ctr,p_form){
   if (arguments.length>3 && arguments[3]=='Y'){
    //using new search
    document.write("<a href=\"javascript:showStockStatus(" + p_qty + ",document." + p_form + ".SIQTY" + p_ctr + ".value);\"><img src=\"/images/btn_check_stock.gif\" border=0 alt=\"Check Stock\"></a>");
   }else{
    document.write("<a href=\"javascript:showStockStatus(" + p_qty + ",document." + p_form + ".CKQTY" + p_ctr + ".value);\">Check Stock</a>");
    document.write(" <INPUT SIZE=3 MAXLENGTH=5 NAME=\"CKQTY" + p_ctr + "\">");
   }
  }

  function DSasStockStatus(p_scrn, p_news){
   if (arguments.length==0){
    document.write("<a href=\"javascript:showDSMessage();\">DS</a>");
   }else{
    if (p_scrn=='C'){
     document.write("<a href=\"javascript:showDSMessage();\">DS</a>");
    }else{
     document.write("<a href=\"javascript:showDSMessage();\"><img src=\"/images/btn_check_stock.gif\" border=0 alt=\"check stock\"></a>");
    }
   }
  }

  function showDSMessage(){
   if(!window.stdInternetPHONE) stdInternetPHONE='1-800-645-7270';
   dsMessage='Item can only be shipped directly from the manufacturer.  Customer Service will contact you shortly with information regarding inventory and delivery options. If you require immediate assistance, please call Customer Service at ' + stdInternetPHONE + ' to discuss delivery options. ';
   alert(dsMessage);
  }

  function showStockStatus(onhand,amt){
   var invalidNumerics = false;

   if (onhand==0){
    alert("This item is currently out of stock.");
   }else{
    if ((amt/amt != 1 && amt != 0) || amt=="") invalidNumerics=true;
 
    if (invalidNumerics)
     alert("Please enter a valid quantity");
    else if (amt <= onhand)
     alert("Your requested quantity of " + amt + " is in stock and ready to ship.");
    else
     alert("We have " + onhand + " of your requested quantity in stock and ready to ship.");
   }
  }

  /******FOR ZERO PRICED ITEMS ON WEBSITE******/
  var zpm="";
  function zl(){
   if(!window.stdInternetPHONECOM) stdInternetPHONECOM='1-800-753-7970';
   zpm="Please contact our Ecommerce Customer Service Support at " + stdInternetPHONECOM + " for pricing.";
   document.write('<a href="javascript:zm();"><img src="/images/Alert.gif" alt="' + zpm + '" border=0></a>');
  }

  function zm(){
   alert(zpm);
  }

  function chkAddToCart(inForm){
   if (chkDblClick()){
    switch (inForm.SITYPE001[inForm.SITYPE001.selectedIndex].value){
     case ("2"):
      cartAddType="Competitor";
      break;
     case ("3"):
      cartAddType="Customer";
      break;
     case ("4"):
      cartAddType="Manufacturer";
      break;
     case ("5"):
      cartAddType="UPC";
      break;
     case ("6"):
      cartAddType="NSN";
      break; 
     default:
      cartAddType="MSC";
    }

    if (inForm.SIITEM001.value=="" && inForm.SIQTY001.value==""){
     cartAddError="Please enter a " + cartAddType + " part # and a quantity.";
    }else if (inForm.SIITEM001.value!="" && inForm.SIQTY001.value==""){
     cartAddError="You have entered a " + cartAddType + " part #:" + inForm.SIITEM001.value + " with no quantity.";
    }else if(inForm.SIITEM001.value=="" && inForm.SIQTY001.value!=""){
     cartAddError="You have entered a quantity of " + inForm.SIQTY001.value + " with no " + cartAddType + " part #";
    }else{
     cartAddError="";
    }

    if (cartAddError!=""){
     resetDblClick();
     alert(cartAddError);
     return false;
    }else{
     return true;
    }
   }else{
    return false;
   }
  }


 /******MULTIPURPOSE: ADD EVENT LISTENER TO OBJECT******/

 /* examples:

         // wrapped with an inline function inorder to pass "this"
      addEvent(inputs[i], 'focus',function() { myFunction(this); } ); 

         // otherwise use the function itself -- *not* a call to it, i.e. no () 
      addEvent(inputs[i], 'focus', myFunction );  // no parms
 */

 
  function addEvent( obj, type, fn ) 
  {
   if ( obj.attachEvent ) {
     obj['e'+type+fn] = fn;
     obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
     obj.attachEvent( 'on'+type, obj[type+fn] );
   } else
   obj.addEventListener( type, fn, false );
  }

  function removeEvent( obj, type, fn ) 
  {
   if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, obj[type+fn] );
    obj[type+fn] = null;
   } else
    obj.removeEventListener( type, fn, false );
  }

 /******FOR "GHOSTED" FIELDS******/
  function blurGhostFld(element){
    var myValue=element.value;
    var myDefault=element.getAttribute('ghostValue');
    if ( myValue == myDefault || myValue == '')
    {
    	element.className="ghostedField";
        if ( myValue == '' )
        {
           element.value=myDefault;
        }
    }
    else
    {
    	element.className="unghostedField";
    }
  }

  function focusGhostFld(element){
    var myValue=element.value;
    var myDefault=element.getAttribute('ghostValue');
    if ( myValue == myDefault || myValue == '')
    {
    	element.className="unghostedField";
    	element.value='';
    }
  }

  function initializeGhosts()  {
    var inputs = document.getElementsByTagName("input");
    var inputsLength = inputs.length;
    for (var i = 0; i < inputsLength; i++) {
      if ( inputs[i].getAttribute('ghostValue') && !inputs[i].getAttribute('ghostValueInit') ) // not null
      {
          inputs[i].setAttribute("autocomplete","off");
          addEvent(inputs[i], 'blur' ,function() { blurGhostFld(this);  } );
          addEvent(inputs[i], 'focus',function() { focusGhostFld(this); } );
          blurGhostFld(inputs[i]);
          inputs[i].setAttribute('ghostValueInit','x');
      }
    }
  }

  function determinePO(formName, formActionName, poboxWarn, weatherWarn){
   if (poboxWarn!='Y'){
    zipMessage(formName, formActionName, weatherWarn);
   }else{
    if (confirm("The shipping address provided appears to be a P.O. Box. Please be advised that we cannot ship merchandise to a P.O. Box.\n\nClick 'OK' to use the current ship to address.\n\nClick 'Cancel' to provide a street address for shipping.")){
     zipMessage(formName, formActionName, weatherWarn);
    }else{
     resetDblClick(); 
    }
   }
  }

  function zipMessage(formName, formActionName, weatherWarn){
   if (weatherWarn!='Y'){
    submit_form(formActionName, formName);
   }else{
    if (confirm("Shipping Alert: Due to weather, delivery into this area may be delayed.")){
     submit_form(formActionName, formName);
    }else{
     resetDblClick();
    }
   }
  }