/*

 Ajax Functions for eLinkCart
 Copyright (c) 1998 - 2010 by TRJ Designs, Inc.
 All rights reserved.
 No part of this script may be used, altered in any way, or distributed
 without the express written consent of the author(s).
 
 10/2007 - Added Sarissa AJax library

 These functions require the Sarissa library

*/


var demoOnly = false;
var blnDisabled = false;
var strResponse = '';

var procType = '';
var itemError = -1;
var lastIndex = -1;
var quickSearch = false;
var strStatus = '';

var totalShippers = 3;
var company  = new Array(totalShippers);
var options = new Array(totalShippers);
var lastModWin;
var blnCheckout=false;
var trackingNumber='';
var shipVia='';

var xmlDoc = new Sarissa.getDomDocument();
var loc = document.URL.toString().toLowerCase();
loc = loc.substring(0,loc.indexOf('customerscripts'));

/* Global Functions */

function IExmlVerify() 
{ 
 // 0 Object is not initialized 
 // 1 Loading object is loading data 
 // 2 Loaded object has loaded data 
 // 3 Data from object can be worked with 
 // 4 Object completely initialized 
 if (xmlDoc.readyState != 4) 
   return false; 
};

function xmlHTTPCall(strPostMsg, blnAsync, blnXML, blnHideIt){

  strResponse = '';
  var xmlhttp = new XMLHttpRequest();
  var currentTime = new Date();

  if ( blnXML && browserVersion != 1)
    xmlhttp.overrideMimeType('text/xml');

  if (strPostMsg.indexOf('?') != -1)
    strPostMsg += '&currenttime=' + currentTime.getTime();
  else
    strPostMsg += '?currenttime=' + currentTime.getTime();

  //if (xmlHTTPCall.arguments.length != 4 && xmlHTTPCall.arguments[4].toString().toLowerCase() == "post" ) {
    xmlhttp.open("POST", strPostMsg, blnAsync);
  //}
  //else {
  //  xmlhttp.open("GET", strPostMsg, blnAsync);
  //}

  // if needed set header information
  // using the setRequestHeader method

  xmlhttp.send(strPostMsg);

  if (blnAsync==true)
    xmlhttp.onreadystatechange=function()
    {
      if(xmlhttp.readyState == 1)
      {

        //Display waiting image and message while content loads.
        //Make sure you have the corect path for the image
        //document.getElementById(elementid).innerHTML = "<p>"+waitmsg+ "</p>" ;

        //Check if it is ready to recieve data
      }
      else if(xmlhttp.readyState==4)
      {
        //Make sure there is something in the content variable
        strResponse = xmlhttp.responseText;
        if ( blnXML && browserVersion != 1 )
          strResponse = xmlhttp.responseXML;
        switch(procType)
        {
          case 'ship':
            processShipReturn(strResponse, blnXML);
            break;
          case 'checkout':
            processAuthReturn(strResponse, true);
            blnHideIt = false;
            break;
          case 'payauth':
            processPaymentAuth(strResponse);
            break;
          case 'findorder':
            findOrderReturn(strResponse);
            break;
          case 'resendorders':
            resendOrdersReturn(strResponse);
            //setTimeout("resendOrdersReturn('" + strResponse + "');",500);
            break;
          case 'deleteorders':
            deleteOrdersReturn(strResponse);
            break;
          case 'deleteitems':
            deleteItemsReturn(strResponse);
            break;
          case 'sitelink':
            siteLinkReturn(strResponse);
            break;
          case 'customerlogins':
            loginsReturn(strResponse);
            break;
          case 'customerprice':
            priceReturn(strResponse);
            break;
          case 'customershipto':
            shiptoReturn(strResponse);
            break;
          case 'orderPeriod':
            dashboardReturn(strResponse);
            break;
          default:
            //nothing yet
            break;
        };


        if ( blnHideIt ){
          hidePopWin(false);
        }
        
        document.body.style.cursor='default';
        blnDisabled = false;
        procType = '';

      }
    };
  else {
    strResponse = xmlhttp.responseText;
    if ( blnXML && browserVersion != 1 )
      strResponse = xmlhttp.responseXML;
  }
  return strResponse;
  
}
    
function doReturn() {

  try {
    var strType = document.getElementById('returnType').value;

    document.getElementById('returnApproval').innerHTML = '';
    document.getElementById('returnApproval').style.display = 'none';
    document.getElementById('returnStatus').innerHTML = '';
    document.getElementById('returnStatus').style.display = 'none';
    document.getElementById('returnMessage').style.display = 'none';
    document.getElementById('returnMessage').innerHTML = '';
    document.getElementById('returnType').value = 'approved';
    document.getElementById('returnForm').style.display = 'none';
    document.getElementById('entryForm').style.display = '';
    document.getElementById('btnSubmit').disabled = false;
    document.getElementById('btnReset').disabled = false;
    return true;
  }
  catch (e) { }
  
  return false;
}

function stopEntry(e){
  try {
    if (!msie){
      e.stopPropagation();
      self.blur();
    }
    else
    {
      window.event.returnValue = false;
      self.blur();
    }
  }
  catch (e) {
    //TODO
  }
  
  return false;
}

function ieStopEntry(){
  try {
    if (!msie || !blnDisabled){return true;}

    window.event.returnValue = false;
    self.blur();
  }
  catch (e) {
    //TODO
  }
  
  return false;

}

/* Login functions */

function doLogin(strFunction){

  var strResponse = '';
  var strTemp = '';
  var strUser = document.getElementById('txtUserName').value;
  var strPassword = document.getElementById('txtPassword').value;
  var argCount = doLogin.arguments.length;

  if ( !IsBlank(strUser) && !IsBlank(strPassword) )
  {
    document.body.style.cursor="wait";
    var showTimer = setTimeout("showPopWin('','<DIV id=\"modalContent\" style=\"margin-top:25px;\"><TABLE align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"200px\"><TR><TD id=\"loadingMsg\"align=\"center\"><span style=\"font-size:10pt;font-weight:bold;\">Retrieving Login Information.<br>Please Wait...</span></TD></TR></TABLE></DIV>',325,100,refreshCurrentPage);", 100);
    var hideTimer = setTimeout("hidePopWin(true);", 500);

    blnDisabled = true;
    var loc = document.URL.toString().toLowerCase();
    loc = loc.substring(0,loc.indexOf('customerscripts'));
    //loc=loc.replace('http:','https:');
    //if (browserVersion==1) {
    //  strResponse = xmlHTTPCall(loc+'Includes/ajaxFunctions.aspx?type=login&user=' + strUser + '&pwd=' + strPassword, false,false,false);
    //}
    //else
    strResponse = xmlHTTPCall('../Includes/ajaxFunctions.aspx?type=login&user=' + strUser + '&pwd=' + strPassword, false,false,false);

    var aryResponse = strResponse.split('|',20);
    try {
      if ( aryResponse[0] == 'true' ) {
        if ( aryResponse.length > 1 && Trim(aryResponse[1].toLowerCase()) == 'admin' ) {
          location.replace('../CustomerScripts/page.aspx?page=admin');
          return false;
        }
        else {
          try {
            if (document.getElementById('loginTable')!=null)
              document.getElementById('loginTable').style.display='none';
          }
          catch (e) { }
          
          try {
            document.getElementById('loginBox').style.display = 'none';
            if (document.getElementById('loginError') != null) {
              document.getElementById('loginError').innerHTML = '';
              document.getElementById('loginError').style.display = 'none';
              if (document.getElementById('loginErrorText') != null) {
                document.getElementById('loginErrorText').style.display = 'none'; 
              }
            }
          }
          catch (e) { }

          if ( strFunction == 'checkout'){
            document.getElementById('billingFirstName').value = aryResponse[2];
            document.getElementById('billingInitial').value = aryResponse[3];
            document.getElementById('billingLastName').value = aryResponse[4];
            document.getElementById('billingAddress1').value = aryResponse[5];
            document.getElementById('billingAddress2').value = aryResponse[6];
            document.getElementById('billingCity').value = aryResponse[7];

            SetSelectValue('cboBillingState',aryResponse[8]);

            document.getElementById('billingZip').value = aryResponse[9];
            document.getElementById('billingPhone').value = aryResponse[10];
            document.getElementById('billingEmail').value = aryResponse[11];
            blnDisabled = false;
            window.location.reload();
            return false;
          }
          else if ( strFunction == 'custom' ) {
            blnDisabled = false;
            if ( argCount > 1 ) 
              window.location.replace(doLogin.arguments[1].toString());
            else
              window.location.reload();
            return false;
          }
          else {
            document.body.style.cursor='default';
            blnDisabled = false;
            if (document.URL.toString().toLowerCase().indexOf('login')!=-1)
              window.location.replace('../CustomerScripts/page.aspx?type=defaultbrowse');
            else
              window.location.reload();
            return false;
          }
        }
      }
      else {
        try {
          if (document.getElementById('loginError') != null) {
            if ( aryResponse[1]+'' == 'undefined' || aryResponse[1] == '' || aryResponse[1] == null ) {
              document.getElementById('loginErrorText').innerHTML = 'Unable to Login. Please try again.';
            }
            else {
              document.getElementById('loginErrorText').innerHTML = aryResponse[1];
            }
            clearTimeout(hideTimer);
            document.getElementById('loginErrorText').style.display = '';
            document.getElementById('loginError').style.display = '';
          }
        }
        catch (e) { 
          document.body.style.cursor='default';
          blnDisabled = false;
        }
      }
    }
    catch (e) { 
      //TODO
    }

  }
  
  document.body.style.cursor='default';
  blnDisabled = false;
  //if (gPopupIsShown)
    setTimeout("hidePopWin(false);",150);

  return false;
}

function doUpdateQty() {

  var itemCount = -1;
  var item;
  var price;
  var ext;
  var subTotal = 0;
  var shipping = 0;
  var tax = 0;
  var total = 0;
  
  var itemElements;
  var qtyElements;
  var priceElements;
  var extElements;
  
  itemElements = getElementsByName('span','itemNumber');
  qtyElements = getElementsByName('input','itemQty');
  priceElements = getElementsByName('div','itemPrice');
  extElements = getElementsByName('div','itemExt');

  try {
  
    if (itemElements.length > 0) {
      for (var i=0;i<itemElements.length;i++) {
        item = itemElements[i].innerHTML;
        price = stripCharsNotInBag(priceElements[i].innerHTML,'0123456789.') * 1;
        qty = stripCharsNotInBag(qtyElements[i].value,'0123456789.') * 1;
        ext = stripCharsNotInBag(extElements[i].innerHTML,'0123456789.') * 1;
        
        subTotal = subTotal + (qty * price);
        
        //Do we need to update this one?
        if ( (price * qty) != ext ) {
          addToCart(item, 0, qty, false);
          ext = formatDollar(price * qty, true);
          extElements[i].innerHTML = ext + '&nbsp;';
        }
      }

      // Update the Totals
      shipping = stripCharsNotInBag(document.getElementById('cartShipping').value,'0123456789.') * 1;
      tax = stripCharsNotInBag(document.getElementById('cartTax').value,'0123456789.') * 1;
      total = subTotal + shipping + tax;
      document.getElementById('cartSubTotalRvw').value = formatDollar(subTotal, true);
      document.getElementById('cartTotal').value = formatDollar(total, true);
    }
  }
  catch (e) {
    //TODO
  }
  
}

function updateCart(strItem, intQty) {

  updateCart = addToCart(strItem, 0, intQty);

}

function addToCart(strItem, price, intQty, uom) {

  var updateCartTotals = true;
  var argCount = addToCart.arguments.length;

  if (allowOrder==0) {
    showPopWin('','<DIV id="modalContent" style="margin-top:25px;"><TABLE align="center" border="0" cellpadding="0" cellspacing="0" width="200px"><TR><TD id="loadingMsg"align="center"><span style="font-size:10pt;font-weight:bold;">Ordering functions for this login have been disabled.<br>Please see your administrator.</span></TD></TR></TABLE></DIV>',250,125,null);
    return false;
  }
    
  if ( argCount > 3 )
    updateCartTotals = false;

  try { 
    if ( !IsBlank(strItem) && !IsBlank(intQty) && allowOrders == 1 )
    {

      strResponse = xmlHTTPCall('../Includes/ajaxFunctions.aspx?type=addtocart&item=' + strItem + '&prc=' + price + '&qty=' + intQty + '&uom=' + uom, false, false, false);
      var aryResponse = strResponse.split('|', 20);

      if ( aryResponse[0] == 'true' ) {
        if ( aryResponse[1] == 0 ){
          if ( updateCartTotals == true) {
            location.replace('../CustomerScripts/page.aspx?page=index');
          }
        }
        else {
          document.getElementById('cartQty').innerHTML = aryResponse[1];
          document.getElementById('cartSubTotal').innerHTML = formatDollar(aryResponse[2],true);
          if ( updateCartTotals == true )
            document.getElementById('viewCartDiv').style.display = '';
        }
      }
      else {

        if (aryResponse[1] == 'overlimit') {
          showPopWin('','<DIV id="modalContent" style="margin-top:25px;"><TABLE align="center" border="0" cellpadding="0" cellspacing="0" width="200px"><TR><TD id="loadingMsg"align="center"><span style="font-size:10pt;font-weight:bold;">Adding this item would put you over your Order Limit.</span></TD></TR></TABLE></DIV>',250,100,null);    
        }

      }

      //document.body.style.cursor='default';
      blnDisabled = false;

      if ( intQty == 0 )
        location.reload();
    }
  }
  catch (e) {   }
  
  return false;
  
}

function doShipping(strShipper, blnEst, blnTax, checkout, modWin){

  var strAddr1 = '';
  var strCity = '';
  var strState = '';
  var strZip = '';
  blnCheckout=checkout;
 
  if ( applyShipping == 1 ) {
  
    try {

      if (document.getElementById('shipToZipCode') != null)
        strZip = document.getElementById('shipToZipCode').value;

      if (document.getElementById('shipToAddress1') != null)
        strAddr1 = document.getElementById('shipToAddress1').value;

      if (document.getElementById('shipToCity') != null)
        strCity = document.getElementById('shipToCity').value;

      if (GetSelectValue(document.getElementById('cboShipToState')) != null )
        strState = GetSelectValue(document.getElementById('cboShipToState'));

      if ( ((strZip != '' && strCity != '' && strState != '' && blnCheckout == 1) || blnCheckout == 0) && shippers != '') {
        if (modWin+'' != 'undefined' && modWin != null && modWin != ''){
          lastModWin=modWin;
          showPopWin('', modWin, 250, 110, null);
        }
        var timer=setTimeout("doShippingFunc('" + strShipper + "'," + blnEst + "," + blnTax + "," + checkout + ");",300);
      }
    }
    catch (e) { }
  }
  else {
  

    //Calc Sales Tax   
    setTimeout("salesTax('" + cart + "');",300);

  }
  
}

function doShippingFunc(strShipper, blnEst, blnTax, checkout){

  var strResponse;
  var strTemp = '';
  var dblShipping = 0;
  var lngWeight  = 0;
  var strAddr1 = '';
  var strAddr2 = '';
  var strCity = '';
  var strState = '';
  var strZip = '';
  var strOpts = '';
  var strCompany = '';
  var strRateType = '';
  var dblRate = 0;
  var blnPopUp = true;
  var blnAsync = false;
  
  if ( applyShipping == 1) {
    try {
  //    if (modWin+'' != 'undefined' && modWin != null && modWin != '' && blnAsync){
  //      showPopWin('', modWin, 250, 110, null);
  //      blnPopUp == true;
  //    }

      if (document.getElementById('cartWeight') != null) {
        lngWeight = document.getElementById('cartWeight').innerHTML;
        lngWeight = stripCharsNotInBag(lngWeight,'0123456789.');
      }

      if (document.getElementById('shipToZipCode') != null)
        strZip = document.getElementById('shipToZipCode').value;

      if (document.getElementById('shipToAddress1') != null)
        strAddr1 = document.getElementById('shipToAddress1').value;

      if (document.getElementById('shipToAddress2') != null)
        strAddr2 = document.getElementById('shipToAddress2').value;

      if (document.getElementById('shipToCity') != null)
        strCity = document.getElementById('shipToCity').value;

      if (GetSelectValue(document.getElementById('cboShipToState')) != null )
        strState = GetSelectValue(document.getElementById('cboShipToState'));

      if ( !IsBlank(lngWeight) && lngWeight != 0 && strZip != '') {
        
        //document.body.style.cursor='wait';

        if (strShipper == '')
          strShipper = shippers;

        strOpts = '&shipper=' + strShipper + '&weight=' + lngWeight + '&addr1=' + strAddr1  + '&addr2=' + strAddr2 ;
        strOpts = strOpts + '&city=' + strCity + '&st=' + strState  + '&zip=' + strZip + '&est=' + blnEst + '&tax=' + blnTax + '&xml=' + blnCheckout;

        blnDisabled = true;
        if (validateShipAddress == '1' && shippers.indexOf('U')!=-1){
          setTimeout("validateAddress('"+strOpts+"');",300);
        }
        else
          setTimeout("continueShipping('"+strOpts+"');",300);

      }
      else {
        document.body.style.cursor='default';
        hidePopWin(false);

        //Calc Sales Tax   
        setTimeout("salesTax('" + cart + "');",300);
      }

    }
    catch (e) {

      document.body.style.cursor='default';
      hidePopWin(false);
    }
  }

  //Calc Sales Tax   
  //setTimeout("salesTax('" + cart + "');",300);

  return false;
  
}

function validateAddress(strOpts){

  var strResponse;
  var strTemp = '';
  var blnPopUp = true;
  var blnAsync = false;

  try {
    procType = '';
    var loc = document.URL.toString().toLowerCase();
    loc = loc.substring(0,loc.indexOf('customerscripts'));
    strResponse = xmlHTTPCall(loc+'Includes/ajaxFunctions.aspx?type=validateaddress' + strOpts, false, false, false);

    var aryResponse = strResponse.split('||',20);
    if (aryResponse[0]=='true'){
      if (aryResponse[1].toString().toLowerCase()=='select' && aryResponse[2]!='') {        
        hidePopWin(false);
        setTimeout('getShipAddress(\''+aryResponse[2]+'\',\''+strOpts+'\');',200);
      }
      else{
        continueShipping(strOpts);
      }
    }
    else
      continueShipping(strOpts);
  }
  catch(e){
    //No Error Here, use the address as entered
    document.body.style.cursor='default';
    continueShipping(strOpts);
  }
}

function getShipAddress(val,strOpts){

  lastOpts=strOpts;
  try{
    resetPopWin(460,405);
    var loc = document.URL.toString().toLowerCase();
    loc = loc.substring(0,loc.indexOf('customerscripts'));
    showPopWin(loc+'Includes/ajaxFunctions.aspx?t=addressvalidation&c='+Url.encode(val),'',460,405,shipAddressReturn);
  }
  catch(e){
    //TODO
  }
  
  return true;
  
}

function changeStatus(val){
  strStatus=val;
}

function shipAddressReturn(val){

  try {
    if (strStatus=='back')
      return false;
    else{

      try{

        strZip = document.getElementById('shipToZipCode').value;
        strCity = document.getElementById('shipToCity').value;
        strState = GetSelectValue(document.getElementById('cboShipToState'));

      }
      catch(e){ }
    }
  }
  catch(e){ }
  
  if (gPopupIsShown)
    hidePopWin(false);
    
  if (gPopupIsShown==false){
    resetPopWin(250,110);
    setTimeout('showNewWin("", lastModWin, 250, 110, null);',10);
  }

  setTimeout("continueShipping('"+lastOpts+"');",400);

}

function continueShipping(strOpts){

  var strResponse;
  var strTemp = '';
  var blnPopUp = true;
  var blnAsync = false;
  
  try {

    //Shipping Company, Weight, ShipToAddr1, ShipToAddr2, ShipToCity, ShipToState, ShipToZip
    var loc = document.URL.toString().toLowerCase();
    loc = loc.substring(0,loc.indexOf('customerscripts'));
    procType = 'ship';
    strResponse = xmlHTTPCall(loc+'Includes/ajaxFunctions.aspx?type=shipping' + strOpts, blnAsync, blnCheckout, true);

    if ( !blnAsync ) {

      processShipReturn(strResponse, blnCheckout);
      procType = '';
      document.body.style.cursor='default';
      hidePopWin(false);
    }
    
  }
  catch(e){
    document.body.style.cursor='default';
    hidePopWin(false);
  }


  document.body.style.cursor='default';
  hidePopWin(false);

  //Calc Sales Tax   
  setTimeout("salesTax('" + cart + "');",300);

  return false;
}

function processShipReturn(strResponse, blnCheckout){

  var strTemp = '';
  var dblShipping = 0;
  var lngWeight  = 0;
  var strCompany = '';
  var dblRate = 0;

  try {
    if ( !blnCheckout )
      var aryResponse = strResponse.split('|',20);
    else
      var aryResponse = new Array(10);

    if ( aryResponse[0] == 'true' || ( blnCheckout == 1 && !IsBlank(strResponse)) ) {

      if ( blnCheckout != 1) {
        updateShipping(aryResponse[1]);
      }
      else {

        if (browserVersion == 1 ){
          //aryResponse = strResponse.split('|',20);
          var xmlDoc = new Sarissa.getDomDocument();
          xmlDoc.async = false;
          xmlDoc.onreadystatechange=IExmlVerify;
          xmlDoc.loadXML(strResponse);
          var root = xmlDoc.documentElement;
        }
        else{
          var oDomDoc = strResponse;
          var root = oDomDoc.getElementsByTagName('Rates').item(0);
        }     
        // Build the HTML for Shipping Tables

        var rateCnt = 0;
        var companyCnt = 0;
        var strChecked = '';

        for (var d = 0; d < 20; d++){
            options[d] = new Array(40);
        }

        for (var iNode = 0; iNode < root.childNodes.length; iNode++) {
          var node = root.childNodes.item(iNode);
          if (node.childNodes.length > 0) {
            strCompany = node.getAttribute("ID");
            company[companyCnt] = strCompany;
            rateCnt = 0;
            for (var i = 0; i < node.childNodes.length; i++) {
              var sibl = node.childNodes.item(i);
              var len = parseInt(sibl.childNodes.length / 2);
              for (x = 0; x < sibl.childNodes.length; x++) {
                var sibl2 = sibl.childNodes.item(x);
                var sibl3;
                if (sibl2.childNodes.length > 0) {
                  sibl3 = sibl2.childNodes.item(0);
                  options[companyCnt][rateCnt] = sibl3.data;
                  rateCnt++;
                }
              }
            }

            if ( strCompany != '' )
              companyCnt++;
          }
        };


        //always gets one too many in the loop?????       
        //companyCnt = companyCnt - 1;
        if ( companyCnt != 0){

          // First build the Shippers Table
          var s='<table class="visible" border="0" cellpadding="0" cellspacing="0" width="97%">';
          s+='<tr>';

          for (var i = 0; i < companyCnt; i++) {
            if (i == 0){
              strChecked='checked';
            }
            else{
              strChecked = '';
            }
            s+='<td class="reviewFont"><input id="company' + i + '" name="shipper" onclick="buildRates(this.value);" style="border: 0pt none ;" value="' + i + '" type="radio" class="checkoutRadio" ' + strChecked + '><span id="shipper' + i + '">' + company[i] + '</span></td>';
            s+='</tr>';
          }

          s+='<tr class="reviewFont">';
          s+='<td class="reviewFont">&nbsp;</td>';
          s+='</tr>';
          s+='<tr class="reviewFont">';
          s+='<td class="reviewFont">&nbsp;* Available Shippers</td>';
          s+='</tr>';
          s+='</table>';

          if (document.getElementById('shippers') ) {
            document.getElementById('shippers').innerHTML = s;
          }

          s = null;
          // First build the Shippers Table


          var t = buildRates(0);

        }

      }
    }
    else {

        // Displaying shipping error msg

    }

  }
  catch (e) {
    //TODO
  }
  
  document.body.style.cursor='default';
  blnDisabled = false;


  return true;
}

function buildRates(intCompany, objID){

  var strChecked = '';
  var intMod = 0;
  var lowest = 0;
  var lowCheck = 999999999;
  var test;

  try {
    intCompany = stripCharsNotInBag(Trim(intCompany),'0123456789.');
    intCompany = intCompany * 1; // Back to a number
    setShippingMessages(company[intCompany]);
    var s = '<table bgcolor="#FFFFFF" class="visible" border="0" cellpadding="0" cellspacing="0" width="100%">';
    s+='<tr>';

    for (var z = 0; z < 10; z++) {


      if (z == 0){
        strChecked = ''; //'checked';
      }
      else{
        strChecked = '';
      }

      intMod = z % 2;
      if ( options[intCompany][z]+'' != '' && options[intCompany][z]+'' != 'undefined'  && options[intCompany][z] != null ){
        if (intMod != 0){
          s+='<td id="rateAmttd' + z + '" class="priceBold" align="right"><span id="rateAmt' + z + '" style="margin-right:5px;">' + formatDollar(stripCharsNotInBag(Trim(options[intCompany][z]),'0123456789.'),true) + '</span></td>';
          s+='</tr>';
          s+='<tr>';

          test = stripCharsNotInBag(options[intCompany][z],'0123456789.');
          test = test * 1; // Convert to a number
          if (test < lowCheck ){
            lowCheck = test;
            lowest = z - 1;
          }
        }
        else{
          s+='<td class="reviewFont"><input id="rate' + z + '" name="rate" onclick="var amt=document.getElementById(\'rateAmt' + (z + 1) + '\').innerHTML;updateShipping(amt);" style="border: 0pt none ;" ' + strChecked + ' type="radio" class="checkoutRadio" >' + changeCase(options[intCompany][z]) + '</td>';
        }
      }
    }

    s+='<tr class="reviewFont">';
    s+='<td class="reviewFont">&nbsp;</td>';
    s+='</tr>';
    s+='<tr class="reviewFont">';
    s+='<td class="reviewFont">&nbsp;* Available Rates</td>';
    s+='</tr>';
    s+='</table>';

    document.getElementById('shipRates').innerHTML = s;
    document.getElementById('rate'+lowest).checked = true;

    updateShipping(lowCheck); 
    
  }
  catch (e) {
    //TODO
  }
  
  return true;

}

function setShippingMessages(companyID) {

//var uspsCopyright = "All Information provided by U.S.P.S.&reg;"
//var fedexCopyright = "All Information provided by FedEx Corp&reg;. FedEx&reg; Logo and FedEx&reg; are registered trademarks of FedEx Corporation"
  try {
    
    switch (companyID.toString().toLowerCase()) {
      case 'usps':
          document.getElementById('shipImg').src = '../Images/uspsLogo.jpg';
          document.getElementById('shipTMText').innerHTML = 'All Information provided by U.S.P.S.&reg;';
          document.getElementById('shipMsg').innerHTML = '';
          document.getElementById('shipMsgDiv').style.display = 'none';
          document.getElementById('shipAddrMsg').innerHTML = '';
        break;
        
      case 'ups':
          document.getElementById('shipImg').src = '../Images/ups_logo_md.gif';
          document.getElementById('shipTMText').innerHTML = 'UPS, The UPS Shield Trademark, the UPS Ready Mark, the UPS Online Tools Mark and the Color Brown are trademarks of United Parcel Service of America, Inc. All Rights Reserved.';
          document.getElementById('shipMsg').innerHTML = 'NOTICE: These fees do not necessarily represent UPS published rates and may include charges levied by ' + companyName;
          document.getElementById('shipMsgDiv').style.display = '';
          document.getElementById('shipAddrMsg').innerHTML = '<br>NOTICE: The address validation functionality will validate P.O. Box addresses; however, UPS does not deliver to P.O. boxes. Attempts by customer to ship tp a P.O. Box via UPS may result in additional charges.';
        break;
        
      case 'fedex':
          document.getElementById('shipImg').src = '../Images/fedex_corp_logo.gif';
          document.getElementById('shipTMText').innerHTML = 'All Information provided by FedEx Corp&reg;. FedEx&reg; Logo and FedEx&reg; are registered trademarks of FedEx Corporation';
          document.getElementById('shipMsg').innerHTML = '';
          document.getElementById('shipMsgDiv').style.display = 'none';
          document.getElementById('shipAddrMsg').innerHTML = '';
        break;
        
        
      default:
          document.getElementById('shipImg').src = '../Images/spacer.gif';
          document.getElementById('shipTMText').innerHTML = '';
          document.getElementById('shipMsg').innerHTML = '';
          document.getElementById('shipMsgDiv').style.display = 'none';
          document.getElementById('shipAddrMsg').innerHTML = '';
        break;
    
    }
    
  }
  catch (e) {
    // No Error
  }
    
}

function updateShipping(dblVar){

  var dblTotal = 0;
  var dblHandling = 0;
  var dblTax = 0;
  var dblTemp = 0;
  var dblShipping = 0;
  var review = 0;

  try { 
    if (document.getElementById('cartSubTotalRvw')) {
      dblTotal = stripCharsNotInBag(document.getElementById('cartSubTotalRvw').value,'0123456789.');
      review = 1;
    }
    else if (document.getElementById('cartSubTotal')) {
      dblTotal = stripCharsNotInBag(document.getElementById('cartSubTotal').value,'0123456789.');
    }
    dblHandling = stripCharsNotInBag(document.getElementById('cartHandling').value,'0123456789.');
    dblTax = stripCharsNotInBag(document.getElementById('cartTax').value,'0123456789.');

    dblTotal = dblTotal * 1; // Convert to a number
    dblHandling = dblHandling * 1;
    dblTax = dblTax * 1;

    dblTemp = stripCharsNotInBag(Trim(dblVar),'0123456789.');
    if (dblVar+""=="")
      dblVar = "0";
    dblShipping = dblTemp * 1; // Convert back to a number

    dblTotal = dblTotal + dblShipping + dblHandling + dblTax;
    if ( review == 1) {
      dblShipping = dblShipping + dblHandling;
    }
    document.getElementById('cartShipping').value = formatDollar(dblShipping,true);
    document.getElementById('cartTotal').value = formatDollar(dblTotal,true);

  }
  catch (e) {
    //TODO
  }
  
}

function loadItemDetail(strItem) {

  //var itemPopUp = true;
  
  try {
    
    if ( !IsBlank(strItem))
    {
      
      if (itemPopUp == true ) {
        /* Do not let them off the PopUp Window */
        strResponse = xmlHTTPCall('../Includes/ajaxFunctions.aspx?type=itemdetail&item=' + strItem, false, false, false);

        var aryResponse = strResponse.split('|',20);

        if ( aryResponse[0] == 'true' ) {
          showPopWin('', aryResponse[1], 700, 550, null);
        }

      }
      else {
        location.replace('../CustomerScripts/page.aspx?page=itemdetail&item=' + strItem);
      }
    }

  }
  catch (e) {
    //TODO
  }
  
  document.body.style.cursor='default';
  blnDisabled = false;
  
  return false;
  
}

function displayOrder(order) {

  try {
    if ( !IsBlank(order))
    {

      /* Do not let them off the PopUp Window */
      strResponse = xmlHTTPCall('../Includes/ajaxFunctions.aspx?type=displayorder&order=' + order, false, false, false);

      var aryResponse = strResponse.split('|',20);

      if ( aryResponse[0].toString().toLowerCase() == 'true' ) {
        showPopWin(aryResponse[1],'', 700, 575, releaseCursor);
      }

    }

  }
  catch (e) {
    //TODO
  }
  
  document.body.style.cursor='default';
  blnDisabled = false;
  
  return false;
  
}

function releaseCursor() {
  document.body.style.cursor='default';
  blnDisabled = false;
}

function addOrderToCart(order) {

  try {
    
    if ( !IsBlank(order))
    {

      strResponse = xmlHTTPCall('../Includes/ajaxFunctions.aspx?type=addOrder&order=' + order, false, false, false);

      var aryResponse = strResponse.split('|',10);

      if ( aryResponse[0].toString().toLowerCase() == 'true'  || (aryResponse[1] != '0' || aryResponse[1] == '' )) {
        try {
          document.getElementById('cartQty').innerHTML = aryResponse[1];
          try {
            document.getElementById('cartAmount').innerHTML = formatDollar(aryResponse[2],true);
          }
          catch (e) { }
          
          try {
            document.getElementById('cartSubTotal').innerHTML = formatDollar(aryResponse[2],true);
          }
          catch (e) { }
          
          try {
            document.getElementById('viewCartDiv').style.display = '';
            document.getElementById('saveCartDiv').style.display = '';
          }
          catch (e) { }
        }
        catch (e) {
          //Stop the errors
        }
        showPopWin('',aryResponse[3], 250, 110, null);
      }

    }

  }
  catch (e) {
    //TODO
  }
  
  //document.body.style.cursor='default';
  blnDisabled = false;
  
  return false;
  
}

function displayInvoice(invoice) {

  try {
    
    if ( !IsBlank(invoice))
    {

      strResponse = xmlHTTPCall('../Includes/ajaxFunctions.aspx?type=displayinvoice&invoice=' + invoice, false, false, false);
      var aryResponse = strResponse.split('|',20);

      if ( aryResponse[0].toString().toLowerCase() == 'true' ) {
        showPopWin(aryResponse[1],'', 700, 575, null);
      }
      else {

        // What Here ?

      }

    }

  }
  catch (e) {
    //TODO
  }
  
  //document.body.style.cursor='default';
  blnDisabled = false;
  
  return false;
  
}

function displayHistoryInvoice(invoice) {

  try {
    
    if ( !IsBlank(invoice))
    {

      var strOpts;
      var strResponse;
      
      try {
        strOpts = '&i=' + invoice;
        strResponse = xmlHTTPCall(loc+'Includes/ajaxFunctions.aspx?type=displayHistoryInvoice' + strOpts, false, false, false);

        var aryResponse = strResponse.split('|',20);
        if ( aryResponse[0].toString().toLowerCase() == 'true' ) {
          showPopWin(aryResponse[1],'', 700, 575, null);
        }
      }
      catch (e) { }

    }

  }
  catch (e) {
    //TODO
  }
  
  //document.body.style.cursor='default';
  blnDisabled = false;
  
  return false;
  
}

function displayARStatement(invoice) {

  try {
    
    var strOpts;
    var strResponse;
    try {
      var loc = document.URL.toString().toLowerCase();
      loc = loc.substring(0,loc.indexOf('customerscripts'));
      strResponse = xmlHTTPCall(loc+'Includes/ajaxFunctions.aspx?type=displayARStatement', false, false, false);
      var aryResponse = strResponse.split('|',20);
      if ( aryResponse[0].toString().toLowerCase() == 'true' ) {
        showPopWin(aryResponse[1],'', 700, 575, null);
      }
    }
    catch (e) { }

  }
  catch (e) {
    //TODO
  }
  
  //document.body.style.cursor='default';
  blnDisabled = false;
  
  return false;
  
}

function showCheckoutMessage(strMethod, modWin){

  try {

    //var cart = document.getElementById('cartID').value;

    if (modWin+'' != 'undefined' && modWin != null && modWin != '' ){
      showPopWin('', modWin, 250, 110, null);
    }
    
    setTimeout("createOrder('" + cart.toString() + "', '', '', true);",300);

    /*
    if (fastCheckout==1 || fastCheckout==true) {
      var cart = document.getElementById('cartID').value;
      setTimeout("createOrder(" + cart.toString() + ", '', '', true);",300);
    }
    else
      var timer = setTimeout("processCheckout('"+strMethod+"',true);",300);
      setTimeout("createOrder(" + cart.toString() + ", '', '', true);",300);
    //processCheckout(strMethod,true);
    */
  }
  catch (e) { showPopWin('../Includes/ajaxFunctions.aspx?type=orderproblem', '', 520, 350, null); }
  

}

function processCheckout(strMethod, blnPopup){

  var strOpts = '';
  var blnAsync = false;
  
  procType = 'checkout';

  try {

    switch (strMethod)
    {
      case 'CC' :
        strOpts = '&CCTYPE=' + document.getElementById('ccType').selectedIndex;
        strOpts = strOpts + '&CCNUM=' + document.getElementById('ccNumber').value;
        var strDate = GetSelectValue(document.getElementById('ccExpMonth')) + GetSelectValue(document.getElementById('ccExpYear'));
        strOpts = strOpts + '&EXPDATE=' + strDate;
        try {
          strOpts = strOpts + '&AMOUNT=' + stripCharsNotInBag(Trim(document.getElementById('cartTotal').value),'0123456789.');
        }
        catch (e) {
          strOpts = strOpts + '&AMOUNT=' + stripCharsNotInBag(Trim(document.getElementById('cartTotal').innerHTML),'0123456789.');
        }
        strOpts = strOpts + '&CVV2=' + document.getElementById('ccId').value;

        break;


      case 'CHK' :
      /*
        strOpts = '';
        ind = document.getElementById('x_bank_acct_type').selectedIndex;
        strOpts = '&ACCTTYPE=' + document.getElementById('x_bank_acct_type').options[ind].text;
        strOpts = strOpts + '&ABA=' + document.getElementById('x_bank_aba_code').value;
        strOpts = strOpts + '&ACCTNUM=' + document.getElementById('x_bank_acct_num').value;
        strOpts = strOpts + '&BANKNAME=' + document.getElementById('x_bank_name').value;
        strOpts = strOpts + '&ACCTNAME=' + document.getElementById('x_bank_acct_name').value;
        strOpts = strOpts + '&AMOUNT=' + document.getElementById('x_amount_1').value;

        */  
        break;

      case 'PO':
        //No Processing required
        break;
        
      default :
        hidePopWin(false);
        return false;

    };


    strOpts = strOpts + '&CUSTID=' + customerNumber;
    strOpts = strOpts + '&COMPANY=' + document.getElementById('billingCompany').value;
    strOpts = strOpts + '&FNAME=' + document.getElementById('billingFirstName').value;
    strOpts = strOpts + '&LNAME=' + document.getElementById('billingLastName').value;
    strOpts = strOpts + '&ADDR=' + document.getElementById('billingAddress1').value;
    strOpts = strOpts + '&CITY=' + document.getElementById('billingCity').value;
    strOpts = strOpts + '&STATE=' + GetSelectValue(document.getElementById('cboBillingState'));
    strOpts = strOpts + '&ZIP=' + document.getElementById('billingZip').value;
    strOpts = strOpts + '&PHONE=' + document.getElementById('billingPhone').value;
    strOpts = strOpts + '&FAX=';
    strOpts = strOpts + '&EMAIL=' + document.getElementById('billingEmail').value;
    strOpts = strOpts + '&ORDER=' + cart;


    strOpts = '&AUTHTYPE=' + strMethod + strOpts;

    if ( strMethod != 'PO' ) {
      document.body.style.cursor='wait';

      // Now Send the Data
      var loc = document.URL.toString().toLowerCase();
      loc = loc.substring(0,loc.indexOf('customerscripts'));
      strResponse = xmlHTTPCall(loc + 'Includes/ajaxFunctions.aspx?type=payauth' + strOpts, blnAsync, false, false);
    }
    else {
      strResponse = 'true|PO|none|';  
    }
    
    if ( !blnAsync ) {
      processAuthReturn(strResponse, true);
      procType = '';
      blnDisabled = false;
    }

  }
  catch (e) {
    hidePopWin(false);
  }
  
  document.body.style.cursor='default';
  
  return true;
}

function processAuthReturn(strResults, blnPopUp){

  var aryResponse = strResults.split('|',20);
  //var cart = document.getElementById('cartID').value;
  var strOrder = '';
  var strTest = '';

  try {

    if ( aryResponse[0].toString().toLowerCase() != 'true' ){
      if ( blnPopUp ) {
        hidePopWin(false);
      }
      
      showPopWin('../Includes/ajaxFunctions.aspx?type=orderproblem', '', 520, 350, null);

    }
    else{

      strOrder = createOrder(cart, Trim(aryResponse[1]), Trim(aryResponse[2]), true);

    }

  }
  catch (e) {
    //TODO
    hidePopWin(false);
  }
  
  document.body.style.cursor='default';
  return true;
  
}

function createOrder(cart, auth, ccref, blnPopUp){

  var strOpts = '';
  var strLocal = '';
  var shipToNumber = '';
  
  try {

    strOpts = strOpts + '&CART=' + cart;
    strOpts = strOpts + '&BEML=' + document.getElementById('billingEmail').value;
    strOpts = strOpts + '&BPH=' + document.getElementById('billingPhone').value;
    strOpts = strOpts + '&BC=' + document.getElementById('billingCompany').value;
    strOpts = strOpts + '&BNF=' + document.getElementById('billingFirstName').value;
    strOpts = strOpts + '&BNL=' + document.getElementById('billingLastName').value;
    strOpts = strOpts + '&BNI=' + document.getElementById('billingInitial').value;
    strOpts = strOpts + '&BNG=';
    strOpts = strOpts + '&BAD1=' + document.getElementById('billingAddress1').value;
    strOpts = strOpts + '&BAD2=' + document.getElementById('billingAddress2').value;
    strOpts = strOpts + '&BCTY=' + document.getElementById('billingCity').value;
    strOpts = strOpts + '&BST=' + GetSelectValue(document.getElementById('cboBillingState'));
    strOpts = strOpts + '&BZIP=' + document.getElementById('billingZip').value;
    try {
      shipToNumber = GetSelectValue(document.getElementById('shipToCBO'));
    }
    catch (e) {
      try {
        shipToNumber = document.getElementById('shipTo').value;
      }
      catch (e) {
        shipToNumber = '';
      }
    }
    strOpts = strOpts + '&ST=' + shipToNumber;
    strOpts = strOpts + '&STN=' + document.getElementById('shipToName').value;
    strOpts = strOpts + '&STAD1=' + document.getElementById('shipToAddress1').value;
    strOpts = strOpts + '&STAD2=' + document.getElementById('shipToAddress2').value;
    strOpts = strOpts + '&STCTY=' + document.getElementById('shipToCity').value;
    strOpts = strOpts + '&STST=' + GetSelectValue(document.getElementById('cboShipToState'));
    strOpts = strOpts + '&STZIP=' + document.getElementById('shipToZipCode').value;
    strOpts = strOpts + '&STPH=' + document.getElementById('shipToPhone').value;
    strOpts = strOpts + '&STFAX=';
    strOpts = strOpts + '&STEML=' + document.getElementById('billingEmail').value;
    strOpts = strOpts + '&REQDT=';
    strOpts = strOpts + '&CNDT=';
    
    var shipVia = '';
    try {
      shipVia = document.getElementById('shipper'+GetRadioValue(getElementsByName('input','shipper'))).innerHTML;
    }
    catch (e) { };
    strOpts = strOpts + '&SHVIA=' + shipVia;
    strOpts = strOpts + '&SHNT=';
    strOpts = strOpts + '&PO=' + document.getElementById('PONumber').value;

    try {
      strOpts = strOpts + '&FRT=' + stripCharsNotInBag(Trim(document.getElementById('cartShipping').value),'0123456789.');
    }
    catch (e) {
      strOpts = strOpts + '&FRT=' + stripCharsNotInBag(Trim(document.getElementById('cartShipping').innerHTML),'0123456789.');
    }
    try {
      strOpts = strOpts + '&TX=' + stripCharsNotInBag(document.getElementById('cartTax').value,'0123456789.');
    }
    catch (e) {
      strOpts = strOpts + '&TX=' + stripCharsNotInBag(document.getElementById('cartTax').innerHTML,'0123456789.');
    }
    try {
      strOpts = strOpts + '&HND=' + stripCharsNotInBag(document.getElementById('cartHandling').value,'0123456789.');
    }
    catch (e) {
      strOpts = strOpts + '&HND=' + stripCharsNotInBag(document.getElementById('cartHandling').value,'0123456789.');
    }
    strOpts = strOpts + '&CCNUM=' + document.getElementById('ccNumber').value;
    var strDate = GetSelectValue(document.getElementById('ccExpMonth')) + '/01/' + GetSelectValue(document.getElementById('ccExpYear'));
    strOpts = strOpts + '&EXPDATE=' + strDate;
    try {
      strOpts = strOpts + '&AMOUNT=' + stripCharsNotInBag(Trim(document.getElementById('cartTotal').value),'0123456789.');
    }
    catch (e) {
      strOpts = strOpts + '&AMOUNT=' + stripCharsNotInBag(Trim(document.getElementById('cartTotal').innerHTML),'0123456789.');
    }
    
    strOpts = strOpts + '&CVV2=' + document.getElementById('ccId').value;
    strOpts = strOpts + '&ATH=' + auth;
    strOpts = strOpts + '&REF=' + ccref;
    strOpts = strOpts + '&ABA='; // + document.getElementById('x_bank_aba_code').value;
    strOpts = strOpts + '&ACCTNUM='; // + document.getElementById('x_bank_acct_num').value;
    strOpts = strOpts + '&BANKNAME='; // + document.getElementById('x_bank_name').value;
    strOpts = strOpts + '&ACCTNAME='; // + document.getElementById('x_bank_acct_name').value;
    strOpts = strOpts + '&CCTYPE=' + document.getElementById('ccType').selectedIndex;
    strOpts = strOpts + '&PONAME=' + document.getElementById('POName').value;
    strOpts = strOpts + '&STC=' + document.getElementById('shipToFirstName').value + ' ' + document.getElementById('shipToLastName').value;

    var loc = document.URL.toString().toLowerCase();
    loc = loc.substring(0,loc.indexOf('customerscripts'));
//resetPopWin(500,200);
//showPopWin('',loc + 'Includes/ajaxFunctions.aspx?type=createorder' + strOpts,500,200,null);
//return false;
    strResponse = xmlHTTPCall(loc + 'Includes/ajaxFunctions.aspx?type=createorder' + strOpts, false, false, false);
    document.body.style.cursor='default';

    if ( blnPopUp )
      hidePopWin(false);

    var aryResponse = strResponse.split('|',20);
    if ( aryResponse[0].toString().toLowerCase() != 'true' ){
      showPopWin('../Includes/ajaxFunctions.aspx?type=orderproblem', '', 520, 350, null);
    }
    else{
      var orderDoc = '';
      if (aryResponse[2].indexOf('\\')!=-1)
        orderDoc = loc + 'Temp/' + GetFileName(aryResponse[2]);
      else
        orderDoc = aryResponse[2];

      if (orderDoc!='' && orderDoc.toLowerCase().indexOf('error')==-1)
        showPopWin(loc + 'Temp/' + GetFileName(aryResponse[2]), '', 750, 575, redirectHome);
      else
        setTimeout('redirectHome()',200);
    }
  
  }
  catch (e) { hidePopWin(false); }

  document.body.style.cursor='default';

  return true;

}

function doUpdateAccount(comp,cust) {

  var strOpts = '';
  var strLocal = '';
  var newsLetter = '0';

  try {

    strOpts = strOpts + '&co=' + comp;
    strOpts = strOpts + '&cm=' + cust;
    strOpts = strOpts + '&u=' + document.getElementById('txtUserLogin').value;
    strOpts = strOpts + '&op=' + document.getElementById('txtOldPassword').value;
    strOpts = strOpts + '&p=' + document.getElementById('txtNewPassword').value;
    strOpts = strOpts + '&fn=' + document.getElementById('txtBillingNameFirst').value;
    strOpts = strOpts + '&mn=' + document.getElementById('txtBillingNameMI').value;
    strOpts = strOpts + '&ln=' + document.getElementById('txtBillingNameLast').value;
    strOpts = strOpts + '&gn=' + GetSelectValue(document.getElementById('cboBillingNameGen'));
    strOpts = strOpts + '&a1=' + document.getElementById('txtShipToAddr1').value;
    strOpts = strOpts + '&a2=' + document.getElementById('txtShipToAddr2').value;
    strOpts = strOpts + '&c=' + document.getElementById('txtShipToCity').value;
    strOpts = strOpts + '&s=' + GetSelectValue(document.getElementById('cboShipToState'));
    strOpts = strOpts + '&z=' + document.getElementById('txtShipToZip').value;
    strOpts = strOpts + '&e=' + document.getElementById('txtShipToEMail').value;
    strOpts = strOpts + '&pn=' + document.getElementById('txtShipToPhone').value;
    strOpts = strOpts + '&ep=' + document.getElementById('txtEncryptedPassword').value;
    if (doUpdateAccount.arguments.length > 2)
      strOpts = strOpts + '&usertype=' + doUpdateAccount.arguments[2];
    else
      strOpts = strOpts + '&usertype=0';

    try {
    if (document.getElementById('chkNewsLetter').checked)
      newsLetter = '1';
    }
    catch (e) { }
    strOpts = strOpts + '&nl='+newsLetter;

    document.body.style.cursor='wait';

    blnDisabled = true;
    var loc = document.URL.toString().toLowerCase();
    loc = loc.substring(0,loc.indexOf('customerscripts'));
    strResponse = xmlHTTPCall(loc + 'Includes/ajaxFunctions.aspx?type=updateProfile' + strOpts, false,false,false);

    var aryResponse = strResponse.split('|',20);

    if ( aryResponse[0] == 'true' ) {
      if ( doUpdateAccount.arguments.length == 3 ) 
        showPopWin('', aryResponse[1], 250, 110, redirectHome);
      else
        showPopWin('', aryResponse[1], 250, 110, null);
    }
    else {
      showPopWin('', 'Unable to update Profile Information.', 250, 110, null);
    }

  }
  catch (e) {
    //Abort Update
    blnDisabled = false;
    document.body.style.cursor='default';
  }
  finally {
  
    blnDisabled = false;
    document.body.style.cursor='default';
  }
  
}

function getUserInfo(comp,cust) {

  var strOpts = '';
  var strLocal = '';

  try {
  
    var user=cboUsers.getSelectedValue();
    document.body.style.cursor='wait';

    strOpts = strOpts + '&co=' + comp;
    strOpts = strOpts + '&cm=' + cust;
    strOpts = strOpts + '&u=' + user;
    

    blnDisabled = true;
    var loc = document.URL.toString().toLowerCase();
    loc = loc.substring(0,loc.indexOf('customerscripts'));
    strResponse = xmlHTTPCall(loc + 'Includes/ajaxFunctions.aspx?type=getuserinfo' + strOpts, false,false,false);

    var aryResponse = strResponse.split('|',20);
    try {
      if (aryResponse[0].toString().toLowerCase() == 'true') {
        document.getElementById('txtUserEncryptedPassword').value = aryResponse[1];
        document.getElementById('txtUserNameFirst').value = aryResponse[2];
        document.getElementById('txtUserNameMI').value = aryResponse[3];
        document.getElementById('txtUserNameLast').value = aryResponse[4];
        SetSelectValue(document.getElementById('cboUserNameGen'), aryResponse[5]);
        document.getElementById('txtUserAddr1').value = aryResponse[6];
        document.getElementById('txtUserAddr2').value = aryResponse[7];
        document.getElementById('txtUserCity').value = aryResponse[8];
        SetSelectValue(document.getElementById('cboUserState'), aryResponse[9]);
        document.getElementById('txtUserZip').value = aryResponse[10];
        document.getElementById('txtUserEMail').value = aryResponse[11];
        document.getElementById('txtUserPhone').value = aryResponse[12];
        document.getElementById('txtUserOrderLimit').value = formatDollar(aryResponse[13], true); ;
        if (aryResponse[14] == '1')
          document.getElementById('chkUserAllowAR').checked = true;
        else
          document.getElementById('chkUserAllowAR').checked = false;

        if (aryResponse[15] == '1')
          document.getElementById('chkUserAllowOrders').checked = true;
        else
          document.getElementById('chkUserAllowOrders').checked = false;

        if (aryResponse[16] == '1')
          document.getElementById('chkUserNewsLetter').checked = true;
        else
          document.getElementById('chkUserNewsLetter').checked = false;

        document.getElementById('txtUserSalesman').value = aryResponse[17];
        document.getElementById('txtUserSalesRegion').value = aryResponse[18];
      }
      else {
        document.getElementById('txtUserEncryptedPassword').value = '';
        document.getElementById('txtUserNameFirst').value = '';
        document.getElementById('txtUserNameMI').value = '';
        document.getElementById('txtUserNameLast').value = '';
        SetSelectValue(document.getElementById('cboUserNameGen'), '');
        document.getElementById('txtUserAddr1').value = '';
        document.getElementById('txtUserAddr2').value = '';
        document.getElementById('txtUserCity').value = '';
        SetSelectValue(document.getElementById('cboUserState'), '');
        document.getElementById('txtUserZip').value = '';
        document.getElementById('txtUserEMail').value = '';
        document.getElementById('txtUserPhone').value = '';
        document.getElementById('txtUserOrderLimit').value = '0.00';
        document.getElementById('chkUserAllowAR').checked = true;
        document.getElementById('chkUserAllowOrders').checked = true;
        document.getElementById('chkUserNewsLetter').checked = true;
        document.getElementById('txtUserSalesman').value = '';
        document.getElementById('txtUserSalesRegion').value = '';
      }
    }
    catch (e) { }
  
  }
  catch (e) {
    //Abort Update
    document.body.style.cursor='default';
  }
  finally {
  
    blnDisabled = false;
    document.body.style.cursor='default';
  }  

  return false;
}

function doUpdateUserInfo(comp,cust) {

  var strOpts = '';
  var strLocal = '';
  var newsLetter = '0';
  var allowAR = '0';
  var allowOrders = '0';

  try {
  
    if ((document.getElementById('txtUserEncryptedPassword').value=='' && document.getElementById('txtUserNewPassword').value=='') || (document.getElementById('txtUserNewPassword').value!='' && (document.getElementById('txtUserNewPassword').value!=document.getElementById('txtUserNewPasswordTest').value))) {
      showPopWin('','<DIV id="modalContent" style="margin-top:25px;"><TABLE align="center" border="0" cellpadding="0" cellspacing="0" width="200px"><TR><TD id="loadingMsg"align="center"><span style="font-size:10pt;font-weight:bold;">Your password is Invalid or missing. Please re-enter your password.</span></TD></TR></TABLE></DIV>',250,100,null);
      return false;
    }

    var user=cboUsers.getSelectedValue();
    if (user==null) user = cboUsers.getComboText();
    
    strOpts = strOpts + '&co=' + comp;
    strOpts = strOpts + '&cm=' + cust;
    strOpts = strOpts + '&u=' + user;
    strOpts = strOpts + '&op=';
    strOpts = strOpts + '&p=' + document.getElementById('txtUserNewPassword').value;
    strOpts = strOpts + '&fn=' + document.getElementById('txtUserNameFirst').value;
    strOpts = strOpts + '&mn=' + document.getElementById('txtUserNameMI').value;
    strOpts = strOpts + '&ln=' + document.getElementById('txtUserNameLast').value;
    strOpts = strOpts + '&gn=' + GetSelectValue(document.getElementById('cboUserNameGen'));
    strOpts = strOpts + '&a1=' + document.getElementById('txtUserAddr1').value;
    strOpts = strOpts + '&a2=' + document.getElementById('txtUserAddr2').value;
    strOpts = strOpts + '&c=' + document.getElementById('txtUserCity').value;
    strOpts = strOpts + '&s=' + GetSelectValue(document.getElementById('cboUserState'));
    strOpts = strOpts + '&z=' + document.getElementById('txtUserZip').value;
    strOpts = strOpts + '&e=' + document.getElementById('txtUserEMail').value;
    strOpts = strOpts + '&pn=' + document.getElementById('txtUserPhone').value;
    strOpts = strOpts + '&ep=' + document.getElementById('txtUserEncryptedPassword').value;
    strOpts = strOpts + '&usertype=2';
    strOpts = strOpts + '&ol=' + stripCharsInBag(document.getElementById('txtUserOrderLimit').value,'$,');
    if (document.getElementById('chkUserNewsLetter').checked)
      newsLetter = '1';
    strOpts = strOpts + '&nl='+newsLetter;
    if (document.getElementById('chkUserAllowAR').checked)
      allowAR = '1';
    strOpts = strOpts + '&aa=' + allowAR;
    if (document.getElementById('chkUserAllowOrders').checked)
      allowOrders = '1';
    strOpts = strOpts + '&ao=' + allowOrders;
    strOpts = strOpts + '&sm=' + document.getElementById('txtUserSalesman').value;
    strOpts = strOpts + '&sr=' + document.getElementById('txtUserSalesRegion').value;

    document.body.style.cursor='wait';

    blnDisabled = true;
    var loc = document.URL.toString().toLowerCase();
    loc = loc.substring(0,loc.indexOf('customerscripts'));    
    strResponse = xmlHTTPCall(loc + 'Includes/ajaxFunctions.aspx?type=updateuserinfo' + strOpts, false,false,false);

    var aryResponse = strResponse.split('|',20);
    if (aryResponse[0].length > 1)
      showPopWin('', aryResponse[1], 250, 110, null);
    else
      showPopWin('', 'Unable to update User Information.', 250, 110, null);

  }
  catch (e) {
    //Abort Update
    document.body.style.cursor='default';
  }
  finally {
  
    blnDisabled = false;
    document.body.style.cursor='default';
  }  

  return false;

}

function doAddUser(comp,cust) {

  doUpdateUserInfo(comp,cust);
  
}

function findItem(count, type) {

  var allElements;
  var itemSub = 0;
  var itemValue;
  var status = false;

  if (quickSearch == true)
    return false;

  try {
    switch (type) {
      case 0:

        allElements = document.getElementsByName("txtItem");
        itemSub = count * 1;
        itemValue = allElements[itemSub].value;


        if ( !IsBlank(itemValue))
        {
          document.body.style.cursor='wait';

          blnDisabled = true;
          strResponse = xmlHTTPCall('../Includes/ajaxFunctions.aspx?type=itemlookup&item=' + itemValue, false,false,false);

          var aryResponse = strResponse.split('|',20);

          if ( aryResponse[0] == 'true' ) {
          
            switch (Trim(aryResponse[1].toString().toLowerCase()))
            {
              case 'search':
                
                  lastIndex = count;
                  setTimeout("displayQuickSearch('" + itemValue + "');",150);
                  quickSearch = true;
                break;
                
              default:
                itemError = -1;

                allElements = document.getElementsByName("fieldError");
                allElements[itemSub].style.visibility = 'hidden';

                allElements = document.getElementsByName("txtItem");
                allElements[itemSub].value = aryResponse[1];

                //Trim the description to 50 chars max
                var description = aryResponse[3];
                if ( description.length > 50 )
                  description = description.substring(0,49);

                allElements = document.getElementsByName("txtDescription");
                allElements[itemSub].innerHTML = description;

                allElements = document.getElementsByName("txtPrice");
                allElements[itemSub].innerHTML = formatCurrency(aryResponse[6]);

                allElements = document.getElementsByName("txtQty");
                var value = allElements[itemSub].value;
                if ( IsBlank(value) ) {
                  allElements[itemSub].value = '1';
                }

                updateExt(count, 0);

                allElements[itemSub].focus();
              
              break;
            }

          }
          else {
            allElements = document.getElementsByName("fieldError");
            allElements[itemSub].style.visibility = '';

            allElements = document.getElementsByName("txtItem");
            allElements[itemSub].value='';
            allElements[itemSub].focus();
            
            itemError = itemSub;

          }

          document.body.style.cursor='default';
          blnDisabled = false;

          return false;

        }
        else {
            //allElements = document.getElementsByName("txtItem");
            //allElements[itemSub].focus();
            return false;
        }

        break;
    }
  }
  catch (e) {
    //TODO
  }
  
  return false;
  
}

function updateExt(count, type) {

  var allElements;
  var itemValue;
  var itemSub;
  var itemPrice;
  var itemQty;

  try {
    switch (type) {
      case 0:
        
        itemSub = count * 1;
        allElements = document.getElementsByName("txtItem");
        itemValue = allElements[itemSub].value;
        
        if ( !IsBlank(itemValue) ) {
          allElements = document.getElementsByName("txtPrice");
          itemPrice = stripCharsInBag(allElements[itemSub].innerHTML,'$, ') * 1;

          allElements = document.getElementsByName("txtQty");
          itemQty = stripCharsInBag(allElements[itemSub].value,'$, ') * 1;
          
          if (!IsInt(itemQty) && !IsBlank(itemQty) ) {
            allElements[itemSub].value = '1';
            itemQty = 1;
          }
          
          var itemExt = itemPrice * itemQty;
          allElements = document.getElementsByName("txtExtPrice");
          allElements[itemSub].innerHTML = formatCurrency(itemExt);
          
        }

        break;
    }
  }
  catch (e) {
    //TODO
  }
}

function findFocus(count, type) {

  var itemValue = '';
  var allElements;
  var itemSub = -1;
  var itemTest = count * 1;
  
  try {
    allElements = document.getElementsByName("txtItem");

    if ( itemError != -1 ) {
      allElements[itemError].focus();
    }
    else {

      switch (type)
      {
        case 0:
          allElements = document.getElementsByName("txtItem");
          for (var i=allElements.length - 1; i >= 0; i--) {
            itemValue = allElements[i].value;
            if ( !IsBlank(itemValue) && itemSub == -1 )
              itemSub = i+1;
          }

          if ( itemSub != -1 ) {
            allElements[itemSub].focus();
          }
          else {
            allElements = document.getElementsByName("txtItem");
            allElements[0].focus();
          }
          break;

        case 1:
          allElements = document.getElementsByName("txtQty");
          if ( allElements[itemTest].value != '' ) {
            allElements[itemTest].focus();
          }
          else {
            for (var i=allElements.length - 1; i >= 0; i--) {
              itemValue = allElements[i].value;
              if ( !IsBlank(itemValue) && itemSub == -1 )
                itemSub = i;
            }
            
            if ( itemSub != -1 ) {
              allElements[itemSub].focus();
            }
            else {
              allElements = document.getElementsByName("txtItem");
              allElements[0].focus();
            }
          }
          break;
      }
    }
  }
  catch (e) {
    //TODO
  }
  
}

function addQuickCart() {

  var itemElements;
  var qtyElements;
  var itemValue;
  var itemSub;
  var itemPrice;
  var itemQty;

  try {
    itemElements = document.getElementsByName("txtItem");
    qtyElements = document.getElementsByName("txtQty");
    for (var i=0; i < itemElements.length; i++) {
      itemValue = itemElements[i].value;
      if ( !IsBlank(itemValue) ) {
        itemQty = stripCharsInBag(qtyElements[i].value,'$, ') * 1;
        if ( itemQty != 0 && !isNaN(itemQty) ) {
          addToCart(itemValue, 0, itemQty);   
        }
      }
    }
  }
  catch (e) {
    //TODO
  }
  
  location.replace('../CustomerScripts/page.aspx?page=reviewcart');
}

function quickResults() {

  ClearTimer();
  
  quickSearch = false;
  var itemSub = -1;
  var strResponse = '';
  var allElements;
  
  itemSub = lastIndex;
  lastIndex = -1;

  //Make sure we recieved something from the callback
  if ( quickResults.arguments.length == 0 ) {
    return false;
  }
  else
    strResponse = quickResults.arguments[0].toString();
    
  var aryResponse = strResponse.split('|',20);

  switch (aryResponse[0].toString().toLowerCase()) {
    case 'true':

      itemError = -1;
      allElements = document.getElementsByName("txtItem");
      allElements[itemSub].value = aryResponse[1];      
      timer = setTimeout("findItem('" + itemSub + "', 0);",150);
      break;
    
    default:
    
      ClearTimer();
    
      allElements = document.getElementsByName("fieldError");
      allElements[itemSub].style.visibility = '';

      allElements = document.getElementsByName("txtItem");
      allElements[itemSub].value='';
      allElements[itemSub].focus();

      itemError = lastIndex;
      return false;

      break
  } 
  
}

function changeCustomer(customer) {

  var strResponse;
  
  try {
    var loc = document.URL.toString().toLowerCase();
    loc = loc.substring(0,loc.indexOf('customerscripts'));
    strResponse = xmlHTTPCall(loc + 'Includes/ajaxFunctions.aspx?type=changeCustomer&cust=' + customer, false,false,false);

    var aryResponse = strResponse.split('|',20);

    if ( aryResponse[0] == 'true' ) {
      showPopWin('', aryResponse[1], 250, 110, null);
      setTimeout('refreshLocation()',150);
    }
    else {
      showPopWin('', 'Unable to change to selected customer.', 250, 110, null);
    }
  }
  catch(e) {
    // No Errors
  }
}

function selectCart(cart) {

  var strResponse;
  
  try {
    var loc = document.URL.toString().toLowerCase();
    loc = loc.substring(0,loc.indexOf('customerscripts'));
    strResponse = xmlHTTPCall(loc + 'Includes/ajaxFunctions.aspx?type=changeCart&cart=' + cart, false,false,false);

    var aryResponse = strResponse.split('|',20);

    if ( aryResponse[0] == 'true' ) {
      document.getElementById('cartQty').innerHTML = aryResponse[1];
      document.getElementById('cartSubTotal').innerHTML = formatDollar(aryResponse[2],true);
      checkCart(aryResponse[2],'');
      //document.getElementById('viewCartDiv').style.display = '';
      showPopWin('', aryResponse[3], 250, 110, null);
      setTimeout("hidePopWin(true);",1500);
    }
    else {
      showPopWin('', 'Unable to change to selected cart.', 250, 110, null);
    }
  }
  catch(e) {
    // No Errors
  }
}

function saveCart(cart) {

  var strResponse;
  
  try {
    var loc = document.URL.toString().toLowerCase();
    var subLoc = loc.substring(0,loc.indexOf('customerscripts'));
    strResponse = xmlHTTPCall(subLoc + 'Includes/ajaxFunctions.aspx?type=saveCart', false,false,false);

    var aryResponse = strResponse.split('|',20);

    if ( aryResponse[0] == 'true' ) {
      document.getElementById('cartQty').innerHTML = aryResponse[1];
      document.getElementById('cartSubTotal').innerHTML = formatDollar(aryResponse[2],true);
      document.getElementById('viewCartDiv').style.display = '';
      checkCart(0,'');
      if ( loc.indexOf('reviewcart') != -1 ) {
        showPopWin('', aryResponse[3], 250, 110, redirectHome);
      }
      else {
        showPopWin('', aryResponse[3], 250, 110, null);
      }
      setTimeout("hidePopWin(true);",1500);
    }
    else {
      showPopWin('', 'Unable to save selected cart.', 250, 110, null);
    }
  }
  catch(e) {
    // No Errors
  }
}

function displayTracking(track, via) {

  var strResponse;
  
  try {
    if (shippers!='' && shippers.indexOf('U')!=-1 && via.toString().toUpperCase().indexOf(shipperTypes[0])!=-1){
      trackingNumber = track;
      shipVia = via;

      var loc = document.URL.toString().toLowerCase();
      var subLoc = loc.substring(0,loc.indexOf('customerscripts'));
      strResponse = xmlHTTPCall(subLoc + 'Includes/ajaxFunctions.aspx?type=trackingagree&t=' + track + '&s=' + via, false,false,false);

      var aryResponse = strResponse.split('|~|',20);
      var height=430;
      var width=475;
      if (browserVersion==1){
        height=525;
        width=475;
      }


      if ( aryResponse[0] == 'true' ) {
        if ( gPopupIsShown == true ) {
          resetPopWin(width,height);
          window.frames['popupFrame'].document.body.innerHTML = aryResponse[1];
          window.frames['popupFrame'].document.getElementById('shipmentTracker').innerHTML = 'UPS Online&reg; Tools Tracking';
        }
        else {
          showPopWin('', aryResponse[1], width, height, null);
        }
      }
      else{
        trackingNumber = '';
        shipVia = '';
      }
    }
    else {
      trackingScreen(track,via);
    }
    
  }
  catch(e) {
    // No Errors
  }
}

function trackAgreeReturn(val,agree,track,via){

  try{
    switch (val){
      case 0:
        if (agree!=true)
          alert('You must agree to the Terms by checking the "Agree" box before you continue! ');
        else if (track=='')
          alert('You must enter a UPS Tracking Number before you continue! ');
        else
          trackingScreen(track,via);
        break;
      case 1:
        hidePopWin(false);
        break;
    }
  }
  catch(e){
    //No Errors
  }
  return true; 
 
}

function trackingScreen(track, via) {

  var strResponse;
  
  try {
    if (track==''){
      track=trackingNumber;
      via=shipVia;
    }
      

    var loc = document.URL.toString().toLowerCase();
    var subLoc = loc.substring(0,loc.indexOf('customerscripts'));
    strResponse = xmlHTTPCall(subLoc + 'Includes/ajaxFunctions.aspx?type=displaytracking&t=' + track + '&s=' + via, false,false,false);

    var aryResponse = strResponse.split('|',20);

    if ( aryResponse[0] == 'true' ) {
      if ( gPopupIsShown == true ) {
        resetPopWin(600,575);
        window.frames['popupFrame'].document.body.innerHTML = aryResponse[1];
      }
      else {
        showPopWin('', aryResponse[1], 600, 500, null);
      }
    }
    else{
      trackingNumber = '';
      shipVia = '';
    }    
  }
  catch(e) {
    // No Errors
  }
}

function displayQuickSearch(keyWords) {

  var strResponse;
  
  try {
    var loc = document.URL.toString().toLowerCase();
    var subLoc = loc.substring(0,loc.indexOf('customerscripts'));

    showPopWin(subLoc + 'Includes/ajaxFunctions.aspx?type=displayquicksearch&k=' + keyWords, '', 600, 525, quickResults);

  }
  catch(e) {
    // No Errors
  }

}

function salesTax(order) {

  var strResponse = '';
  var strOpts = '';
  var shipToNumber = '';
  
  try {
  
    if ( order != '' && order != null ) {
      strOpts = '&o=' + order;
      try {
        shipToNumber = GetSelectValue(document.getElementById('shipToCBO'));
      }
      catch (e) {
        try {
          shipToNumber = document.getElementById('shipToName').value;
        }
        catch (e) {
          shipToNumber = '';
        }
      }
      strOpts = strOpts + '&ST=' + shipToNumber;
      strOpts = strOpts + '&STN=' + document.getElementById('shipToFirstName').value + ' ' + document.getElementById('shipToLastName').value;
      strOpts = strOpts + '&STAD1=' + document.getElementById('shipToAddress1').value;
      strOpts = strOpts + '&STAD2=' + document.getElementById('shipToAddress2').value;
      strOpts = strOpts + '&STCTY=' + document.getElementById('shipToCity').value;
      strOpts = strOpts + '&STST=' + GetSelectValue(document.getElementById('cboShipToState'));
      strOpts = strOpts + '&STZIP=' + document.getElementById('shipToZipCode').value;
      try {
        strOpts = strOpts + '&FRT=' + document.getElementById('cartShipping').value;
      }
      catch (e) { }
      var loc = document.URL.toString().toLowerCase();
      var subLoc = loc.substring(0,loc.indexOf('customerscripts'));
      strResponse = xmlHTTPCall(subLoc + 'Includes/ajaxFunctions.aspx?type=salestax' + strOpts, false,false,false);

      var aryResponse = strResponse.split('|',20);

      if ( aryResponse[0] == 'true' ) {
        document.getElementById('cartTax').value = aryResponse[1];
        updateTotals();
      }
    }
  }
  catch(e) {
    // No Errors
  }
}

function updateTotals(){

  var dblTotal = 0;
  var dblHandling = 0;
  var dblTax = 0;
  var dblTemp = 0;
  var dblShipping = 0;
  var review = 0;

  try { 
    if (document.getElementById('cartSubTotalRvw') != null) {
      dblTotal = stripCharsNotInBag(document.getElementById('cartSubTotalRvw').value,'0123456789.');
      review = 1;
    }
    else if (document.getElementById('cartSubTotal') != null) {
      dblTotal = stripCharsNotInBag(document.getElementById('cartSubTotal').value,'0123456789.');
    }
    dblHandling = stripCharsNotInBag(document.getElementById('cartHandling').value,'0123456789.');
    dblTax = stripCharsNotInBag(document.getElementById('cartTax').value,'0123456789.');
    dblShipping = stripCharsNotInBag(document.getElementById('cartShipping').value,'0123456789.');  

    dblTotal = dblTotal * 1; // Convert to a number
    dblHandling = dblHandling * 1;
    dblTax = dblTax * 1;
    dblShipping = dblShipping * 1; // Convert back to a number

    dblTotal = dblTotal + dblShipping + dblHandling + dblTax;
    if ( review == 1) {
      dblShipping = dblShipping + dblHandling;
    }
    document.getElementById('cartTotal').value = formatDollar(dblTotal,true);

  }
  catch (e) {
    //TODO
  }
  
}

// Admin Functions

function getSessionValue(sessionID) {

  var rtnVal = '';
  var strResponse = '';

  try {
    
    if ( !IsBlank(sessionID))
    {
      strResponse = xmlHTTPCall('../Includes/ajaxFunctions.aspx?type=session&s=' + sessionID, false, false, false);

      var aryResponse = strResponse.split('|',20);

      if ( aryResponse[0].toString().toLowerCase() == 'true' ) {
        rtnVal = aryResponse[1].toString();
      }
      else { }

    }

  }
  catch (e) {
    //TODO
  }
  
  //document.body.style.cursor='default';
  blnDisabled = false;
  
  return rtnVal;
  
}

function printReport(strReport) {

  var strResponse;
  
  try {
    var reportTimeout = setTimeout("showPopWin('','<DIV id=\"modalContent\" style=\"margin-top:25px;\"><TABLE align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"200px\"><TR><TD id=\"loadingMsg\"align=\"center\"><span style=\"font-size:10pt;font-weight:bold;\">Creating Product Catalog.<br>Please Wait...</span></TD></TR></TABLE></DIV>',250,100,null);",50);

    var loc = document.URL.toString().toLowerCase();
    var subLoc = loc.substring(0,loc.indexOf('customerscripts'));
    strResponse = xmlHTTPCall(subLoc + 'Includes/ajaxFunctions.aspx?t=printReport&r=' + strReport, false,false,false);
    
    clearTimeout(reportTimeout);

    var aryResponse = strResponse.split('|',20);

    if ( aryResponse[0] == 'true' ) {
      var fileLoc = subLoc + 'Temp/' + aryResponse[1].substring(aryResponse[1].lastIndexOf('\\')+1,aryResponse[1].length);
      if ( gPopupIsShown == true ) {
        resetPopWin(900,550);
        gPopFrame.src = fileLoc;
      }
      else {
        showPopWin(fileLoc, '', 900, 550, null);
      }
      
      //if (is_fx && is_major==3)
      //  hidePopWin();
    }
  }
  catch(e) {
    // No Errors
  }
}

function forgotPassword() {

  try {

    var loc = document.URL.toString().toLowerCase();
    var subLoc = loc.substring(0,loc.indexOf('customerscripts'));
    strResponse = xmlHTTPCall(subLoc + 'Includes/ajaxFunctions.aspx?type=forgotpassword', false,false,false);

    var aryResponse = strResponse.split('|~|',20);
    var height=250;
    var width=475;
    if (browserVersion==1){
      height=250;
      width=475;
    }


    if ( aryResponse[0] == 'true' ) {
      if ( gPopupIsShown == true ) {
        resetPopWin(width,height);
        window.frames['popupFrame'].document.body.innerHTML = aryResponse[1];
      }
      else {
        showPopWin('', aryResponse[1], width, height, null);
      }
      
    }
    
  }
  catch (e) {
    //No Errors
  }

}

function resendPassword(email) {

  try {

    var loc = document.URL.toString().toLowerCase();
    loc = loc.substring(0,loc.indexOf('customerscripts'));
    strResponse = xmlHTTPCall(loc + 'Includes/ajaxFunctions.aspx?type=PasswordReminder&user='+email, false,false,false);

    var aryResponse = strResponse.split('|',20);
    resetPopWin(250,110);

    if ( aryResponse[0] == 'true' ) {
      showPopWin('', '<DIV id="modalContent" style="margin-top:25px;"><TABLE align="center" border="0" cellpadding="0" cellspacing="0" width="200px"><TR><TD id="loadingMsg"align="center"><span style="font-size:10pt;font-weight:bold;">Your new password has been sent. Please<br>check your email.</span></TD></TR></TABLE></DIV>', 250, 110, null);
    }
    else {
      showPopWin('', '<DIV id="modalContent" style="margin-top:25px;"><TABLE align="center" border="0" cellpadding="0" cellspacing="0" width="200px"><TR><TD id="loadingMsg"align="center"><span style="font-size:10pt;font-weight:bold;">Email address is not on file.</span></TD></TR></TABLE></DIV>', 250, 110, null);
    }

  }
  catch (e) {
    // No Errors
  }

}

function validateRegister(url) {

  try {

    if (companyNumber.toLowerCase() != 'retail')
      showPopWin('', '<DIV id=\"modalContent\" style=\"margin-top:25px;\"><TABLE align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"350px\"><TR><TD id=\"loadingMsg\"align=\"center\"><span style=\"font-size:10pt;font-weight:bold;\">Please goto the "User" tab on the My Account<br>screen to create users for your account.</span></TD></TR></TABLE></DIV>', 400, 100, null);
    else
      location.replace(url);

  }
  catch (e) { }

}
 function refreshLocation() { location.reload(); }