/********************************************************************
 * globals
 ********************************************************************/	
 
 
var isNS = (document.layers); 

//check if IE 6 on page load
var browser=navigator.userAgent;
if(browser.indexOf("MSIE")!=-1){
	var isIE=true;	
}
if ((verOffset=browser.indexOf("MSIE"))!=-1) {
	versionNum = parseFloat(browser.substring(verOffset+5,browser.length));
	if(versionNum==6){
		var isIE6=true;	
	}
}


// IE6 Flicker bug 
ie = document.all;
if(ie) {
	try {
		document.execCommand("BackgroundImageCache", false, true);
	} catch(err) {}
}


// WINDOW ONLOAD MANAGER
function womOn(){
	window.onload = womGo;
}
function womGo(){
	for(var i = 0;i < woms.length;i++)
		eval(woms[i]);
}
function womAdd(func){
	woms[woms.length] = func;
}
var woms = new Array();
womAdd('getExistingFontSize()');
womOn();


// TEXT SIZER
var currentFontSize;
var defaultFont='100%';
var mediumFont='110%';
var maximumFont='125%';
var path="/";
var domain=".amfam.com"
/**
* This functionality retrives the existing font from the cookie and based on the 
* cookie value this will call respective javascript functionality. If the cookie 
* value is null then it will set the default value.
*/
function getExistingFontSize(){
	var existingFontSize = getFontSizeCookie("fontSize");
	if (existingFontSize!=null){
		if (existingFontSize==defaultFont){
			defaults();
		}else if (existingFontSize==mediumFont){
			setMiniFontSize();			
		}else if (existingFontSize==maximumFont){
			setMaxFontSize();
		}
	}else{
		defaults();
	}	
}

/**
 * This function sets the default font size to the document's body style
 * and sets the fontSize cookie
 */
function defaults(){
	document.body.style.fontSize=defaultFont;
	setFontSizeCookie("fontSize",defaultFont,null,path,domain);
}

/**
 * This function sets the large font size to the document's body style
 * and sets the fontSize cookie
 */
function setMaxFontSize(){
	document.body.style.fontSize=maximumFont;
	setFontSizeCookie("fontSize",maximumFont,null,path,domain);
}

/**
 * This function sets the medium font size to the document's body style
 * and sets the fontSize cookie
 */
function setMiniFontSize(){
	document.body.style.fontSize=mediumFont;
	setFontSizeCookie("fontSize",mediumFont,null,path,domain);
}


/** getFontSizeCookie */
function getFontSizeCookie(cookieName){
	if (document.cookie.length > 0) { 
		var startOfCookie = document.cookie.indexOf(cookieName+"="); 
		if (startOfCookie != -1) { 
			startOfCookie += cookieName.length+1;
			var endOfCookie = document.cookie.indexOf(";", startOfCookie);
			if (endOfCookie == -1) 
				endOfCookie = document.cookie.length;
				return unescape(document.cookie.substring(startOfCookie, endOfCookie)); 
			} 
	}
	return null; 
}

/** setFontSizeCookie */
function setFontSizeCookie(cookieName, cookieValue, cookieExpiredays, path, domain) {
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (cookieExpiredays * 24 * 3600 * 1000));
	document.cookie = cookieName + "=" + escape(cookieValue) + 
	((cookieExpiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString())
	+ ( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" );
}

function clearField(field) {
	myType = field.type;
	if (myType == 'checkbox' || myType == 'radio' || myType == undefined)
	    try{for (i = 0; i < 20; i++) field[i].checked = false;}catch (e){}            
	if (myType == 'hidden' || myType == 'password' || myType == 'text' || myType == 'textarea')
	    field.value = "";
	if (myType == 'select-one' || myType == 'select-multiple')
	    field.selectedIndex = 0;
}

function checkDropdown(obj,msg){
	if (obj.options[obj.selectedIndex].value=="") {
		alert(msg);
		return false;
	}   
}
function gotoURL(frm,msg) { 
	if (frm.state.options[frm.state.selectedIndex].value=="") {
		alert("Please Select a State");
		return false;
	} else {	
		top.location.href = frm.state.options[frm.state.selectedIndex].value;
	}
}

function PrintThisPage(layer_id) {

   var sOption="toolbar=no,location=no,directories=no,menubar=no,";
       sOption+="scrollbars=yes,width=775,height=600,left=100,top=25";
var sLayerID = document.getElementById(layer_id).innerHTML;
  
   var sWinHTML = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
	                 "<head><link rel=\"stylesheet\" type=\"text/css\" href=\"https://web.amfam.com/site_files/css/print_content.css\"><title>"+document.title+"</title>\n" +
	                 "<script type=\"text/javascript\" src=\"https://web.amfam.com/site_files/js/getElementsByClassName.js\"></script>\n" +
	                 "<script type=\"text/javascript\" src=\"https://web.amfam.com/site_files/js/disableElements.js\"></script>\n" +
	                 "</head>\n" +
	                 "<body>\n" +
	                 "<div id=\"amfam_logo\"><img src=\"https://web.amfam.com/site_files/images/amfam/header/amfam_logo.gif\" alt=\"American Family Insurance\" /></div>\n" +
	                 "<div id=\"toolbar\"><ul><li><a href=\"javascript:void(0)\" onclick=\"window.print();\"><img src=\"https://web.amfam.com/site_files/images/amfam/tool_bar/ico_print.gif\"/></a>\n" + 
	                 "<a href=\"javascript:void(0)\" onclick=\"window.print();\">Print This Page</a></li></ul></div>\n" +
					 "<div id=\"" + layer_id + "\">" + sLayerID + "</div>\n" +
			      	 "</body></html>\n";
  
   var winprint=window.open("","",sOption);
       winprint.document.open();
	   winprint.document.write(sWinHTML);
	   winprint.document.close();
       winprint.focus();
}

function refreshParent(url) {
  window.opener.location.href = url;  
  window.blur();  
}

function newWindow(theURL,winName,w,h) { //v2.0
  var winleft = (screen.width - w) / 2;
  var winUp = (screen.height - h) / 2;
  winProp = 'width='+w+',height='+h+',left='+winleft+',top='+winUp+',scrollbars=no,resizable=no'
  window.open(theURL,winName,winProp);
}
