﻿// File JScript
<!--

var http = "http://demo.webreservation.it";
//var http = "http://localhost:1258/webreservation";
var aObj;
var idu;

//inclusione file x calendario
var js=document.createElement("script");
js.setAttribute("language","javascript");
//js.setAttribute("src",http+"/remote/CalendarPopup.js");
js.setAttribute("src",http+"/remote/calendar/calendar.js");
document.getElementsByTagName('head')[0].appendChild(js);
//************ solo x nuovo calendario ************
js=document.createElement("script");
js.setAttribute("language","javascript");
js.setAttribute("src",http+"/remote/calendar/calendar-setup.js");
document.getElementsByTagName('head')[0].appendChild(js);

js=document.createElement("script");
js.setAttribute("language","javascript");
js.setAttribute("src",http+"/remote/calendar/lang/calendar-en.js");
document.getElementsByTagName('head')[0].appendChild(js);
//**************************************************
js=document.createElement("link");
js.setAttribute("rel","stylesheet");
js.setAttribute("type","text/css");
js.setAttribute("href",http+"/remote/calendar/calendar-win2k-cold-1.css");
//js.setAttribute("href",http+"/remote/calendar_style.css");

document.getElementsByTagName('head')[0].appendChild(js);

var cal10;

var divCalendar = document.createElement("div");
divCalendar.setAttribute("id","divCalendar");
divCalendar.setAttribute("class", "divCalendar");
divCalendar.className = "divCalendar";
//############### utility ############################
function isMsie()
{
	return (navigator.userAgent.toLowerCase().indexOf('msie') != -1)
}

function ricarica(evt)
{
	window.location.reload();
}
//###################################################

/*****************************************************
****************** creazione form ricerca ************
*****************************************************/

function createForm(ut)
{
    idu = ut;
	var searchTab;
	var searchTabBody;
	var tblRow;
	var tblCol;
	var txt;
	var input;
	var slc;
	var opt;
	var dateTab,dateTabBody;
	var a;
	
	searchTab = document.createElement("table");	
	searchTab.setAttribute("id","searchTab");
	
	searchTab.setAttribute("class","rmt_tab_ricerca");
	searchTab.className = "rmt_tab_ricerca";
		
	searchTabBody = document.createElement("tbody");
	searchTabBody.setAttribute("id","tbCamere");
	//searchTabBody.setAttribute("class", "remotetesto");
	//searchTabBody.className = "remotetesto";
	searchTab.appendChild(searchTabBody);
	//########### intestazione colonne tabella ricerca ##################
	tblRow = document.createElement("tr");
	
	tblCol = document.createElement("td");
	tblCol.setAttribute("width","33%");
	tblCol.setAttribute("align","center");
	
	
	txt = document.createTextNode("n Camere");
	tblCol.appendChild(txt);
	input = document.createElement("input")
	input.setAttribute("id","fhNCamere")
	input.setAttribute("type","hidden")
	input.setAttribute("value","1")
	tblCol.appendChild(input);
	//++++++ id +++++++
	input = document.createElement("input")
	input.setAttribute("id","rmtid")
	input.setAttribute("type","hidden")
	input.setAttribute("value",ut)
	tblCol.appendChild(input);
	tblRow.appendChild(tblCol);
	
	tblCol = document.createElement("td");
	tblCol.setAttribute("width","34%");
	tblCol.setAttribute("align","center");
	txt = document.createTextNode("n Adulti");
	tblCol.appendChild(txt);
	tblRow.appendChild(tblCol);
	
	
	tblCol = document.createElement("td");
	tblCol.setAttribute("width","33%");
	tblCol.setAttribute("align","center");
	txt = document.createTextNode("n Bambini");
	tblCol.appendChild(txt);
	
	tblRow.appendChild(tblCol);
	
	
	searchTabBody.appendChild(tblRow);
	//########### FINE intestazione colonne tabella ricerca ##################
	
	//########### riga numero camere e persone camera 1 ##################
	tblRow = document.createElement("tr");
	tblRow.setAttribute("id","trCam1");
	
	tblCol = document.createElement("td");
	tblCol.setAttribute("width","33%");
	tblCol.setAttribute("align","center");
	//###### select ###############
	slc = document.createElement("select");
	slc.setAttribute("id","slcCamere");
	
	for(var i=1;i<=5;i++)
	{
		opt = document.createElement("option");
		opt.setAttribute("value",i);
		txt = document.createTextNode(i);
		opt.appendChild(txt);
		slc.appendChild(opt);
	}
	slc.setAttribute("class","rmt_campo_combo");
	slc.className = "rmt_campo_combo";
	slc.onchange = AddCamera;//selectNCamere;
	tblCol.appendChild(slc);
	//###### fine select ##########
	tblRow.appendChild(tblCol);
	
	tblCol = document.createElement("td");
	tblCol.setAttribute("width","34%");
	tblCol.setAttribute("align","center");
	//###### select ###############
	slc = document.createElement("select");
	slc.setAttribute("id","slcAdulti1");
	for(var i=0;i<=5;i++)
	{
		opt = document.createElement("option");
		opt.setAttribute("value",i);
		txt = document.createTextNode(i);
		opt.appendChild(txt);
		slc.appendChild(opt);
	}
	slc.setAttribute("class","rmt_campo_combo");
	slc.className = "rmt_campo_combo";
	tblCol.appendChild(slc);
	//###### fine select ##########
	tblRow.appendChild(tblCol);
	
	tblCol = document.createElement("td");
	tblCol.setAttribute("width","33%");
	tblCol.setAttribute("align","center");
	//###### select ###############
	slc = document.createElement("select");
	slc.setAttribute("id","slcBambini1")
	for(var i=0;i<=5;i++)
	{
		opt = document.createElement("option");
		opt.setAttribute("value",i);
		txt = document.createTextNode(i);
		opt.appendChild(txt);
		slc.appendChild(opt);
	}
	slc.setAttribute("class","rmt_campo_combo");
	slc.className = "rmt_campo_combo";
	slc.onchange = AddEtaBambini;
	tblCol.appendChild(slc);
	//###### fine select ##########
	tblRow.appendChild(tblCol);
	
	searchTabBody.appendChild(tblRow);
	//########### FINE tabella ricerca ##################
	
	
	
	//################## tabella date e tasto cerca #####################
	dateTab = document.createElement("table");
	dateTab.setAttribute("id","dateTab");
	dateTab.setAttribute("class","rmt_tab_ricerca");
	dateTab.className = "rmt_tab_ricerca";
	
	dateTabBody = document.createElement("tbody");
	dateTabBody.setAttribute("id","tbDate");
	//dateTabBody.setAttribute("class", "remotetesto");
	//dateTabBody.className = "remotetesto";
	dateTab.appendChild(dateTabBody);
	
	//########### riga date e tasto cerca ##################
	tblRow = document.createElement("tr");
	tblCol.setAttribute("id","trDate");
	tblCol = document.createElement("td");
	tblCol.setAttribute("width","40%");
	tblCol.setAttribute("align","center");
	//####### input dal
	tblCol.appendChild(document.createTextNode("dal "));
	input = document.createElement("input");
	input.setAttribute("type","text");
	input.setAttribute("id","dal");
	input.setAttribute("name","dal");
	input.setAttribute("class","rmt_campo_box");
	input.className = "rmt_campo_box";
	//input.setAttribute("value",today());
	var data = new Date(); 	
	var giorno = (data.getDate()<10?"0" + data.getDate():data.getDate());
	var mese = ((data.getMonth()+1)<10?"0" + (data.getMonth()+1):(data.getMonth()+1));
	input.setAttribute("value",giorno+"/"+mese+"/" +data.getFullYear());
	input.setAttribute("size","11");
	input.setAttribute("maxlenght","10");
	 
	tblCol.appendChild(input);
	/* calendario dal */
	tblCol.appendChild(document.createTextNode(" "));
	a = document.createElement("a");
	a.setAttribute("id","adal");
	a.setAttribute("href","javascript:;");
	a.onclick = visualizzaCalendario;
	
	input = document.createElement("img");
	input.setAttribute("id","imgdal");
	input.setAttribute("border","0");
	input.setAttribute("src",http+"/remote/img/calendar.gif");
	//a.appendChild(input); x vecchio calendario
	
	tblCol.appendChild(input);// per vecchio calendario -> tblCol.appendChild(a);
	//###### input dal##########
	tblRow.appendChild(tblCol);
	
	tblCol = document.createElement("td");
	tblCol.setAttribute("width","40%");
	tblCol.setAttribute("align","center");
	//####### input al
	tblCol.appendChild(document.createTextNode("al "));
	input = document.createElement("input");
	input.setAttribute("type","text");
	input.setAttribute("class","rmt_campo_box");
	input.className = "rmt_campo_box";
	input.setAttribute("id","al");
	input.setAttribute("name","al");
	input.setAttribute("size","11");
	input.setAttribute("maxlenght","10");
	giorno = ((data.getDate()+1)<10?"0" + (data.getDate()+1):data.getDate()+1);	
	input.setAttribute("value",giorno+"/"+mese+"/" +data.getFullYear());
	tblCol.appendChild(input);
	//###### input al##########
	
	
	/* calendario dal */
	tblCol.appendChild(document.createTextNode(" "));
	a = document.createElement("a");
	a.setAttribute("id","aal");
	a.setAttribute("href","javascript:;");
	a.onclick = visualizzaCalendario;
	
	input = document.createElement("img");
	input.setAttribute("id","imgal");
	input.setAttribute("border","0");
	input.setAttribute("src",http+"/remote/img/calendar.gif");
	//a.appendChild(input); x vecchio calendario
	
	tblCol.appendChild(input);//x vecchio calendario ->  tblCol.appendChild(a);
	/******************************/
	tblRow.appendChild(tblCol);
	
	tblCol = document.createElement("td");
	tblCol.setAttribute("width","20%");
	tblCol.setAttribute("align","center");
	//####### input cerca
	input = document.createElement("input");
	input.setAttribute("type","button");
	input.setAttribute("id","cerca");
	input.setAttribute("value","Cerca");
	input.setAttribute("class","rmt_campo_cerca");
	input.className = "rmt_campo_cerca";	
	input.onclick = callRemote;
	tblCol.appendChild(input);
	//####### input cerca
	tblRow.appendChild(tblCol);
	
	dateTabBody.appendChild(tblRow);
	//####################################################################
	//#### aggiungo al div principale ###################################
	var container = document.getElementById("rmtbkg");
	var form = document.createElement("form");
	form.setAttribute("id","searchForm");
	form.appendChild(searchTab);
	form.appendChild(dateTab);
	container.appendChild(form);
	
	
	var loading = document.createElement("div");
	/*loading.setAttribute("class","rmt_loading");
	loading.className = "rmt_loading";*/
	if (isMsie())
	{	
		loading.style.position = "relative"
		loading.style.paddingTop = 1;
	}
	else
		loading.style.position = "inherit";
	
	var img = document.createElement("img");
	img.setAttribute("src",http+"/remote/img/bigrotation2.gif");
	loading.appendChild(document.createElement("br"));
	loading.appendChild(document.createElement("br"));
	loading.appendChild(img);
	loading.appendChild(document.createElement("br"));
	loading.appendChild(document.createElement("br"));
	loading.appendChild(document.createTextNode("Attendere. Elaborazione in corso..."));
	loading.appendChild(document.createElement("br"));
	loading.appendChild(document.createTextNode("(se l'applicazione non risponde per molto tempo premi F5 per aggiornare la pagina)"));
	loading.style.display = "none";
	loading.setAttribute("id","loading");
	container.appendChild(loading);
	
	document.getElementsByTagName("body")[0].appendChild(divCalendar);
    
    /*/########## script per  vecchio calendario #######
    cal10 = new CalendarPopup("divCalendar");
	cal10.showNavigationDropdowns();*/
	
	//**************** inizializzazione nuovo calendario *******
	
	Calendar.setup({
        inputField     :    "dal",     // id of the input field
        ifFormat       :    "%d/%m/%Y",      // format of the input field
        daFormat       :    "%d/%m/%Y",
        button         :    "imgdal",  // trigger for the calendar (button ID)
        align          :    "c1",           // alignment (defaults to "Bl")
        singleClick    :    true
    });
    
    Calendar.setup({
        inputField     :    "al",     // id of the input field
        ifFormat       :    "%d/%m/%Y",      // format of the input field
        daFormat       :    "%d/%m/%Y",
        button         :    "imgal",  // trigger for the calendar (button ID)
        align          :    "c1",           // alignment (defaults to "Bl")
        singleClick    :    true
    });
}



//aggiunta righe in base al numero camere indicato dal cliente
function EliminaVoce(tabella,oggetto)
{		

	var riga = document.getElementById(oggetto);
	var tbl=document.getElementById(tabella);		
	tbl.removeChild(riga);
}
	
function AddCamera(evt)
{
    var controllo;
	if (!evt)
	{
		evt = event;
		controllo = evt.srcElement;
	}
	else
	{
		controllo = evt.target;
	}
	
	var n_camere = controllo.value;
			
	for(i=2;i<=n_camere;i++)
	{
		if(!document.getElementById("trCam" + i))
		{
			var trCamera = document.createElement("tr");
			trCamera.setAttribute("id","trCam" + i);
			
			var tdCamere = document.createElement("td");
			tdCamere.setAttribute("height","10");
			tdCamere.setAttribute("width","33%");
			tdCamere.setAttribute("align","center");
			tdCamere.innerHTML = "camera N " + i;			
			trCamera.appendChild(tdCamere);			
					
			var tdAdulti = document.createElement("td");
			tdAdulti.setAttribute("height","10");
			tdAdulti.setAttribute("width","33%");
			tdAdulti.setAttribute("align","center");
			
			var slcAdulti = document.createElement("select");
			slcAdulti.setAttribute("class","rmt_campo_combo");
			slcAdulti.className = "rmt_campo_combo";
			slcAdulti.setAttribute("id","slcAdulti" + i);
			slcAdulti.setAttribute("name","slcAdulti" + i);	
						
			for(var j=0;j<=5;j++)
			{
				opt = document.createElement("option");
				opt.setAttribute("value",j);
				txt = document.createTextNode(j);
				opt.appendChild(txt);
				slcAdulti.appendChild(opt);
			}				
			tdAdulti.appendChild(slcAdulti);				
			trCamera.appendChild(tdAdulti);	
			
			var tdBambini = document.createElement("td");
			tdBambini.setAttribute("height","10");
			tdBambini.setAttribute("width","33%");
			tdBambini.setAttribute("align","center");
			
			var slcBambini = document.createElement("select");
			slcBambini.setAttribute("class","rmt_campo_combo");
			slcBambini.className = "rmt_campo_combo";
			slcBambini.setAttribute("id","slcBambini" + i);	
			slcBambini.setAttribute("name","slcBambini" + i);	
			for(var j=0;j<=5;j++)
			{
				opt = document.createElement("option");
				opt.setAttribute("value",j);
				txt = document.createTextNode(j);
				opt.appendChild(txt);
				slcBambini.appendChild(opt);
			}
			slcBambini.onchange = AddEtaBambini;

			tdBambini.appendChild(slcBambini);				
			trCamera.appendChild(tdBambini);	
			
			document.getElementById("tbCamere").appendChild(trCamera);	
						
		}
	}
	
	//elimino le vecchie righe
	var old_camere = document.getElementById("fhNCamere").value;	
		
	for(var k=parseInt(n_camere)+1; k<=parseInt(old_camere); k++)
	{		
		
		var max_bambini = document.getElementById("slcBambini" + k).options.length;;
		
		for(var j=1; j<max_bambini; j++)
		{				
			if(document.getElementById("txtBambini_" + k + "_" + j))
			{
				EliminaVoce("tdBambini" + k,"txtBambini_" + k + "_" + j);
				EliminaVoce("tdBambini" + k,"lblBambini_" + k + "_" + j);
			}
		}	
		
		if(document.getElementById("trBambini" + k)) 
		    EliminaVoce("tbCamere","trBambini" + k);
		EliminaVoce("tbCamere","trCam" + k);
	}
		
	document.getElementById("fhNCamere").value = n_camere;
}

function AddEtaBambini(evt)
{
    var controllo;
    var n_cam;
	if (!evt)
	{
		evt = event;
		controllo = evt.srcElement;
	}
	else
	{
		controllo = evt.target;
	}

    n_cam = parseInt(controllo.id.substr(controllo.id.indexOf("slcBambini")+10));
    
    var n_bambini = parseInt(controllo.value);
	var max_bambini = 5;
	var max_camere = document.getElementById("slcCamere").options.length;	
	
	if(n_bambini==0)
	{			
		if(document.getElementById("trBambini" + n_cam)) 
		{
			EliminaVoce("tbCamere","trBambini" + n_cam);
		}
	}
	else
	{
		var trBambini = document.getElementById("trBambini" + n_cam);
		var tdBambini = null;
		if(!document.getElementById("trBambini" + n_cam))
		{
			trBambini = document.createElement("tr");
			trBambini.setAttribute("id","trBambini" + n_cam);
			
			tdBambini = document.createElement("td");
			tdBambini.setAttribute("height","10");
			tdBambini.setAttribute("width","100%");
			tdBambini.setAttribute("align","left");
			tdBambini.colSpan ="3";
			tdBambini.setAttribute("id","tdBambini" + n_cam);
		}
		else
		{
			tdBambini = trBambini.getElementsByTagName("td").item(0);				
		}
		
		for(var i=1; i<=n_bambini; i++)
		{
			if(!document.getElementById("txtBambini_" + n_cam + "_" + i))
			{
				var lblBambini = document.createElement("label");
				lblBambini.setAttribute("id","lblBambini_" + n_cam + "_" + i);
				lblBambini.appendChild(document.createTextNode("Età Bambino " + i + " "));					
				txtBambini = document.createElement("input");
				txtBambini.setAttribute("id","txtBambini_" + n_cam + "_" + i);
				txtBambini.setAttribute("name","txtBambini_" + n_cam + "_" + i);
				txtBambini.setAttribute("type","text");
				txtBambini.setAttribute("class","rmt_campo_box");
				txtBambini.className = "rmt_campo_box";					
				txtBambini.setAttribute("size","2");
				txtBambini.maxLength = 2;
				txtBambini.onkeypress = new Function("if ((event.keyCode < 48 || event.keyCode > 57) && event.keyCode != 46 ) event.returnValue = false");
				
				tdBambini.appendChild(lblBambini);
				tdBambini.appendChild(txtBambini);
			}
		}
		trBambini.appendChild(tdBambini);
		
		for(var j=parseInt(n_bambini)+1; j<=max_bambini; j++)
		{				
			if(document.getElementById("txtBambini_" + n_cam + "_" + j))
			{
				EliminaVoce("tdBambini" + n_cam,"txtBambini_" + n_cam + "_" + j);
				EliminaVoce("tdBambini" + n_cam,"lblBambini_" + n_cam + "_" + j);
			}
		}			
		
		if(!document.getElementById("trBambini" + n_cam))
		{
			var tbCamere = document.getElementById("tbCamere");
			var ind_riga_suc = parseInt(n_cam) + 1;				
			var riga_succ = document.getElementById("trCam" + ind_riga_suc);
			
			if(riga_succ)
				tbCamere.insertBefore(trBambini, riga_succ);
			else
				tbCamere.appendChild(trBambini);
		}
	}
}

//***********************************************************************

function callRemote(evt)
{
	
	var request = http+"/remote/search.aspx";
	
	var searchFrom = document.getElementById("searchForm");
	if (checkData(document.getElementById("dal").value) && checkData(document.getElementById("al").value))
	{
	    if(confrontaDate(document.getElementById("dal").value,document.getElementById("al").value))
	    {
	    var parametri = "dal=" + document.getElementById("dal").value.replace(/\057/g,"-") +"&al=" + document.getElementById("al").value.replace(/\057/g,"-") +"&u=" + document.getElementById("rmtid").value +"&n=" + document.getElementById("slcCamere").value +"&a1=" + document.getElementById("slcAdulti1").value +"&b1=" + document.getElementById("slcBambini1").value ;
    	
	    var a = true;
	    var b = true;
	    var c = true;
	    var d = true;
	    var e = true;
    	
    	
	    a = ((parseInt(document.getElementById("slcAdulti1").value) + parseInt(document.getElementById("slcBambini1").value)) > 0)
    	if(document.getElementById("slcBambini1").value > 0)
        {
            for(var i=1;i<=document.getElementById("slcBambini1").value;i++)
                parametri += "&eb1"+i+"=" + document.getElementById("txtBambini_1_" + i).value ;
        }
        
	    if(parseInt(document.getElementById("slcCamere").value) > 1) 
	    {
	        parametri += "&a2=" + document.getElementById("slcAdulti2").value +"&b2=" + document.getElementById("slcBambini2").value ;
	        if(document.getElementById("slcBambini2").value > 0)
	        {
	            for(var i=1;i<=document.getElementById("slcBambini2").value;i++)
	                parametri += "&eb2"+i+"=" + document.getElementById("txtBambini_2_" + i).value ;
	        }
	        
	        b = ((parseInt(document.getElementById("slcAdulti2").value) + parseInt(document.getElementById("slcBambini2").value)) > 0)
	    }
	    if(parseInt(document.getElementById("slcCamere").value) > 2)
	    {
	        parametri += "&a3=" + document.getElementById("slcAdulti3").value +"&b3=" + document.getElementById("slcBambini3").value ;
	        if(document.getElementById("slcBambini3").value > 0)
	        {
	            for(var i=1;i<=document.getElementById("slcBambini3").value;i++)
	                parametri += "&eb3"+i+"=" + document.getElementById("txtBambini_3_" + i).value ;
	        }
	        c = ((parseInt(document.getElementById("slcAdulti3").value) + parseInt(document.getElementById("slcBambini3").value)) > 0)
	    }
	    if(parseInt(document.getElementById("slcCamere").value) > 3) 
	    {
	        parametri += "&a4=" + document.getElementById("slcAdulti4").value +"&b4=" + document.getElementById("slcBambini4").value ;
	        if(document.getElementById("slcBambini4").value > 0)
	        {
	            for(var i=1;i<=document.getElementById("slcBambini4").value;i++)
	                parametri += "&eb4"+i+"=" + document.getElementById("txtBambini_4_" + i).value ;
	        }
	        d = ((parseInt(document.getElementById("slcAdulti4").value) + parseInt(document.getElementById("slcBambini4").value)) > 0)
	    }
	    if(parseInt(document.getElementById("slcCamere").value) > 4) 
	    {
	        parametri += "&a5=" + document.getElementById("slcAdulti5").value +"&b5=" + document.getElementById("slcBambini5").value ;
	        if(document.getElementById("slcBambini5").value > 0)
	        {
	            for(var i=1;i<=document.getElementById("slcBambini5").value;i++)
	                parametri += "&eb5"+i+"=" + document.getElementById("txtBambini_5_" + i).value ;
	        }
	        e = ((parseInt(document.getElementById("slcAdulti5").value) + parseInt(document.getElementById("slcBambini5").value)) > 0)
	    }
    	
	    if (a && b && c && d && e)
	    {
		    document.getElementById("searchTab").style.display = "none";
		    document.getElementById("dateTab").style.display = "none";
		    document.getElementById("loading").style.display = "inline";
    		
		    request += "?"+parametri;
		    aObj = new JSONscriptRequest(request);
    		aObj.buildScriptTag();
		    aObj.addScriptTag();
		    
		    //document.write(request);
	    }
	    else
		    alert("Selezionare almeno una persona per camera!");
	    }
	    else
	        alert("La Data di Partenza deve essere successiva a quella di Arrivo!");
	}
	else
		alert("Formato date non corretto! (dd/mm/aaaa)");
}

function checkData(stringa)
{
    var res = false;
    var espressione = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
    if (!espressione.test(stringa))	
    {
        res =  false;	
    }
    else
    {
        var anno = parseInt(stringa.substr(6),10);
        var mese = parseInt(stringa.substr(3, 2),10);
        var giorno = parseInt(stringa.substr(0, 2),10);
        var data = new Date(anno, mese-1, giorno);
        
        if(data.getFullYear()== anno && (data.getMonth()+1) == mese && data.getDate()== giorno)
        {
            res = true;
        }
        else
        {
            res = false;
        }
    }
    return res;
}

function confrontaDate(dal,al)
{
    var anno1 = parseInt(dal.substr(6),10);
    var mese1 = parseInt(dal.substr(3, 2),10);
    var giorno1 = parseInt(dal.substr(0, 2),10);
    var anno2 = parseInt(al.substr(6),10);
    var mese2 = parseInt(al.substr(3, 2),10);
    var giorno2 = parseInt(al.substr(0, 2),10);
    
    var dat1 = new Date(anno1, mese1-1, giorno1);
    var dat2 = new Date(anno2, mese2-1, giorno2);
    
    return(dat1 < dat2);
}
 //####################################################################
 
 function showRes(jsonData)
{
	
	var parser;
	var inizio,fine;
	xmlDoc = jsonData;
	try
	{
		
		if(xmlDoc)
		{
			inizio = "dal: "+xmlDoc.inizio.substr(0,10);
			fine = "al: "+xmlDoc.fine.substr(0,10);
			
			if(xmlDoc.struttura != null && xmlDoc.struttura.length > 0)
			{
				
				var graybox,tab,tabBody,tblRow,tblCol,img,a,p,text,nColonne,slc,opt,input,div;
				
				graybox = document.createElement("div");
				graybox.setAttribute("class","rmt_graybox");
				graybox.className = "rmt_graybox";
				
				tab = document.createElement("table");
				tab.setAttribute("id","tabres");
				tab.setAttribute("class","rmt_tab_risultato");
				tab.className = "rmt_tab_risultato";
				tabBody = document.createElement("tbody");
				tab.appendChild(tabBody);
				var strutture = xmlDoc.struttura;
	
				for(var i=0;i<strutture.length;i++)
				{
				    if(strutture[i] != null)
					{
					var id_struttura = strutture[i].id;
					
					tblRow = document.createElement("tr");//nome foto descrizione struttura
					tblCol = document.createElement("td");//colonna x foto
					tblCol.setAttribute("width","25%");
					tblCol.setAttribute("align","center");
					tblCol.setAttribute("valign","middle");					
					//a = document.createElement("a");
					//a.setAttribute("href","http://");//url struttura !?
					img = document.createElement("img");
					img.setAttribute("src",strutture[i].img);
					
					img.setAttribute("border","0");
					//a.appendChild(img)
					tblCol.appendChild(img);
					tblCol.appendChild(document.createElement("br"));
					txt = document.createTextNode(inizio);
					tblCol.appendChild(txt);
					tblCol.appendChild(document.createElement("br"));
					txt = document.createTextNode(fine);
					tblCol.appendChild(txt);
					tblRow.appendChild(tblCol);
					//##########################################################
					tblCol = document.createElement("td");//col x nome struttura,stelle descr
					tblCol.setAttribute("width","75%");
					var primaRicerca = strutture[i].ricerca[0];
					
					nColonne = (primaRicerca.n == primaRicerca.su)?4:3;
					tblCol.colSpan = nColonne
					
					p = document.createElement("p");
					p.setAttribute("class", "rmt_intestazione_hotel");
					p.className = "rmt_intestazione_hotel";
					txt = document.createTextNode(strutture[i].nome+" ");//nome struttura
					p.appendChild(txt);
					
					img = document.createElement("img");
					img.setAttribute("src",http+"/remote/img/"+strutture[i].stelle);//url immagine struttura
					//txt = document.createTextNode(strutture[i].getAttribute("stelle"));//stelle
					p.appendChild(img);
					p.appendChild(document.createElement("br"));
					tblCol.appendChild(p);
					p = document.createElement("p");
					p.setAttribute("align","left");
					txt = document.createTextNode(strutture[i].descrizione);//descrizione
					p.appendChild(txt);
					tblCol.appendChild(p);
					tblRow.appendChild(tblCol);
					tabBody.appendChild(tblRow);
					//##### intestazione righe camere ###############à
					tblRow = document.createElement("tr");
					
					tblCol = document.createElement("td");
					tblCol.setAttribute("width",((nColonne == 4)?"20%":"25%"));
					tblCol.setAttribute("align","center");
					tblCol.setAttribute("class", "rmt_intestazione_campi_risultato");
					tblCol.className = "rmt_intestazione_campi_risultato";
					txt = document.createTextNode("Tipo Camera");
					tblCol.appendChild(txt);
					tblRow.appendChild(tblCol);
					
					tblCol = document.createElement("td");
					tblCol.setAttribute("class", "rmt_intestazione_campi_risultato");
					tblCol.className = "rmt_intestazione_campi_risultato";
					tblCol.setAttribute("width",((nColonne == 4)?"20%":"25%"));
					tblCol.setAttribute("align","center");					
					txt = document.createTextNode("Persone");
					tblCol.appendChild(txt);
					tblRow.appendChild(tblCol);
					
					tblCol = document.createElement("td");
					tblCol.setAttribute("class", "rmt_intestazione_campi_risultato");
					tblCol.className = "rmt_intestazione_campi_risultato";
					tblCol.setAttribute("width",((nColonne == 4)?"20%":"25%"));
					tblCol.setAttribute("align","center");
					txt = document.createTextNode("Trattamento");
					tblCol.appendChild(txt);
					tblRow.appendChild(tblCol);
					
					tblCol = document.createElement("td");
					tblCol.setAttribute("class", "rmt_intestazione_campi_risultato");
					tblCol.className = "rmt_intestazione_campi_risultato";
					tblCol.setAttribute("width",((nColonne == 4)?"20%":"25%"));
					tblCol.setAttribute("align","center");					
					txt = document.createTextNode("Costo Camera");
					tblCol.appendChild(txt);
					tblRow.appendChild(tblCol);
					
					if(nColonne == 4)
					{
						tblCol = document.createElement("td");
						tblCol.setAttribute("width","20%");
						tblCol.setAttribute("align","center");
						tblCol.setAttribute("class", "remoteintestazione");
					tblCol.setAttribute("className", "remoteintestazione");
						tblRow.appendChild(tblCol);
					}
					tabBody.appendChild(tblRow);
					//####### righe camere #################
					if(nColonne == 4)//caso ricerca camera singola
					{
						var ricerca = strutture[i].ricerca[0];
						var camere = ricerca.camera;
						if(camere.length > 0)
						{
							for(var j=0;j<camere.length;j++)
							{
								var id_camera = camere[j].id;
								tblRow = document.createElement("tr")
								//######### nome camera ########
								tblCol = document.createElement("td");
								tblCol.setAttribute("align","center");
								tblCol.setAttribute("class", "rmt_testo_camera");
								tblCol.className = "rmt_testo_camera";
								txt = document.createTextNode(camere[j].nome);
								tblCol.appendChild(txt);
								tblRow.appendChild(tblCol);
								//##### riepilogo persone
								tblCol = document.createElement("td");
								tblCol.setAttribute("align","center");
								tblCol.setAttribute("class", "rmt_testo_persone");
								tblCol.className = "rmt_testo_persone";
								if(camere[j].a != "0")
								{
									txt = document.createTextNode("Adulti: "+camere[j].a);
									tblCol.appendChild(txt);
									tblCol.appendChild(document.createElement("br"));
								}
								if(camere[j].b != "0")
								{
									txt = document.createTextNode("Bambini: "+camere[j].b);
									tblCol.appendChild(txt);
									tblCol.appendChild(document.createElement("br"));
								}
								if(camere[j].n != "0")
								{
									txt = document.createTextNode("Neonati: "+camere[j].n);
									tblCol.appendChild(txt);
								}
								tblRow.appendChild(tblCol);
								//###### dropdown trattamenti#####
								tblCol = document.createElement("td");
								tblCol.setAttribute("class", "rmt_testo_persone");
								tblCol.setAttribute("className", "rmt_testo_persone");
								slc = document.createElement("select");
								slc.setAttribute("class", "rmt_campo_combo");
								slc.className = "rmt_campo_combo";
								slc.setAttribute("id","trattamento_"+camere[j].id_real); //id_trattamento
								slc.onchange = switchtratt;
								var trattamenti = camere[j].trattamento;								
								var costo_minimo = 1000000;
								for(var k=0;k<trattamenti.length;k++)
								{
									opt = document.createElement("option");
									opt.setAttribute("value",trattamenti[k].tipo);
									opt.appendChild(document.createTextNode(trattamenti[k].nome));
									
									if(parseFloat(trattamenti[k].costo.replace(",",".")) < costo_minimo)
									{
										if(slc.selectedIndex >= 0)
										{
											slc[slc.selectedIndex].selected = false;
										}
										opt.selected = true;
										costo_minimo = parseFloat(trattamenti[k].costo.replace(",","."))
									}
									slc.appendChild(opt);
								}
								tblCol.appendChild(slc);
								
								input = document.createElement("input");
								input.setAttribute("id","adulti_"+camere[j].id_real);
								input.setAttribute("type","hidden");
								input.setAttribute("value",camere[j].a);
								tblCol.appendChild(input);
								
								input = document.createElement("input");
								input.setAttribute("id","bambini_"+camere[j].id_real);
								input.setAttribute("type","hidden");
								input.setAttribute("value",camere[j].b);
								tblCol.appendChild(input);
								
								input = document.createElement("input");
								input.setAttribute("id","neonati_"+camere[j].id_real);
								input.setAttribute("type","hidden");
								input.setAttribute("value",camere[j].n);
								tblCol.appendChild(input);
								
								input = document.createElement("input");
								input.setAttribute("id","tariffa_"+camere[j].id_real);
								input.setAttribute("type","hidden");
								input.setAttribute("value",camere[j].tariffa);
								tblCol.appendChild(input);
								
								tblRow.appendChild(tblCol);
								//############ costo camera ########
								tblCol = document.createElement("td");
								tblCol.setAttribute("align","center");
								tblCol.className = "rmt_testo_costo_camera";
								tblCol.setAttribute("align","center");								
								tblCol.setAttribute("id","costo_"+camere[j].id_real);
								txt = document.createTextNode(costo_minimo.toFixed(2)+" €");
								tblCol.appendChild(txt);
								tblRow.appendChild(tblCol);
								//#########################
								//############ tasto prenota ########
								tblCol = document.createElement("td");
								tblCol.setAttribute("align","center");
								tblCol.setAttribute("class", "rmt_testo_prenota");
								tblCol.className = "rmt_testo_prenota";
								
								input = document.createElement("input");
								input.setAttribute("type","button");
								input.setAttribute("id",id_struttura+"-1-"+xmlDoc.inizio.substr(0,10)+"-"+xmlDoc.fine.substr(0,10)+"-"+strutture[i].notti+"-"+camere[j].id_real);
								input.onclick = prenota;
								input.setAttribute("value","Prenota");
								input.setAttribute("class", "rmt_campo_prenota");
								input.className = "rmt_campo_prenota";								
								tblCol.appendChild(input);
								tblRow.appendChild(tblCol);
								//#########################
								
								tabBody.appendChild(tblRow);
								
								
							}
							tblRow = document.createElement("tr");
							tblCol = document.createElement("td");
							tblCol.setAttribute("height","20");
							tblCol.colSpan = 5;
							tblRow.appendChild(tblCol);
							tabBody.appendChild(tblRow);
							tabBody.appendChild(tblRow);
							
							tblRow = document.createElement("tr");
							tblCol = document.createElement("td");
							tblCol.style.backgroundImage = "url("+http+"/remote/img/divise.jpg)";
							tblCol.colSpan = 5;
							tblRow.appendChild(tblCol);
							tabBody.appendChild(tblRow);
						}
						else//nessuna camera caso anomalo
						{
							alert("ERR 02: Formato risposta non valido");
							alert(stringa);
						}
					}
					else //caso ricerca più camere
					{
						var ricerche;
						ricerche = strutture[i].ricerca;
						if(ricerche.length > 0)
						{
							var costoTotale;
							costoTotale = 0;
							for(var j=0;j<ricerche.length;j++)
							{
								tblRow = document.createElement("tr")
								//######### nome camera ########
								tblCol = document.createElement("td");
								tblCol.setAttribute("align","center");
								tblCol.setAttribute("class", "rmt_testo_camera");
								tblCol.className = "rmt_testo_camera";
								//##### slc tipologia camera######
								var camere,adulti,bambini,neonati;
								camere = ricerche[j].camera;
								slc = document.createElement("select");
								slc.id = "slcCam_"+id_struttura+"_"+j;
								slc.onchange = Aggiorna_camere;
								slc.setAttribute("class", "rmt_campo_combo");
								slc.className = "rmt_campo_combo";
								for(var k=0;k<camere.length;k++)
								{
									adulti = camere[k].a;
									bambini = camere[k].b;
									neonati = camere[k].n;
									
									opt = document.createElement("option");
									opt.value = camere[k].id_real+"_"+camere[k].disponibili+"_"+camere[k].tariffa;
									opt.appendChild(document.createTextNode(camere[k].nome+" ("+camere[k].disponibili+" disponibili)"));
									slc.appendChild(opt);
								}
								tblCol.appendChild(slc);
								tblRow.appendChild(tblCol);
								
								//######### riepilogo persone ########
								tblCol = document.createElement("td");
								tblCol.setAttribute("align","center");
								tblCol.setAttribute("class", "rmt_testo_camera");
								tblCol.className = "rmt_testo_camera";
								//##### ######
								if(adulti != "0")
								{
									txt = document.createTextNode("Adulti: "+adulti);
									tblCol.appendChild(txt);
									tblCol.appendChild(document.createElement("br"));
								}
								if(bambini != "0")
								{
									txt = document.createTextNode("Bambini: "+bambini);
									tblCol.appendChild(txt);
									tblCol.appendChild(document.createElement("br"));
								}
								if(neonati != "0")
								{
									txt = document.createTextNode("Neonati: "+neonati);
									tblCol.appendChild(txt);
								}
								
								input = document.createElement("input");
								input.setAttribute("id","txtA_"+id_struttura+"_"+j);
								input.setAttribute("type","hidden");
								input.setAttribute("value",adulti);
								tblCol.appendChild(input);
								
								input = document.createElement("input");
								input.setAttribute("id","txtB_"+id_struttura+"_"+j);
								input.setAttribute("type","hidden");
								input.setAttribute("value",bambini);
								tblCol.appendChild(input);
								
								input = document.createElement("input");
								input.setAttribute("id","txtN_"+id_struttura+"_"+j);
								input.setAttribute("type","hidden");
								input.setAttribute("value",neonati);
								tblCol.appendChild(input);
								
								tblRow.appendChild(tblCol);
								
								//######### trattamenti ########
								tblCol = document.createElement("td");
								tblCol.setAttribute("align","center");
								tblCol.setAttribute("class", "rmt_testo_camera");
								tblCol.className = "rmt_testo_camera";
								//##### slc trattamenti relativi alla camera selezionata ######
								var trattamenti = ricerche[j].camera[0].trattamento;
								var costo_minimo = 100000000;
								
								slc = document.createElement("select");
								slc.id = "slcTratt_"+id_struttura+"_"+j;
								slc.setAttribute("class", "rmt_campo_combo");
								slc.className = "rmt_campo_combo";
								slc.onchange = getCostoCameraMultipla;
								for(var x=0;x<trattamenti.length;x++)
								{
									opt = document.createElement("option");
									opt.value = trattamenti[x].tipo;
									opt.appendChild(document.createTextNode(trattamenti[x].nome));
									if(parseFloat(trattamenti[x].costo.replace(",",".")) < costo_minimo)
									{
										if(slc.selectedIndex >= 0)
										{
											slc[slc.selectedIndex].selected = false;
										}
										opt.selected = true;
										costo_minimo = parseFloat(trattamenti[x].costo.replace(",","."))
									}
									slc.appendChild(opt);
								}
								tblCol.appendChild(slc);
								tblRow.appendChild(tblCol);
								
								//######### costo ########
								tblCol = document.createElement("td");
								tblCol.setAttribute("align","center");
								tblCol.setAttribute("class", "rmt_testo_costo_camera");
								tblCol.className = "rmt_testo_costo_camera";
								//##### costo camera con trattamento ######
								tblCol.setAttribute("id","totXCam_"+id_struttura+"_"+j);
								txt = document.createTextNode(costo_minimo.toFixed(2)+" €");
								tblCol.appendChild(txt);
								input = document.createElement("input");
								input.setAttribute("id","costo_"+id_struttura+"_"+j);
								input.setAttribute("type","hidden");
								input.setAttribute("value",costo_minimo);
								tblCol.appendChild(input);
								
								
								tblRow.appendChild(tblCol);
								
								//#########################
								
								tabBody.appendChild(tblRow);
								costoTotale += costo_minimo;
							}
							
							tblRow = document.createElement("tr");
							tblCol = document.createElement("td");
							tblCol.colSpan = 2;
							tblRow.appendChild(tblCol);
							
							tblCol = document.createElement("td");
							tblCol.setAttribute("class", "rmt_intestazione_campi_risultato");
							tblCol.className = "rmt_intestazione_campi_risultato";
							tblCol.setAttribute("align","right");
							tblCol.appendChild(document.createTextNode("Totale"));
							tblRow.appendChild(tblCol);
							
							tblCol = document.createElement("td");
							tblCol.setAttribute("class", "rmt_testo_costo_camera");
							tblCol.setAttribute("className", "rmt_testo_costo_camera");
							tblCol.setAttribute("align","center");
							tblCol.setAttribute("id","tot_"+id_struttura);
							tblCol.appendChild(document.createTextNode(costoTotale+" €"));
							
							tblRow.appendChild(tblCol);
							tabBody.appendChild(tblRow);
							
							tblRow = document.createElement("tr");
							tblCol = document.createElement("td");
							tblCol.setAttribute("align","right");
							tblCol.colSpan = 4;
							input = document.createElement("input");
							input.setAttribute("type","button");
							
							input.setAttribute("id",id_struttura+"_"+j+"_"+xmlDoc.inizio.substr(0,10)+"_"+xmlDoc.fine.substr(0,10));
							input.onclick = quotation;
							input.setAttribute("value","Prenota");
							tblCol.appendChild(input);
							input = document.createElement("input");
							input.setAttribute("type","hidden");
							
							input.setAttribute("id","notti_"+id_struttura);
							input.setAttribute("value",strutture[i].notti);
							tblCol.appendChild(input);
							tblRow.appendChild(tblCol);
							tabBody.appendChild(tblRow);
							//####### separatore tratteggiato ####################
							
							tblRow = document.createElement("tr");
							tblCol = document.createElement("td");
							tblCol.style.backgroundImage = "url("+http+"/remote/img/divise.jpg)";
							tblCol.colSpan = 4;
							tblRow.appendChild(tblCol);
							tabBody.appendChild(tblRow);
						}
						else
						{//caso anomalo
							alert("ERR 001: Formato risposta non valido");
						}
					}
					}//fine if oggenno struttura nullo
					
				}
				
				var container = document.getElementById("rmtbkg");
				div = document.createElement("div");
				div.setAttribute("align","center");
				div.setAttribute("width","100%");
				div.setAttribute("class", "rmt_reset");
				div.className = "rmt_reset";	
				div.style.cursor = "pointer";
				div.onclick = ricarica;
				div.appendChild(document.createTextNode("Effettua nuova ricerca"))
				container.appendChild(div);
				container.appendChild(tab);
				document.getElementById("loading").style.display = "none";
				
				graybox.appendChild(container);
				document.getElementsByTagName("body")[0].appendChild(graybox);
				aObj.removeScriptTag();
			}
			else//non ci sono risultati
			{
			    container = document.getElementById("rmtbkg");
			   //########### creo contenitore del messaggio
	            var messaggio = document.createElement("div");
	            messaggio.setAttribute("height","110");
	            messaggio.setAttribute("align","center");
	            messaggio.setAttribute("class", "rmt_testo_prenotazione_eseguita");
	            messaggio.className = "rmt_testo_prenotazione_eseguita";
	            //########### creo immagine
	            var img = document.createElement("img");
	            img.setAttribute("src",http+"/remote/img/warning.png");
	            img.setAttribute("border","0");
	            img.setAttribute("height","32");
	            img.setAttribute("width","32");
	            messaggio.appendChild(document.createElement("br"));
	            messaggio.appendChild(document.createElement("br"));
	            messaggio.appendChild(img);
	            //########## inserisco messaggio testuale
	            messaggio.appendChild(document.createElement("br"));
	            messaggio.appendChild(document.createElement("br"));
	            messaggio.appendChild(document.createTextNode("Siamo spiacenti. Nessuna Soluzione per la configurazione cercata."));
	            
            	
	            //########## inserisco link per nuova ricerca
	            var child = document.createElement("div");
	            child.setAttribute("align","center");
	            child.style.cursor = "pointer";		
	            child.setAttribute("class", "rmt_testo_link");
	            child.className = "rmt_testo_link";	
	            child.appendChild(document.createTextNode("Effettua una nuova ricerca"));
	            child.onclick = ricarica;
            	
	            messaggio.appendChild(child);
            	
	            //########## inserisco il messaggio completo nel contenitore
	            container.appendChild(messaggio);
	            document.getElementById("loading").style.display = "none";
			}   
		}
		else
		{
			alert("ERR 01: Formato risposta non valido");
			alert(stringa);
		}
	}
	catch(e)
	{
		alert(e.message);
	}
	
		
}

function switchtratt(evt)
{
	var slc;
	if (!evt)
	{
		evt = event;
		slc = evt.srcElement;
	}
	else
	{
		slc = evt.target;
	}
	
	var id_real_camera = slc.id.split("_")[1];
	var camere;
	//camere = xmlDoc.getElementsByTagName("camera");
	var trovato = false;
	var trattamento;
	
	var i, j , n , m;
	i=0;
	
	while(!trovato && (i < xmlDoc.struttura.length))
	{
		
		j=0;
		while(!trovato && (j < xmlDoc.struttura[i].ricerca.length))
		{
			n=0;
			while(!trovato && (n < xmlDoc.struttura[i].ricerca[j].camera.length))
			{
				if(xmlDoc.struttura[i].ricerca[j].camera[n].id_real == id_real_camera)
				{
					m=0;
					while(!trovato && (m < xmlDoc.struttura[i].ricerca[j].camera[n].trattamento.length))
					{
						if(xmlDoc.struttura[i].ricerca[j].camera[n].trattamento[m].tipo == slc.value)
						{
							document.getElementById("costo_"+id_real_camera).firstChild.nodeValue = parseInt(xmlDoc.struttura[i].ricerca[j].camera[n].trattamento[m].costo).toFixed(2).replace(",",".")+" €" ;																									  						trovato = true;	
						}
						
						m++;
					}
				}
				n++;
			}
			j++;
		}
		i++;
		
	}
}

function getCostoCameraMultipla(evt)
{
	var slc,slcCam;
	if (!evt)
	{
		evt = event;
		slc = evt.srcElement;
	}
	else
	{
		slc = evt.target;
	}
	
	slcCam = document.getElementById(slc.id.replace("slcTratt_","slcCam_"));
	
	
	id_struttura = slcCam.id.split("_")[1];
	nCamera  = slcCam.id.split("_")[2];
	id_camera = slcCam.value.split("_")[0];
	
	//alert(slcCam.id+"-"+slcCam.value+"-"+slc.id+"-"+slc.value);
	
	var strutture;
	strutture = xmlDoc.struttura;
	var j;
	j=0;
	while(strutture[j].id != id_struttura)
		j++;
	
	var ricerca;
	ricerca = strutture[j].ricerca[nCamera];
	
	var camere;
	camere = ricerca.camera;
	var k;
	k=0;
	while(camere[k].id_real != id_camera)
		k++;
	var trattamenti;
	trattamenti = camere[k].trattamento;
	
	var y;
	y=0;
	while(trattamenti[y].tipo != slc.value)
		y++;
	//alert(trattamenti[y].firstChild.nodeValue);
	
	costo  = parseFloat(trattamenti[y].costo.replace(",","."));
	
	document.getElementById("costo_"+id_struttura+"_"+nCamera).value = costo;
	document.getElementById("totXCam_"+id_struttura+"_"+nCamera).firstChild.nodeValue = costo.toFixed(2)+" €";
	
	totale = 0;
	for(var i=0;i<5;i++)
	{
		if(document.getElementById("costo_"+id_struttura+"_"+i))
		{
			totale = totale + parseFloat(document.getElementById("costo_"+id_struttura+"_"+i).value);
		}
		
	}
	document.getElementById("tot_"+id_struttura).firstChild.nodeValue = parseFloat(totale).toFixed(2) + " €";
}

function Aggiorna_camere(evt)
{
	var slc,slcTratt;
	if (!evt)
	{
		evt = event;
		slc = evt.srcElement;
	}
	else
	{
		slc = evt.target;
	}
	
	var id_struttura,id_camera,nCamera;
	
	id_struttura = slc.id.split("_")[1];
	id_camera = slc.value.split("_")[0];
	nCamera = slc.id.split("_")[2];
	
	var strutture;
	strutture = xmlDoc.struttura;
	var j;
	j=0;
	while(strutture[j].id != id_struttura)
		j++;
	
	var ricerca;
	ricerca = strutture[j].ricerca;
	
	var camere;
	camere = ricerca[nCamera].camera;
	var k;
	k=0;
	while(camere[k].id_real != id_camera)
		k++;
	
	
	var trattamenti;
	trattamenti = camere[k].trattamento;
	
	temp = document.getElementById("slcTratt_"+id_struttura+"_"+nCamera);
	//elimino le vecchie tariffe
	for (m=temp.options.length-1;m>=0;m--)
		temp.options[m]=null;
		
	for(var i=0;i<trattamenti.length;i++)
	{
		
		temp.options[i]=new Option(trattamenti[i].nome,trattamenti[i].tipo)
		if(i == 0)
		{//
			temp.options[i].selected = true;
			document.getElementById("costo_"+id_struttura+"_"+nCamera).value = trattamenti[i].costo.replace(",",".");
			document.getElementById("totXCam_"+id_struttura+"_"+nCamera).firstChild.nodeValue = parseFloat(trattamenti[i].costo.replace(",",".")).toFixed(2)+" €";
		}
		
	}
	
	totale = 0;
	for(var i=0;i<5;i++)
	{
		if(document.getElementById("costo_"+id_struttura+"_"+i))
		{
			totale = totale + parseFloat(document.getElementById("costo_"+id_struttura+"_"+i).value);
		}
		
	}
	document.getElementById("tot_"+id_struttura).firstChild.nodeValue = totale.toFixed(2) + " €";
		
}

function prenota(evt)
{
	var input,id_struttura,camere,dal,al,notti,id_real_camera;
	if (!evt)
	{
		evt = event;
		input = evt.srcElement;
	}
	else
	{
		input = evt.target;
	}
	
	id_struttura = input.id.split("-")[0];
	camere = input.id.split("-")[1];
	dal = input.id.split("-")[2].replace(/\057/g,"-");
	al = input.id.split("-")[3].replace(/\057/g,"-");
	notti = input.id.split("-")[4];
	id_real_camera = input.id.split("-")[5];

	
	var querystring = "?str="+id_struttura+"&n="+camere+"&dal="+dal+"&al="+al+"&nt="+notti;
	var disponibili = 1;
	
	var tariffa  = document.getElementById('tariffa_'+id_real_camera).value;
	var slc = document.getElementById('trattamento_'+id_real_camera);
	
	var trattamento  = slc[document.getElementById('trattamento_'+id_real_camera).selectedIndex].value.replace("&","-");
	var adulti  = document.getElementById('adulti_'+id_real_camera).value;
	var bambini  = document.getElementById('bambini_'+id_real_camera).value;
	var neonati  = document.getElementById('neonati_'+id_real_camera).value;
	querystring += "&cam0="+id_real_camera+"_"+1+"_"+tariffa+"_"+trattamento+"_"+adulti+"_"+bambini+"_"+neonati;
	
	//location.href = "hotel-quotation.aspx?"+querystring;
	akkia(querystring);
	
	
}
 
function akkia(querystring)
{
	
	var url = http+"/remote/quotation.aspx";
    //alert("1304 : "+querystring);
	
	document.getElementById("tabres").style.display = "none";
	document.getElementById("loading").style.display = "inline";
	aObj = new JSONscriptRequest(url+querystring);
	aObj.buildScriptTag();
	aObj.addScriptTag(); 
}

function quotation(evt)
{
	var input,id_struttura,camere,dal,al,notti,id_real_camera;
	if (!evt)
	{
		evt = event;
		input = evt.srcElement;
	}
	else
	{
		input = evt.target;
	}
	
	var id_struttura,n_camere,dal,al; //parametri
	id_struttura = input.id.split("_")[0];
	n_camere = input.id.split("_")[1] ;
	dal = input.id.split("_")[2].replace(/\057/g,"-") ;
	al = input.id.split("_")[3].replace(/\057/g,"-") ;
	
	var i,cam,camera,persone,trattamento,querystring,notti,j,presente,prosegui;
	cam = "";
	notti = document.getElementById("notti_"+id_struttura).value;
	i=0;
	j = 0;
	presente = false;
	prosegui = true;
	var camere;
		camere = new Array();
	var disponibilita;
		disponibilita = new Array();
	var richiesta;
		richiesta = new Array();
	
	for(i=0;i<parseInt(n_camere);i++)
	{//alert(id_struttura+" "+n_camere+" "+dal+" "+al);
		camera = document.getElementById("slcCam_"+id_struttura+"_"+i).value;
		trattamento = document.getElementById("slcTratt_"+id_struttura+"_"+i).options[document.getElementById("slcTratt_"+id_struttura+"_"+i).selectedIndex].value.replace("&","-")
		persone = document.getElementById("txtA_"+id_struttura+"_"+i).value+"_"+document.getElementById("txtB_"+id_struttura+"_"+i).value+"_"+document.getElementById("txtN_"+id_struttura+"_"+i).value;
		cam += "&cam"+i+"="+camera+"_"+trattamento+"_"+persone;	
		
		if(i>0)
		{
			presente = false;
			for(j=0;j<(i);j++)
			{
				if(camere[j] == camera.split("_")[0])
				{
					presente = true;
					richiesta[j] = (richiesta[j] + 1);
				}
			}
			if(presente == false)
			{
				camere[i] = camera.split("_")[0];
				disponibilita[i] = camera.split("_")[1];
				richiesta[i] = 1;
			}
		}
		else
		{
			camere[i] = camera.split("_")[0];
			disponibilita[i] = camera.split("_")[1];
			richiesta[i] = 1;
		}
		
	}
	querystring = "?str="+id_struttura+"&n="+n_camere+"&dal="+dal+"&al="+al+"&nt="+notti+cam;
	//alert(camere[0]+" "+disponibilita[0]+" "+richiesta[0]);
	for(i=0;i<camere.length;i++)
	{
		if(disponibilita[i] < richiesta[i])
			prosegui = false;
	}
	if(prosegui)
		//location.href = "hotel-quotation.aspx"+querystring;
		akkia(querystring);
	else
		alert("Per proseguire scegliere la tipologia delle camere in accordo con la disponibilità");
	
		
}


function riepilogo(XMLString)
	{
		
		
		var inizio,fine,nomeStruttura,notti,id_struttura;
		
		xmlDoc = XMLString;
		try
		{
			
			
			if(xmlDoc.struttura)
			{
				inizio = "dal: "+xmlDoc.struttura.dal.substr(0,10);
				fine = "al: "+xmlDoc.struttura.al.substr(0,10);
				nomeStruttura = xmlDoc.struttura.nome;
				notti = xmlDoc.struttura.notti;
				id_struttura = xmlDoc.struttura.id;
				
				if(xmlDoc.camera.length > 0)
				{
					
					var form,tab,tabBody,tblRow,tblCol,img,a,p,text,nColonne,slc,opt,input;
					form = document.createElement("form");
					form.setAttribute("id","formdett");
					tab = document.createElement("table");
					tab.setAttribute("id","tabDett");
					tab.setAttribute("class", "rmt_tab_riepilogo");
					tab.className = "rmt_tab_riepilogo";
					tabBody = document.createElement("tbody");
					tab.appendChild(tabBody);
					var camere = xmlDoc.camera;
					
					tblRow = document.createElement("tr");
					
					tblCol = document.createElement("td");
					tblCol.colSpan = 5;
					tblCol.setAttribute("align","center");
					tblCol.setAttribute("class", "rmt_intestazione_riepilogo");
					tblCol.className = "rmt_intestazione_riepilogo";
					txt = document.createTextNode("'" + nomeStruttura + "'" + " Riepilogo Soggiorno "+inizio+" "+fine);
					tblCol.appendChild(txt);
					//##############
					input = document.createElement("input");
					input.setAttribute("id","dal");
					input.setAttribute("type","hidden");
					input.setAttribute("value",xmlDoc.struttura.dal.substr(0,10));
					tblCol.appendChild(input);
					//##############
					//##############
					input = document.createElement("input");
					input.setAttribute("id","al");
					input.setAttribute("type","hidden");
					input.setAttribute("value",xmlDoc.struttura.al.substr(0,10));
					tblCol.appendChild(input);
					//##############
					
					tblRow.appendChild(tblCol);
					tabBody.appendChild(tblRow);
					
					//################ intestazione righe camere ##############
					tblRow = document.createElement("tr");
						
					tblCol = document.createElement("td");
					tblCol.setAttribute("width","35%");
					tblCol.setAttribute("align","center");
					tblCol.setAttribute("class", "rmt_intestazione_prenotazione");
					tblCol.className = "rmt_intestazione_prenotazione";
					txt = document.createTextNode("Tipo Camera");
					tblCol.appendChild(txt);
					tblRow.appendChild(tblCol);
					
					tblCol = document.createElement("td");
					tblCol.setAttribute("width","5%");
					tblCol.setAttribute("align","center");
					tblCol.setAttribute("class", "rmt_intestazione_prenotazione");
					tblCol.className = "rmt_intestazione_prenotazione";
					txt = document.createTextNode("Notti");
					tblCol.appendChild(txt);
					tblRow.appendChild(tblCol);
					tblCol = document.createElement("td");
					tblCol.setAttribute("width","10%");
					tblCol.setAttribute("align","center");
					tblCol.setAttribute("class", "rmt_intestazione_prenotazione");
					tblCol.className = "rmt_intestazione_prenotazione";
					txt = document.createTextNode("n° Pax");
					tblCol.appendChild(txt);
					tblRow.appendChild(tblCol);
					
					tblCol = document.createElement("td");
					tblCol.setAttribute("width","20%");
					tblCol.setAttribute("align","center");
					tblCol.setAttribute("class", "rmt_intestazione_prenotazione");
					tblCol.className = "rmt_intestazione_prenotazione";
					txt = document.createTextNode("Trattamento");
					tblCol.appendChild(txt);
					tblRow.appendChild(tblCol);
					
					tblCol = document.createElement("td");
					tblCol.setAttribute("width","30%");
					tblCol.setAttribute("align","center");
					tblCol.setAttribute("class", "rmt_intestazione_prenotazione");
					tblCol.className = "rmt_intestazione_prenotazione";
					txt = document.createTextNode("Costo Giornaliero");
					tblCol.appendChild(txt);
					tblRow.appendChild(tblCol);
					
					tabBody.appendChild(tblRow);
		
					var costoTotale;
					costoTotale = 0;
					var caparraTotale;
					caparraTotale = 0;
					for(var i=0;i<camere.length;i++)
					{
						//##### righe camere ###############à
						tblRow = document.createElement("tr");
						
						tblCol = document.createElement("td");
						tblCol.setAttribute("width","35%");
						tblCol.setAttribute("align","center");
						tblCol.setAttribute("class", "rmt_righe_camera");
						tblCol.className = "rmt_righe_camera";
						txt = document.createTextNode(camere[i].nome);
						tblCol.appendChild(txt);
						//##############
						input = document.createElement("input");
						input.setAttribute("id","txtCamera"+i);
						input.setAttribute("type","hidden");
						input.setAttribute("value",camere[i].id);
						tblCol.appendChild(input);
						//##############
						tblRow.appendChild(tblCol);
						
						tblCol = document.createElement("td");
						tblCol.setAttribute("width","5%");
						tblCol.setAttribute("align","center");
						tblCol.setAttribute("class", "rmt_righe_camera");
						tblCol.className = "rmt_righe_camera";
						txt = document.createTextNode(notti);
						tblCol.appendChild(txt);
						tblRow.appendChild(tblCol);
						
						tblCol = document.createElement("td");
						tblCol.setAttribute("width","10%");
						tblCol.setAttribute("align","center");
						tblCol.setAttribute("class", "rmt_righe_camera");
						tblCol.className = "rmt_righe_camera";
						if(camere[i].a != "0")
						{
							txt = document.createTextNode("Adulti: "+camere[i].a);
							tblCol.appendChild(txt);
							tblCol.appendChild(document.createElement("br"));
						}
						//#########
						input = document.createElement("input");
						input.setAttribute("id","txtAdulti"+i);
						input.setAttribute("type","hidden");
						input.setAttribute("value",camere[i].a);
						tblCol.appendChild(input);
						//###########
						if(camere[i].b != "0")
						{
							txt = document.createTextNode("Bambini: "+camere[i].b);
							tblCol.appendChild(txt);
							tblCol.appendChild(document.createElement("br"));
						}
						//#########
						input = document.createElement("input");
						input.setAttribute("id","txtBambini"+i);
						input.setAttribute("type","hidden");
						input.setAttribute("value",camere[i].b);
						tblCol.appendChild(input);
						//###########
						if(camere[i].n != "0")
						{
							txt = document.createTextNode("Neonati: "+camere[i].n);
							tblCol.appendChild(txt);
						}
						//#########
						input = document.createElement("input");
						input.setAttribute("id","txtNeonati"+i);
						input.setAttribute("type","hidden");
						input.setAttribute("value",camere[i].n);
						tblCol.appendChild(input);
						//###########
						tblRow.appendChild(tblCol);
						
						tblCol = document.createElement("td");
						tblCol.setAttribute("width","20%");
						tblCol.setAttribute("align","center");
						tblCol.setAttribute("class", "rmt_righe_camera");
						tblCol.className = "rmt_righe_camera";
						txt = document.createTextNode(camere[i].trattamento.nome);
						tblCol.appendChild(txt);
						//#########
						input = document.createElement("input");
						input.setAttribute("id","trattamento"+i);
						input.setAttribute("type","hidden");
						input.setAttribute("value",camere[i].trattamento.tipo);
						tblCol.appendChild(input);
						//###########
						tblRow.appendChild(tblCol);
						
						tblCol = document.createElement("td");
						tblCol.setAttribute("width","30%");
						tblCol.setAttribute("align","center");
						tblCol.setAttribute("class", "rmt_righe_camera");
						tblCol.className = "rmt_righe_camera";
						txt = document.createTextNode(camere[i].costogiornaliero+" Euro");
						tblCol.appendChild(txt);
						//### campi hidden #########
						input = document.createElement("input");
						input.setAttribute("id","percCapCam_"+i);
						input.setAttribute("type","hidden");
						input.setAttribute("value",camere[i].caparra.perc);
						tblCol.appendChild(input);
						//###########################################
						input = document.createElement("input");
						input.setAttribute("id","costoCam_"+i);
						input.setAttribute("type","hidden");
						input.setAttribute("value",camere[i].costo.totale);
						tblCol.appendChild(input);
						//### fine campi hidden #########
						tblRow.appendChild(tblCol);
						tabBody.appendChild(tblRow);
						
						//###### inserisci qui gestione supplementi ########
						
						var id_servizi_obbligatori = "";
						
						if(camere[i].servizi)
						{
						    for(var j in camere[i].servizi)
						    {
						        var S = camere[i].servizi[j];
						        if(S.invisibile == "NO")
						        {
						            tblRow = document.createElement("tr");
    						        
						            tblCol = document.createElement("td");
						            tblCol.setAttribute("class", "rmt_itestazione_suprid");
						            tblCol.className = "rmt_itestazione_suprid";
						            txt = document.createTextNode(S.tipo);
						            tblCol.appendChild(txt);
    						        
						            tblRow.appendChild(tblCol);
						            //######
						            tblCol = document.createElement("td");
						            tblCol.setAttribute("class", "rmt_righe_camera");
						            tblCol.className = "rmt_righe_camera";
						            if(S.obbligatorio == "NO")
						            {
						                input = document.createElement("input");
						                input.setAttribute("id","ckbServizio-"+i+"-"+j);
						                input.setAttribute("type","checkbox");
						                input.setAttribute("value",S.id);
						                input.onclick = supplemento;
						            }
						            else
						            {
						                input = document.createElement("img");
						                input.setAttribute("id","ckbServizio-"+i+"-"+j);
						                input.setAttribute("alt","Servizio Obbligatorio (incluso nel costo giornaliero)");
						                input.setAttribute("src",http+"/immagini/obbligatorio.jpg");
						                
						                if(id_servizi_obbligatori != "")
						                    id_servizi_obbligatori += ",";
						                id_servizi_obbligatori += S.id;
						            }
						            tblCol.appendChild(input);
						            //############## campo hidden costo supplemento o riduzione
						            input = document.createElement("input");
						            input.setAttribute("id","costoServizio-"+i+"-"+j);
						            input.setAttribute("type","hidden");
						            
						            if(S.tipo != "RIDUZIONE")
						                input.value = S.costo
						            else
						                input.value = "-"+S.costo
    						        tblCol.appendChild(input);
    						        //##########################################################
						            tblRow.appendChild(tblCol);
						            //######
						            tblCol = document.createElement("td");
						            tblCol.colSpan = 2;
						            tblCol.setAttribute("class", "rmt_righe_camera");
						            tblCol.className = "rmt_righe_camera";
						            txt = document.createTextNode(S.servizio);
						            tblCol.appendChild(txt);
    						        
						            tblRow.appendChild(tblCol);
						            //######
						            tblCol = document.createElement("td");
						            tblCol.setAttribute("class", "rmt_righe_camera");
						            tblCol.className = "rmt_righe_camera";
						            txt = document.createTextNode(parseFloat(input.value).toFixed(2)+" €");
						            tblCol.appendChild(txt);
    						        
						            tblRow.appendChild(tblCol);
						            //######
						            tabBody.appendChild(tblRow);
						        }
						        else
						        {
						            if(id_servizi_obbligatori != "")
						                id_servizi_obbligatori += ",";
						            id_servizi_obbligatori += S.id;
						        }
						    }
						    
						}
						//########### separatore ###############
						tblRow = document.createElement("tr");
						tblCol = document.createElement("td");
						tblCol.colSpan = 5;
						tblCol.setAttribute("align","center");
						tblCol.setAttribute("class", "remotetesto");
						tblCol.className = "remotetesto";
						tblCol.setAttribute("height","20");
						txt = document.createTextNode(" ");
						tblCol.appendChild(txt);
						//############## campo idden per supplementi e riduzioni
						input = document.createElement("input");
						input.setAttribute("id","txtSupRid"+i);
						input.setAttribute("type","hidden");
						input.value = id_servizi_obbligatori;
						tblCol.appendChild(input);
						//##############
						tblRow.appendChild(tblCol);
						tabBody.appendChild(tblRow);
						//######################################
						
						
						//###### riepilogo costo camera ########
						tblRow = document.createElement("tr");
						tblCol = document.createElement("td");
						tblCol.colSpan=3;
						tblRow.appendChild(tblCol);
						tabBody.appendChild(tblRow);
						tblCol = document.createElement("td");
						tblCol.setAttribute("align","center");
						tblCol.setAttribute("class", "rmt_intestazione_prenotazione_costi_parziali");
						tblCol.className = "rmt_intestazione_prenotazione_costi_parziali";
						txt = document.createTextNode("Caparra");
						tblCol.appendChild(txt);
						
						//##############
						input = document.createElement("input");
						input.setAttribute("id","txtCaparra"+i);
						input.setAttribute("type","hidden");
						input.setAttribute("value",parseFloat(camere[i].caparra.caparra.replace(",",".")));
						tblCol.appendChild(input);
						//##############
						
						tblRow.appendChild(tblCol);
						tabBody.appendChild(tblRow);
						
						tblCol = document.createElement("td");
						tblCol.setAttribute("align","center");
						tblCol.setAttribute("class", "rmt_text_costi_parziali");
						tblCol.className = "rmt_text_costi_parziali";
						tblCol.setAttribute("id","capCam_"+i);
						txt = document.createTextNode(camere[i].caparra.caparra+" Euro");
						caparraTotale += parseFloat(camere[i].caparra.caparra.replace(",","."));
						tblCol.appendChild(txt);
						
						tblRow.appendChild(tblCol);
						tabBody.appendChild(tblRow);
						tabBody.appendChild(tblRow);
						
						tblRow = document.createElement("tr");
						tblCol = document.createElement("td");
						tblCol.colSpan=3;
						tblRow.appendChild(tblCol);
						tabBody.appendChild(tblRow);
						tblCol = document.createElement("td");
						tblCol.setAttribute("align","center");
						tblCol.setAttribute("class", "rmt_intestazione_prenotazione_costi_parziali");
						tblCol.className = "rmt_intestazione_prenotazione_costi_parziali";
						txt = document.createTextNode("Saldo");
						tblCol.appendChild(txt);
						tblRow.appendChild(tblCol);
						tabBody.appendChild(tblRow);
						tblCol = document.createElement("td");
						tblCol.setAttribute("align","center");
						tblCol.setAttribute("class", "rmt_text_costi_parziali");
						tblCol.className = "rmt_text_costi_parziali";
						tblCol.setAttribute("id","saldoCam_"+i);
						txt = document.createTextNode(camere[i].saldo+" Euro");
						tblCol.appendChild(txt);
						tblRow.appendChild(tblCol);
						tabBody.appendChild(tblRow);
						tabBody.appendChild(tblRow);
						
						tblRow = document.createElement("tr");
						tblCol = document.createElement("td");
						tblCol.colSpan=3;
						tblRow.appendChild(tblCol);
						tabBody.appendChild(tblRow);
						tblCol = document.createElement("td");
						tblCol.setAttribute("align","center");
						tblCol.setAttribute("class", "rmt_intestazione_prenotazione_costi_parziali");
						tblCol.className = "rmt_intestazione_prenotazione_costi_parziali";
						txt = document.createTextNode("Totale");
						tblCol.appendChild(txt);
						//##############
						input = document.createElement("input");
						input.setAttribute("id","txtImporto"+i);
						input.setAttribute("type","hidden");
						input.setAttribute("value",parseFloat(camere[i].costo.totale.replace(",",".")));
						tblCol.appendChild(input);
						//##############
						tblRow.appendChild(tblCol);
						tabBody.appendChild(tblRow);
						tblCol = document.createElement("td");
						tblCol.setAttribute("align","center");
						tblCol.setAttribute("class", "rmt_text_totale_parziale");
						tblCol.className = "rmt_text_totale_parziale";
						tblCol.setAttribute("id","totCam_"+i);
						txt = document.createTextNode(camere[i].costo.totale+" Euro");
						costoTotale += parseFloat(camere[i].costo.totale.replace(",","."));
						tblCol.appendChild(txt);
						
						tblRow.appendChild(tblCol);
						tabBody.appendChild(tblRow);
						tabBody.appendChild(tblRow);
						
						//########### separatore ###############
						tblRow = document.createElement("tr");
						tblCol = document.createElement("td");
						tblCol.colSpan = 5;
						tblCol.setAttribute("align","center");
						/*tblCol.setAttribute("class", "rmt_text_totale_costi");
						tblCol.className = "rmt_text_totale_costi";*/
						tblCol.setAttribute("height","20")
						txt = document.createTextNode(" ");
						tblCol.appendChild(txt);
						
						tblRow.appendChild(tblCol);
						tabBody.appendChild(tblRow);
						
					}
					
					//########### RIEPILOGO ###############
					tblRow = document.createElement("tr");
					tblCol = document.createElement("td");
					tblCol.colSpan = 5;
					tblCol.setAttribute("align","center");
					tblCol.setAttribute("class", "rmt_intestazione_riepilogo");
					tblCol.className = "rmt_intestazione_riepilogo";
					txt = document.createTextNode("Riepilogo Costi. Totale camere : "+camere.length);
					tblCol.appendChild(txt);
					//##############
					input = document.createElement("input");
					input.setAttribute("id","txtCamere");
					input.setAttribute("type","hidden");
					input.setAttribute("value",camere.length);
					tblCol.appendChild(input);
					//##############
					//##############
					input = document.createElement("input");
					input.setAttribute("id","txtStruttura");
					input.setAttribute("type","hidden");
					input.setAttribute("value",id_struttura);
					tblCol.appendChild(input);
					//##############
					tblRow.appendChild(tblCol);
					tabBody.appendChild(tblRow);
					
					tblRow = document.createElement("tr");
					tblCol = document.createElement("td");
					tblCol.colSpan = 5;
					tblCol.setAttribute("align","center");					
					tblCol.setAttribute("height","20")
					txt = document.createTextNode(" ");
					tblCol.appendChild(txt);
					tblRow.appendChild(tblCol);
					tabBody.appendChild(tblRow);
					
					tblRow = document.createElement("tr");
						tblCol = document.createElement("td");
						tblCol.colSpan=3;
						tblRow.appendChild(tblCol);
						tabBody.appendChild(tblRow);
						tblCol = document.createElement("td");
						tblCol.setAttribute("align","center");
						tblCol.setAttribute("class", "rmt_intestazione_prenotazione_costi_totali");
						tblCol.setAttribute("className", "rmt_intestazione_prenotazione_costi_totali");
						txt = document.createTextNode("Caparra");
						tblCol.appendChild(txt);
						tblRow.appendChild(tblCol);
						tabBody.appendChild(tblRow);
						tblCol = document.createElement("td");
						tblCol.setAttribute("align","center");
						tblCol.setAttribute("class", "rmt_text_costi_parziali");
						tblCol.className = "rmt_text_costi_parziali";
						tblCol.setAttribute("id","capTotale");
						txt = document.createTextNode(caparraTotale.toFixed(2)+" Euro");
						
						tblCol.appendChild(txt);
						tblRow.appendChild(tblCol);
						tabBody.appendChild(tblRow);
						tabBody.appendChild(tblRow);
						
							tblRow = document.createElement("tr");
						tblCol = document.createElement("td");
						tblCol.colSpan=3;
						tblRow.appendChild(tblCol);
						tabBody.appendChild(tblRow);
						tblCol = document.createElement("td");
						tblCol.setAttribute("align","center");
						tblCol.setAttribute("class", "rmt_intestazione_prenotazione_costi_totali");
						tblCol.className = "rmt_intestazione_prenotazione_costi_totali";
						txt = document.createTextNode("Saldo");
						tblCol.appendChild(txt);
						tblRow.appendChild(tblCol);
						tabBody.appendChild(tblRow);
						tblCol = document.createElement("td");
						tblCol.setAttribute("align","center");
						tblCol.setAttribute("class", "rmt_text_costi_parziali");
						tblCol.className = "rmt_text_costi_parziali";
						tblCol.setAttribute("id","saldoTotale");
						txt = document.createTextNode((costoTotale-caparraTotale).toFixed(2)+" Euro");
						tblCol.appendChild(txt);
						tblRow.appendChild(tblCol);
						tabBody.appendChild(tblRow);
						tabBody.appendChild(tblRow);
						
						tblRow = document.createElement("tr");
						tblCol = document.createElement("td");
						tblCol.colSpan=3;
						tblRow.appendChild(tblCol);
						tabBody.appendChild(tblRow);
						tblCol = document.createElement("td");
						tblCol.setAttribute("align","center");
						tblCol.setAttribute("class", "rmt_intestazione_prenotazione_costi_totali");
						tblCol.className = "rmt_intestazione_prenotazione_costi_totali";
						txt = document.createTextNode("Totale");
						tblCol.appendChild(txt);
						tblRow.appendChild(tblCol);
						tabBody.appendChild(tblRow);
						tblCol = document.createElement("td");
						tblCol.setAttribute("align","center");
						tblCol.setAttribute("class", "rmt_text_totale_parziale");
						tblCol.className = "rmt_text_totale_parziale";
						tblCol.setAttribute("id","Totale");
						txt = document.createTextNode(costoTotale.toFixed(2)+" Euro");
						 
						tblCol.appendChild(txt);
						tblRow.appendChild(tblCol);
						tabBody.appendChild(tblRow);
						tabBody.appendChild(tblRow);
					//######################################
					//###### dati personali #############
					//########### separatore ###############
					tblRow = document.createElement("tr");
					tblCol = document.createElement("td");
					tblCol.colSpan = 5;
					tblCol.setAttribute("align","center");
					tblCol.setAttribute("class", "rmt_dati_utente");
					tblCol.className = "rmt_dati_utente";
					tblCol.setAttribute("height","20");
					txt = document.createTextNode(" ");
					tblCol.appendChild(txt);
					tblRow.appendChild(tblCol);
					tabBody.appendChild(tblRow);
					//######################################
					tblRow = document.createElement("tr");
					tblCol = document.createElement("td");
					tblCol.colSpan = 5;
					tblCol.setAttribute("align","center");
					tblCol.setAttribute("class", "rmt_intestazione_riepilogo");
					tblCol.className = "rmt_intestazione_riepilogo";
					tblCol.setAttribute("height","20");
					txt = document.createTextNode("Dati Personali per Prenotazione e Pagamento");
					tblCol.appendChild(txt);
					tblRow.appendChild(tblCol);
					tabBody.appendChild(tblRow);
					//########### separatore ###############
					tblRow = document.createElement("tr");
					tblCol = document.createElement("td");
					tblCol.colSpan = 5;
					tblCol.setAttribute("align","center");
					tblCol.setAttribute("class", "rmt_dati_utente");
					tblCol.className = "rmt_dati_utente";
					tblCol.setAttribute("height","20");
					txt = document.createTextNode(" ");
					tblCol.appendChild(txt);
					tblRow.appendChild(tblCol);
					tabBody.appendChild(tblRow);
					//######################################
					tblRow = document.createElement("tr");
					//#### colonna 1 ####
					tblCol = document.createElement("td");
					/*tblCol.colSpan = 1;
					tblCol.setAttribute("align","center");
					tblCol.setAttribute("class", "rmt_dati_utente");
					tblCol.className = "rmt_dati_utente";
					txt = document.createTextNode("Tipo Pagamento : ");
					tblCol.appendChild(txt);*/
					
					tblCol.colSpan = 5;
					tblCol.setAttribute("align","center");
					tblCol.setAttribute("class", "rmt_dati_pagamento");
					tblCol.className = "rmt_dati_pagamento";
					tblCol.setAttribute("height","20");
					
					slc = document.createElement("select");
					slc.setAttribute("id","pagamento");
					slc.setAttribute("class", "rmt_campo_combo");
					slc.className = "rmt_campo_combo";
					
					opt = document.createElement("option");
					opt.setAttribute("value","BB");
					opt.appendChild(document.createTextNode("Bonifico Bancario"));
					slc.appendChild(opt);
					// ########## attivare appena imposti pagina pagamenti paypal ########
					opt = document.createElement("option");
					opt.setAttribute("value","CC");
					opt.appendChild(document.createTextNode("Carta di Credito"));
					slc.appendChild(opt);
					
					opt = document.createElement("option");
					opt.setAttribute("value","PP");
					opt.appendChild(document.createTextNode("PayPal"));
					slc.appendChild(opt);
					
					tblCol.appendChild(slc);
					tblRow.appendChild(tblCol);
					tabBody.appendChild(tblRow);
					
					tblRow = document.createElement("tr");
					
					tblCol = document.createElement("td");
					tblCol.colSpan = 1;
					tblCol.setAttribute("align","center");
					tblCol.setAttribute("class", "rmt_dati_utente");
					tblCol.className = "rmt_dati_utente";
					txt = document.createTextNode("Gift Card : ");
					tblCol.appendChild(txt);
					input = document.createElement("input");
					input.setAttribute("type","text");
					input.setAttribute("id","txtCoupon");
					input.setAttribute("class", "rmt_campo_box");
					input.className = "rmt_campo_box";
					input.setAttribute("size","19");
					tblCol.appendChild(input);
					tblRow.appendChild(tblCol);
					
					tblCol = document.createElement("td");
					tblCol.setAttribute("align","left");
					tblCol.colSpan = 4;
					txt = document.createTextNode(" * se hai ricevuto una Gift Card , inserisci qui il suo codice");
					tblCol.appendChild(txt);
					tblRow.appendChild(tblCol);
					
					tabBody.appendChild(tblRow);
					//######################################
					//#### colonna 1 ####
					tblRow = document.createElement("tr");
					tblCol = document.createElement("td");
					tblCol.colSpan = 1;
					tblCol.setAttribute("align","center");
					tblCol.setAttribute("class", "rmt_dati_utente");
					tblCol.className = "rmt_dati_utente";
					txt = document.createTextNode("nome : ");
					tblCol.appendChild(txt);
					input = document.createElement("input");
					input.setAttribute("type","text");
					input.setAttribute("id","txtNome");
					input.setAttribute("class", "rmt_campo_box");
					input.className = "rmt_campo_box";					
					input.setAttribute("size","19");
					tblCol.appendChild(input);
					tblRow.appendChild(tblCol);
					//#### colonna 2 ####
					tblCol = document.createElement("td");
					tblCol.colSpan = 2;
					tblRow.appendChild(tblCol);
					//#### colonna 3 ####
					tblCol = document.createElement("td");
					tblCol.colSpan = 1;
					tblCol.setAttribute("align","center");
					tblCol.setAttribute("class", "rmt_dati_utente");
					tblCol.className = "rmt_dati_utente";
					txt = document.createTextNode("cognome : ");
					tblCol.appendChild(txt);
					input = document.createElement("input");
					input.setAttribute("type","text");
					input.setAttribute("id","txtCognome");
					input.setAttribute("class", "rmt_campo_box");
					input.className = "rmt_campo_box";
					input.setAttribute("size","19");
					tblCol.appendChild(input);
					tblRow.appendChild(tblCol);
					//#### colonna 4 ####
					tblCol = document.createElement("td");
					tblCol.colSpan = 1;
					
					tblRow.appendChild(tblCol);
					tabBody.appendChild(tblRow);
					//######################################
					tblRow = document.createElement("tr");
					tblCol = document.createElement("td");
					tblCol.colSpan = 1;
					tblCol.setAttribute("align","center");
					tblCol.setAttribute("class", "rmt_dati_utente");
					tblCol.className = "rmt_dati_utente";
					txt = document.createTextNode("telefono : ");
					tblCol.appendChild(txt);
					input = document.createElement("input");
					input.setAttribute("type","text");
					input.setAttribute("id","txtTelefono");
					input.setAttribute("class", "rmt_campo_box");
					input.className = "rmt_campo_box";
					input.setAttribute("size","19");
					tblCol.appendChild(input);
					tblRow.appendChild(tblCol);
					tblCol = document.createElement("td");
					tblCol.colSpan = 2;
					tblRow.appendChild(tblCol);
					tblCol = document.createElement("td");
					tblCol.colSpan = 1;
					tblCol.setAttribute("align","center");
					tblCol.setAttribute("class", "rmt_dati_utente");
					tblCol.className = "rmt_dati_utente";
					txt = document.createTextNode("email : ");
					tblCol.appendChild(txt);
					input = document.createElement("input");
					input.setAttribute("type","text");
					input.setAttribute("id","txtEmail");
					input.setAttribute("class", "rmt_campo_box");
					input.className = "rmt_campo_box";
					input.setAttribute("size","19");
					tblCol.appendChild(input);
					tblRow.appendChild(tblCol);
					tblRow.appendChild(tblCol);
					tblCol = document.createElement("td");
					tblCol.colSpan = 1;
					tabBody.appendChild(tblRow);
					//######################################
					tblRow = document.createElement("tr");
					tblCol = document.createElement("td");
					tblCol.colSpan = 1;
					tblCol.setAttribute("align","center");
					tblCol.setAttribute("class", "rmt_dati_utente");
					tblCol.className = "rmt_dati_utente";
					txt = document.createTextNode("città : ");
					tblCol.appendChild(txt);
					input = document.createElement("input");
					input.setAttribute("type","text");
					input.setAttribute("id","txtCitta");
					input.setAttribute("class", "rmt_campo_box");
					input.className = "rmt_campo_box";
					input.setAttribute("size","19");
					tblCol.appendChild(input);
					tblRow.appendChild(tblCol);
					tblCol = document.createElement("td");
					tblCol.colSpan = 2;
					tblRow.appendChild(tblCol);
					tblCol = document.createElement("td");
					tblCol.colSpan = 1;
					tblCol.setAttribute("align","center");
					tblCol.setAttribute("class", "rmt_dati_utente");
					tblCol.className = "rmt_dati_utente";
					txt = document.createTextNode("nazione : ");
					tblCol.appendChild(txt);
					input = document.createElement("input");
					input.setAttribute("type","text");
					input.setAttribute("id","txtNazione");
					input.setAttribute("class", "rmt_campo_box");
					input.className = "rmt_campo_box";
					input.setAttribute("size","19");
					tblCol.appendChild(input);
					tblRow.appendChild(tblCol);
					tblRow.appendChild(tblCol);
					tblCol = document.createElement("td");
					tblCol.colSpan = 1;
					tabBody.appendChild(tblRow);
					//######################################
					tblRow = document.createElement("tr");
					
					tblCol = document.createElement("td");
					tblCol.colSpan = 5;
					tblCol.setAttribute("align","center");
					
					input = document.createElement("input");
					input.setAttribute("type","button");
					input.setAttribute("id","prenota");
					input.setAttribute("value","Prenota");
					input.setAttribute("class", "rmt_campo_prenota");
					input.className = "rmt_campo_prenota";
					input.onclick = check;
					
					tblCol.appendChild(input);
					
					tblRow.appendChild(tblCol);					
					
					tabBody.appendChild(tblRow);
					//######################################
					
					var container = document.getElementById("rmtbkg");
					form.appendChild(tab);
					container.appendChild(form);
					document.getElementById("loading").style.display = "none";
				}
				else
				{
					alert("ERR 202: Formato risposta non valido");
				}
			}
			else
			{
				alert("ERR 201: Formato risposta non valido \n"+ stringa);
				document.write(stringa);
				
			}
			
		}
		catch(e)
		{
			alert(e.message);
		}
		aObj.removeScriptTag();
	}

function check(evt)
	{
		
		var myForm;
		myForm = document.getElementById("formdett");
		var email2 = /\w+@\w+.+\w{2,4}$/;
		var errMess;
		errMess = "";
		if(myForm.txtNome.value.length == 0)
			errMess += "Nome Obbligatorio \n";
		if(myForm.txtCognome.value.length == 0)
			errMess += "Cognome Obbligatorio \n";
		if(myForm.txtTelefono.value.length < 6)
			errMess += "Telefono Non Corretto \n";
		if(isNaN(myForm.txtTelefono.value))
			errMess += "Telefono Non Corretto \n";
		if(myForm.txtEmail.value.length == 0)
			errMess += "Email Obbligatorio \n";
		if(!myForm.txtEmail.value.match(email2))
			errMess += "Email Non Corretto \n";
		if(myForm.txtCitta.value.length == 0)
			errMess += "Città Obbligatorio \n";
		if(parseInt(myForm.txtCamere.value) >1 && myForm.txtCoupon.value.length >0)
			errMess += "La Gift Card è utilizzabile solo per prenotazioni di una singla camera. \n Per utilizzare il codice ripetere la ricerca per una sola camera. \n";
		if(errMess.length > 0)
			alert("ATTENZIONE IMPOSSIBILE PROSEGUIRE :\n"+errMess);
		else
		{
			
			var url = http+"/remote/save.aspx";
			
			var parametri = "ut="+idu+"&nam="+myForm.txtNome.value+"&sur="+myForm.txtCognome.value+"&tel="+myForm.txtTelefono.value+"&mail="+myForm.txtEmail.value+"&city="+myForm.txtCitta.value+"&state="+myForm.txtNazione.value+"&buy="+myForm.pagamento.value+"&dal="+myForm.dal.value+"&al="+myForm.al.value+"&ncam="+myForm.txtCamere.value+"&str="+myForm.txtStruttura.value+"&gft="+myForm.txtCoupon.value;
			
			
			for(var i=0;i<parseInt(myForm.txtCamere.value);i++)
			{
			    parametri += "&cam"+i+"="+document.getElementById("txtCamera"+i).value+"&sprd"+i+"="+document.getElementById("txtSupRid"+i).value+"&tratt"+i+"="+document.getElementById("trattamento"+i).value+"&a"+i+"="+document.getElementById("txtAdulti"+i).value+"&b"+i+"="+document.getElementById("txtBambini"+i).value+"&n"+i+"="+document.getElementById("txtNeonati"+i).value;
		    }
			 parametri += "&url=" + document.location.href;
			
			document.getElementById("tabDett").style.display = "none";//tabDett
			document.getElementById("loading").style.display = "inline";
			
			//document.write("2093: "+parametri)
			aObj = new JSONscriptRequest(url+"?"+parametri);
		
			aObj.buildScriptTag();
			aObj.addScriptTag();
			
		}
			
	}
/**********************************************************************
************************** funzioni servizi ****************************
***********************************************************************/

function supplemento(evt)
{
    var checkbox;
    if (!evt)
	{
		evt = event;
		checkbox = evt.srcElement;
	}
	else
	{
		checkbox = evt.target;
	}
    var id =  checkbox.id.split("-")[1]+"-"+ checkbox.id.split("-")[2];
    var i = id.split("-")[0];
	
	var supplemento = parseFloat(document.getElementById("costoServizio-"+id).value);
	var percentualeCaparra = parseFloat(document.getElementById("percCapCam_"+i).value);
	var caparra = ((supplemento / 100) * parseFloat(percentualeCaparra));
	var saldo = (supplemento - caparra);
	
	var txtCaparra = document.getElementById("txtCaparra"+i);
	var txtImporto = document.getElementById("txtImporto"+i);
	
	var caparraAbitazione = parseFloat(txtCaparra.value);
	var importoAbitazione = parseFloat(txtImporto.value);
	
	if (checkbox.checked == true)
	{//aggiungi supplemento
	
		txtCaparra.value = (caparraAbitazione + caparra).toFixed(2);
		txtImporto.value = (importoAbitazione + supplemento).toFixed(2);
		
		document.getElementById("capCam_"+i).innerHTML = txtCaparra.value+" €";
		document.getElementById("saldoCam_"+i).innerHTML = (importoAbitazione + supplemento)-(caparraAbitazione + caparra) + " €";
		document.getElementById("totCam_"+i).innerHTML = txtImporto.value+" €";
		
		
		
		//######### aggiornamento form #####*/
		document.getElementById("txtSupRid"+i).value += ","+checkbox.value;
	}
	else
	{//sottrai supplemento
		txtCaparra.value = (caparraAbitazione - caparra).toFixed(2);
		txtImporto.value = (importoAbitazione - supplemento).toFixed(2);
		
		document.getElementById("capCam_"+i).innerHTML = txtCaparra.value+" €";
		document.getElementById("saldoCam_"+i).innerHTML = ((importoAbitazione - supplemento)-(caparraAbitazione - caparra)).toFixed(2) + " €";
		document.getElementById("totCam_"+i).innerHTML = txtImporto.value+" €";
		
		
		//######### aggiornamento form #####
		document.getElementById("txtSupRid"+i).value = document.getElementById("txtSupRid"+i).value.replace(","+checkbox.value,"");
	}
	//############ ricalcolo il totale della prenotazione #############
	var ImportoTotale = 0;
	var CaparraTotale = 0;
	for(var i = 0;i<parseInt(document.getElementById("txtCamere").value);i++)
	{
	    ImportoTotale += parseFloat(document.getElementById("txtImporto"+i).value);
	    CaparraTotale += parseFloat(document.getElementById("txtCaparra"+i).value);
	}
	
	document.getElementById("capTotale").innerHTML = CaparraTotale.toFixed(2)+" €";
	document.getElementById("saldoTotale").innerHTML =  (ImportoTotale - CaparraTotale).toFixed(2)+ " €";
	document.getElementById("Totale").innerHTML = ImportoTotale.toFixed(2)+" €";
}

 /*********************************************************************
 ************************ messaggi di sistema *************************
 **********************************************************************/
 function choose(status)
 {
    var container = document.getElementById("rmtbkg");
		
		//########### creo contenitore del messaggio
		var messaggio = document.createElement("div");
		messaggio.setAttribute("id","divChoise");
		messaggio.setAttribute("height","150");
		messaggio.setAttribute("align","center");
		messaggio.setAttribute("class", "rmt_testo_prenotazione_eseguita");
		messaggio.className = "rmt_testo_prenotazione_eseguita";
		//########### creo immagine
		var img = document.createElement("img");
		img.setAttribute("src",http+"/remote/img/"+status.ImgSrc);
		img.setAttribute("border","0");
		messaggio.appendChild(document.createElement("br"));
		messaggio.appendChild(document.createElement("br"));
		
		messaggio.appendChild(img);
		//########## inserisco messaggio testuale
		messaggio.appendChild(document.createElement("br"));
		messaggio.appendChild(document.createElement("br"));
		messaggio.appendChild(document.createTextNode(" ("+status.Code+") " + status.Message));
		messaggio.appendChild(document.createElement("br"));
		messaggio.appendChild(document.createTextNode(status.Description));
		messaggio.appendChild(document.createElement("br"));
		messaggio.appendChild(document.createTextNode(status.Solution));
		
		
	    messaggio.setAttribute("class", "rmt_testo_prenotazione_eseguita");
		messaggio.className = "rmt_testo_prenotazione_eseguita";
		messaggio.appendChild(document.createElement("br"));
	    messaggio.appendChild(document.createTextNode("La preghiamo di conservare i seguenti dati relativi alla prenotazione :"));
	    messaggio.appendChild(document.createElement("br"));
	    messaggio.appendChild(document.createTextNode("Booking Code: "+status.BookingCode));
	    messaggio.appendChild(document.createElement("br"));
	    messaggio.appendChild(document.createTextNode("ID : "+status.UserId));
		messaggio.appendChild(document.createElement("br"));
		//########## inserisco tasti scelta
		var child = document.createElement("input");
		child.setAttribute("type","hidden");
		child.setAttribute("value", status.BookingCode);
		child.setAttribute("id","choiseBookingCode");
		messaggio.appendChild(child);
		
		var child = document.createElement("input");
		child.setAttribute("type","hidden");
		child.setAttribute("value", status.Link);
		child.setAttribute("id","choiseCodiceCoupon");
		messaggio.appendChild(child);
		
		child = document.createElement("input");
		child.setAttribute("type","button");
		child.setAttribute("value", "Conferma");
		child.setAttribute("class","rmt_campo_cerca");
	    child.className = "rmt_campo_cerca";	
		child.onclick = choiseOK;
		messaggio.appendChild(child);
		
		messaggio.appendChild(document.createTextNode("    "));
		
		child = document.createElement("input");
		child.setAttribute("type","button");
		child.setAttribute("value", "Annulla");
		child.setAttribute("class","rmt_campo_cerca");
	    child.className = "rmt_campo_cerca";
		child.onclick = choiseKO;
		
		messaggio.appendChild(child);
		messaggio.appendChild(document.createElement("br"));
		var form = document.createElement("form");
	    form.setAttribute("id","choiseForm");
	    form.appendChild(messaggio);
		//########## inserisco il messaggio completo nel contenitore
		container.appendChild(form);
		document.getElementById("loading").style.display = "none";
		aObj.removeScriptTag();
 }
 
 function choiseKO(evt)
 {
    var controllo;
	if (!evt)
	{
		evt = event;
		controllo = evt.srcElement;
	}
	else
	{
		controllo = evt.target;
	}
	
	var myForm;
	myForm = document.getElementById("choiseForm");
	
	var url = http+"/remote/choose.aspx";
		
	var parametri = "act=KO&ut="+idu+"&bkc="+myForm.choiseBookingCode.value+"&gft="+myForm.choiseCodiceCoupon.value+"&url=" + document.location.href;
	
	document.getElementById("divChoise").style.display = "none";//tabDett
	document.getElementById("loading").style.display = "inline";
	
	//document.write("2093: "+parametri)
	aObj = new JSONscriptRequest(url+"?"+parametri);

	aObj.buildScriptTag();
	aObj.addScriptTag();
 }
 
 function choiseOK(evt)
 {
    var controllo;
	if (!evt)
	{
		evt = event;
		controllo = evt.srcElement;
	}
	else
	{
		controllo = evt.target;
	}
	
	var myForm;
	myForm = document.getElementById("choiseForm");
	
	var url = http+"/remote/choose.aspx";
		
	var parametri = "act=OK&ut="+idu+"&bkc="+myForm.choiseBookingCode.value+"&gft="+myForm.choiseCodiceCoupon.value+"&url=" + document.location.href;
	
	document.getElementById("divChoise").style.display = "none";//tabDett
	document.getElementById("loading").style.display = "inline";
	
	//document.write("2093: "+parametri)
	aObj = new JSONscriptRequest(url+"?"+parametri);

	aObj.buildScriptTag();
	aObj.addScriptTag();
			
		
 }
 
 function status(status)
	{
		var container = document.getElementById("rmtbkg");
		
		//########### creo contenitore del messaggio
		var messaggio = document.createElement("div");
		messaggio.setAttribute("height","150");
		messaggio.setAttribute("align","center");
		messaggio.setAttribute("class", "rmt_testo_prenotazione_eseguita");
		messaggio.className = "rmt_testo_prenotazione_eseguita";
		//########### creo immagine
		var img = document.createElement("img");
		img.setAttribute("src",http+"/remote/img/"+status.ImgSrc);
		img.setAttribute("border","0");
		messaggio.appendChild(document.createElement("br"));
		messaggio.appendChild(document.createElement("br"));
		
		//########### se c'è un link rendo l'immagine clickabile, e la inserisco nel contenitore
		if (status.Link != '')
		{
			a = document.createElement("a");
			//a.href = http + "/" +status.Link;//"/pay/AspNet/remoteSetExpressCheckout.aspx?id="+obj.id+"&code="+obj.code+"&usr="+obj.usr;
	        a.href = status.Link;		
			a.appendChild(img);
			messaggio.appendChild(a);
		}
		else
			messaggio.appendChild(img);
		//########## inserisco messaggio testuale
		messaggio.appendChild(document.createElement("br"));
		messaggio.appendChild(document.createElement("br"));
		messaggio.appendChild(document.createTextNode(" ("+status.Code+") " + status.Message));
		messaggio.appendChild(document.createElement("br"));
		messaggio.appendChild(document.createTextNode(status.Description));
		messaggio.appendChild(document.createElement("br"));
		messaggio.appendChild(document.createTextNode(status.Solution));
		
		if(status.bookingcode != null && status.bookingcode != "")
		{
		    messaggio.setAttribute("class", "rmt_testo_prenotazione_eseguita");
			messaggio.className = "rmt_testo_prenotazione_eseguita";
			messaggio.appendChild(document.createElement("br"));
		    messaggio.appendChild(document.createTextNode("La preghiamo di conservare i seguenti dati relativi alla prenotazione :"));
		    messaggio.appendChild(document.createElement("br"));
		    messaggio.appendChild(document.createTextNode("Booking Code: "+status.BookingCode));
		    messaggio.appendChild(document.createElement("br"));
		    messaggio.appendChild(document.createTextNode("ID : "+status.UserId));
		}
		//########## inserisco link per nuova ricerca
		var child = document.createElement("div");
		child.setAttribute("align","center");
		child.style.cursor = "pointer";		
		child.setAttribute("class", "rmt_testo_link");
		child.className = "rmt_testo_link";	
		child.appendChild(document.createTextNode("Effettua nuova ricerca"));
		child.onclick = ricarica;
		
		messaggio.appendChild(child);
		
		//########## inserisco il messaggio completo nel contenitore
		container.appendChild(messaggio);
		document.getElementById("loading").style.display = "none";
		aObj.removeScriptTag();
	}
 
 
 //####################################################################
 // Constructor -- pass a REST request URL to the constructor
 //####################################################################
function JSONscriptRequest(fullUrl) {
    // REST request path
    this.fullUrl = fullUrl; 
    // Keep IE from caching requests
    this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
    // Get the DOM location to put the script tag
    this.headLoc = document.getElementsByTagName("head").item(0);
    // Generate a unique script tag id
    this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++;
}

// Static script ID counter
JSONscriptRequest.scriptCounter = 1;

// buildScriptTag method
//

JSONscriptRequest.prototype.buildScriptTag = function () {
	
    // Create the script tag
    this.scriptObj = document.createElement("script");
    
    // Add script object attributes
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("charset", "utf-8");
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
    this.scriptObj.setAttribute("id", this.scriptId);
}
 
// removeScriptTag method
// 
JSONscriptRequest.prototype.removeScriptTag = function () {
    // Destroy the script tag
    this.headLoc.removeChild(this.scriptObj);  
};

// addScriptTag method
//
JSONscriptRequest.prototype.addScriptTag = function () {
    // Create the script tag
    this.headLoc.appendChild(this.scriptObj);
};
/********************************************************************
********************************************************************
***********************************************************************/
function visualizzaCalendario(evt)
{
    var img;
    if (!evt)
	{
		evt = event;
		img = evt.srcElement;
	}
	else
	{
		img = evt.target;
	}
	
	cal10.select(document.getElementById(img.id.replace("img","")),img.id.replace("img","a"),'dd/MM/yyyy','current'); return false;
}

-->