// Window onLoad Events
function winOnLoad(){
	window.onload = winOnLoadGo;
}

function winOnLoadGo(){
	for(var i = 0;i < winOnLoadEvents.length;i++)
		eval(winOnLoadEvents[i]);
}

function winOnLoadAdd(func){
	winOnLoadEvents[winOnLoadEvents.length] = func;
}
var winOnLoadEvents = new Array();

winOnLoadAdd('resetWindowSize();');
winOnLoadAdd('setNavigation();');
winOnLoad();

window.onresize = new Function("resetWindowSize();");

// Browser Detection 
function BrowserCheck() {
	var b = navigator.appName;	
	if (b=="Netscape") this.b = "ns";
	else if (b=="Microsoft Internet Explorer") this.b = "ie";
	else this.b = b;
	this.version = navigator.appVersion;
	//if (this.version.indexOf('Win')>0) this.os = "PC";
	//else if (this.version.indexOf('Mac')>0) this.os = "Mac";	
	this.WinOs = (this.version.indexOf('Win')>0);
	this.v = parseInt(this.version);
	this.ns = (this.b=="ns" && this.v>=4);
	this.ns4 = (this.b=="ns" && this.v==4);
	this.ns5 = (this.b=="ns" && this.v>=5);
	this.ie = (this.b=="ie" && this.v>=4);
	this.ie4 = (this.version.indexOf('MSIE 4')>0);
	this.ie5 = (this.version.indexOf('MSIE 5')>0);
	this.ie6 = (this.version.indexOf('MSIE 6')>0);
	this.min = (this.ns||this.ie);
}
var browser = new BrowserCheck();

/***********************************************
* Dynamic Ajax Content-  Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
document.getElementById(containerid).innerHTML=page_request.responseText;
}
}




function setTabOn(tab,pageURL,divID){
	var e=document.getElementsByTagName("div");
	for(var i=0;i<e.length;i++){							
		if(e[i].className.indexOf("contentTab_Links") > -1){														
			var k=e[i].getElementsByTagName("li");								
			for(var n=0;n<k.length;n++){									
				if (k[n].innerHTML.indexOf(tab.innerHTML) > -1){
					k[n].className = 'tabOn';
					ajaxpage(pageURL, divID);
				}else{
					k[n].className = '';
				}									
			}	
		}
	}
}

function popWindow(url, width, height, name, scrollbars){
	if (!scrollbars) scrollbars = false;
	if (!width) width = 500;
	if (!height) height = 500;
 	var realW = (width)/2;
	var realH = (height)/2;
 	if (document.all){		
        var xMax = screen.width, yMax = screen.height;
    }else if (document.layers){       
        var xMax = screen.width, yMax = screen.height;
    }else if (document.getElementById){
		var xMax = screen.width, yMax = screen.height;
	}else{
		var xMax = 800, yMax=600;
	}
	var xOffset = ((xMax)/2) - realW, yOffset = (((yMax)/2)) - realH; 
	if (yMax==600){
		yOffset = 0;
	}	
	
	if (scrollbars) {
		var options = "directories=no,status=no,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=no" + ",screenX=" + xOffset + ",screenY=" + yOffset + ",top=" + yOffset + ",left=" + xOffset + ",width=" + width + ",height=" + height;
	}else{
		var options = "directories=no,status=no,location=no,scrollbars=no,menubar=no,toolbar=no,resizable=no" + ",screenX=" + xOffset + ",screenY=" + yOffset + ",top=" + yOffset + ",left=" + xOffset + ",width=" + width + ",height=" + height;
	}
	
	if (!name) name = "default_window";
	
	popup = window.open(url,name,options);
	popup.focus();	
}


var timerID;
var timeout = 500;

function overMenuParent(listId){	
	if (timerID) clearTimeout(timerID);
	tempClassName = listId.className;	
	if (tempClassName.indexOf("NavOver") == -1 && tempClassName.indexOf("NavNoChildOver") == -1){
		closeMenus();			
		displayChildMenu(listId);					
	}	
}
function overChildMenu(){
	if (timerID) clearTimeout(timerID);		
}
function displayChildMenu(listId){
	navRoot = getElmtRef("gblMainNavList");
	navContainer = getElmtRef("gblMainNav");
	for (i=0; i<navRoot.childNodes.length; i++) {				
		node = navRoot.childNodes[i];			
		if (node==listId) {					
			for (j=0; j<node.childNodes.length; j++) {	
				node2 = node.childNodes[j];				
				if (node2.nodeName=="UL") {		
													
					node.className = tempClassName + ' NavOver';	
					node2.style.display = "block";	
					
					leftPosition = 0;
					topPosition = 0;
					
					if(findGlobalPosX(listId) != 0){
						leftPosition = findGlobalPosX(listId) + 1;
					}
					
					if (leftPosition + node2.offsetWidth > getElmtRef("page").offsetWidth){
						leftPosition = (findGlobalPosX(listId) + listId.offsetWidth) - node2.offsetWidth;
					}	
					
					node2.style.left = leftPosition+'px';
					
					node2.style.top = topPosition + navContainer.offsetHeight +'px';
					
					hideShowSelectBox(findGlobalPosX(node2),findGlobalPosY(node2),node2.offsetWidth,node2.offsetHeight);
					
					if(browser.ie6){						
						linkWidth = node2.offsetWidth - 2;					
						for(var z=0;z<node2.childNodes.length;z++){	
							var x=node2.childNodes[z].getElementsByTagName("a");
							for(var y=0;y<x.length;y++){							
								x[y].style.width = (linkWidth - 45)+ "px";																
							}									
						}
					}
					
					node2.style.visibility = "visible";	
									
					break;
				}else{					
					node.className = tempClassName + ' NavNoChildOver';	
				}
			}						
		}
	}	
}
function offMenuParent(listId){
	timerID = setTimeout('closeMenus();',timeout);
}

function closeMenus(){	
	showAllSelectBoxes();
	navRoot = getElmtRef("gblMainNavList");
	for (i=0; i<navRoot.childNodes.length; i++) {				
		node = navRoot.childNodes[i];			
		if (node.nodeName=="LI") {	
			for (j=0; j<node.childNodes.length; j++) {	
				node2 = node.childNodes[j];				
				if (node2.nodeName=="UL") {						
					if (node.className.indexOf("NavOver") > -1){											
						if (node.className.indexOf(" ") > -1){
							beginSpace = node.className.indexOf(" NavOver");
							node.className = node.className.substr(0,beginSpace);								
						}else{
							node.className = '';
						}	
					}	
					node2.style.visibility = "hidden";	
					node2.style.display = "none";								
					break;
				}else{					
					if (node.className.indexOf("NavNoChildOver") > -1){											
						if (node.className.indexOf(" ") > -1){
							beginSpace = node.className.indexOf(" NavNoChildOver");
							node.className = node.className.substr(0,beginSpace);								
						}else{
							node.className = '';
						}	
					}
				}
			}	
		}
	}	
}



function hideShowSelectBox(menuLeftPos,menuTopPos,menuWidth,menuHeight){	
	for(slectLoop1=0;slectLoop1<document.forms.length;slectLoop1++){		
		for(slectLoop2=0;slectLoop2<document.forms[slectLoop1].elements.length;slectLoop2++){			
			if(document.forms[slectLoop1].elements[slectLoop2].type.indexOf("select") > -1){
				var tempSelectY = findGlobalPosY(document.forms[slectLoop1].elements[slectLoop2]);
				var tempSelectX = findGlobalPosX(document.forms[slectLoop1].elements[slectLoop2]);
				var tempSelectWidth = document.forms[slectLoop1].elements[slectLoop2].offsetWidth;
				var tempSelectHeight = document.forms[slectLoop1].elements[slectLoop2].offsetHeight;
				if((tempSelectY <= menuTopPos + menuHeight && tempSelectY + tempSelectHeight >= menuTopPos ) && ((tempSelectX <= menuLeftPos && menuLeftPos <= (tempSelectWidth + tempSelectX)) || ((menuLeftPos <= tempSelectX) && (menuLeftPos + menuWidth > tempSelectX)))){
					document.forms[slectLoop1].elements[slectLoop2].style.visibility = 'hidden';
				}else{
					document.forms[slectLoop1].elements[slectLoop2].style.visibility = 'visible';
				}
			}
		}
	}

}

function showAllSelectBoxes(){
	for(i=0;i<document.forms.length;i++){		
		for(j=0;j<document.forms[i].elements.length;j++){			
			if(document.forms[i].elements[j].type.indexOf("select") > -1){					
				document.forms[i].elements[j].style.visibility = 'visible';					
			}
		}
	}
}


function getElmtRef(strElmtId) {
	if (!document.getElementById) {
		return document.all[strElmtId];
	} else {
		return document.getElementById(strElmtId);
	}
}
function findGlobalPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
		curleft += obj.x;
	}
	return curleft;
}

function findGlobalPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
		curtop += 1;
	} else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  //return [ scrOfX, scrOfY ];
  return scrOfY;
}

function resetWindowSize(){	
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		window_width = window.innerWidth;
		window_height = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		window_width = document.documentElement.clientWidth;
		window_height = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		window_width = document.body.clientWidth;
		window_height = document.body.clientHeight;
	}
}



function setNavigation() {		
	if(getElmtRef("gblMainNavList")){
		navRoot = getElmtRef("gblMainNavList");
		for (i=0; i<navRoot.childNodes.length; i++) {				
			node = navRoot.childNodes[i];			
			if (node.nodeName=="LI") {						
				node.onmouseover=function() {
					overMenuParent(this);
				}
				node.onmouseout=function() {
					offMenuParent(this);
				}						
			}
		}	
	}
}
//window.onload=startList;





/* Code for Layer Pop Ups*/
function dynInfo(linkObj,header,content){
	closeDynInfo();	
	getElmtRef("popDynInfoHeader").innerHTML = header;
	getElmtRef("popDynInfoContent").innerHTML = content;
	getElmtRef("popDynInfoContainer").style.display = 'block';	
	
	var popLayerXpos = findGlobalPosX(getElmtRef("popDynInfoContainer"));
	var popLayerYpos = findGlobalPosY(getElmtRef("popDynInfoContainer"));
	var popLayerHeight = getElmtRef("popDynInfoContainer").offsetHeight;
	var popLayerWidth = getElmtRef("popDynInfoContainer").offsetWidth;
	var popLayerArrowWidth = getElmtRef("popDynArrow").offsetWidth;
	var popLayerArrowHeight = getElmtRef("popDynArrow").offsetHeight;
	var pageWidth = getElmtRef("page").offsetWidth;	
	
	var arrowTopPos = ((popLayerHeight / 2) - (popLayerArrowHeight / 2));	
	var topPos = (findGlobalPosY(linkObj) - (popLayerHeight / 2));	

	if (topPos - getScrollXY() + popLayerHeight > window_height){		
		tempDifference = topPos - getScrollXY() + popLayerHeight - window_height;		
		topPos = topPos - tempDifference;
		arrowTopPos = arrowTopPos + tempDifference;
		if(arrowTopPos + popLayerArrowHeight > popLayerHeight){
			arrowTopPos = popLayerHeight - popLayerArrowHeight - 2;
		}	
	}else if (topPos - getScrollXY() < 0){		
		tempDifference = topPos - getScrollXY();
		topPos = topPos - tempDifference;
		arrowTopPos = arrowTopPos + tempDifference + 2;	
		if(arrowTopPos < 1){
			arrowTopPos = 2;
		}		
	}
	
	getElmtRef("popDynInfoContainer").style.top = topPos + 'px';
	
	var leftPos = findGlobalPosX(linkObj) + linkObj.offsetWidth + popLayerArrowWidth;
	
	if(leftPos + popLayerWidth > pageWidth){
		leftPos = findGlobalPosX(linkObj) - popLayerWidth - popLayerArrowWidth;
		getElmtRef("popDynArrow").style.left = popLayerWidth - 3 + 'px';
		getElmtRef("popDynArrow").className = 'right';
	}else{		
		getElmtRef("popDynArrow").style.left = 0 - popLayerArrowWidth + 'px';
		getElmtRef("popDynArrow").className = 'left';
	}
		
	getElmtRef("popDynArrow").style.top = arrowTopPos + 'px';
	getElmtRef("popDynInfoContainer").style.left = leftPos + 'px';	
	
	hideShowSelectBox(leftPos,topPos,popLayerWidth,popLayerHeight);
	
	getElmtRef("popDynInfoContainer").style.visibility = 'visible';

}

function closeDynInfo(){
	showAllSelectBoxes();
	getElmtRef("popDynInfoContainer").style.visibility = 'hidden';
	getElmtRef("popDynInfoContainer").style.display = 'none';
	getElmtRef("popDynInfoContainer").style.top = '0px';
	getElmtRef("popDynInfoContainer").style.left = '0px';
	getElmtRef("popDynArrow").className = '';
	getElmtRef("popDynInfoHeader").innerHTML = '';
	getElmtRef("popDynInfoContent").innerHTML = '';
}

//Form Inputs (Text) Clear and Replace
function addEvent(element, eventType, lamdaFunction, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(eventType, lamdaFunction, useCapture);
        return true;
    } else if (element.attachEvent) {
        var r = element.attachEvent('on' + eventType, lamdaFunction);
        return r;
    } else {
        return false;
    }
}

// pknoll 6/7/2007
//
// This event handler functionality is causing problems with dsp:input tags which set "value=" from bean properties.
// if the clear/replace default text functionality is required, a separate function should be written to set these
// using another method than the "value" attribute 

/*addEvent(window, 'load', init, false);

function init() {
    var formInputs = document.getElementsByTagName('input');
    for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        
        if (theInput.type == 'text') {  
	    // Add event handlers
            addEvent(theInput, 'focus', clearDefaultText, false);
            addEvent(theInput, 'blur', replaceDefaultText, false);
			
       // Save the current value 
            if (theInput.value != '') {
                theInput.defaultText = theInput.value;
            }
        }
    }
}
*/
function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == target.defaultText) {
        target.value = '';
    }
}

function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == '' && target.defaultText) {
        target.value = target.defaultText;
    }
}

/* Homepage Cursor Trail */
function trailLayerobj(){
	if (document.getElementById)
	return document.getElementById("homeProductCursorTrail").style
	else if (document.all)
	return document.all.homeProductCursorTrail.style
}

function docBodyType(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

var cursoroffset=[20,-10]

var cursorTimerID;
var cursorTimecount = 200;
var bolProdLayerShown = false;

function trailCursor(e){
	if (cursorTimerID) clearTimeout(cursorTimerID);
	var xcoordinate=cursoroffset[0]
	var ycoordinate=cursoroffset[1]
	if (typeof e != "undefined"){
		xcoordinate+=e.pageX
		ycoordinate+=e.pageY
	}
	else if (typeof window.event !="undefined"){
		xcoordinate+=docBodyType().scrollLeft+event.clientX
		ycoordinate+=docBodyType().scrollTop+event.clientY
	}		
	trailLayerobj().left=xcoordinate+"px"
	trailLayerobj().top=ycoordinate+"px"
	
	if (!bolProdLayerShown){
		trailLayerobj().visibility="visible";
		trailLayerobj().display="";
		bolProdLayerShown = true;
	}
}

function completeHideLayer(){		
	trailLayerobj().visibility="hidden";
	bolProdLayerShown = false;
}

function hideTrailLayer(){
	cursorTimerID = setTimeout('completeHideLayer();',cursorTimecount);	
}

function initCursorTrail(){
getElmtRef("home_product_bkgnd").onmousemove=trailCursor
getElmtRef("home_product_bkgnd").onmouseout=hideTrailLayer
}

