// HPWEB JAVASCRIPT hpweb_utilities.js VERSION hpweb.1.2d - IE7
// with hpshopping.com additional classes
var mysiteurl = "http://localhost/ea/";
var cssDir = null;
var NS4CSS = null;
var winIECSS = null;
var winIE6CSS = null;
var strdCSS = null;
var macCSS = null;
var agt = null;
var is_major = null;
var is_minor = null;
var is_nav = null;
var is_nav4 = null;
var is_nav5 = null;
var is_nav5up = null;
var is_nav6 = null;
var is_nav4up = null;
var is_nav6up = null;
var is_ie = null;
var is_ie3 = null;
var is_ie4 = null;
var is_ie5 = null;
var is_ie5up = null;
var is_ie6 = null;
var is_ie7 = null;
var is_opera = null;
var is_win = null;
var is_mac = null;
var is_sun = null;
var is_irix = null;
var is_hpux = null;
var is_aix = null;
var is_linux = null;
var is_sco = null;
var is_unixware = null;
var is_mpras = null;
var is_reliant = null;
var is_dec = null;
var is_sinix = null;
var is_freebsd = null;
var is_bsd = null;
var is_unix = null;
var initWidth = null;
var initHeight = null;
var fileHead = null;
var styles = null;
var obj = null;
var index = null;
var url = null;
var Theme = null;
var str = null;
var defaultColor = null;
var i = null;
var j = null;

// Files and directory structures

	var cssDir = mysiteurl+ "css/";


	var NS4CSS = "h_n4.css";
	var winIECSS = "h_we.css";
	var winIE6CSS = "h_we6.css";
	var strdCSS = "h_s.css";
	var macCSS = "h_m.css";

	//  CLIENT_SIDE SNIFFER CODE
	// convert all characters to lowercase
	var agt=navigator.userAgent.toLowerCase();

	// *** BROWSER VERSION ***
	// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
	var is_major = parseInt(navigator.appVersion);
	var is_minor = parseFloat(navigator.appVersion);

	// *** BROWSER TYPE ***
	var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
	            && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
	            && (agt.indexOf('webtv')==-1));
	var is_nav4 = (is_nav && (is_major == 4));
	var is_nav5 = (is_nav && (is_major == 5));
	var is_nav5up = (is_nav && (is_major >= 5));
	var is_nav6 = (is_nav && (is_major == 6));
	var is_nav4up = (is_nav && (is_major >= 4));
	var is_nav6up = (is_nav && (is_major >= 6));
	var is_ie   = (agt.indexOf("msie") != -1);
	var is_ie3  = (is_ie && (is_major < 4));
	var is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
	var is_ie5up  = (is_ie  && !is_ie3 && !is_ie4);
	var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
	var is_ie7    = (is_ie && (is_major == 4) && (agt.indexOf("msie 7.")!=-1) );
	var is_ie4  = (is_ie && (is_major <= 4) && !is_ie5 && !is_ie6 && !is_ie7);
	var is_opera = (agt.indexOf("opera") != -1);

	// *** PLATFORM ***
	var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
	var is_mac    = (agt.indexOf("mac")!=-1);
	var is_sun   = (agt.indexOf("sunos")!=-1);
	var is_irix  = (agt.indexOf("irix") !=-1);    // SGI
	var is_hpux  = (agt.indexOf("hp-ux")!=-1);
	var is_aix   = (agt.indexOf("aix") !=-1);      // IBM
	var is_linux = (agt.indexOf("inux")!=-1);
	var is_sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
	var is_unixware = (agt.indexOf("unix_system_v")!=-1);
	var is_mpras    = (agt.indexOf("ncr")!=-1);
	var is_reliant  = (agt.indexOf("reliantunix")!=-1);
	var is_dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) ||
	       (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) ||
	       (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1));
	var is_sinix = (agt.indexOf("sinix")!=-1);
	var is_freebsd = (agt.indexOf("freebsd")!=-1);
	var is_bsd = (agt.indexOf("bsd")!=-1);
	var is_unix  = ((agt.indexOf("x11")!=-1) || is_irix || is_sco ||
	is_unixware || is_mpras || is_reliant ||
	             is_dec || is_sinix || is_aix || is_bsd || is_freebsd);

	// Load stylesheet
	ChooseStyleSheet();

// Handle Navigator 4 window resizing
if (is_nav4up && !is_nav5up) {
   var initWidth, initHeight;
   initWidth = window.innerWidth;
   initHeight = window.innerHeight;
   window.captureEvents(Event.RESIZE);
   window.onresize = handleResize;
}

//  UTILITY FUNCTIONS
// Function to handle window resizing on Navigator 4
function handleResize() {
   if (((initWidth != window.innerWidth) || (initHeight != window.innerHeight)) && (typeof disableReload == "undefined")) {
     location.reload();
   }
   return false;
}

// Function to choose stylesheet for platform and browser version
	function ChooseStyleSheet() {
	  var fileHead = cssDir;
	  var styles;
	  if (is_win) {
		if (is_nav4) {
		    styles = fileHead + NS4CSS;
		} else if (is_ie6 || is_ie7) {
		    styles = fileHead + winIE6CSS;
		} else if (is_nav5up) {
		    styles = fileHead + macCSS;
		} else if (is_opera) {
		    styles = fileHead + macCSS;
		} else {
		    styles = fileHead + winIECSS;
		}
	  } else if (is_mac) {
		    styles = fileHead + macCSS;
	  } else if (is_linux) {
		if (is_nav4) {
		    styles = fileHead + strdCSS;
		} else {
		    styles = fileHead + macCSS;
		}
	  } else if (is_hpux) {
		if (is_ie5) {
		    styles = fileHead + macCSS;
		} else if (is_nav5up) {
		    styles = fileHead + macCSS;
		} else {
		    styles = fileHead + strdCSS;
		}
	  } else if (is_sun) {
		if (is_nav4) {
		    styles = fileHead + NS4CSS;
		} else {
		    styles = fileHead + strdCSS;
		}
	  // Created by Tru 64 Team - added 09/04
	  } else if (is_dec) {
		if (is_nav4) {
		    styles = fileHead + NS4CSS;
		} else if (is_nav5up) {
		    styles = fileHead + macCSS;
		} else {
		    styles = fileHead + strdCSS;
		}
	  } else {
		styles = fileHead + strdCSS;
	  }
	  document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + styles + "\">");
	  return true;
	}

	// Function to jump to a URL in a <select> menu. In this case, the name of the array containing the URLs is determined based on the name of the pulldown menu.
	function jumpToURL(formName,menuName) {
	 var obj = eval("document." + formName + "." + menuName);
	 var index = obj.selectedIndex;
	 var url = eval(menuName + "_URLs[" + index + "]");
	 if (url != "") {
	   location.href=url;
	 }
	}

	// Theme Color Generator
		var Theme = new Function();{
		this.bgcolors = new Array;
		this.textColor = "";
		}

		aThemes = new Array();

		// For use with white text
		aThemes[0] = new Theme();
		aThemes[0].bgcolors = ['#990000','#CC0066','#336666','#003366','#000000','#666666','#336633','#EB5F01','#0066FF','#4FAF00','#0A357E','#FF0000'];
		aThemes[0].textColor = "#fff";

		// For use with black text
		aThemes[1] = new Theme();
		aThemes[1].bgcolors = ['#FFCC00'];
		aThemes[1].textColor = "#000000";

		function cssStr(type) {
			switch(type){
				case "start": return '<style type="text/css">\n';
				case "end": return '</style>';
				case "classes": return '.themeheader {color:'+ defaultColor +'; font-weight: bold;}\n' + 
					'.themebody {color:'+ defaultColor +'; font-weight: normal;}\n' + 
					'.leveld {font-weight: bold; border-bottom: solid 2px '+ theme +'; margin: 0; padding: 1px;}\n' +
					'td.theme {color:'+ defaultColor +';}\n' + 
					'tr.theme td {color:'+ defaultColor +';}\n' + 
					'div.theme {color:'+ defaultColor +';}\n' + 
					'a.themeheaderlink {font-weight: bold; color:'+ defaultColor +'; text-decoration: none;}\n' + 
					'a.themeheaderlink:active {font-weight: bold; color:'+ defaultColor +';}\n' + 
					'a.themeheaderlink:link {font-weight: bold; color:'+ defaultColor +';}\n' + 
					'a.themeheaderlink:visited {font-weight: bold; color:'+ defaultColor +';}\n' + 
					'a.themeheaderlink:hover {text-decoration: underline;}\n' + 
					'a.themelink {color:'+ defaultColor +'; text-decoration: none;}\n' + 
					'a.themelink:active {color:'+ defaultColor +';}\n' + 
					'a.themelink:link {color:'+ defaultColor +';}\n' + 
					'a.themelink:visited {color:'+ defaultColor +';}\n' + 
					'a.themelink:hover {text-decoration: underline;}\n' + 
					'a.themebodylink {color:'+ defaultColor +'; font-weight: normal; text-decoration: underline;}\n' + 
					'a.themebodylink:active {color:'+ defaultColor +';}\n' + 
					'a.themebodylink:link {color:'+ defaultColor +';}\n' + 
					'a.themebodylink:visited {color:'+ defaultColor +';}\n' + 
					'.boldtheme {color:'+ theme +'; font-weight: bold;}\n' + 
					'.bodytheme {color:'+ theme +';}\n\n' + 
					'.alert {margin-bottom: 10px; padding: 4px; border: 2px solid '+ theme +'; background: #fff;}\n' + 
					'.tabbox {margin-bottom: 10px; padding: 10px 10px 10px 0; border-top: 2px solid '+ theme +'; border-right: 2px solid '+ theme +'; border-bottom: 2px solid '+ theme +'; width: 548px;}\n' + 
					'.theme_ruled {padding-bottom: 1px; border-bottom: 4px solid; border-color: '+ theme +';}\n' + 
					'.theme_border_top {border-top: 4px solid '+ theme +';}\n' + 
					'.theme_border_btm {border-bottom: 4px solid '+ theme +';}\n' + 
					'.theme_border_topbtm {border-top: 4px solid '+ theme +'; border-bottom: 4px solid '+ theme +';}\n' + 
					'.theme {background: '+ theme +';}\n';
				default: return '\n'
			}
		}

		function writeCSS() {
			var str = cssStr('start')+cssStr('classes')+cssStr('end');
			document.write(str);
		}

		var defaultColor = '#000';

		if ((typeof theme) != 'undefined') {
			for (var i=0; i<aThemes.length; i++){
				for (var j=0; j<aThemes[i].bgcolors.length; j++){
					if (aThemes[i].bgcolors[j]==theme){
						defaultColor = aThemes[i].textColor;
						break;
					}
				}
			}

			writeCSS();

		}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
		
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_showHideLayers() 
{ //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  
  for (i=0; i<(args.length-2); i+=3)
  	if ((obj=MM_findObj(args[i]))!=null) 
  	{ 
  		v=args[i+2];
    	if (obj.style) 
    	{ 
    		obj=obj.style; 
    		v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
    	}
    	obj.visibility=v; 
  	}
}

var DHTML = (document.getElementById || document.all || document.layers);
function getObj(name) {
  if (document.getElementById)
  {
	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
	this.obj = document.layers[name];
	this.style = document.layers[name];
  }
}
function changeCol(colora,x) {
	if (!DHTML) return;
	var x = new getObj(x);
	x.style.color = colora;
}
function changeTD(colorb,colorc,y) {
	if (!DHTML) return;
	var y = new getObj(y);
	y.style.className = 'tdMouseOn';
	y.style.backgroundColor = colorb;
	y.style.color = colorc;
}

// begin positioning code

var ns4=document.layers?1:0
var ie4=document.all?1:0
var ns6=document.getElementById&&!document.all?1:0

function xDef() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}

function xParent(e,bNode){
  var p=null;
  if (!bNode && xDef(e.offsetParent)) p=e.offsetParent;
  else if (xDef(e.parentNode)) p=e.parentNode;
  else if (xDef(e.parentElement)) p=e.parentElement;
  else if (xDef(e.parentLayer)){if (e.parentLayer!=window) p=e.parentLayer;}
  return p;
}

function xPageY(e) {
  if (xDef(e.pageY)) return e.pageY;
  var y = 0;
  while (e) {
    if (xDef(e.offsetTop)) y += e.offsetTop;
    e = xParent(e);
  }
  return y;
}
function xPageX(e) {
  if (xDef(e.pageX)) return e.pageX;
  var x = 0;
  while (e) {
    if (xDef(e.offsetLeft)) x += e.offsetLeft;
    e = xDef(e.offsetParent) ? e.offsetParent : null;
  }
  return x;
}

function alignMenuTop(markerID) {
  var topmenuid = markerID;
  var mm = HM_DOM ? document.getElementById(topmenuid) : HM_IE4 ? document.all(topmenuid) : eval("window." + topmenuid);

  var my = xPageY(mm);

  return my;
}

function alignMenuLeft(markerID) {
  var topmenuid = markerID;

  var mm1 = HM_DOM ? document.getElementById(topmenuid) : HM_IE4 ? document.all(topmenuid) : eval("window." + topmenuid);
  var mx = xPageX(mm1);

  return mx;
}

function alignMenu() {
  HM_UserAgent = navigator.userAgent;
  HM_DOM = (document.getElementById) ? true : false;
  HM_NS4 = (document.layers) ? true : false;
  HM_IE = (document.all) ? true : false;
  HM_IE4 = HM_IE && !HM_DOM;
  HM_Mac = (navigator.appVersion.indexOf("Mac") != -1);
  HM_IE4M = HM_IE4 && HM_Mac;

   if (ie4) {
     menu1.style.pixelTop = alignMenuTop('menu1Marker')+56; 
     menu1.style.pixelLeft = alignMenuLeft('menu1Marker');
     menu2.style.pixelTop = alignMenuTop('menu2Marker')+56; 
     menu2.style.pixelLeft = alignMenuLeft('menu2Marker');  
     menu3.style.pixelTop = alignMenuTop('menu3Marker')+56; 
     menu3.style.pixelLeft = alignMenuLeft('menu3Marker');
     menu4.style.pixelTop = alignMenuTop('menu4Marker')+56; 
     menu4.style.pixelLeft = alignMenuLeft('menu4Marker');         
     //menu2.style.pixelTop = alignMenuTop('menu2Marker'); menu2.style.pixelLeft = alignMenuLeft('menu2Marker');
 
   }
   else if (ns6) {
     document.getElementById("menu1").style.top = alignMenuTop('menu1Marker')+56;
     document.getElementById("menu1").style.left = alignMenuLeft('menu1Marker');
  
     document.getElementById("menu2").style.top = alignMenuTop('menu2Marker')+56;
     document.getElementById("menu2").style.left = alignMenuLeft('menu2Marker');

     document.getElementById("menu3").style.top = alignMenuTop('menu3Marker')+56;
     document.getElementById("menu3").style.left = alignMenuLeft('menu3Marker');
     
     document.getElementById("menu4").style.top = alignMenuTop('menu4Marker')+56;
     document.getElementById("menu4").style.left = alignMenuLeft('menu4Marker');
     
   }


}
