var debug= false //   true // /*========================================================================Force a redirect to the 'Document Not Available' page in the ARM Combo production database if ALL of the following are true:(1) URL is for ARM Combo production database; (2) current user is NOT Anonymous; (3) URL contains "?OpenDocument" or  "fm10K_FS?OpenForm'; (4) authentication failure reason is either "1" (not authorized) or "2" (Invalid username or password").========================================================================*/function noAccessCheck() {	if(debug) {alert('Function noAccessCheck() tripped in frame "' + self.name + '".')};	var sPath = location.href.toUpperCase()  //Get current URL	var isCombo = sPath.indexOf('WK/RM.NSF');   // true if > -1	var iOpenDoc= sPath.indexOf('?OPENDOCUMENT');   // true if > -1	var iOpen10K = sPath.indexOf('FM10K_FS?OPENFORM');   // true if > -1	var sUser = document.forms[0].AuthenticatedUser.value;	var sReason = document.forms[0].reasonType.value ;		//Set flag for whether 'fmNoDoc' page should be loaded	var isNoAccess = (isCombo > -1  && sUser != "Anonymous" && (iOpenDoc > -1 || iOpen10K > -1) && (sReason =="1" || sReason=="2"))? true : false ;	//show prompt if debug flag set	if (debug) {		var sTest = "Debug for noAccessCheck(): \n\nisCombo: \n  " + isCombo + "\nAuthenticatedUser: \n  " + sUser +  "\niOpenDoc: \n  " + iOpenDoc  ;		sTest += "\niOpen10K: \n  " + iOpen10K + "\nReasonType: \n  " + sReason + "\nreferrer: \n  " + document.referrer ;		sTest +=  "\nlocation.href: \n  " + location.href + "\nframes: \n  " + top.frames.length + "\nisNoAccess: \n  " + isNoAccess;		alert( sTest);	}		//redirect to 'fmNoDoc' page if isNoAccess == true	if (isNoAccess) {		document.write("<NOSCRIPT>")  //hide remaining login form's text/fields		location.replace("/wk/rm.nsf/fmNoDoc?OpenForm&amp;rnm=" + RanNumber())	}}/*===================================================Redirect to secured, distributor login site, if applicable. ===================================================*/function reDir() {	if(debug) {alert('Function reDir() tripped in frame "' + self.name + '".')};		if ( document.forms[0].RedirectURL ) {		//Check for "&noredir" 'skip redirect' URL param		var iSkip = -1   //assume redirect will NOT be skipped		if (document.forms[0].Path_Info) {			var sParam = "&noredir"			iSkip = document.forms[0].Path_Info.value.toLowerCase().indexOf(sParam)			//if (debug) { alert('Skip re-direct setting for "&noredir": ' + iSkip) }		}					//Check for 'nologin' URL param, if above 'skip redirect' URL param was NOT set		if (iSkip == -1) {   // if '&noredir' was not present, then iSkip will remain at -1; If so, now check for '&nologin' 			if (document.forms[0].Path_Info) {				sParam = "&nologin"				iSkip = document.forms[0].Path_Info.value.toLowerCase().indexOf(sParam)				//if (debug) { alert('Skip re-direct setting for "&nologin": ' + iSkip) }			}			}				//Perform redirect to non-null URL, if applicable		var sTarget = '';		if (document.forms[0].RedirectURL.value != '') {			sTarget = document.forms[0].RedirectURL.value;		}		var doRedirect = (iSkip == -1 && sTarget != '') ? true : false ;				if (debug) { alert('Debug for reDir() : \n\niSkip: \n  ' + iSkip + '\nRedirect target: \n  ' + sTarget + '\ndoRedirect: \n  ' + doRedirect) }		if ( doRedirect ) {			top.location.replace( sTarget );		}	}}/*=======================================Set login form full screen, if in a frameset=======================================*/function showFullScreen() {	if(debug) {alert('Function showFullScreen() tripped in frame "' + self.name + '".')};	//if (document.forms[0].reasonType.value=="3") {	if (parent.frames.length > 0)  {				 		if( self != top) {					//Specially handle reloads from non-'fmain' frames (e.g., nav, toolbar) if 'fmain' is available by forcing authentication of 'fmain' page instead			if (self.name != "fmain" && parent.fmain) { //Load 'fmain' contents if it exists				top.location.replace( parent.fmain.location.href)  // dbpath + "fmFS?OpenForm&pth=" + parent.fmain.location.href+ "&end"  //			} else {				top.location.replace( self.location)			}					/*==================== SUPERCEDED BY SPECIFIC CODE ABOVE ======================			//Always reload top frameset URL			 top.location.replace( parent.top.document.location)  	// parent.top.document.location.reload(); //This is SLOW!			=====================================================================*/		}					}}/*================================Add radio buttons, if applicable================================*/function setRadios() {	if(debug) {alert('Function setRadios() tripped in frame "' + self.name + '".')};	var ckNone='';  //assume not checked	var ckUser='' ;  //assume not checked	var ckBoth='' ;  //assume not checked	var craw = getCookieData('UN')		if (debug) {		var sMsg = 'Debug for setRadios(): \n  Retrieved cookie data: \n    ' + craw + '\n  document.forms[0].Username.value: \n    ' ;		sMsg += document.forms[0].Username.value + '\n  document.forms[0].Password.value: \n    ' + document.forms[0].Password.value ;		alert(sMsg );	}		//Retrieve user info from cookie	if (craw==null) {		var uname = ''		var pw = ''	} else if (craw.indexOf('###') == -1) {		var uname = craw		var pw = ''	} else {		var uname = craw.substring(0,craw.indexOf('###'))		var pw = craw.substring(craw.indexOf('###') + 3, craw.length)	}	//Update fields based on values retrieved	if (uname == "") {		ckNone='CHECKED'		clearLogin(false) //needed for IE 6 bug where HTTP_Cookie incorectly caches info	} else {		if (pw=='') {			ckUser='CHECKED'			clearLogin(true) //needed for IE 6 bug where HTTP_Cookie incorectly caches info		} else {			ckBoth='CHECKED'		}	}		//Set radio HTML string	var sTmp = "<table cellspacing=0 cellpadding=0 border=0><tr><td class='tah'>"	sTmp += "<input type='radio' name='save' value='0' " + ckNone + ">Don't save my login</input><br>" 	sTmp += "<input type='radio' name='save' value='1' " + ckUser + ">Save my Username only</input><br>" 	sTmp += "<input type='radio' name='save' value='2' " + ckBoth + ">Save both my Username and Password</input>" 	sTmp += "</td></tr></table>"	if (debug) alert('About to write save login radio button HTML: \n' + sTmp);		document.write( sTmp);	}/*=============Set form focus=============*/function setFormFocus() {	if(debug) {alert('Function setFormFocus() tripped in frame "' + self.name + '".')};	var form = document.forms[0];		if (form) {		if (form.Username && form.Password ) {  //skip if both fields not present			if (form.Username.value == ""  ) {				form.Username.focus(); 			} else if ( form.Password.value == ""  ) {				form.Password.focus(); 			} else {  //both populated				//form.Password.select();						// form.Password.focus(); 				//form.Username.focus();  				form.elements[12].focus();  //element 12 is login button			}		}	} else {		window.location.reload(true);  //needed to force refresh so radio buttons appear		}}/*=========================Load ID/PW Request window=========================*/function setIDPW() {	if(debug) {alert('Function setIDPW() tripped in frame "' + self.name + '".')};		var starget = '/cdb/armdb.nsf/idpw?openform'	var winew=window.open( starget, '_tempwin' , 'scrollbars=0,resizable,width=800,height=450');	winew.focus();}/*============================Login/Submit (checkForm) function============================*/function checkForm() {	if(debug) {alert('Function checkForm() tripped in frame "' + self.name + '".')};		var form = document.forms[0];		if ( form.Username.value != ""  && form.Password.value !="") { //Inputs complete		//Save user info as applicable		setDist();		UpdateRemember();				//Override RedirectTo field so full Query_String is retained		form.RedirectTo.value = form.ReallyRedirectTo.value;				//Submit login form		form.submit();		return false;			} else {  //Incomplete inputs		alert ( "Please enter both your username and password." );		setFormFocus();		return false;	} }/*===========================================Either sets cookie with entered non-null username if 'Rememberny username' checkbox is checked, or if unchecked, deletes anycookie containing this saved value.===========================================*/function UpdateRemember() {	if(debug) {alert('Function UpdateRemember() tripped in frame "' + self.name + '".')};	var cval = ''	var uname=document.forms[0].Username.value;	var pwd =GetHash(document.forms[0].Password.value) //document.forms[0].PWHash.value  // document.forms[0].Password.value;		for (i=0; i < document.forms[0].save.length;i++) {		if (document.forms[0].save[i].checked) {			sel = document.forms[0].save[i].value;			break;		}	}				if (sel == '0') {		cval=''	} else if (sel=='1' && uname !='') {		cval = uname		} else if (sel =='2' && uname !='' && pwd !='') {		cval = uname + "###" + pwd	} else if (sel =='2' && uname !=''  && pwd =='') {		cval = uname 	} else {		cval =''	}	 	if(cval !='') {		if (debug) { alert('Debug for UpdateRemember(): \n  About to set cookie "UN" to value "' + cval + '".') }		SetCookie ('UN', cval)	} else {		if (debug) { alert('Debug for UpdateRemember(): \n  About to set cookie "UN" to null "###" value.') }		SetCookie ('UN', '###')		//BELOW COOKIE DELETE FAILS IN IE 6 IF BROWSER NOT CLOSED		//if (debug) { alert('Debug for UpdateRemember(): \n  About to delete cookie "UN".') }		//DeleteCookie ('UN')	}}/*====================================================================Clears Username and/or Password fields if populated. Needed for IE 6 bug where old UN cookie data is incorrectly cached by HTTP_Cookie field (but not JS!)If pwOnly param is true, only clear Password field.====================================================================*/function clearLogin(pwOnly) {	if(debug) {alert('Function clearLogin(' + pwOnly + ') tripped in frame "' + self.name + '".')};		if (document.forms[0]) {		//clear username		if (!(pwOnly)) {  //ignore Username clearing if pwOnly is true			if (document.forms[0].Username) {				if (document.forms[0].Username.value != '') {					document.forms[0].Username.value = '' ;				}			}		}		//clear password		if (document.forms[0].Password) {			if (document.forms[0].Password.value != '') {				document.forms[0].Password.value = '' ;			}		}	}}/*====================================================================Sets cookie with non-ARM branding ID; Uses Brand_Key value BEFORE authentication====================================================================*/function setDist() {	if(debug) {alert('Function setDist() tripped in frame "' + self.name + '".')};		//get current brand key setting	var sBrandKey = '';	if (document.forms[0].Brand_Key) {		sBrandKey = document.forms[0].Brand_Key.value;	}		//get any cookie brand key setting	var sBrandCookie = '';	if (document.forms[0].CookieKey) {		sBrandCookie = document.forms[0].CookieKey.value;	}	if (debug) alert('Debug for setDist(): \n  sBrandKey: \n    ' + sBrandKey + '\n  sBrandCookie: \n    ' + sBrandCookie);	//Check for if brand key update to cookie is needed	if (sBrandKey.toLowerCase() == "arm" && sBrandCookie.length == 0) {		if(debug) alert('Debug for setDist():\n  Brand cookie UNKey not set, since Brand_Key is "' + sBrandKey + '" and CookieKey is "' + sBrandCookie + '".');	} else if (sBrandKey.toLowerCase() != sBrandCookie.toLowerCase()) {		if (sBrandKey.toLowerCase() == "arm") {			if(debug) alert('Debug for setDist():\n  About to delete brand cookie UNKey, since Brand_Key is "' + sBrandKey + '" and CookieKey is "' + sBrandCookie + '".');			DeleteCookie ("UNKey") ;		} else {			if(debug) alert('Debug for setDist():\n  About to set brand cookie UNKey to "' + sBrandKey.toLowerCase() + '", since Brand_Key is "' + sBrandKey + '" and CookieKey is "' + sBrandCookie + '".');			SetCookie ("UNKey", sBrandKey.toLowerCase()) 		}		top.location.replace( top.document.location)  	}}/*==========================================================================Deletes cookie with non-ARM branding ID (Loaded by 'Reset ARM Loogin Page' link)==========================================================================*/function delDist() {	if(debug) {alert('Function delDist() tripped in frame "' + self.name + '".')};		if(debug) {alert("Debug for delDist():\n  About to delete brand cookie 'UNKey'.");}		DeleteCookie ("UNKey") ;	top.location.replace( top.document.location)  }/*===============================Handle ENTER key press (instead of Login button)===============================*/if (document.layers) { document.captureEvents(Event.KEYPRESS)}; //Required for NS4document.onkeypress = keyhandler; function keyhandler(e) {	if (e) {		if (e.which) {			var Key = e.which; 		} else {			if (e.keyCode) {				var Key = e.keyCode;			} else {				var Key = window.event.keyCode; 			}		}	} else {		var Key = window.event.keyCode; 	}	//if (debug) {alert('Key with code: ' + Key + ' was pressed!')}		if (Key == 13){		if (debug) {alert('ENTER was pressed!')}		checkForm();		return false;	} }/*==============================Prompts user if cookies are disabled==============================*/function chkCookie() {	if(debug) {alert('Function chkCookie() tripped in frame "' + self.name + '".')};	//Check if browser has cookies enabled. Warn if not.	if (chkCookiesEnabled() ) {		window.status="Cookies properly enabled."	} else {		window.status="Cookies disabled in browser."		alert("Your browser is set to not accept cookies. Please change your browser settings to accept cookies in order to access the requested page.")	}}/*==============================================Function Name:  chkCookiesEnabled()Parameters:  NoneDescription:  Determines if browser has cookies enabled 		==============================================*/function chkCookiesEnabled() {	if(debug) {alert('Function chkCookiesEnabled() tripped in frame "' + self.name + '".')};		var cookieenabled = false  //assume disabled	//For IE4+ and NS6+ , use navigator property	if (navigator.cookieenabled) {		cookieenabled = true 	} else { //if not IE4+ nor NS6+		if ( typeof navigator.cookieenabled =="undefined" && !cookieenabled ) {			//document.cookie="testcookie"  //causes new cookie at each sub-folder levels!			SetCookie ("testcookie", "1") 			if (document.cookie.indexOf("testcookie") != -1) {				cookieenabled =  true				DeleteCookie ("testcookie")			}		} 	}	return cookieenabled}/*==============================================Function Name:  getCookieData(labelName)													Parameters:  labelName (cookie label to retrieve, in case several exist)	Description: Retrieves cookie value for passed-in cookie name ==============================================*/function getCookieData(labelName) {	if(debug) {alert('Function getCookieData(' + labelName + ') tripped in frame "' + self.name + '".')};		var rtnData = null;	var labelLen = labelName.length		//Read cookie property only once for speed	var cookieData = document.cookie	var cLen = cookieData.length	var i = 0	var cEnd	while (i < cLen) {		var j = i + labelLen		//alert('cookieData.substring(i,j): ' + cookieData.substring(i,j) + '\ncookieData.substring(j,j+1): ' + cookieData.substring(j,j+1) + '\nlabelName: ' + labelName)		if (cookieData.substring(i,j) == labelName && cookieData.substring(j,j+1) == "=") {  // added cookieData.substring(j,j+1) to handle partial name matches			cEnd = cookieData.indexOf( ";", j)			if (cEnd == -1) {				cEnd = cookieData.length			}			rtnData = unescape(cookieData.substring(j + 1, cEnd))		}		i++	}	if(debug) {alert('Debug for getCookieData() \n  Data in cookie "' + labelName + '":  ' + rtnData + '.')};	return rtnData}/*==============================================Function Name:  setCookie(name, value)													Parameters:  cookie name ; cookie valueDescription: Sets cookie using passed-in cookie name and value==============================================*/function SetCookie (name, cval) {	if(debug) {alert('Function SetCookie (' + name + ',' + escape(cval) + ') tripped in frame "' + self.name + '".')};		var exp_amt = 25 * 365 * 24 * 60 * 60 * 1000; //25 years hence	var exp = new Date();	exp.setTime (exp.getTime() + exp_amt);	document.cookie = name + "=" + escape(cval) + "; expires=" + exp.toGMTString() + "; path=/";}/*================================================Function Name:  DeleteCookie(name)													Parameters:  cookie nameDescription: Deletes cookie with passed-in cookie name by dropping as expired================================================*/function DeleteCookie (name) {	if(debug) {alert('Function DeleteCookie(' + name + ') tripped in frame "' + self.name + '".')};		var exp_amt = 20 * 365 * 24 * 60 * 60 * 1000; //20 years ago	var exp = new Date(); 	exp.setTime (exp.getTime() - exp_amt);	var cval = '';	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString() + "; path=/";}/*===============Get hash string===============*/function GetHash(sval) {	var stmp=''	var snew=''	var s1=''	var s2=''	var s3=''		//check null	if (sval=='' || sval == null) {		return ''	}			//get codes	i=0	for (i =0; i < sval.length; i++) { 		stmp = sval.charCodeAt(i) ; 		stmp = '000' + stmp 		stmp = stmp.substring(stmp.length - 3, stmp.length) 		snew = snew + stmp + ","	}	snew = snew.substring(0, snew.length - 1)		var sarray = snew.split(',')	for (i=0; i < sarray.length; i++) {		s1 = s1 + sarray[i].substring(0,1)		s2 = s2 + sarray[i].substring(1,2)		s3 = s3 + sarray[i].substring(2,3)	}		var r1=Math.random() * 100	r1 = '00' + r1	r1 = r1.substring(r1.length - 2, r1.length)		var r2=Math.random() * 100	r2 = '00' + r2	r2 = r2.substring(r2.length - 2, r2.length)	return s3 + r1 + s1 + r2 + s2}/*====================Return a six-digit random number=====================*/function RanNumber() {	var ran = Math.random()	var hash = '000000' + parseInt(ran * 1000000).toString()	var ran6 = hash.substring(hash.length - 6, hash.length)	//alert('ran:   \t' + ran +'\nhash: \t' + hash + '\nsix  \t' + six);	return ran6;}/*=========================================================Reload Netscape 4 window on a  resize, since JS may not re-execute; Called via onResize event in form's HTML Body Attributes section =========================================================*/function resizeNS() {	if(debug) {alert('Function resizeNS() tripped in frame "' + self.name + '".')};		if (document.layers) {		//alert('Ran...')		//location.reload(true)  //SLOW!!!		top.location.replace( top.document.location)  	}}