/* Copyright Humana Inc 2007

Find each of the a elements <a> marked for opening in a new window.
Tags will have the form of:
<a href="default.asp" name="newWindow....." id="unique window name">

The specified name attribute allows for a specific dimension and decoration options.

The specified id attribute allows for a specific window to be used as a target.
If id is omitted, subsequent clicks on the link will open a new window for each click
If id is given, a elements that share the id value will open only one window.
Also, a elements <a> that share the id value will open only one window.

Find elements <a> marked for "masked" tracking URL.
Tags will have the form of:
<a href="http://www.humana-one.com" name="TrackingLink" id="default.asp?tracking=information1234567890">

*/
function applySelectors() {
/*  creates onclick for special popup windows and tracking links  */	
	var aTag=new Array;
	var i = 0;

	aTag = document.getElementsByName("newWindow770550");
	for (i=0; i<aTag.length; i++) {
			aTag[i].onclick =  newWindow770550;
	}
	aTag = document.getElementsByName("newWindow350500");
	for (i=0; i<aTag.length; i++) {
			aTag[i].onclick =  newWindow350500;
	}
	aTag = document.getElementsByName("newWindow710540");
	for (i=0; i<aTag.length; i++) {
		 aTag[i].onclick =  newWindow710540;  			
	}
	aTag = document.getElementsByName("newWindow770570");
	for (i=0; i<aTag.length; i++) {
			aTag[i].onclick =  newWindow770570;
	}
	aTag = document.getElementsByName("PrinterFriendly");
	for (i=0; i<aTag.length; i++) {
			aTag[i].onclick = printerFriendlyNewWindow;
	}
	aTag = document.getElementsByName("printWindow");
	for (i=0; i<aTag.length; i++) {
			aTag[i].onclick =  printWindow;
	}
	aTag = document.getElementsByName("closeWindow");
	for (i=0; i<aTag.length; i++) {
			aTag[i].onclick =  closeWindow;
	}
	aTag = document.getElementsByName("KeyLink");
	for (i=0; i<aTag.length; i++) {
		aTag[i].onclick =  appendKey;
	}
	aTag = document.getElementsByName("FontSizeAdjust");
	for (i=0; i<aTag.length; i++) {
		aTag[i].onclick =  fontSizeAdjust;
	}

}



// Open a new window with the proper options
// The options are outlined at http://developer.mozilla.org/en/docs/DOM:window.open
function openWindow(stringURL,stringWindowName,stringDecorations) {
	//first get rid of any non alphanum chars in the id
	var searchRE = /[^a-zA-Z0-9]+/gi;
	stringWindowName = stringWindowName.replace(searchRE,"")

	var wWindow = window.open(stringURL,stringWindowName,stringDecorations);
	wWindow.focus();
}

// The next three functions open the window with different width, height and other options.
function newWindow770550() {
	var newWindowURL = this.href;
	var idstring = this.id;
	var decorations = "width=770,height=550,toolbar=no,location=no,status=yes,menubar=no,resizable=yes,scrollbars=yes";

	openWindow(newWindowURL,idstring,decorations);
	return false;
}

function newWindow350500() {
	var newWindowURL = this.href;
	var idstring = this.id;
	var decorations = "width=350,height=500,toolbar=no,location=no,status=no,menubar=no,resizable=no,scrollbars=yes";

	openWindow(newWindowURL,idstring,decorations);
	return false;
}

function newWindow710540() {
	var newWindowURL = this.href;
	var idstring = this.id;
	var decorations = "width=710,height=540,toolbar=no,location=no,status=yes,menubar=yes,resizable=yes,scrollbars=yes";

	openWindow(newWindowURL,idstring,decorations);
	return false;
}


function newWindow770570() {
	var newWindowURL = this.href;
	var idstring = this.id;
	var decorations = "width=770,height=570,toolbar=no,location=no,status=yes,menubar=no,resizable=yes,scrollbars=yes";

	openWindow(newWindowURL,idstring,decorations);
	return false;
}


function closeWindow() {
	self.close();
}

function printWindow() {
	window.print();
}

function appendKey() {
	if (this.href.indexOf("?") == -1)
	{
		this.href = this.href + this.id;
	}
}

function printerFriendlyNewWindow()
{
    //Show the printer friendly page in new window with specified decorations
	var newWindowURL = this.href;
	var idstring = "";
	var decorations = "width=710,height=540,toolbar=no,location=no,status=yes,menubar=yes,resizable=yes,scrollbars=yes";

	//Append pre-defined query string value to show printer friendly page in new window.
	if (this.href.indexOf("?") == -1)
	{
		newWindowURL = this.href + "?pf=1";
	}
	//Remove the unwanted special character "#" that may add during url build because href is set-up as #	
	if (this.href.indexOf("#") != -1)
	{
		newWindowURL = newWindowURL.replace("#","");
	}
	
	openWindow(newWindowURL,idstring,decorations);
	
	return false;
}

function fontSizeAdjust()
{
   //Show the printer friendly page in new window with specified decorations
	var newWindowURL = unescape(window.location.pathname);
	var idstringS  = "sfontsize=" + this.id;
	
	//Remove the unwanted special character "#" that may add during url build because href is set-up as #	
	if (this.href.indexOf("#") != -1)
	{
		newWindowURL = newWindowURL.replace("#","");
	}
	
		
	//Add or Set the 'fontsize' in cookie where it will be picked up from 'sfontsize' or 'fontsize' in detail page tpl code execution. 
	document.cookie = idstringS;

	//refresh the current page that will bring the changes in efffect.	
	window.location.href = newWindowURL;
	
	
	return false;
}


window.onload = applySelectors;
