function over(id, color, menu) {
	if (id == "") {return false;}
	document.getElementById(id).style.fontWeight = 'bold';
	/*if (color != "") { 
		document.all(id).style.backgroundColor = '#'+color;
		}
	else {
		document.all(id).style.backgroundColor = '';
		}*/
	if (menu != "no") {
		document.getElementById(id).style.cursor = 'pointer';
		}
	}
function over2(id, color, menu) {
	if (id == "") {return false;}
	document.getElementById(id).style.fontWeight = 'bold';
	/*document.all(id).style.backgroundColor = '#FFFFFF';*/
	if (menu != "no") {
		document.getElementById(id).style.cursor = 'pointer';
		}
	}	
function over3(id, color, menu) {
	if (id == "") {return false;}
	if (menu != "no") {
		document.getElementById(id).style.cursor = 'pointer';
		}
	}
function out(id, color, menu) {
	if (id == "") {return false;}
	document.getElementById(id).style.fontWeight = 'normal';
	/*if (color != "") {
		document.all(id).style.backgroundColor = '#'+color;
		}
	else {
		document.all(id).style.backgroundColor = '';
		}*/
	if (menu != "no") {
		document.getElementById(id).style.cursor = '';
		}
	}
function out2(id, color, menu) {
	if (id == "") {return false;}
	document.getElementById(id).style.fontWeight = 'normal';
	document.getElementById(id).style.backgroundColor = '#fff3c5';
	if (menu != "no") {
		document.getElementById(id).style.cursor = '';
		}
	}
function mx_popupImg(URL,TTL) {
	var inc_y = 29;
	var inc_x = 10;
	params = "top=50, left=200,width=600, height=500, Status=no, toolbar=no, menubar=no, location=no, directories=no, scrollbars=no";
	popupWin = window.open("","popupWin",params);
	popupWin.focus();
	popupWin.document.open();
	popupWin.document.write("<html><head"+"><"+"title>"+TTL+"</"+"title></"+"head>");
	popupWin.document.write("<sc"+"ript language = JavaScript>");
	popupWin.document.write("function closeWindow(){");
	popupWin.document.write("parent.window.close() };");
	popupWin.document.write("</"+"script"+">");
	popupWin.document.write("<bo"+"dy leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'><"+"a href=''><im"+"g src='"+URL+"' border='0' name='cha1' onClick='closeWindow()' alt=''  onload='window.resizeTo(window.document.images[0].width+"+inc_x+",window.document.images[0].height+"+inc_y+")'></"+"a></"+"body></"+"html>");
	popupWin.document.close();
	}
 
 function setAnswer(id) 
 {
 	for(i=1;i<50;i++)
 	{
 		if(document.getElementById('a'+i))
 			document.getElementById('a'+i).style.backgroundColor = '';
 	}
 	document.getElementById(id).style.backgroundColor = '#fff3c5';
 }
 
 function newPrice(price1,rowId)
 {
 	
 	var km=null;//alert(document.getElementById('km'+rowId).value);
 	if(document.getElementById('km'+rowId).value!=null)
 	{
 		km = document.getElementById('km'+rowId).value;
 		km = intval(km);
 	}
 	
	
 	if(addservices[rowId]==0)
 	{
 		if(km!=null)
 		{
 			totalPrice = totalPrice+price1*km;
 			document.getElementById('price'+rowId).innerHTML = price1*km+' руб.';
 		}	
 		else
 			totalPrice = totalPrice+price1;
 		addservices[rowId] = 1;
 		color = 'lightgrey';
 		document.getElementById('check'+rowId).checked=true;
 	}	
 	else
 	{
 		if(km!=null)
 		{
 			totalPrice = totalPrice-price1*km;
 			document.getElementById('price'+rowId).innerHTML = price1*km+' руб.';
 		}	
 		else
	 		totalPrice = totalPrice-price1;
 		addservices[rowId] = 0;
 		color = 'white';
 		document.getElementById('check'+rowId).checked='';
 	}
 	document.getElementById('totalprice').innerHTML = totalPrice+' руб.'; 
 	document.getElementById('row'+rowId).style.backgroundColor = color;
 }
 
 function intval( mixed_var, base ) 
 {  
    var tmp;  
   
    if( typeof( mixed_var ) == 'string' )
    {  
        tmp = parseInt(mixed_var*1);  
        if(isNaN(tmp) || !isFinite(tmp))
        {  
            return 0;  
        } else{  
            return tmp.toString(base || 10);  
        }  
    } else if( typeof( mixed_var ) == 'number' && isFinite(mixed_var) ){  
        //return Math.floor(mixed_var);  
        return mixed_var;  
    } else{  
        return 0;  
    }  
}  

function setpic(layer,filename)
{
	document.getElementById('layer'+layer).innerHTML = '<img WIDTH="650" src="'+filename+'">'; 
}
function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

// credit
function setPrice(value)
{	
	document.getElementById('pricefield').value = value*1000;
	setFirstDeposit(document.getElementById('percentfield').value);
	setMonthly();
}
function setPercent(value)
{	
	document.getElementById('percentfield').value = Math.floor(value/document.getElementById('pricefield').value*100);
	document.getElementById('creditsumfield').value = document.getElementById('pricefield').value-document.getElementById('firstdepositfield').value;
	setMonthly();
}
function setFirstDeposit(value)
{	
	document.getElementById('firstdepositfield').value = Math.floor(document.getElementById('pricefield').value*value/100);
	document.getElementById('creditsumfield').value = document.getElementById('pricefield').value-document.getElementById('firstdepositfield').value;
	setMonthly();
}
function setMonthly()
{	
	// Миллионный
	if(document.getElementById('percentfield').value>=15 && document.getElementById('creditsumfield').value>=25000 && document.getElementById('creditsumfield').value<=2500000 && document.getElementById('creditperiodfield').value<=84 && document.getElementById('creditperiodfield').value)
	{
		mainsum=0;
		maindebt=document.getElementById('creditsumfield').value;
		monthly=roundNumber(Math.ceil(document.getElementById('creditsumfield').value/document.getElementById('creditperiodfield').value),2);
		for(crper=1;crper<=document.getElementById('creditperiodfield').value;crper++)
		{
			mainsum+= roundNumber(Math.ceil(parseInt(maindebt*0.109/12)),2);
			maindebt-= roundNumber(parseInt(monthly),2);
		}
		document.getElementById('creditmonthly1field').value = roundNumber(
			(parseInt(document.getElementById('creditsumfield').value) + 
			 /*parseInt(0.05*document.getElementById('creditsumfield').value) + */
			 mainsum + 
			 parseInt(document.getElementById('creditperiodfield').value*0.0050*document.getElementById('creditsumfield').value)+
			 /*parseInt(document.getElementById('creditperiodfield').value*0.002*document.getElementById('creditsumfield').value)+*/
			 0
			)/document.getElementById('creditperiodfield').value,2);
		document.getElementById('alert').innerHTML = "";
		document.getElementById('print').style.visibility = "visible";
		document.getElementById('firstdepositrow').style.backgroundColor = "#2a2924";
		document.getElementById('creditperiodrow').style.backgroundColor = "#2a2924";
	}	
	else
	{
		document.getElementById('creditmonthly1field').value = "";
		if(document.getElementById('selhouse').value && document.getElementById('percentfield').value>0 && document.getElementById('percentfield').value<10) {
			document.getElementById('print').style.visibility = "hidden";
			document.getElementById('alert').innerHTML = "Первоначальный взнос должен быть от 10% и выше.";
			document.getElementById('firstdepositrow').style.backgroundColor = "red";
		}
		/*if(!document.getElementById('creditperiodfield').value && document.getElementById('selhouse').value) {
			document.getElementById('print').style.visibility = "hidden";
			document.getElementById('alert').innerHTML = "Выберите срок кредита.";
			document.getElementById('creditperiodrow').style.backgroundColor = "red";
		}*/
	}
	
	// Солидный
	if(document.getElementById('percentfield').value>=10 && document.getElementById('creditsumfield').value>=65000 && document.getElementById('creditsumfield').value<=3000000 && document.getElementById('creditperiodfield').value)
	{
		if(document.getElementById('percentfield').value>=10 && document.getElementById('percentfield').value<20) rate = 0.0050;
		if(document.getElementById('percentfield').value>=20 && document.getElementById('percentfield').value<40) rate = 0.0040;
		if(document.getElementById('percentfield').value>=40 && document.getElementById('percentfield').value<100) rate = 0.0030;
	
		mainsum=0;
		maindebt=document.getElementById('creditsumfield').value;
		monthly=roundNumber(Math.ceil(document.getElementById('creditsumfield').value/document.getElementById('creditperiodfield').value),2);
		for(crper=1;crper<=document.getElementById('creditperiodfield').value;crper++)
		{
			mainsum+= roundNumber(Math.ceil(parseInt(maindebt*0.099/12)),2);
			maindebt-= roundNumber(parseInt(monthly),2);
		}
		
		document.getElementById('creditmonthly2field').value = roundNumber(
			(parseInt(document.getElementById('creditsumfield').value) + 
			 mainsum + 
			 parseInt(document.getElementById('creditperiodfield').value*rate*document.getElementById('creditsumfield').value)+
			 /*parseInt(document.getElementById('creditperiodfield').value*0.002*document.getElementById('creditsumfield').value)+*/
			 0
			 )/document.getElementById('creditperiodfield').value,2);
		document.getElementById('alert').innerHTML = "";
		document.getElementById('print').style.visibility = "visible";
		document.getElementById('firstdepositrow').style.backgroundColor = "#2a2924";
		document.getElementById('creditperiodrow').style.backgroundColor = "#2a2924";
	}
	else
	{
		document.getElementById('creditmonthly2field').value = "";
		if(document.getElementById('selhouse').value && document.getElementById('percentfield').value>0 && document.getElementById('percentfield').value<10) {
			document.getElementById('alert').innerHTML = "Первоначальный взнос должен быть от 10% и выше.";
			document.getElementById('print').style.visibility = "hidden";
		}
		/*if(!document.getElementById('creditperiodfield').value && document.getElementById('selhouse').value) {
			document.getElementById('print').style.visibility = "hidden";
			document.getElementById('alert').innerHTML = "Выберите срок кредита.";
			document.getElementById('creditperiodrow').style.backgroundColor = "red";
		}*/
	}	
}
function check_email(email_id,err_id){
            emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;
            var err_mail='Неверный email!';
            if(emailRegExp.test(document.getElementById(email_id).value)){
                return true;
            }else{
                document.getElementById(err_id).innerHTML=err_mail;
                return false;
            }
        }
function showtab(id1,id2){
	document.getElementById(id2).style.visibility = "hidden";
	document.getElementById(id2).style.height = "0px";
	document.getElementById(id2+"_tab").setAttribute("class", "cat_tab_inactive");
	
	document.getElementById(id1).style.visibility = "visible";
	document.getElementById(id1).style.height = "600px";
	document.getElementById(id1+"_tab").setAttribute("class", "cat_tab_active");
	//document.getElementById(id1).style.margin = "0 -600px";
}        
