function checkForm ( formName ) {
	allGood = true;
	var textInputs = document.getElementsByTagName ( 'input' ) ;
	var selectInputs = document.getElementsByTagName ( 'select' ) ;
	var textAreas = document.getElementsByTagName ( 'textarea' ) ;
	
	for ( var i = 0 ; i < textInputs.length ; i++ ) {
		if ( textInputs[i].type == "text" ) {
			var inputName = textInputs[i].name ;
			if ( inputName.indexOf ( "phone" ) >= 0 ) {
				var labelName = "phoneLbl";
			} else {
				var labelName = textInputs[i].name + "Lbl";
			}
			var curLabel = document.getElementById ( labelName ) ; 
			var lblClassName = curLabel.className;
			checkInputClass ( textInputs[i].value, curLabel, lblClassName, textInputs[i].className );			
		}
	}
	
	for ( var i = 0 ; i < selectInputs.length ; i++ ) {
		var selectName = selectInputs[i].name;
		var labelName = selectName + "Lbl";
		var curLabel = document.getElementById ( labelName ) ;
		var selectValue = selectInputs[i][selectInputs[i].selectedIndex].value;
		var lblClassName = curLabel.className;
		checkInputClass ( selectValue, curLabel, lblClassName ) ;
	}
	
	for ( var i = 0 ; i < textAreas.length ; i++ ) {
		var areaLabel = document.getElementById ( textAreas[i].name + "Lbl" ) ;
		var lblClassName = areaLabel.className;
		checkInputClass ( textAreas[i].value, areaLabel, lblClassName ) ;
	}
	
	if ( allGood ) {
		document.forms[formName].submit();
	} else {
		return false;
	}
}


function checkInputClass ( inputValue, labelName, labelClass, inputClass) {
	var classType = inputClass;
	/*alert ( labelClass ) ;
	if ( labelClass.indexOf ( " invalid" ) ) {
		classType = classType.replace ( " invalid", "" ) ;
	}*/
	if ( inputValue == "" || !checkEntry ( classType, inputValue  ) ) {
		if ( labelClass.indexOf ( " invalid" ) < 0 ) {
			labelClass += " invalid";
		}
		allGood = false;
	} else {
		if ( labelClass.indexOf ( " invalid" ) >= 0 ) {
			labelClass = labelClass.replace ( " invalid", "" ) ;	
		}
	}
	labelName.className = labelClass;
}

function resetForm ( formName ) {
	var textInputs = document.getElementsByTagName('input');
	var selectInputs = document.getElementsByTagName('select');
	var textAreas = document.getElementsByTagName('textarea');
	var labels = document.getElementsByTagName('label');
	
	for ( var i = 0; i < textInputs.length ; i++ ) {
		if ( textInputs[i].type == "checkbox" ) {
			textInputs[i].checked = false;
		} else {
			textInputs[i].value = "";	
		}
	}
	
	for ( var j = 0 ; j < selectInputs.length ; j++ ) {
		selectInputs[j].selectedIndex = 0;	
		if ( selectInputs[j].onchange ) {
			selectInputs[j].onchange();
		}
	}
	
	for ( var k = 0 ; k < textAreas.length ; k++ ) {
		textAreas[k].value = "";

	}
	
	for ( var m = 0 ; m < labels.length ; m++ ) {
		var labelClass = labels[m].className;
		if ( labelClass.indexOf ( " invalid" ) ) {
			labelClass = labelClass.replace ( " invalid", "" ) ;
			labels[m].className = labelClass;
		}
	}
}

function checkKey ( fieldType ) {
	switch ( fieldType ) {
		case "phone":
			break;
		default:
			break;
	}
}

function checkEntry ( entryType, entryVal ) {
	//alert ( entryType );
	switch ( entryType ) {
		case "email":
			var myExp = /^(\w*(\-|\.)?)*@\w*\-?\w*([\.A-Za-z]{3})([\.A-Za-z]{2,3})*$/;
			if ( myExp.test ( entryVal ) ) { return true; }
			break;
		case "name":
		default:
			return true;
			break;
	}

}
