function changeDIV(DivName,DivMenu){
	
	for(i=1;i<=4;i++){
		$("menu-"+i+"-1").className = "kai-mana-curr-l1 kai-mana-curr-l-no1";
		$("menu-"+i+"-2").className = "kai-mana-curr-repeat1 kai-mana-curr-repeat-no1";
		$("menu-"+i+"-3").className = "kai-mana-curr-l1 kai-mana-curr-r1 kai-mana-curr-r-no1";
		$("trTools"+i).style.display="none";
	}
	
	$(DivMenu + "-1").className = "kai-mana-curr-l1";
	$(DivMenu + "-2").className = "kai-mana-curr-repeat1";
	$(DivMenu + "-3").className = "kai-mana-curr-l1 kai-mana-curr-r1";
	
	$(DivName).style.display="";
}

function CalcLoan(){
	setLoadingNow();
	var LoanType="";

	if($("SameGiveLoan").checked){
		LoanType = "1";
	}
	if($("SameMoneyLoan").checked){
		LoanType = "2";
	}
	if(LoanType==""){
		alert("还款方式为空，请选择");
		return;
	}

	intBussnessLoan = $("BussnessLoan").value;
	if(intBussnessLoan==""){
		intBussnessLoan = 0;
	}
	
	intProvidentFundLoan = $("ProvidentFundLoan").value;
	if(intProvidentFundLoan==""){
		intProvidentFundLoan = 0;
	}
	intLoanYears = $("LoanYears").value;
	intInterestRates = $("InterestRates").value;
	strURL="../Tool/CalcLoanInfo.php?id=" + Math.random();
	strData  = "loanType=" + encodeURIComponent(LoanType);
	strData  += "&bussnessLoan=" + encodeURIComponent(intBussnessLoan);
	strData  += "&providentFundLoan=" + encodeURIComponent(intProvidentFundLoan);
	strData  += "&loanYears=" + encodeURIComponent(intLoanYears);
	strData  += "&interestRates=" + encodeURIComponent(intInterestRates);
	new Ajax.Request(strURL, {method: 'post', parameters: strData, onComplete: CalcLoanReceive});
}

function CalcLoanReceive(httpObj){
	
	text = httpObj.responseText;
	text = getConvForSafari(text);
	//alert(text);
	t = text.parseJSON();
	
	workMonthList=$("tabLoanInfoEveryMonth");
	WorkCount = workMonthList.getElementsByTagName("tr").length;
	//alert(WorkCount);
	for(i=0;i<WorkCount;i++){
		workMonthList.deleteRow(0);
	}
	
	/**workList=$("tabLoanInfo");
	WorkCount = workList.getElementsByTagName("tr").length;
	for(i=0;i<WorkCount;i++){
		workList.deleteRow(0);
	}*/
	
	intLoanYears = $("LoanYears").value;
	intBussnessLoan = $("BussnessLoan").value;
	if(intBussnessLoan==""){
		intBussnessLoan = 0;
	}
	
	intProvidentFundLoan = $("ProvidentFundLoan").value;
	if(intProvidentFundLoan==""){
		intProvidentFundLoan = 0;
	}
	
	/**var _tr=workList.insertRow(0);
	var _td0=_tr.insertCell(0);
	_td0.colSpan=3;
	_td0.innerHTML = "&nbsp;";*/
	if(t.LoanType==1){
		$("intLoanCount").innerHTML = getFormatNumber(((Number(intBussnessLoan) +Number(intProvidentFundLoan))*10000)) +"元";
		if(intLoanYears!=0){
			$("intRepaymentCount").innerHTML = getFormatNumber(Math.round(t.LoanCount*10000*intLoanYears*12))+"元";
		}else{
			$("intRepaymentCount").innerHTML = getFormatNumber(Math.round(t.LoanCount*10000*0.5*12))+"元";
		}

		if(intLoanYears!=0){
			$("intInterestCount").innerHTML = getFormatNumber(Math.round(t.LoanCount*10000*intLoanYears*12) - ((Number(intBussnessLoan) +Number(intProvidentFundLoan))*10000) )+"元";
		}else{
			$("intInterestCount").innerHTML = getFormatNumber(Math.round(t.LoanCount*10000*0.5*12) - ((Number(intBussnessLoan) +Number(intProvidentFundLoan))*10000))+"元";
		}

		if(intLoanYears!=0){
			$("intMonthRepayment").innerHTML = getFormatNumber(Math.round(t.LoanCount*10000))+"元";
		}else{
			$("intMonthRepayment").innerHTML = getFormatNumber(Math.round(t.LoanCount*10000))+"元";
		}
	}else{
		
		$("intLoanCount").innerHTML = getFormatNumber(((Number(intBussnessLoan) +Number(intProvidentFundLoan))*10000)) +"元";
		$("intRepaymentCount").innerHTML = t.LoanCount*10000+"元";
		$("intInterestCount").innerHTML = getFormatNumber(((Number(t.LoanCount) - (Number(intBussnessLoan) + Number(intProvidentFundLoan))) *10000).toFixed(2)) +"元";
		$("intMonthRepayment").innerHTML = "";
		workMonthList=$("tabLoanInfoEveryMonth");
		var _tr=workMonthList.insertRow(0);
		var _td0=_tr.insertCell(0);
		var _td1=_tr.insertCell(1);
		var _td2=_tr.insertCell(2);
		var _td3=_tr.insertCell(3);
		var _td4=_tr.insertCell(4);
		
		_td0.innerHTML = "还款期数";
		_td1.innerHTML = "还款金额";
		_td2.innerHTML = "本金";
		_td3.innerHTML = "利息";
		_td4.innerHTML = "期末余额";
		
		_td0.className="oa-loan-calcu-inner-rightbord-content-title";
		_td1.className="oa-loan-calcu-inner-rightbord-content-title";
		_td2.className="oa-loan-calcu-inner-rightbord-content-title";
		_td3.className="oa-loan-calcu-inner-rightbord-content-title";
		_td4.className="oa-loan-calcu-inner-rightbord-content-title";
		
		dayLastMoney = Number(intBussnessLoan) + Number(intProvidentFundLoan);
		repaymentMoeny = 0;
		//alert(t.LoanListCount);
		for(i=1;i<=t.LoanListCount;i++){
			var _tr=workMonthList.insertRow(i);
			var _td0=_tr.insertCell(0);
			var _td1=_tr.insertCell(1);
			var _td2=_tr.insertCell(2);
			var _td3=_tr.insertCell(3);
			var _td4=_tr.insertCell(4);
			
			_td0.width='16%';
			_td1.width='21%';
			_td2.width='21%';
			_td3.width='21%';
			_td4.width='21%';
			
			_td0.innerHTML = "第"+i+"期";
			//alert(t.LoanList[i-1].BussMonthMoney);
			_td1.innerHTML =  getFormatNumber(((Number(t.LoanList[i-1].BussMonthMoney) +Number(t.LoanList[i-1].FundMonthMoney))*10000).toFixed(2)) +"元";
			_td2.innerHTML = getFormatNumber(((Number(t.LoanList[i-1].BussPrincipalMoney) + Number(t.LoanList[i-1].FundPrincipalMoney))*10000).toFixed(2))+"元";
			_td3.innerHTML = getFormatNumber(((Number(t.LoanList[i-1].BussMonthMoney) +Number(t.LoanList[i-1].FundMonthMoney))*10000 - (Number(t.LoanList[i-1].BussPrincipalMoney) + Number(t.LoanList[i-1].FundPrincipalMoney))*10000).toFixed(2)) + "元";
			
			//repaymentMoeny = Number(repaymentMoeny) + getFormatNumber(((Number(t.LoanList[i-1].BussMonthMoney) +Number(t.LoanList[i-1].FundMonthMoney))*10000).toFixed(2));
			dayLastMoney = Number(dayLastMoney)-Number(t.LoanList[i-1].BussPrincipalMoney)-Number(t.LoanList[i-1].FundPrincipalMoney);
			_td4.innerHTML = getFormatNumber((dayLastMoney*10000).toFixed(2)) +"元";
			
		}
	}
	setLoadingNow();
}

function getFormatNumber(num){
	num = String( num );
	num.match( /(\d+)(\.\d+)*/ );
	num = RegExp.$1;
	var frac = RegExp.$2;
	while(num != (num = num.replace(/^(-?\d+)(\d{3})/, "$1,$2")));
	num = frac ? num + frac : num;
	return num;
}

function CalcTax(){
	setLoadingNow();
	intBuildAreas = $('BuildAreas').value;
	intUnitPrice = $('UnitPrice').value;
	strHouseArea = $('houseArea').value;
	strHouseType = $('houseType').value;
	intHaveArea = $('haveArea').value;
	strBuyType = $('buyType').value;
	intloanPrice = $('loanPrice').value;
	strloanPrice = $('loanType').value;
	intBuyYears = $('buyHouseYears').value;
	intSellCountPrice = $('sellCountPrice').value;
	if($("chkOneHouse").checked){
		intOneHouse = "On";
	}else{
		intOneHouse = "Off";
	}
	
	if($("chkNumbleHouse").checked){
		intNumbleHouse = "On";
	}else{
		intNumbleHouse = "Off";
	}
	strURL="../Tool/CalcTaxInfo.php?id=" + Math.random();
	strData  = "buildAreas=" + encodeURIComponent(intBuildAreas);
	strData  += "&UnitPrice=" + encodeURIComponent(intUnitPrice);
	strData  += "&HouseArea=" + encodeURIComponent(strHouseArea);
	strData  += "&HouseType=" + encodeURIComponent(strHouseType);
	strData  += "&HaveArea=" + encodeURIComponent(intHaveArea);
	strData  += "&buyType=" + encodeURIComponent(strBuyType);
	strData  += "&LoanPrice=" + encodeURIComponent(intloanPrice);
	strData  += "&LoanType=" + encodeURIComponent(strloanPrice);
	strData  += "&BuyYears=" + encodeURIComponent(intBuyYears);
	strData  += "&SellCountPrice=" + encodeURIComponent(intSellCountPrice);
	strData  += "&OneHouse=" + encodeURIComponent(intOneHouse);
	strData  += "&NumbleHouse=" + encodeURIComponent(intNumbleHouse);
	//alert(strData);
	new Ajax.Request(strURL, {method: 'post', parameters: strData, onComplete: CalcTaxReceive});
}



function CalcTaxReceive(httpObj){
	text = httpObj.responseText;
	text = getConvForSafari(text);
	//alert(text);
	t = text.parseJSON();
	$('buyTransactionFees').innerHTML = t.buyTransactionFees;
	$('sellTransactionFees').innerHTML = t.sellTransactionFees;
	$('sellDeedTax').innerHTML = t.sellDeedTax;
	$('buyStampDuty').innerHTML = t.buyStampDuty;
	$('sellStampDuty').innerHTML = t.sellStampDuty;
	$('sellCofEStampDuty').innerHTML = t.sellCofEStampDuty;
	$('buyPrivateContractsFee').innerHTML = t.buyPrivateContractsFee;
	$('sellPrivateContractsFee').innerHTML = t.sellPrivateContractsFee;
	$('sellRegistrationFee').innerHTML = t.sellRegistrationFee;
	$('sellPictureFee').innerHTML = t.sellPictureFee;

	$('buyPrivateContractsFee').innerHTML = t.buyPrivateContractsFee;
	$('sellPrivateContractsFee').innerHTML = t.sellPrivateContractsFee;
	$('sellPrivateMortgageContracts').innerHTML = t.sellPrivateMortgageContracts;
	$('sellMortgageRegistrationFee').innerHTML = t.sellMortgageRegistrationFee;
	$('buyBusinessTaxAndSurcharge').innerHTML = t.buyBusinessTaxAndSurcharge;
	$('buyPersonalIncomeTax').innerHTML = t.buyPersonalIncomeTax;
	//alert($('UnitPrice').value);
	$('buyCountPrice2').innerHTML = Number(t.buyTransactionFees)+Number(t.buyStampDuty)
		+Number(t.buyPrivateContractsFee)+Number(t.buyPrivateContractsFee)+Number(t.buyBusinessTaxAndSurcharge)
		+Number(t.buyPersonalIncomeTax);
	
	$('sellCountPrice2').innerHTML = Number(t.sellTransactionFees) + Number(t.sellDeedTax) + Number(t.sellStampDuty)
		+Number(t.sellCofEStampDuty) +Number(t.sellPrivateContractsFee) + Number(t.sellRegistrationFee)+Number(t.sellPictureFee)
		+Number(t.sellPrivateContractsFee)+Number(t.sellPrivateMortgageContracts)+Number(t.sellMortgageRegistrationFee);
	setLoadingNow();
}

function printpdf51(httpObj){
	text = httpObj.responseText;
	text = getConvForSafari(text);
	
}

function printPDF4(){
	var LoanType="";

	if($("SameGiveLoan").checked){
		LoanType = "1";
	}
	if($("SameMoneyLoan").checked){
		LoanType = "2";
	}
	if(LoanType==""){
		alert("还款方式为空，请选择");
		return;
	}

	intBussnessLoan = $("BussnessLoan").value;
	if(intBussnessLoan==""){
		intBussnessLoan = 0;
	}
	
	intProvidentFundLoan = $("ProvidentFundLoan").value;
	if(intProvidentFundLoan==""){
		intProvidentFundLoan = 0;
	}
	intLoanYears = $("LoanYears").value;
	intInterestRates = $("InterestRates").value;
	strURL="./Tool/CalcLoanInfo.php?id=" + Math.random();
	strData  = "loanType=" + encodeURIComponent(LoanType);
	strData  += "&bussnessLoan=" + encodeURIComponent(intBussnessLoan);
	strData  += "&providentFundLoan=" + encodeURIComponent(intProvidentFundLoan);
	strData  += "&loanYears=" + encodeURIComponent(intLoanYears);
	strData  += "&interestRates=" + encodeURIComponent(intInterestRates);
	new Ajax.Request(strURL, {method: 'post', parameters: strData, onComplete: printPDF41});
}


function printPDF41(httpObj){
	text = httpObj.responseText;
	text = getConvForSafari(text);
	t = text.parseJSON();
	intLoanYears = $("LoanYears").value;
	intBussnessLoan = $("BussnessLoan").value;
	if(intBussnessLoan==""){
		intBussnessLoan = 0;
	}
	intProvidentFundLoan = $("ProvidentFundLoan").value;
	if(intProvidentFundLoan==""){
		intProvidentFundLoan = 0;
	}
	
	
	
	if(t.LoanType==1){
		countHuo = getFormatNumber(((Number(intBussnessLoan) +Number(intProvidentFundLoan))*10000));
		if(intLoanYears!=0){
			countHuan = getFormatNumber(Math.round(t.LoanCount*10000*intLoanYears*12));
		}else{
			countHuan = getFormatNumber(Math.round(t.LoanCount*10000*0.5*12));
		}

		if(intLoanYears!=0){
			  interest = getFormatNumber(Math.round(t.LoanCount*10000*intLoanYears*12) - ((Number(intBussnessLoan) +Number(intProvidentFundLoan))*10000) );
		}else{
			interest = getFormatNumber(Math.round(t.LoanCount*10000*0.5*12) - ((Number(intBussnessLoan) +Number(intProvidentFundLoan))*10000));
		}

		if(intLoanYears!=0){
			MonthRepayment = getFormatNumber(Math.round(t.LoanCount*10000));
		}else{
			MonthRepayment = getFormatNumber(Math.round(t.LoanCount*10000));
		}
		window.open("./Tool/Printer1/PrintFlow.php?countHuo="+countHuo+"&countHuan="+countHuan+"&interest="+interest+"&MonthRepayment="+MonthRepayment+"&type="+t.LoanType);
	}else{
		countHuo = getFormatNumber(((Number(intBussnessLoan) +Number(intProvidentFundLoan))*10000));
		countHuan = t.LoanCount*10000;
		interest = getFormatNumber(((Number(t.LoanCount) - (Number(intBussnessLoan) + Number(intProvidentFundLoan))) *10000).toFixed(2));
		MonthRepayment = "";
		var huo2="";
		dayLastMoney = Number(intBussnessLoan) + Number(intProvidentFundLoan);
		repaymentMoeny = 0;
		//alert(t.LoanListCount);
		for(i=1;i<=t.LoanListCount;i++){
			
			huo2 += "~"+i+";";
			//alert(t.LoanList[i-1].BussMonthMoney);
			huo2 += getFormatNumber((dayLastMoney*10000).toFixed(2))+";";
			huo2 += getFormatNumber(((Number(t.LoanList[i-1].BussPrincipalMoney) + Number(t.LoanList[i-1].FundPrincipalMoney))*10000).toFixed(2))+";";
			huo2 += getFormatNumber(((Number(t.LoanList[i-1].BussMonthMoney) +Number(t.LoanList[i-1].FundMonthMoney))*10000 - (Number(t.LoanList[i-1].BussPrincipalMoney) + Number(t.LoanList[i-1].FundPrincipalMoney))*10000).toFixed(2)) + ";";
			huo2 += getFormatNumber(((Number(t.LoanList[i-1].BussMonthMoney) +Number(t.LoanList[i-1].FundMonthMoney))*10000).toFixed(2)) +";";
			//repaymentMoeny = Number(repaymentMoeny) + getFormatNumber(((Number(t.LoanList[i-1].BussMonthMoney) +Number(t.LoanList[i-1].FundMonthMoney))*10000).toFixed(2));
			dayLastMoney = Number(dayLastMoney)-Number(t.LoanList[i-1].BussPrincipalMoney)-Number(t.LoanList[i-1].FundPrincipalMoney);
			huo2 += getFormatNumber((dayLastMoney*10000).toFixed(2)) +";";
		}
		alert(huo2);
		window.open("./Tool/Printer1/PrintFlow.php?countHuo="+countHuo+"&countHuan="+countHuan+"&interest="+interest+"&MonthRepayment="+MonthRepayment+"&type="+t.LoanType+"&huo2="+huo2);
	}
}







function anjie2(z){

	Num=$("InterestRates1").value;
	Num2=$("InterestRates2").value;
	//alert(Num);
	var strNum=Num.split(".");
	var strNum2=Num2.split(".");
	if(strNum[1]){
		if(strNum[1].length>3){
			alert("年利率只允许3位小数");	
		}
	}
	if(strNum2[1]){
		if(strNum2[1].length>3){
			alert("年利率只允许3位小数");	
		}
	}


	loanKim=$("loanKim1").value*10000;
	InterestRates=$("InterestRates1").value/1200;
	loanTime=$("loanTime1").value;
	
	a=Math.pow(1+InterestRates,loanTime);

	benxi=[loanKim*InterestRates*a/(a-1)]*loanTime;
	lixi=benxi-loanKim;


	loanKim=$("loanKim2").value*10000;
	InterestRates=$("InterestRates2").value/1200;
	loanTime=$("loanTime2").value;
	
	a=Math.pow(1+InterestRates,loanTime);

	benxi_2=[loanKim*InterestRates*a/(a-1)]*loanTime;
	lixi_2=benxi_2-loanKim;
	if(lixi-lixi_2<0){
		alert("错误");
		return false;
	}


	$("value_1_1").innerHTML=benxi.toFixed(3);
	$("value_2_1").innerHTML=lixi.toFixed(3);




	$("value_1_2").innerHTML=benxi_2.toFixed(3);
	$("value_2_2").innerHTML=lixi_2.toFixed(3);
	$("value_3_2").innerHTML=(lixi-(benxi_2-loanKim)).toFixed(3);
}





function myKeyDown(){
    var   k=window.event.keyCode; 
    if ((k==46)||(k==8)||(k==189)||(k==109)||(k==190)||(k==110)|| (k>=48 && k<=57)||(k>=96 && k<=105)||(k>=37 && k<=40)) {
	}else if(k==13) {
        window.event.keyCode = 9;
	}else{
       window.event.returnValue = false;
	}
}


function huanKuan(){
	objAllLoan=$("AllLoan").value*10000;
	objLoanPeriod=$("loanPeriod").value;
	objInterestRates=$("InterestRates").value/1200;
	
	//	等额本金(首期）=贷款本金×月利率+贷款本金/贷款月数
	DEBJ=(objAllLoan*objInterestRates)+(objAllLoan/objLoanPeriod);
	alert(DEBJ);
	
	
	//	按月等额本息还款＝贷款本金×月贷款利息×(1+月贷款利息)^贷款期限/((1+月贷款利息)^贷款期限-1)
	a=Math.pow(1+objInterestRates,objLoanPeriod);
	anYueDEBX=(DEBJ*objInterestRates*a)/(a-1);
	alert(anYueDEBX);
	
	//	双周供=贷款本金×14天贷款利息×(1+14天贷款利息)^贷款期限/((1+14天贷款利息)^贷款期限-1)

}