String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function validate(){
	var formEl = document.getElementById('reg_form');
	
	var errors = [];
	if(formEl.fname.value.trim() == ''){
		errors.push("Your first name is required.");
	}
	
	if(formEl.lname.value.trim() == '' ){
		errors.push("Your last name is required.");
	}
	
	if(formEl.email.value.trim() == '' ){
		errors.push("Your email address is required.");
	}
	
	if(formEl.phone.value.trim() == ''){
		errors.push("Your telephone number is required.");
	}
	
	if(formEl.city.value.trim() == ''){
		errors.push("Your city is required.");
	}
	
	if(formEl.state.options[formEl.state.selectedIndex].value == '-1'){
		errors.push("Please select your state.");
	}
	
	if(formEl.zipcode.value.trim() == '' ){
		errors.push("Your zipcode is required.");
	}
	
	// validate how heard of taxliens
	if(formEl.howheard.value.trim() == ''){
		errors.push("Please enter how you heard about taxliens.com.");
	}
	
	//validate why tax liens
	var haveVal = false;
	for(var i = 0; i < formEl.whytaxliens.length; i++){
		if(formEl.whytaxliens[i].checked){
			haveVal = true;
		}
	}
	if(!haveVal){
		errors.push("Please select why you are interested in tax liens.");
	}
	
	// validate currently investing
	var haveVal = false;
	for(var i = 0; i < formEl.investing.length; i++){
		if(formEl.investing[i].checked){
			haveVal = true;
		}
	}
	if(!haveVal){
		errors.push("Please select if you are currently investing in real estate.");
	}
	
	// validate credit
	var haveVal = false;
	for(var i = 0; i < formEl.credit.length; i++){
		if(formEl.credit[i].checked){
			haveVal = true;
		}
	}
	if(!haveVal){
		errors.push("Please select how you would rate your credit.");
	}
	
	// validate best time to contact
	var haveVal = false;
	for(var i = 0; i < formEl.contact.length; i++){
		if(formEl.contact[i].checked){
			haveVal = true;
		}
	}
	if(!haveVal){
		errors.push("Please select the best time to contact you.");
	}
	

	var haveVal = false;
	for(var i = 0; i < formEl.experience.length; i++){
		if(formEl.experience[i].checked){
			haveVal = true;
		}
	}
	if(!haveVal){
		errors.push("Please select your real estate investing experience level.");
	}
	
	if(errors.length != 0){
		errorStr = '<ul>';
		for(var i=0; i<errors.length; i++){
			errorStr += '<li>' + errors[i] + '</li>';
		}
		errorStr += '</ul>';
		
		var errorDiv = document.getElementById('error_message') 
		errorDiv.innerHTML = errorStr;
		errorDiv.style.display = 'block';
		return false;
	}
	return true;
}