
function findObj(theObj, theDoc){
  var p, i, foundObj;if(!theDoc) theDoc = document;if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {theDoc = parent.frames[theObj.substring(p+1)].document;theObj = theObj.substring(0,p);}
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++)foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);return foundObj;
}

function toggleFields(obj, fields){

	//Is the checkboxed checked or not?
	var retVal = (!obj.checked)? true : false;
	var i,j,curObj;
	var fieldList = fields
    var sepFieldList = fieldList.split(",");
	var fieldCount = sepFieldList.length;

	//Create a list of common fields minus their cst and cstShp prefixes respectively
	var arrCommonFields = sepFieldList;
	var arrCommonFields_length = arrCommonFields.length;

	//Create a list of special fields that have need other work done before they can have a value set or be enabled/disabled
	var arrSpecialFields = sepFieldList;

	//An array of all fields, both common and special for the purpose of enabling/disabling the fields
	var arrAllFields = arrCommonFields.concat(arrSpecialFields);
	var arrAllFields_length = arrAllFields.length;

	//Loop through all fields and disable them if the box is checked, otherwise enable the fields.
	for(j=0; j<arrAllFields_length;j++){
		curObj = findObj(arrAllFields[j]);
		if(curObj){			
			if(retVal)
			{
			  curObj.setAttribute("disabled","disabled");
			} else {
			  curObj.removeAttribute("disabled");
			}
		}
	}
    return retVal;
  
}
