//jsUpdateButtonLinks.js//NEW 23Jun2008 *DS*//make sure any parms like "&sort=4" are passed on from document.referrer to button <a href> link URLs// ADDED 05Sep2008: auto-select subproile *if* UCase(QueryString) contains "OPENFORM&TYPE=###&SUBPROFILE=###-###"function updateSubprofilePerhaps(){	var o=document.forms[0]["TypeField"];	var qs=(""+location.href).toUpperCase();	var arMatch=qs.match(/OPENFORM\&TYPE\=\d+\&SUBPROFILE\=(\d+\-(\d+))/);	if(o && arMatch)	{		//will auto-select dropdown choice # [intSub], i.e. value=[intComplete]		var intComplete=arMatch[1];		var intSub=arMatch[2];				//cycle through dropdown "TypeField" and look for the first instance of value="[intComplete]", and change that value then		var bChanged=false;		var intCurrent=o.selectedIndex;		var strLabel="";		for(var i=0;i<o.length && !bChanged;i++)		{			if(i!=intCurrent && o[i].value==intComplete)			{				o.selectedIndex=i;				strLabel=o[i].text;				if(strLabel)strLabel=' -- "' + strLabel + '" --';				bChanged=true;			};		};		if(bChanged)		{			o.focus();			alert("Please wait a brief moment for the page to reload...\n\n(with Subprofile " + intComplete + strLabel + " auto-selected!)");			setTimeout("_doClick('$Refresh', document.forms[0]['TypeField'], '_self', '#_RefreshKW_TypeField')", 42);		};	};//end if(o && arMatch)	};//end function updateSubprofilePerhaps()function updateButtonLinksRTWDL(){	//global variable, so the buttons that use JS ("actionPost(5)" etc.) can also have this added to their URLs (if possible)	URL_SUFFIX="";		var PARM_LIST=";sort;";	//does nothing if "&sort=..." is not found inside the document.referrer	//but if it IS found, cycles thru all of document.links (<a href=...> anchors),	// and will update URL* to include the "&sort=..." parm, unchanged from document.referrer	//NOTE: "PARM_LIST" includes all parms to be "carried over, unchanged" -- for now it's just "&sort=..."	// *URL is appended only if it includes itself (i.e. same ".nsf/") or (".ca/app ... /notesload")	//NEW: refnum "1" = QUERYSTRING ; "2"=document.referrer (if needed, i.e. QS has none of those parms)	var intRefNum=1;	var ref=""+location.href;	while(intRefNum<3 && !URL_SUFFIX)	{		//if no "referrer" attribute is found, we MIGHT be inside a "clone" document, so check for the "referrer" attribute of this document's "opener" (i.e. parent/launcher)		//if neither finds a value, then we have no referrer -- nothing to pass along...		if(intRefNum==2)		{			ref=document.referrer;			if(!ref)			{				try{				ref=(window.opener && opener.document && opener.document.referrer) ? opener.document.referrer : "";				} catch(e) {ref="";};			};		};		if(ref)		{			var intLoc=-1;			var intLocMin=ref.length;					//cycle thru each of the possible querystring parameters that we wish to "pass along"			//if any of the parms are found in the querystring, find the "left-most" one and keep ALL to the right of its beginning			var arParms=PARM_LIST.split(";");			for(strParm in arParms)			{				if(arParms[strParm])				{					intLoc=ref.indexOf("&" + arParms[strParm] + "=");					if(intLoc!=-1 && intLoc<intLocMin)intLocMin=intLoc;				};			};			//here is where we set the global variable, which will be used immediately for the normal-URL buttons, and on submit for the JS-actionPost buttons...			URL_SUFFIX=(intLocMin!=ref.length) ? ref.substring(intLocMin) : "";		};//end if(ref)				intRefNum++;	};//end while(intRefNum<3 && !URL_SUFFIX)	if(!URL_SUFFIX)return false;	//now that we know what needs to be added to all button links, LET'S DO IT!	var o;	for(key in document.links)	{		o=document.links[key];		if(isButtonToBeUpdated(o))appendToButtonURL(URL_SUFFIX,o);	};};function isButtonToBeUpdated(o){	// *URL is appended only if it includes itself (i.e. same ".nsf/") or (".ca/app ... /notesload[and other paths besides `notesload`]")	var rv=false;	if(!o || !o.href)return false;	var strButtonURL=o.href;	var intLoc=-1;	intLoc=strButtonURL.indexOf(".nsf/");	if(intLoc!=-1)	{		rv=(location.href.substring(0,intLoc)==strButtonURL.substring(0,intLoc));	}	else	{		intLoc=strButtonURL.indexOf(".ca/app");		rv=(intLoc!=-1 && (strButtonURL.indexOf("/notesload")>intLoc || strButtonURL.indexOf("/loadlist")>intLoc || strButtonURL.indexOf("/listingmaint")>intLoc) );	};		//during testing I had a "fake" link added to the bottom of page, which includes this parm...	if(strButtonURL.indexOf("&fakelink=1")!=-1)rv=false;		return rv;};function appendToButtonURL(URL_SUFFIX,o){	if(!o || !o.href)return false;	o.href=(""+o.href)+URL_SUFFIX;	return true;};setTimeout("updateButtonLinksRTWDL()",42);setTimeout("updateSubprofilePerhaps()",142);
