function clearClass(elem){
	document.getElementById(elem.id).className = "";
}

function clearFormField(theText){
	if (theText.value == theText.defaultValue) {
		theText.value = "";
	}
}
function defaultFormField(theText){
	if (theText.value == "") {
		theText.value = theText.defaultValue;
	}	
}


function isEmpty(elem){
	if(elem.value.length == 0){
		return false;
	}
	return true;
}

function isAlphabet(elem){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		return false;
	}
}

function isAlphanumeric(elem){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		return false;
	}
}

function isValidEmail(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		return false;
	}
}



function formValidator(){
	// Make quick references to our fields
	var txtFirstName = document.getElementById('txtFirstName');
	var txtLastName = document.getElementById('txtLastName');
	var txtAddress1 = document.getElementById('txtAddress1');
	var txtCity = document.getElementById('txtCity');
	var txtPostalCode = document.getElementById('txtPostalCode');
	var txtTelephone = document.getElementById('txtTelephone');
	var txtBillingDetailYourReference = document.getElementById('txtBillingDetailYourReference');
	var confirm_txtBillingDetailYourReference = document.getElementById('confirm_txtBillingDetailYourReference');
	
	var msg = new Array();
	
	if(!isEmpty(txtFirstName)) { 
		msg.push("Enter your first name."); 
		document.getElementById("txtFirstName").className += " invalid";
	}
	if(!isEmpty(txtLastName)) { 
		msg.push("Enter your last name."); 
		document.getElementById("txtLastName").className += " invalid";
	}
	if(!isEmpty(txtAddress1)) { 
		msg.push("Enter your address.");
		document.getElementById("txtAddress1").className += " invalid";
	}
	if(!isEmpty(txtCity)) { 
		msg.push("Enter your city."); 
		document.getElementById("txtCity").className += " invalid";
	}
	if(!isEmpty(txtPostalCode)) { 
		msg.push("Enter your postal code.");
		document.getElementById("txtPostalCode").className += " invalid";
	}
	if(!isEmpty(txtTelephone)) { 
		msg.push("Enter your telephone."); 
		document.getElementById("txtTelephone").className += " invalid";
	}
	if(!isValidEmail(txtBillingDetailYourReference)) {
		msg.push("Enter a valid email address."); 
		document.getElementById("txtBillingDetailYourReference").className += " invalid";		
	}
	if(!isEmpty(confirm_txtBillingDetailYourReference)) {
		msg.push("Confirm your email address."); 
		document.getElementById("confirm_txtBillingDetailYourReference").className += " invalid";		
	}
	if(txtBillingDetailYourReference.value != confirm_txtBillingDetailYourReference.value) {
		msg.push("Your email addresses do not match."); 
		document.getElementById("confirm_txtBillingDetailYourReference").className += " invalid";		
	}	

	//alert(msg);
	if (msg.length <1){
		return true;
	} else {
		alert("Please complete all required fields.");
		return false;
	}	
	
}



