// JavaScript Document
var roundToolsImage = "/global_images/content_prod_cuttingtools.jpg";
var sawBladesImage = "/global_images/content_prod_sawblades.jpg";
var indexableImage = "/global_images/content_prod_carbide.jpg";
var toolworkholdingimage = "/global_images/content_prod_toolholding.jpg";
var precisionmeasuringimage = "/global_images/content_prod_measuring.jpg";
var abrassiveimage = "/global_images/content_prod_abrasives.jpg";
var handtoolsimage = "/global_images/content_prod_mhandtools.jpg";
var powertoolsimage = "/global_images/content_prod_powertools.jpg";
var materialhandlingimage = "/global_images/content_prod_materialHand.gif";
var adhesivesimage = "/global_images/content_prod_adhesives.gif";
var safetyimage = "/global_images/content_prod_safety.gif";
var tollingcompimage = "/global_images/content_prod_toolcomp.gif";
var flatstockmaterialimage = "/global_images/content_prod_flatstock.gif";
var machineryimage = "/global_images/content_prod_machinery.gif";
var remember = new Array();
var remember2 = new Array();
var checkIt;
var DHTML = (document.getElementById || document.all || document.layers);
var submit = false;
var timeout = 0;
var backOrderItems = 0;
var backOrder = false;
var shipMethodOK = true;
var shipMethodOK1 = true;
var dropDownName = "";
var oldPostal="";
var oldPostal2="";


function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function show()
{
    //alert("hello"+timeout);
    if (!DHTML) return;
    //checkUserInput();


    if(timeout == 100) return;

    if (remember[1] && remember[1] == dropDownName) return;


    if (remember[1])
    {
        closeAll(1);
    }
    if (dropDownName)
    {
        var x = getObj(dropDownName);
        x.visibility = 'visible';
    }
    remember[1] = dropDownName;
    //if (obj.parentNode) y = obj.parentNode;
    //else if (obj.parentElement) y = obj.parentElement;
    //else return;
    //if (y.className) return;
    //y.className = 'over';
    //if (remember2[lvl]) remember2[lvl].className = '';
    //remember2[lvl] = y;
}

function delay(name)
{

    dropDownName = name;

    setTimeout("show();", 500);
}

function closeAll(lvl)
{
    for (i=remember.length - 1;i>=lvl;i--)
    {
        if (remember[i])
        {
            var x = getObj(remember[i]);
            x.visibility = 'hidden';
        }
        remember[i] = null;
        if (remember2[i])
        {
            remember2[i].className = '';
            remember2[i] = null;
        }
    }
}

function checkUserInput(time)
{

    timeout = time;
    if (checkIt) clearTimeout(checkIt);
    checkIt = setTimeout('closeAll(1)',time);
}

function swapProductImage(name)
{

    if (name=="roundTools")
    {
        document.productImage.src = roundToolsImage;
    }

    if (name=="sawBlades")
    {
        document.productImage.src = sawBladesImage;
    }

    if(name=="indexable")
    {
        document.productImage.src = indexableImage;
    }

    if(name=="toolHolding")
    {
        document.productImage.src = toolworkholdingimage;
    }

    if(name=="precisionMeasuring")
    {
        document.productImage.src = precisionmeasuringimage;
    }
    if(name=="abbrasives")
    {
        document.productImage.src = abrassiveimage;
    }
    if(name=="handTools")
    {
        document.productImage.src = handtoolsimage;
    }
    if(name=="powerTools")
    {
        document.productImage.src = powertoolsimage;
    }
    if(name=="materialHandling")
    {
        document.productImage.src = materialhandlingimage;
    }
    if(name=="adhesivesLubrication")
    {
        document.productImage.src = adhesivesimage;
    }
    if(name=="safety")
    {
        document.productImage.src = safetyimage;
    }
    if(name=="toollingComponents")
    {
        document.productImage.src = tollingcompimage;
    }
    if(name=="flatStock")
    {
        document.productImage.src = flatstockmaterialimage;
    }
    if(name=="machinery")
    {
        document.productImage.src = machineryimage;
    }

}

function getObj(name)
{
  if (document.getElementById)
  {
    return document.getElementById(name).style;
  }
  else if (document.all)
  {
    return document.all[name].style;
  }
  else if (document.layers)
  {
    return document.layers[name];
  }
  else return false;
}

function getObj2(name)
{
  if (document.getElementById)
  {
    return document.getElementById(name);
  }
  else if (document.all)
  {
    return document.all[name];
  }
  else if (document.layers)
  {
    return document.layers[name];
  }
  else return false;
}

function sureClear(){
    var message = "";
    if(backOrder){
      message = "Most items are available for immediate drop-ship from the manufacturer.  Call 1-800-521-9520 to request drop-shipment.\n";
      message = message + "If you still want to clear your cart click the \"OK\" button.";
    }else{
      message = "Are you sure you want to clear your cart?";
    }
    var return_value = confirm(message);
    if ( return_value == true ) {
        return true;
    }else{
        return false;
    }
}




function sureUpdate(){
    var message = "Most items are available for immediate drop-ship from the manufacturer.\nCall 1-800-521-9520 to request drop-shipment.\n\n";
    message = message + "If you still want to remove items from your cart click the \"OK\" button.";
    if(backOrderItems != 0){
      var return_value = confirm(message);
      if ( return_value == true ) {
            return true;
      }else{
        return false;
      }
    }else{
        return true;
    }
}

function sureClearUK(){
    var message = "";
    if(backOrder){
      message = "Most items are available for immediate drop-ship from the manufacturer.  Call 0800 66 33 55 to request drop-shipment.\n";
      message = message + "If you still want to clear your basket click the \"OK\" button.";
    }else{
      message = "Are you sure you want to clear your basket?";
    }
    var return_value = confirm(message);
    if ( return_value == true ) {
        return true;
    }else{
        return false;
    }
}




function sureUpdateUK(){
    var message = "Most items are available for immediate drop-ship from the manufacturer.\nCall 0800 66 33 55 to request drop-shipment.\n\n";
    message = message + "If you still want to remove items from your basket click the \"OK\" button.";
    if(backOrderItems != 0){
      var return_value = confirm(message);
      if ( return_value == true ) {
            return true;
      }else{
        return false;
      }
    }else{
        return true;
    }
}

function backorderExist(){
    backOrder = true;
}

function stateLoad(){
    var countryObj = document.jlform.countrySelect1;
    if(countryObj != null){
        showState(countryObj);
    }
}

function stateLoad2(){
    var countryObj = document.jlform.countrySelect2;
    if(countryObj != null){
        showState2(countryObj);
    }
}

function setPostalCode(el){
 if(el.value == 'RI'){
  if(document.f.SIIPST != null){
   oldPostal = document.f.SIIPST.value;
   document.f.SIIPST.value='00000';
  }
 }else if(document.f.SIIPST != null){
  document.f.SIIPST.value = oldPostal;
 }
}

function setPostalCode2(el){
 if(el.value == 'RI'){
  if(document.f.SIMPST != null){
   oldPostal2 = document.f.SIMPST.value;
   document.f.SIMPST.value='00000';
  }
 }else if(document.f.SIMPST != null){
  document.f.SIMPST.value = oldPostal2;
 }
}

function showState(el) {
 setPostalCode(el);
}

function showState2(el) {
 setPostalCode2(el);
}

function showText(el) {
    var txt = (el[el.selectedIndex].value);
    var manu = getObj2("manuDiv");
    if(txt == ""){
        manu.style.display = 'none';
    }else{
        manu.innerHTML = "You selected: " + txt;
        manu.style.display = '';
    }
}

function showText2(el) {
    var txt = (el[el.selectedIndex].value);
    var divName = el.name;
    len = divName.length;
    var attr = getObj2(divName.substring(0,len-5)+'Div');

    if(txt == ""){
        attr.style.display = 'none';
    }else{
        attr.innerHTML = "You selected: " + txt;
        attr.style.display = '';
    }
}

function checkSubmit()
{

  // This is to make sure that the form is submitted only once when
  // the user hits several times on the login button.
  if (submit)
  {
    alert("We are performing your search.\nPlease do not hit the \"Go\" button multiple times as it will slow the search process.\nClick the \"OK\" button below to continue.");
    return false;
  }
  submit = true;

  return true;
}

var strFreigthService;
function setFreightService(freigthService)
{
    //alert (" inside setFreightService" + freigthService) ;
    strFreigthService = freightService;

}
function disableOrderSubmit()
{
  var orderDiv = getObj2("orderDiv");
  var orderButton = getObj2("orderButton");
  var scheduleButton = getObj2("scheduleDiv");
  var cancelDiv = getObj2("cancelDiv");
  orderButton.style.visibility = 'hidden';
  if(scheduleButton){
      scheduleButton.style.visibility = 'hidden';
  }
  cancelDiv.style.visibility = 'hidden';
  orderDiv.innerHTML = "We are processing your order.  Do not click the &quot;Stop&quot; button as it will not stop your order.  Please call or e-mail us if you wish to make any changes to this order.";
  orderDiv.style.display = '';

}

function protectOzoneRefresh()
{
  var oz1Div = getObj2("oz1Div");
  var oz2Div = getObj2("oz2Div");
  var oz3Div = getObj2("oz3Div");
  var oz4Div = getObj2("oz4Div");
  oz1Div.innerHTML = "Please wait until we process your request.";
  oz1Div.style.display = '';
  oz2Div.style.display = 'none';
  oz3Div.style.display = 'none';
  oz4Div.style.display = 'none';
}

function checkBackorder(item)
{
  if(item == true){
    backOrderItems++;
  }else{
    backOrderItems--;
  }
}

function checkShipMethod(item)
{
    strItem = item.toLowerCase();
    var checkAir = strItem.indexOf("air");
  if(item == "UPS Next Day Delivery by 10:30 AM" || item == "UPS Next Day Delivery by 8:30 AM" || strFreigthService == item){
    shipMethodOK = false;
      }else{
    shipMethodOK = true;
  }
}

var newWin;
function openVirtualCatalog(domain, adRef, pageNumber){
  url = "http://" + domain + "/jlindustrial/new_user_entry.asp?AdRef=" + adRef + "&DisplayPageNumber=" + pageNumber;
  newWin = window.open(url,'_virtual');
  setTimeout('newWin.focus();',250);
}
function openVirtualCatalogUK(domain, adRef, pageNumber){
  //url = "/common/NewPage.jsp";
  newWin = window.open(domain,'_virtual');
  setTimeout('newWin.focus();',250);
}
function openVirtualCatalogUK(url){
  newWin = window.open(url,'_virtual');
  setTimeout('newWin.focus();',250);
}
function hazardNotification(message){


      var return_value = confirm(message);
      if ( return_value == true ) {
            return true;
          }else{
               return false;
              }
 }

 function leadNotification(leadMsg){

      var return_value = alert(leadMsg);
      if ( return_value == true ) {
            return true;
          }else{
               return false;
              }
 }


function sureShippingForPromo()
{
    //alert (document.shipping.shippingMethod[document.shipping.shippingMethod.selectedIndex].text) ;
  
    var message1 = "Are you sure you meant to select a premium shipping method?  You will be charged a significantly higher rate for next morning delivery.\n";
    message1 = message1 + "Click \"OK\" to  proceed with your order or \"Cancel\" to choose another shipping method";
    
    var item = document.shipping.shippingMethod[document.shipping.shippingMethod.selectedIndex].text ;
    var itemCode =  document.shipping.shippingMethod[document.shipping.shippingMethod.selectedIndex].value ;
    
    checkShipMethodNew(item) ;
    var message = document.shipping.msg1.value ;
   
    if(shipMethodOK == false )
    {
      var return_value = confirm(message);
      if ( return_value == true ) 
      {
      	 checkAdditionalShipMethod (item) ;	
	 if(shipMethodOK1 == false )
	  {
		var return_value1 = confirm(message1);
		if ( return_value1 == true ) 
		{
			return true;
		}else{
		return false;
		}
	}else{
	return true;
	}
     }else{
        return false;
      }
    }else{
            return true;
    }
    
}



function sureShipping()
{
    //alert (" inside sure shipping ") ;
    //alert (document.shipping.shippingMethod[document.shipping.shippingMethod.selectedIndex].value) ;
    var item = document.shipping.shippingMethod[document.shipping.shippingMethod.selectedIndex].text ;
    var itemCode = document.shipping.shippingMethod[document.shipping.shippingMethod.selectedIndex].value ;
    //alert ("item is "  + item) ;
    checkModifiedShipMethod(itemCode,item) ;
    	
    var message = "Are you sure you meant to select a premium shipping method?  You will be charged a significantly higher rate for next morning delivery.\n";
    message = message + "Click \"OK\" to  proceed with your order or \"Cancel\" to choose another shipping method";

    if(shipMethodOK == false )
    {
      var return_value = confirm(message);
      if ( return_value == true ) 
      {
            return true;
      }else{
        return false;
      }
    }else{
            return true;
    }
    
}


function checkAdditionalShipMethod(item)
{
  if(item == "UPS Next Day Delivery by 10:30 AM" || item == "UPS Next Day Delivery by 8:30 AM")
  {
  	  shipMethodOK1 = false;
      }else{
    shipMethodOK1 = true;
  }
}


function checkModifiedShipMethod(itemCode,item)
{
    strItem = item.toLowerCase();
    var checkAir = strItem.indexOf("air");
  if(item == "UPS Next Day Delivery by 10:30 AM" || item == "UPS Next Day Delivery by 8:30 AM" || strFreigthService == itemCode){
    shipMethodOK = false;
      }else{
    shipMethodOK = true;
  }
}


function checkShipMethodNew(item)
{

if(item == "REGULAR GROUND DELIVERY" || item == "Express Delivery")
{
   	shipMethodOK= true;
      }else
   {
    shipMethodOK = false;
  }
}

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("Please be patient. Your request is being processed.");
  return false;
 }else{
  dblclick=2;
  return true;
 }
}

function resetDblClick(){
 dblclick=1;
}