function CheckContentForm(daForm) {
	var MissingFields=0;
	var ManFieldValue=daForm.mandatory.value;
	var ManFields=ManFieldValue.split(",");
	for(x=0;x<ManFields.length;x++) {
	FieldName=ManFields[x];
		// go through validation options	
		if(FieldName.indexOf("{email}")>1) {
			FieldName=FieldName.replace("{email}","");
			if(!TestEmail($F(FieldName))) {
			var MissingFields=MissingFields+1;
			}
		}
		else if(FieldName.indexOf("{number}")>1) {
			FieldName=FieldName.replace("{number}","");			
			if(isNaN($F(FieldName))) {
			var MissingFields=MissingFields+1;
			}
		}
		else if(FieldName.indexOf("{amount}")>1) {
			FieldName=FieldName.replace("{amount}","");			
			FieldValue=$F(FieldName).replace("$","");
			if(isNaN(FieldValue) || $F(FieldName)=="") {
			var MissingFields=MissingFields+1;
			}
		}
		else if(FieldName.indexOf("[]")>1) {
			FieldName=FieldName.replace("[]","");
			//alert(FieldName);
		}
		else {
			if(MM_findObj(FieldName).length>1) {
				if(MM_findObj(FieldName)[0].type=="radio" || MM_findObj(FieldName)[0].type=="checkbox") {
					var MissingFields=MissingFields+1;
					for(y=0;y<MM_findObj(FieldName).length;y++) {
						if(MM_findObj(FieldName)[y].checked==true) {
						var MissingFields=MissingFields-1;
						}
					}
				}
			}
			else {
				if(MM_findObj(FieldName).value=="") {
				var MissingFields=MissingFields+1;
				}
			}
		}
	}
		
	if(ManFields.length > 0) {
		if(MissingFields>0) {
		alert("Please fill out all fields marked with an asterisk.");
		return false;
		}
		else {
		return true;
		}
	}
	else {
	return true;
	}
}

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 TestEmail(e) {
	if(e) {
	p = e.indexOf('@');
	s = e.indexOf(';');
	d = e.lastIndexOf('.');
		if (p<1 || p==(e.length-1) || d<p || d==(e.length-1) || s>-1) {
		return false;
		}
	return true;
	}
return false;
}

function RemoveJunk(El,DataType) {
var V = El.value;
	if(DataType=="int") {
		if (/[^0-9\.]/g.test(V)) {
		El.value = V.replace(/[^0-9\.]/g, '');
		}
	}
	else if(DataType=="string") {
		if (/[^a-zA-Z\.]/g.test(V)) {
		El.value = V.replace(/[^a-zA-Z\.]/g, '');
		}
	}
	else if(DataType=="stringint") {
		if (/[^a-zA-Z0-9]/g.test(V)) {
		El.value = V.replace(/[^a-zA-Z0-9]/g, '');
		}
	}
	else if(DataType=="username") {
		if (/[^a-zA-Z0-9_\-]/g.test(V)) {
		El.value = V.replace(/[^a-zA-Z0-9_\-]/g, '');
		}
	}
	else if(DataType=="stringnospace") {
		if (/[^a-zA-Z0-9_\- ]/g.test(V)) {
		El.value = V.replace(/[^a-zA-Z0-9_\- ]/g, '');
		}
	}
	else if(DataType=="password") {
		if (/[^a-zA-Z0-9_!\$\.]/g.test(V)) {
		El.value = V.replace(/[^a-zA-Z0-9_!\$\.]/g, '');
		}
	}
	else if(DataType=="amount") {
		if (/[^0-9\.\$]/g.test(V)) {
		El.value = V.replace(/[^0-9\.\$]/g, '');
		}
	}
	else if(DataType=="nofloat") {
		if (/[^0-9\$]/g.test(V)) {
		alert('Sorry, only whole dollar amounts are permitted.');
		El.value = V.replace(/[^0-9\$]/g, '');
		}
	}
}

function CheckHandle(El) {
	var myAjax = new Ajax.Updater(
		{success: 'HandlerContainer'}, 
		"_ajax.checkhandle.inc.php", 
		{
		method: 'get', 
		parameters: "username="+El.value, 
		evalScripts: true
	});
}

function CheckIsSelected(ElName,ElType) {
	var Len=document.FormDisplay.elements.length;
	var IsaGo=false;
	for(x=0;x<Len;x++) {
		if(document.FormDisplay.elements[x].name==ElName) {
			if(document.FormDisplay.elements[x].checked==true) {
			var IsaGo=true;
			}
		}
	}
	
	if(IsaGo==true) {
	return true;
	}
	else {
	alert('Please use the checkboxes to the left to select the '+ ElType);
	return false;
	}
}

var CheckedStatus="off";

function doSelectAll(ElName) {
	var Len=document.FormDisplay.elements.length;
	for(x=0;x<Len;x++) {
		if(document.FormDisplay.elements[x].name==ElName) {
			if(CheckedStatus=="off") {
				if(document.FormDisplay.elements[x].checked==false) {
				document.FormDisplay.elements[x].checked=true;
				}			
			}
			else {
			document.FormDisplay.elements[x].checked=false;
			}
		}
	}
	if(CheckedStatus=="off") {
	CheckedStatus="on";
	}
	else {
	CheckedStatus="off";
	}
}

function clearForm(formIdent) 
{ 
  var form, elements, i, elm; 
  form = document.getElementById 
    ? document.getElementById(formIdent) 
    : document.forms[formIdent]; 

	elements = form.elements;
		for( i=0, elm; elm=elements[i++]; )
		{
			if (elm.type == "text")
			{
				elm.value ='';
			}
			
			if (elm.type == "radio" || elm.type == "checkbox")
			{
				elm.checked = false;
			}
			
			if (elm.length > 1 && (elm.type != "radio" || elm.type != "checkbox"))
			{
			
				elm.selectedIndex = 0;
			}
		}
}

