var coment = "";
mnogo_listov=0;


function check_sposob(){
	sposob=document.getElementById("calc").sposob.value;
	if (sposob=="cifra"){
		document.getElementById('kraski').style.visibility="hidden";
//		document.getElementById('help_oborot').style.visibility="hidden";
		document.getElementById('oborot').style.visibility="hidden";
		document.getElementById('bumaga').style.visibility="hidden";
//		document.getElementById('kraski').style.position="absolute";
		document.getElementById('kolor').style.visibility="visible";
		document.getElementById('kolor').style.position="relative";
		document.getElementById('bumaga2').style.visibility="visible";
		document.getElementById('bumaga2').style.position="relative";
	}
	else if (sposob=="ofset"){
		document.getElementById('kraski').style.visibility="visible";
//		document.getElementById('help_oborot').style.visibility="visible";
		document.getElementById('oborot').style.visibility="visible";
		document.getElementById('bumaga').style.visibility="visible";
//		document.getElementById('kraski').style.position="relative";
		document.getElementById('kolor').style.visibility="hidden";
		document.getElementById('kolor').style.position="absolute";
		document.getElementById('bumaga2').style.visibility="hidden";
		document.getElementById('bumaga2').style.position="absolute";
	}
}




function read_param(){
	tirag=document.getElementById("calc").tirag.value;
	
	nomer_mm=tirag.indexOf("m");
	if (nomer_mm>0){manager_calc=1; nomer_m=nomer_mm; tirag=tirag.slice(0,nomer_m);}
 	if (tirag*1){coment=coment;} else {coment=coment+"Не верно задан тираж. "; out=1;}
 	if ((tirag-Math.round(tirag))!=0) {coment=coment+"Не верно задан тираж. "; out=1;}
	
	kraska=document.getElementById("calc").kraska.value;
	bumaga=document.getElementById("calc").bumaga.value;
	oborot=document.getElementById("calc").oborot.value;
	if ((kraska==10)||(kraska==20)||(kraska==30)||(kraska==40)||(kraska==50)||(kraska==60)){oborot="chujoi";}
	laminat=document.getElementById("calc").laminat.value;
	kolor=document.getElementById("calc").kolor.value;
	bumaga2=document.getElementById("calc").bumaga2.value;
	sposob=document.getElementById("calc").sposob.value;
	if (tirag<0){opt=1; tirag=-tirag;} else {opt=0;}

	if (document.getElementById("calc").manager_storon){storonnie=document.getElementById("calc").manager_storon.value;} 
	else {storonnie=0;}
	if (document.getElementById("calc").SKIDKA){
		SKIDKA=document.getElementById("calc").SKIDKA.value*1;
		if ((opt==1)&(SKIDKA!=skidka_opt)){out=1; coment=coment+"Произвольная скидка только с положительным тиражем. ";}
	} 
	else {
		if (opt==1){SKIDKA=skidka_opt;} else {SKIDKA=0;}
	}

	chas_cena=Math.round(C_h_romayor_rozn*(1-SKIDKA/100)*10)/10;
	for (i=0; i<3; i++) {if (document.getElementById("calc").maket[i].checked) {maket=document.getElementById("calc").maket[i].value;}}
}



//}
/*
function obrabotka(){
	if (laminat==0){cena_obr=0;obrabotka_opt=0;}
	else if (laminat==11){cena_obr=Lam_pr+(Lam_a3_gl*oborot-Lam_a4_gl*(oborot-1)*2)*tirag; obrabotka_opt=Lam_opt;}
	else if (laminat==12){cena_obr=Lam_pr+Lam_a3_gl*tirag*2; obrabotka_opt=Lam_opt;}
	else if (laminat==21){cena_obr=Lam_pr+(Lam_a3_mat*oborot-Lam_a4_mat*(oborot-1)*2)*tirag; obrabotka_opt=Lam_opt;}
	else if (laminat==22){cena_obr=Lam_pr+Lam_a3_mat*tirag*2; obrabotka_opt=Lam_opt;}
	else if (laminat==31){cena_obr=Lak_pr+Lak_a3*tirag; obrabotka_opt=Lak_opt;}
	else if (laminat==32){cena_obr=Lak_pr+Lak_a3*tirag*2; obrabotka_opt=Lak_opt;}
	else if (laminat==41){cena_obr=Uf_pr+(Uf_a3*oborot-Uf_a4*(oborot-1)*2)*tirag; obrabotka_opt=Uf_opt;}
	else if (laminat==42){cena_obr=Uf_pr+Uf_a3*tirag*2; obrabotka_opt=Uf_opt;}
	else if (laminat==52){cena_obr=Lam_pr+Lam_a3_100mk_gl*tirag*2; obrabotka_opt=Lam_opt;}
	else if (laminat==62){cena_obr=Lam_pr+Lam_a3_100mk_mat*tirag*2; obrabotka_opt=Lam_opt;}
	if (OPT==0){obrabotka_opt=0;}
	cena_obr=cena_obr*(1-(obrabotka_opt/100));
}
*/
function cena_maketa(){
	if (maket==2){cena_maket=maket_a3_1;}
	else if (maket==1){cena_maket=maket_a3_2;}
	else if (maket==0){cena_maket=0;}
	cena_maket=Math.round(cena_maket*(1-SKIDKA*maket_skidka_K/100));
}


function gg(){
	coment="";
	out=0;
	manager_calc=0;
	
	read_param();
	if (tirag<0){OPT=1; tirag=-tirag;} else {OPT=0;}
	
	if (sposob=="cifra"){
//		oborot=1;
		cena_print_d=cena_print_cifra();
		cena_print_r=cena_print_d*kurs*NDS;
		cena_maketa();
		cena_obr=pokritie("A3", tirag, laminat, oborot);
		cena_print_d=Math.round(cena_print_d*10)/10;
		cena_r=cena_print_r+(cena_obr+cena_maket+storonnie*(1+storonnie_dop/100))*kurs*NDS;
		cena_d=cena_print_d+cena_obr+cena_maket+storonnie*(1+storonnie_dop/100);
		m_print=manager_func(cena_print_d, cena_maket, cena_obr, 0, 0, storonnie);
		n=" <input type='text' name='manager_storon' class='manager_input'   onkeypress='enter_func(event)' value="+storonnie+" /> затраты на стороне<br>"+
		" <input type='text' name='SKIDKA' class='manager_input'  onkeypress='enter_func(event)' value="+SKIDKA+" /> скидка на печать <br>"+"печать="+cena_print_d+"<br>"+"покрытие="+cena_obr+"<br>"+"макет="+cena_maket+"<br>"+"Менеджерские="+m_print+"<br>";		
	}

	
	else if (sposob=="ofset"){
		cena_bumagi("A3", tirag);
		cena_print_d=cena_print_Romayor(); coment_mah="Ромаер";
		cena_obr=pokritie("A3", tirag, laminat, oborot);
		cena_maketa();
		m_print=manager_func(cena_print_d, cena_maket, cena_obr, 0, 0, storonnie);

		cena_r=cena_bumagi_r+(cena_print_d+cena_form+cena_obr+cena_maket+storonnie*(1+storonnie_dop/100))*kurs*NDS;
		cena_d=cena_bumagi_d+cena_print_d+cena_form+cena_obr+cena_maket+storonnie*(1+storonnie_dop/100);
	
		cena_d=Math.round(cena_d);
		cena_form=Math.round(cena_form);
		cena_bumagi_d=Math.round(cena_bumagi_d);
		cena_print_d=Math.round(cena_print_d);
		V_mah=Math.round(V_mah*100)/100;
		n=" <input type='text' name='manager_storon' class='manager_input'  onkeypress='enter_func(event)' value="+storonnie+" /> затраты на стороне<br>"+
		" <input type='text' name='chas_cena' class='manager_input'  onkeypress='enter_func(event)' value="+chas_cena+" onkeyup='return change_procent2_r()'/> цена часа = скидка "+
		" <input type='text' name='SKIDKA' class='manager_input' onkeypress='enter_func(event)' value="+SKIDKA+" onkeyup='return change_procent_r();'/>%<br>"+
		"бумага="+cena_bumagi_d+" (пр. "+bumaga_dop+"л.)"+"<br>"+"печать="+cena_print_d+" ("+Vpr+"+"+Math.round((V_mah-Vpr)*100)/100+"="+V_mah+" ч.)"+"<br>" + "формы="+cena_form+"<br>"+"покрытие="+cena_obr+"<br>"+"макет="+cena_maket+"<br>"+"Менеджерские="+m_print+"<br>";
	}
	if (out==0){
		if (manager_calc!=1){n="";}
		nn="Цена с НДС="+razdelitel(cena_r)+" р"+"<br>"+"Код заказа: "+cena_d;
	}
	else {nn=""; n="";}
document.getElementById("coment").innerHTML=coment;
document.getElementById("manager_info").innerHTML=n;
document.getElementById("cena").innerHTML=nn;
}