/**********************************************************************************************
This is the global javascript repository for the GE Store (as of the 2006 redesign).
**********************************************************************************************/


// global vars

var popupWin;
var scrnwidth=screen.width;
var scrnheight=screen.height;



/**********************************************************************************************
 "only 1 open at a time" popup function.

The fifth argument, windowname, is optional.  If specified, it is passed as the second argument 
to window.open().  This is required in order to leave the popup opener page (without closing 
the popup), come back to it, and NOT have a duplicate popup window.

**********************************************************************************************/
function openPopUp (url, width, height, addloptions, windowname) {

	if (windowname == null) {
		windowname = "";
	}

	var xspot = Math.round((scrnwidth/2)-(width/2));
	var yspot = Math.round((scrnheight/2)-(height/2)-30);

	features = "height="+height+",width="+width+",top="+yspot+",screenY="+yspot+",left="+xspot+",screenX="+xspot;

	if (addloptions && addloptions!="") { features += ","+addloptions; }

	if (!popupWin || popupWin.closed) {
		popupWin = window.open(url, windowname, features);
	} else {
		window.popupWin.close();	
		popupWin = window.open(url, windowname, features);
	}
}

function closepopups(){
	if (popupWin && popupWin.open){
		window.popupWin.close();
	}
}



//	Function to View Larger Image, View Control Panel Image of SKU.
//	Opens window which contains ONLY a 480 x 500 image
function openLarger(imgurl) {
var largerWin;
	if (!largerWin || largerWin.closed) {
		largerWin = window.open("","","width=480,height=500");
	}
	else {
		window.largerWin.close();
		largerWin = window.open("","","width=480,height=500");
	}
	drawstr =  '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
	drawstr += '<html><head><title>Larger Photo</title></head>';
	drawstr += '<body bgcolor="white" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0">';
	drawstr += '</body></html>';
	largerWin.document.open();
	largerWin.document.write(drawstr);
	largerWin.document.close();
	largerWin.document.location=imgurl;
}

// Function to open the Photo Gallery in a window 590 x 750
function photoGallery(url)
{
	newwindow=window.open(url,'name','height=590,width=750');
	if (window.focus) {newwindow.focus()}
}




/**********************************************************************************************
 This function unhides, sizes, and positions a specified "tooltip" div on the click of a link.
 
 All 'tooltips' for a given page should be have a class of "tooltipDiv" and a unique ID.

The basic "a" tag to call this function is as follows, where the user specifies the ID of the
tooltip to be displayed and the width at which the tooltip should be displayed:
 
 <a href="javascript:void(0);" onclick="showTooltip(divID,width,event);">
 
**********************************************************************************************/
function showTooltip(divID,divWidth,event) {
	
	
	hideAllTooltips();		// comment out to allow multiple tooltips on the screen at one time
	//pushbackTooltips();	// comment out to allow a only single tooltip on the screen at one time
	
	
	// if div with id of 'divID' exists, function will run normally, otherwise it will do nothing //
	if(document.getElementById(divID)) { 
			
		// get tooltip[x] //
		var obj = document.getElementById(divID);
			
		obj.style.width = divWidth+"px";
		obj.style.zIndex = 1005;
		
			var ww = document.documentElement.clientWidth;		
			var wh = document.documentElement.clientHeight;
			var st = document.documentElement.scrollTop;
			var sl = document.documentElement.scrollLeft;
			var sh = document.documentElement.scrollHeight;
			var docWidth = document.getElementById('document').clientWidth;
			var sideMargin = (ww - docWidth) / 2;
			var divHeight = obj.clientHeight;
		
		
		//get mouse coordinates
		var root = document.documentElement || document.body;
		mouseX = event.clientX + root.scrollLeft;
		mouseY = event.clientY + root.scrollTop;
				
		
		//set initial tooltip[x] position //
		xpt = mouseX - (divWidth / 2);
		ypt = mouseY + 10;
		
		
		// testing the document/window boundaries //
		if (sideMargin > 0 && xpt < sideMargin) {
			var xpt = sideMargin + 25;
		}	
		if(xpt < 20) {
			var xpt = 20;
		}
		if(ww < divWidth) {
			var xpt = sl + 20;
		}
		if (sideMargin > 0 && (xpt + divWidth + 20) > (sideMargin + docWidth)) {
			var xpt = (sideMargin + docWidth) - divWidth - 30;
		} else if(sideMargin < 0 && (xpt + divWidth) > docWidth) {
			xpt = docWidth - divWidth - 30;
		}	
		if ((ypt + divHeight + 10) > sh) {
			var ypt = ypt - divHeight - 35;
		}	
		
		
		//set definite tooltip[x] position //
		obj.style.left = xpt+"px"; 
		obj.style.top = ypt+"px";	
		
		
		// show tooltip[x] //
		obj.style.visibility = "visible";
	}
			
}



/*** This function is used on the tooltip close button to hide the tooltip. ***/
function hideTooltip(nodeObj)	{
	while(!nodeObj.className || !/\btooltipDiv\b/.test(nodeObj.className))	{
		nodeObj = nodeObj.parentNode;
	}
	nodeObj.style.visibility = "hidden";
}



/*** This function hides all open tooltips ***/
function hideAllTooltips() {
	// determine which divs are tooltips and hide any open tooltips //
	var tooltipDivArray = document.getElementsByTagName('div');
	for (var j = 0; j < tooltipDivArray.length; ++j) {
		var tooltipDiv = tooltipDivArray[j];
		if (!tooltipDiv.className || !/\btooltipDiv\b/.test(tooltipDiv.className)) {
			continue;
		}
		tooltipDiv.style.visibility = "hidden";
	}
}

/*** This function pushes open tooltips behind a newly opened tooltip ***/
function pushbackTooltips() {
	// determine which divs are tooltips and hide any open tooltips //
	var tooltipDivArray = document.getElementsByTagName('div');
	for (var j = 0; j < tooltipDivArray.length; ++j) {
		var tooltipDiv = tooltipDivArray[j];
		if (!tooltipDiv.className || !/\btooltipDiv\b/.test(tooltipDiv.className)) {
			continue;
		}
		tooltipDiv.style.zIndex -= 5;
	}
}



/*** This will cause any open tooltip to close if the page is resized. ***/
window.onresize = hideAllTooltips;




/************************************************************************
This function reads the initial size of the browser window and defines a
reasonable size for the iframe in the page. Minimum iframe size is set to
425px. Maximum will be as large as the window can allow.
************************************************************************/
function smartIframeSize()	{
	var wh = document.documentElement.clientHeight;
	var frameHeight = wh - 245;
	if(frameHeight < 425) {
		var frameHeight = 425;
	}
document.writeln('<style type="text/css">');
	document.writeln('#smartIframe {height:'+frameHeight+'px;}');
document.writeln('</style>');
}


/************************************************************************
This selects and styles the current "tab" in the top nav based on values
provided in an associative array.
************************************************************************/
var tabGroups = new Array();
tabGroups["homeTab"] = new Array("home");
tabGroups["productsTab"] = new Array("products");
tabGroups["salesRebatesTab"] = new Array("sales_rebates");
tabGroups["customerServiceTab"] = new Array("cust_service");
tabGroups["deliveryInstallationTab"] = new Array("delivery_installation");

function selectActiveTab(selectedTab) {
	
	//alert(".."+selectedTab);
	//var ourUrl = top.document.location.href + "";
	var ourUrl = selectedTab;
	var tabChosen = "none";
	
	for (var i in tabGroups) {	
		arry = tabGroups[i];
	
		for (var j in arry) {	
			if (arry[j] == ourUrl) {	
				tabChosen = i;
				//alert("Inside of IF");
			}
			
		}
	
	}
	
	if((tabChosen != "none") && (document.getElementById(tabChosen)!=null)) {
		//alert("Inside selected");
		//alert("Value >>>>>"+document.getElementById(tabChosen));
		document.getElementById(tabChosen).className += " gestore_header_selected";
	}
	else{//alert("Nothing is selected");
	}
}

/*function selectActiveTab() {
	
}*/
