//########## Pop up script for HOTPICKS ##########
function popWinCenter(purl, winWidth, winHeight) {
		var pheight = winHeight;
		var pwidth = winWidth;
		var params;
		
		if (window.screen) {
			if (screen.availHeight <= 600) {
				pheight = 480;
			}

			params = "height=" + pheight + ",innerHeight=" + pheight;
			params += ",width=" + pwidth + ",innerWidth=" + pwidth;
		
			var ah = screen.availHeight - 30;
			var aw = screen.availWidth - 10;
			var xc = (aw - pwidth) / 2;
			var yc = (ah - pheight) / 2;
			params += ",left=" + xc + ",screenX=" + xc;
			params += ",top=" + yc + ",screenY=" + yc;
		}
	
		if (screen.availHeight <= 600 && !isNN)
        {
            params += ',resizable,scrollbars';
        }

		if (screen.availHeight <= 600 && isNN)
        {
            params += ',scrollbars=yes,resizable=yes';
        }

		window.open(purl,'',params);
	}

//########## custom dropdown form trigger ##########
function customdd(parentID,hiddenFlID,layerID,myVal) {
	document.getElementById(parentID).innerHTML = myVal;
	document.getElementById(hiddenFlID).value = myVal;
	hideLyr(layerID);
}


//########## swap graphic form buttons on click ##########
//customize values as necessary
//function updated to find ID instead of NAME

//radio buttons
rdboff=new Image();
rdboff.src="/images/en/sites/corp/btn_radio_off.gif";
rdbon=new Image();
rdbon.src="/images/en/sites/corp/btn_radio_on.gif";

//checkboxes
chboff=new Image();
chboff.src="/images/en/sites/corp/btn_checkbox_off.gif";
chbon=new Image();
chbon.src="/images/en/sites/corp/btn_checkbox_on.gif";

function changeImages() {
	for (var i=0; i<changeImages.arguments.length; i+=2) {
		document.getElementById(changeImages.arguments[i]).src = eval(changeImages.arguments[i+1] + ".src");
	}
}


//########## custom radio button form trigger ##########
//this version is obsolete; use NEW function below which is generic and reusable for any number of radio button sets
function doRadio(el) {
	if(el=='b1') {
		changeImages(el,'rdbon');
		changeImages('b2','rdboff');
		document.GT.Radio_1.value="I am " + el;
	}
	if(el=='b2') {
		changeImages(el,'rdbon');
		changeImages('b1','rdboff');
		document.GT.Radio_1.value="I am " + el;
	}
}

//########## NEW custom radio button form trigger ##########
//new function can now figure out on the fly how many radios are in each group based on prefix in ID
//in HTML, use same prefix for selfID for each set separated by a number in succession; use corresponding ID in IMG tag so it can swap the image
//e.g. search_1 and search_2 are two radio buttons of the same set
//e.g. purchase_1 and purchase_2 are two radio buttons of the same set
//e.g. there is no limit to the number of radios per set
//NOTE: all radio buttons in the HTML are now optimized to get rid of unnecessary DIV tags for easier usage (THIS VERSION IS RECOMMENDED)
function customrad(selfID,hiddenFlID,myVal) {
	var radArr = selfID.split('_');
	changeImages(selfID,'rdbon');
	document.getElementById(hiddenFlID).value = myVal;
	var my_img=document.getElementsByTagName("IMG");
	for (var i=0; i<my_img.length; i++) {
		if(my_img[i].id.match(radArr[0])) {
			if (my_img[i].id != selfID) {
				changeImages(my_img[i].id,'rdboff');
			}
		}
	}
}


//########## custom checkbox button form trigger ##########
function customchb(selfID,hiddenFlID) {
	var chkStatus = document.getElementById(hiddenFlID).value;
	if (chkStatus == 1) {
		changeImages(selfID, 'chboff');
		document.getElementById(hiddenFlID).value = 0;
	} else {
		changeImages(selfID, 'chbon');
		document.getElementById(hiddenFlID).value = 1;
	}
}


//########## main nav button rollovers ##########
function showhidebtn(id) {
	if (document.getElementById(id+'b').className == 'l1btnbgmid') {
		document.getElementById(id+'a').className = 'l1btnbglefton';
		document.getElementById(id+'b').className = 'l1btnbgmidon';
		document.getElementById(id+'c').className = 'l1btnbgrighton';
	} else {
		document.getElementById(id+'a').className = 'l1btnbgleft';
		document.getElementById(id+'b').className = 'l1btnbgmid';
		document.getElementById(id+'c').className = 'l1btnbgright';
	}
}


//########## custom dropdown menu ##########
//all functions below for custom dropdowns are update
//new functions use unique timers for each dropdown to avoid stray layers from getting "stuck" when mousing over more than one in succession
//NOTE: all custom dropdowns in the HTML are now optimized to get rid of unnecessary DIV tags for easier usage (THIS VERSION IS RECOMMENDED)

//initialize a flag to ID unique layers to trigger timeout;
var idFlag;

//initialize all dropdown timer names; passed by unique hidden layer ID
//must include a master list of all hidden layer IDs (this matches the ID of all hidden ULs
//NOTE: must use for maximum usability and client side (browser) compatibility
var dd_storelocations;
var dd_province;
var dd_province_CH;
var dd_units01;
var dd_units02;
var dd_units03;
var dd_units04;
var dd_units05;
var dd_cardtype;
var dd_cardmonth;
var dd_cardyear;
var dd_purchasesupplies;
var dd_employeenumber;
var dd_shoppingexperience;

//update case statement to match the master list of hidden layer IDs
function stopTr(whichLyr){
	idFlag = whichLyr;
	switch (whichLyr) {
		case "dd_storelocations":
			clearTimeout(dd_storelocations);
			break
		case "dd_province":
			clearTimeout(dd_province);
			break
		case "dd_province_CH":
			clearTimeout(dd_province_CH);
			break
		case "dd_units01":
			clearTimeout(dd_units01);
			break
		case "dd_units02":
			clearTimeout(dd_units02);
			break
		case "dd_units03":
			clearTimeout(dd_units03);
			break
		case "dd_units04":
			clearTimeout(dd_units04);
			break
		case "dd_units05":
			clearTimeout(dd_units05);
			break
		case "dd_cardtype":
			clearTimeout(dd_cardtype);
			break
		case "dd_cardmonth":
			clearTimeout(dd_cardmonth);
			break
		case "dd_cardyear":
			clearTimeout(dd_cardyear);
			break
		case "dd_purchasesupplies":
			clearTimeout(dd_purchasesupplies);
			break
		case "dd_employeenumber":
			clearTimeout(dd_employeenumber);
			break
		case "dd_shoppingexperience":
			clearTimeout(dd_shoppingexperience);
			break
	}
}

//update case statement to match master list of hidden layer IDs
function startTr(whichLyr){
	if (whichLyr != undefined){
		switch (whichLyr) {
		case "dd_storelocations":
			dd_storelocations = setTimeout("hideLyr('" + whichLyr + "')", 500);
			break
		case "dd_province":
			dd_province = setTimeout("hideLyr('" + whichLyr + "')", 500);
			break
		case "dd_province_CH":
			dd_province_CH = setTimeout("hideLyr('" + whichLyr + "')", 500);
			break
		case "dd_units01":
			dd_units01 = setTimeout("hideLyr('" + whichLyr + "')", 500);
			break
		case "dd_units02":
			dd_units02 = setTimeout("hideLyr('" + whichLyr + "')", 500);
			break
		case "dd_units03":
			dd_units03 = setTimeout("hideLyr('" + whichLyr + "')", 500);
			break
		case "dd_units04":
			dd_units04 = setTimeout("hideLyr('" + whichLyr + "')", 500);
			break
		case "dd_units05":
			dd_units05 = setTimeout("hideLyr('" + whichLyr + "')", 500);
			break
		case "dd_cardtype":
			dd_cardtype = setTimeout("hideLyr('" + whichLyr + "')", 500);
			break
		case "dd_cardmonth":
			dd_cardmonth = setTimeout("hideLyr('" + whichLyr + "')", 500);
			break
		case "dd_cardyear":
			dd_cardyear = setTimeout("hideLyr('" + whichLyr + "')", 500);
			break
		case "dd_purchasesupplies":
			dd_purchasesupplies = setTimeout("hideLyr('" + whichLyr + "')", 500);
			break
		case "dd_employeenumber":
			dd_employeenumber = setTimeout("hideLyr('" + whichLyr + "')", 500);
			break
		case "dd_shoppingexperience":
			dd_shoppingexperience = setTimeout("hideLyr('" + whichLyr + "')", 500);
			break
		}
	}
}

//obj is the dropdown menu button
//lyr is the ID of the hidden menu list layer, ID must be unique
function showLyr(obj,lyr) {
	stopTr(lyr);
	var dimensions = findDim(obj);
	var x = document.getElementById(lyr);
	if (x.offsetWidth > dimensions[2]) { //if the menu list layer is wider than the menu button, set it to new width
		dimensions[2] = x.offsetWidth - 2;
	}
	x.style.left = dimensions[0] + 'px';
	x.style.top = dimensions[1] + 'px';
	x.style.width = dimensions[2] + 'px';
	x.style.visibility = 'visible';
}

function hideLyr(lyr) {
	document.getElementById(lyr).style.visibility='hidden';
}

//figure out position of dropdown button
function findDim(obj) { 
	var curleft = curtop = curwidth = 0;
	if (obj.offsetParent) { 
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		curwidth = obj.offsetWidth - 2;
		while (obj = obj.offsetParent) { 
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} 
	} 
	return [curleft,curtop,curwidth]; 
}

//used to hide menu list layer when mouse rolls out
function killtrigger(e,lyr) {
	if (!e) var e = window.event;
	var relTarg = e.relatedTarget || e.toElement;
	if (lyr == idFlag) {
		startTr(lyr);
	}
	if (relTarg != null)
	{
		if(relTarg.nodeName !='#text' && relTarg.nodeName !='A' && relTarg.nodeName !='LI' && relTarg.nodeName !='UL') 
		{
			startTr(lyr);
		}
	}
}

//IE hack for LI onmouseover
sfHover = function() {
	var my_ul=document.getElementsByTagName("UL");
	for(j=0, x=my_ul.length; j<x; j++){
		if(my_ul[j].id.match("dd_")) {
			var sfEls = my_ul[j].getElementsByTagName("LI");
			for (var i=0; i<sfEls.length; i++) {
				sfEls[i].onmouseover=function() {
					this.className="hover";
				}
				sfEls[i].onmouseout=function() {
					this.className="";
				}
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
