function checkRegister() {
	var last_name = '';
	var first_name = '';
	var username = '';
	var password = '';
	var email = '';
	var phone = '';
	var state = '';
	var address = '';
	var city = '';
	var zip = '';
	var sc = '';
	var terms = '';
	
	/*var inputs = document.getElementsByTagName("input");
    var end = inputs.length;
	
	for (i=0; i < end - 6; i++) {
			inputs[i].style.border = '1px solid #ABADB3';
	}*/
	
	
	
	phone 		= 	checkPhone('phone','c-fv6','c-fr6');
	
	terms 		= 	checkTerms('terms','c-fv11','c-fr11');
	
	zip 		= 	checkFilled('zip','c-fv2','c-fr2');
	state 		= 	checkFilled('state','c-fv4','c-fr4');
	city 		= 	checkFilled('city','c-fv3','c-fr3');
	address 	= 	checkFilled('address','c-fv1','c-fr1');
	
	last_name 	=	checkFilled('last_name','b-fv2','b-fr2');
	first_name 	=	checkFilled('first_name','b-fv1','b-fr1');
	
	password 	=	checkFilled('password','a-fv3','a-fr3');
	email 		=	validateEmail('email','a-fv2','a-fr2');
	username 	=	validateUsername('username','a-fv1','a-fr1');
	
	sc 		= 	checkCode('sc','c-fv10','c-fr10');
	
	errors = username + email + password + first_name + last_name + phone + state + city + address + zip + sc + terms;
	
	if (errors == '') {
		return true;
	} else {
		alert('Please fill in all required fields');
		return false;
		
	}		
}


function hilight(rowID) {
	var row = document.getElementById(rowID);
	row.style.backgroundColor = '#EEEEEE';
 	return;
}
function lowlight(rowID) {
	var row = document.getElementById(rowID);
	row.style.backgroundColor = '#FFFFFF';
 	return;
}
function checkFilled(formID, validateID, rowID) {
	var error="";
	var validate = document.getElementById(validateID);
	var form = document.getElementById(formID);
	var row = document.getElementById(rowID);
	if (form.value == 0) {
	   	error = 'This is a required field';
	   	form.style.border = '1px solid red';
		row.style.backgroundColor = '#FFFFFF';
	   	validate.style.backgroundImage = 'url(../assets/images/form_error.gif)';
		validate.innerHTML = error;
	   	return error;
	} else {
		form.style.border = '1px solid #7BC94B';
		row.style.backgroundColor = '#FFFFFF';
	   	validate.style.backgroundImage = 'url(../assets/images/form_valid.gif)';
		validate.innerHTML = '';
		return error;
	}
}

function checkTerms(formID, validateID, rowID) {
	var error="";
	var validate = document.getElementById(validateID);
	var form = document.getElementById(formID);
	var row = document.getElementById(rowID);
	row.style.backgroundColor = '#FFFFFF';
	if (form.checked == false) {
	   	error = 'Must be agreed to';
	   	form.style.border = '1px solid red';
	   	validate.style.backgroundImage = 'url(../assets/images/form_error.gif)';
		validate.innerHTML = error;
	   	return error;
	} else {
		form.style.border = '1px solid #7BC94B';
	   	validate.style.backgroundImage = 'url(../assets/images/form_valid.gif)';
		validate.innerHTML = '';
		return error;
	}
}
/* Basic validate email format function

function checkEmail(formID, validateID, rowID) {
	var error="";
	var validate = document.getElementById(validateID);
	var form = document.getElementById(formID);
	var row = document.getElementById(rowID);
	if (form.value <= 0) {
	   	error = "Please enter an email address";
	   	form.style.border = '1px solid red';
		row.style.backgroundColor = '#FFFFFF';
	   	validate.style.backgroundImage = 'url(../assets/images/form_error.gif)';
		validate.innerHTML = error;
	   	return error;
	}
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(form.value))) { 
	   	error = "Not a valid format";
	   	form.style.border = '1px solid red';
		row.style.backgroundColor = '#FFFFFF';
	   	validate.style.backgroundImage = 'url(../assets/images/form_error.gif)';
		validate.innerHTML = error;
	   	return error;
	} else {
	//test email for illegal characters
	   	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/;
		if (form.value.match(illegalChars)) {
			error = "Contains illegal characters";
			form.style.border = '1px solid red';
			row.style.backgroundColor = '#FFFFFF';
			validate.style.backgroundImage = 'url(../assets/images/form_error.gif)';
			validate.innerHTML = error;
			return error;
	   }
	}
	form.style.border = '1px solid #7BC94B';
	row.style.backgroundColor = '#FFFFFF';
	validate.style.backgroundImage = 'url(../assets/images/form_valid.gif)';
	validate.innerHTML = '';
	return error;   
}*/

//check to see if the email exists in the database function (Ajax version)
function validateEmail(formID, validateID, rowID) {	
	var error = '';								 
	document.getElementById(rowID).style.backgroundColor = '#FFFFFF';
	//remove all the class add the messagebox classes and start fading
	$('#'+validateID).removeClass().addClass('form_validate').text('Checking database...').fadeIn("slow");
	//check the username exists or not from ajax
	$.post("forms/_register/ajax_check.php",{ email:$('#'+formID).val() } ,function(data) {
		
		if(data=='blank') {
			error = 'Please enter email address';
			document.getElementById(formID).style.border = '1px solid red';
			$('#'+validateID).fadeTo(200,0.1,function() { 
				//add message and change the class of the box and start fading
				$(this).html(error).addClass('messageboxerror').fadeTo(900,1);
			});
			return error;
		} else if(data=='invalid') { //if username not available
			error = 'Email is not valid format';
			document.getElementById(formID).style.border = '1px solid red';
			$('#'+validateID).fadeTo(200,0.1,function() { 
				//add message and change the class of the box and start fading
				$(this).html(error).addClass('messageboxerror').fadeTo(900,1);  
			});
			return error;
		} else if(data=='taken') { //if username not available
			error = 'Email exists in database';
			document.getElementById(formID).style.border = '1px solid red';
			$('#'+validateID).fadeTo(200,0.1,function() { 
				//add message and change the class of the box and start fading
				$(this).html(error).addClass('messageboxerror').fadeTo(900,1);  
			});
			return error;
		} else {
			error = '';
			document.getElementById(formID).style.border = '1px solid #7BC94B';
			$('#'+validateID).fadeTo(200,0.1,function() { //start fading the messagebox
				//add message and change the class of the box and start fading
				$(this).html(error).addClass('messageboxok').fadeTo(900,1);
			});
			return error;
		}
			
	});
	return error;
}


function checkPassword(formID, validateID, rowID) {
	var error='';
	var validate = document.getElementById(validateID);
	var form = document.getElementById(formID);
	var row = document.getElementById(rowID);
	if (form.value <= 0) {
	   	error = "Please enter a password";
	   	form.style.border = '1px solid red';
		row.style.backgroundColor = '#FFFFFF';
		validate.style.backgroundImage = 'url(../assets/images/form_error.gif)';
		validate.innerHTML = error;
		return error;
	}
	
	var illegalChars = /[\W_]/; // allow only letters and numbers
	if (form.value.length < 6) {
		error = "Must be 6 or more characters";
		form.style.border = '1px solid red';
		row.style.backgroundColor = '#FFFFFF';
		validate.style.backgroundImage = 'url(../assets/images/form_error.gif)';
		validate.innerHTML = error;
		return error;
	} else if (illegalChars.test(form.value)) {
		error = "Contains illegal characters";
		form.style.border = '1px solid red';
		row.style.backgroundColor = '#FFFFFF';
		validate.style.backgroundImage = 'url(../assets/images/form_error.gif)';
		validate.innerHTML = error;
		return error;
	}
	form.style.border = '1px solid #7BC94B';
	row.style.backgroundColor = '#FFFFFF';
	validate.style.backgroundImage = 'url(../assets/images/form_valid.gif)';
	validate.innerHTML = '';
	return error;   
} 

function checkPhone(formID, validateID, rowID) {
	var error = "";
	var validate = document.getElementById(validateID);
	var form = document.getElementById(formID);
	var row = document.getElementById(rowID);
	if (form.value <= 0) {
		error = "Please enter a phone number";
		form.style.border = '1px solid red';
		row.style.backgroundColor = '#FFFFFF';
		validate.style.backgroundImage = 'url(../assets/images/form_error.gif)';
		validate.innerHTML = error;
		return error;
	}
	
	var stripped = form.value.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
		if (!(stripped.length >= 10)) {
			error = "Must be at least 10 numbers";
			form.style.border = '1px solid red';
			row.style.backgroundColor = '#FFFFFF';
			validate.style.backgroundImage = 'url(../assets/images/form_error.gif)';
			validate.innerHTML = error;
			return error;
		} 
	form.style.border = '1px solid #7BC94B';
	row.style.backgroundColor = '#FFFFFF';
	validate.style.backgroundImage = 'url(../assets/images/form_valid.gif)';
	validate.innerHTML = '';
	return error;   
}  
function checkCode(formID, validateID, rowID) {
	var error = '';
	document.getElementById(rowID).style.backgroundColor = '#FFFFFF';
			
			//remove all the class add the messagebox classes and start fading
			$('#'+validateID).removeClass().addClass('form_validate').text('Checking database...').fadeIn("slow");
			//check the username exists or not from ajax
			$.post("forms/_register/ajax_check.php",{ checkcode:$('#'+formID).val() } ,function(data) {
			  	
				if(data=='blank') {
					document.getElementById(formID).style.border = '1px solid red';
				  	$('#'+validateID).fadeTo(200,0.1,function() { 
					  	//add message and change the class of the box and start fading
					  	$(this).html('Please enter verification code').addClass('messageboxerror').fadeTo(900,1);
			  		});
				
				} else if(data=='invalid') { //if username not available
					document.getElementById(formID).style.border = '1px solid red';
					$('#'+validateID).fadeTo(200,0.1,function() { 
					  	//add message and change the class of the box and start fading
					  	$(this).html('Verification code is incorrect').addClass('messageboxerror').fadeTo(900,1);  
					});
					
			  	} else {
					document.getElementById(formID).style.border = '1px solid #7BC94B';
					$('#'+validateID).fadeTo(200,0.1,function() { //start fading the messagebox
				  		//add message and change the class of the box and start fading
				  		$(this).html('').addClass('messageboxok').fadeTo(900,1);
					});
			  	}
					
			});
			return error;
		}
		
//check to see if the email exists in the database
function checkEmail(formID, validateID, rowID) {	
			var error = '';						 
			document.getElementById(rowID).style.backgroundColor = '#FFFFFF';
			
			//remove all the class add the messagebox classes and start fading
			$('#'+validateID).removeClass().addClass('form_validate').text('Checking database...').fadeIn("slow");
			//check the username exists or not from ajax
			$.post("forms/_register/ajax_check.php",{ email:$('#'+formID).val() } ,function(data) {
			  	
				if(data=='blank') {
					error = 'Please enter email address';
					document.getElementById(formID).style.border = '1px solid red';
				  	$('#'+validateID).fadeTo(200,0.1,function() { 
					  	//add message and change the class of the box and start fading
					  	$(this).html(error).addClass('messageboxerror').fadeTo(900,1);
			  		});
				
				} else if(data=='invalid') { //if username not available
					error = 'Email is not valid format';
					document.getElementById(formID).style.border = '1px solid red';
					$('#'+validateID).fadeTo(200,0.1,function() { 
					  	//add message and change the class of the box and start fading
					  	$(this).html(error).addClass('messageboxerror').fadeTo(900,1);  
					});
					
				} else if(data=='taken') { //if username not available
					error = 'Email exists in database';
					document.getElementById(formID).style.border = '1px solid red';
					$('#'+validateID).fadeTo(200,0.1,function() { 
					  	//add message and change the class of the box and start fading
					  	$(this).html(error).addClass('messageboxerror').fadeTo(900,1);  
					});
					
			  	} else {
					error = '';
					document.getElementById(formID).style.border = '1px solid #7BC94B';
					$('#'+validateID).fadeTo(200,0.1,function() { //start fading the messagebox
				  		//add message and change the class of the box and start fading
				  		$(this).html(error).addClass('messageboxok').fadeTo(900,1);
					});
			  	}
					
			});
			return error;
		}

//check to see if the username exists in the database
function validateUsername(formID, validateID, rowID) {	
			var error = '';						 
			document.getElementById(rowID).style.backgroundColor = '#FFFFFF';
			
			//remove all the class add the messagebox classes and start fading
			$('#'+validateID).removeClass().addClass('form_validate').text('Checking database...').fadeIn("slow");
			//check the username exists or not from ajax
			$.post("forms/_register/ajax_check.php",{ username:$('#'+formID).val() } ,function(data) {
			  	
				if(data=='blank') {
					error = 'Please enter a username';
					document.getElementById(formID).style.border = '1px solid red';
				  	$('#'+validateID).fadeTo(200,0.1,function() { 
					  	//add message and change the class of the box and start fading
					  	$(this).html(error).addClass('messageboxerror').fadeTo(900,1);
			  		});
				} else if(data=='invalid') { //if username not available
					error = 'Username not a valid format';
					document.getElementById(formID).style.border = '1px solid red';
					$('#'+validateID).fadeTo(200,0.1,function() { 
					  	//add message and change the class of the box and start fading
					  	$(this).html(error).addClass('messageboxerror').fadeTo(900,1);  
					});
				} else if(data=='taken') { //if username not available
					error = 'Username exists in database';
					document.getElementById(formID).style.border = '1px solid red';
					$('#'+validateID).fadeTo(200,0.1,function() { 
					  	//add message and change the class of the box and start fading
					  	$(this).html(error).addClass('messageboxerror').fadeTo(900,1);  
					});
			  	} else {
					error = '';
					document.getElementById(formID).style.border = '1px solid #7BC94B';
					$('#'+validateID).fadeTo(200,0.1,function() { //start fading the messagebox
				  		//add message and change the class of the box and start fading
				  		$(this).html(error).addClass('messageboxok').fadeTo(900,1);
					});
			  	}	
			});
			return error;
		}