var FRM		= document.all["allotForm"];


/******************************************************************
 USAGE : ÀÔ·Â»çÇ× Ã¼Å©
 @para : NONE
 @return : NONE
*******************************************************************/
function AllotCheck(){
	if(FRM.frmAllotMoney.value==""){ alert("ÇÒºÎ¿ø±ÝÀ» ³Ö¾îÁÖ¼¼¿ä."); FRM.frmAllotMoney.focus(); return false; }
	if(FRM.frmInterestRate.value==""){ alert("¿¬ÀÌÀ²À» ³Ö¾îÁÖ¼Å¾ß ÇÕ´Ï´Ù."); FRM.frmInterestRate.focus(); return false; }
	if(FRM.frmAllotMonth.value==""){ alert("ÇÒºÎ°³¿öÀ» ³Ö¾îÁÖ¼¼¿ä."); FRM.frmAllotMonth.focus(); return false; }

	CalMonthInstallMoney();
}

/******************************************************************
 USAGE : ÄÞ¸¶¸¦ ºÙ¿©¼­ ¹ÝÈ¯
 @para : NONE
 @return : NONE
*******************************************************************/
function chgNumber(){
	AllotMoney = FRM.frmAllotMoney.value;
	if(AllotMoney=="") AllotMoney = 0;
	AllotMoney = parseInt(removeComma(AllotMoney));
	FRM.frmAllotMoney.value = returnNumFormat(AllotMoney);
}

/*
 *****************************************************************************
 * @FName	: GetMonthLease()
 * @USAGE	: 10¸¸¿ø´ç ¸®½º·á
                  ¼Ò¼ö 1ÀÚ¸®¿¡¼­ ¹Ý¿Ã¸²
 * @para	: NONE
 * @return	: (Array) PV : A±â°£ ¸®½º·á , B±â°£ ¸®½º·á
 * @Edit Log    : 
 *                |Name      |Date          |Note 
 *                +----------+--------------+------------
 *                |Nexeration|2005-01-07    |ÃÊ±âÀÛ¼º
 *****************************************************************************
 */
function GetMonthLease()
{
	a      = 100000;
	hLongA = 0;
	hFeeA  = 0;

	hLongA = parseInt(FRM.frmAllotMonth.value);
	hFeeA = parseFloat(FRM.frmInterestRate.value) / 100 / 12;
	
	PVA   = (   a * hFeeA * Math.pow(1+hFeeA, hLongA)  )  / ( Math.pow(1+hFeeA, hLongA) - 1);



	if(hFeeA == 0 || hLongA == 0) 
		PV = 0;
	else 
		PV = rund(PVA,4);
  
	return PV;
}

/*
 *****************************************************************************
 * @FName	: CalMonthInstallMoney()
 * @USAGE	: ¿ùÇÒºÎ±Ý°è»ê(¿ý´ÜÀ§)
 * @para	: NONE
 * @return	: (Array) MonthMoney : A±â°£ ¿ùÇÒºÎ±Ý, B±â°£ ¿ùÇÒºÎ±Ý
 * @Edit Log    : 
 *                |Name      |Date          |Note 
 *                +----------+--------------+------------
 *                |Nexeration|2005-01-07    |ÃÊ±âÀÛ¼º
 *****************************************************************************
 */
function CalMonthInstallMoney()
{
	//10¸¸¿ø´ç ¸®½º·á
	hLease = new Array();
	hLease = GetMonthLease();
	hLongA = parseInt(FRM.frmAllotMonth.value);
	AllotMoney = parseInt(removeComma(FRM.frmAllotMoney.value));

	//ÇÒºÎÀÌÀ²
	hFeeA = parseFloat(FRM.frmInterestRate.value) / 100;
	//¿ùÇÒºÎ±Ý
	MaMoney = Math.round( (hLease * AllotMoney ) / 100000);
	//ÇÒºÎÀÌÀÚ¾×À» ±¸ÇÑ´Ù.
	MaIntrMoney = (MaMoney * hLongA) - AllotMoney;

	FRM.frmMonthMoneyA.value = returnNumFormat(MaMoney);
	FRM.frmAllotMoneyTotal.value =returnNumFormat(MaMoney*hLongA);
	FRM.frmMonthIntrMoney.value =returnNumFormat(parseInt(MaIntrMoney/hLongA));
	FRM.frmIntrMoney.value = returnNumFormat(MaIntrMoney);

}

/******************************************************************
 USAGE : ¼ýÀÚ¸¸ ÀÔ·ÂÇã¿ë
 @para : NONE
 @return : NONE
*******************************************************************/
function inputNum(){
	if((event.keyCode<48)||(event.keyCode>57)){
		alert("¼ýÀÚ¸¸ ÀÔ·ÂÇØÁÖ¼¼¿ä");
		event.returnValue=false; 
	}
}

function inputPer(){
	if((event.keyCode<48)||(event.keyCode>57)){
		if(event.keyCode != 46){
			alert("¼ýÀÚ¿Í Á¡(.)¸¸ ÀÔ·ÂÇØÁÖ¼¼¿ä");
			event.returnValue=false; 
		}
	}
}

/******************************************************************
 USAGE : ÄÞ¸¶Âï±â
 @para : NONE
 @return : NONE
*******************************************************************/
function returnNumFormat(sNum)
{
	str = new Array();
	reVal = false;
	val = "" + sNum;
	if(val.indexOf("-") != -1){
		val = val.substr(1,val.length);
		reVal = true;
	}
	len = val.length;
	val1 = Math.floor(len / 3);
	val2 = len % 3;
	strTmp = "";
	strReturn = "";
	result = false;
	if(val2){
		strTmp = val.substr(0,val2);
	}
	
	for(i=0;i<val1;i++){
		if(strTmp!=""){
			if(i==0){
				str[i] = val.substr(val2,3);
		}else{
				str[i] = val.substr(val2 + 3 * i,3);
		}
		}else{
			str[i] = val.substr(i * 3,3);
	}
		result = true;
	}
	strReturn = str.join(",");
	if(strTmp!=""){
		if(result == true){
			rStr = strTmp + "," + strReturn;
		}else{
			rStr = strTmp;
		}
	}else{
		rStr = strReturn;
	}
	if(reVal == true) rStr = "-" + rStr;
	return rStr;
}
/******************************************************************
 USAGE : ÄÞ¸¶ ¾ø¾Ö±â
 @para : NONE
 @return : NONE
*******************************************************************/
function removeComma(str)
{
	str = str + '';
	preStr = str.split(",");
	reStr = preStr.join("");
	return reStr;
}

/******************************************************************
 USAGE : ÀÚ¸´¼ö ÀÚ¸£±â
 @para : NONE
 @return : NONE
*******************************************************************/
function rund(num,tg)
{
	temp = new Array();
	temp_num = num;
	temp_num = "" + temp_num;
	temp = temp_num.split(".");
	t = temp[1].substr(tg-1,1);
	if(t >= 5) r = (temp[1].substr(0,tg-1) * 1) + 1;
	else r = temp[1].substr(0,tg-1);
	r = r / Math.pow(10,tg-1);
	return (temp[0] * 1) + (r * 1);
}

