function CheckThem() {
	chks = document.getElementsByTagName('input');
	for (i=0;i<chks.length;i++) {
		var tempobj=chks[i];
		if (tempobj.tagName.toLowerCase()!='checkbox') {
			if (tempobj.name != 'CheckAll') {
				tempobj.checked = document.getElementById('CheckAll').checked;
			}
		}
	}	
}

function CheckAllEmployees(me) {
	chks = document.getElementsByTagName('input');
	for (i=0;i<chks.length;i++) {
		var tempobj=chks[i];
		if (tempobj.tagName.toLowerCase()!='checkbox') {
			if (tempobj.name.substring(0,8) != 'CheckAll') {
				if (tempobj.name.substring(0,8) == 'Employee') {
					tempobj.checked = me.checked;
				}
			}
		}
	}	
}

function CheckAllGroups(me) {
alert("Here");
}


function UserFilledInSomething(which) {
	var pass=false;
	if (document.images) {
		for (i=0;i<which.length;i++) {
			var tempobj=which.elements[i];
			if (tempobj.name.substring(0,8)=='required') {
				if (((tempobj.type=='text'||tempobj.type=='textarea'||tempobj.type=="password")&& tempobj.value!='')||(tempobj.type.toString().charAt(0)=='s'&& tempobj.selectedIndex!=0)) {
					pass=true; 
					break;
				}
			}
		}
	}
	if (!pass) {
		shortFieldName=tempobj.name.substring(8,30).toUpperCase();
		document.getElementById('SubmitError').innerHTML = 'You need to fill in at least one field before continuing.';
	} else {
		document.getElementById('SubmitError').innerHTML = '';
	}
	return pass;
}
			
function CheckRequiredFields(which) {
//alert('Here');
	var pass=true;
	if (document.images) {
		for (i=0;i<which.length;i++) {
			var tempobj=which.elements[i];
			if (tempobj.name.substring(0,8)=='required') {
				if (((tempobj.type=='text'||tempobj.type=='textarea'||tempobj.type=="password")&& tempobj.value=='')||(tempobj.type.toString().charAt(0)=='s'&& tempobj.selectedIndex==0)) {
					pass=false; 
					break;
				}
			}
		}
	}
	if (!pass) {
		shortFieldName=tempobj.name.substring(8,30).toUpperCase();
		document.getElementById('SubmitError').innerHTML = 'Please make sure the '+shortFieldName+' field was properly completed.';
	} else {
		document.getElementById('SubmitError').innerHTML = '';
	}
	return pass;

}

function CheckEmailField(field) {
	value = document.getElementById(field).value;
	apos=value.indexOf("@");
	dotpos=value.lastIndexOf(".");
	if (apos<1||dotpos-apos<2){
		document.getElementById('SubmitError').innerHTML = 'The email address you entered is not valid!';
		return false;
	} else {
		document.getElementById('SubmitError').innerHTML = '';
		return true;
	}
}

function CheckPhoneField(field) {
	value = document.getElementById(field).value;
	var stripped = value.replace(/[\(\)\.\-\ ]/g, '');
	//strip out acceptable non-numeric characters
	var error='';
	if (isNaN(parseInt(stripped))) {
   		error = "The phone number contains illegal characters.";
	}
	if (stripped.length == 10) {
	} else {
		error = "The phone number you entered is not valid";
	}
	if (error.length > 0 ) {
		document.getElementById('SubmitError').innerHTML = error;
		return false;
	} else {
		document.getElementById('SubmitError').innerHTML = '';
		return true;
	}
	return false;
}

function CheckFieldsMatch(field1, field2) {
	val1 = document.getElementById(field1).value;
	val2 = document.getElementById(field2).value;
	if (val1 == val2) {
		document.getElementById('SubmitError').innerHTML = '';
		return true;
	} else {
		if (field1.substring(0,8)=='required') {
			shortFieldName1=field1.substring(8,30).toUpperCase();
		} else {
			shortFieldName1=field1.toUpperCase();
		}
		if (field2.substring(0,8)=='required') {
			shortFieldName2=field2.substring(8,30).toUpperCase();
		} else {
			shortFieldName2=field2.toUpperCase();
		}
		document.getElementById('SubmitError').innerHTML = shortFieldName1+' and '+shortFieldName2+' do not match.';
		return false;
	}
}



function AreYouSure(Type, Name, Forward) {
	if (confirm("Clicking OK will delete " + Type + " '" + Name + "' permanently.  Are you sure you want to proceed?")) {
		window.location= Forward;
	}
}

function AreYouSureGroup(Group, Name) {
	return confirm("Clicking OK will remove " + Name + " from group '" + Group + "' permanently.  Are you sure you want to proceed?");
}

