//Define PopupWindow process
function winopen(filenamewtoken,winWidth,winHeight,whichwindow) {
	closechild(); 
 	if (document.all) {	var xMax = screen.width, yMax = screen.height;
    } else {
		if (document.layers) { var xMax = window.outerWidth, yMax = window.outerHeight;
        } else { var xMax = 800, yMax=600; }
	}
	var xOffset = (xMax - winWidth)/2, yOffset = ((yMax - winHeight)/2) - 30;
	//Whichwindow == 1 -- No Scrolls, no Menu
	//Whichwindow == 2 -- Scrolls, no Menu
	//Whichwindow == 3 -- Scrolls, Menu
	//Whichwindow == 4 -- Custom: for shopping cart popup window
	if (whichwindow == 1) { PopupWindow = window.open(filenamewtoken,'PopupWindow', 'screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,hotkeys=no,resizable=no,width='+winWidth+',height='+winHeight+'');
	} else if (whichwindow == 2) { PopupWindow = window.open(filenamewtoken,'PopupWindow', 'screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,hotkeys=no,resizable=no,width='+winWidth+',height='+winHeight+'');
	} else if (whichwindow == 4) { PopupWindow = window.open(filenamewtoken,'PopupWindow', 'screenX='+1+',screenY='+yOffset+',top='+yOffset+',left='+1+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,hotkeys=no,resizable=no,width='+winWidth+',height='+winHeight+'');
	} else { PopupWindow = window.open(filenamewtoken,'PopupWindow', 'screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+',toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,hotkeys=no,resizable=no,width='+winWidth+',height='+winHeight+'');
	}
	if (!PopupWindow.opener) { PopupWindow.opener = self; }
	PopupWindow.focus();
	if (PopupWindow && PopupWindow.open && !PopupWindow.closed) {
	 	if (document.all && PopupWindow.document && PopupWindow.document.body && PopupWindow.document.body.clientWidth) {	
			if (Math.abs(winWidth-PopupWindow.document.body.clientWidth) > 30) { winopen(filenamewtoken,winWidth,winHeight,whichwindow); }
	    } else if (PopupWindow.innerWidth) {
			if (Math.abs(winWidth-PopupWindow.window.innerWidth) > 30) { winopen(filenamewtoken,winWidth,winHeight,whichwindow); }
		}
	}
}

//This function closes the PopupWindow if it is open when the main page is redirected
var PopupWindow = '';
function closechild() { if (PopupWindow && PopupWindow.open && !PopupWindow.closed) { PopupWindow.close(); } }

//Pre-Load top navigation rollover imagery
if (window.imageNameArray1) {
	for (var i=0;i<imageNameArray1.length;i++) {
		eval(imageNameArray1[i]+'_up = new Image();'+imageNameArray1[i]+'_up.src = "'+temprooturlpath+'images/navigation/'+imageNameArray1[i]+'_up.gif"');
		eval(imageNameArray1[i]+'_down = new Image();'+imageNameArray1[i]+'_down.src = "'+temprooturlpath+'images/navigation/'+imageNameArray1[i]+'_down.gif"');
	}
}
if (window.imageNameArray2) {
	for (var i=0;i<imageNameArray2.length;i++) {
		eval(imageNameArray2[i]+'_up = new Image();'+imageNameArray2[i]+'_up.src = "'+temprooturlpath+'images/rollover_buttons/'+imageNameArray2[i]+'_up.png"');
		eval(imageNameArray2[i]+'_over = new Image();'+imageNameArray2[i]+'_over.src = "'+temprooturlpath+'images/rollover_buttons/'+imageNameArray2[i]+'_over.png"');
		eval(imageNameArray2[i]+'_down = new Image();'+imageNameArray2[i]+'_down.src = "'+temprooturlpath+'images/rollover_buttons/'+imageNameArray2[i]+'_down.png"');
	}
}

//Mouse fire functions
var deactivatemouse = 0;
function mouseup(name) { if (deactivatemouse == 0) { document[name].src = eval(name + "_up.src"); } }
function mouseover(name) { if (deactivatemouse == 0) { document[name].src = eval(name + "_over.src"); } }
function mousedown(name) { if (deactivatemouse == 0) { document[name].src = eval(name + "_down.src"); } }

//Enter key press trap
function TrapEnterKeyPress(e) {
	var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode; 
	if (keyCode == 13) { return false; } else { return true; }
}

//Automatically closes window
function WindowManagement(someminutes) {
  	var myTimer = null;
	myTimer = setTimeout('window.close();',(someminutes*60000));
}
