var scanpos = 0;// Populating Field Optionsfunction start_wait(forid, strWait){	if(strWait=="") strWait = "Loading...";	clearOptions(forid);	var myNewOption = new Option(strWait,strWait);		document.getElementById(forid).options[0] = myNewOption;	document.getElementById(forid).value = strWait;}function clearOptions(forid){	if(isAvailable(forid)){		var aField = document.getElementById(forid);		aField.options.length = 0;	}}//for radio buttons and checkboxesfunction setRCOptions(name, type, objDiv,tUrl, tWaitMsg, defaultPos, swap, exclude) {if(swap == undefined) swap = false;if(exclude == undefined) exclude = "";AjaxRequest.get(  {    'url':tUrl    ,'onLoading':function() { objDiv.innerHTML = tWaitMsg	  }    ,'onSuccess':function(req){      		    		objDiv.textContent = "";    		objDiv.innerHTML = "";		populateRC(name , type, objDiv, req.responseText.replace(exclude, ""), defaultPos, swap); }    ,'timeout':60000		//timeout after a minute    ,'onTimeout':function(req){ alert('Sorry, timed out! Please try again.'); }    ,'onError':function(req){ 	var tError = 'Error!\nStatusText='+req.statusText+'\nContents='+req.responseText; 	alert(tError); }  });} //End function function clearRCOptions(aField, objDiv){		var html = objDiv.innerHTML	var len = aField.length;	var count = 0;	var infiniteLoop = 1500		//if it gets to that count the is a problem	while( len > 0 & count<infiniteLoop){		html =  html.replace(new RegExp(aField[len-1].value,'gi'),"");				html =  html.replace(new RegExp(aField[len-1].text,'gi'),"");				aField[len-1].remove(len-1);		len = aField.length		count++;	}	   	objDiv.innerHTML = html   	objDiv.textContent = ""}// Return new array with duplicate values removedArray.prototype.unique =  function() {    var a = [];    var l = this.length;    for(var i=0; i<l; i++) {      for(var j=i+1; j<l; j++) {        // If this[i] is found later in the array        if (this[i] === this[j])          j = ++i;      }      a.push(this[i]);    }    return a;  };function populateRC(name,type, objDiv, strReturn, defaultPos, swap){	if(swap == undefined ) swap = false;	var aString=strReturn.split("&")	var arrData = new Array();	var tCount = 0;	for (i = 0; i < aString.length; i++) {    			var lString=aString[i].split(new RegExp( "[|~]{1}", "gi" ))    			var tValue = "";    			var tText = "";			if(lString.length==2) {				tText = lString[0];				tValue = lString[1]; 			}else{				tText = lString[0];				tValue = tText;			}			if(tText != "" & tValue != "") {				if (!swap) arrData[tCount] = [tText,tValue]; else arrData[tCount] = [tValue,tText];				tCount++;			}	} //end for loop	addRC(type,name,name,arrData.sort(), objDiv, defaultPos)} //End functionfunction setFieldOptions(forid, tUrl, tWaitMsg) {AjaxRequest.get(  {    'url':tUrl    ,'onLoading':function() {  start_wait(forid, tWaitMsg); }    ,'onSuccess':function(req){  populateOptions(forid , req.responseText); }     ,'timeout':60000		//timeout after a minute    ,'onTimeout':function(req){ alert('Sorry, timed out! Please try again.'); }    ,'onError':function(req){ 	var tError = 'Error!\nStatusText='+req.statusText+'\nContents='+req.responseText; 	alert(tError); }  });} //End function setOptionsfunction populateOptions(forid, strReturn){	if(isAvailable(forid)){		var aString=strReturn.split("&")    		for (i = 0; i < aString.length; i++) {    			var lString=aString[i].split(new RegExp( "[|~]{1}", "gi" ))			var myNewOption = new Option(lString[1],lString[0]);			document.getElementById(forid).options[i] = myNewOption			if(i==0) document.getElementById(forid).value = lString[0];		}	}}//for flat optionsfunction setFlatFieldOptions(forid, tUrl, tWaitMsg, defaultValues) {	if(!isAvailable(forid)) return;AjaxRequest.get(  {    'url':tUrl    ,'onLoading':function() {  start_wait(forid, tWaitMsg); }    ,'onSuccess':function(req){  populateFlatOptions(forid , req.responseText, defaultValues); }     ,'timeout':60000		//timeout after a minute    ,'onTimeout':function(req){ alert('Sorry, timed out! Please try again.'); }    ,'onError':function(req){ 	var tError = 'Error!\nStatusText='+req.statusText+'\nContents='+req.responseText; 	alert(tError); }  });} //End function function populateFlatOptions(forid, strReturn, defaultValues){	if(isAvailable(forid)){		var tField = document.getElementById(forid);		var aString=strReturn.split("&")    		for (i = 0; i < aString.length; i++) {    			var lString=aString[i].split(new RegExp( "[|~]{1}", "gi" ))    			var tValue = "";    			var tText = "";			if(lString.length==2) {				tText = lString[0];				tValue = lString[1]; 			}else{				tText = lString[0];				tValue = tText;			}			var myNewOption = new Option(tText,tValue);			tField.options[i] = myNewOption				var tempVal = "";			for(key in defaultValues){				tempVal = defaultValues[key].toString();				if(tempVal != "" & tempVal != undefined) if(tempVal.trim() == tText.trim() | tempVal.trim() == tValue.trim()) tField.options[i].selected = true;			}		}		if(defaultValues == "undefined") tField.value = aString[i];	}}/*** Displaying embedded views **/function jumpToView(id, path, dspid,waitid, tWaitMsg, tParams){	if(tParams == undefined) tParams = '?openview';	if(isAvailable(id)){		var viewname = document.getElementById(id).value		var sKey = path + "/" +  viewname.trim();		var tUrl=path + "/" +  viewname.trim() + tParams;				if(isAvailable(dspid)) document.getElementById(dspid).style.display = 'none';AjaxRequest.get(  {    'url':tUrl    ,'onLoading':function() { wait_loading_view(waitid, tWaitMsg); }    ,'onSuccess':function(req){      		var tResult = 	scanResult(req.responseText, sKey,id, path, dspid,waitid, tWaitMsg, tParams);    		displayView(dspid , tResult, waitid); }    ,'timeout':60000		//timeout after a minute    ,'onTimeout':function(req){ alert('Sorry, timed out! Please try again.'); }    ,'onError':function(req){ 	var tError = '<center><div class="alert">\'Error!\nStatusText='+req.statusText+'\nContents='+req.responseText + "</div></center>"; 	displayView(dspid,tError, waitid); }  });	} //End if statement} // end functionfunction wait_loading_view(wid,tmsg){	var loaddiv = document.getElementById(wid);	loaddiv.style.display = "block";	document.getElementById('loadingMsg').innerHTML = tmsg;	}function displayView(dspid, content, twaitid){	if(isAvailable(dspid)){		document.getElementById(dspid).style.display = 'block';		document.getElementById(twaitid).style.display= "none";		//strip off the html, body, form tags and select only the result - as usual to try and make it work in IE.		var tmp = getstr(content,"=start_result=","=end_result=");		if (tmp != "") content = tmp;		document.getElementById(dspid).innerHTML = content;	}} //End function displayViewfunction getstr(string,query1,query2) {var startIndex =string.indexOf(query1,scanpos+1)+query1.length;if(startIndex > query1.length){var endIndex = string.indexOf(query2, startIndex + 1);scanpos = endIndex;}else {	return "";}return string.substring(startIndex,endIndex);} //End function getstrfunction ajaxViewRecall(tUrl,id, path, dspid,waitid, tWaitMsg, tParams){	if(tParams == undefined) tParams = '?openview';	if(isAvailable(id)){		var viewname = document.getElementById(id).value		var tSkey=path + "/" +  viewname.trim(); //+ tParams;				if(isAvailable(dspid)) document.getElementById(dspid).style.display = 'none';AjaxRequest.get(  {    'url':tUrl + tParams    ,'onLoading':function() { wait_loading_view(waitid, tWaitMsg); }    ,'onSuccess':function(req){      		var tResult = 	scanResult(req.responseText, tSkey,id, path, dspid,waitid, tWaitMsg, tParams);    		displayView(dspid , tResult, waitid); }    ,'timeout':60000		//timeout after a minute    ,'onTimeout':function(req){ alert('Sorry, timed out! Please try again.'); }    ,'onError':function(req){ 	var tError = '<center><div class="alert">\'Error!\nStatusText='+req.statusText+'\nContents='+req.responseText + "</div></center>"; 	displayView(dspid,tError, waitid); }  });	} //End if statement} // end ajaxViewRecall functionfunction isPartialMatch(tvalue, key){	var i = tvalue.toLowerCase().indexOf(key.toLowerCase());	if(i >= 0) return true; else return false;}function scanResult(tResult, tKey,id, path, dspid,waitid, tWaitMsg, tParams){/*	- The form display views that are actually embedded on a form and called using ajax. When the person	   clicks on the category to expand/collapse it, it needs to call the view using ajax again rather than simply opening the form with the embedded view	-  So this function goes thru the category links and replace it with an onclick event that works the ajax way.	> tResult: The resultant view served	> tKey:	The link value to scan for and make it do an ajax call intead*/scanpos = 0;tLinks = '';var tExtract = getstr(tResult,"href=\"","\"")while(tExtract != ""){	//Check if it matches the key	if(isPartialMatch(tExtract,tKey)){		 tLinks += tExtract + "~";	}		//get the next possible link	tExtract = getstr(tResult,"href=\"","\"");}//reset our pos value;scanpos = 0;var tLoop = tLinks.split('~');for(i=0;i < tLoop.length;i++){	var toReplace = tLoop[i]	if(toReplace != ""){		tResult = replaceSubstring ( tResult, "href=\"" + toReplace + "\"", " onclick=\"ajaxViewRecall('" + toReplace +"','" + id + "','"+path+"','" + dspid + "','" +waitid+"','" + tWaitMsg + "','" + tParams + "');return false;\" href=\"\"", false ) 	}}return tResult;}function replaceSubstring ( inputString, badString, goodString, caseSensitive ) {	//Taken from http://www.dominopower.com/issuesprint/issue200004/howto.html	fixedReplace = " ";	UI = inputString;	UB = badString;	if ((caseSensitive !=1) && (caseSensitive != true)) {		UI = inputString.toUpperCase();		UB = badString.toUpperCase();	}	badEnd = -1;	badLoc = UI.indexOf(UB);	if (badLoc != -1) {		for (x=1; (badLoc != -1); x++) {			fixedReplace = fixedReplace + inputString.substring((badEnd + 1), badLoc) + goodString			badEnd = badLoc + UB.length - 1;			badLoc = UI.indexOf(UB, (badLoc + 1)); 		}		fixedReplace = fixedReplace + inputString.substring((badEnd + 1), inputString.length); 	} else { 		fixedReplace = inputString; 	}	return fixedReplace;}