<!--
function MM_findObj(n, d) { //v4.01
  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_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function buildDoubleDelegate(function1,function2) {
    return function() {
        if (function1)
            function1();
        if (function2)
            function2();
    }
}
        
function Seperate(intLevel) {
	return "[sep(" + intLevel + ")/]";
}

function displayCalendar(e, id, format, showsTime, showsOtherMonths, xOff, yOff) {
    e = (e == null) ? window.event : e;
    var objWork
    objWork = document.getElementById(id);
    var _position = getAbsolutePosition(objWork);
    return showCalendar(id, format, showsTime, showsOtherMonths, _position.x - xOff, _position.y - yOff);
}

function swapDisplays(strName,optMode) {
	if (!(objWork = document.getElementById(strName))) return false;
	switch (optMode) {
		case 0:
			objWork.className += " hidden";
			return 0;
			break;
		case 1:
			objWork.className = replaceAll(objWork.className,"hidden", "");
			return 1;
			break;
		default:
			if (objWork.className.indexOf("hidden") != -1) {
				objWork.className = replaceAll(objWork.className,"hidden", "");
				return 1;
			}else{
				objWork.className += " hidden";
				return 0;
			}
			break;
	}
}

 function removeClassName(e,cls) {
     if (typeof e == "string") {
         e = document.getElementById(e);
     }
     //code to change and replace strings
     var ec = ' ' + e.className.replace(/^s*|s*$/g,'') + ' ';
     var nc = ec;
     cls = cls.replace(/^s*|s*$/g,'');
     //check if there
     if (ec.indexOf(' '+ cls +' ') != -1) {
         //found, so lets remove it
         nc = ec.replace(' ' + cls.replace(/^s*|s*$/g,'') + ' ',' ');
     }
     //return the changed text!
     e.className = nc.replace(/^s*|s*$/g,''); //trimmed whitespace
     return true;
}

function addClassName(e,cls) {
     if (typeof e == "string") {
         e = document.getElementById(e);
     }
     var ec = ' ' + e.className.replace(/^s*|s*$/g,'') + ' ';
     //check if not already there
     if (ec.indexOf(' '+ cls +' ') != -1) {
         //found return without adding
         return false;
     }
     e.className = ec + ' ' + cls + ' '
}

function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
	}
	return true;
}

function isInteger(val){
	for(var i=0;i<val.length;i++){
		if(!isDigit(val.charAt(i))){return false;}
		}
	return true;
	}

function isNumeric(val){return(parseFloat(val,10)==val);}

function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
	}

function showModal(intMode) { 
	switch(intMode) {
		case 1: 
			window.open("/public/popup_account_reasons.aspx", null, "height=375px,width=375px");
			break;
		case 2:
			window.open("/public/newsletter/container.aspx", null, "height=325px,width=695px");
			break;	
		case 3:
			window.open("/public/popup_search_tips.aspx", null, "height=425px,width=375px");
			break;
		case 4:
			window.open("popup_invoice_help.aspx", null, "height=435px,width=520px");
			break;
		case 5:
			window.open("/public/vms_demo.htm", null, "height=360, width=640");
	}
}

function locateRadioItem(strField, strValue) {
	for(ri=0; ri <= document.getElementsByName(strField).length; ri++) {
		if (document.getElementsByName(strField).item(ri).value == strValue) {
			return ri;
		}
	}
	return strField;
}

function resetIndex(obj){obj.value = "";}
function enableElement(obj, blnDisabled){obj.disabled = blnDisabled;}

function getField(strField, blnSuppress) {
    var objField = document.getElementById(strField);
	switch (getFieldType(strField).toLowerCase()) {
		case "radio": 
			objField = document.getElementsByName(strField);
			if (objField.length == 0) objField = document.getElementsByName(strField.replace(/_/g,"$"));
			for (var s = 0; s < objField.length; s++) {
				if(objField[s].checked == true )
					return objField[s].value;
			}
			return "";
		case "checkbox":
			if (objField.checked == true)
				return "True";
			else
				return "False";
		case "select-multiple":
			var strReturn = ""; var i = 0;
			for(i=0;i<objField.length;i++){
				if (objField.getAttribute('SubmitAll') != null) {
		            strReturn += objField.options[i].value + Seperate(99);
		        }else{
			        if(objField.options[i].selected == true){
		                strReturn += objField.options[i].value + Seperate(99);
                    }
                }
			}
			return strReturn;
		case "label":
			return objField.innerHTML;
		case null:
		    if (blnSuppress != true) alert('Field ' + strField + ' does not exist');
		    return "";
		default :
			return objField.value;
	}
}

function getFieldLiteral(strField, strMatchValue) {
    var objField = document.getElementById(strField);
	switch (getFieldType(strField)) {
		case "radio": 
			objField = document.getElementsByName(strField);
			if (objField.length == 0) objField = document.getElementsByName(strField.replace(/_/g,"$"));
			for (var s = 0; s < objField.length; s++) {
				if(objField[s].checked == true || objField[s].value == strMatchValue)
				    if (objField[s].getAttribute('SummaryText') == null)
					    return objField[s].value;
					else
					    return objField[s].getAttribute('SummaryText');
			}
			return "";
		case "checkbox":
			if (objField.checked == true || strMatchValue == "True")
		    	if (objField.getAttribute('SummaryText') == null)
				    return "True";
				else
				    return objField.getAttribute('SummaryText');
			else
				return "";
        case "select-one":
            if (strMatchValue != null) {
                for(i=0;i<objField.length;i++){
                     if(objField.options[i].value == strMatchValue)
                        if (objField.options[i].getAttribute('SummaryText') == null)
			                return objField.options[i].text;
			            else
                            return objField.options[i].getAttribute('SummaryText');
                }
            }else{
                if (objField.selectedIndex != null && objField.selectedIndex != -1)
			        if (objField.options[objField.selectedIndex].getAttribute('SummaryText') == null)
		                return objField.options[objField.selectedIndex].text;
		            else
		                return objField.options[objField.selectedIndex].getAttribute('SummaryText');
            }
            return "";
		case "select-multiple":
			var strReturn = ""; var i = 0;
			for(i=0;i<objField.length;i++){
                if (objField.getAttribute('SubmitAll') != null) {
				    if(strReturn != "") strReturn += ",";
				        if (objField.options[i].getAttribute('SummaryText') == null)
			                strReturn += objField.options[i].text;
			            else
			                strReturn += objField.options[i].getAttribute('SummaryText');
		        }else{
				    if(objField.options[i].selected == true || objField.options[i].value == strMatchValue){ 
				        if(strReturn != "") strReturn += ","
				        if (objField.options[i].getAttribute('SummaryText') == null)
			                strReturn += objField.options[i].text;
			            else
			                strReturn += objField.options[i].getAttribute('SummaryText');
                    }
                }
			}
			return strReturn;
		case "label":
			return objField.innerHTML;
		case null:
		    return "";
		default :
		    if (strMatchValue != null) return strMatchValue;
		    if (objField.getAttribute('SummaryText') == null)
			    return objField.value;
			else
			    return objField.getAttribute('SummaryText');
	}
}

function setField(strField,strValue) {
	var objField = document.getElementById(strField);
	//alert(getFieldType(strField));
	switch (getFieldType(strField).toLowerCase()) {
		case "radio":
			objField = document.getElementsByName(strField);
			if (objField.length == 0) objField = document.getElementsByName(strField.replace(/_/g,"$"));
			for (var s = 0; s < objField.length; s++) {
				if(objField[s].value == strValue)
					return objField[s].checked = true;
			}
			break;
		case "checkbox":
			if (strValue == "True")
				objField.checked = true;
			else
				objField.checked= false;
			break;
		case "select-multiple":
			var i = 0; var j = 0;
			var aryOptions = strValue.split(Seperate(99));
			for(i=0;i<document.getElementById(strField).length;i++){
				document.getElementById(strField).options[i].selected = false;
				for(j=0;j<aryOptions.length;j++) {
					if(document.getElementById(strField).options[i].value == aryOptions[j]) document.getElementById(strField).options[i].selected = true;
				}
			}
			break;
		case "label":
			objField.innerHTML = strValue;
			break;
		case null:
		    break;
		default :
			objField.value = strValue;
			break;
	}
}

function inArray(aryList,strValue) {
	for (var i=0;i<aryList.length;i++) if (aryList[i] == strValue) return(true);
	return(false);
}

function getFieldType(strField) {
	var strFieldType
	var objField = document.getElementById(strField);
	if (objField == null) objField = document.getElementsByName(strField).item(0);
	if (objField == null) objField = document.getElementsByName(strField.replace(/_/g,"$")).item(0);
	if (objField == null) return null;
	if (objField.type != null) strFieldType = objField.type;
	if (strFieldType == null && objField[0] != null) {
		if (objField[0].type != null) strFieldType = objField[0].type;
	}
	if (strFieldType == null && objField.tagName != null) strFieldType = objField.tagName;
	return (strFieldType);
}

function setRequiredField(strField){
	var objField = document.getElementById(strField);
	if (objField == null) objField = document.getElementsByName(strField).item(0);
	var strFieldType = objField.type;
	switch (strFieldType) 
	{
		case "text": case "textarea": case "checkbox":
			objField.className = "required";
			break;
		case "select-one": case "select-multiple":
			objField.className = "requiredSelect";
			break;
		case "radio": case "hidden":
			break;
	}
}

function isChecked(strField, strValue) {
	var strCompare = null;
	objField = document.getElementsByName(strField);
	for (var s = 0; s < objField.length; s++) {
		if(objField[s].checked == true )
			strCompare = objField[s].value;
	}
	if (strValue == "" && strCompare != null) return true;
	if (strCompare == strValue){
		return true;
	}else{
		return false;
	}
}

function verifyReportField(strValue, strField, intType) {
    return verifyField(strValue, strMainContentControlPrefix + strField, intType);
}

function verifyField(strValue, strField, intType) {
    if (strValue == null) if (getField(strField, true) != "") strValue = getField(strField); else strValue = "";
	switch (intType) {
		case 0: default: //not empty
			if (isBlank(strValue)) return false;
			break;
		case 1: //phone
			var strFilter = /^(\d{10}|\d{3}-\d{3}-\d{4}|\(\d{3}\) \d{3}-\d{4})$/;
			return strFilter.test(strValue);
			break;
		case 2: //social with dashes
			/*
			var strSSN = getField(strField);
			if ((window.event.keyCode != 8) && (strSSN.length == 3 || strSSN.length == 6)) {
				strSSN = strSSN + "-";
				document[strForm][strField].value = strSSN;
			}
			else if ((strSSN.length == 5 || strSSN.length == 8) && (strSSN.charAt(strSSN.length - 1) == "-")) {
				//If they typed a "-" after we've already inserted one for them, back theirs out.
				strSSN = strSSN.substring(0,strSSN.length - 1);
				document[strForm][strField].value = strSSN;
			}*/
			var strFilter = /^[0-9]{3,3}\-[0-9]{2,2}\-[0-9]{4,4}$/;
			return strFilter.test(strValue);
			break;
		case 3: //social with no dashes
			return false;
			break;
		case 4: //email
			//var strFilter = /^.+@.+\..{2,3}$/;
			//return strFilter.test(strValue);
			var strFilter1 = /^.+@.+\..{2,3}$/;
			var strFilter2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
			if (strFilter1.test(strValue) == false || strFilter2.test(strValue) == false)
				return false
            else
				return true
			break;
		case 5: //checked
			if (!isChecked(strField, "")) return false;
			break;
		case 6: //numeric
			return(isNumeric(strValue));
			break;
		case 7: //date
			return isDate(strValue,"MM/DD/YYYY");
			break;
		case 8: //integer
			return(isInteger(strValue));
			break;
		case 9: //integer and greater than 0
			if (isInteger(strValue))
				if (strValue > 0) return(true);
			return(false);
			break;
		case 10: //email or blank valid
			if (isBlank(strValue)) return true;
			var strFilter = /^.+@.+\..{2,3}$/;
			return strFilter.test(strValue);
			break;
		case 11: //email and NOT Blank
			if (isBlank(strValue)) return false;
			var strFilter = /^.+@.+\..{2,3}$/;
			return strFilter.test(strValue);
			break;
		case 12: //numeric and greater than 0
			if (isNumeric(strValue))
				if (strValue > 0) return(true);
			return(false);
			break;
		case 13: //date or blank valid
			if (isBlank(strValue)) return true;
			return isDate(strValue,"MM/DD/YYYY");
			break;
	}
	return true;
}

function isDate (sDate,sFormat) {
	var aDaysInMonth=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	var sSepDate=sDate.charAt(sDate.search(/\D/));
	var sSepFormat=sFormat.charAt(sFormat.search(/[^MDY]/i));
	if (sSepDate!=sSepFormat) return false;
	var aValueMDY=sDate.split(sSepDate);
	var aFormatMDY=sFormat.split(sSepFormat);
	var iMonth,iDay,iYear;
	iMonth = aValueMDY[0];
	iDay   = aValueMDY[1];
	iYear  = aValueMDY[2];
	if ( iMonth == null 
		|| iDay == null
		|| iYear == null )
		return false;
	if (  !isInteger( iMonth )
		||!isInteger( iDay   )
		||!isInteger( iYear  ) )
		return false;
	if(iYear.length!=4) return false;
	if(iYear<1900) return false;
	var iDaysInMonth=(iMonth!=2)?aDaysInMonth[iMonth-1]:
		((iYear%4==0 && iYear%100!=0 || iYear % 400==0)?29:28);
	return (iDay!=null && iMonth!=null && iYear!=null
			&& iMonth<13 && iMonth>0 && iDay>0 && iDay<=iDaysInMonth);
}

function replaceAll( str, from, to ) {
    var idx = str.indexOf( from );
    while ( idx > -1 ) {
        str = str.replace( from, to ); 
        idx = str.indexOf( from );
    }
    return str;
}

function ShowPopupContent(strAName, strNotes, strType) {
	if (strType == null) return false;
    window._CurrentPopup = new PopupWindow(strType);
	window[strType + "_Content"].innerHTML = strNotes;
	window._CurrentPopup.populate(window[strType].innerHTML);
	IsMenuOpen = true;
	window._CurrentPopup.showPopup(strAName);
}

function trimToLength(strString, intLength) {
	if (strString.length > intLength) {
		var strNew = strString.substr(0, intLength - 3);
		strNew += "...";
		//alert(strNew);
		return strNew;
	}else{
		return strString;		
	}
}

function ReformatDate(strField,e)	//Handle the re-formatting of the Date as they type
{			
  	var strDate = getField(strField);
  	
  	if ((e == 47) && (strDate.length == 1))
		strDate = "0" + strDate;
  	if ((e == 47) && (strDate.length == 4)) {
  		strSave = strDate.charAt(strDate.length - 1);
  		strDate = strDate.substring(0,strDate.length - 1) + "0" + strSave;
	}
  	
	if ((e != 8) && (e != 47) && (strDate.length == 2 || strDate.length == 5))
		strDate = strDate + "/";
	else if ((strDate.length == 4 || strDate.length == 7) && (e == 47))
		//If they typed a "/" after we've already inserted one for them, back theirs out.
		strDate = strDate.substring(0,strDate.length - 1);
	setField(strField,strDate);
}

Constants = new Object();
	Constants.FieldName = 0;
	Constants.FieldType = 1;
	Constants.FieldSummary = 2;
	Constants.FieldVerify = 3;
	Constants.FieldRequired = 4;
	Constants.FieldForServerUpdate = 5;
	Constants.FieldDisabled = 6;

function DataControl(strSection, strSummaryLabel, strSummary, strAddID, strSaveID, strCancelID, strUpdateCommand, strOutputField) {
	this.Bin = new Array();
	this.Items = new Array();
	this.Section = strSection;
	this._Parent = null;
	this.Count = -1;
	this.Current = -1;
	this.Required = 0;
	this.IsMultiple = true;
	this.Edit = "Edit";
	this.EditClass = "underline pointer emphasis";
	this.EditActive = "Save";
	this.EditActiveClass = "underline pointer color7 emphasis";
	this.View = "View";
	this.ViewClass = "underline pointer color5 emphasis";
	this.ViewActive = "View";
	this.ViewActiveClass = "underline pointer color5 emphasis";
	this.Delete = null;
	this.DeleteClass = "underline pointer color7 emphasis"
	this.DeleteActive = "Deleting";
	this.AddID = strAddID;
	this.SaveID = strSaveID;
	this.CancelID = strCancelID;
	this.SummaryLabel = strSummaryLabel;
	this.SummaryDesign = strSummary;
	this.UpdateCommandName = strUpdateCommand;
	this.UpdateAlert = true;
	this.UpdateURL = null;
	this.UpdateInstanceID = null;
	this.UpdateProcedure = null;
	this.Queue = new Object();
	this.Queue.Contents = new Array();
	this.Queue.Push = function (intRecord, strProcedure) {var intQueue = this.Contents.length;this.Contents[intQueue] = new Object();this.Contents[intQueue]["ID"] = intRecord;this.Contents[intQueue]["Procedure"] = strProcedure;}
	this.Queue.Pop = function (intRecord) {this.Contents.splice(intRecord,1);}
	this.AlertErrors = true;
	this.HighlightErrors = true;
	this.InitialData = null;
	this.CustomErrorMessage = null; //set from CustomVerfiy and return true
	this.Error = new Object();
	this.CustomVerify = function(obj) {return true;};
	this.CustomUpdate = function(obj, procedure) {return true;};
	this.LoadToPage_Pre = function(obj, intRecord) {return true;};
	this.LoadToPage_Post = function(obj, intRecord) {return true;};
	this.OutputField = strOutputField;
	this.SummaryIndicClosed = "<img src=\"/images/triangle_down.gif\" align=\"absmiddle\">&nbsp;";
	this.SummaryIndicOpen = "<img src=\"/images/triangle_up.gif\" align=\"absmiddle\">&nbsp;";

	this.Initialize = function() {
		if(this.IsMultiple == true) {
			if (!document.getElementById(this.Section + "_Summary")) return false;
			for (var i=0; i<this.Items.length; i++) {if (this.Items[i][Constants.FieldType]._Parent == this) {this.Items[i][Constants.FieldType].Initialize();}}
			if (this.Insert()){
			    this.Populate();
			}else{return false;}
		}else{
			if (!document.getElementById(this.Section + "_Form") || (this.AddID != null && !document.getElementById(this.AddID))) return false;
			for (var i=0; i<this.Items.length; i++) {if (this.Items[i]._Parent == this) this.Items[i].Initialize();}
			return this.Insert();
		}
		return true;
	}
	this.AddField = function(strLabel, objType, strSummary, strError, objRequired, blnForServerUpdate) {
		if (objType == null) objType = -1;
		if (objType.Bin != null) {
			objType._Parent = this;
		}
		var objField = document.getElementById(this.Section + strLabel); var blnDisabled = false;
		if(objField != null) {blnDisabled = objField.disabled}
		this.Items[this.Items.length] = new Array(strLabel, objType, strSummary, strError, objRequired, blnForServerUpdate, blnDisabled);
		this.Items[strLabel] = this.Items[this.Items.length-1];
		if (strError != null) this.Required++;
	}
	this.Insert = function(blnPreserveForm, intRecordID) {
	    var blnHoldForInsert = false;
	    if (blnPreserveForm == null) blnPreserveForm = false;
	    if (this.UpdateInstanceID != null && intRecordID != null) {this.Queue.Push(intRecordID, "Insert"); return false;}
	    if (this.UpdateInstanceID != null && intRecordID == null) {alert("Another action is in process. Please wait"); return false;}
		if (intRecordID == this.Current || intRecordID == null) {if (!this.Verify()) return false;}
		if (!this.CustomUpdate(this, "Insert")) return false;
		if (intRecordID > 0) {this.UpdateProvider(intRecordID, "PostInsert"); return true;}
        if (this.Count >= 0) {
            for (var i=0; i<this.Items.length; i++) {
                if (this._Parent != null) {
                    if (this.Items[i][Constants.FieldName] == "_" + this._Parent.Section + "_ID") {
                        if (this.Bin[0][this.Items[i][Constants.FieldName]] == 0) 
                            blnHoldForInsert = true;
                    }
                }
            }
        }
		if(this.Count >= 0 && this.UpdateURL != null && blnHoldForInsert == false) {this.UpdateProvider(0, "Insert"); return true;}
		this.Count++;
		this.Bin[this.Count] = new Object();
		for (var i=0; i<this.Items.length; i++) {
			if (this.Items[i][Constants.FieldType]._Parent == this){
				this.Bin[this.Count][this.Items[i][Constants.FieldName]] = clone(this.Items[i][Constants.FieldType].Bin);
				this.Items[i][Constants.FieldType].ResetBin();
			}else{
				this.Bin[this.Count][this.Items[i][Constants.FieldName]] = getField(this.Section + this.Items[i][Constants.FieldName]);
			}
		}
		if (blnPreserveForm == true || this.IsMultiple == false) {this.Summarize();}
		if (blnPreserveForm != true) this.ResetForm();
		this.SetButtons(true,false,false);
		return true;
	}
	this.Update = function(blnDoVerify) {
	    if(this.UpdateInstanceID != null) {alert("Another action is in process. Please wait"); return false;}
	    if(blnDoVerify == null) blnDoVerify = true;
		if (blnDoVerify) {if(!this.Verify()) return false;}
		if (this.IsMultiple == true) {
			if (this.HasDataChanged() && this.Current > 0) {
				if (!this.CustomUpdate(this, "Update")) return false;
				if (this.UpdateURL != null && this.Bin[this.Current]["_ID"] > 0) {this.UpdateProvider(null,"Update"); return true;}
				for (var i=0; i<this.Items.length; i++) {			
			        if (this.Items[i][Constants.FieldType]._Parent == this){
				        this.Bin[this.Current][this.Items[i][Constants.FieldName]] = clone(this.Items[i][Constants.FieldType].Bin);
					    this.Items[i][Constants.FieldType].ResetBin();
			        }else{
				        this.Bin[this.Current][this.Items[i][Constants.FieldName]] = getField(this.Section + this.Items[i][Constants.FieldName]);
			        }
				}
			}
			this.ResetForm();
			this.SetButtons(true,false,false);
		}else{
			if (this.Current == -1) {
				this.Current = 0;
				swapDisplays(this.Section + "_Form", 1);
		        if (this.Bin[0]["_ID"] == -1) {
	                setContents(this.Section + "_EditLabel", this.SummaryIndicOpen + this.ViewActive, 1);
	                setClass(this.Section + "_EditLabel", this.ViewActiveClass);
		            this.DisableForm(true);
		            this.SetButtons(true,false,true);
                } else {
	                setContents(this.Section + "_EditLabel", this.SummaryIndicOpen + this.EditActive, 1);
	                setClass(this.Section + "_EditLabel", this.EditActiveClass);
		            this.DisableForm(false);
		            this.SetButtons(true,true,true);
	            }
			}else if(this.Current == 0) {
			    if (this.Bin[0]["_ID"] != -1) {
				    if (!this.CustomUpdate(this, "Update")) return false;
				    if (this.UpdateURL != null) {this.UpdateProvider(null, "Update"); return true;}
				}
				this.ResetForm();
			}
		}
		return true;
	}
	this.ConcatData = function (intID, strProcedure, intSeperator) {
	    var strData = "";
		if (this.IsMultiple == true) {
			for (var i=0; i<this.Items.length; i++) {
			    if (this.Items[i][Constants.FieldForServerUpdate] != false) {
				    if (intID == this.Current && strProcedure != "Delete") {
				        if (this.Items[i][Constants.FieldType]._Parent == this) {
				            if (this.Items[i][Constants.FieldType].UpdateURL == null) {
				                strData += this.Items[i][Constants.FieldName] + Seperate(intSeperator);
				                for (var j=1; j<=this.Items[i][Constants.FieldType].Count; j++) {
				                    strData += this.Items[i][Constants.FieldType].ConcatData(j, strProcedure, intSeperator + 3) + Seperate(intSeperator + 2);
				                }
				                strData += Seperate(intSeperator + 1);
				            }
				        }else{
                            strData += this.Items[i][Constants.FieldName] + Seperate(intSeperator) + getField(this.Section + this.Items[i][Constants.FieldName]) + Seperate(intSeperator + 1);
                        }
				    }else{
				        strData += this.Items[i][Constants.FieldName] + Seperate(intSeperator) + this.Bin[intID][this.Items[i][Constants.FieldName]] + Seperate(intSeperator + 1);
				    }
		        }
			}
		}else{
			for (var i=0; i<this.Items.length; i++) {
			    if (this.Items[i][Constants.FieldForServerUpdate] != false)
				    strData += this.Items[i][Constants.FieldName] + Seperate(intSeperator) + getField(this.Section + this.Items[i][Constants.FieldName]) + Seperate(intSeperator + 1);
			}
		}
		return strData;
	}
	this.UpdateProvider = function(intID, strProcedure) {
		var strData = "";
		if(intID == null || intID < 1) intID = this.Current;
        this.UpdateInstanceID = intID;
        this.UpdateProcedure = strProcedure;
		strData += this.ConcatData(intID, strProcedure, 0);
		if (strProcedure == "Delete") {
			callDataInterface(this.UpdateURL + "?Data=" + escape(strData) + "&Procedure=" + this.UpdateCommandName + "_Delete", this.UpdateCommandName, this.UpdateAlert);
			//alert(this.UpdateURL + "?Data=" + escape(strData) + "&Procedure=" + this.UpdateCommandName + "_Delete");
		}else{
		    callDataInterface(this.UpdateURL + "?Data=" + escape(strData) + "&Procedure=" + this.UpdateCommandName, this.UpdateCommandName, this.UpdateAlert);
		    //alert(this.UpdateURL + "?Data=" + strData + "&Procedure=" + this.UpdateCommandName);
		}
	}
	this.UpdateProviderResult = function(intDataID, blnSuccess) {
	    if (blnSuccess == true) {
	        switch (this.UpdateProcedure) {       
	            case "Insert":
	                var blnHoldObjectOpen = false;
    	            this.Count++;
    	            this.Current = this.Count;
		            this.Bin[this.Count] = new Object();
	                for (var i=0; i<this.Items.length; i++) {
		                if (this.Items[i][Constants.FieldType]._Parent != this){
			                this.Bin[this.Count][this.Items[i][Constants.FieldName]] = getField(this.Section + this.Items[i][Constants.FieldName]);
		                }
	                }         
		           
		           if (this.UpdateInstanceID != null && intDataID > 0) this.Bin[this.Count]["_ID"] = intDataID;
                    for (var i=0; i<this.Items.length; i++) {
	                    if (this.Items[i][Constants.FieldType]._Parent == this){
    	                    for(var j=1; j<=this.Items[i][Constants.FieldType].Count; j++) {
    	                        for (var s=0; s<this.Items[i][Constants.FieldType].Items.length; s++) {
    	                            if (this.Items[i][Constants.FieldType].Items[s][Constants.FieldName] == "_" + this.Section + "_ID")
    	                                this.Items[i][Constants.FieldType].Bin[j]["_" + this.Section + "_ID"] = intDataID;
    	                        }
    	                        this.Items[i][Constants.FieldType].Insert(false,j);
    	                        //this.Items[i][Constants.FieldType].Queue.Push(j, "Insert");
    	                        blnHoldObjectOpen = true;
    	                    }
    	                }
    	            }
		            
         		    this.UpdateInstanceID = null;
        		    this.UpdateProcedure = null;
        		    if (blnHoldObjectOpen == false) {
   		                for (var i=0; i<this.Items.length; i++) {
			                if (this.Items[i][Constants.FieldType]._Parent == this){
				                this.Bin[this.Count][this.Items[i][Constants.FieldName]] = clone(this.Items[i][Constants.FieldType].Bin);
				                this.Items[i][Constants.FieldType].ResetBin();
			                }
		                }
		                this.Summarize();
		                this.ResetForm();
		                this.SetButtons(true,false,false);
		            }
    	            break;
    	        case "PostInsert":
           	        if (this.UpdateInstanceID != null && intDataID > 0) this.Bin[this.UpdateInstanceID]["_ID"] = intDataID;
         		    this.UpdateInstanceID = null;
        		    this.UpdateProcedure = null;
      	            if (this.Queue.Contents.length > 0) {
		                switch (this.Queue.Contents[this.Queue.Contents.length-1]["Procedure"]) {
		                    case "Insert":
		                        this.Insert(false, this.Queue.Contents[this.Queue.Contents.length-1]["ID"])
		                        this.Queue.Pop(this.Queue.Contents.length-1);
		                        break;
		                }
		            }else{      
   		                for (var i=0; i<this._Parent.Items.length; i++) {
			                if (this._Parent.Items[i][Constants.FieldType] == this){
				                this._Parent.Bin[this._Parent.Current][this._Parent.Items[i][Constants.FieldName]] = clone(this.Bin);
				                this.ResetBin();
			                }
		                }
		                this.Summarize();
		                this.ResetForm();
		                this._Parent.Summarize();
		                this._Parent.ResetForm();
		            }
    	            break;
	            case "Update":          
			        for (var i=0; i<this.Items.length; i++) {			
		                if (this.Items[i][Constants.FieldType]._Parent == this){
			                this.Bin[this.UpdateInstanceID][this.Items[i][Constants.FieldName]] = clone(this.Items[i][Constants.FieldType].Bin);
				            this.Items[i][Constants.FieldType].ResetBin();
		                }else{
			                this.Bin[this.UpdateInstanceID][this.Items[i][Constants.FieldName]] = getField(this.Section + this.Items[i][Constants.FieldName]);
		                }
			        }
         		    this.UpdateInstanceID = null;
        		    this.UpdateProcedure = null;
        		    this.ResetForm();
        		    this.Summarize();
			        if (this.IsMultiple == true) this.SetButtons(true,false,false);
    	            break;
	            case "Delete":
                    this.Bin.splice(this.UpdateInstanceID,1);
		            this.Count--;
		            this.ResetForm();
         		    this.UpdateInstanceID = null;
        		    this.UpdateProcedure = null;
		            break;
		    }
	    } else {
	        this.UpdateInstanceID = null;
	        this.UpdateProcedure = null;
	    }
	}
	this.Summarize = function() {
		var strFieldName; var strFieldValue;
		var strText = this.SummaryDesign;
		var blnFound = false;
		var blnLocked = false;
		var strSummary = "";
		if (this.IsMultiple == true) {
			strSummary = "<table id=\"" + this.Section + "_Summary\" width=\"100%\" cellpadding=\"0\" cellspacing =\"1\" border=\"0\">";
			for (var i=1; i<=this.Count; i++) {
				blnLocked = false;
				for (var j=0; j<this.Items.length; j++) {
					if (this.Items[j]._Parent != this) {
						while (strText.indexOf("$" + this.Items[j][Constants.FieldName] + "$") > -1) {
							strFieldName = this.Section + this.Items[j][Constants.FieldName];
							strFieldValue = getFieldLiteral(strFieldName, this.Bin[i][this.Items[j][Constants.FieldName]]);
        			        if (typeof(this.Items[j][Constants.FieldSummary]) == "function")
				                strText = strText.replace("$" + this.Items[j][Constants.FieldName] + "$", this.Items[j][Constants.FieldSummary](this, i));
							else if (this.Items[j][Constants.FieldSummary] == null || strFieldValue == "")
								strText = strText.replace("$" + this.Items[j][Constants.FieldName] + "$", strFieldValue);
							else
								strText = strText.replace("$" + this.Items[j][Constants.FieldName] + "$", this.Items[j][Constants.FieldSummary].replace("$" + this.Items[j][Constants.FieldName],strFieldValue));
						}
					}
				}
				blnFound = true;
				if (this.SummaryLabel >"") {
				    strSummary += "<tr id ='" + this.Section + i + "'><td valign=\"top\"><img src=\"/images/spacer.gif\" align=\"absmiddle\" name=\"" + this.Section + "Arrow" + i + "\">" + this.SummaryLabel + "</td><td width=\"100%\" valign=\"top\">" + strText + "</td>";
				} else {
				    strSummary += "<tr id ='" + this.Section + i + "'>" + strText;
				}
			    if (this.Bin[i]["_ID"] == -1) {
			        if ((typeof(this.View) == "function"?this.View(this,i):this.View) != null) strSummary += "<td valign=\"top\" nowrap>&nbsp;<label id=\"" + this.Section + "_Edit" + i + "\" class=\"" + this.ViewClass + "\" onClick=\"window._" + this.Section + ".LoadToPage(" + i + ");\">" + this.SummaryIndicClosed + (typeof(this.View) == "function"?this.View(this,i):this.View) + "</label>&nbsp;</td>";
			    } else {
			        if ((typeof(this.Edit) == "function"?this.Edit(this,i):this.Edit) != null) strSummary += "<td valign=\"top\" nowrap>&nbsp;<label id=\"" + this.Section + "_Edit" + i + "\" class=\"" + this.EditClass + "\" onClick=\"window._" + this.Section + ".LoadToPage(" + i + ");\">" + this.SummaryIndicClosed + (typeof(this.Edit) == "function"?this.Edit(this,i):this.Edit) + "</label>&nbsp;</td>";
			    }
				if ((typeof(this.Delete) == "function"?this.Delete(this,i):this.Delete) != null && this.Bin[i]["_ID"] != -1 && this.Bin[i]["_Delete"] != 0) strSummary += "<td valign=\"top\" nowrap>&nbsp;<label id=\"" + this.Section + "_Delete" + i + "\" class=\"" + this.DeleteClass + "\" onClick=\"window._" + this.Section + ".DeleteRecord(" + i + ");\">" + (typeof(this.Delete) == "function"?this.Delete(this,i):this.Delete) + "</label>&nbsp;</td>";
				strText = this.SummaryDesign;
			}
			if (blnFound == false) strSummary += "<tr><td></td>";
			strSummary +="</tr></table>";
		}else{
			for (var j=0; j<this.Items.length; j++) {
				if (this.Items[j][Constants.FieldName] == "IsVerified") {
					if (this.Bin[0][this.Items[j][Constants.FieldName]] == "True")
						blnLocked = true;
				}
				while (strText.indexOf("$" + this.Items[j][Constants.FieldName] + "$") > -1) {
					strFieldName = this.Section + this.Items[j][Constants.FieldName];
					strFieldValue = getFieldLiteral(strFieldName);
			        if (typeof(this.Items[j][Constants.FieldSummary]) == "function")
		                strText = strText.replace("$" + this.Items[j][Constants.FieldName] + "$", this.Items[j][Constants.FieldSummary](this, i));
					else if (this.Items[j][Constants.FieldSummary] == null || strFieldValue == "")
						strText = strText.replace("$" + this.Items[j][Constants.FieldName] + "$", strFieldValue);
					else
						strText = strText.replace("$" + this.Items[j][Constants.FieldName] + "$", this.Items[j][Constants.FieldSummary].replace("$" + this.Items[j][Constants.FieldName],strFieldValue));
				}
			}
		    if (this.Bin[0]["_ID"] == -1) {
    			if ((typeof(this.View) == "function"?this.View(this,i):this.View) != null) 
    			    setContents(this.AddID, "&nbsp;<label id=\"" + this.Section + "_EditLabel\" class=\"" + this.ViewClass + "\" onClick=\"window._" + this.Section + ".Update();\">" + this.SummaryIndicClosed + (typeof(this.View) == "function"?this.View(this):this.View) + "</label>&nbsp;", 1);
       			else 
    			    setContents(this.AddID, "",1);
		    } else {
    			if ((typeof(this.Edit) == "function"?this.Edit(this,i):this.Edit) != null) 
    			    setContents(this.AddID, "&nbsp;<label id=\"" + this.Section + "_EditLabel\" class=\"" + this.EditClass + "\" onClick=\"window._" + this.Section + ".Update();\">" + this.SummaryIndicClosed + (typeof(this.Edit) == "function"?this.Edit(this):this.Edit) + "</label>&nbsp;", 1);
    			else 
    			    setContents(this.AddID, "",1);
    	    }
			strSummary = strText;
		}
		setContents(this.Section + "_Summary", strSummary, 1);
	}
	this.DeleteRecord = function(intRecord, blnConfirmation) {
	    if(this.UpdateInstanceID != null) {alert("Another action is in process. Please wait"); return false;}
		var intWasCurrent = this.Current;
		this.Current = intRecord;
		if (!this.CustomUpdate(this, "Delete")) {this.Current = intWasCurrent; return false;}
		setContents(this.Section + "_Delete" + intRecord, this.DeleteActive, 1);
		if (blnConfirmation != false) {if (!confirm("Are you sure you wish to delete?")) {this.Current = intWasCurrent;setContents(this.Section + "_Delete" + intRecord, this.Delete, 1);return false;}}
		if (this.UpdateURL != null && this.Bin[this.Current]["_ID"] != this.Bin[0]["_ID"]) {
		    this.UpdateProvider(this.Current, "Delete");
		    if (intWasCurrent == intRecord) this.ResetForm();
		    if (intRecord != intWasCurrent) this.Current = intWasCurrent;
		    return true;
		}
		if (intWasCurrent == intRecord) this.ResetForm();
        this.Bin.splice(intRecord,1);
		if (intRecord != intWasCurrent) this.Current = intWasCurrent;
		this.Count--;
		this.Summarize();
	}
	this.LoadToPage = function(intRecord) {
	    if(this.UpdateInstanceID != null && intRecord > 0) {alert("Another action is in process. Please wait"); return false;}
		if (this.LoadToPage_Pre(this, intRecord) == false) {return false;}
		if(intRecord == this.Current && intRecord > 0) {
		    if (this.Bin[intRecord]["_ID"] == -1) {
		        this.ResetForm(); return;
		    }
			this.Update(); return;
		}
		this.Summarize();

		if (this.Bin[intRecord]["_ID"] == -1) {
		    setContents(this.Section + "_Edit" + intRecord, this.SummaryIndicOpen + this.ViewActive, 1);
		    setClass(this.Section + "_Edit" + intRecord,this.ViewActiveClass);
		} else {
		    setContents(this.Section + "_Edit" + intRecord, this.SummaryIndicOpen + this.EditActive, 1);
		    setClass(this.Section + "_Edit" + intRecord,this.EditActiveClass);
		}
		for (var i=0; i<this.Items.length; i++) {
			if (this.Items[i][Constants.FieldType]._Parent == this) {
				this.Items[i][Constants.FieldType].Bin = clone(this.Bin[intRecord][this.Items[i][Constants.FieldName]]);
				this.Items[i][Constants.FieldType].Count = this.Items[i][Constants.FieldType].Bin.length - 1;
				for(var j=0; j<this.Items[i][Constants.FieldType].Items.length; j++) {
				    if (this.Items[i][Constants.FieldType].Items[j][Constants.FieldName] == "_" + this.Section + "_ID")
				        this.Items[i][Constants.FieldType].Bin[0][this.Items[i][Constants.FieldType].Items[j][Constants.FieldName]] = this.Bin[intRecord]["_ID"];
				}
				this.Items[i][Constants.FieldType].LoadToPage(0);
			}else{
				setField(this.Section + this.Items[i][Constants.FieldName], this.Bin[intRecord][this.Items[i][Constants.FieldName]]);
			}
		}
		this.Current = intRecord
		if (intRecord==0)
		    this.SetButtons(true,false,false);
		else
		    this.SetButtons(false,true,true);

		if (this.Bin[intRecord]["_ID"] == -1) {
		    this.DisableForm(true);
		    this.SetButtons(false,false,true);
		} else {
		    this.DisableForm(false);
		}

		MM_swapImage(this.Section + "Arrow" + intRecord,"","/images/icon_arrow_right.gif",1);
		this.ClearHighlights();
		this.LoadToPage_Post(this, intRecord);
	}
	this.Verify = function(intRecord) {
		if (this.Current == -1) return true;
		if (!this.CustomVerify(this)) return false;
		var strError = ""; var strTemp = ""; var strFirstFieldError = ""; 
		var strFieldName = ""; var strErrorFields = ""; var blnRequired = false;
		for (var i=0; i<this.Items.length; i++) {
			if (this.Items[i][Constants.FieldType] != -1) {
				if (this.Items[i][Constants.FieldType]._Parent == this) {
					if (this.Items[i][Constants.FieldType].Count < this.Items[i][Constants.FieldRequired]) {
						if (this.AlertErrors == true) {
							if (this.Items[i][Constants.FieldVerify] != null) 
								strError += this.Items[i][Constants.FieldVerify] + "\n";
							else
								strError += this.Items[i][Constants.FieldName] + " is insufficent.\n";
						}
					}
				}else{
					strFieldName = this.Section + this.Items[i][Constants.FieldName];
					if (this.Items[i][Constants.FieldRequired] != null) blnRequired = this.Items[i][Constants.FieldRequired];
					if (intRecord > 0) {
						if (blnRequired == true) {
							if(!verifyField(this.Bin[intRecord][this.Items[i][Constants.FieldName]], null ,this.Items[i][Constants.FieldType]))
								strTemp = this.Items[i][Constants.FieldVerify];
						}else{
							if (isBlank(getField(this.Bin[intRecord][this.Items[i][Constants.FieldName]])) == false)
								if(!verifyField(this.Bin[intRecord][this.Items[i][Constants.FieldName]], null ,this.Items[i][Constants.FieldType]))
									strTemp = this.Items[i][Constants.FieldVerify];
						}
					}else{
						if (blnRequired == true) {
							if (!verifyField(getField(strFieldName), null ,this.Items[i][Constants.FieldType]))					
								strTemp = this.Items[i][Constants.FieldVerify];
						}else{
							if (isBlank(getField(strFieldName)) == false)
								if (!verifyField(getField(strFieldName), null ,this.Items[i][Constants.FieldType]))					
									strTemp = this.Items[i][Constants.FieldVerify];
						}
					}
					
					if (strTemp == null) strTemp = this.Items[i][Constants.FieldName] + " is incorrect.";
					if (strTemp != "") {
						strError += strTemp + "\n";
						if (blnRequired == true){
							strErrorFields += "^" + strFieldName;
						}else
							strErrorFields += "^~" + strFieldName;
						if (strFirstFieldError == "") strFirstFieldError = strFieldName;
						if (this.HighlightErrors) this.SetHighlight(strFieldName);
					}else{
						if (document.getElementById(this.Section + this.Items[i][Constants.FieldName]) != null) document.getElementById(this.Section + this.Items[i][Constants.FieldName]).className = "";
					}
					strTemp = "";
				}
			}
		}
		if (this.CustomErrorMessage != null) strError = this.CustomErrorMessage + strError;
		if (this.AlertErrors == true && strError != "") {
			alert(strError);
			if (strFirstFieldError != "")
			    if (document.getElementById(strFirstFieldError) != null) document.getElementById(strFirstFieldError).focus();
		}
		this.Error.Message = strError;
		this.Error.Fields = strErrorFields;
		this.CustomErrorMessage = null;
		if (strError != "")
			return false;
		else
			return true;
	}
	this.HasDataChanged = function() {
		for (var i=0; i<this.Items.length; i++) {
		    if (this.Items[i][Constants.FieldType]._Parent == this) {
		        if(this.Bin[this.Current][this.Items[i][Constants.FieldName]] != this.Items[i][Constants.FieldType].Bin) return true;
		    }else{
			    if (this.Items[i][Constants.FieldName].charAt(0) != "_") {
				    if(this.Bin[this.Current][this.Items[i][Constants.FieldName]] != getField(this.Section + this.Items[i][Constants.FieldName])) return true;
			    }
    		}
		}
		return false;
	}
	this.ResetBin = function() {
        while (this.Count > 0) {
            this.Bin.splice(this.Count,1);
    		this.Count--;
        }
		this.Summarize();
		this.ResetForm();
	}
	this.ResetForm = function() {
		if (this.IsMultiple == true) {
			this.LoadToPage(0);
		}else{
			swapDisplays(this.Section + "_Form", 0);
			if (this.Bin[0]["_ID"] == -1) {
	            setContents(this.Section + "_EditLabel", this.SummaryIndicClosed + (typeof(this.View) == "function"?this.View(this):this.View), 1);
	            setClass(this.Section + "_EditLabel", this.ViewClass);
			} else {
	            setContents(this.Section + "_EditLabel", this.SummaryIndicClosed + (typeof(this.Edit) == "function"?this.Edit(this):this.Edit), 1);
	            setClass(this.Section + "_EditLabel", this.EditClass);
	        }
			this.Current = -1;
		}
	}
	this.RenewForm = function(intRecord) {
		for (var i=0; i<this.Items.length; i++) {
			if (this.Items[i][Constants.FieldName] != "IsVerified") 
				setField(this.Section + this.Items[i][Constants.FieldName], this.Bin[intRecord][this.Items[i][Constants.FieldName]]);
		}
		this.LoadToPage(0);
		this.SetButtons(true,false,true);
	}
	this.DisableForm = function(blnDisabled) {
		for (var i=0; i<this.Items.length; i++) {
			if (this.Items[i][Constants.FieldType]._Parent == this) {
				this.Items[i][Constants.FieldType].DisableForm(blnDisabled);
			}else{
			    if(this.Items[i][Constants.FieldDisabled] != true) {
				    if (this.Items[i][Constants.FieldName].charAt(0) != "_") {
					    if (document.getElementById(this.Section + this.Items[i][Constants.FieldName])) {
						    document.getElementById(this.Section + this.Items[i][Constants.FieldName]).disabled = blnDisabled;
					    } else if (document.getElementsByName(this.Section + this.Items[i][Constants.FieldName])) {
						    for (j=0; j<document.getElementsByName(this.Section + this.Items[i][Constants.FieldName]).length; j++) {
							    document.getElementsByName(this.Section + this.Items[i][Constants.FieldName])[j].disabled = blnDisabled;
						    }
					    }
				    }
			    }
			}
		}
	}
	this.SetButtons = function(blnAdd,blnSave,blnCancel) {
		swapDisplays(this.AddID,0);swapDisplays(this.SaveID,0);swapDisplays(this.CancelID,0);
		if (blnAdd == true && this.AddID != null)
			swapDisplays(this.AddID,1);
		if (blnSave == true && this.SaveID != null)
			swapDisplays(this.SaveID,1);
		if (blnCancel == true && this.CancelID != null)
			swapDisplays(this.CancelID,1);
	}
	this.Populate = function(intSeperator) {
		if (this.InitialData != null) {
		    if (intSeperator == null) intSeperator = 0;
			var strData = this.InitialData;
			var aryRecords = strData.split(Seperate(intSeperator + 1)); var aryFields;
			for (var i=0; i< aryRecords.length; i++) {		
				if(aryRecords[i] > "") {
					varFields = aryRecords[i].split(Seperate(intSeperator));
					this.Count++;
					this.Bin[this.Count] = new Object();
					for (var j=0; j<this.Items.length; j++) {
					    if (this.Items[j][Constants.FieldType]._Parent == this) {
					        this.Items[j][Constants.FieldType].InitialData = varFields[j];
					        this.Bin[this.Count][this.Items[j][Constants.FieldName]] = this.Items[j][Constants.FieldType].Populate(intSeperator + 2);
					        this.Items[j][Constants.FieldType].ResetBin();
					    }else{
						    if (varFields[j] == null) varFields[j] = "";
						    this.Bin[this.Count][this.Items[j][Constants.FieldName]] = varFields[j];
						}
					}				
				}
			}
			this.ResetForm();
			this.SetButtons(true,false,false);
		}
		return clone(this.Bin);
	}
	this.WriteToField = function() {
		var strOutput = "";
		var blnFoundGroup = false;
		var blnFoundFields = false;
		var intSepOffset = 0;
		if (this._Parent != null) intSepOffset = this._Parent.Items.length;
		if (this.OutputField != null) {
			for (var i=1; i<=this.Count; i++) {
				blnFoundFields = false;
				for (var j=0; j<this.Items.length; j++) {
					strOutput += this.Bin[i][this.Items[j][Constants.FieldName]] + Seperate(0+intSepOffset);
					blnFoundFields = true;
				}
				if (blnFoundFields == true) strOutput = strOutput.substr(0,(strOutput.length - Seperate(0+intSepOffset).length));
				strOutput += Seperate(1+intSepOffset);
				blnFoundGroup = true;
			}
			if (blnFoundGroup == true) strOutput = strOutput.substr(0,(strOutput.length - Seperate(1+intSepOffset).length));
		}
		setField(this.OutputField,strOutput);
	}
	this.SetHighlight = function(strField) {
		var strFieldType = getFieldType(strField);
		switch (strFieldType) {
			case "text": case "textarea": case "checkbox":
				document.getElementById(strField).className = "required";
				break;
			case "select-one": case "select-multiple":
				document.getElementById(strField).className = "requiredSelect";
				break;
			case "radio":
				document.getElementsByName(strField).className = "required";
				break;
			case "hidden":
				break;
		}
	}
	this.ClearHighlights = function(strField) {
	    if (strField == null) {
	        for (var i=0; i<this.Items.length; i++) {
	            if(document.getElementById(this.Section + this.Items[i][Constants.FieldName]))
	                document.getElementById(this.Section + this.Items[i][Constants.FieldName]).className = "";
	        }
	    }else{
			document.getElementById(strField).className = "";	    
	    }
	}
}

function clone(obj) { 
    var o = new obj.constructor(); 
    for (var p in obj) 
        if (obj.hasOwnProperty(p)) 
            if (typeof(obj[p]) == "object")
                o[p]=clone(obj[p]);
            else
                o[p]=obj[p];
    return o; 
} 

function dataReturn(command, objReturn,	blnResult) {
	if (objReturn.Status == "SUCCESS") {
	    if (window._dataReturnEvents) {
	        for (var i=0;i<window._dataReturnEvents.length;i++){
		        if (command == window._dataReturnEvents[i][0]) window._dataReturnEvents[i][1](objReturn, blnResult);
	        }
	    }
	}else{
	    alert(objReturn.Message);
	}
}

function regDataReturn(id, obj) {
    if (!window._dataReturnEvents) window._dataReturnEvents = new Array();
	window._dataReturnEvents[window._dataReturnEvents.length] = new Array(id, obj);
}

function setContents(objName, strContents, intMode) {
	if(objWork = document.getElementById(objName)) {
		if (intMode == 1) 
			objWork.innerHTML = strContents;
		else
			objWork.outerHTML = strContents;
	}
}

function setClass(objName, strClass) {
	if(objWork = document.getElementById(objName)) {	
			objWork.className = strClass;
	}
}

function SelectAllMultiple(strObjectName) {
	obj = document.getElementById(strObjectName);
	for(i=0;i<obj.length;i++) {
		obj.options[i].selected = true;
	}
}

function unFormatFlashString(strString) {
	strString = replaceAll(strString, "[amp;]", "&");
	return strString;
}

function FormatNameCase(strName){
	//6/15/2005 - Bill Marshall.  Per KP/Brenda/Ed, removed the auto formatting.
	//			Ed felt that nurses may get frustrated when trying to change
	//			something to the proper case, only to have it auto formatted again.
    /*if (strName.length < 1) return ("");
    var strWork = "";
    var aryName = strName.toLowerCase().split(" ");
    for (var i in aryName) {
		strWork += aryName[i].charAt(0).toUpperCase() + aryName[i].substring(1) + " ";
    }
    return strWork.substring(0,strWork.length-1);
    */
    return strName;
}

function ReformatSSN(strField,e){		//Handle the re-formatting of the SSN as they type, similar to RegExp of: /d{3}-\d{2}-\d{4}$/;
  	var sSSN = document.getElementById(strField).value;
	if ((e != 8) && (sSSN.length == 3 || sSSN.length == 6))
		sSSN = sSSN + "-";
	else if ((sSSN.length == 5 || sSSN.length == 8) && (sSSN.charAt(sSSN.length - 1) == "-"))
		//If they typed a "-" after we've already inserted one for them, back theirs out.
		sSSN = sSSN.substring(0,sSSN.length - 1);
	document.getElementById(strField).value = sSSN;
}

function ReformatPhone(strField,e){		//Handle the re-formatting of the SSN as they type, similar to RegExp of: /d{3}-\d{2}-\d{4}$/;
  	var sPhone = document.getElementById(strField).value;
	if ((e != 8) && (sPhone.length == 3 || sPhone.length == 7))
		sPhone = sPhone + "-";
	else if ((sPhone.length == 5 || sPhone.length == 9) && (sPhone.charAt(sPhone.length - 1) == "-"))
		//If they typed a "-" after we've already inserted one for them, back theirs out.
		sPhone = sPhone.substring(0,sPhone.length - 1);
	document.getElementById(strField).value = sPhone;
}

function evalKeyPress(e) {
	this.Evaluations = new Array();
	this.addEval = function(id, obj) {
		if(typeof(obj) != "function" || !id) return false;
		if(!document.onkeypress) document.onkeypress = evalKeyPress;
		for (var i=0; i<document.onkeypressevents.Evaluations.length; i++){ //no double dipping
			if (id == document.onkeypressevents.Evaluations[i][0]) return false;
		}
		document.onkeypressevents.Evaluations[document.onkeypressevents.Evaluations.length] = new Array(id, obj);
	}
	if(window.event==null && e==null) {
		if(!document.onkeypressevents) {document.onkeypressevents = new Object;document.onkeypressevents = new evalKeyPress();}
		return false;
	}
    var currNode = e?e.target:window.event.srcElement;
	var currCode = e?e.which:(window.event?window.event.keyCode:0);
	for (var i=0; i<document.onkeypressevents.Evaluations.length; i++){
		if (currNode.id == document.onkeypressevents.Evaluations[i][0]) document.onkeypressevents.Evaluations[i][1](currNode.id,currCode);
	}
}

function showDocument(intDocumentImageID) {
	window.open("/profile/view_document.aspx?ID=" + intDocumentImageID,"_blank","titlebar=no,menubar=no,resizable=yes,scrollbars=yes");
}

function showSubcontractorDocument(intDocumentImageID) {
	window.open("/subcontractor/view_document.aspx?ID=" + intDocumentImageID,"_blank","titlebar=no,menubar=no,resizable=yes,scrollbars=yes");
}

function showPDFDocument(intDocumentImageID) {
	window.open("/profile/view_pdf_document.aspx?ID=" + intDocumentImageID,"_blank","titlebar=no,menubar=no,resizable=yes,scrollbars=yes");
}

function showDocumentByID(intDocumentImageID) {
	window.open("/unseen/document_display.aspx?ID=" + intDocumentImageID,"_blank","titlebar=no,menubar=no,resizable=yes,scrollbars=yes");
}

function showDocumentByFile(strFileName, strContentType) {
	window.open("/unseen/document_display.aspx?FileName=" + strFileName + "&ContentType=" + strContentType,"_blank","titlebar=no,menubar=no,resizable=yes,scrollbars=yes");
}

function SelectAll(obj) {
	for(x = 0;x<obj.length;x++){	
		obj(x).selected = true; 
	}
	return true;
}

function AddToSelected(AllList,SelectedList){
	for (var x = 0 ; x < AllList.length;x++){
		var Found = false
		if(AllList(x).selected){
			for (var i=0; i < SelectedList.length; i++){
				if (SelectedList(i).value == AllList(x).value)
					Found = true;
			}
			if (!Found){
			    var newOpt = new Option(AllList(x).innerText, AllList(x).value);
			    SelectedList.options[SelectedList.length] = newOpt;
			}
		}
	}
}

function RemoveSelectedItem(SelectedList){
	for (var i=0; i < SelectedList.length; i++)	{
		if (SelectedList(i).selected){
			SelectedList.remove(i);
			i=-1
		}
	}
}

function clearDropDown(obj){
	for (var i=obj.length; i>0; i--)
		obj.options[i] = null;
}

function OptionUp(obj)	{
	var strValue;
	var strName;
	var intIndex;
	intIndex = obj.selectedIndex;
	if (intIndex == 0)
		return false;
	strValue = obj(intIndex - 1).value;
	strName = obj(intIndex - 1).innerText;
	obj(intIndex - 1).value = obj(intIndex).value;
	obj(intIndex - 1).innerText = obj(intIndex).innerText;
	obj(intIndex).value = strValue;
	obj(intIndex).innerText = strName;
	obj.selectedIndex = intIndex - 1;
}

function OptionDown(obj) {
	var strValue;
	var strName;
	var intIndex;
	intIndex = obj.selectedIndex;
	if (intIndex == (obj.length - 1))
		return false;
	strValue = obj(intIndex + 1).value;
	strName = obj(intIndex + 1).innerText;
	obj(intIndex + 1).value = obj(intIndex).value;
	obj(intIndex + 1).innerText = obj(intIndex).innerText;
	obj(intIndex).value = strValue;
	obj(intIndex).innerText = strName;
	obj.selectedIndex = intIndex + 1;
}

function clipboardCopy(strData) {	
	window.clipboardData.setData('Text', strData);
}

function showImage(lngCustomerNo,lngImageNo,lngRecordNo) {
	var lngNewRecordNo = 0;
	if (lngRecordNo != null) lngNewRecordNo = lngRecordNo;
	window.open("/client/image_display.aspx?CustomerNo=" + lngCustomerNo + "&ImageNo=" + lngImageNo + "&RecordNo=" + lngNewRecordNo + "&ValidateCustomer=False",'_blank','width=760,height=420,titlebar=no,location=no,scrollbars=yes,resizable=yes');
}

function showInvoice(lngInvoiceNo,lngInvoiceModID) {
	window.open("/client/printable_invoice.aspx?InvoiceNo=" + lngInvoiceNo + "&ModifyID=" + lngInvoiceModID,'_blank','titlebar=no,location=no,scrollbars=yes,resizable=yes');
}

function showEditCustomer(lngCustomerNo) {
	window.open("/client/edit_customer.aspx?CustomerNo=" + lngCustomerNo,'_blank','width=650,height=450,titlebar=no,location=no,scrollbars=yes,resizable=yes');
}

function selectHide(x, y, xOffset, yOffset, intClear) {
	var self = this;
	function getVisib(obj){
		var value = obj.style.visibility;
		if (!value) {
			value = obj.currentStyle.visibility;
		}
		return value;
	};
	var strTags = new Array("applet", "select");
	var objX = x;
	var objXOff = xOffset + objX;
	var objY = y;
	var objYOff = yOffset + objY;
	for (var k = strTags.length; k > 0; ) {
		var objElements = document.getElementsByTagName(strTags[--k]);
		var elmCurrent = null;
		for (var i = objElements.length; i > 0;) {
			elmCurrent = objElements[--i];
			objElement = getAbsolutePosition(elmCurrent);
			var elmX = objElement.x;
			var elmXOff = elmCurrent.offsetWidth + elmX;
			var elmY = objElement.y;
			var elmYOff = elmCurrent.offsetHeight + elmY;

			if (self.hidden || (elmX > objXOff) || (elmXOff < objX) || (elmY > objYOff) || (elmYOff < objY)) {
				if (!elmCurrent.__msh_save_visibility) {
					elmCurrent.__msh_save_visibility = getVisib(elmCurrent);
				}
					if(intClear == 1) elmCurrent.style.visibility = elmCurrent.__msh_save_visibility;
			} else {
				if (!elmCurrent.__msh_save_visibility) {
					elmCurrent.__msh_save_visibility = getVisib(elmCurrent);
				}
				elmCurrent.style.visibility = "hidden";
			}
		}
	}
}

function getAbsolutePosition(el) {
	var SL = 0, ST = 0;
	var is_div = /^div$/i.test(el.tagName);
	if (is_div && el.scrollLeft)
		SL = el.scrollLeft;
	if (is_div && el.scrollTop)
		ST = el.scrollTop;
	var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
	if (el.offsetParent) {
		var tmp = getAbsolutePosition(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}

function TrimWhitespace(str) {
   return str.replace(/^\s*|\s*$/g,"");
}

function onEnterClick(e, strButton) {
    var keycode = null;
    if (!e) var e = window.event
    if (e.keyCode) keycode = e.keyCode;
    else if (e.which) keycode = e.which;
    if (keycode == 13) {
        var objControl = document.getElementById(strButton);
        if (objControl != null) objControl.click();
        return false;
    }
    return true;
}

function onEnterClickSSN(e, strSSNTextBox, strButton) {
    var keycode = null;
    if (!e) var e = window.event
    if (e.keyCode) keycode = e.keyCode;
    else if (e.which) keycode = e.which;
    if (keycode == 13) {
        var objControl = document.getElementById(strButton);
        objControl.click();
        return false;
    } else {
        if (document.selection.createRange().text != '') setField(strSSNTextBox,'');
        ReformatSSN(strSSNTextBox, keycode);
        return true;
    }
}

function onEnterClickPhone(e, strPhoneTextBox, strButton) {
    var keycode = null;
    if (!e) var e = window.event
    if (e.keyCode) keycode = e.keyCode;
    else if (e.which) keycode = e.which;
    if (keycode == 13) {
        var objControl = document.getElementById(strButton);
        objControl.click();
        return false;
    } else {
        if (document.selection.createRange().text != '') setField(strPhoneTextBox,'');
        ReformatPhone(strPhoneTextBox, keycode);
        return true;
    }
}

function onEnterClickDate(e, strDateTextBox, strButton) {
    var keycode = null;
    if (!e) var e = window.event
    if (e.keyCode) keycode = e.keyCode;
    else if (e.which) keycode = e.which;
    if (keycode == 13) {
        var objControl = document.getElementById(strButton);
        objControl.click();
        return false;
    } else {
        if (document.selection.createRange().text != '') setField(strDateTextBox,'');
        ReformatDate(strDateTextBox, keycode);
        return true;
    }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
evalKeyPress();// initializes the global keyeventhandler

/* catching to many errors right now - 5/11/07
window.errorHandler = function(error, file, line) {
  if(!error){ try{ error=event }catch(error){ alert('error: your page script has stopped without explanation, if you were performing an action it might have failed.'); return}}
  alert("Unexpected Client Error: '" + error + "' on line: " + line + "\n \n If this error persists please contact the help desk with information on what you did to produce this error.");
  return true;
}
window.onerror = window.errorHandler;
*/
//-->

