function changeStatus(){
	var anchors = document.getElementsByTagName("A");
	for(var i = 0; i < anchors.length; i++){
		a = anchors[i];
		if (a.href.indexOf(".asp") > 0){
			a.onmouseover = function(){
				status = a.innerHTML;
			}
			a.onmouseout = function(){
				status = defaultStatus;
			}
		}
	}
}

function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}

function checkForm(frmName){
	booleanName = true
	booleanAge = true
	booleanContact = true
	booleanEmail = true
	booleanAdd = true
	booleanPostal = true
	booleanSubject = true
	booleanFeedback = true
	booleanPool = true
	booleanProficiency = true
	booleanSize = true
	booleanType = true
	msg = ""
	if(document.forms[frmName].txtName!=null){
		txtName = document.forms[frmName].txtName
		checkName(txtName)
	}
	if(document.forms[frmName].txtAge!=null){
		txtAge = document.forms[frmName].txtAge
		checkAge(txtAge)
	}
	if(document.forms[frmName].txtContact!=null){
		txtContact = document.forms[frmName].txtContact
		checkContact(txtContact)
	}
	if(document.forms[frmName].txtEmail!=null){
		txtEmail = document.forms[frmName].txtEmail
		checkEmail(txtEmail)
	}
	if(document.forms[frmName].txtAdd!=null){
		txtAdd = document.forms[frmName].txtAdd
		checkAdd(txtAdd)
	}
	if(document.forms[frmName].txtPostal!=null){
		txtPostal = document.forms[frmName].txtPostal
		checkPostal(txtPostal)
	}
	if(document.forms[frmName].txtSubject!=null){
		txtSubject = document.forms[frmName].txtSubject
		checkSubject(txtSubject)
	}
	if(document.forms[frmName].txtFeedback!=null){
		txtFeedback = document.forms[frmName].txtFeedback
		checkFeedback(txtFeedback)
	}
	if(document.forms[frmName].txtPool!=null){
		txtPool = document.forms[frmName].txtPool
		checkPool(txtPool)
	}
	if(document.forms[frmName].txtProficiency!=null){
		txtProficiency = document.forms[frmName].txtProficiency
		checkProficiency(txtProficiency)
	}
	if(document.forms[frmName].txtSize!=null){
		txtSize = document.forms[frmName].txtSize
		checkSize(txtSize)
	}
	if(document.forms[frmName].txtType!=null){
		txtType = document.forms[frmName].txtType
		checkType(txtType)
	}
	if(msg != ""){
		msg = "The following information is required:\n\n" + msg
		alert(msg)
	}
	return booleanName && booleanAge && booleanContact && booleanEmail && booleanAdd && booleanPostal && booleanSubject && booleanFeedback && booleanPool && booleanProficiency && booleanSize && booleanType
}

function checkName(txt){
	if(txt.value.length==0){
		msg = msg + "Name.\n"
		txt.focus()
		booleanName = false
	}
}

function checkAge(txt){
	expression = /^[0-9]+$/
	if (!txt.value.match(expression)){
		msg = msg + "Valid Age.\n"
		txt.focus()
		booleanAge = false
	}
//	else{
//		if (txt.value.length==1 && txt.value != "9"){
//			msg = msg + "Age 9 and above.\n"
//			txt.focus()
//			booleanAge = false
//		}
//	}
}

function checkContact(txt){
	validD1 = false
	expression = /^[0-9]+$/
	if(txt.value.charAt(0) == "9" || txt.value.charAt(0) == "8" || txt.value.charAt(0) == "6"){
		validD1 = true
	}
	if (!txt.value.match(expression) || txt.value.length != 8 || validD1 == false){
		msg = msg + "Valid contact number.\n"
		txt.focus()
		booleanContact = false
	}
}

function checkEmail(txt){
	var testString = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3}){1,2}$/
	if (!testString.test(txt.value)){
		msg = msg + "Valid email address.\n"
		txt.focus()
		booleanEmail = false
	}
}

function checkAdd(txt){
	if (txt.value.length==0){
		msg = msg + "Valid address.\n"
		txt.focus()
		booleanAdd = false
	}
}

function checkPostal(txt){
	if (isNaN(parseInt(txt)) && txt.value.length!=6){
		msg = msg + "6-digit postal code.\n"
		txt.focus()
		booleanPostal = false
	}
}

function checkSubject(txt){
	if (txt.value.length==0){
		msg = msg + "Subject.\n"
		txt.focus()
		booleanSubject = false
	}
}

function checkFeedback(txt){
	if (txt.value.length==0){
		msg = msg + "Message.\n"
		txt.focus()
		booleanFeedback = false
	}
}

function checkPool(txt){
	if (txt.value=="Name of pool here..."){
		msg = msg + "Name of preferred pool.\n"
		txt.focus()
		booleanPool = false
	}
}

function checkProficiency(txt){
	var isChecked = false
	for(var i=0; i < txt.length; i++){
		if (txt[i].checked){
			isChecked = true
			break;
		}
	}
	if (isChecked == false){
		msg = msg + "Proficiency level.\n"
		booleanProficiency = false
	}
}

function checkSize(txt){
	if (txt.value=="na"){
		msg = msg + "No. of people learning.\n"
		txt.focus()
		booleanSize = false
	}
}

function checkType(txt){
	var isChecked = false
	for(var i=0; i < txt.length; i++){
		if (txt[i].checked){
			isChecked = true
			break;
		}
	}
	if (isChecked == false){
		msg = msg + "Who is learning.\n"
		booleanType = false
	}
}
