/* -------------------------------------------------------------------------------
	10/15/02 - nettles
	Global VARs
------------------------------------------------------------------------------- */
var NS = (navigator.appName == "Netscape");

/* -------------------------------------------------------------------------------
		09/23/03 - jgould
		Function for preventing multiple submit.
		It both submits the form and ensures the form can not be submit again
		by reassigning the funciton to a function that does nothing.
		It also disables the buttons (this part only works in IE).
		f - the form the buttons are in
------------------------------------------------------------------------------- */
function safeSubmit(f) {
	for (i=1; i<f.elements.length; i++) {
		if (f.elements[i].type == 'submit') {
			f.elements[i].disabled = true;
		}
	}
	f.submit();
	safeSubmit = blockIt;
	return false;
}

/* -------------------------------------------------------------------------------
		09/23/03 - jgould
		Dummy function that is used in conjunciton with safeSubmit(f) to prevent
		multiple submits.
------------------------------------------------------------------------------- */
function blockIt(f) {
	return false;
}	


/* -------------------------------------------------------------------------------
	10/15/02 - nettles
	Base window opening function
	Functions below override certain properties. This function will open
	a default window with default parameters.
		internalURL  -> if none passed function will exit as it has nowhere to go
		internalName -> defaults to popupWin if none specified
		internalArgs -> string of defaults for window attributes
------------------------------------------------------------------------------- */
function openWindow(internalURL,internalName,internalArgs) {
	if (internalURL == null || internalURL == '') {
		exit;
	}
	if (internalName == null || internalName == '') {
		internalName = 'popupWin';
	}
	if (internalArgs == null || internalArgs == '') {
		internalArgs = 'scrollbars,resizable,toolbar,status,width=640,height=480,left=50,top=50';
	}
	popupWin = window.open(internalURL,internalName,internalArgs);
 	popupWin.focus();
}

/*
	Overrides openWindow with different name attribute
*/
function openWindow640(thisURL) {
	openWindow(thisURL,'popupWin640','');
}

/*
	Overrides openWindow with the width/height passed in
*/
function openWindowWH(thisURL,thisW,thisH) {
	internalArgs = 'scrollbars,resizable,toolbar,status,left=50,top=50,width=' + thisW + ',height=' + thisH;
	openWindow(thisURL,'popupWinWH',internalArgs);
}

/*
	Overrides openWindow with the standard demo window args
*/
function openWindowDemo(thisURL) {
	internalName = 'popupWinDemo';
	internalArgs = 'scrollbars,resizable,toolbar,status,left=50,top=50,width=525,height=570';
  openWindow(thisURL,internalName,internalArgs);
}

/*
	Overrides openWindow with the small demo window args
*/
function openWindowDemoSmall(thisURL) {
	internalName = 'popupWinDemo';
	internalArgs = 'scrollbars,resizable,toolbar,status,left=50,top=50,width=250,height=250';
  openWindow(thisURL,internalName,internalArgs);
}

function openWindowATC(thisURL,thisType,thisWidth,thisHeight,thisArgs,thisName) {
	if (thisType != '') {
		switch (thisType) {
			case 'demo':
				openWindowDemo(thisURL);
				break;
			case 'demosmall':
				openWindowDemo(thisURL);
				break;
			case '640':
				openWindow640(thisURL);
				break;
		}
	} else {
		if ((thisWidth != '') && (thisHeight != '')) {
			openWindowWH(thisURL,thisWidth,thisHeight);
		} else {
			openWindow(thisURL,thisName,thisArgs);
		}
	}
}

/*
	Overrides open single pop
*/
var singlePop;
function openSinglePop(thisURL,thisWidth,thisHeight) {
	var internalArgs = 'left=50,top=50,width=' + thisWidth + ',height=' + thisHeight + ',resizable=1,scrollbars=1';
	if (singlePop != null) {
		newPop = window.open(thisURL,'singlePop',internalArgs);
		singlePop.close();
		singlePop = newPop;
	} else {
		singlePop = window.open(thisURL,'singlePop',internalArgs);
	}	
}


/* -------------------------------------------------------------------------------
	Window naming function to establish unique names.
	Replace dashes with underscores.
------------------------------------------------------------------------------- */
function windowNamer(thisURL) {
	var tmp = thisURL;
	var tmpArray = tmp.split('/');
	var idx = ((tmpArray.length) - 1);
  var name = 'popupWin_';
  if (tmpArray[idx] != null) {
  		name += tmpArray[idx].replace(/[-]/g,"_");	
  }
  return(name);
}

function writeWindow(inURL,inType,inWidth,inHeight,inArgs) {
	var tmpName = windowNamer(inURL);
	var linkStr = "<a href=\"#\" onclick=\"javascript:openWindowATC('" + inURL + "','" + inType + "','" + inWidth + "','" + inHeight + "','" + inArgs + "','" + tmpName + "');return false;\">";
	document.write(linkStr);
}

/* -------------------------------------------------------------------------------
	10/15/02 - nettles
	This function iterates through the checkboxes on a page and toggles them from
	on to off.
	WARNING: this function assumes one form per page
		dowhat -> if dowhat is on, it checks all boxes, else it unchecks all
------------------------------------------------------------------------------- */
function ToggleBoxes(dowhat) {
	for (i=0; i<document.forms[0].elements.length; i++) {
		if (document.forms[0].elements[i].type == 'checkbox') {
			if (dowhat == 'on') {
				document.forms[0].elements[i].checked = true;
			} else {
				document.forms[0].elements[i].checked = false;
			}
		}
	}
}

/* -------------------------------------------------------------------------------
	10/15/02 - nettles
	Function used to call the print command
	Netscape -> if NS tests to true, all that needs to happen is a call to the
		print command
	IE -> if IE, then the particular print object is inserted on the page, thank
		you M$
------------------------------------------------------------------------------- */
function printit(){
	window.print();
}
	
/* -------------------------------------------------------------------------------
	10/15/02 - nettles
	Here begins the help stuff
	Documentation to come!
------------------------------------------------------------------------------- */
var scrX = screen.availWidth;
var scrY = screen.availHeight;
var tgtX = 240;
var win1 = new Array (0, 0, (scrX - tgtX), scrY);
var win2 = new Array ((scrX - tgtX), 0, tgtX, scrY);
var balloonFlag = -1;
var winTracker;

function ContextOpenHelp(whichPage) {
	//if (!winTracker) {
		window.resizeTo(win1[2],win1[3]);
		window.moveTo(win1[0],win1[1]);
		var winHandle;
		winHandle = window.open('/cgi-bin/webscr?cmd=p/hlp/context/index-outside&page=' + whichPage ,'popHelp','scrollbars=no,resizable=no,menubar=no,location=no,personalbar=no,titlebar=no,toolbar=no,status=yes');
		winHandle.resizeTo(win2[2],win2[3]);
		winHandle.moveTo(win2[0],win2[1]);
		self.focus();
		winHandle.focus();
		winTracker = winHandle;
	/* } else {
		winTracker.focus();
	} */
}

function ContextShowHideHelp (whichDiv) {
	if (balloonFlag > 0) {
		var thisDiv = eval("document.all." + whichDiv);
		var thisX = window.event.x;
		var thisY = window.event.y;
		if (thisDiv.style.visibility == 'hidden') {
			thisDiv.style.visibility = 'visible';
			thisDiv.style.top = thisY;
			thisDiv.style.left = (thisX + 10);
		} else {
			thisDiv.style.visibility = 'hidden';
		}
	}
}

self.name = "superDaddy";

/*-----------------------------------------------------
6/17/04
New JS for CountrySelector on Homepage
 jhauman-blistwon
------------------------------------------------------*/
function ReloadLocalizedPage(whichCountry) {
	var thisProtocol = document.location.protocol;
	var thisHost = document.location.host;
	var thisPath = document.location.pathname;
	var newLocation = thisProtocol + "//" + thisHost + "/" + whichCountry + thisPath;
	ReloadPage(newLocation);
}
function ReloadPage(whichPage) {
	// Remove alert for production
	//alert(whichPage);
	document.location = whichPage;
	return (false);
}

/*-----------------------------------------------------
7/29/04
Copied ToggleCheck for XPT from
p/gen/contact/wf_unauth_ext_financial-outside
-  rashah0&#64;paypal.com
------------------------------------------------------*/
function ToggleCheck(source,country_format) {
	
	if (document.images) {
		document.images.check_image.src = source;
	} else {
		document.all.check_image.src = source;
	}
	document.forms[0].ach_format.value = country_format;
}

/*-----------------------------------------------------
8/9/04
New JS for data submission to SF.com
 pvasireddy
------------------------------------------------------*/
function submitToSF(frmSFData){
	frmSFData.submit();
}

/*-----------------------------------------------------
08/16/04
Iterates through all the divs and hides all of the ones with ids of "div_XXX",and the sets shows the div with the passed in index.
------------------------------------------------------*/

function displaySubindustry(form, index) {
	var divs = form.getElementsByTagName("DIV");
	for (var i = 0; i < divs.length; i++) {
	     var currentDiv = divs[i];
	     var divId = currentDiv.getAttribute("id");
	     if (divId != null && divId.indexOf("div_") > -1) {
		  currentDiv.style.display = "none";
	      }	
	}
	if (index > -1) {
		var d1 = document.getElementById("div_" + index);
		d1.style.display = '';
			    }
}

/*-----------------------------------------------------
09/10/04
Character Counter WBN et cetera...
------------------------------------------------------*/

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	} else {
		countfield.value = maxlimit - field.value.length;
	}
}

/*-----------------------------------------------------
09/15/04
Parse Image URL for Image PopUp preview WBN
------------------------------------------------------*/

function FillPrefix(val) {
	len = document.forms[0].image_url.value.length;
	str = "";
	str = document.forms[0].image_url.value;
	
	if (len > 0) {
		if (str.search('https:\/\/') != -1) {
			str = str.slice(8);
		}
		else if (str.search('http:\/\/') != -1) {
			str = str.slice(7);
		}
		else {
			str = "";
		}
	}
	document.forms[0].image_url.value = "";
	document.forms[0].image_url.value = val + str;
	document.forms[0].image_url.focus();
}
/*-----------------------------------------------------
9/15/04
removes <!-- and --> from textareas
 jgibson
------------------------------------------------------*/
function removeComment(node) {
	var txt = node.value;
	var ntxt = txt.replace(/\<\!\-\-/g, "");
	var etxt = ntxt.replace(/\-\-\>/g, "");
	node.value=etxt;
}