// ---------------------------------------------------------
//	GLOBAL VARIABLES
//----------------------------------------------------------
var popWin;
var popWintype;
var ie;

ie = (document.all) ? true : false;

/* -----------------------------------------------
FUNCTION: helpModLvl 
DESC: Create a module level pop up window
ARGS:
	hrefTarget - url to be opened
-------------------------------------------------*/
function helpModLvl(hrefTarget) {
	//Set Variables
	var name, width, height;
	name = "helpModLvl";
	width="463";
	height="500";
	// Pop up the window
	popWindow(hrefTarget,name,width,height,resizable="yes");
}

/* -----------------------------------------------
FUNCTION: helpFieldLvl 
DESC: Create a field level pop up window
ARGS:
	hrefTarget - url to be opened
-------------------------------------------------*/
function helpFieldLvl(hrefTarget) {
//Set Variables
	var name, width, height;
	name = "helpFieldLvl";
	width="323";
	height="500";
	popWindow(hrefTarget,name,width,height,resizable="yes");
}

/* -----------------------------------------------
FUNCTION: printerFriend 
DESC: Create a printer friendly pop up window
ARGS:
	hrefTarget - url to be opened
-------------------------------------------------*/
function printerFriend(hrefTarget) {
//Set Variables
	var name, width, height;
	name = "printerVersion";
	width="603";
	height="500";
	popWindow(hrefTarget,name,width,height,resizable="yes");
}
/* -----------------------------------------------
FUNCTION: newWindow 
DESC: Create a new browser window
ARGS:
	hrefTarget - url to be opened
-------------------------------------------------*/
function newWindow(hrefTarget) {
//Set Variables
	window.open(hrefTarget)
}

/* -----------------------------------------------
FUNCTION: popWindow 
DESC: Opens a window and positions it on the screen

ARGS:
	hrefTarget - url to be opened
	name - name of popup window (becomes popuptype)
	width - width of the pop up window
	height - height of the pop up window
-------------------------------------------------*/
function popWindow(hrefTarget,name,width,height) {
// Create offset
	if (document.all) {
		xMax = screen.width, yMax = screen.height;
	} else {
		if (document.layers) {
			xMax = window.outerWidth, yMax = window.outerHeight;
		} else {
			xMax = 640, yMax=480;
		}
	}
	var xOffset = (xMax - 586)/2, yOffset = (yMax - 700)/2;
//Check if pop up exists	
	if (!popWin||popWin.closed) {
		// no pop up exists set the popWintype to the current type
		popWintype = name;
		// open pop up window
		popWin = window.open(hrefTarget,name,'width='+width+',height='+height+',screenX='+xOffset+',screenY='+yOffset+', top='+yOffset+',left='+xOffset+',scrollbars=yes,menubar=no,resizable=yes');
	} else {
		// Check if the pop up is the same type
		if (popWintype != name) {
		// it is not the same type so close the current pop up
		popWin.close();
		// set the popWintype to the current type
		popWintype = name;
		// open pop up window
		popWin = window.open(hrefTarget,name,'width='+width+',height='+height+',screenX='+xOffset+',screenY='+yOffset+', top='+yOffset+',left='+xOffset+',scrollbars=yes,menubar=no,resizable=yes');
		return;
		}
		// Bring pop up to the foreground
		popWin.focus();
		// Change the location of the pop up to the location being requested
		popWin.location = hrefTarget;
	}		
}

/* -----------------------------------------------
FUNCTION: poplanguage
DESC: Create a module level pop up window
ARGS:
	formName - url to be opened
	sel - name of the select element from which to
		  get the value.
-------------------------------------------------*/
function poplanguage(formName,sel) {
	//Set Variables
	var name, width, height, fieldValue, localeValue, hrefTarget,objTest,bolTestResult;
	name = "languageSelection";
	width ="316";
	height ="350";
	objTest = /_none/;
	fieldValue = sel.options[sel.selectedIndex].value;
	localeValue = fieldValue.substring(3,5) + "_" + fieldValue.substring(0,2);
	bolTestResult = objTest.test(fieldValue);
	if (bolTestResult) {
		formName.submit();
	} else if(fieldValue == ""){
		alert('Please select a Country')
	}else {
		hrefTarget = "/content/global/popup.jsx?country=" + fieldValue + "&Locale=" + localeValue;
		// Pop up the window
		popWindow(hrefTarget,name,width,height);
	}
	return false;
}

/* -----------------------------------------------
FUNCTION: setPreferences
DESC: calls the url to change the language / homepage
		preferences...then closes the window.
ARGS:
	strRedirectorKey - url
	strPermanentFlag - flag that says whether or not
					   the use wants to save these settings.
					   ("yes"/"no")
-------------------------------------------------*/
function setPreferences(strRedirectorKey,strPermanentFlag) {
	if (opener)
	{
		opener.location.href = "/?cookie="+strRedirectorKey+"&setCookie="+strPermanentFlag;
		window.close();
	}
}

/* -----------------------------------------------
FUNCTION: popWrapper
DESC: Wrapper function takes in a url and a popup type
ARGS:
	hrefTarget - url to be opened
	poptype - type of popup to use

NOTES:
	valid popup types are:
	pop_up_2_col = 2-Column Help
	pop_up_3_col = 3-Column Help
	pr_fr_3_col = 3 column printer friendly page
	pr_fr_4_col = 4 column printer friendly page
	pop_up_full_page = pop up full page
	pop_up_4_col = 4- Column Help
-------------------------------------------------*/
function popWrapper(hrefTarget,poptype) {
	if ((poptype == "pop_up_2_col"))
	{
		helpFieldLvl(hrefTarget);
	}
	else if ((poptype == "pop_up_3_col") || (poptype == "pop_up_3_col") || (poptype == "pr_fr_3_col"))
	{ 
		helpModLvl(hrefTarget);
	}
	else if ((poptype == "pop_up_4_col") ||(poptype == "pr_fr_4_col"))
	{ 
		printerFriend(hrefTarget);
	}
	else if ((poptype == "pop_up_full_page")) 
	{
		newWindow(hrefTarget);
	}
	else {
		return;
	}
}