// To replace usage of osCommerce function, tep_get_all_get_params(), in the header.
// Thus, it shrinks each page size by shrinking header.php.
// exclude must be an Object acting as an associative array.
function getURLwithGet(exclude)
{
  var getobj = new Object; //what will be returned
  
  var myRe = new RegExp("/([^/]+\.(php|html))(.*)$", "i"); //basename
  var myurl = document.location.toString();
  var basename = "";
      
  var myArr = myurl.match(myRe);
  if( myArr ){
    basename = myArr[1].toString();
    var getparams = myArr[3].toString();
    
    //remove the '?'
    if( getparams.substring(0,1) == "?" ){
      if( getparams.length > 1 ){ getparams = getparams.substring( 1 ); }
      else{ getparams = ""; }
    }

    // the get parameters have the normal style, &'s and ='s.
    if( getparams.indexOf('=') >= 0 )
    {
       var temp = getparams.split("&");
       if( temp ){
         for( var i=0; i < temp.length; i++)
         {
            var pair = temp[i].split("=");
            if( pair && pair.length == 2 ){
              getobj[pair[0]] = pair[1];
            }
         }
       }
    }
    // the get params have osCommerce style, '/' separating keys and values.
    else
    {
      var temp = getparams.split("/");
      if( temp && temp.length > 0){
        var keys = new Array();
        var vals = new Array();
        var keysize = 0;
        var valsize = 0;
        
        //evens are keys, odds are values.
        for( var i=0; i < temp.length; i++){
          if( i % 2 == 0 ){   //even
            keys[i] = temp[i];
            keysize += 1;
          }else{   // odd
            vals[i] = temp[i];
            valsize += 1;
          }
        }
        
        // put the key/value pairs in an array.
        if( keysize == valsize && keysize > 0){
          for( var i=0; i < keysize; i++){
            getobj[ keys[i] ] = vals[i];
          }
        }
      }
    }
  }
  
  var retstring = basename + '?';
  
  for( var i in getobj ){
    if( ! exclude[i] ){
      retstring += '&' + i + '=' + getobj[i];
    }
  }
  
  return getobj;
}

// Detect if the browser is IE or not. If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)
// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Variables to hold mouse x-y pos.s
var mousetrackX = 0
var mousetrackY = 0

var showNotifyBox = false;
var showWarehouseBox = false;
var showRetailBox = false;

//============================================================
// This function will display or hide a DIV element.
// The first argument specifies the hide/unhide action.
// The second argument determines which DIV element this affects.
// PRE: the Element should have a style similar to this:
//      position:absolute; width:xxx; height:yyy; display:none;
//
function showInfoBox(disp, elemName)
{
    var el = document.getElementById( elemName );
    if(el){
        var xy = getWindowSize();
        var scxy = getScrollOffset();

        el.style.left = mousetrackX + 10;
        if( parseInt(el.style.left, 10) + parseInt(el.style.width, 10) > xy[0] + scxy[0] )   //the infoBox->right is off the page
        {
            el.style.left = mousetrackX - parseInt(el.style.width,10) - 30;
        }

        el.style.top = mousetrackY + 10;
        if( parseInt(el.style.top, 10) + parseInt(el.style.height, 10) > xy[1] + scxy[1] )   //the infoBox->bottom is off the page
        {
            el.style.top = mousetrackY - parseInt(el.style.height, 10) - 30;
        }
        el.style.display = disp;
    }
}


/*
============================================================
Capturing The Mouse Position in IE4-6 & NS4-6
(C) 2000 www.CodeLifter.com
Free for all users, but leave in this  header
*/
function getMouseXY(e)
{
  if (IE) { // grab the x-y pos.s if browser is IE
    mousetrackX = event.clientX + document.body.scrollLeft
    mousetrackY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    mousetrackX = e.pageX
    mousetrackY = e.pageY
  }  
  // catch possible negative values in NS4
  if (mousetrackX < 0){mousetrackX = 0}
  if (mousetrackY < 0){mousetrackY = 0}

  if(showNotifyBox){ showInfoBox('','emailnotifyInfo'); }
  else{
    var el=document.getElementById('emailnotifyInfo')
    if(el){ el.style.display='none'; }
  }
  
  if(showWarehouseBox){ showInfoBox('','warehouseInfo'); }
  else{
    var el=document.getElementById('warehouseInfo')
    if(el){ el.style.display='none'; }
  }
  
  
  if(showRetailBox){ showInfoBox('','viewableInfo'); }
  else{
    var el=document.getElementById('viewableInfo')
    if(el){ el.style.display='none'; }
  }
  return true
}

/*
 ============================================================
 Code from
  http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
 1/31/2008.
 alertSize() modified by Matt D.
*/
function getWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return new Array( myWidth, myHeight );
}

/*
 ============================================================
 Code from: http://www.quirksmode.org/viewport/compatibility.html
 
*/
function getScrollOffset(){
  var x,y;
  if (self.pageYOffset) // all except Explorer
  {
    x = self.pageXOffset;
    y = self.pageYOffset;
  }
  else if (document.documentElement && document.documentElement.scrollTop)
  // Explorer 6 Strict
  {
    x = document.documentElement.scrollLeft;
    y = document.documentElement.scrollTop;
  }
  else if (document.body) // all other Explorers
  {
    x = document.body.scrollLeft;
    y = document.body.scrollTop;
  }
  return new Array(x, y);
}

