//JS Navigation Menu 
function popit(url,windowname){window.open(url, windowname, "toolbar=no,status=no,location=no,menubar=no,left=15,top=15,width=700,height=550,scrollbars=yes,resizable=yes,dependent");}

function popit(url,windowname){window.open(url, windowname, "toolbar=no,status=no,location=no,menubar=no,left=15,top=15,width=700,height=550,scrollbars=yes,resizable=yes,dependent");}
/*
preloadImages('/images/navigation/tab_topnav_home_on.gif','/images/navigation/tab_topnav_rewards_on.gif','/images/navigation/tab_topnav_products_on.gif',
'/images/navigation/tab_topnav_articles_on.gif','/images/navigation/tab_topnav_tools_on.gif','/images/navigation/tab_topnav_ask_on.gif',
'/images/navigation/tab_topnav_contact_on.gif');
*/
function preloadImages(){
  if(document.images)  {
    if(!document.imageArray) document.imageArray = new Array();
    var i,j = document.imageArray.length, args = preloadImages.arguments;   
    for(i=0; i<args.length; i++)    {
      if (args[i].indexOf("#")!=0)      {
        document.imageArray[j] = new Image;
        document.imageArray[j++].src = args[i];
      }
    }
  }
}

function switchImage(imgName, imgSrc) {
  if (document.images)  {
    if (imgSrc != "none")    {
      document.images[imgName].src = imgSrc;
    }
  }
}

function ShowMenu(MenuID,visibility) {
    var Menu = document.getElementById(MenuID);
    Menu.style.visibility = visibility;
}


function getObject( obj ) {
      if ( document.getElementById ) {
        obj = document.getElementById( obj );
      } else if ( document.all ) {
        obj = document.all.item( obj );
      } else {    obj = null;  }
      return obj;
  }

function PopUpCallOut( Container, e, xoffset, yoffset) {
  if (!xoffset) var xoffset = 0;
  if (!yoffset) var yoffset = 0;
  var tempX = 0;
  var tempY = 0;
  var objHolder = Container;
  var SwitchView = ''; //Used for switching object calls (i.e. Right to Left)


  disableLeftRightObjects(Container); // There are two version (left and right) for the callout popup
  

  //Determine Left or Right CallOut
  if (document.all) {
    tempX = event.clientX + (document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft);
    tempY = event.clientY + (document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop);
  } else {
    tempX = e.pageX;
    tempY = e.pageY;
  }

  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}

  if ((tempX + xoffset) < 0) { //Switch to left callout if on far left
    SwitchView = 'Left';
    Container += SwitchView;
    objHolder = Container;
  }
  Container = getObject( Container );
  if (Container==null) return;
  Container.style.top  = (tempY + yoffset) + 'px';
  Container.style.left = (tempX + xoffset) + 'px';
  
  displayObject( objHolder, true );
}

function disableLeftRightObjects( obj ) {
  var objRight = getObject( obj );
  if (objRight==null) return;
  objRight.style.display = 'none';
  var objLeft = getObject( obj + 'Left' );
  if (objLeft==null) return;
  objLeft.style.display = 'none';
}

function displayObject( obj, show ) {

  obj = getObject( obj );
  if (obj==null) return;

  obj.style.display = show ? 'block' : 'none';
  obj.style.visibility = show ? 'visible' : 'hidden';
}
    
function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
}

function URLDecode(encoded)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
}


var userAgent = navigator.userAgent;
var versionOffset = userAgent.indexOf("MSIE");
var isIE = (versionOffset >= 0);
var isPreIE7 = false;
var fullVersionIE = "";
var majorVersionIE = "";
if (isIE)
{
    fullVersionIE = parseFloat(userAgent.substring(versionOffset+5, userAgent.length));
    majorVersionIE = parseInt('' + fullVersionIE);
    isPreIE7 = majorVersionIE < 7;
}

function showSelectBoxes(){
    if (isIE) {
	    selects = document.getElementsByTagName("select");
	    for (i = 0; i != selects.length; i++) {
		    selects[i].style.visibility = "visible";
			selects[i].style.display = "block";
	    }
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
    if (isIE) {
	    selects = document.getElementsByTagName("select");
	    for (i = 0; i != selects.length; i++) {
	            selects[i].style.visibility = "hidden";
				selects[i].style.display = "none";
        }
    }
}

function Popup(page,w,h) {
   x = (screen.availWidth-w)/2;
   y = (screen.availHeight-h)/2;

OpenWin = this.open(page, "NewWindow", "height=" + h + ",width=" + w + ",left=" + x +",top=" +y +",location=no,scrollbars=yes");
} 