// ---------------------------------------------------------
//	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=yes,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=yes,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.
	check - checkbox to remember location
-------------------------------------------------*/
function popLanguage(formName,sel,check) {
	//Set Variables
	var  fieldValue, localeValue, hrefTarget,objTest,bolTestResult;
	objTest = /_none/;
	fieldValue = sel.options[sel.selectedIndex].value;
	bolTestResult = objTest.test(fieldValue);
	cookieValue = "";
	if ( check.checked )
	{
		cookieValue = check.value;
	}
	
	if ( fieldValue == "" )
	{
		alert('Please select a location')
	
	}
	else if ( bolTestResult || cookieValue == "yes" )
	{
		formName.submit();
	}
	else
	{
		location.href="/content/"+fieldValue.substring(0,2)+"/"+fieldValue.substring(3,5)+"/index.jsx";
	}
	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;
	}
}

/* -----------------------------------------------
FUNCTION: submitHomepageLinkContent
DESC: submit function for homepage dropdowns
ARGS: 
	formName - Name of the form submitting

NOTES:
	
-------------------------------------------------*/

function submitHomepageLinkContent(formName)
{
	docForm = document.forms[formName];
	if ( docForm.dropdownList.options[docForm.dropdownList.selectedIndex].value != "")
	{
		docForm.action=docForm.dropdownList.options[docForm.dropdownList.selectedIndex].value;
		docForm.method="POST";
		docForm.submit();
	}
}