// ********************** sym:Foundation **********************************
// *  ©2001, 2002, 2003, 2004 All Rights Reserved Symbiosys Consulting CC *
// ************************************************************************
// *   Description : Form Validation Functions                            *
// *   Version     : 4.1                                                  *
// *   Date        : 15 May 2004 0900                                     *
// ************************************************************************

//<root>
//	<sym:ver>
//		<sym:rel>060404.1 JD ,PCE000,</sym:rel>
//	</sym:ver>
//</root>


var blnrecordexists=false;

function FormChangeSet(objVal) {
	//document.forms[0].Post = true;
	document.formchange = true;
	if (objVal!=null) {
		document.areturn='';
		if (!ValidField(objVal.name,'n')) {

			var trimAreturn
			trimAreturn = document.areturn
			
			while (trimAreturn.search("newError")>=0) {
				trimAreturn = trimAreturn.replace("newError","")
			}
			
			if(trimAreturn!="")
				alert (trimAreturn);
			
			//objVal.value='';
			objVal.value=getOriginal(objVal);
			try {
				objVal.focus() }
			catch (e) {
				return false	}
		}
	} else {
		return true;
	}
}

function FormChangeSave() {

	var pLoc = window.location
	var printLoc = new String(pLoc)
	var oRegExp
	oRegExp=/\printformat=1/
	var qPos = printLoc.search(oRegExp)
	if (qPos>=0)
		return;

	if(document.formchange == true) {
		document.frmBody.target="saveWin"
		
		var sLoc = window.location
		var sLocStr = new String(sLoc)
		var oRegExp
		oRegExp=/\?/
		var qPos = sLocStr.search(oRegExp)
		if (qPos>=0) {
			document.frmBody.action=window.location + "&popupsave=1"
		} else {
			document.frmBody.action=window.location + "?popupsave=1"
		}
			
		saveWin = window.open ("blank.asp?resize=1",'saveWin','top=1,left=1,width=10,height=80,scrollbars=no')
		document.frmBody.submit()
	}
}

function createFormChangeCheckElement() {
	if (document.frmBody.formChangeCheck!=null) {
		document.frmBody.formChangeCheck.value="1"
	} else {
		var newFormChangeCheck = document.createElement("<INPUT TYPE='HIDDEN' NAME='formChangeCheck' VALUE='1'>")
		document.frmBody.insertBefore(newFormChangeCheck)
	}
}

function FormChangeCheck()	{

	if(document.formchange == true) {
		var bChoice;
		bChoice = window.confirm("Do you want to save your changes?");
		if(bChoice==true) {
			createFormChangeCheckElement()
			document.frmBody.submit()
		}
	}
	
	if (window.opener!=null) {
		if (window.opener.location!=null) {
			//window.opener.location.reload()
		}
	}
}

function FormChangeAlert()	{

	if(document.formchange == true) {
		event.returnValue = "You have not saved your changes, please click on Cancel and then save your changes.\nClicking on OK will result in your changes being lost.";
	} else {
		var spanResult = MM_findObject("spanResult")
		if (spanResult) {
			if (spanResult.innerHTML.search("Saving")<0) {
				spanResult.innerHTML = "<div align='left'><p class='resultPending'>Loading...please be patient.</p></div>"
				if (document.getElementsByTagName("BODY")(0)) {
					if (document.getElementsByTagName("BODY")(0).style)
						document.getElementsByTagName("BODY")(0).style.cursor = "wait"
				}
			}
		}
	}
	
}

function frmBodySubmit(pSubmitType) {
	if (pSubmitType==null)
		pSubmitType="null"
	var newFormChangeCheck = document.createElement("<INPUT TYPE='HIDDEN' NAME='oSubmitType' VALUE='" + pSubmitType + "'>")
	document.frmBody.insertBefore(newFormChangeCheck)
	document.frmBody.submit()
}

function ValidField(field,freq) {

	var fld,fldDisplay,areturn='', fvalue;
	fld = ReturnObject(field);
	//fld.originalVal = ""
	
	if ((fld.type=="hidden")||((fld.getAttribute("readonly")!=null)&&(fld.getAttribute("readonly")!=false))||(fld.style.display=="none")) {
		return(true);
	}

	fvalue = fld.value;
	if ((fld.getAttribute("required")!=null) && (document.skipvalid != true)) {
		freq="y"
	}

	fldtype = fld.name.substr(0,1);
	if (fld.name.substr(0,1)==1 || fld.name.substr(0,1)==2)	{
		fldtype = fld.name.substr(4,1);
		if (fld.name.substr(4,5)!="_")
			fldtype=""
	} else {
		if (fld.name.substr(1,2)!="_")
			fldtype=""
	}

	if (fld.getAttribute("numeric")!=null) {
		fldtype = "i"
	}
	
	var fldtel=false
	if (fld.getAttribute("telno")!=null) {
		fldtype = "t"
		fldtel=true
	}

	if (fld.getAttribute("datetime")!=null) {
		fldtype = "d"
	}

	//if (fld.name.substr(fld.name.length-2,2)=="Id") {
	//	fldtype="lookup";
	//	intIndex = fld.selectedIndex;
	//	fvalue = fld.options[intIndex].value;
	//}
	if ((fvalue != "")&&(fvalue.toLowerCase()!="null")) {
		if (fldtype == "d") {
	//		fyear = fld.value.substr(0,4);
	//		fmonth = fld.value.substr(5,2);
	//		fday = fld.value.substr(8,2);
			//alert(fyear+"|"+fmonth+"|"+fday);
	//		if ((fyear<1900 || fyear>2020) || (isNaN(fyear)==true) || (fmonth<'01' || fmonth>'12') || (isNaN(fmonth)==true)|| (fday<'01' || fday>'31') || (isNaN(fday)==true))
			//if (varTestDate!=null) { varTestDate=null; }
			var defaultDateFormat = "dd mmm yyyy"
			var defaultDateFormatEg = "21 Feb 1974"
			if (defaultDateFormat=="dd mmm yyyy") {
				var dString = new String(fvalue)
				var dRegExp = new RegExp()
				dRegExp = /\d+\s[A-Za-z]{3}\s\d{4}/
				//dRegExp = /[A-Za-z]{3}/
				//var iSearchPos = dString.search(dRegExp)
				if (!dString.match(dRegExp)) {
					areturn="The field "+ReturnTxtName(field,fld)+" should be a Date in the format (" + defaultDateFormat + "). Eg." + defaultDateFormatEg + ".\n";
					fvalue="01 Jan 2005";
				} else {
					var dayVal, monthVal, yearVal, maxDays
					maxDays=31
					//dayVal = parseInt(dString.substr(0,2))
					//dayVal = parseInt(dString.match(/\d+/))
					var sDayVal = dString.substring(0,2)
					if ((sDayVal=="08")||(sDayVal=="09")) {
						dayVal = parseInt(dString.substring(1,2))
					} else {
						dayVal = parseInt(dString.substring(0,2))
					}
					monthVal = new String(dString.match(/[a-z]{3}/i))
					monthVal = monthVal.toLowerCase()
					yearVal = parseInt(dString.match(/\d{4}/))
					if ((monthVal=="feb")&&(!isNaN(yearVal))) {

						var IsLeapYear2 = false
						if ((yearVal % 4) == 0) {
						  if ((yearVal % 100) == 0) {
						    if ((yearVal % 400) == 0) {
						      IsLeapYear2 = true
						    }
						  } else {
						    IsLeapYear2 = true
						  }
						}
						maxDays=((IsLeapYear2)?29:28)
						
					}
					if ((monthVal=="apr")||(monthVal=="jun")||(monthVal=="sep")||(monthVal=="nov"))
						maxDays=30
					if ((isNaN(dayVal))||(dayVal<=0)||(dayVal>maxDays)||(isNaN(yearVal))) {
						areturn="The field "+ReturnTxtName(field,fld)+" should be a valid Date in the format (" + defaultDateFormat + "). Eg." + defaultDateFormatEg + ".\n";
						fvalue="01 Jan 2005";
					}
				}
			}
			
			var varTestDate
			varTestDate = new Date (fvalue);
			
			if (isNaN(varTestDate)) {
				areturn="The field "+ReturnTxtName(field,fld)+" should be a Date.\n";
			} else {
				var i=1
			}
		}
		if (fldtype == "i" || fldtype == "f") {
			fld.value = removeCommas(fld.value)
			fvalue = fld.value
			if (fldtel==true) {
				fvalue = removeSpaces(fvalue)
			}
			if (isNaN(fvalue)) {
				fld.originalVal=isNaN(parseInt(fvalue))?"":parseInt(fvalue)
				areturn="The field "+ReturnTxtName(field,fld)+" should be a Number.\n";
			} else {
				if (fld.nodecimal!=null)
					fld.value=Math.round(fld.value)
				if (fld.comma!=null)
					fld.value=seperateThousands(fld.value)
			}
		}
		if (fldtype == "t" ) {
			fld.value = removeCommas(fld.value)
			fvalue = fld.value
			fvalue = removeSpaces(fvalue)
			if (fld.value.length<10) {
				fld.originalVal=fld.value
				areturn+="The field "+ReturnTxtName(field,fld)+" should be minimum of 10 digits long.\n";
			}

		}
		if (fld.requiredlength!=null) {
			if (fld.value.length!=fld.requiredlength) {
				fld.originalVal=fld.value
				areturn+="The field "+ReturnTxtName(field,fld)+" should be " + fld.requiredlength + " characters long.\n";
			}
		}
		if (fld.maximumlength!=null) {
			if (fld.value.length>fld.maximumlength) {
				fld.originalVal=fld.value.substring(0,fld.maximumlength)
				areturn+="The field "+ReturnTxtName(field,fld)+" should be at most " + fld.maximumlength + " characters long.\n";
			}
		}
		if (fld.minlength!=null) {
			if (fld.value.length<fld.minlength) {
				fld.originalVal=fld.value
				areturn+="The field "+ReturnTxtName(field,fld)+" should be at least " + fld.minlength + " characters long.\n";
			}
		}
		if (fld.email!=null) {
			re = /@/
			r=fvalue.search(re)
			re = /\./
			var s, bError
			bError=0
			s=fvalue.search(re)
			if ((r==-1)||(s==-1))
				bError=1
			if ((fvalue.charAt(fvalue.length-1)=="@")||(fvalue.charAt(fvalue.length-1)=="."))
				bError=1
			if ((fvalue.charAt(0)=="@")||(fvalue.charAt(0)=="."))
				bError=1

			if (bError==1)
				{areturn="The field "+ReturnTxtName(field,fld)+" is an invalid email address.\n";}
		}
		if (fld.pattern!=null) {
			re = new RegExp(fld.pattern)
			if (!re.test(fvalue)) {
				if (fld.patternDesc!=null)
					areturn="The field "+ReturnTxtName(field,fld)+" should be in the format " + fld.patternDesc + ".\n";
				else
					areturn="The field "+ReturnTxtName(field,fld)+" should be in the correct format.\n";
			}
		}
		
	}
	if (((fld.value == "")||(fld.value.toLowerCase() == "null")) && (freq=="y")) {
		areturn="The field "+ReturnTxtName(field,fld)+" is Required.\n";
	}
	if (areturn!='') {
		if (document.all) {
			if (fld.style.background != "yellow") {
				fld.oldbackground=fld.style.background
			}
			fld.style.background = "yellow";
			if (fld.style.display=='none') {
				fldDisplay = ReturnObject(field.replace("i_","c_") + "_display")
				if (fldDisplay!=null) {
					if (fldDisplay.style.background != 'yellow') {
						fldDisplay.oldbackground=fldDisplay.style.background
					}
					fldDisplay.style.background = 'yellow';
				}
				fldDisplay = null
			}
		}
		
		var newError = document.getElementById("imgerr" + fld.name)
		if (newError!=null) { 
			updateErrorIcon (newError, fld, areturn)
			areturn = 'newError'
		}
		
		document.areturn += areturn;
		//alert(areturn);
	} 
	else {
		if (document.all) {
			if (fld.style.background=="yellow") {
				if (fld.oldbackground!=null) {
					fld.style.background = fld.oldbackground
				} else {
					fld.style.background = "white";
				}
				//alert("here" + fld.displayName + " = " + fld.style.background)
			}
			if (fld.style.display=='none') {
				fldDisplay = ReturnObject(field.replace("i_","c_") + "_display")
				if (fldDisplay!=null) {
					if (fldDisplay.oldbackground!=null) {
						fldDisplay.style.background = fldDisplay.oldbackground
					}
					else {
						fldDisplay.style.background = 'white';
					}
				}
			}
			fldDisplay = null
		}
	}
	fld=null	
	return (areturn=='');
}

function ReturnTxtName(fname, fldObj)
{
	if (fldObj.getAttribute("displayName")!=null) {
		return fldObj.getAttribute("displayName");
	}
	var txtname,pname,tname;
	txtname= '';
	pname = fname.substr(0,fname.length);
	if (fname.substr(0,1)==1 || fname.substr(0,1)==2)
		{
		pname = fname.substr(6,fname.length-6);
		}
	//alert(pname);
	if (fname.substr(1,1)=='_') {
		pname = pname.substr(2,pname.length-2)
	}

	if (pname.substr(pname.length-2,2)== "Id" || pname.substr(pname.length-2,2)== "ID")
		{
		tname = pname.substr(0,pname.length-2);
		pname = tname;
		}
	for(var i=0;i<pname.length; i++)
	{
		if ((pname.charCodeAt(i)<97)&&(i>0))
		{
		txtname += " "
		}
	txtname += pname.charAt(i);
	}
	if (txtname.substr(txtname.length-2,2)=="Id" || txtname.substr(txtname.length-2,2)=="ID") txtname = txtname.substr(0,txtname.length-2);
	return txtname;
}

function ReturnObject(name) {
	var doc,i,obj;
  //if(!doc) doc=document; 
  //if(!(x=doc[name])&&doc.all) obj=doc.all[name];
  //for (i=0;!obj&&i<doc.forms.length;i++) obj=doc.forms[i][name];
  //if(!obj && document.getElementById) obj=document.getElementById(name); return obj;
  for(var u=0;u<document.forms['frmBody'].length;u++)
		{
		if(name==document.forms['frmBody'][u].name) obj =document.forms['frmBody'][u];
		}
	return obj;
}

function Validate()
	{
	removeErrorIcons()
	var i; 
	var vfield;
	document.validating=true;
	document.areturn = '';
	for (i=0;i<document.frmBody.length;i++)
	{
	vfield = document.frmBody[i];
	if ((vfield.name.substr(0,3)!='btn')&&(vfield.type!="hidden")&&(vfield.readonly==null))
			{
			ValidField(vfield.name,'n');
			//alert(vfield.name);
			}
	}

	var trimAreturn
	trimAreturn = document.areturn
	
	var bError = false
	while (trimAreturn.search("newError")>=0) {
		trimAreturn = trimAreturn.replace("newError","")
		bError = true
	}
	
	if(trimAreturn!="")
		{
			alert("The following fields have errors:\n"+document.areturn);
			bError = true
		}

	if (bError==true) {
//**		var spanResult = MM_findObject("spanResult")
//**		if (spanResult!=null) {
//**			spanResult.innerHTML = "<div align='right'><p class='resultError'>Errors found on page.</p></div>"
//**		}
//**		if (document.getElementsByTagName("BODY")(0)!=null)
//**			if (document.getElementsByTagName("BODY")(0).style!=null)
//**				document.getElementsByTagName("BODY")(0).style.cursor = "default"
	}


	document.areturn = (document.areturn == '');
	document.validating=false;
	document.validated=true;
}

function doSubmit() {
document.formchange=false; 

return true
}
		
		
function openProjectWin (url) {
	if (self.parent!=null) {
		self.parent.frames('body').location=url
	} else {
		var projectWin
		projectWin = window.open (url,'projectWinVar','top=5,left=5,width=800,height=600,scrollbars=yes')
	}
}

function setFirstFocus() {
	for (i=0;i<document.frmBody.length;i++)	{
		vfield = document.frmBody[i];
		bSetFocus=true
		if ((vfield.type=="hidden")||(vfield.style.display=="none")) {
			bSetFocus=false
		}
		if (vfield.name.search("sys")>=0) {
			bSetFocus=false
		}
		if (bSetFocus==true) {
			//alert(vfield.name)
			vfield.focus()	
			return
		}
	}
}

var addButton
function setNewItemFocus(pObjName) {
	if (addButton!=null) {
		for (i=document.frmBody.length-1;i>=0;i--) {
			if ((document.frmBody[i]).name!=null) {
				if (document.frmBody[i].name.search(addButton)>=0) {
					var addButtonPos=i
				}
			}
		}
	}
	if (addButtonPos==null)
		var addButtonPos=document.frmBody.length-1
	for (i=addButtonPos;i>=0;i--)	{
		if ((document.frmBody[i]).name!=null) {
			//alert (document.frmBody[i].name + " " + document.frmBody[i].name.search(pObjName).toString())
			if (document.frmBody[i].name.search(pObjName)>=0) {
				document.frmBody[i].focus()
				return
			}
		}
	}	
}

function splitNumber(pVal,pWhat) {
	var pStr = pVal.toString()
	var iDec = pStr.indexOf(".")
	
	var wholeNumStr
	var decNumStr
	
	if (iDec==-1) {
		wholeNumStr=pStr
		decNumStr=""
	} else {
		wholeNumStr=pStr.substr(0,iDec)
		decNumStr=pStr.substr(iDec+1)
	}
	
	if (pWhat=="decimal") {
		return (decNumStr)
	} else {
		return (wholeNumStr)
	}
	
}

function formatDecimal(pVal,pNumDecimals) {
	pVal=removeCommas(pVal)
	var wholeNumStr = splitNumber (pVal,"whole")
	var decNumStr = splitNumber (pVal,"decimal")
	
	var decNumStrRounded=decNumStr
	while (decNumStrRounded.length>pNumDecimals) {
		if (decNumStrRounded.length>pNumDecimals) {
			decNumStrRounded = decNumStrRounded.substr(0,pNumDecimals) + "." + decNumStrRounded.substr(pNumDecimals)
		}
		decNumStrRounded = Math.round(decNumStrRounded).toString()
	}
	
	if (decNumStrRounded.length<parseFloat(pNumDecimals)) {
		for (var k=1;k<(pNumDecimals-decNumStrRounded.length);k++) {
			decNumStrRounded = decNumStrRounded + "0"
		}
	}
	
	if (decNumStrRounded.length > 0) 
		var retValue = wholeNumStr + "." + decNumStrRounded
	else
		var retValue = wholeNumStr 
	
	return (retValue)
}

function seperateThousands(pVal) {

	pVal=removeCommas(pVal)
	var wholeNumStr = splitNumber (pVal,"whole")
	var decNumStr = splitNumber (pVal,"decimal")
	
	var newWholeNumStr=""
	var k=1
	for (var j=wholeNumStr.length-1;j>=0;j--) {
		newWholeNumStr = wholeNumStr.charAt(j) + newWholeNumStr
		if (((k%3)==0)&&(j!=0)) {
			newWholeNumStr="," + newWholeNumStr
		}
		k=k+1
	}
	
	wholeNumStr=newWholeNumStr
	
	if (decNumStr.length==0) {
		return wholeNumStr
	} else {
		return wholeNumStr + "." + decNumStr
	}
}

function removeCommas(pVal) {
	var pStr = pVal.toString()
	while (pStr.search(",")>-1) {
		pStr=pStr.replace(",","")
	}
	
	return pStr
}

function removeSpaces(pVal) {
	var pStr = pVal.toString()
	while (pStr.search(" ")>-1) {
		pStr=pStr.replace(" ","")
	}
	
	return pStr
}

function sumFields (pFieldName) {
	var fGrandTotal = 0
	var ColumnName = pFieldName.substr(4)
	var rowCount = 101
	while (document.frmBody(rowCount + "_sysRow")!=null) {
	  if(document.frmBody(rowCount + "_" + ColumnName)!=null) {
		if (!isNaN(parseFloat(document.frmBody(rowCount + "_" + ColumnName).value)))
			fGrandTotal = fGrandTotal + parseFloat(removeCommas(document.frmBody(rowCount + "_" + ColumnName).value))
	  }
	  rowCount = rowCount + 1
	}
	document.frmBody("Total" + ColumnName).value=seperateThousands(fGrandTotal)
}

function formatForPrint(dontAutoPrint) {
	var x
	for (var i=document.frmBody.length-1;i>=0;i--) {
		//alert (document.frmBody[i].type);
		switch (document.frmBody[i].tagName.toUpperCase()) {
			case "INPUT" :
				//alert (document.frmBody[i].type);
				switch (document.frmBody[i].type) {
					case "button" :
						document.frmBody[i].style.display='none';
						break;
					case "submit" :
						document.frmBody[i].style.display='none';
						break;
					case "image" :
						document.frmBody[i].style.display='none';
						break;
					case "radio", "checkbox" :
						break;
					default :
						if ((document.frmBody[i].value!=null)&&(document.frmBody[i].type!="hidden")&&(document.frmBody[i].style.display!="none")) {
							document.frmBody[i].outerHTML=document.frmBody[i].value
						}
						break;
				}
				break;
			case "TEXTAREA" :
				if ((document.frmBody[i].style.display!="none")) {
					if(document.frmBody[i].innerHTML.length>0) {
						var hInner = document.frmBody[i].innerHTML.toString()
						//alert (hInner);
						document.frmBody[i].outerHTML=hInner
						//document.frmBody[i].outerHTML=document.frmBody[i].outerHTML.toString() + "<p>" + hInner + "</p>"
					} else {
						document.frmBody[i].outerHTML=""
					}
				}
				break;
			case "SELECT" :
				var sValue = document.frmBody[i].options[document.frmBody[i].selectedIndex].text
				sValue = sValue.replace ("<","&lt;")
				document.frmBody[i].outerHTML = sValue
				break;
			default :
				x=1 //dummy statement
				break;
		}
	}
	var arrImgs = document.body.getElementsByTagName("IMG")
	for (i=arrImgs.length-1;i>=0;i--) {
		if (arrImgs[i].noprint!=null)
			arrImgs[i].outerHTML=""
	}
	arrImgs = document.body.getElementsByTagName("TR")
	for (i=arrImgs.length-1;i>=0;i--) {
		if (arrImgs[i].noprint!=null)
			arrImgs[i].style.display="none"
	}
	arrImgs = document.body.getElementsByTagName("INPUT")
	for (i=arrImgs.length-1;i>=0;i--) {
		if (arrImgs[i].type=="image") {
			if (arrImgs[i].noprint!=null)
				arrImgs[i].outerHTML=""
		}
	}
	arrImgs = document.body.getElementsByTagName("TD")
	for (i=arrImgs.length-1;i>=0;i--) {
		if (arrImgs[i].className=="Tab") {
				arrImgs[i].style.display="none";
		}
		if (arrImgs[i].className=="tabHighlight") {
			x=2 //dummy statement
		}
	}
	
	var arrLinks = document.body.getElementsByTagName("A");
	for (var j=arrLinks.length-1;j>=0;j--) {
		if (arrLinks[j].noprint!=null)
			arrLinks[j].outerHTML=""
		else
			arrLinks[j].outerHTML="<font class='A' style='text-decoration:underline;'>" + arrLinks[j].innerHTML + "</font>"
	}
	
	if (!(dontAutoPrint=='excel'||dontAutoPrint=='word')) {
		self.print()
	} else {
		var pLoc
		pLoc = window.location
		var printLoc = new String(pLoc)
		var oRegExp

		oRegExp=/ProductView/
		var qPos = printLoc.search(oRegExp)
		if(qPos>0) {
			var qView = '&view=p'
		} else {
			var qView = '&view=a'
		}
		if (dontAutoPrint=='word') {


			window.open ('wordexcelinstructions.asp?format=word'+qView,'winInstr','top=200,left=200,height=300,width=300')
		} else {
			window.open ('wordexcelinstructions.asp?format=excel'+qView,'winInstr','top=200,left=200,height=300,width=300')
		}
	}
}


function setupEventObject(e) {
	// Map NS event object to IEs
	if (e==null) return // IE returns
	window.event = e
	window.event.fromElement = e.target
	window.event.toElement = e.target
	window.event.srcElement = e.target
	window.event.x = e.x
	window.event.y = e.y
	// Route the event to the original element
	// Necessary to make sure _tip is set.
	window.event.srcElement.handleEvent(e);
}

function checkName(src) {
	// Look for tooltip in IE
	var oldSRC = src
		//if ((src.outerHTML)&&(src!=null))
			//top.status=src.outerHTML
	while ((src!=null) && (src.href==null)) {
		src = src.parentElement
	}
	if (src!=null)
		return src
	else
		return oldSRC
}


function hideLinks(e) {
	// Mouse moves over an element
	setupEventObject(e)
	var el = checkName(window.event.srcElement)
	//alert (top.status)
	//if ((el.outerHTML)&&(el!=null))
	//	top.status=el.outerHTML
}

function MM_findObject(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObject(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function getOriginal(el) {
  if (el.getAttribute("originalVal")!=null) {
	return el.originalVal
  } else
	return ""
}

function setOriginal(el) {
	el.setAttribute("originalVal") = el.value
}

function handleMouseClick() {
  if (event.button==2) {
	alert("Could not retrieve browser information.");
	window.event.cancelBubble = true;
	window.event.returnValue = false;
	return(false);
  }  
}

function returnRandomLocation(pLoc) {
	var rNumber, rString, rIndex, rObj, pString, rChar, rCode, rEsc
	rCode = "pccfgn"
	rNumber = parseInt((9999999999 - 1000000000 + 1) * Math.random() + 1000000000)
	rObj = /\?/
	pString = new String(pLoc)
	rChar = pString.substring(pString.length-1,pString.length)
	if (rChar=="#") {
		pString = pString.substring(0,pString.length-1)
	}

	var nRegExp = new RegExp(rCode)
	var nIndex = pString.search(nRegExp)
	if (nIndex>-1) {
		var xString=pString.substring(nIndex,nIndex+rCode.length+1+10)
		var xObj = new RegExp(xString)
		pString = pString.replace(xObj,"")
		pString = pString.substring(0,pString.length-1)
	}

	rIndex = pString.search(rObj)
	if (rIndex==-1) { 
		rString = new String("?" + rCode + "=" + rNumber.toString())
		rEsc = "\?"
	} else {
		rString = new String("&" + rCode + "=" + rNumber.toString())
		rEsc = "\&"
	}
	
	pString+=rString
	//return pString
	
	
	var oLoc = new String(pLoc)

			var rAttrib = "pccfgn"
			var rOldValue = ""
			var rNewValue = rNumber
			
			var nRegExp = new RegExp(rAttrib)
			
			var attribIndex = oLoc.indexOf(rAttrib)
			if (attribIndex>-1) {
				var ampIndex = oLoc.indexOf("&",attribIndex)
				if (ampIndex==-1) {
					ampIndex = oLoc.length
				}
				
				var rAttribComplete = oLoc.substring(attribIndex,ampIndex)
				
				rOldValue = rAttribComplete.replace(rAttrib + "=", "")
				
				if (oLoc.indexOf("?" + rAttrib + "=")>-1) {
					oLoc = oLoc.replace("?" + rAttrib + "=" + rOldValue, "?" + rAttrib + "=" + rNewValue)
				} else {
					oLoc = oLoc.replace("&" + rAttrib + "=" + rOldValue, "&" + rAttrib + "=" + rNewValue)
				}

				
			} else {
				if (oLoc.indexOf("?")>-1)
					oLoc = oLoc + "&" + rAttrib + "=" + rNewValue
				else
					oLoc = oLoc + "?" + rAttrib + "=" + rNewValue

			}
			
			return oLoc
	
}

function setFormAction(pForm,pAction,pButton) {
	if (pAction=="delete") {
		if(!self.confirm('Are you sure you want to delete this item?')) {
			return false
		}
	}
	if (pAction=="save") {
		var spanResult = MM_findObject("spanResult")
		if (spanResult) {
			spanResult.innerHTML = "<div align='left'><p class='resultPending'>Saving...please be patient.</p></div>"
			if (document.getElementsByTagName("BODY")(0)) {
				if (document.getElementsByTagName("BODY")(0).style)
					document.getElementsByTagName("BODY")(0).style.cursor = "wait"
			}
		}
	}
	if (document.frmBody.symFormAction!=null) {
		document.frmBody.symFormAction.value=pAction
	} else {
		var newFormAction = document.createElement("<INPUT TYPE='HIDDEN' NAME='symFormAction' VALUE='" + pAction + "'>")
		document.forms(pForm).insertBefore(newFormAction)
	}
}

function updateErrorIcon(pNewError,pControl,pMessage) {
	
	if (pNewError!=null) {
		pNewError.alt= pMessage
		pNewError.title = pMessage
		pNewError.style.display="inline"
	}
}

function removeErrorIcons() {
	var arrImgs = document.body.getElementsByTagName("IMG")
	for (i=arrImgs.length-1;i>=0;i--) {
		if (arrImgs[i].ERROR!=null)
			arrImgs[i].style.display = "none"
	}
}

function popupWin(pURL) {
	var popupWin = window.open(pURL,"popupWin","top=50,left=100,width=600,height=500,scrollbars=1")
}

function appendFunction(pEvent, pFunction) {
	if (pEvent!=null) {
		var pFunctionCut = new String(pFunction)
		var pEventCut = new String(pEvent)

		/*
		if (pFunctionCut.search("{")>0) 
			pFunctionCut = pFunctionCut.substring(pFunctionCut.search("{")+1,pFunctionCut.length)

		if (pEventCut.lastIndexOf("}")>0) 
			pEventCut = pEventCut.substring(0, pEventCut.lastIndexOf("}")-1)

		pEventCut += pFunctionCut
		*/
		alert("xx:" + pFunctionCut)
		alert("yy:" + pEventCut)
		
		if (pEventCut.search("symFunctionBind")>=0) {
			
			var sFunctionName = "three();"
			var sRandomName = pEventCut.substring(pEventCut.indexOf("symFunctionBind"),pEventCut.indexOf("symFunctionBind")+25)
			alert("sFunctionName=" + sFunctionName)
			alert("sRandomName=" + sRandomName)
			pEventCut = pEventCut.replace("}",sFunctionName + "\n}")
			eval(pEventCut)
			pEventCut = eval(sRandomName)

		} else {
		
			var rNumber
			rNumber = parseInt((9999999999 - 1000000000 + 1) * Math.random() + 1000000000)
			
			eval("function symFunctionBind" + rNumber.toString() + "() {one();two();}")
			pEventCut = eval("symFunctionBind" + rNumber.toString())
		}
		
	} else {
		var pEventCut = pFunction
	}
	return pEventCut
}



//document.onmousedown = handleMouseClick
