/**
 * cetelem calculater reader
 * 
 * v1.0
 * (C) Karol Danko
 *  
 **/
 
 
 function cetDetail(price){
 	//document.getElementById('cetelemCalculator').className='';
 	cet_onLoad(price);
 }
 function cetDetailClose(){
 	//document.getElementById('cetelemCalculator').className='hidden';
 	return false;
 }
 function cet_onLoad(price){
 	document.getElementById('cet_loader').style.display='';
 
 	var param = 'what=getcalc';
 	param+= '&cet_material='+document.getElementById('cet_material').value;
 	if(price)param+= '&cet_total='+price;
 	
	url=rootdir+'inc/flow/cetelem.php?'+param;  
	xmlHttp=GetXmlHttpObject(cet_loadStateChanged,true);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
	return false; 
 }
function cet_loadStateChanged(){ 
	if (xmlHttp.readyState==2){ 
	
	} 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById('cet_loader').style.display='none';
		document.getElementById('cet_display').style.display='';
		document.getElementById('cet_display').innerHTML = xmlHttp.responseText;
	} 
}    

var IgnoreMsg;
function cet_calculate(ignoreMsg){
	//IgnoreMsg = ignoreMsg
	setOpacity(document.getElementById('cet_display'),30);
 	var param = 'what=calculate';
 	param+= '&cet_total='+document.getElementById('cet_total').value;
 	param+= '&cet_material='+document.getElementById('cet_material').value;
 	param+= '&cet_barem='+document.getElementById('cet_barem').value;
 	param+= '&cet_pojisteni='+document.getElementById('cet_pojisteni').value;
 	param+= '&cet_prima='+document.getElementById('cet_prima').value;
 	param+= '&cet_pocet='+document.getElementById('cet_pocet').value;
 	param+= '&cet_odklad='+document.getElementById('cet_odklad').value;

	url=rootdir+'inc/flow/cetelem.php?'+param;  
	xmlHttp=GetXmlHttpObject(cet_calculateStateChanged,true);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
	return false; 	
} 

function cet_calculateStateChanged(){ 
	if (xmlHttp.readyState==2){ 
	
	} 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		//ret = JSON.decode(xmlHttp.responseText);
		var myObject = eval('(' + xmlHttp.responseText + ')')
		setOpacity(document.getElementById('cet_display'),100);
		document.getElementById('cet_pocet').value=myObject['pocetSplatek'];
		document.getElementById('cet_prima').value=myObject['primaPlatba'];
		document.getElementById('cet_uver').value=myObject['vyseUveru'];
		document.getElementById('cet_mes').innerHTML=myObject['vyseSplatky'];
		document.getElementById('cet_cena_uv').innerHTML=myObject['cenaUveru'];
		document.getElementById('cet_rpsn').innerHTML=myObject['RPSN'];
		document.getElementById('cet_ursaz').innerHTML=myObject['ursaz'];
		document.getElementById('cet_odklad').value=myObject['odklad'];
		
		
		
		
		
		if(myObject['zprava']&&!IgnoreMsg)alert(myObject['zprava']);
		//document.getElementById('cet_display').innerHTML = xmlHttp.responseText;
	} 
}   

function cet_directPayChanged(){
	total = 1*document.getElementById('cet_total').value;
	direct = 1*document.getElementById('cet_prima').value;
	if(direct>total){
		document.getElementById('cet_prima').value=total;
		direct = total;
	}
	document.getElementById('cet_uver').innerHTML = ( total - direct);
}

function cet_splatkyValid(){

	if(document.getElementById('cet_cena_uv').innerHTML=='-'){
		alert('Vyplňte prosím všechna pole a stisněte přepočítat');
		return false;
	}else{
		return true;
	}
	
	
}
function cet_redirect(){

}
