
	/**************cookie handling************************/

	
	//to clear default field value
	function clearText(thefield){
		if (thefield.defaultValue==thefield.value)
			thefield.value = ""
	} 
	
	function setBackText(thefield){
		if (thefield.value=="")
			thefield.value = thefield.defaultValue;
	} 
	

	function calcDays(date1,date2){
	  date1 = date1.split(".");
	  date2 = date2.split(".");
	  
	  var sDate = new Date(date1[1]+"/"+date1[0]+"/"+date1[2]);
	  var eDate = new Date(date2[1]+"/"+date2[0]+"/"+date2[2]);
	  var daysApart = Math.abs(Math.round((sDate-eDate)/86400000));
	  return daysApart;
	}	
	
	function update_price_field(){
		if (document.vehicle_form.date_from.value && document.vehicle_form.date_to.value){
			if (document.vehicle_form.vehicle.value){
				var cost=calcDays(document.vehicle_form.date_from.value,document.vehicle_form.date_to.value)*prices[document.vehicle_form.vehicle.value];
				document.vehicle_form.price_field.value=curr(cost)+' kn ('+curr(cost/7.3)+' Eur)';
			} else
				LightBox({delay:4000,msg:"Vozilo nije označeno!",mode:'errors'});
		}
	}

	function curr(num) {
		num = num.toString().replace(/\$|\,/g,'');
		if(isNaN(num))
			num = "0";
			
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
		
		if(cents<10)
			cents = "0" + cents;
			
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+'.'+
			
		num.substring(num.length-(4*i+3));
		
		return (((sign)?'':'-') +  num + ',' + cents);
	}	
	
	
	
	function common() {	
	

	
		//login module
		$("#top_cont form input[type='text']").livequery("focus",function(){
			clearText(this);							   
		});
		$("#top_cont form input[type='text']").livequery("blur",function(){
			setBackText(this);							   
		});		
	
		$("#top_cont form input").livequery("keydown",function(e){
			if (e.keyCode==13)		 
				this.parentNode.submit();						   				
		});
		
		$("#top_cont form").livequery("submit",function(e){
			$("#top_cont form input[type='text']").livequery(function(){
				clearText(this);							   
			});					   
		});












		$("table.table_skinned tr:odd").addClass("rw"); 



		$(".vehicles_form").livequery("submit",function(){
			input_field=$("input",this);
			
			clearText(input_field[0]);										 						
			clearText(input_field[1]);										 									

		});
		
		$(".vehicles_form input[class='inputf']").livequery("focus",function(){
			clearText(this);
		});

		$(".vehicles_form input[class='inputf']").livequery("blur",function(){
			setBackText(this);
		});
		
		$(".vehicles_form a").livequery("click",function(){
			if ($(".vehicles_form div").css('display')=='none'){
				$(".vehicles_form div").css({display:'block'});
				$(".vehicles_form a.advanced").css({display:'none'});							
			}else{
				$(".vehicles_form div").css({display:'none'});		
				$(".vehicles_form a.advanced").css({display:'inline-block'});			
			}
				
			return false;
		});
	

	}

	$(document).livequery(common);
