$(document).ready(function() {
	$(".inputField").bind("click", function(){
		if(this.id == $(this).val()) $(this).val("");
	});
	
	$(".inputField").bind("blur", function(){
		if($(this).val() == "") $(this).val(this.id);
	});	

	$("#commBut").bind("click", function(){
		$(".developmentsSearch").hide();
		$.ajax({
			type: "POST",
			url: "commercial.php",
			success: function(html){
				$("#developments").empty();
				$("#developments").append(html);
				$("#developments").fadeIn();
			}
		});
	});
	
	$("#resBut").bind("click", function(){
		$(".developmentsSearch").hide();
		$.ajax({
			type: "POST",
			url: "residential.php",
			success: function(html){
				$("#developments").empty();
				$("#developments").append(html);
				$("#developments").fadeIn();
			}
		});
	});
	
	$("#requestBrochure,#requestBrochure2").bind("click", function(){
		$("#requestBrochureForm").css("display", "block");
		$("#submitBrochure").bind("click", function(){
			var error1 = false;
			var error2 = false;
			var error3 = false;
			var error4 = false;
			var error5 = false;
			var error6 = false;
			var error7 = false;
			var error8 = false;
			
			if ($("input[name=name]").val() == ""){
				error1 = false;
				$("#error1").slideDown("slow");
			}else{
				error1 = true;
				$("#error1").slideUp("slow");
			}
			
			
			if (!checkEmailAddress($("input[name=email]").val()) || $("input[name=email]").val() == ""){
				error2 = false;
				$("#error2").slideDown("slow");
			}else{
				error2 = true;
				$("#error2").slideUp("slow");
			}
			
			if ($("textarea[name=comments]").val() == ""){
				error3 = false;
				$("#error3").slideDown("slow");
			}else{
				error3 = true;
				$("#error3").slideUp("slow");
			}
			
			if ($("input[name=phone]").val() == ""){
				error4 = false;
				$("#error4").slideDown("slow");
			}else{
				error4 = true;
				$("#error4").slideUp("slow");
			}
			
			if ($("input[name=address_1]").val() == ""){
				error5 = false;
				$("#error5").slideDown("slow");
			}else{
				error5 = true;
				$("#error5").slideUp("slow");
			}
			
			if ($("input[name=town]").val() == ""){
				error6 = false;
				$("#error6").slideDown("slow");
			}else{
				error6 = true;
				$("#error6").slideUp("slow");
			}
			
			if ($("input[name=county]").val() == ""){
				error7 = false;
				$("#error7").slideDown("slow");
			}else{
				error7 = true;
				$("#error7").slideUp("slow");
			}
			
			if ($("input[name=postcode]").val() == ""){
				error8 = false;
				$("#error8").slideDown("slow");
			}else{
				error8 = true;
				$("#error8").slideUp("slow");
			}
			
			if (error1 && error2 && error3 && error4 && error5 && error6 && error7 && error8){
				document.brochureForm.submit();
			}
		});
		sIFR.replace(avenir_light, {
			selector: '.buttonOrangeMiddle',
			wmode: 'transparent',
			css: ['.sIFR-root { font-size: 14px; color: #FFFFFF; text-align: center;cursor:pointer;cursor:hand; float: left;}'
				,'a { color: #FFFFFF; text-decoration: none; text-transform: uppercase; cursor:pointer;cursor:hand;}'
				,'a:link { color: #FFFFFF; text-decoration: none; text-transform: uppercase; cursor:pointer;cursor:hand;}'
				,'a:hover { color: #FFFFFF; text-decoration: none; text-transform: uppercase; cursor:pointer;cursor:hand;}'
				,'a:visited { color: #FFFFFF; text-decoration: none; text-transform: uppercase; cursor:pointer;cursor:hand;}']
		});
		sIFR.replace(baskoldface, {
			selector: '.headingBigOrange',
			wmode: 'transparent',
			css: ['.sIFR-root { font-size: 35px;color: #FF3401;text-align:left;cursor:pointer;cursor:hand;float: left;}'
				,'a { color: #FF3401; text-decoration: none; cursor:pointer;cursor:hand;}'
				,'a:link { color: #FF3401; text-decoration: none; cursor:pointer;cursor:hand;}'
				,'a:hover { color: #FF3401; text-decoration: none; cursor:pointer;cursor:hand;}'
				,'a:visited { color: #FF3401; text-decoration: none; cursor:pointer;cursor:hand;}']
		});
		sIFR.replace(baskoldface, {
			selector: '.headingOrangeSmall1',
			wmode: 'transparent',
			css: ['.sIFR-root { font-size: 15px; color: #FF3401; text-align: left;cursor:pointer;cursor:hand; float: left;}'
				,'a { color: #FF3401; text-decoration: none; text-transform: uppercase; cursor:pointer;cursor:hand;}'
				,'a:link { color: #FF3401; text-decoration: none; text-transform: uppercase; cursor:pointer;cursor:hand;}'
				,'a:hover { color: #FF3401; text-decoration: none; text-transform: uppercase; cursor:pointer;cursor:hand;}'
				,'a:visited { color: #FF3401; text-decoration: none; text-transform: uppercase; cursor:pointer;cursor:hand;}']
		});
	}); 
	
	$("#submitContacts").bind("click", function(){
		var error1 = false;
		var error2 = false;
		var error3 = false;
		
		if ($("input[name=name]").val() == ""){
			error1 = false;
			$("#error1").slideDown("slow");
		}else{
			error1 = true;
			$("#error1").slideUp("slow");
		}
		
		if (!checkEmailAddress($("input[name=email]").val()) || $("input[name=email]").val() == ""){
			error2 = false;
			$("#error2").slideDown("slow");
		}else{
			error2 = true;
			$("#error2").slideUp("slow");
		}
		
		if ($("textarea[name=comments]").val() == ""){
			error3 = false;
			$("#error3").slideDown("slow");
		}else{
			error3 = true;
			$("#error3").slideUp("slow");
		}
		
		if (error1 && error2 && error3){
			document.contactsForm.submit();
		}
	}); 
	
});

function checkEmailAddress(email){
	var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])*([a-zA-Z])/;
	 if(pattern.test(email)){         
		return true;
    }else{   
		return false;
    }
}
