image3 = new Image();
image3.src = "images/headerback.gif";

image3 = new Image();
image3.src = "images/back.gif";

image4 = new Image();
image4.src = "images/innertop.gif";

image5 = new Image();
image5.src = "images/innerbot.gif";

image1 = new Image();
image1.src = "images/button.gif";

image2 = new Image();
image2.src = "images/button_over.gif";

monthlyincome="00.00";
partnersincome="00.00";
otherincome="00.00";
mortgagerent="00.00";
bills="00.00";
loans="00.00";
creditcard="00.00";
otherexpenses="00.00";

$(document).ready(

function () {

	$("input.totalincome").attr("disabled", "disabled");

	$("input.totalexpenditure").attr("disabled", "disabled");

	$("select.timeataddressyr").change( function(){

		if(this.value=='1yr' || this.value=='2yr'){

			$("textarea.previousaddress").removeAttr("disabled");
			$("input.previouspostcode").removeAttr("disabled");
			$("select.timeatpreviousaddress").removeAttr("disabled");

		}
		else{

			$("textarea.previousaddress").attr("disabled", "disabled");
			$("input.previouspostcode").attr("disabled", "disabled");
			$("select.timeatpreviousaddress").attr("disabled", "disabled");

		}

	});

	$("select.timewithemployeryr").change( function(){

		if(this.value=='1yr' || this.value=='2yr'){

			$("input.previousemployer").removeAttr("disabled");
			$("textarea.previousemployersaddress").removeAttr("disabled");
			$("input.previousemployerspostcode").removeAttr("disabled");

		}
		else{

			$("input.previousemployer").attr("disabled", "disabled");
			$("textarea.previousemployersaddress").attr("disabled", "disabled");
			$("input.previousemployerspostcode").attr("disabled", "disabled");

		}

	});

	$("select.btype").change( function(){


		if(this.value!='Limited Company'){

			$("input.regno").attr("disabled", "disabled");

		}
		else{

			$("input.regno").removeAttr("disabled");

		}

	});
	
	
		$("input.noofowners").change( function(){
			
			if(this.value=="1"){
			 
			 $("#owner3, #owner4, #owner5, #owner6").addClass("display");
				
			}
			
			
			if(this.value=="2"){
			 
			 $("#owner3, #owner4, #owner5, #owner6").addClass("display");
				
			}
			
			if(this.value=="3"){
				
			 $("#owner3").removeClass("display");
			 
			 $("#owner4, #owner5, #owner6").addClass("display");
				
			}
		   if(this.value=="4"){
				
			 $("#owner3").removeClass("display");
			 $("#owner4").removeClass("display");
			 
			 $("#owner5, #owner6").addClass("display");
				
			}
			if(this.value=="5"){
				
			 $("#owner3").removeClass("display");
			 $("#owner4").removeClass("display");
			 $("#owner5").removeClass("display");
			 
			 $("#owner6").addClass("display");
				
			}
			if(this.value=="6"){
				
			 $("#owner3").removeClass("display");
			 $("#owner4").removeClass("display");
			 $("#owner5").removeClass("display");
			 $("#owner6").removeClass("display");
				
			}
			if(this.value<2){

			$("input.title2").attr("disabled", "disabled");
			$("input.firstname2").attr("disabled", "disabled");
			$("input.surname2").attr("disabled", "disabled");
			$("input.dob2").attr("disabled", "disabled");
			$("textarea.address2").attr("disabled", "disabled");
			$("input.postcode2").attr("disabled", "disabled");
			$("select.residentialstatus2").attr("disabled", "disabled");
			$("select.timeataddress2yr").attr("disabled", "disabled");
			$("select.timeataddress2mth").attr("disabled", "disabled");
			$("select.maritalstatus").attr("disabled", "disabled");

		}
		else{

			$("input.title2").removeAttr("disabled");
			$("input.firstname2").removeAttr("disabled");
			$("input.surname2").removeAttr("disabled");
			$("input.dob2").removeAttr("disabled");
			$("textarea.address2").removeAttr("disabled");
			$("input.postcode2").removeAttr("disabled");
			$("select.residentialstatus2").removeAttr("disabled");
			$("select.timeataddress2yr").removeAttr("disabled");
			$("select.timeataddress2mth").removeAttr("disabled");
			$("select.maritalstatus").removeAttr("disabled");
		}

	});
	
	$("input").click(function(){

		if(this.value=='00.00' || this.value=='DDMMYYYY')

		{

			this.value='' //emptys input box when clicked

		}

	});

	$("input.monthlyincome").change( function(){

		monthlyincome = this.value;
		totalincome();

	});

	$("input.partnersincome").change( function(){

		partnersincome = this.value;
		totalincome();
	});

	$("input.otherincome").change( function(){

		otherincome = this.value;
		totalincome();
	});

	$("input.mortgagerent").change( function(){

		mortgagerent = this.value;
		totalexpenditure();
	});

	$("input.bills").change( function(){

		bills = this.value;
		totalexpenditure();
	});

	$("input.creditcard").change( function(){

		creditcard = this.value;
		totalexpenditure();
	});

	$("input.otherexpenses").change( function(){

		otherexpenses = this.value;
		totalexpenditure();
	});

	$("input.loans").change( function(){

		loans = this.value;
		totalexpenditure();
	});

	$(".popup a").hover(function() {
		$(this).next("em").animate({opacity: "show", top: "-10"}, "slow");
	}, function() {
		$(this).next("em").animate({opacity: "hide", top: "-20"}, "fast");
	});

	$("input.num").change( function(){

		checkerrors();

	});

	function checkerrors(){

		var inputtext = $("input.num").serialize(); //stores submited form information


		$.ajax({
			type: "POST",
			url: "formerrors.php",
			data: inputtext,
			success: function(msg){

				if(msg==''){

				}
				else{

					alert(msg);

				}
			}
		});

	};

	function totalincome()
	{

		totalincome2 = Number(monthlyincome)+Number(partnersincome)+Number(otherincome);

		$("input.totalincome").val(totalincome2);

	};

	function totalexpenditure()
	{

		totalexpenditure2 = Number(mortgagerent)+Number(bills)+Number(creditcard)+Number(loans)+Number(otherexpenses);

		$("input.totalexpenditure").val(totalexpenditure2);

	};

});