/*
Make sure to always use server side validation as the 
user can turn off javascript and if no server side 
validation is in place then anything can be entered 
into the form.

*/

/* Start of the auto complete style */
function toggle(obj) {
    var el = document.getElementById(obj);
    if ( el.style.display != 'none' ) {
        el.style.display = 'none';
    }
    else {
        el.style.display = '';
    }
}
/* end of the auto complete style */

function home ()
{
    document.form.submit() ;
}

/* start of limit characters for join form */
function limitText(limitField, limitCount, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } else {
        limitCount.value = limitNum - limitField.value.length;
    }
}
/* end of limit characters for join form */

/* start of join form validation */
function joinForm_validation(fname, lname, phone, email, email2, year) {
    var regexObjName = /^[a-zA-Z]+$/;
    if (fname==null || fname=="") {
        alert("Please enter your first name.");
        return false;
    }
	
    if (!regexObjName.test(fname)) {
        alert("Your first name contains illegal characters, please enter only letters.");
        return false;
    } 
	
    if (lname==null || lname=="") {
        alert("Please enter your last name.");
        return false;
    }
	
    if (!regexObjName.test(lname)) {
        alert("Your last name contains illegal characters, please enter only letters.");
        return false;
    }
	
    if (phone==null || phone=="") {
        alert("Please enter your phone number.");
        return false;
    }
    var regexObjPhone = /^([0-9]{3})([-]{1})([0-9]{3})([-]{1})([0-9]{4})$/;
    if (!regexObjPhone.test(phone)){
        alert("Please enter your phone number in this format: xxx-xxx-xxxx.");
        return false;
    }
	
    if (email==null || email=="") {
        alert("Please enter your email.");
        return false;
    }
	
    var atpos=email.indexOf("@");
    var dotpos=email.lastIndexOf(".");
    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length) {
        alert("Your email " + email + " is not a valid email.");
        return false;
    }
    if (email != email2) {
        alert("Your emails, " + email + ", " + email2 + " do not match.");
        return false;
    }
	
/*if (year.checked==false) {
		alert(year);
		return false;
	} */
}
/* end of join form validation */

/* start of search form validation */
function search_validation(find) {
    if (find==null || find=="") {
        alert("Please enter something to search.");
        return false;
    }
}
/* end of search form validation */

/* start of confrim for Populating the Attendance Database */
function popDataConfirm(){
    var agree = confirm(" Are you sure you want to clear all entries in the attendance database and start from nothing?\n This will clear every event added and make all brothers start at zero points.");
    if (agree) {
        return true ;
    }
    else {
        return false ;
    }
}
/* End of confrim for Populating the Attendance Database */

/* start of confrim for deleting an event */
function attendDelete(){
    var agree = confirm("Are you sure you want to delete this event from the database?");
    if (agree) {
        return true ;
    }
    else {
        return false ;
    }
}
/* End of confrim for deleting an event */

/* End of confrim for emailing the attendance for brothers  */
function emailConfirm(){
    var agree = confirm("Are you sure you want to email the Brothers?");
    if (agree) {
        return true ;
    }
    else {
        return false ;
    }
}
/* End of confrim for emailing the attendance for brothers */

/* start of confrim for deleting tokens */
function deleteToken(){
    var agree = confirm("Are you sure you want to delete all the Tokens?");
    if (agree) {
        return true ;
    }
    else {
        return false ;
    }
}
/* End of confrim for deleting tokens */
		

/* start of check all radio buttons
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
 end of check all radio buttons*/


