// JavaScript Document
function checkMyForm(form){
	errors=0;
	errorText="";
	errorElement="";
	
	checkSelect(form.sport_id);
	checkMultipleCheckboxes(form.aptitude);
	checkText(form.zipcode);

	if(errors){
		alert(errorText);
		return false;
	}else{
		// change below to true when done with testing
		return true;
	}
}

function checkText(element){
	if(element.value) return element.value;
	setErrors(element,element.title);
	return 0;
}

function checkRadio(element){
	for(i=0;i<element.length;i++){
		if(element[i].checked) return element[i].value;
	}
	setErrors(element,element[0].title);
	return 0;
}

function checkSelect(element){
	if(v = getSelectValue(element)) return v;
	setErrors(element,element.title);
	return 0;
}

function checkMultipleCheckboxes(element){
	ce=0;
	for(i=0; i<element.length;i++){
		if(element[i].checked) ce++;
	}
	if((!ce)&&(arguments[1]!=true)) setErrors(element,element[0].title);
	return ce;
}

function checkCheckbox(element){
	if(element.checked) return element.value;
	if(arguments[1]!=true) 	setErrors(element,element.title);
	return 0;
}

function getSelectValue(S){
	return S[S.selectedIndex].value;
}

function checkValue(element,value){
	if(element.value>=value) return element.value;
	setErrors(element,element.title);
	return 0;
}

function setErrors(element,text){
	errors++;
	errorText+=text+"\n";
	if(!errorElement) errorElement=element;
}