	var rates=[[41,48,52],[44,51,55],[47,54,58],[53,62,66],[47,54,58],[44,51,55],[41,48,52],[38,45,49]];
	var rateDates=[new Date(2012,8,4,0,0,0,0).getTime(),new Date(2012,7,24,0,0,0,0).getTime(),new Date(2012,7,18,0,0,0,0).getTime(),new Date(2012,7,8,0,0,0,0).getTime(),new Date(2012,7,1,0,0,0,0).getTime(),new Date(2012,6,10,0,0,0,0).getTime(),new Date(2012,5,16,0,0,0,0).getTime(),new Date(2012,4,15,0,0,0,0).getTime()];
	var messages=["ATTENZIONE: Inserire la data!","ATTENZIONE: Errore nelle date!","ATTENZIONE: Troppe persone per camera!","Il costo della tua vacanza corrisponde a: euro "];

if(document.location.href.indexOf('/de/')>-1){
messages=["ACHTUNG: Datum eingeben!","ACHTUNG: Falsches Datum!","ACHTUNG: zu viele Personen pro Zimmer!","Der Gesamtbetrag Ihres Urlaubs entspricht: euro "];
}else if(document.location.href.indexOf('/en/')>-1){
messages=["WARNING: Insert the information!","WARNING: Data error!","WARNING: too many people per room!","The cost of your holiday is: euro "];
}

function calculator(){

	var startDate;
	var endDate;
	var mode=document.getElementById("mode").value;
	var total=0;
	var threedays=false;
	var msg="";

	if(document.getElementById("sel1").value=="" || document.getElementById("sel3").value==""){
		msg=messages[0];
	}else{
		var startDateFields=document.getElementById("sel3").value.split("/");
		startDate=new Date(startDateFields[2],startDateFields[1]-1,startDateFields[0],0,0,0,0);
		startDate=startDate.getTime();
		var endDateFields=document.getElementById("sel1").value.split("/");
		endDate=new Date(endDateFields[2],endDateFields[1]-1,endDateFields[0],0,0,0,0);
		endDate=endDate.getTime();

		if( (startDate+86400000) > endDate){
			msg=messages[1];
		}else if((document.getElementById("camera1-1").value*1+document.getElementById("camera1-3").value*1+document.getElementById("camera1-4").value*1)>5 || (document.getElementById("camera2-1").value*1+document.getElementById("camera2-3").value*1+document.getElementById("camera2-4").value*1)>5){
			msg=messages[2];
		}else{
			if(endDate-startDate<(86400000*3)){
				threedays=true;
			}
			for(var i in rateDates){
			while(endDate>rateDates[i] && endDate>startDate){
				if( (document.getElementById("camera1-1").value*1) > 2){
					total=total+(rates[i][mode]*2);
					total=total+(rates[i][mode]*(document.getElementById("camera1-1").value*1-2)*0.9);
				}else{
					total=total+(rates[i][mode]*(document.getElementById("camera1-1").value*1));
				}
				if( (document.getElementById("camera2-1").value*1) > 2){
					total=total+(rates[i][mode]*2);
					total=total+(rates[i][mode]*(document.getElementById("camera2-1").value*1-2)*0.9);
				}else{
					total=total+(rates[i][mode]*(document.getElementById("camera2-1").value*1));
				}
				if((document.getElementById("camera1-1").value*1)>0){
					total=total+(rates[i][mode]*0.4)*(document.getElementById("camera1-3").value*1);
					total=total+(rates[i][mode]*0.6)*(document.getElementById("camera1-4").value*1);
				}else{	
					total=total+rates[i][mode]*(document.getElementById("camera1-3").value*1+document.getElementById("camera1-4").value*1);
				}
				if((document.getElementById("camera2-1").value*1)>0){
					total=total+(rates[i][mode]*0.4)*(document.getElementById("camera2-3").value*1);
					total=total+(rates[i][mode]*0.6)*(document.getElementById("camera2-4").value*1);
				}else{	
					total=total+rates[i][mode]*(document.getElementById("camera2-3").value*1+document.getElementById("camera2-4").value*1);
				}
				endDate=endDate-86400000;
			}
			}
			if(threedays==true){
				total=total+(10*(document.getElementById("camera1-1").value*1+document.getElementById("camera1-3").value*1+document.getElementById("camera1-4").value*1+document.getElementById("camera2-1").value*1+document.getElementById("camera2-3").value*1+document.getElementById("camera2-4").value*1));
			}
			total=total+(9*(document.getElementById("camera1-2").value*1+document.getElementById("camera2-2").value*1));
			msg=messages[3]+Math.round(total);
		}
	}
		document.getElementById('result').innerHTML=msg;
		_gaq.push(['_trackEvent','Calculator',msg]);
}

