function init(){	MIN_VALUE_LENGTH=2;	//field values that are 'required' MUST have at least this many characters	MAX_VALUE_LENGTH=100;	//both optional and required fields (TEXT) can not exceed 100 characters	MAX_VALUE_LENGTH_TEXTAREA=500; //ditto for textarea, but 500 instead of 100	df=document.forms[0];	if(df)	{		var o=null;		o=df["btnSubmit"];		if(o)df["btnSubmit"].onclick=doSubmit;		o=df["cbo_Occupation"];		if(o)		{			o.onchange=updateOccupation;			if(!document.all)o.onkeypress=updateOccupation;		};		updateOccupation();		o=df["cbo_Province"];		if(o)		{			o.onchange=updateProvince;			if(!document.all)o.onkeypress=updateProvince;		};		updateProvince();	};//end if(df)	intSecondsStart=new Date().getTime()/1000;};function SinglePlural(intNum,strSingle,strPlural){	return intNum + " " + (intNum!=1 ? strPlural : strSingle);};function getRandom(iN,iR){if(!iR){iR=iN;iN=0;}else{iN=1*iN;iR=1*iR;};if(isNaN(iN))iN=0;if(isNaN(iR))iR=10;if(iN<0)iN--;return parseInt(iN+(Math.random(0)*iR));};function getRandomRange(iN,iX){iN=1*iN;iX=1*iX;if(isNaN(iN))return iX;if(isNaN(iX)){iX=iN;iN=0;};if(iX<iN){var iT=iX;iX=iN;iN=iT;};return getRandom(iN,(iX-iN)+1);};function getElement(o){	var rv=!o?null:typeof(o)=="object"?o:document.getElementById?document.getElementById(o):document.all?document.all(o):document.layers?document.layers[o]:null;	return rv;};function isFocusable(o){	var rv=false;	o=(typeof o=="string")?df[o]:(!o?null:o);	if(o && !o.type)o=o[0];	if(o)	{		switch(o.type)		{		case "hidden":			rv=false;			break;		case "submit":		case "reset":		case "button":		case "image":		case "file":		case "text":		case "textarea":		case "password":		case "select-one":		case "select-multi":		case "radio":		case "checkbox":			rv=true;			break;		};		rv=(o.focus ? rv : false);	};	return rv;};function getDropdownValue(o){	var rv="";	o=(typeof o=="string")?df[o]:(!o?null:o);	if(o && o.type=="select-one")	{		if(o.length<2)		{			o.selectedIndex=0;			rv=(o[0].value);		}		else		{			rv=(o[0].value!=o[1].value)?(o[o.selectedIndex].value):(o[o.selectedIndex].text);		};	};	return rv;};function setDropdownValue(o,s){	s=(""+s).toUpperCase();	o=(typeof o=="string")?df[o]:(!o?null:o);	if(o && o.type=="select-one" && typeof s=="string")	{		if(o.length<2)		{			o.selectedIndex=0;		}		else		{			var bUseValues=(o[0].value!=o[1].value);			var intFound=-1;			for(var i=0;i<o.length && intFound==-1;i++)			{				intFound=(!s && bUseValues) ? (o[i].value.toUpperCase()==s ? i : -1) : (o[i].value.toUpperCase()==s || o[i].text.toUpperCase()==s ? i : -1);			};			if(intFound!=-1)o.selectedIndex=intFound;		};	};};function getFieldValue(o){	var rv="";	o=(typeof o=="string")?df[o]:(!o?null:o);	if(o)	{		switch(o.type)		{		case "text":		case "textarea":		case "hidden":		case "password":			rv=o.value;			break;				case "select-one":			rv=getDropdownValue(o);			break;		case "submit":		case "reset":		case "button":		case "image":		case "file":			rv="";			break;		default:			if(!o.type && o[0].type)			{				alert(o[0].type + " 0g not finished quite yet -- not needed I guess...");			}			else			{				alert(o.type + " -g not finished quite yet -- not needed I guess...");			};			break;		};	};	return rv;};function setFieldValue(o,s){	var rv="";	o=(typeof o=="string")?df[o]:(!o?null:o);	if(o)	{		switch(o.type)		{		case "text":		case "textarea":		case "hidden":		case "password":			o.value=s;			break;				case "select-one":			setDropdownValue(o,s);			break;		case "submit":		case "reset":		case "button":		case "image":		case "file":			//skip			break;		default:			if(!o.type && o[0].type)			{				alert(o[0].type + " 0s not finished quite yet -- not needed I guess...");			}			else			{				alert(o.type + " -s not finished quite yet -- not needed I guess...");			};			break;		};	};};function setReadOnly(o,b){	if(o)	{		if(b)		{			if(o.setAttribute){o.setAttribute("readOnly",true)}else{o.readOnly=true};		}		else		{			if(o.removeAttribute){o.removeAttribute("readOnly")}else{o.readOnly=false};		};	};};function updateProvince(){	var strValue=getFieldValue("cbo_Province");	var o=df["txt_Province_Other"];	if(o)setReadOnly(o,strValue!="(other)" && strValue!="other");};function updateOccupation(){	var strValue=getFieldValue("cbo_Occupation");	var o=df["txt_Occupation_Other"];	if(o)setReadOnly(o,strValue!="(other)" && strValue!="other");};function setMS(){return "42" + new Date().getTime() + "1723";};function checkMS(){	var rv=false;	var strCheck=location.href;	if(strCheck.indexOf("&txtJS=")!=-1)strCheck=strCheck.substring(strCheck.indexOf("&txtJS=")+7);	strCheck=(strCheck.indexOf("42")!=0) ? "" : strCheck.substring(2);	strCheck=(strCheck.indexOf("1723")!=strCheck.length-4) ? "" : strCheck.substring(0,strCheck.length-4);	rv=(1*strCheck==strCheck && new Date().getTime()-(1*strCheck)<1800000);	//30minutes	return rv;};function trimWhitespace(s){	var arLines=s.split(/\n/);	for(var i=0;i<arLines.length;i++)arLines[i]=arLines[i].replace(/^\s+|\s+$/g,"");	return arLines.join("\n").replace(/\n{2,}/g,"\n");};function getEmailError(s){	var rv="";	if(!s)s="";		if(s.indexOf("@")==-1)	{		rv="does not contain a '@' character";	}	else if(s.lastIndexOf(".")<=s.indexOf("@"))	{		rv="does not contain a '.' character on the right side of the '@' character";	}	else if(s.indexOf(" ")!=-1)	{		rv="contains spaces";	};	return rv;};function FixUpPhone_ORIGINAL(strOld, strTown){	if(!strOld)strOld="";	if(!strTown)strTown="";	var rv=strOld;		//remove "(", such as with "(403) ###-####"	rv=rv.replace(/\(/g, "");		//now instead of just REMOVING the ")", we make it so ")#" becomes " #" but ") #" becomes "  #" (two spaces)	rv=rv.replace(/\)/g, " ");		//now keep only single spaces (which will be converted to "-")		while(rv.indexOf("  ")!=-1)	{		rv=rv.replace(/  /g, " ");	}		//convert spaces to "-" ... the only reason we did things this way is because of extensions etc. otherwise we coulda just removed ALL non-# and then fixed it up based ONLY on length	rv=rv.replace(/^\s+|\s+$/g, "").replace(/ /g, "-");		if(rv.length<7)	{		//less than 7 numbers SO obviously not valid		rv="";	}	else if(rv.length==7)	{		//exactly 7 numbers: ABCDEFG becomes ABC-DEFG		rv=rv.substring(0,3) + "-" + rv.substring(3);	};	if(rv.length==10 || rv.length==11)	{		//exactly 10/11 numbers: XYZABCDEFG (or XYZ-ABCDEFG, or even XYZABC-DEFG) becomes XYZ-ABC-DEFG		rv=rv.replace(/\-/g, "");		rv=rv.substring(0,3) + "-" + rv.substring(3,6) + "-" + rv.substring(6);	};		if(rv.length==8)	{		switch(strTown.toUpperCase())		{		case "AIRDRIE": case "BANFF": case "BROOKS": case "CALGARY": case "CANMORE": case "CARDSTON": case "CARSTAIRS": case "COCHRANE": case "CONSORT": case "CORONATION": case "DIDSBURY": case "DRUMHELLER": case "FORT MACLEOD": case "HANNA": case "HIGH RIVER": case "INNISFAIL": case "KANANASKIS": case "LACOMBE": case "LAKE LOUISE": case "LETHBRIDGE": case "MEDICINE HAT": case "OKOTOKS": case "OLDS": case "PINCHER CREEK": case "PROVOST": case "RED DEER": case "ROCKY MOUNTAIN HOUSE": case "STETTLER": case "STRATHMORE": case "SYLVAN LAKE": case "THREE HILLS": case "VULCAN":			rv="403-" + rv;			break;		default:			rv="780-" + rv;			break;		};	};		return rv;};//end function FixUpPhone_ORIGINAL(strOld, strTown)function FixUpPhone(strOld, strTown){	if(!strOld)strOld="";	if(!strTown)strTown="";	var rv=strOld;	if(rv.indexOf("1")==0 || rv.indexOf("+")==0)return rv;	//new 01Aug2008: leave the phone # alone if first character is "1" or "+" e.g. "1800WHATEVA" becomes "180-0WH-ATEVA" otherwise :lol: and now International numbers are left un"corrected" ;)	/*NOT ANYMORE... we want (for example) "310-FARM (3276)" to be left as-is :sigh:	//remove "(", such as with "(403) ###-####"	rv=rv.replace(/\(/g, "");		//now instead of just REMOVING the ")", we make it so ")#" becomes " #" but ") #" becomes "  #" (two spaces)	rv=rv.replace(/\)/g, " ");*/	//we *do* need this MODIFIED version though, since many phone #'s = "(403) 555-1212"	rv=rv.replace(/^\s+|\s+$/g, "");	if(rv.length>5)	{		if(rv.charAt(0)=="(" && rv.charAt(4)==")")rv=rv.substring(1,4) + (rv.substring(5).replace(/^\s+|\s+$/g, ""));	};		//now keep only single spaces, which will be converted to "-"... unless " (" which will be left alone :sigh again:	while(rv.indexOf("  ")!=-1)	{		rv=rv.replace(/  /g, " ");	}	//new 01Aug2008: temporarily replace " (" with chr(1) so it does not become "-(" :sigh once again:	rv=rv.replace(/ \(/g, "\x01");		//convert spaces to "-" ... the only reason we did things this way is because of extensions etc. otherwise we coulda just removed ALL non-# and then fixed it up based ONLY on length	rv=rv.replace(/^\s+|\s+$/g, "").replace(/ /g, "-");		//new 01Aug2008: revert chr(1) back to " ("	rv=rv.replace(/\x01/g, " (");		if(rv.length<7)	{		//less than 7 numbers SO obviously not valid		rv="";	}	else if(rv.length==7)	{		//exactly 7 numbers: ABCDEFG becomes ABC-DEFG		rv=rv.substring(0,3) + "-" + rv.substring(3);	};	if(rv.length==10 || rv.length==11)	{		//exactly 10/11 numbers: XYZABCDEFG (or XYZ-ABCDEFG, or even XYZABC-DEFG) becomes XYZ-ABC-DEFG		rv=rv.replace(/\-/g, "");		rv=rv.substring(0,3) + "-" + rv.substring(3,6) + "-" + rv.substring(6);	};	/*NOT ANYMORE -- stupid new province-wide "587" area code... >_< also "310-FARM" can't be auto-prefixed :p	if(rv.length==8)	{		switch(strTown.toUpperCase())		{		case "AIRDRIE": case "BANFF": case "BROOKS": case "CALGARY": case "CANMORE": case "CARDSTON": case "CARSTAIRS": case "COCHRANE": case "CONSORT": case "CORONATION": case "DIDSBURY": case "DRUMHELLER": case "FORT MACLEOD": case "HANNA": case "HIGH RIVER": case "INNISFAIL": case "KANANASKIS": case "LACOMBE": case "LAKE LOUISE": case "LETHBRIDGE": case "MEDICINE HAT": case "OKOTOKS": case "OLDS": case "PINCHER CREEK": case "PROVOST": case "RED DEER": case "ROCKY MOUNTAIN HOUSE": case "STETTLER": case "STRATHMORE": case "SYLVAN LAKE": case "THREE HILLS": case "VULCAN":			rv="403-" + rv;			break;		default:			rv="780-" + rv;			break;		};	};*/		return rv;};//end function FixUpPhone(strOld, strTown)function FixUpPostal(strOld){	if(!strOld)strOld="";	var rv=strOld;		rv=rv.toUpperCase().replace(/\s+/g, "");	rv=rv.replace(/\-/g, "");	if(rv.length==6)rv=rv.substring(0,3) + " " + rv.substring(3);	return rv;};function doSubmit(){	if(!window.arReq)	{		alert("OOPS -- no contact fields are displayed; nothing to submit!\n\nAdministrator must correct the Profile for this ApplicationID.");		return false;	};	//rv is the "error message" -- and possibly a 2-element array (if it needs to 'focus' after doing the alert().)	var rv="";	var strFieldName="";	var strFieldLabel="";	var strFieldValue="";	var bReq=false;	var o;	var strType="";	var strFieldsDisplayed="";		var strValueProvince=getFieldValue("cbo_Province");	var strValueOccupation=getFieldValue("cbo_Occupation");		var strFieldList=""	var strFieldsWithLengthMax="";		//reminder: first thing it does is fixup phone numbers, then goes through all of the text fields, and TRIM the values	//then it goes through all the REQUIRED fields, and if any of them are blank then it fails	//then lastly it goes through "format-required" fields (for now, just email and Occupation_Other -- but NOT the phone numbers!) and validates the values		//note: BEFORE validating all the rest, should "fix up" the phone number fields...	var strTownName="";	o=df["txt_City"];if(o)strTownName=o.value.replace(/^\s+|\s+$/g,"");	o=df["txt_Phone"];if(o)o.value=FixUpPhone(o.value, strTownName);	o=df["txt_Cell"];if(o)o.value=FixUpPhone(o.value, strTownName);	o=df["txt_Fax"];if(o)o.value=FixUpPhone(o.value, strTownName);	o=df["txt_PostalCode"];if(o)o.value=FixUpPostal(o.value);	for(var i=0;i<arReq.length && !rv;i++)	{		strFieldName=arReq[i][0];		bReq=arReq[i][1];		strFieldLabel=arReq[i][2];				o=df["cbo_" + strFieldName];		if(o)		{			strFieldName="cbo_" + strFieldName;		}		else		{			o=df["txt_" + strFieldName];			if(o)			{				strFieldsWithLengthMax+="`" + strFieldName + "=" + strFieldLabel;				strFieldName="txt_" + strFieldName;			};		};		if(!o)		{			rv="Notify Administrator: could not find `" + strFieldName + "` when validating form fields.";		}		else		{			strFieldsDisplayed+="`"+strFieldName;			strType=o.type;			if(strType && strType!="radio" && strType!="checkbox")			{				strFieldValue=trimWhitespace(getFieldValue(strFieldName));				setFieldValue(strFieldName,strFieldValue);				if(bReq && (""+strFieldValue).length<MIN_VALUE_LENGTH)				{					strFieldList+="`"+strFieldName+"="+strFieldLabel;				};			};		};//end if(!o)	};//end for(var i=0;i<arReq.length && rv;i++)	if(strFieldList)	{		rv=strFieldList.substring(1).split("`");		o=null;		for(var i=0;i<rv.length;i++)		{			strFieldLabel=rv[i].split("=");			if(!o && isFocusable(df[strFieldLabel[0]]))o=df[strFieldLabel[0]];			rv[i]=strFieldLabel[1];		};		rv=[ "You must fill in all required fields:\n\n" + rv.join("\n"), o?o:null ];	};		if(!rv)	{		//check for "maximum" length being exceeded...		var arFields=(strFieldsWithLengthMax.substring(1)).split("`");		var intCharMax=0;		var intCharCount=0;		for(var i=0;i<arFields.length && !rv;i++)		{			strFieldName=arFields[i].split("=");			var o=df["txt_" + strFieldName[0]];			if(o)			{							intCharMax=(o.type!="textarea"?MAX_VALUE_LENGTH:MAX_VALUE_LENGTH_TEXTAREA);								intCharCount=getFieldValue(o).length;				if(intCharCount>intCharMax)				{					rv=[ "The field `" + strFieldName[1] + "` is too long!\n\n" + intCharCount + " characters have been entered, when maximum for this field is " + intCharMax + ".\n\nPlease remove at least " + SinglePlural(intCharCount-intCharMax, "character", "characters") + " before submitting the form.", isFocusable(o)?o:null ];				};			};		};	};		if(!rv)	{		//now check other, "special" fields...		o=df["txt_Email"];		var strEmailError=o?getEmailError(getFieldValue(o)):"";		if(getFieldValue(o) && strEmailError)		{			rv=[ "Invalid Email: " + strEmailError + ".\n\nPlease use standard simplified format, such as User.Name@abc.hostname.xyz", isFocusable(o)?o:null ];		};	};		if(!rv)	{		if(strValueProvince=="(other)" || strValueProvince=="other")		{			o=df["txt_Province_Other"];			strFieldValue=trimWhitespace(getFieldValue(o));			setFieldValue(o,strFieldValue);			if((""+strFieldValue).length<MIN_VALUE_LENGTH)			{				rv=[ "Please fill in `other province/state`, or select one of the `Province/State` choices in the dropdown box.", isFocusable(o)?o:null ];			};		};//end if(strValueProvince=="(other)" || strValueProvince=="other")	};	};	if(!rv)	{		if(strValueOccupation=="(other)" || strValueOccupation=="other")		{			o=df["txt_Occupation_Other"];			strFieldValue=trimWhitespace(getFieldValue(o));			setFieldValue(o,strFieldValue);			if((""+strFieldValue).length<MIN_VALUE_LENGTH)			{				rv=[ "Please fill in `other occupation`, or select one of the `Occupation` choices in the dropdown box.", isFocusable(o)?o:null ];			};		};//end if(strValueOccupation=="(other)" || strValueOccupation=="other")	};	if(!rv && window.ROW_VISIBLE)	{		if(!confirmOrder())		{			o=df["txt_Order1_Agdex_Num"];			rv=[ "Please enter complete details for all of the free publications you wish to order.\n\nYou must fill in all 3 fields for each publication:\n-Agdex No.\n-Title\n-Quantity", isFocusable(o)?o:null ];		};	};	if(!rv && window.FEEDGRAINPEAS)	{		if(!confirmFeedGrainPeas())		{			o=df["txt_FeedGrainPeas_ForSaleOrWanted"];			rv=[ "Please enter complete details about the feed grain/peas you are selling or want.\n\nYou must fill in all 6 fields:\n-'For Sale Or Wanted?'\n-Quantity\n-Condition\n-Type\n-Weight\n-Price" + (df["txt_OtherComments"]?"\n\n(use the bottom textbox to provide any other details)":""), isFocusable(o)?o:null ];		};	};	if(!rv && window.FOODPROCEQUIP)	{		if(!confirmFoodProcEquip())		{			o=df["txt_FoodProcEquip_ForSaleOrWanted"];			rv=[ "Please enter complete details about the food processing equipment you are selling or want.\n\nYou must fill in all 5 fields:\n-'For Sale Or Wanted?'\n-Type Of Industry\n-Type Of Equipment\n-Make/Model\n-Year/Condition" + (df["txt_OtherComments"]?"\n\n(use the bottom textbox to provide price and/or any other details)":""), isFocusable(o)?o:null ];		};	};	var strConfirmText="Submit your response now?";	strConfirmText+="\n\nNOTE: after clicking OK, do *not* click Submit again if the form seems to take a long time to be submitted (due to Internet unpredictability).";	if(rv)	{		if(typeof(rv)=="string")		{			alert(rv);		}		else		{			alert(rv[0]);			if(rv[1])			{				// UGH -- thought this would HELP instead it's way more confusing -- doFocus();				if(rv[1].focus)				{					rv[1].focus();				}				else if(rv[1][0] && rv[1][0].focus)				{					rv[1][0].focus();				};			};		};	}	else if(confirm(strConfirmText))	{		o=df["txt_Province_Other"];		if(o && strValueOccupation!="(other)" && strValueOccupation!="other")setFieldValue(o,"");		o=df["txt_Occupation_Other"];		if(o && strValueOccupation!="(other)" && strValueOccupation!="other")setFieldValue(o,"");		var intSeconds=parseInt((new Date().getTime()/1000-intSecondsStart)*10)/10;		df["SecondsToSubmit"].value=(isNaN(intSeconds)) ? 0 : intSeconds;				df["txtJS"].value=setMS();		df["FieldsDisplayed"].value=!strFieldsDisplayed?"":(strFieldsDisplayed.substring(1));		df.submit();	};		return rv;};//Added 07Jul2008 (only used for the AgFreePubs profile, i.e. VERY specific purpose)... (COMPLETELY REDESIGNED 30Jul2008)function drawOrderTable(intRowCount){	df=document.forms[0];	if(!intRowCount || intRowCount<2)return "";		HTML_REQUIRED='<font size="+2" color="#ff0000">*</font>';		ROW_MAX=intRowCount;	//the maximum # of rows EVER possibly visible (never changes after page load!)	ROW_VISIBLE=2;		//# of rows CURRENTLY visible (always at least 2!)		var strEvents='onkeyup="updateOrder();" onclick="updateOrder();" onbeforepaste="updateOrder();"';	var rv="";	var strPrefix="";	for(var i=1;i<=ROW_MAX;i++)	{		strPrefix='txt_Order' + i + '_';		rv+='<tr style="display:' + (i>2?"none":"") + ';" id="div_Order' + i + '"><td align="right">' + (i>1 ? "" : (HTML_REQUIRED + "&nbsp;")) + i + '.</td>';		rv+='<td align="center"><input ' + strEvents + ' style="width:90%;" type="text" name="' + strPrefix + 'Agdex_Num" /></td>';		rv+='<td align="center"><input ' + strEvents + ' style="width:95%;" type="text" name="' + strPrefix + 'Title" /></td>';		rv+='<td align="center"><input ' + strEvents + ' style="width:80%;" type="text" name="' + strPrefix + 'Quantity" /></td>';		rv+='</tr>\n';	};	var strHeading='<tr><td width="5%">&nbsp;</td><td width="20%" align="center"><b>Agdex No.</b></td><td align="center"><b>Title</b></td><td width="10%" align="center"><b>Quantity</b></td></tr>\n';	rv='<table width="90%" border="' + (document.all?3:1) + '" align="center">\n' + strHeading + rv + '</table>\n';	document.write(rv);	removeEmptyRowsOrder();	//important to do this FIRST since it also sets the global variable "df" (and, of course, removes empty rows in the Order table)	return rv;};function updateOrder(){	//updates the visibility of the OrderDetails rows...	if(!df)return false;		ROW_VISIBLE=0;		//reset the # of rows visible -- this will be set based on the bottom-most blank row	var o=null;	var strPrefix="";	//cycle thru from LAST to FIRST row, until we find the first "non-blank" row (VISIBLE = that row + 1)	for(var i=ROW_MAX;i>1 && !ROW_VISIBLE;i--)	{		strPrefix='txt_Order' + i + '_';		o=getElement("div_Order" + i);		if(o && o.style)		{			if(trimWhitespace(df[strPrefix+'Agdex_Num'].value)!="" || trimWhitespace(df[strPrefix+'Title'].value)!="" || trimWhitespace(df[strPrefix+'Quantity'].value)!="")			ROW_VISIBLE=i+(i<ROW_MAX ? 1 : 0);		};	};	if(!ROW_VISIBLE)ROW_VISIBLE=2;	//cycle thru all rows, making sure to hide those that are not visible, and also to ensure the visible ones are no longer hidden (just in case)	for(var i=ROW_MAX;i>2;i--)	{		strPrefix='txt_Order' + i + '_';		o=getElement("div_Order" + i);		if(o && o.style)		{			if(i>ROW_VISIBLE)			{				if(!o.style.display)o.style.display="none";			}			else			{				if(o.style.display)o.style.display="";				//do NOT force force a blank in this row, since it's invisible -- should theoretically never happen anymore, however even if it does somehow, the SUBMIT event will be "compressing" blank rows I think			};		};	};};//end function updateOrder()function getOrderRowString(i){	var rv="";	var strPrefix='txt_Order' + i + '_';	rv=trimWhitespace(df[strPrefix+'Agdex_Num'].value).replace(/\t/g,"") + "\t" + trimWhitespace(df[strPrefix+'Title'].value).replace(/\t/g,"") + "\t" + trimWhitespace(df[strPrefix+'Quantity'].value).replace(/\t/g,"");	if(trimWhitespace(rv)=="")rv="";	return rv;};function setOrderRow(i, strValues){	if(!strValues)strValues="" + "\t" + "" + "\t" + "";	var strPrefix='txt_Order' + i + '_';	var arValues=strValues.split("\t");	if(i && df[strPrefix+'Agdex_Num'])	{		df[strPrefix+'Agdex_Num'].value=arValues[0];		df[strPrefix+'Title'].value=arValues[1];		df[strPrefix+'Quantity'].value=arValues[2];	};};function removeEmptyRowsOrder(){	if(!df)return false;	var arRowValues=[];	var strRowValue="";		//for any row that is not completely blank, store its 3 values into a returned array	for(var i=1;i<=ROW_MAX;i++)	{		strRowValue=getOrderRowString(i);		if(strRowValue)		{			arRowValues[arRowValues.length]=strRowValue;		};	};	for(var i=1;i<=ROW_MAX;i++)	{		if(!arRowValues[i-1])arRowValues[i-1]="";		setOrderRow(i, arRowValues[i-1]);	};	updateOrder();	//update the visibility of the rows, in other words	return arRowValues;};function confirmOrder(){	//FIRST, move rows "up" to replace any blanks between rows, since the top rows could now theoretically be blank (:sigh:)	//then, set the "final" values for the array that stores the table values, or set it to blank if the validation fails	var rv=true;	var arRowValues=removeEmptyRowsOrder();	var arThisRow=[];		rv=!(!arRowValues[0]);	for(var i=1;i<=ROW_MAX && rv;i++)	{		if(arRowValues[i-1])		{			arThisRow=arRowValues[i-1].split("\t");			//any incomplete rows will result in a failure (since any complete-blanks have been removed by now)			if(!arThisRow[0] || !arThisRow[1] || !arThisRow[2])			{				rv=false;			}			else			{				arRowValues[i-1]=i + ".\t" + arRowValues[i-1];			};		};	};		df["OrderDetails"].value=(!rv) ? "" : (arRowValues.join("\n"));	return rv;};// /Added 07Jul2008 (and COMPLETELY REDESIGNED 30Jul2008)// Added 30Jul2008... (only used for the FeedGrainPeas profile, i.e. VERY specific purpose -- similar to AgFreePubs order table)...function drawFeedGrainPeasTable(){	df=document.forms[0];	FEEDGRAINPEAS=true;	HTML_REQUIRED='<font size="+2" color="#ff0000">*</font>';		var strHeadingList="ForSaleOrWanted=For Sale Or Wanted?;Quantity;Condition;Type=Type of feed grain/peas;Weight;Price;";	var CONDITION_EXTRA="<br />\n(frozen, damp, tough, plump?)";		var rv="";	var strPrefix='txt_FeedGrainPeas_';	var strHeading="";	var strFieldName="";	var strLine="";		while(strHeadingList!="")	{		strHeading=strHeadingList.substring(0,strHeadingList.indexOf(";"));		strHeadingList=strHeadingList.substring(strHeadingList.indexOf(";")+1);		if(strHeading!="")		{			if(strHeading.indexOf("=")!=-1)			{				strFieldName=strHeading.substring(0,strHeading.indexOf("="));				strHeading=strHeading.substring(strHeading.indexOf("=")+1);			}			else			{				strFieldName=strHeading;			};			if(strFieldName && strHeading)			{				strLine='<tr><td width="10%">&nbsp;</td><td width="30%" align="right">';				strLine+=strHeading + ( (strHeading.indexOf("?")==strHeading.length-1) ? "" : ":" );				strLine+='</td><td width="1%" valign="top" style="vertical-align:top;">' + HTML_REQUIRED + '</td><td>\n';				if(strFieldName!="ForSaleOrWanted")				{					strLine+='<input name="' + strPrefix + strFieldName + '" value="" maxlength="100" style="width:48%">' + (strFieldName=="Condition"?CONDITION_EXTRA:"");				}				else				{					strLine+='<select name="' + strPrefix + strFieldName + '" style="width:49%">\n<option value="">--Select One--</option>\n<option value="For Sale">For Sale</option>\n<option value="Wanted">Wanted</option>\n</select>';				};				strLine+='</td></tr>\n';				rv+=strLine + "\n";			};		};	};//end while(strHeadingList!="")	if(rv)	{		rv='<table width="90%" border="' + (document.all?3:1) + '" align="center">\n' + rv + '</table>\n';		document.write(rv);	};	return rv;};function confirmFeedGrainPeas(){	var rv=true;		var strHeadingList="ForSaleOrWanted;Quantity;Condition;Type;Weight;Price;";	var arFeedGrainPeasRows=[];	var strPrefix="txt_FeedGrainPeas_";	var strFieldName="";		while(strHeadingList!="")	{		strFieldName=strHeadingList.substring(0,strHeadingList.indexOf(";"));		strHeadingList=strHeadingList.substring(strHeadingList.indexOf(";")+1);		if(strFieldName!="")		{			if(!df[strPrefix+strFieldName] || trimWhitespace(df[strPrefix+strFieldName].value)=="")			{				rv=false;			}			else			{				arFeedGrainPeasRows[arFeedGrainPeasRows.length]=trimWhitespace(df[strPrefix+strFieldName].value);			};		};	};//end while(strHeadingList!="")	if(rv)df["FeedGrainPeasDetails"].value=arFeedGrainPeasRows.join("\t");		return rv;};// /Added 30Jul2008.// Added 03Sep2008... (only used for the FoodProcEquip profile, i.e. very specific purpose -- EXTREMELY similar to FeedGrainPeas)...function drawFoodProcEquipTable(){	df=document.forms[0];	FOODPROCEQUIP=true;	HTML_REQUIRED='<font size="+2" color="#ff0000">*</font>';		var strHeadingList="ForSaleOrWanted=For Sale Or Wanted?;Industry=Type Of Industry;Equipment=Type Of Equipment;MakeModel=Make And Model;YearCond=Year And Condition;";	var rv="";	var strPrefix='txt_FoodProcEquip_';	var strHeading="";	var strFieldName="";	var strLine="";		while(strHeadingList!="")	{		strHeading=strHeadingList.substring(0,strHeadingList.indexOf(";"));		strHeadingList=strHeadingList.substring(strHeadingList.indexOf(";")+1);		if(strHeading!="")		{			if(strHeading.indexOf("=")!=-1)			{				strFieldName=strHeading.substring(0,strHeading.indexOf("="));				strHeading=strHeading.substring(strHeading.indexOf("=")+1);			}			else			{				strFieldName=strHeading;			};			if(strFieldName && strHeading)			{				strLine='<tr><td width="10%">&nbsp;</td><td width="30%" align="right">';				strLine+=strHeading + ( (strHeading.indexOf("?")==strHeading.length-1) ? "" : ":" );				strLine+='</td><td width="1%" valign="top" style="vertical-align:top;">' + HTML_REQUIRED + '</td><td>\n';				if(strFieldName!="ForSaleOrWanted")				{					strLine+='<input name="' + strPrefix + strFieldName + '" value="" maxlength="100" style="width:48%">';				}				else				{					strLine+='<select name="' + strPrefix + strFieldName + '" style="width:49%">\n<option value="">--Select One--</option>\n<option value="For Sale">For Sale</option>\n<option value="Wanted">Wanted</option>\n</select>';				};				strLine+='</td></tr>\n';				rv+=strLine + "\n";			};		};	};//end while(strHeadingList!="")	if(rv)	{		rv='<table width="90%" border="' + (document.all?3:1) + '" align="center">\n' + rv + '</table>\n';		document.write(rv);	};	return rv;};function confirmFoodProcEquip(){	var rv=true;		var strHeadingList="ForSaleOrWanted;Industry;Equipment;MakeModel;YearCond;";	var arFoodProcEquipRows=[];	var strPrefix="txt_FoodProcEquip_";	var strFieldName="";		while(strHeadingList!="")	{		strFieldName=strHeadingList.substring(0,strHeadingList.indexOf(";"));		strHeadingList=strHeadingList.substring(strHeadingList.indexOf(";")+1);		if(strFieldName!="")		{			if(!df[strPrefix+strFieldName] || trimWhitespace(df[strPrefix+strFieldName].value)=="")			{				rv=false;			}			else			{				arFoodProcEquipRows[arFoodProcEquipRows.length]=trimWhitespace(df[strPrefix+strFieldName].value);			};		};	};//end while(strHeadingList!="")	if(rv)df["FoodProcEquipDetails"].value=arFoodProcEquipRows.join("\t");		return rv;};// /Added 03Sep2008.// Added 30Jul2008...function addCountEvents(strFieldName,intMax){	//USAGE: add script immediately after the textarea: addCountEvents(TEXTAREA_FIELD_NAME[,MAX_CHARS_IF_NOT_500])		if(!intMax)intMax=500;	var o=document.forms[0];	o=o[strFieldName];	if(!o)return false;	//#1 document.write() to generate readonly INPUT field [0 used, 500 remaining]...	var strBG=(document.all ? "background:;" : "background:transparent;");	var strFontWeight=(document.all ? "font-weight:900; " : "");	var strFontSize=(document.all ? "100%" : "90%");	var strHelpTitle="click to see help for filling in this detailed text field";	var strDetailsWord=Extra_HelpText!="" ? ('<a style="font-face:verdana; color:gray;' + strFontWeight + 'font-size:' + strFontSize + ';" href="#" title="' + strHelpTitle + '" onclick="ShowHelpText(\'' + Extra_HelpText + '\'); return false;">' + "provide details</a>") : ("provide details");	var strLabel='<font size="1" color="gray" face="Verdana"><b>Please ' + strDetailsWord + ' in ' + intMax + ' characters or less</b>';	var strInput='&nbsp;&nbsp;<input type="text" readonly="1" disabled="1" style="font-face:verdana; color:gray; border:0; width:200px; ' + strBG + strFontWeight + 'font-size:' + strFontSize + '; " name="txt_' + strFieldName + '_count" value="(0 used, ' + intMax + ' remaining)" />';	document.write('<br />' + strLabel + '&nbsp;&nbsp;' + strInput + '<br /><br /></font>');	updateCount(strFieldName,intMax);	//#2 add events so when the textarea is changed, the # of chars is used to update the INPUT field...	var strEval="function(){updateCount(this.name," + intMax + ");}";	eval("o.onpaste=" + strEval + ";o.onkeyup=" + strEval + ";o.oninput=" + strEval + ";o.onfocus=" + strEval);};function updateCount(strFieldName,intMax){	//updates the READONLY textbox, and also returns the # of characters OVER the maximum the textarea contains	if(!intMax)intMax=500;	var df=document.forms[0];	var o=df[strFieldName];	if(!o)return 0;	var intLength=o.value.length;	o=df["txt_"+strFieldName+"_count"];	if(o)o.value="(" + intLength + " used, " + (intLength<=intMax ? ((intMax-intLength)+" remaining") : ((intLength-intMax)+" too many") ) + ")";	return intLength<=intMax ? 0 : (intLength-intMax);};function ShowHelpText(strText){	alert(strText);};// /Added 30Jul2008.
