// --------------- capture user details --------------- //

function add_user_details() {
	
	$("#result").html("");
	document.getElementById('result').style.display = 'none';
	
	var name = $("input#user_name").val();
	var email = $("input#user_email").val();
	var age = $("input[name='age']:checked").val();
	var temp_terms = $('#terms').attr('checked');
	
	if(temp_terms == true) {
		var terms = "1";
	} else {
		var terms = "0";
	}
	
	if (name == "") {
		$("input#user_name").val("");
		$("input#user_name").focus();
		alert("Please enter your name");
		return false;
	}
	
	if (email == "") {
		$("input#user_email").val("");
		$("input#user_email").focus();
		alert("Please enter an email address");
		return false;
	}
	
	if(age == null) {
		alert("Please specify your age");
		return false;
	} else {
	
		if(age == 0) {
			var final_age = "over 12";
		} else {
			var final_age = "under 12";
		}
	
	}
	
	if (terms == 0) {
		alert("You must agree to our terms and conditions");
		return false;
	}
	
	var dataString = 'name=' + name + '&email=' + email + '&age=' + final_age;
		
	$.ajax({
  		type: "POST",
 		url: "scripts/register_user.php",
 		data: dataString,
 		dataType: 'html',
  		success: function(html) {
    		$("#result").append(html);
    		setTimeout("show_loading()", 500);
  		}
 
 	});
 	
}

function show_loading() {
	$("#loading").slideDown('fast');
	setTimeout("hide_loading()", 2000);	
}

function hide_loading() {
	document.getElementById('loading').style.display = 'none';
	$("#result").fadeIn('fast');
	//setTimeout("reload_form()", 5000);	
}

function reload_form() {
	document.getElementById('result').style.display = 'none';
	$("#display").fadeIn('fast');
}



function post_message() {
	
	var name = $("input#name").val();
	var email = $("input#email").val();
	var message = $("#message").val();
		
	if (name == "") {
		$("input#name").val("");
		$("input#name").focus();
		alert("Please enter your name");
		return false;
	}
	
	if (email == "") {
		$("input#email").val("");
		$("input#email").focus();
		alert("Please enter an email address");
		return false;
	}
	
	if (message == "") {
		$("input#message").val("");
		$("input#message").focus();
		alert("Please enter a message for Cathy");
		return false;
	}
		
	var dataString = 'name=' + name + '&email=' + email + '&message=' + message;
		
	$.ajax({
  		type: "POST",
 		url: "scripts/mailform.php",
 		data: dataString,
 		dataType: 'html',
  		success: function(html) {
    		$("#inner").fadeOut('fast');
    		$("#contact_result").append(html);
    		setTimeout("contact_loading()", 500);
  		}
 
 	});

}

function contact_loading() {
	$("#contact_load").fadeIn("fast");
	setTimeout("contact_loading_hide()", 1000);	
}

function contact_loading_hide() {
	document.getElementById('contact_load').style.display = "none";
	$("#contact_result").fadeIn('fast');
}

