/**
**	I perform a product search for MI.com
*/	
var parameters = "";
var initFilter = false;

		function setParameters(_desc,_val) {
			if(_val != "N/A")
				parameters = parameters + "±" + _desc + " " + _val;
		}

	function imgLoadErr(obj,_src) {
		if(_src)
			obj.src = _src;
		else
			obj.src = "/motion3/images/spacer.gif";
	}

function toggleLanguage(_lang) {

	var en = new RegExp("/(es|fr|en)/",["g"])
	
	var _loc = "'" + window.location;
	
	if(en.test(_loc)) {
		_loc = _loc.replace(en,"/" + _lang + "/");
	}

	window.location = _loc.substring(1);
}


function validateSearchByEmail(lang) {
	var fields 		= new Array();
	fieldCounter 	= 0;
	
	fields[fieldCounter++] = new requiredField("ORDER_SEARCH_EMAIL","leftEmailLABEL","EMAIL");
	fields[fieldCounter++] = new requiredField("ORDER_SEARCH_OCN","leftOcnLABEL","OCN");

	return validatePage(fields,lang);
}
	
function signout() {
 	document.forms[0].action = makeUnSecure("signout.jsp");
	document.forms[0].AM_ACTION.value  = "SignoutAM";
	document.forms[0].AM_FIRST.value = "Y";
	document.forms[0].BUS_ACTION.value = "SIGNOUT";
  	document.forms[0].submit(); 
}
	
function purge(_lang) {
	if(confirmPurge(0,_lang)) {
		document.forms[0].action = makeUnSecure("purgeOrder.jsp");
		document.forms[0].AM_ACTION.value  = "PurgeOrderAM";
		document.forms[0].AM_FIRST.value = "Y";
		document.forms[0].BUS_ACTION.value = "purgeOrder";
		document.forms[0].submit();
	}
}
	function clearForm() {
		var formList = document.forms[0].elements;
		for(r=0; r < formList.length; r++) {
			if(formList[r].type == "select-one")
				formList[r].selectedIndex = 0;
			else if(formList[r].type == "text") {
				if(formList[r].name == "dueMonth")
					formList[r].value = "mm";
				else if(formList[r].name == "dueDay")
					formList[r].value = "dd";
				else if(formList[r].name == "dueYear")
					formList[r].value = "yyyy";
				else
					formList[r].value = "";
			}
		}
	}

	function limitedSearch(_busAction) {
	 	document.forms[0].action ="limitedProductSearch.jsp";
		document.forms[0].AM_ACTION.value  = "LimitedProductSearchAM";
		document.forms[0].BUS_ACTION.value = _busAction;
		if(_busAction && (_busAction == "new" || _busAction == "NEW")) {
			if(document.forms[0].SPECIAL_SEARCH)
				document.forms[0].SPECIAL_SEARCH.value = ""
		}
		document.forms[0].submit();
	}
	
	function validSearch(_lang) {

		var fields 		= new Array();
		fieldCounter 	= 0;

		doc.forms[0].SEARCH_DESC.value = doc.forms[0].SEARCH_DESC.value.trim();
		var searchString = 	doc.forms[0].SEARCH_DESC.value;
		var mfrSelectedIndex = doc.forms[0].SELECT_MFR.selectedIndex;
		var reqType		= doc.forms[0].SEARCH_FIELD[doc.forms[0].SEARCH_FIELD.selectedIndex].value;

		switch(reqType) {
			
			case 'M' :
				if(isNaN(searchString)) {
					fields[fieldCounter++] = new requiredField("SEARCH_DESC","SEARCH_DESC_LABEL","mino");
				} else {
					fields[fieldCounter++] = new requiredField("SEARCH_DESC","SEARCH_DESC_LABEL","itemNumber");
				}
				break;
			case 'C' :
				fields[fieldCounter++] = new requiredField("SEARCH_DESC","SEARCH_DESC_LABEL","text");
				break;
			default:
				fields[fieldCounter++] = new requiredField("SEARCH_DESC","SEARCH_DESC_LABEL","text");
		}
			

		return validatePage(fields,_lang);

	}

	function validSearchMRO(_lang) {

		var fields 		= new Array();
		fieldCounter 	= 0;

		doc.forms[0].SEARCH_DESC.value = doc.forms[0].SEARCH_DESC.value.trim();
		var searchString = doc.forms[0].SEARCH_DESC.value;
		var mfrSelectedIndex = doc.forms[0].SELECT_MFR.selectedIndex;
		var reqType		= doc.forms[0].SEARCH_FIELD[doc.forms[0].SEARCH_FIELD.selectedIndex].value;

		if(document.forms[0].customer && document.forms[0].customer.length > 0)
			fields[fieldCounter++] = new requiredField(new selectBox("customer",0),"customerLABEL","select");
			
		switch(reqType) {
			
			case 'M' :
				if(isNaN(searchString)) {
					fields[fieldCounter++] = new requiredField("SEARCH_DESC","SEARCH_DESC_LABEL","mino");
				} else {
					fields[fieldCounter++] = new requiredField("SEARCH_DESC","SEARCH_DESC_LABEL","itemNumber");
				}
				break;
			case 'C' :
				fields[fieldCounter++] = new requiredField("SEARCH_DESC","SEARCH_DESC_LABEL","text");
				break;
			default:
				fields[fieldCounter++] = new requiredField("SEARCH_DESC","SEARCH_DESC_LABEL","text");
		}
			

		return validatePage(fields,_lang);

	}
	
	function partSearch(_busAction,validation,_action) {

		var temp = window.location.href;
		if(temp && (temp.indexOf("motionMRO.jsp") == -1 && temp.indexOf("oci/") == -1))
		 	document.forms[0].action = "productSearch.jsp";
				
		if(_action)
		 	document.forms[0].action = _action;
			
		document.forms[0].AM_ACTION.value  = "ProductSearchAM";

		if(_busAction == "new" || _busAction == "NEW") {
			try{setMFR(document.forms[0].SELECT_MFR);}catch(e) {}
		}

		if(initFilter)
			document.forms[0].BUS_ACTION.value = "MFR_ONLY";
		else 
		document.forms[0].BUS_ACTION.value = _busAction;
		if(_busAction && (_busAction == "new" || _busAction == "NEW")) {
			if(document.forms[0].SPECIAL_SEARCH)
				document.forms[0].SPECIAL_SEARCH.value = ""
		}
		
		if(validation) {
			var valid = "";
	
			if(validation.indexOf("(") != -1)
				valid = validation;
			else
				valid = validation + "()";
	
			if(validation == "none")	{
		document.forms[0].submit();
			} else if(eval(valid))	{
				document.forms[0].submit();
	}
		} else {	
			document.forms[0].submit();
		}
	}
	
	function search(_busAction) {
		partSearch(_busAction);
	}

	function setMFR(_box) {
		if(_box.selectedIndex && _box.selectedIndex > 0) {
		setValue('FILTER_DESC',_box[_box.selectedIndex].text);
		setValue('MFR',_box[_box.selectedIndex].value);
		setValue('CATEGORY',2);
		initFilter = true;
		} else {
			setValue('FILTER_DESC',"");
			setValue('MFR',"");
			setValue('CATEGORY',2);
			initFilter = false;
	}
	}

	function searchMfrOnly(mfrCode,mfrName,busAction) {
		setValue('SPECIAL_SEARCH',"MFRCTLNO!" + mfrCode);
		setValue('SEARCH_DESC',mfrName);
		setValue('FILTER_DESC',mfrName);
		setValue('MFR',mfrCode);
		setValue('CATEGORY',2);
		try {
			if(document.forms[0].SEARCH_FIELD)
				document.forms[0].SEARCH_FIELD.selectedIndex = 0;
		} catch(e) {}

		if(document.forms[0].SHOW_ALL_RESULTS)
			document.forms[0].SHOW_ALL_RESULTS.value = "";

		if(document.forms[0].LAST_SEARCH_TERM)
			document.forms[0].LAST_SEARCH_TERM.value = ""
		partSearch("MFR_ONLY");
	}
	
	function searchParametric() {
		// arguments cgc,_desc,_desc2, desc3, desc4
	  //FORMAT PARAMETRIC!CGC050303±Material Steel±
	  
   		var cgcCount = parseInt(arguments.length,10);
	  	var cgc = arguments[0];
		var paraAction = "";
		var paraLevel = "0"

		setValue('CATEGORY',1);

		try {
			if(document.forms[0].SEARCH_FIELD)
				document.forms[0].SEARCH_FIELD.selectedIndex = 0;
		} catch(e) {}

		if(document.forms[0].LAST_SEARCH_TERM)
			document.forms[0].LAST_SEARCH_TERM.value = ""

		switch(cgcCount) {
			case 5:
				setValue('lvl4_cgc',cgc.substring(0,8));
				setValue('lvl4_descr',arguments[4]);
			case 4:
				setValue('lvl3_cgc',cgc.substring(0,6));
				setValue('lvl3_descr',arguments[3]);
			case 3:
				setValue('lvl2_cgc',cgc.substring(0,4));
				setValue('lvl2_descr',arguments[2]);
			case 2:
		setValue('lvl1_cgc',cgc.substring(0,2));
				setValue('lvl1_descr',arguments[1]);
		}
		
		switch(cgcCount) {
			case 5:
			case 4:
			case 3:
				paraAction = cgc.substring(2,4) + arguments[2];
				paraLevel = "1";
				break;
			case 2:
				paraAction = cgc.substring(0,2) + arguments[1];
				break;
		}

		//FORMAT PARAMETRIC!CGC050303±Material Steel±
		if(parameters && parameters.length > 0)
			cgc = cgc + parameters;

		setValue('SPECIAL_SEARCH',"PARAMETRIC!CGC" + cgc); // VIEW ALL from parametric
		setValue('PARAMETRIC_ACTION',paraAction);
		setValue('PARAMETRIC_LEVEL',paraLevel);
	  	setValue('SEARCH_DESC','');
	  	partSearch("PARAMETRIC");
	}
	
	function setCGC1(amAction,busAction,validation,action,level1Category,cgc1) {
		try {
			if(document.forms[0].SEARCH_FIELD)
				document.forms[0].SEARCH_FIELD.selectedIndex = 0;
		} catch(e) {}

		document.forms[0].lvl1_descr.value = level1Category;
		document.forms[0].lvl1_cgc.value = cgc1;
		if(action.indexOf(".jsp") > 0)
			submitPage(amAction,busAction,validation,action);
		else
			submitPage(amAction,busAction,validation);
	}
	
	function setCGC2(amAction,busAction,validation,action,level2Category,cgc2,level1Category,cgc1) {
		try {
			if(document.forms[0].SEARCH_FIELD)
				document.forms[0].SEARCH_FIELD.selectedIndex = 0;
		} catch(e) {}

		document.forms[0].lvl2_descr.value = level2Category;
		document.forms[0].lvl2_cgc.value = cgc2;
		document.forms[0].lvl1_descr.value = level1Category;
		document.forms[0].lvl1_cgc.value = cgc1;	
		if(action.indexOf(".jsp") > 0)
			submitPage(amAction,busAction,validation,action);
		else
			submitPage(amAction,busAction,validation);
	}
	
	function searchCGC() {
		// arguments cgc,_desc,_desc2, desc3, desc4
	  	//FORMAT PARAMETRIC!CGC050303±Material Steel±
	  
   		var cgcCount = parseInt(arguments.length,10);
	  	var cgc = arguments[0];
		var paraAction = "";
		var paraLevel = "0"

		setValue('CATEGORY',1);

		try {
			if(document.forms[0].SEARCH_FIELD)
				document.forms[0].SEARCH_FIELD.selectedIndex = 0;
		} catch(e) {}

		if(document.forms[0].LAST_SEARCH_TERM)
			document.forms[0].LAST_SEARCH_TERM.value = ""

		switch(cgcCount) {
			case 5:
				setValue('lvl4_cgc',cgc.substring(0,8));
				setValue('lvl4_descr',arguments[4]);
			case 4:
				setValue('lvl3_cgc',cgc.substring(0,6));
				setValue('lvl3_descr',arguments[3]);
			case 3:
				setValue('lvl2_cgc',cgc.substring(0,4));
				setValue('lvl2_descr',arguments[2]);
			case 2:
				setValue('lvl1_cgc',cgc.substring(0,2));
				setValue('lvl1_descr',arguments[1]);
		}

		switch(cgcCount) {
			case 5:
			case 4:
			case 3:
				paraAction = cgc.substring(2,4) + arguments[2];
				paraLevel = "1";
				break;
			case 2:
				paraAction = cgc.substring(0,2) + arguments[1];
				break;
		}

		//FORMAT PARAMETRIC!CGC050303±Material Steel±
		if(parameters && parameters.length > 0)
			cgc = cgc + parameters;

		if(document.forms[0].SHOW_ALL_RESULTS)
			document.forms[0].SHOW_ALL_RESULTS.value = "";

		setValue('SPECIAL_SEARCH',"CGC!" + cgc);	// VIEW everywhere else
		setValue('PARAMETRIC_ACTION',paraAction);
		setValue('PARAMETRIC_LEVEL',paraLevel);
	  	setValue('SEARCH_DESC','');
	  	partSearch("PARAMETRIC");
	}
	
	function setCGC1(amAction,busAction,validation,action,level1Category,cgc1) {
		try {
			if(document.forms[0].SEARCH_FIELD)
				document.forms[0].SEARCH_FIELD.selectedIndex = 0;
		} catch(e) {}

		document.forms[0].lvl1_descr.value = level1Category;
		document.forms[0].lvl1_cgc.value = cgc1;
		if(action.indexOf(".jsp") > 0)
			submitPage(amAction,busAction,validation,action);
		else
			submitPage(amAction,busAction,validation);
	}
	
	function setCGC2(amAction,busAction,validation,action,level2Category,cgc2,level1Category,cgc1) {
		try {
			if(document.forms[0].SEARCH_FIELD)
				document.forms[0].SEARCH_FIELD.selectedIndex = 0;
		} catch(e) {}

		document.forms[0].lvl2_descr.value = level2Category;
		document.forms[0].lvl2_cgc.value = cgc2;
		document.forms[0].lvl1_descr.value = level1Category;
		document.forms[0].lvl1_cgc.value = cgc1;	
		if(action.indexOf(".jsp") > 0)
			submitPage(amAction,busAction,validation,action);
		else
			submitPage(amAction,busAction,validation);
	}
	
	function adCustomerSearch(amAction,busAction) {
		SearchPage = window.open("","Advanced_Customer_Search","toolbar=yes,dependent=yes,menubar=yes,scrollbars=yes,resizeable=yes,status=yes,width=550,height=300");
		this.document.forms[0].target = "Advanced_Customer_Search";
		submitPage('CustomerSearchAM','switch-account','none','customerSearch.jsp');
		this.document.forms[0].target = "";
		document.forms[0].action = "motionMRO.jsp";
		this.document.forms[0].AM_ACTION.value = amAction;
		this.document.forms[0].BUS_ACTION.value = busAction;
	}
	
	
	function toggleSearchCat(id,_which) {
		var _me = 1;
		if(_which)
			_me = _which;
		switch(id) {
			case 0:
				if(_me == 1) {
					if(document.getElementById("product"))
					document.getElementById("product").className = "selected";
					document.getElementById("brand").className = "not-selected";
					document.getElementById("keyword").className = "not-selected";
				} else if(_me == 2) {
					if(document.getElementById("product"))
					document.getElementById("product").className = "not-selected";
					document.getElementById("brand").className = "selected";
					document.getElementById("keyword").className = "not-selected";
				} else if(_me == 3) {
					if(document.getElementById("product"))
					document.getElementById("product").className = "not-selected";
					document.getElementById("brand").className = "not-selected";
					document.getElementById("keyword").className = "selected";
				}

				if(document.getElementById("product"))
				document.getElementById("product-listing").className = "hideThis";
				document.getElementById("brand-listing").className = "hideThis";
				document.getElementById("keyword-listing").className = "hideThis";
				break;
			case 1:
				if(document.getElementById("product"))
				document.getElementById("product").className = "selected";
				document.getElementById("brand").className = "not-selected";
				document.getElementById("keyword").className = "not-selected";

				if(document.getElementById("product"))
				document.getElementById("product-listing").className = "showThis";
				document.getElementById("brand-listing").className = "hideThis";
				document.getElementById("keyword-listing").className = "hideThis";
				break;
			case 2:
				if(document.getElementById("product"))
				document.getElementById("product").className = "not-selected";
				document.getElementById("brand").className = "selected";
				document.getElementById("keyword").className = "not-selected";

				if(document.getElementById("product"))
				document.getElementById("product-listing").className = "hideThis";
				document.getElementById("brand-listing").className = "showThis";
				document.getElementById("keyword-listing").className = "hideThis";
				break;
			case 3:
				if(document.getElementById("product"))
				document.getElementById("product").className = "not-selected";
				document.getElementById("brand").className = "not-selected";
				document.getElementById("keyword").className = "selected";

				if(document.getElementById("product"))
				document.getElementById("product-listing").className = "hideThis";
				document.getElementById("brand-listing").className = "hideThis";
				document.getElementById("keyword-listing").className = "showThis";
				break;
		}
		setValue("CATEGORY",id);
	}
	
	var lastBrandId = 0;
	
	function toggleBrandListing(id) {
		for(x=1;x<=4;x++) {
			if(document.getElementById("brand-listing-"+x).className == "showThis")
				lastBrandId = x;
			document.getElementById("brand-listing-"+x).className = "hideThis";
		}
		
		document.getElementById("brand-listing-"+(lastBrandId + id)).className = "showThis";
 	
	 	if((lastBrandId + id) == 1)
			document.getElementById("previous").className = "hideThis";
		else if((lastBrandId + id) == 4)
			document.getElementById("next").className = "hideThis";
		else {
			document.getElementById("previous").className = "showThis";
			document.getElementById("next").className = "showThis";
		}

	}
	
/* redirect to supplier inMotion for Supplier Portal */
function supplierPortal() {
/*	
  var df0 = document.forms[0];
  df0.action = "portal.jsp";
  var temp = makeSecure(df0.action);
  var url = temp.substring(0,temp.lastIndexOf(df0.action)-1);
  url = url.substring(0,url.lastIndexOf("/"));
  if (url.indexOf("motionindustries.com") != -1) {
  	  url = url.substring(0, url.indexOf("motionindustries.com")) + 
  	  "supplierinmotion.com" +
  	  url.substring(url.indexOf("motionindustries.com")+20, url.length);
  }
  df0.action = url + "/misupplier/portal.jsp";
  if (df0.AM_ACTION.value != 'LoginAM') {
  	  df0.AM_ACTION.value = 'PortalAM';
  }
  if (df0.AM_FIRST) {
 	 df0.AM_FIRST.value = '';
  }
  document.forms[0].submit();
*/
  var df0 = document.forms[0];
  var count = 3;
  df0.action = "portal.jsp";
  var temp = makeSecure(df0.action);
  var urlHolder = temp.substring(temp.indexOf("//")+2,temp.length).split("/");
  var url = temp.substring(0,temp.indexOf("//")+2) + urlHolder[0];
  for(var x=1;x<count;x++) {
	  url += ("/" + urlHolder[x]);
  }
  if (url.indexOf("motionindustries.com") != -1) {
  	  url = url.substring(0, url.indexOf("motionindustries.com")) + 
  	  "supplierinmotion.com" +
  	  url.substring(url.indexOf("motionindustries.com")+20, url.length);
  }
  df0.action = url + "/misupplier/portal.jsp";
  if (df0.AM_ACTION.value != 'LoginAM') {
  	  df0.AM_ACTION.value = 'PortalAM';
  }
  if (df0.AM_FIRST) {
 	 df0.AM_FIRST.value = '';
  }
  document.forms[0].submit();
  
}
	
	
/* <![CDATA[ */
<!--

var now = new Date();
// fix the bug in Navigator 2.0, Macintosh
fixDate(now);
// cookie expires in one year (actually, 365 days)
// 365 days in a year
// 24 hours in a day
// 60 minutes in an hour
// 60 seconds in a minute
// 1000 milliseconds in a second
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
var userid = getCookie("userInformation");

function confirmLogin() {
 	document.forms[0].action = makeSecure("motionMRO.jsp");
	document.forms[0].AM_ACTION.value  = "MotionLoginAM";
	document.forms[0].AM_FIRST.value = "Y";
	document.forms[0].BUS_ACTION.value = "review";
	document.forms[0].APP_LOGIN.disabled = false;
	this.document.forms[0].USERNAME.value = this.document.forms[0].USERNAME.value.toUpperCase();
	if(this.document.forms[0].storeUserID && this.document.forms[0].storeUserID.checked) {
		if(!userid) {
			userid = this.document.forms[0].USERNAME.value;
			setCookie("userInformation",userid, now);
		} else if(userid != this.document.forms[0].USERNAME.value) {
			userid = this.document.forms[0].USERNAME.value;
			setCookie("userInformation",userid, now);
		}
	} else {
		deleteCookie("userInformation");
	}
  	document.forms[0].submit(); 
}

function makeSecure(_fileName) {
	/*
		LOCAL	: http://10.0.155.100:9080/MIWeb/servlet/mii/motionMRO.jsp
		DEV		: http://dev.miindustrial.com/motion3/jsp/mii/motionMRO.jsp
		PROD	: http://www.miindustrial.com/motion3/jsp/mii/motionMRO.jsp
	*/
	
	var temp = window.location.href;
	var SECURE = "https";
	if(temp.indexOf("localhost") > 0 || temp.indexOf("http://10") ==  0)
		SECURE = "http";
	var URL = SECURE + temp.substring(temp.indexOf("://"),temp.lastIndexOf("/")+1) + _fileName;
	return URL;
}

function makeUnSecure(_fileName) {
	var temp = window.location.href;
	var UNSECURE = "http";
	var URL = UNSECURE + temp.substring(temp.indexOf("://"),temp.lastIndexOf("/")+1) + _fileName;
	return URL;
}


function createAccount(_busAction) {
//	http://localhost:9080/MIWeb/servlet/mi/checkout.jsp
 	document.forms[0].action = makeSecure("checkout.jsp");
	document.forms[0].AM_ACTION.value  = "ChekoutAM";
	document.forms[0].BUS_ACTION.value = _busAction;
	
  	document.forms[0].submit(); 
}

function continueShopping() {
	window.location = makeUnSecure("index.html");
}

function clearUserName() {
	var testIt = document.forms[0].USERNAME.value;
	if(testIt == "username" || testIt == "nombre de usuario" || testIt == "Nom de l'utilisateur") {
		document.forms[0].USERNAME.value = "";
	}
}

function clearThis(_obj,_checkIt) {
	var testIt = document.forms[0].elements[_obj.name].value;
	if(testIt == _checkIt)
		document.forms[0].elements[_obj.name].value = "";
}

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

// Note: I recommend you use a more comprehensive event management script for
// production (aka "live") pages.
// Dean Edwards' event manipulation functions is a good example. You can find
// them here: http://dean.edwards.name/weblog/2005/10/add-event2/
var LoadHandler = {
  handlers:[],
  add:function(fn){
    if(window.onload!=LoadHandler.theHandler) LoadHandler._push(window.onload);
    LoadHandler._push(fn);
    window.onload=LoadHandler.theHandler;
  },
  _push:function(fn){
    if(typeof(fn)!='function') return;
    LoadHandler.handlers[LoadHandler.handlers.length]=fn;
  },
  theHandler:function(){
    var handlers=LoadHandler.handlers,i=-1,fn;
    while(fn=handlers[++i]) fn();
  }
}

// Example 2 (JS part 1)
function changeInputType(
  oldElm, // a reference to the input element
  iType, // value of the type property: 'text' or 'password'
  iValue, // the default value, set to 'password' in the demo
  blankValue, // true if the value should be empty, false otherwise
  noFocus) {  // set to true if the element should not be given focus
  if(!oldElm || !oldElm.parentNode || (iType.length<4) || 
    !document.getElementById || !document.createElement) return;
  var isMSIE=/*@cc_on!@*/false; //http://dean.edwards.name/weblog/2007/03/sniff/
  if(!isMSIE){
    var newElm=document.createElement('input');
    newElm.type=iType;
  } else {
    var newElm=document.createElement('span');
    newElm.innerHTML="<input type='" + iType + "' name='" + oldElm.name + "' onkeypress=\"idKeyPress(event,'userLogin')\">";
    newElm=newElm.firstChild;
  }
  var props=['name','id','className','size','tabIndex','accessKey','onkeypress'];
  for(var i=0,l=props.length;i<l;i++){
    if(oldElm[props[i]]) newElm[props[i]]=oldElm[props[i]];
  }
  newElm.onfocus=function(){return function(){
    if(this.hasFocus) return;
    var newElm=changeInputType(this,'password',iValue,
      (this.value.toLowerCase()==iValue.toLowerCase())?true:false);
    if(newElm) newElm.hasFocus=true;
  }}();
  newElm.onblur=function(){return function(){
    if(this.hasFocus)
    if(this.value=='' || (this.value.toLowerCase()==iValue.toLowerCase())) {
      changeInputType(this,'text',iValue,false,true);
    }
  }}();
 // hasFocus is to prevent a loop where onfocus is triggered over and over again
  newElm.hasFocus=false;
  // some browsers need the value set before the element is added to the page
  // while others need it set after
  if(!blankValue) newElm.value=iValue;
  oldElm.parentNode.replaceChild(newElm,oldElm);
  if(!isMSIE && !blankValue) newElm.value=iValue;
  if(!noFocus || typeof(noFocus)=='undefined') {
    window.tempElm=newElm;
    setTimeout("tempElm.hasFocus=true;tempElm.focus();",1);
  }
  return newElm;
}
/* ]]> */