function schimbaMasina(id)
{
	var o=document.getElementById('masina_id');
	if(o)
		for(i=0;i<o.options.length;i++)
			if( id == parseInt(o.options[i].value))
			{ 
				o.options[i].selected=true;
				document.getElementById("frm1").submit();
				break;
			}
}

//RENT
function FormatNumber(nr)
{
	var num = parseFloat(nr);
	num = num.toFixed(0);	
	num += '';
	num = num.replace('.',',');
	x = num.split(',');
	x1 = x[0];
	x2 = x.length > 1 ? ',' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + '.' + '$2');
	}
	return x1 + x2;
}
var pretTotal = 0;
function CalcPrice()
{
	//init var
	pretTotal = 0;
	var conditie = "";
	
	//get days
	var days = CalcDays();
	if(days<0)
	{
		alert("Data aleasa este in trecut!");
		return;
	}
	
	var taxa = document.getElementById('taxam');	
	if(taxa) ;//pretTotal=parseFloat(taxa.value);

	var cond = document.getElementById('strcond');	
	var conditie="";
	if(cond) conditie = cond.value;
	var pretday = 0;	
	eval(conditie);	
	
	pretTotal+=pretday*days;
	//verific optiunile
	//var opt = document.getElementsByName("optiuni[]");
	//maxim optiuni
	for(i=0;i<50;i++)
	{
		var opt = document.getElementById("optiune"+i);
		if(opt && opt.checked) pretTotal+= parseFloat(opt.value);
	}
	
	var t = document.getElementById('total_p');
	if(t) t.innerHTML = FormatNumber(pretTotal);

	var z = document.getElementById('zile_p');
	if(z) z.innerHTML = (days==1?days+" zi" : days+" zile");
	var o;
	//salvez total,zile,pret/zi
	o = document.getElementById('costtotal');
	if(o) o.value = pretTotal;
	o = document.getElementById('nrzile');
	if(o) o.value = days;
	o = document.getElementById('pretzi');
	if(o) o.value = pretday;
}
function CalcDays()
{
	var y1=0,y2=0,d1=0,d2=0,m1=0,m2=0,h1=0,h2=0,mi1=0,mi2=0;
	var o;
	o = document.getElementById('year1');if(o) y1=parseInt(o.value);
	o = document.getElementById('year2');if(o) y2=parseInt(o.value);

	o = document.getElementById('month1');if(o) m1=parseInt(o.value);
	o = document.getElementById('month2');if(o) m2=parseInt(o.value);

	o = document.getElementById('day1');if(o) d1=parseInt(o.value);
	o = document.getElementById('day2');if(o) d2=parseInt(o.value);

	o = document.getElementById('hour1');if(o) h1=parseInt(o.value);
	o = document.getElementById('hour2');if(o) h2=parseInt(o.value);
	
	o = document.getElementById('minute1');if(o) mi1=parseInt(o.value);
	o = document.getElementById('minute2');if(o) mi2=parseInt(o.value);
	


	var sd = new Date(y1,m1,d1,h1,mi1,0,0);
	var ed = new Date(y2,m2,d2,h2,mi2,0,0);
	var dif = ed-sd;//microsecunde
	days = Math.ceil(dif/86400000);
	return days?(days):1;
}
function FixPrice(chk)
{
	
}
//AJAX
function getCar(id)
{
	var myAjax = new Ajax("getcar.php?id="+id, {method: 'get',onComplete:completeGetCar}).request();
}
function completeGetCar(response)
{
	$("cardata").innerHTML = response;	
	CalcPrice();
	
	if(typeof sIFR == "function"){
		sIFR.replaceElement(named({sSelector:"h1", sFlashSrc:"sifr/sifr.swf", sColor:"#ff7f00", sLinkColor:"#000000", sBgColor:"#ffffff", sHoverColor:"#CCCCCC", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0", sWmode:"transparent"}));
		sIFR.replaceElement(named({sSelector:"h3", sFlashSrc:"sifr/sifr.swf", sColor:"#000000", sLinkColor:"#000000", sBgColor:"#ffffff", sHoverColor:"#CCCCCC", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=center&offsetTop=0", sWmode:"transparent"}));
	sIFR.replaceElement(named({sSelector:"h4", sFlashSrc:"sifr/sifr.swf", sColor:"#000000", sLinkColor:"#000000", sBgColor:"#ffffff", sHoverColor:"#CCCCCC", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0", sWmode:"transparent"}));
	};
	
	Shadowbox.setup();
}

// SUBMIT
function submitForm(act)
{
	var o = document.getElementById('actiune');
	if(o) o.value = act;
	document.forms[0].submit();
}