// ---------------------------------------------------------
//	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");
	return false;
}

/* -----------------------------------------------
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 
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
		if (name == "emailthis") {
		popWin = window.open(hrefTarget,name,'width='+width+',height='+height+',screenX='+xOffset+',screenY='+yOffset+', top='+yOffset+',left='+xOffset+',scrollbars=no,menubar=yes,resizable=yes');
		} else {
		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
		if (name == "emailthis") {
		popWin = window.open(hrefTarget,name,'width='+width+',height='+height+',screenX='+xOffset+',screenY='+yOffset+', top='+yOffset+',left='+xOffset+',scrollbars=no,menubar=yes,resizable=yes');
		} else {
		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 popWindowCenter(hrefTarget,name,width,height) {
	openWin(hrefTarget,name,width,height,'0','0','1','width='+width+',height='+height);
}


function openWin(u,n,w,h,l,t,c,f,x) {
  var ww=((screen.width-w)/2);if(c==1){l=ww;t=(screen.height-h)/2;}if(c==2){l=ww}
	f+=',top='+t+',left='+l;upsWin = window.open(u,n,f);upsWin.focus();
}
/* -----------------------------------------------
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,npc;
	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 location')
	} 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 if ((popType == "mailpop")) 
	{
		popWindowCenter(hrefTarget,popType,392,450);
	}
	else if ((popType == "video")) 
	{
		popWindowCenter(hrefTarget,popType,490,530);
	}
	else if ((popType == "pressroomvideo")) 
	{
		popWindow(hrefTarget,popType,380,350);
	}
	else {
		return;
	}
}

function pollResults(pollID){
newWind=window.open("poll.cfm?choice=0&pollid=" + pollID,"pollWindow","status=no,toolbar=no,scrollbars=yes,width=480,height=350")
}

/* -----------------------------------------------
FUNCTION: showHide
DESC: Show/Hide a layer
ARGS:
	layername - layer to be show/hide'd
	

NOTES:
	
-------------------------------------------------*/
function showHide (layername) {
	if (document.getElementById(layername).style.display == 'none') {
		document.getElementById(layername).style.display = '';

	} else {

		document.getElementById(layername).display = 'none';
	}
}

/* -----------------------------------------------
FUNCTION: changeProductArchive
DESC: Change the product archive page
ARGS:


NOTES:
	
-------------------------------------------------*/
function changeProductArchive (box) {
	//var box = document.getElementById("productMetaList");
	//var product = box.options[box.selectedIndex].value;
product = box.options[box.selectedIndex].value;
if (product != "") {
	if (location.href.indexOf('?') > -1) {
location.href = location.href.split('?')[0] + "?product="+product;
	} else {
	
location.href = location.href+"?product="+product;
	}
}
	
}

function changeIssueArchive (box) {
	//var box = document.getElementById("productMetaList");
	//var product = box.options[box.selectedIndex].value;

idate = box.options[box.selectedIndex].value;

if (idate != "") {
	if (location.href.indexOf('?') > -1) {
location.href = location.href.split('?')[0] + "?idate="+idate;
	} else {
	
location.href = location.href+"?idate="+idate;
	}
}
	
}

function openEmailPop() {
	popWrapper('/mailthis.aspx?murl='+location.href+'&title='+document.title,'mailpop');
}