function validateContactForm()
{			
	/* declare the variables, var error is the variable that we use on the end to determine if there was an error or not */
	var error = false;
	var name = $('#name').val();
	var email = $('#email').val();
	var telephone = $('#telephone').val();
	var message = $('#message').val();
				
	/* in the next section we do the checking by using VARIABLE.length where VARIABLE is the variable we are checking (like name, email),
	length is a javascript function to get the number of characters. And as you can see if the num of characters is 0 we set the error
	variable to true and show the name_error div with the fadeIn effect. If it's not 0 then we fadeOut the div( that's if the div is shown and
	the error is fixed it fadesOut. 
	
	The only difference from these checks is the email checking, we have email.indexOf('@') which checks if there is @ in the email input field.
	This javascript function will return -1 if no occurence have been found.*/
	if(name.length == 0){
		var error = true;
		$('#name_error').fadeIn(500);
	}else{
		$('#name_error').fadeOut(500);
	}
	if(email.length == 0 || email.indexOf('@') == '-1'){
		var error = true;
		$('#email_error').fadeIn(500);
	}else{
		$('#email_error').fadeOut(500);
	}
	if(telephone.length == 0){
		var error = true;
		$('#telephone_error').fadeIn(500);
	}else{
		$('#telephone_error').fadeOut(500);
	}
	if(message.length == 0){
		var error = true;
		$('#message_error').fadeIn(500);
	}else{
		$('#message_error').fadeOut(500);
	}
				
	//now when the validation is done we check if the error variable is false (no errors)
	if(error == false){
		//disable the submit button to avoid spamming
		$('#send_message').attr({'disabled' : 'true'});
		
		return true;
	}    
	else{
		return false;
	}
	
	return false;
}

function suggestSitename()
{
	sitename = $('#agency_name').val();
	
	oldSitename = sitename.replace(/[^a-zA-Z0-9]+/g,'').toLowerCase();
	newSitename = oldSitename.substring(0,24);
	$('#instance_prefix').val(newSitename);
	
	validateSitename();
}

function validateSitename() 
{
	if($('#instance_prefix').val() != '') {
		$.ajax({
			type: "POST",
			url: "/trial/ajax_validate_sitename",
			data: "instance_prefix="+$("#instance_prefix").val(),
			beforeSend: function(){
				$('#validate_sitename_result_div').show();
				$('#validate_sitename_result_div').html('<p class="ajax-loading">Checking sitename availability.</p>')
			},	  
			success: function(html){
				$('#validate_sitename_result_div').html(html);
			}
		});
	} else {
		$('#validate_sitename_result_div').hide();
	}	
}

function validateCouponCode() 
{
	if($('#coupon_code').val() != '') {
		$.ajax({
			type: "POST",
			url: "/trial/ajax_validate_coupon_code",
			data: "coupon_code="+$("#coupon_code").val(),
			beforeSend: function(){
				$('#validate_coupon_code_result_div').show();
				$('#validate_coupon_code_result_div').html('<p class="ajax-loading">Checking code.</p>')
			},	  
			success: function(html){
				$('#validate_coupon_code_result_div').html(html);
			}
		});
	} else {
		$('#validate_coupon_code_result_div').hide();
	}
}
