// JavaScript Document
// this javascript is included in all jsp pages of ALL products



//////////////////// This is for the navbar rollovers ////////////////////

// change an image from on to off

function swapOnOff(imageName) {



	var newImage = new Image();

	var imgLocation = document.images[imageName].src;

	var oldImage = document.images[imageName];



	if (imgLocation.indexOf("_off") != -1) {

	imgLocation = imgLocation.replace("_off","_on");

	}

	else {

	imgLocation = imgLocation.replace("_on","_off");

	}



	newImage.src = imgLocation;

	oldImage.src = newImage.src;



}



function chgIn(image1,image2) {

	image1.src = image2.src;

}





// enhanced String

String.prototype.trim =

	function () {

		return this.replace(/(^\s*)|(\s*$)/g, "");

	}



// prevent double submits

function coFormAllowSubmit(f) {

	var x = f.elements["_co_form_submitted"];

	if (!x) return true;

	if (x.value != "0") {

		alert("Your request is being processed.");

		return false;

	}

	x.value = "1";

	return true;

}



function coFormResetAllowSubmit(f) {

	var x = f.elements["_co_form_submitted"];

	if (x) x.value = "0";

	return false;

}



function ht_gotoPage(formName, page) {

	var f = document.forms[formName];

	f.elements["_htpage"].value = page;

	var ae = f.elements["action"];

	if (ae && ae.selectedIndex) ae.selectedIndex = 0;

	f.submit();

}



function ht_gotoPageByGet(formName, page) {

	var f = document.forms[formName];

	f.elements["_htpage"].value = page;

	var ae = f.elements["action"];

	if (ae && ae.selectedIndex) ae.selectedIndex = 0;

	f.method = "GET";

	f.submit();

}



function ht_selectNone(formName, fieldName) {

	var f = document.forms[formName];

	f.elements['_htallselected'].value = "false";

	f.elements['_htnoneselected'].value = "true";

	ht_setChecked(f, fieldName, false, false);

	f.elements['_htselectcount'].value = "0";

	if (document.getElementById)

		document.getElementById("htselectcount").innerHTML = "<strong>" + f.elements['_htselectcount'].value + "</strong>";

}



function ht_selectAll(formName, fieldName) {

	var f = document.forms[formName];

	f.elements['_htallselected'].value = "true";

	f.elements['_htnoneselected'].value = "false";

	ht_setChecked(f, fieldName, false, true);

	f.elements['_htselectcount'].value = f.elements['_httotalrows'].value;

	if (document.getElementById)

		document.getElementById("htselectcount").innerHTML = "<strong>" + f.elements['_htselectcount'].value + "</strong>";

}



function ht_selectPage(formName, fieldName) {

	var f = document.forms[formName];

	ht_setChecked(f, fieldName, true, true);

}



var is_selected = false;



function ht_selectPageToggle(formName, fieldName) {



	var f = document.forms[formName];

	for (i = 0; i < f.elements.length; i++) {

		var fld = f.elements[i];

		if (fld.type == "checkbox" && fld.name == fieldName) {

		   if (fld.checked != !is_selected) {

			  fld.checked = !is_selected;

			}

		}

	}



	is_selected = !is_selected;



}



function ht_setChecked(f, fieldName, updateCount, checked) {

	var n = 0;

	for (i = 0; i < f.elements.length; i++) {

		var fld = f.elements[i];

		if (fld.type == "checkbox" && fld.name == fieldName) {

			if (fld.checked != checked) {

			  fld.checked = checked;

			  n += checked ? 1 : -1;

			}

		}

	}

	if (updateCount) {

		var c = f.elements['_htselectcount'];

		c.value = parseInt(c.value) + n;

		if (document.getElementById)

			document.getElementById("htselectcount").innerHTML = "<strong>" + c.value + "</strong>";

	}

}



function ht_selectChanged(s) {

	var n =  s.checked ? 1 : -1;

	var c = s.form.elements['_htselectcount'];

	if (!c) return;

	c.value = parseInt(c.value) + n;

	if (document.getElementById && document.getElementById("htselectcount"))

		document.getElementById("htselectcount").innerHTML = "<strong>" + c.value + "</strong>";

}





function ht_checkSelection(formName, fieldName, msg) {

	var f = document.forms[formName];

	if (f.elements['_htselectcount'] != null && parseInt(f.elements['_htselectcount'].value) > 0) return true;

	for (i = 0; i < f.elements.length; i++) {

		var fld = f.elements[i];

		if ((fld.type == "checkbox" || fld.type == "radio")&& fld.name == fieldName) {

			if (fld.checked) return true;

		}

	}

	if (msg != null) {

		alert(msg);

	}

	return false;

}



function ht_validateChoiceAction( formName, listName, cbName, hrefVal, itemType ) {

	var gotAction = ht_checkListSelection( formName, listName, null);

	var gotSelection = ht_checkSelection( formName, cbName, null);

	var msg = '';

	var lst = document.forms[formName].elements[listName];

	var sel = lst.selectedIndex;

	var selVal = lst.options[sel].value;

	var isDelete = selVal == 'delete';

	if (!gotAction)

		msg += "You must choose an action";

	if (!gotAction && gotSelection)

		msg += ".";

	if (!gotAction && !gotSelection)

		msg += " and you ";

	if (gotAction && !gotSelection)

		msg += "You ";

	if (!gotSelection)

		msg += "must choose at least one " + itemType + ".";

	if (!gotSelection || !gotAction)

		alert( msg );

	else {

		if (isDelete && confirm("Are you sure you want to delete?")) {

			return true;

		} else if(!isDelete) {

			return true;

		}

	}

	return false;

}



function ht_doChoiceAction( formName, listName, cbName, hrefVal, itemType ) {

	if (ht_validateChoiceAction( formName, listName, cbName, hrefVal, itemType )) {

		hrefSubmit( formName, hrefVal );

	}

}



function ht_checkListSelection(formName, fieldName, msg) {

	var f = document.forms[formName];

	if (f != null) {

		var e = f.elements[fieldName];

		if (e != null) {

			// multilists can have a zeroth selection

			if (e.size > 1 && e.selectedIndex >= 0)

				return true;

			if (e.size < 1 && e.selectedIndex > 0)

				return true;

		}

	}

	if (msg != null) {

		alert(msg);

	}

	return false;

}



// use this in an anchor onclick to link back and scroll the page to the same position

function selfRefScrollTo(anchor) {

	if (!anchor.href || (!document.body.scrollLeft && !document.body.scrollTop)) return true;

	anchor.href += "&_pageX=" + document.body.scrollLeft + "&_pageY=" + document.body.scrollTop;

	return true;

}



// request utils



function getRequestParameter(name) {

	var s = location.search;

	if (!s) return;

	var i = s.indexOf(name + "=");

	if (i < 1 || (i > 1 && s.charAt(i - 1) != "&")) return;

	s = s.substring(i + name.length + 1);

	i = s.indexOf("&");

	return i == -1 ? s : s.substring(0, i);

}



// the standard onload to auto focus the first co:form element

function __onload() {

	if (document.forms["no_cache_kludge_form"])

		document.forms["no_cache_kludge_form"].elements["no_cache_kludge_flag"].value = "1";

	if (window.scrollTo) {

		var px = getRequestParameter("_pageX");

		var py = getRequestParameter("_pageY");

		if (px || py) window.scrollTo(px, py);

	}

	if (window.autoFocus) {

		for (var i = 0; i < document.forms.length; ++i) {

			var f = document.forms[i];

			if (f.name.type) continue;

			if (f.name.match(/^_.*_$/)) continue;

//          if (!f.name.match(/^F[0-9]*/)) continue;

			for (var j = 0; j < f.elements.length; ++j) {

				var e = f.elements[j];

				var t = e.type;

//              if (t == "text" || t == "textarea" || t == "radio" || t == "select" || type == "checkbox") {

				if (t != "hidden") {

					e.focus();

					return;

				}

			}

		}

	}

}



// the following block is for the session timeout mechanism.

//  These following two lines are now inserted programmatically by BoJspPage

//  using values from application ini based on user types:

//  that way different user types get different timeouts

//    var millisToWarning = 30 * 60 * 1000;

//    var millisToTimeout = 5 * 60 * 1000;



	var winWarning = null;

	/* This function shows the confirm box *************************************/

	var windowWidth = 250;

	var windowHeight = 150;

	var locX = ( screen.width - windowWidth ) / 2;

	var locY = ( screen.height - windowHeight ) / 2;

	var windowFeatures = "width=" + windowWidth +

						",height=" + windowHeight +

						",screenX=" + locX +

						",screenY=" + locY +

						",left=" + locX +

						",top=" + locY;

	var sessionTimeoutTimer = null;

	var sessionWarningTimer = null;



	function showWarning() {

		/* Close window first to make sure that our window has */

		/* the desired features */

		if ( ( winWarning != null ) && !winWarning.closed ) {

			winWarning.close();

		}

		winWarning = open( "/shared/security/session_timeout.jsp", "winWarning", windowFeatures ); /* Write to the confirm box */

	}

	/* This function is called by the buttons on the confirm box ***************/



	function buttonClicked( buttonChoice ) {

		/* Put in this function the result of the user's choice */

		/* (in this case, write the user's choice in a textfield) */

		switch( buttonChoice ) {

			case 0:

				initialTimeout();

				winWarning.open(keepAlivePage,"winRefreshed",windowFeatures);

				break;

			case 1:

				if (isPopup){

					opener.buttonClicked(1);self.close();

				} else {

					document.logoutform.submit();

				}

				break;

			default:

				alert("How did I get here?");

		}

	}

	function clearTimeouts() {

		clearTimeout( sessionTimeoutTimer );

		clearTimeout( sessionWarningTimer );

	}

	/** the user has ignored out warning.  we need to log them out

	  */

	function sessionTimeout() {

		winWarning.close();

		document.logoutform.auto.value="true";

		document.logoutform.submit();

	}

	/** the session is about to timeout, show the warning popup

	 *  and set a new timer to redirect if the user does nothing

	 */

	function sessionWarning() {

		clearTimeouts();

		sessionTimeoutTimer = window.setTimeout("sessionTimeout()", millisToTimeout );

		showWarning();

	}

	/** defines the timeout to session warning */

	function initialTimeout() {

		clearTimeouts();

		sessionWarningTimer = window.setTimeout( "sessionWarning()", millisToWarning );

	}

// end Session timeout functions





// begin redirect stuff

function messageRedirect(message, url) {

	if (confirm(message)) {

		window.location = url;

	}

}



function popup(page, name, w, h, direct, locate, menu, scroll, status, tool) {

	var winl = (screen.width - w) / 2;

	var wint = (screen.height - h) / 2;

		winprop = 'height='+h+',width='+w+',top='+wint+',left='+winl+',directories='+direct+',location='+locate+',menubar='+menu+',scrollbars='+scroll+',status='+status+',toolbar='+tool+',resizable=yes'

	var win = window.open(page, name, winprop);

	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }

	//return win;

}





/* This is for the href buttons to submit */

function hrefSubmit(formName, clicked) {

	form = document.forms[formName];

	form.elements['href_submit'].value = clicked;

	form.submit();

}



/* Q&A Toggle */

function qnaToggle(id) {

  var e = document.getElementById(id);

  if (!e) return;

  e.style.display = e.style.display == "none" ? "" : "none";

}



/** toggle an element display on/off */

function toggleDisplay(name) {

	var t = document.getElementById(name);

	changeDisplay(name, t.style.display == "");

}



/** change the display **/

function changeDisplay(name, viewable) {

	var t = document.getElementById(name);

	t.style.display = viewable == "" ? "" : "none";

}



/** disable/enable a group of radio buttons */

function changeRadioStatus(group, status) {

	for (var i=0; i<group.length; i++) group[i].disabled=status;

}

/******************************************************************

This js script is for the hover menus on the main navigation

******************************************************************/

var curEl = null;

var hideEl = null;

var curEl2 = null;

var hideEl2 = null;

/**

 * menu right aligned

 */

function displayMenuRight(owner, name) {

   displayMenuRight2(owner, name, 20);

}



/**

 * menu right aligned

 */

function displayMenuRight2(owner, name, topOffset) {

   var style = handleMenu(owner, name);



   style.top = parseInt(owner.offsetTop)+document.getElementById("acct-subnav-menu").offsetTop+20+"px";

   style.left = parseInt(owner.offsetLeft)+document.getElementById("acct-subnav-menu").offsetLeft+"px";



}



/**

 * menu left aligned

 */

function displayMenuLeft(owner, name) {

   alert("showing now");

   displayMenuLeft2(owner, name, 20);

}



/**

 * menu left aligned

 */

function displayMenuLeft2(owner, name, topOffset) {

   alert("showing now");

   var style = handleMenu(owner, name);

	style.top = parseInt(owner.offsetTop)+topOffset+getElementById("acct-subnav-menu").offsetTop;

   style.left = owner.offsetLeft+getElementById("acct-subnav-menu").offsetLeft;

}





/**

 * menu left aligned (legacy)

 */

function displayMenu(owner, name) {

	return displayMenuLeft(owner, name);

}



/**

 * handle menu

 */

function handleMenu(owner, name) {



   // get the element and set it's parent

   element = document.getElementById(name);

   element.parent = owner;



   // clear the close timeout

   clearClose();

   if (curEl != null) closeMenu();



   // set up the element style and position

   var style = element.style;

   style.display = "";

   style.position = "absolute";



   // set the current menu element

   curEl = element;   



   return style;

}



function handleMenu2(owner, name) {



   // get the element and set it's parent

   element = document.getElementById(name);

   element.parent = owner;



   clearClose2();

   if (curEl2 != null) closeMenu2();



   // set up the element style and position

   var style = element.style;

   style.display = "";

   style.position = "absolute";



   // set the current menu element

   curEl2 = element;   



   return style;

}



function closeMenu() {

   closeMenu(null);

}



function closeMenu(event) {

   timed = event != null && event.type == "mouseout";

   if (timed) hideEl = setTimeout("closeMenu()", 500);

   else if (curEl != null) {

	  curEl.style.display = "none";

	  curEl = null;

   }

}



function closeMenu2(event) {

   timed = event != null && event.type == "mouseout";

   if (timed) hideEl2 = setTimeout("closeMenu2()", 500);

   else if (curEl2 != null) {

	  curEl2.style.display = "none";

	  curEl2 = null;

   }

}



function clearClose() {

   if (hideEl != null) clearTimeout(hideEl);

}



function clearClose2() {

   if (hideEl2 != null) clearTimeout(hideEl2);

}



function navRollOver(obj, state) {

  document.getElementById(obj).className = (state == 'on') ? 'nav-highlight' : 'nav';

}





/******************************************************************

This js script is for the expand menus

******************************************************************/

	var ns6=document.getElementById&&!document.all?1:0



	var head="display:''"

	var folder=''

	var sign = "+"



function expandit(curobj, cnt){

	folder=ns6?curobj.nextSibling.nextSibling.style:document.all[curobj.sourceIndex+cnt].style

	if (folder.display=="none") folder.display=""

	else folder.display="none"

}



function toggleDisplay(id, offnames) {

	var el = document.getElementById(id);

	if(el == null)return;

	if (el.style.display == "none") el.style.display = "block";

	else el.style.display = "none";

	if (offnames) {

		for (var i = 0; i < offnames.length; ++i) {

			document.getElementById(offnames[i]).style.display = "none";

		}

	}

}



/******************************************************************

This js script is for the hover menus on the main navigation

******************************************************************/

var curEl = null;

var hideEl = null;



/**

 * menu right aligned

 */

function displayMenuRight(owner, name) {

   var saf=false

   if(document.getElementById("acct-subnav-menu"))var parentTable=document.getElementById("acct-subnav-menu");

   if(document.getElementById("navbar"))var parentTable=document.getElementById("navbar");

   if(document.getElementById("aa-subnav-menu"))var parentTable=document.getElementById("aa-subnav-menu");

   agt=navigator.userAgent.toLowerCase();

   if (agt.indexOf("safari") != -1)saf=true;

   var offsetAdjust=0;

   if(saf)offsetAdjust=6;

   var style = handleMenu(owner, name);

   style.top = parseInt(owner.offsetTop)+parentTable.offsetTop+18+offsetAdjust+"px";

   style.left = parseInt(owner.offsetLeft)+parentTable.offsetLeft-parseInt(style.width)+parseInt(owner.offsetWidth)+2+offsetAdjust+"px";

}



/**

 * menu left aligned

 */

function displayMenuLeft(owner, name) {

   var saf=false

   if(document.getElementById("acct-subnav-menu"))var parentTable=document.getElementById("acct-subnav-menu");

   if(document.getElementById("navbar"))var parentTable=document.getElementById("navbar");

   if(document.getElementById("aa-subnav-menu"))var parentTable=document.getElementById("aa-subnav-menu");

   agt=navigator.userAgent.toLowerCase();

   if (agt.indexOf("safari") != -1)saf=true;

   var offsetAdjust=0;

   if(saf)offsetAdjust=6;

   var style = handleMenu(owner, name);

   if(style)

   {

//   alert(owner.offsetLeft + " " + document.getElementById("acct-subnav-menu").offsetLeft);

   style.top = parseInt(owner.offsetTop)+parentTable.offsetTop+18+offsetAdjust+"px";

   style.left = parseInt(owner.offsetLeft)+parentTable.offsetLeft+offsetAdjust+"px";

   }

}



/**

 * menu left aligned (legacy)

 */

function displayMenu(owner, name) {

	return displayMenuLeft(owner, name);

}



/**

 * handle menu

 */

function handleMenu(owner, name) {

   element = document.getElementById(name);

   if(element) {

	   // get the element and set it's parent

	   element.parent = owner;



	   // clear the close timeout

	   clearClose();

	   if (curEl != null) closeMenu();



	   // set up the element style and position

	   var style = element.style;

	   style.display = "";

	   style.position = "absolute";



	   // set the current menu element

	   curEl = element;   



	   return style;

   } 

}



function closeMenu() {

   closeMenu(null);

}



function closeMenu(event) {

   timed = event != null && event.type == "mouseout";

   if (timed) hideEl = setTimeout("closeMenu()", 500);

   else if (curEl != null) {

	  curEl.style.display = "none";

	  curEl = null;

   }

}



function clearClose() {

   if (hideEl != null) clearTimeout(hideEl);

}



function navRollOver(obj, state) {

  document.getElementById(obj).className = (state == 'on') ?

  'nav-highlight' : 'nav';

}



function submitForm(f) {

	if (f.onsubmit && !f.onsubmit()) return;

	f.submit();

}





/**

 * tab system

 * @param curSection the selected section

 * @param sections an array of all the section

 */

function changeTabSection(curSection, sections) {



	for (var i=0; i<sections.length; i++) {

		section = sections[i];

		viewable = section == curSection ? true : false;

		el = document.getElementById(section + "Button");

		el.className = viewable ? "tabOn" : "tabOff";

		el = document.getElementById(section + "Content");

		el.style.display = viewable ? "" : "none";

	}



}



/**

 * tab system, pulls style name from element id

 * @param curSection the selected section

 * @param sections an array of all the section

 */

function changeTabSectionById(curSection, sections) {



	for (var i=0; i<sections.length; i++) {

		section = sections[i];

		viewable = section == curSection ? true : false;

		el = document.getElementById(section + "Button");

		el.className = el.id + (viewable ? "On" : "Off");

		el = document.getElementById(section + "Content");

		el.style.display = viewable ? "" : "none";

	}



}



/**

 * create a google ad frame

 */

function createGoogleFrame(url, id) {

	document.write("<sc" + "ript src=\"" + url + "\"></sc" + "ript>");

}



/**

* used to change out the margins for the grid tag

*/

function clearAll() {



	var userAgent = navigator.userAgent

	var isIE = navigator.userAgent.indexOf("MSIE") != -1;

	var isMac = navigator.userAgent.indexOf("Mac") != -1;



	var line = "<div style='clear:both;'>&nbsp;</div>";

	if (isIE && isMac) line = "<div style='margin-bottom:5px; clear:both;'>&nbsp;</div>";

	document.writeln(line);



}



var submitcount=0;

function noDoubleSubmit(){

	if(submitcount == 0){

		submitcount++;

	return true;

	}

	else {

		alert("We are still processing your request, please wait.");

		return false;

	}

}



/**

 * phpads stuff

 */

if(!document.phpAds_used)document.phpAds_used=',';

var expadbxi=0;

function loadAdBox() {

	if (document.expAdBoxen && expadbxi < document.expAdBoxen.length) {

		var phpAds_random=new String(Math.random());

		phpAds_random=phpAds_random.substring(2,11);

		var adjssrc=document.expAdBoxen[expadbxi].replace("__PHPADSRANDOM__",phpAds_random).replace("__PHPADSUSED__",document.phpAds_used);

		document.write("<"+"script language='JavaScript' type='text/javascript' src='");

		document.write(adjssrc);

		document.write("'><"+"/script>");

	}

}

function injectAdBox() {

	document.getElementById("exp_adbox_"+expadbxi++).innerHTML=phpadsbanner;

}



/* Below is for Experience.com homepage - randomize the list of popular jobs*/

function randomizeOrder(contentArray){

	var random_chosen

	var i=0



	while (i<contentArray.length){

		random_chosen=Math.floor(Math.random()*contentArray.length)

			if (contentArray[random_chosen]!="been_chosen"){

				document.write(contentArray[random_chosen]+'<br /><br />')

				contentArray[random_chosen]="been_chosen"

				i++

			}

	}

}
