


function checkboxvalidation(formIndex, alertbox)
{
	// Loops through all checkboxes in a form and determines whether or not at least one is checked
	// if at least one is checked, return true (no alert), else false
// E-mail Validation by Jeremy Gayed / www.DesignByMagik.com

		pass=false;
		
		for(i=0; i<document.forms[formIndex].elements.length; i++)
		{
			if(document.forms[formIndex].elements[i].type=="checkbox"){
				if(document.forms[formIndex].elements[i].checked==true){ pass=true; }
			}
		}
		
		if (pass==false) {
			alert(alertbox);
			return false;
		} else {
			return true;
		}

}



function emailvalidation(entered, alertbox)
{
// E-mail Validation by Jeremy Gayed / www.DesignByMagik.com
with (entered)
{
apos=value.indexOf("@"); 
dotpos=value.lastIndexOf(".");
lastpos=value.length-1;
if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
{if (alertbox) {alert(alertbox);} return false;}
else {return true;}
}
}

function valuevalidation(entered, min, max, alertbox, datatype)
{
// Value Validation by Jeremy Gayed / www.DesignByMagik.com
with (entered)
{
checkvalue=parseFloat(value);
if (datatype)
{smalldatatype=datatype.toLowerCase();
if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(value)};
}
if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || value!=checkvalue)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}


function digitvalidation(entered, min, max, alertbox, datatype)
{
// Digit Validation by Jeremy Gayed / www.DesignByMagik.com
with (entered)
{
checkvalue=parseFloat(value);
if (datatype)
{smalldatatype=datatype.toLowerCase();
if (smalldatatype.charAt(0)=="i") 
{checkvalue=parseInt(value); if (value.indexOf(".")!=-1) {checkvalue=checkvalue+1}};
}
if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || value!=checkvalue)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}


function emptyvalidation(entered, alertbox)
{
// Emptyfield Validation by Jeremy Gayed / www.DesignByMagik.com
if (entered.value==null || entered.value=="")
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}

}

function matchingvalidation(entered, matchwith, alertbox)
{
// Matching  Validation by Jeremy Gayed / www.DesignByMagik.com
	var firstVal = entered.value;
	var secondVal = matchwith.value;
	
	if (firstVal==null || firstVal=="") {
		if (alertbox!=""){alert(alertbox);}
		return false;
	} else if ( secondVal==null || secondVal=="" ) {
		if (alertbox!=""){alert(alertbox);}
		return false;
	} else if ( firstVal != secondVal ) {
		if (alertbox!=""){alert(alertbox);}
		return false;
	} else {
		return true;
	}
}

function matchOKblank(entered, matchwith, alertbox)
{
// Matching  Validation by Jeremy Gayed / www.DesignByMagik.com
	var firstVal = entered.value;
	var secondVal = matchwith.value;
	
	if (firstVal!=secondVal) {
		if (alertbox!=""){alert(alertbox);}
		return false;
	} else {
		return true;
	}
}

function comboValidation (what, init, alertbox) {
	// Written by Magik (designbymagik.com)
	// Validates comboBox, makes sure its not still on defautl 'Init' value
	if (what.value==init) {
		alert(alertbox);
		return false;
	}else{
		return true;
	}
}

function howHearValidation (comboHear, otherHear_, init, other, comboAlertbox, otherAlertbox) {

	if ( comboHear.value == init ) {
		comboHear.focus();
		return false;
	} else if ( comboHear.value == other ) {
		if ( emptyvalidation(otherHear_, otherAlertbox) == false ) {
			otherHear_.focus();
			return false;
		} else {
			return true;
		}
	} else {
		return true;
	}
}

function updatevalid(thisform)
{
// This function checks the entire form before it is submitted
// Note: This function needs to be customized to fit your form
	with (thisform)
		{
		
		// Name
		if (emptyvalidation(name,"Please enter your name.")==false) {name.focus(); return false;};
		
		// Email
		if (emailvalidation(email,"Please enter a valid e-mail address.")==false) {email.focus(); return false;};
		//if (comboValidation(Specialty, "nada", "Please select a Specialty.")==false) {Specialty.focus(); return false;};
		
		// Combos
		if (comboValidation(Groups, "nada", "Please select a Group.")==false) {Groups.focus(); return false;};
		if (comboValidation(skill, "nada", "Please select a Skill.")==false) {skill.focus(); return false;};
		if (comboValidation(position, "nada", "Please select a Position.")==false) {position.focus(); return false;};
	
			// Matching validation
			if (matchOKblank(newpw, newpw2, "Passwords do not match, please try again.")==false) {newpw.focus(); return false;};
		
		}
}

function formteamvalidation(thisform)
{
	with (thisform)
	{
		// Events
		if (checkboxvalidation(0, "Please select at least one event/tournament.")==false) {ShootingContest.focus(); return false;};
		
		// Name
		if (emptyvalidation(yourname,"Please enter your name.")==false) {yourname.focus(); return false;};
		
		// Email
		if (emailvalidation(email,"Illegal E-mail")==false) {email.focus(); return false;};
		
		// Phone
		if (emptyvalidation(phone,"Please enter your phone number.")==false) {phone.focus(); return false;};
		
		// Team Name
		if (emptyvalidation(teamname,"Please enter your Team Name.")==false) {teamname.focus(); return false;};
		// Team Colors
		if (emptyvalidation(teamcolors,"Please enter your Team Colors.")==false) {teamcolors.focus(); return false;};
		// Team City
		if (emptyvalidation(teamcity,"Please enter your Team City.")==false) {teamcity.focus(); return false;};
	}
}

function formindividualvalidation(thisform)
{
	with (thisform)
	{
		// Events
		if (checkboxvalidation(0, "Please select at least one event/tournament.")==false) {ShootingContest.focus(); return false;};
		
		// Name
		if (emptyvalidation(yourname,"Please enter your name.")==false) {yourname.focus(); return false;};
		
		// Email
		if (emailvalidation(email,"Illegal E-mail")==false) {email.focus(); return false;};
		
		// Phone
		if (emptyvalidation(phone,"Please enter your phone number.")==false) {phone.focus(); return false;};
		
		// City
		if (emptyvalidation(city,"Please enter your City.")==false) {city.focus(); return false;};
	}
}

function formvalidation(thisform)
{
// This function checks the entire form before it is submitted
// Note: This function needs to be customized to fit your form
	with (thisform)
		{
		
		// Name
		if (emptyvalidation(name,"Please enter your name.")==false) {name.focus(); return false;};
		
		// Email
		if (emailvalidation(email,"Illegal E-mail")==false) {email.focus(); return false;};
		//if (comboValidation(Specialty, "nada", "Please select a Specialty.")==false) {Specialty.focus(); return false;};
		
		// Combos
		if (comboValidation(Groups, "nada", "Please select a Group.")==false) {Groups.focus(); return false;};
		if (comboValidation(skill, "nada", "Please select a Skill.")==false) {skill.focus(); return false;};
		if (comboValidation(position, "nada", "Please select a Position.")==false) {position.focus(); return false;};
		
		// Username
		if (emptyvalidation(username,"Please enter a Username.")==false) {username.focus(); return false;};
		
		// Passwords
		if (emptyvalidation(password,"Please enter a password.")==false) {password.focus(); return false;};
		if (emptyvalidation(password2,"Please confirm your password.")==false) {password2.focus(); return false;};
			// Matching validation
			if (matchingvalidation(password, password2, "Passwords do not match, please try again.")==false) {password.focus(); return false;};
		
		//if (comboValidation(Prod_interest, "nada", "Please select a Product of Interest.")==false) {Prod_interest.focus(); return false;};
		
		//if (howHearValidation(HowHear, OtherHear, "nada", "other", "Please select how you heard about Microwize.", "Please specify any 'Other' means of how you heard about Microwize in the textbox provided.")==false) {return false;};
		
		//if (valuevalidation(Providers,0,9999,"Number of Providers in Practice value must be in the range 0-9999")==false) {Providers.focus(); return false;};
		//if (valuevalidation(Computers,0,9999,"Number of Computers in Practice value must be in the range 0-9999")==false) {Computers.focus(); return false;};
		
		//if (digitvalidation(Digits,3,4,"You MUST enter 3 or 4 integer digits","I")==false) {Digits.focus(); return false;};
		
		}
}
