/** * 2009 Fossit Solutions LLC */$(document).ready(function(){    // page init    $(window).load(function(){        $.preloadImages("images/processing.gif"); //preload submit image        $(".inputrequired:not(.reqsilent)").after("<span class='required'>*</span>"); // mark required labels        $("#loading").hide();		$(".page").hide(); // hide all pages        $("#page1").show(); // show first page        $(".button").show(); // show tab navigation        $("#print").show(); // show printer icon        $(".bPage1").addClass("buttoncurrent"); // set current page button        $(".initcalc").trigger("change"); // trigger calculations on sample data        $(function(){            $(".inputdate").datepicker({                dateFormat: 'mm/dd/yy',				changeMonth: true,				changeYear: true,				yearRange: '-10:+30'            });        });        $("#warning").dialog({            buttons: {                "Ok": function(){                    $(this).dialog("close");                }            },            autoOpen: false,            modal: true        });        $("#error").dialog({            buttons: {                "Ok": function(){                    $(this).dialog("close");                }            },            autoOpen: false,            modal: true        });    });        // page navigation    $(".bPage1").click(function(){        $(".page").hide();        $("#page1").show();        $(".button").removeClass("buttoncurrent");        $(".bPage1").addClass("buttoncurrent");        scrollTo(0, 0);    });    $(".bPage2").click(function(){        $(".page").hide();        $("#page2").show();        $(".button").removeClass("buttoncurrent");        $(".bPage2").addClass("buttoncurrent");        scrollTo(0, 0);    });    $(".bPage3").click(function(){        $(".page").hide();        $("#page3").show();        $(".button").removeClass("buttoncurrent");        $(".bPage3").addClass("buttoncurrent");        scrollTo(0, 0);    });    $(".bPage4").click(function(){        $(".page").hide();        $("#page4").show();        $(".button").removeClass("buttoncurrent");        $(".bPage4").addClass("buttoncurrent");        scrollTo(0, 0);    });    $("#bPage1Next").click(function(){        $(".page").hide();        $("#page2").show();        $(".button").removeClass("buttoncurrent");        $(".bPage2").addClass("buttoncurrent");        scrollTo(0, 0);    });    $("#bPage2Prev").click(function(){        $(".page").hide();        $("#page1").show();        $(".button").removeClass("buttoncurrent");        $(".bPage1").addClass("buttoncurrent");        scrollTo(0, 0);    });    $("#bPage2Next").click(function(){        $(".page").hide();        $("#page3").show();        $(".button").removeClass("buttoncurrent");        $(".bPage3").addClass("buttoncurrent");        scrollTo(0, 0);    });    $("#bPage3Prev").click(function(){        $(".page").hide();        $("#page2").show();        $(".button").removeClass("buttoncurrent");        $(".bPage2").addClass("buttoncurrent");        scrollTo(0, 0);    });    $("#bPage3Next").click(function(){        $(".page").hide();        $("#page4").show();        $(".button").removeClass("buttoncurrent");        $(".bPage4").addClass("buttoncurrent");        scrollTo(0, 0);    });    $("#bPage4Prev").click(function(){        $(".page").hide();        $("#page3").show();        $(".button").removeClass("buttoncurrent");        $(".bPage3").addClass("buttoncurrent");        scrollTo(0, 0);    });		// live calculations	// page 2	$("#inp_table1 input").change(function(){		$("#totalNumUnits").html(parseInt($(".calcnumunits").sum()));        var netRent = 0;        if ($(".calcnumunits1").val() != '' && $(".calcnetrent1").val() != '')             netRent = netRent + parseInt(parseInt($(".calcnumunits1").val()) * parseInt($(".calcnetrent1").val()));        if ($(".calcnumunits2").val() != '' && $(".calcnetrent2").val() != '')             netRent = netRent + parseInt(parseInt($(".calcnumunits2").val()) * parseInt($(".calcnetrent2").val()));        if ($(".calcnumunits3").val() != '' && $(".calcnetrent3").val() != '')             netRent = netRent + parseInt(parseInt($(".calcnumunits3").val()) * parseInt($(".calcnetrent3").val()));        if ($(".calcnumunits4").val() != '' && $(".calcnetrent4").val() != '')             netRent = netRent + parseInt(parseInt($(".calcnumunits4").val()) * parseInt($(".calcnetrent4").val()));        if ($(".calcnumunits5").val() != '' && $(".calcnetrent5").val() != '')             netRent = netRent + parseInt(parseInt($(".calcnumunits5").val()) * parseInt($(".calcnetrent5").val()));        if ($(".calcnumunits6").val() != '' && $(".calcnetrent6").val() != '')             netRent = netRent + parseInt(parseInt($(".calcnumunits6").val()) * parseInt($(".calcnetrent6").val()));        if ($(".calcnumunits7").val() != '' && $(".calcnetrent7").val() != '')             netRent = netRent + parseInt(parseInt($(".calcnumunits7").val()) * parseInt($(".calcnetrent7").val()));        if ($(".calcnumunits8").val() != '' && $(".calcnetrent8").val() != '')             netRent = netRent + parseInt(parseInt($(".calcnumunits8").val()) * parseInt($(".calcnetrent8").val()));        if ($(".calcnumunits9").val() != '' && $(".calcnetrent9").val() != '')             netRent = netRent + parseInt(parseInt($(".calcnumunits9").val()) * parseInt($(".calcnetrent9").val()));        if ($(".calcnumunits10").val() != '' && $(".calcnetrent10").val() != '')             netRent = netRent + parseInt(parseInt($(".calcnumunits10").val()) * parseInt($(".calcnetrent10").val()));        if ($(".calcnumunits11").val() != '' && $(".calcnetrent11").val() != '')             netRent = netRent + parseInt(parseInt($(".calcnumunits11").val()) * parseInt($(".calcnetrent11").val()));        if ($(".calcnumunits12").val() != '' && $(".calcnetrent12").val() != '')             netRent = netRent + parseInt(parseInt($(".calcnumunits12").val()) * parseInt($(".calcnetrent12").val()));        if ($(".calcnumunits13").val() != '' && $(".calcnetrent13").val() != '')             netRent = netRent + parseInt(parseInt($(".calcnumunits13").val()) * parseInt($(".calcnetrent13").val()));        if ($(".calcnumunits14").val() != '' && $(".calcnetrent14").val() != '')             netRent = netRent + parseInt(parseInt($(".calcnumunits14").val()) * parseInt($(".calcnetrent14").val()));        if ($(".calcnumunits15").val() != '' && $(".calcnetrent15").val() != '')             netRent = netRent + parseInt(parseInt($(".calcnumunits15").val()) * parseInt($(".calcnetrent15").val()));        if ($(".calcnumunits16").val() != '' && $(".calcnetrent16").val() != '')             netRent = netRent + parseInt(parseInt($(".calcnumunits16").val()) * parseInt($(".calcnetrent16").val()));        if ($(".calcnumunits17").val() != '' && $(".calcnetrent17").val() != '')             netRent = netRent + parseInt(parseInt($(".calcnumunits17").val()) * parseInt($(".calcnetrent17").val()));        $("#totalNetRent").html(netRent);	}); 	$(".calcopexp").change(function(){		$("#calc_d32").html(parseInt($("#inp_d32").val() / $("#totalNumUnits").html()));		$("#calc_d33").html(parseInt($("#inp_d33").val() / $("#totalNumUnits").html()));		$("#calc_d35").html(parseInt($("#inp_d35").val() / $("#totalNumUnits").html()));		$("#calc_d36").html(parseInt($("#inp_d36").val() / $("#totalNumUnits").html()));		$("#calc_d37").html(parseInt($("#inp_d37").val() / $("#totalNumUnits").html()));		$("#calc_d38").html(parseInt($("#inp_d38").val() / $("#totalNumUnits").html()));		$("#calc_d40").html(parseInt($("#inp_d40").val() / $("#totalNumUnits").html()));		$("#calc_d41").html(parseInt($("#inp_d41").val() / $("#totalNumUnits").html()));		$("#calc_d42").html(parseInt($("#inp_d42").val() / $("#totalNumUnits").html()));		$("#calc_d43").html(parseInt($("#inp_d43").val() / $("#totalNumUnits").html()));		$("#calc_d45").html(parseInt($("#inp_d45").val() / $("#totalNumUnits").html()));		$("#calc_d46").html(parseInt($("#inp_d46").val() / $("#totalNumUnits").html()));		$("#calc_d47").html(parseInt($("#inp_d47").val() / $("#totalNumUnits").html()));		$("#calc_d48").html(parseInt($("#inp_d48").val() / $("#totalNumUnits").html()));		$("#calc_d49").html(parseInt($("#inp_d49").val() / $("#totalNumUnits").html()));		$("#calc_d50").html(parseInt($("#inp_d50").val() / $("#totalNumUnits").html()));		$("#calc_d51").html(parseInt($("#inp_d51").val() / $("#totalNumUnits").html()));		$("#calc_d52").html(parseInt($("#inp_d52").val() / $("#totalNumUnits").html()));		$("#calc_d53").html(parseInt($("#inp_d53").val() / $("#totalNumUnits").html()));		$("#calc_d54").html(parseInt($("#inp_d54").val() / $("#totalNumUnits").html()));		$("#calc_d55").html(parseInt($("#inp_d55").val() / $("#totalNumUnits").html()));		$("#calc_d56").html(parseInt($("#inp_d56").val() / $("#totalNumUnits").html()));		$("#calc_d57").html(parseInt($("#inp_d57").val() / $("#totalNumUnits").html()));		$("#calc_d58").html(parseInt($("#inp_d58").val() / $("#totalNumUnits").html()));		$("#calc_d60").html(parseInt($("#inp_d60").val() / $("#totalNumUnits").html()));		$("#calc_d61").html(parseInt($("#inp_d61").val() / $("#totalNumUnits").html()));		$("#calc_d63").html(parseInt($("#inp_d63").val() / $("#totalNumUnits").html()));		$("#calc_d64").html(parseInt($("#inp_d64").val() / $("#totalNumUnits").html()));	});	$(".calcopexp").change(function(){		$("#totalOpExp").html(parseInt($(".calcopexp").sum()));	});	$(".calcopexp").change(function(){		if (parseInt($("#totalNumUnits")) != 0) {			var totalPerUnit = parseInt(parseInt($("#totalOpExp").html()) / parseInt($("#totalNumUnits").html()));			$("#totalOpExpUnit").html(totalPerUnit);		}	});	$(".subcalcprof").change(function(){		$("#totalSubCalcProf").html(parseInt($(".subcalcprof").sum()));	});	$(".subcalcadmin").change(function(){		$("#totalSubCalcAdmin").html(parseInt($(".subcalcadmin").sum()));	});	$(".subcalcutil").change(function(){		$("#totalSubCalcUtil").html(parseInt($(".subcalcutil").sum()));	});	$(".subcalcrep").change(function(){		$("#totalSubCalcRep").html(parseInt($(".subcalcrep").sum()));	});	$(".subcalcother").change(function(){		$("#totalSubCalcOther").html(parseInt($(".subcalcother").sum()));	});	// page 3	$(".calcsourceoffunds").change(function(){		$("#totalSourceOfFunds").html(parseInt($(".calcsourceoffunds").sum()));	});	$(".calcappoffunds").change(function(){		$("#totalAppOfFunds").html(parseInt($(".calcappoffunds").sum()));	});	$(".calcappoffunds,.calcsourceoffunds").change(function(){		$("#calcFinancingGap").html(parseInt($("#totalSourceOfFunds").html()) - parseInt($("#totalAppOfFunds").html()));		if (parseInt($("#calcFinancingGap").html()) >= 0) {			$("#calcFinancingGap").removeClass("turnred");		} else {			$("#calcFinancingGap").addClass("turnred");		}	});    $(".subcalcacqcosts").change(function(){		$("#totalAcqCosts").html(parseInt($(".subcalcacqcosts").sum()));	});    $(".subcalcconstcosts").change(function(){		$("#totalConstCosts").html(parseInt($(".subcalcconstcosts").sum()));	});    $(".subcalcproffees").change(function(){		$("#totalProfFees").html(parseInt($(".subcalcproffees").sum()));	});    $(".subcalcfincosts").change(function(){		$("#totalFinCosts").html(parseInt($(".subcalcfincosts").sum()));	});    $(".subcalctaxcred").change(function(){		$("#totalTaxCred").html(parseInt($(".subcalctaxcred").sum()));	});    $(".subcalcstartup").change(function(){		$("#totalStartUp").html(parseInt($(".subcalcstartup").sum()));	});	// page 4	$(".calcnumofunits").change(function(){		$("#totalNumOfUnits").html(parseInt($(".calcnumofunits").sum()));	});	// Add year lables to First, Second and Third years on Completion Lease Up Schedule page	$("#inp_l43").change(function(){		var startDate = new Date($("#inp_l43").val());		$("#firstyear").html(startDate.getFullYear());		$("#secondyear").html(parseInt(startDate.getFullYear())+1);		$("#thirdyear").html(parseInt(startDate.getFullYear())+2);	});	    // validate character input    $(".inputchar").blur(function(){        //charregex = /^([a-zA-Z0-9\s\.\-\_\%\,\&\/\+]+)$/;        charregex = /^([a-zA-Z0-9\s\!\@\#\$\%\^\&\*\(\)\_\-\+\=\|\]\}\{\[\:\;\"\'\<\,\>\.\?\/]+)$/;        if (charregex.test(this.value) == true || this.value == '') {            $(this).removeClass("inputerror");        }        else {            $(this).addClass("inputerror");        }    });        // validate integer input    $(".inputint").blur(function(){        if (parseInt(this.value) == this.value - 0 || this.value == '') {            $(this).removeClass("inputerror");        }        else {            $(this).addClass("inputerror");        }    });        // validate float input    $(".inputfloat").blur(function(){		floatregex = /^[-+]?[0-9]+(\.[0-9]+)?$/;        if (floatregex.test(this.value) == true || this.value == '') {            $(this).removeClass("inputerror");        }		else {            $(this).addClass("inputerror");        }    });        // validate email address    $(".inputemail").blur(function(){        emailregex = /^.+@[^\.].*\.[a-z]{2,}$/;        if (emailregex.test(this.value) == true || this.value == '') {            $(this).removeClass("inputerror");        }        else {            $(this).addClass("inputerror");        }    });        // validate phone number    $(".inputphone").blur(function(){		phoneregex = /^(\(?\d\d\d\)?)?( |-|\.)?\d\d\d( |-|\.)?\d{4,4}(( |-|\.)?[eExXtT\.]+ ?\d+)?$/;        if (phoneregex.test(this.value) == true || this.value == '') {            $(this).removeClass("inputerror");        }        else {            $(this).addClass("inputerror");        }    });        // validate date    $(".inputdate").change(function(){        dateregex = /(?=\d)^(?:(?!(?:10\D(?:0?[5-9]|1[0-4])\D(?:1582))|(?:0?9\D(?:0?[3-9]|1[0-3])\D(?:1752)))((?:0?[13578]|1[02])|(?:0?[469]|11)(?!\/31)(?!-31)(?!\.31)|(?:0?2(?=.?(?:(?:29.(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:(?:\d\d)(?:[02468][048]|[13579][26])(?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20BC))))))|(?:0?2(?=.(?:(?:\d\D)|(?:[01]\d)|(?:2[0-8])))))([-.\/])(0?[1-9]|[12]\d|3[01])\2(?!0000)((?=(?:00(?:4[0-5]|[0-3]?\d)\x20BC)|(?:\d{4}(?!\x20BC)))\d{4}(?:\x20BC)?)(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$/;        if (dateregex.test(this.value) == true || this.value == '') {            $(this).removeClass("inputerror");        }        else {            $(this).addClass("inputerror");        }    });        // validate year    $(".inputyear").blur(function(){        if ((parseInt(this.value) >= 1970 && parseInt(this.value) <= 2099) || (this.value == '')) {            $(this).removeClass("inputerror");        }        else {            $(this).addClass("inputerror");        }    });		// validate text area	$(".inputtext").blur(function(){		charregex = /^([a-zA-Z0-9\s\!\@\#\$\%\^\&\*\(\)\_\-\+\=\|\]\}\{\[\:\;\"\'\<\,\>\.\?\/]+)$/;		var maxwords = 120;		var words = $(".inputtext").val().split(/\s/);		if ((charregex.test(this.value) == true && words.length <= maxwords) || this.value == '') {			$(this).removeClass("inputerror");		} else {			$(this).addClass("inputerror");		}	});		// validate required checkbox	$(".inputreqcheckbox").blur(function(){		if ($(".inputreqcheckbox:checked").val() == null ) {			$("#inp_k54").addClass("inputerror");		} else {			$("#inp_k54").removeClass("inputerror");		}	});		// validate required checkbox	$(".inputreqcheckbox2").blur(function(){		if ($(".inputreqcheckbox2:checked").val() == null ) {			$("#inp_k55").addClass("inputerror");		} else {			$("#inp_k55").removeClass("inputerror");		}	});		// validate required fields	$(".inputrequired").error(function(){		if (this.value == '') {			$(this).addClass("inputerror");        }	});        // update project name for all instances    $(".projectname").change(function(){        $(".projectname").val($(this).val());    });        // validate required fields, count total errors and submit if no errors    $("#submit").click(function(){        $("input").trigger("blur");		$(".inputrequired").trigger("error");		        /*$("#validation_errors").html(parseInt($(".inputerror").size())); //debug code*/						if (parseInt($("#page1 .inputerror").size()) > 0) {            $(".bPage1").addClass("buttonerror");        }        else {            $(".bPage1").removeClass("buttonerror");        }        if (parseInt($("#page2 .inputerror").size()) > 0) {            $(".bPage2").addClass("buttonerror");        }        else {            $(".bPage2").removeClass("buttonerror");        }        if (parseInt($("#page3 .inputerror").size()) > 0) {            $(".bPage3").addClass("buttonerror");        }        else {            $(".bPage3").removeClass("buttonerror");        }        if (parseInt($("#page4 .inputerror").size()) > 0) {            $(".bPage4").addClass("buttonerror");        }        else {            $(".bPage4").removeClass("buttonerror");        }                if (parseInt($(".inputerror").size()) == 0) {            $("#submit").hide();            $("#processing").show();            var formdata = $("form").serialize();            $.post("includes/process.php", formdata, function(data){                $("#debug").html(data);                if (data == "success") {                    $(".page").hide();                    $(".note").hide();                    $(".button").hide();                    $("#processing").hide();                    $("#success").show();                }                else {                    $("#error").dialog('open');                    $("#processing").hide();                    $("#submit").show();                }            });        }        else {            $("#warning").dialog('open');        }    });	// Print Button	$("#print").click(function(){		$("#header,#nav,#footer").hide();		$("body").css({'background' : '#fff 0 0 repeat'});		$("#container").css({'background' : '#fff 0 0 repeat'});		window.print();		$("#container").css({'background' : '#fff url(../images/container-bg.gif) 0 0 repeat'});		$("body").css({'background' : '#fff url(../images/body-bg.gif) 0 0 repeat'});		$("#header,#nav,#footer").show();			});    /*$("#testfill").click(function(){        $("input.inputchar").val("test");        $("input.inputint").val("5");        $("input.inputfloat").val("5.5");        $("input.inputdate").val("01/01/2009");        $("input.inputphone").val("123-123-1234");        $("input.inputemail").val("andy@fossitsolutions.com");        $("input.inputyear").val("2009");        $("textarea.inputchar").val("This is some test text.");    });*/});