<!--
// This is the light-weight undocumented deployment version, 31/1/04.
// See CVS for latest, documented development copy of this lib file.
gh_dontSave=0; 

function GH_LoadFormData() {
	dataFields = top.dataFrame.document.formAll; 
	blankFields = self.document.form1; 
	self.numberOfFields = blankFields.length;
	nameToMatch = blankFields[0].name;
	self.firstFieldNum = -1;
	findField :
	for (i=0;i<dataFields.length;i++) {
		if (dataFields[i].name == nameToMatch) {
			self.firstFieldNum = i;
			break findField; 
		}
	}
	if (self.firstFieldNum == -1) {
		alert("There appears to be an error in this form,\non your browser.\n\nPlease contact support@groundhog.com.au");
		return false;
	}
	for (i=0;i<self.numberOfFields;i++) {
		curDataField = dataFields[i+self.firstFieldNum];
		curBlankField = blankFields[i];
		curPrefix = curDataField.name.substr(0,4);
		if (curPrefix == "rdb_" || curPrefix == "chk_") {
			if (curDataField.checked) {
				curBlankField.checked = true;
			}
		} else {
			if (curPrefix == "slt_") {
				curBlankField.selectedIndex = curDataField.selectedIndex;
			} else {
				blankFields[i].value = dataFields[i+self.firstFieldNum].value;
			}
		}
	}
}

function GH_SaveFormData() {
	if (self.firstFieldNum == -1 || gh_dontSave==1) {
		return false;
	}
	for (i=0;i<self.numberOfFields;i++) {
		curDataField = dataFields[i+self.firstFieldNum];
		curBlankField = blankFields[i];
		curPrefix = curDataField.name.substr(0,4);

		if (curPrefix == "rdb_" || curPrefix == "chk_") {
			if (curBlankField.checked) {
				curDataField.checked = true;
			} else {
				curDataField.checked = false;
			}
		} else {
			if (curPrefix == "slt_") {
				curDataField.selectedIndex = curBlankField.selectedIndex;
			} else {
				dataFields[i+self.firstFieldNum].value = blankFields[i].value;
			}
		}
	}
}

function GH_ValidateEmail(address) {
    var x1,x2,y;
	x1=address.indexOf('@');
	x2=address.lastIndexOf('@');
	y=address.lastIndexOf('.');
    if (x1<1 || x1>=(address.length-3) || x2!=x1) {
		return false;
	} else {
		if (y<=2 || y<=x1+1 || y>=(address.length-1)) {
			return false;
		} else {
			return true;
		}
	}
}

function GH_validateForm() {
   var i,p,q,nm, g,gChr,displayName, test,num,min,max,errors='',args=GH_validateForm.arguments;
   for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; 
	if (test.toUpperCase()=='CHK') {
	  thisForm=args[i+1]; thisField=args[i];
	  if(thisForm != ""){
		theObj = eval("document."+thisForm+"."+thisField);
        if (!theObj.checked) {
 	      if (thisField.length > 4) {
	        displayName = ""; 
	        for (g=4; g<(thisField.length); g++) {
		      gChr = thisField.substr(g,1);
		      if (gChr == "_") gChr = " ";
		      if (gChr == "-") gChr = " ";
	          displayName += gChr;
	  	    }
		    errors += '- '+displayName+' is required.\n';
	      }
	    }
	  }
	} else { 
	if (test.toUpperCase()=='RDB') {
	  thisForm=args[i+1]; thisField=args[i];
	  if(thisForm != ""){
	    Opt = -1;
		theObj = eval("document."+thisForm+"."+thisField);
	    for (j=0; j<theObj.length; j++) {
          if (theObj[j].checked) Opt = j;
	    }
		if (Opt == -1) {
 	      if (thisField.length > 4) {
	        displayName = ""; 
	        for (g=4; g<(thisField.length); g++) {
		      gChr = thisField.substr(g,1);
		      if (gChr == "_") gChr = " "; 
		      if (gChr == "-") gChr = " "; 
	          displayName += gChr;
	  	    }
		    errors += '- '+displayName+' is required.\n';
	      }
	    }
	  } 
	} else { 
	val=GH_findObj(args[i]);
    if (val) { nm=val.name;
	  if (nm.length > 4) {
	    displayName = ""; 
		for (g=4; g<(nm.length); g++) {
		  gChr = nm.substr(g,1);
		  if (gChr == "_") gChr = " "; 
		  if (gChr == "-") gChr = " "; 
	      displayName += gChr;
	  	}
	  }
	  if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=GH_ValidateEmail(val);
        if (!p) errors+='- '+displayName+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+displayName+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+displayName+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+displayName+' is required.\n'; }
	 }
	}
  } if (errors) alert('Please complete the following:\n\n'+errors);
  document.MM_returnValue = (errors == '');
}

function GH_findObj(n, d) {
  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=GH_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
//-->
