// JavaScript Document
var proc;
var ani_c=0;
var flag=0;
var prime=0.38;
function calC(){
	var f=document.forms['calculator'];
	var ptype=f.pay_type.value;
	var psum=parseInt(f.pay_summ.value);
	var month=f.month.value;
	var monthly=parseInt(f.monthly.value);
	if(ptype=='1'){
		if(month=='12'||month=='24') proc=0.36;
		else if(month=='36') proc=0.37;
		else if(month=='48') proc=0.38;
		else proc=0.43;
		proc=proc+prime;
	}else if(ptype=='2'){
		if(month=='24') proc=0.74;
		else if(month=='36') proc=0.75;
		else if(month=='48') proc=0.76;
		else proc=0.82;
	}else{
		if(month=='12') proc=1.13;
		else if(month=='24') proc=1.14;
		else if(month=='36') proc=1.15;
		else if(month=='48') proc=1.16;
		else proc=1.22;
	}
	proc=proc/100;
	if(flag==0 || flag==1){
		if(psum){
			var summ=(Math.ceil((psum*proc)/(1-1/Math.pow((1+proc),(month*1)))*100))/100;
			if(summ.toString().indexOf('.')!=-1){ if(summ.toString().split('.')[1].length<2)summ=summ+'0'; }
			f.monthly.value=summ;
		}else aniMes();
	}else{
		if(monthly){
			var summ=(Math.ceil(((1-1/Math.pow((1+proc),(month*1)))*(monthly*1)/proc)*100))/100;
			if(summ.toString().indexOf('.')!=-1){ if(summ.toString().split('.')[1].length<2)summ=summ+'0'; }
			f.pay_summ.value=summ;
		}else{  aniMes(); }
	}
	iniCalc();
}
function reM(item){
	if(item.value=='2'){
		if(geBi('month').value=='12'){
			geBi('month').value='24';
			if(isIE()!=0) geBi('month_f').innerText='24';
			else  geBi('month_f').innerHTML='24';
		}
		if(geBi('month').firstChild.value=='12'){
			geBi('month').removeChild(geBi('month').firstChild);
			geBi('month_ul').removeChild(geBi('month_ul').firstChild);
		}
	}else if(geBi('month').firstChild.value!='12'){
		var opt=Elemnt('option','','','12');
		opt.value='12';
		geBi('month').insertBefore(opt,geBi('month').firstChild);
		var li=Elemnt('li','','','12');
		li.value='12';
		li.onmouseover=function(){ repHover(this); }
		li.onclick=function(){ repClick(this); }
		geBi('month_ul').insertBefore(li,geBi('month_ul').firstChild);
	}
}
function iniCalc(){
	geBi('calc_message').style.display='none';
	if(geBi('pay_summ').value=='' && geBi('monthly').value==''){
		mesS(1);
		geBi('calc_arr_left').style.backgroundPosition='left bottom';
		geBi('calc_arr_right').style.backgroundPosition='right bottom';
		geBi('calculator_top_fl').style.backgroundPosition='left bottom';
		geBi('calculator_top_fr').style.backgroundPosition='left bottom';
		geBi('calculator_bot_fl').style.backgroundPosition='left top';
		geBi('calculator_bot_fr').style.backgroundPosition='left top';
		geBi('calc_submit').style.backgroundPosition='left bottom';
	}else if(geBi('pay_summ').value!='' && geBi('monthly').value==''){ // || flag==1
		mesS(2);
		geBi('calc_arr_left').style.backgroundPosition='left 25px';
		geBi('calc_arr_right').style.backgroundPosition='right top';
		geBi('calculator_top_fl').style.backgroundPosition='left top';
		geBi('calculator_top_fr').style.backgroundPosition='left top';
		geBi('calculator_bot_fl').style.backgroundPosition='left bottom';
		geBi('calculator_bot_fr').style.backgroundPosition='left bottom';
		geBi('calc_submit').style.backgroundPosition='left top';
	}else if(geBi('pay_summ').value=='' && geBi('monthly').value!=''){ // || flag==2
		mesS(2);
		geBi('calc_arr_left').style.backgroundPosition='left top';
		geBi('calc_arr_right').style.backgroundPosition='right 25px';
		geBi('calculator_top_fl').style.backgroundPosition='left top';
		geBi('calculator_top_fr').style.backgroundPosition='left top';
		geBi('calculator_bot_fl').style.backgroundPosition='left bottom';
		geBi('calculator_bot_fr').style.backgroundPosition='left bottom';
		geBi('calc_submit').style.backgroundPosition='left top';
	}else{
		mesS(3);
		if(flag==2){
			geBi('calc_arr_left').style.backgroundPosition='left top';
			geBi('calc_arr_right').style.backgroundPosition='right 25px';
		}else{
			geBi('calc_arr_left').style.backgroundPosition='left 25px';
			geBi('calc_arr_right').style.backgroundPosition='right top';
		}
		geBi('calculator_top_fl').style.backgroundPosition='left top';
		geBi('calculator_top_fr').style.backgroundPosition='left top';
		geBi('calculator_bot_fl').style.backgroundPosition='left top';
		geBi('calculator_bot_fr').style.backgroundPosition='left top';
		geBi('calc_submit').style.backgroundPosition='left top';
	}
}
function aniMes(){
	if((ani_c/2).toString().indexOf('.')==-1){
		geBi('calc_message_1').style.color='#ff0000';
		geBi('calc_arr_left').style.background='none';
		geBi('calc_arr_right').style.background='none';
	}else{
		geBi('calc_message_1').style.color='#ffffff';
		geBi('calc_arr_left').style.background='url(/images/calculator_arr.gif) left bottom no-repeat';
		geBi('calc_arr_right').style.background='url(/images/calculator_arr.gif) right bottom no-repeat';
	}
	ani_c++;
	if(ani_c<6)setTimeout('aniMes()', 400);
	else ani_c=0;
}
function mesS(item){
	var mess=3;
	var str='calc_message_';
	for(var i=0;i<mess;i++){
		if(i+1!=item*1) inVis(str+(i+1));
	}
	viSi(str+item);
}
function onChS(item){
	if(item.id=='pay_type'){
		geBi('calculator_bot_fl').style.backgroundPosition='left top';
	}else{
		geBi('calculator_bot_fr').style.backgroundPosition='left top';
	}
}
