/* Author: Imran Subhani

*/


$(document).ready(function(){
	
	if($("#slider").length){
		$("#slider").easySlider({
			auto: true,
			continuous: true,
			imageControl: true,
			pause: 4000,
			numericId:'controls'
		}); 
	}
	
	$("#primary-nav ul").supersubs({ 
            minWidth:    12,   // minimum width of sub-menus in em units 
            maxWidth:    27,   // maximum width of sub-menus in em units 
            extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
        }).superfish({ 
            autoArrows:  false,                           // disable generation of arrow mark-up 
            dropShadows: false                            // disable drop shadows 
    }); 
	
	$("#CAT_Custom_207905_0").click(function() {
		
		
  		$(".discharge").show("slow");
		pause: 4000
	});

/*Have u been a bankrupt Common in all*/
	$("#CAT_Custom_207979_0 ,#CAT_Custom_210041_0").click(function() {
		
		
  		$(".discharge").show("slow");
		pause: 4000
	});

$("#CAT_Custom_210000_0").click(function() {

  		$(".discharge1").show("slow");
		
		pause: 4000
	});
$("#CAT_Custom_210000_1").click(function() {

  		$(".discharge1").hide("slow");
		
		pause: 4000
	});

$("#CAT_Custom_210041_1 ,#CAT_Custom_207979_1 ,#CAT_Custom_207905_1").click(function() {

  		$(".discharge").hide("slow");
		
		pause: 4000
	});




/*business Loan working capital*/

	$("#CAT_Custom_209492_3 ,#CAT_Custom_209492_4" ).click(function() {
		
		
  		$(".discharge").show("slow");
		pause: 4000
	});

/*Mortage Loan vehicle */

	$("#CAT_Custom_210033_0" ).click(function() {
		
		
  		$(".discharge1").show("slow");
		pause: 4000
	});


$("#CAT_Custom_210033_1" ).click(function() {
		
		
  		$(".discharge1").hide("slow");
		pause: 4000
	});
	
/*if Less than $800 / fortnight*/
	
	
	$("#CAT_Custom_210047 ,#CAT_Custom_210043 ,#CAT_Custom_210050 ,#CAT_Custom_210004 ,#CAT_Custom_207981 ,#CAT_Custom_207986 ,#CAT_Custom_207988 ,#CAT_Custom_207915 ,#CAT_Custom_207909 ,#CAT_Custom_207911 ,#CAT_Custom_210097").focus(function () {
         $(this).next(".hide").css('display','inline').fadeOut(3000);
    });
	
/*****  Calculate the LVR:
LVR = CurrentLoanValue / 
(PropertyWorth + VehicleWorth) ********/
	
	$("#CAT_Custom_210037").focusout(function(){
		
		var currentLoanValue =	$("#CAT_Custom_210030").val();
		var propertyWorth =	$("#CAT_Custom_210032").val();
		var vehicleWorth =	$("#CAT_Custom_210037").val();
		var sum = 0;
		sum += parseFloat(propertyWorth);
		sum += parseFloat(vehicleWorth);
		
		var LVR = 0;
		LVR = currentLoanValue/sum;
	
	<!--	alert("Current Loan Value = "+currentLoanValue+"   "+" Property Worth = "+propertyWorth+"   "+" Vehicle Worth = "+vehicleWorth+"    LVR ="+LVR);-->
		var opt = "";

	if(LVR < 0.65 ) {
	
		opt += "<div class='error-msg'><p>LVR should be more than 0.65</p></div>";
		$("#CAT_Custom_210037").after(opt);
		$(".error-msg").show("slow");
	}
	else if (LVR > 0.65 ){
		$(".error-msg").hide("slow");	
	}
	

	
	});

/*Home Loan Refiance */


	$("#CAT_Custom_210526_1" ).click(function() {
		
		
  		$(".discharge").show("slow");
		pause: 4000
	});


$("#CAT_Custom_210526_0" ).click(function() {
		
		
  		$(".discharge").hide("slow");
		pause: 4000
	});	
	
/*****  Calculate the LVR:
LVR = CurrentLoanValue / 
PropertyWorth ********/	
	
	$("#CAT_Custom_210086").focusout(function(){
		
		var currentLoanValue =	$("#CAT_Custom_210085").val();
		var propertyWorth =	$("#CAT_Custom_210086").val();
		
		var LVR2 = 0;
		LVR2 = currentLoanValue/propertyWorth;
		
		/*alert("Current Loan Value = "+currentLoanValue+"   "+" Property Worth = "+propertyWorth+"    LVR ="+LVR2);*/
	
	var opt = "";
	
	if(LVR2 < 0.7 ) {
	
		opt += "<div class='error-msg'><p>LVR should be more than 0.7</p></div>";
		$("#CAT_Custom_210086").after(opt);
		$(".error-msg").show("slow");
	}
	else if (LVR2 > 0.7 ){
		$(".error-msg").hide("slow");	
	}


	
	});

/***** Calculate the deposit required:
$Deposit = Home Price x 0.07********/	
	
	$("#CAT_Custom_210088").focusout(function(){
		
		var HomePrice =	$("#CAT_Custom_210088").val();
		var LVR3 = 0;
		LVR3 = HomePrice*(0.07);
		
		alert("Home Price = "+HomePrice+"    LVR ="+LVR3);

	});
	



  jQuery.fn.validateTab = function (toTab) {
	  //initialy we persume that form is valid
      var isValid = true;
	  var nextTab = toTab;	
//		console.log(toTab);
		
		//toTab = 0
		//First tab
		if(toTab == 0){
			//all fields of first fragement
			isValid = $("#CAT_Custom_210027, #CAT_Custom_210029,").valid();
			
			
			isValid = $("#CAT_Custom_210030").valid();
if(isValid == 0){
    $(".custome-error:eq(0)").html("What is your current mortgage value?");
	
	
	
isValid = $("#CAT_Custom_210032").valid();
if(isValid == 0){
    $(".custome-error:eq(1)").html("What is your property worth?");
}


	
	
	
	
	
	
	
}


			
			
		}else if(toTab == 1){
			//second tab
			var haveVehicle = $("input:radio[name=CAT_Custom_210033]:checked").val();
			//if user has vehicle == Yes
			if ( haveVehicle == "Yes" ) {
				isValid = $("#CAT_Custom_210036").valid();
				if(isValid == 0){
					$(".custome-error:eq(3)").html("Please enter Make and Model");
				}
			}
		}else if(toTab == 2){
			//third tab
			isValid = $("#CAT_Custom_210044").valid();
			if(isValid == 0){
				$(".custome-error:eq(2)").html("Please enter What do you work for?");
			}			
		}else if(toTab == 3){
			//fourth tab
		}


/*		var income = $("#income").val();
		if(income > 800){
			$("#hidden").val(income);
		}*/
		
      if (isValid) {
		//if not set toTab then set toTab to 0
		if (!toTab) {
          toTab = 0;
        }		  
		//console.log(parseInt(nextTab));
		if(toTab == 0){
			$("#tabs").tabs('enable', 1);
			$("#tabs").tabs('select', 1);
		}else if(toTab == 1){
			$("#tabs").tabs('enable', 2);
			$("#tabs").tabs('select', 2);
		}else if(toTab == 2){
			$("#tabs").tabs('enable', 3);
			$("#tabs").tabs('select', 3);
		}
      }
      return false;
    }      
    
  $(document).ready(function () {
	//create tabs
	var $tabs = $( "#tabs" ).tabs({ 
		disabled: [1, 2, 3]
	});

	//$tabs.tabs('enable', 2);
	
    $('#btnToStep2').click(function (e) {
	  //prevent default behaviour
      e.preventDefault();
      $("#fragment-1").validateTab(0);
    });
    $('#btnToStep3').click(function (e) {
	  //prevent default behaviour
      e.preventDefault();
      $("#fragment-2").validateTab(1);
    });	
    $('#btnToStep4').click(function (e) {
	  //prevent default behaviour
      e.preventDefault();
      $("#fragment-3").validateTab(2);
    });	
	


  });  















 

	
});


















