// JavaScript Document

//Activate Immediately
$(document).ready(function(){
	$("#request_form").show();	
});

$(function() {		   
	$("#submit").click(function() {
									
		// validate and process form here
		var error = 'The following fields are required:\n\n';
		var invalid = 0;
		
		var title = $("input#title").val();
		if (title == "" || title == "Title") {
			error += '- Title\n';
			invalid = 1;
		}
		
		var firstname = $("input#firstname").val();
		if (firstname == "" || firstname == "First Name") {
			error += '- Full Name\n';
			invalid = 1;
		}
		
		var surname = $("input#surname").val();
		if (surname == "" || surname == "Surname") {
			var surname = "";
		}
		
		var email = $("input#txtemail").val();
		if (email == "" || email == "Email Address") {
			error += '- Email Address\n';
			invalid = 1;
		}
		
		var phone1 = $("input#phone1").val();
		if (phone1 == "" || phone1 == "Cell Number") {
			error += '- Cell Number\n';
			invalid = 1;
		}
		
		var phone2 = $("input#phone2").val();
		if (phone2 == "" || phone2 == "Alternate Number") {
			error += '- Alternate Number\n';
			invalid = 1;
		}
		
		var birthdate = $("input#birthdate").val();
		if (birthdate == "" || birthdate == "Date of Birth - DD/MM/YYYY") {
			error += '- Birth date\n';
			invalid = 1;
		}
		
		var postaladd = $("textarea#postaladd").val();
		var slanguage = $("select#language").val();
		var sage = $("select#age").val();
		var srace = $("select#race").val();
		var skinType = $("select#skinType").val();
		var skincare = $("input#skincare").val();
				
		var skinCondition = ""
		if ($("input#skinCondition1").attr('checked')) {skinCondition += ", Dehydration";}
		if ($("input#skinCondition2").attr('checked')) {skinCondition += ", Sensitivity";}
		if ($("input#skinCondition3").attr('checked')) {skinCondition += ", Ageing";}
		if ($("input#skinCondition4").attr('checked')) {skinCondition += ", Pigmentation";}
		if ($("input#skinCondition5").attr('checked')) {skinCondition += ", Congestion";}
		if ($("input#skinCondition6").attr('checked')) {skinCondition += ", Other";}
		if ($("input#txtother").val() != "") {skinCondition += ", "+$("input#txtother").val();}
/*		
		var ceilingType = "";
		if ($("input#ceilingTypeSR").attr('checked')) {ceilingType += ", Standard Rhinoboard";}
		if ($("input#ceilingTypePM").attr('checked')) {ceilingType += ", Pressed Metal";}
		if ($("input#ceilingTypeRL").attr('checked')) {ceilingType += ", RhinoLite";}
		if ($("input#ceilingTypeSG").attr('checked')) {ceilingType += ", Suspended/Gypsum";}
		if ($("input#ceilingTypeI").attr('checked')) {ceilingType += ", Industrial";}
		
		var existingInstall = ""
		if ($("input#existingInstally").attr('checked')) {existingInstall = "yes";}
		if ($("input#existingInstalln").attr('checked')) {existingInstall = "no";}
		
		var roofType = ""
		if ($("input#roofTypePT").attr('checked')) {roofType += ", Pitched Tiled";}
		if ($("input#roofTypePI").attr('checked')) {roofType += ", Pitched Tin/IBR";}
		if ($("input#roofTypeO").attr('checked')) {roofType += ", Office";}
		if ($("input#roofTypeI").attr('checked')) {roofType += ", Industrial";}
		
		var ceilingAccess = "";
		if ($("input#ceilingAccessTD").attr('checked')) {ceilingAccess += ", Trap Door";}
		if ($("input#ceilingAccessLT").attr('checked')) {ceilingAccess += ", Lift Tiles";}
*/		
		var smessage = $("textarea#message").val();
	
		if(invalid == 1){
			alert (error);
			return false;
		}
		
		$("#request_form").fadeOut("fast");
		$("#request_human").fadeIn("fast");
		window.dataString = 'do=send&title='+title+'&firstname='+firstname+'&surname='+surname+'&email='+email+'&phone1='+phone1+'&phone2='+phone2+'&birthdate='+birthdate+'&postaladd='+postaladd+'&slanguage='+slanguage+'&sage='+sage+'&srace='+srace+'&skinType='+skinType+'&skinCondition='+skinCondition+'&skincare='+skincare+'&smessage='+smessage;
		return false;  
	});
	
	$("#submit2").click(function() {
		
		var error = 'Please answer the question to submit your email.';
		var invalid = 0;
		
		var human = $("input#human").val();
		if (human != "blue" && human != "BLUE" && human != "Blue") {
			invalid = 1;
		}
		
		if(invalid == 1){
			alert (error);
			return false;
		}
		
		$("#request_loader").fadeIn('fast');
		
		//AJAX for Form Submission
		$.ajax({
		type: "POST",
		url: tempPath+"/procLoader.php",
		data: window.dataString,
		success: function() {
			$("#request_human").hide("fast");
			$("#request_loader").hide("fast");
			$("#preq_text").hide("fast");
			$("#request_thanks").fadeIn("fast");
		}
		});
		return false;
	});
	
});
