	var ggselda= "";
	var mmselda= "";
	var yyselda= "";
	var ggsela= "";
	var mmsela= "";
	var yysela= "";
	var date = "&ggselda=" + ggselda;
	date=date + "&mmselda=" + mmselda;
	date=date + "&yyselda=" + yyselda;
	date=date + "&ggsela=" + ggsela;
	date=date + "&mmsela=" + mmsela;
	date=date + "&yysela=" + yysela;
	date=date + "&npers=2&nstanze=1&nrag=0&nbebe=0";


function onclickGoSelMode(args) {

    var hotel, hotelkey, lingua, portale, dal, al, camere, tariffe;

    if (arguments.length < 4) return false;

    hotel = arguments[0];
    hotelkey = arguments[1];
    lingua = arguments[2];
    portale = arguments[3];

    if (arguments.length > 5) {

        if (arguments[4] != undefined && arguments[4] != "") {
            var dalH = new String(arguments[4]).split("/");
            dal = dalH[2] + "-" + dalH[1].lpad("0", 2) + "-" + dalH[0].lpad("0", 2);
        }
        if (arguments[5] != undefined && arguments[5] != "") {
            var alH = new String(arguments[5]).split("/");
            al = alH[2] + "-" + alH[1].lpad("0", 2) + "-" + alH[0].lpad("0", 2);
        }
    }

    if (arguments.length > 6) {
        camere = arguments[6];
    } 
    
    if (arguments.length > 7) {
        tariffe = new String(arguments[7]).replace(";", ",");
    } 

    //la variabile lingua deve essere o IT o GB
    if (lingua == "uk" || lingua == "UK") {
        lingua = "GB";
    }

    var host = "https://netbooking.gpdati.com/CRS/wbenew/PreSelection.aspx"
    //var host = "http://localhost:4135/CRS/wbenew/PreSelection.aspx"
    var w = 750;
    var h = 580;
    var ind;
    ind = host + "?hotel=" + hotel + "&hotelkey=" + hotelkey;
    ind += "&lingua=" + lingua;
    ind += "&portale=" + portale;
    if (dal != undefined && al != undefined) {
        ind += "&arrivo=" + dal + "&partenza=" + al;
    }
    if (camere != undefined) {
        ind += "&camere=" + camere;
    }
    if (tariffe != undefined) {
        ind += "&rateplans=" + tariffe;
    }

    window.open(ind, "Selezione", "toolbar=no,location=no,scrollbars=yes,resizable=yes");
}


function onclickGoSelModeExt(hotel, hotelkey, lingua, portale, dal, al, persone, camere) {
    onclickGoSelMode(hotel, hotelkey, lingua, portale, dal, al, camere);
}


function onclickGoOffers(hotel,hotelkey,lingua,portale,code,quantity)
	{

		//la variabile lingua deve essere o IT o GB
		if(lingua == "uk" || lingua == "UK" || lingua == "en" || lingua == "EN")
		{
			lingua = "GB";
		}

		//indica l'indirizzo della pagina
		var host="https://netbooking.gpdati.com/CRS/wbenew/offers.aspx"

		var w = 750;
		var h = 580;


		var ind;
		ind = host + "?hotel=" + hotel + "&hotelkey=" + hotelkey; 
		ind = ind + "&lingua=" + lingua;
		ind = ind + "&portale=" + portale;
		if(code != undefined && code != '')
		{
			ind = ind + "&packcode=" + code;
		}

		if(quantity != undefined && code != '')
		{
			ind = ind + "&packquantity=" + quantity;
		}

		window.open(ind ,"Selezione","toolbar=no,location=no,scrollbars=yes,resizable=yes");
	}

	
function createBookingForm(args) {

    var hotel, language, portal, rooms, open_type

    if (arguments.length < 3) return false;

    hotel = arguments[0];
    language = arguments[1];
    portal = arguments[2];

    if (arguments.length > 3) {
        rooms = arguments[3];
    }
    else {
        rooms = "2";
    }

    // 0 = pop-up, 1 = redirect
    if (arguments.length > 4) {
        open_type = arguments[4];
    }

    if (arguments.length > 5) {
        font_size = arguments[5];
    }

    var d = new Date();
    year = d.getFullYear();

    var bookingPara = document.getElementById("bookingParagraph");
    bookingPara.innerHTML = "";
    var bookingForm = document.createElement("form");

    var arrivalDaySelect = document.createElement("select");
    arrivalDaySelect.setAttribute("class", "bookingSelect");
    for (i = 0; i < 31; i++) {
        theOption = document.createElement("OPTION");
        theText = document.createTextNode(i + 1);
        theOption.appendChild(theText);
        if (i + 1 == d.getDate()) {
            theOption.setAttribute("selected", "true");
        }
        theOption.setAttribute("value", i + 1);
        arrivalDaySelect.appendChild(theOption);
    }

    var arrivalMonthSelect = document.createElement("select");
    arrivalMonthSelect.setAttribute("class", "bookingSelect");
    for (i = 0; i < 12; i++) {
        theOption = document.createElement("OPTION");
        theText = document.createTextNode(i + 1);
        theOption.appendChild(theText);
        if (i == d.getMonth()) {
            theOption.setAttribute("selected", "true");
        }
        theOption.setAttribute("value", i + 1);
        arrivalMonthSelect.appendChild(theOption);
    }

    var arrivalYearSelect = document.createElement("select");
    arrivalYearSelect.setAttribute("class", "bookingSelect");
    for (i = 0; i < 2; i++) {
        theOption = document.createElement("OPTION");
        theText = document.createTextNode(year + i);
        theOption.appendChild(theText);
        theOption.setAttribute("value", year + i);
        arrivalYearSelect.appendChild(theOption);
    }

    arrivalText = document.createTextNode("Arrivo: ");
    bookingForm.appendChild(arrivalText);
    bookingForm.appendChild(arrivalDaySelect);
    bookingForm.appendChild(arrivalMonthSelect);
    bookingForm.appendChild(arrivalYearSelect);

    parBreak = document.createElement("p");
    bookingForm.appendChild(parBreak);

    nightsText = document.createTextNode("Notti: ");
    bookingForm.appendChild(nightsText);

    var nightsSelect = document.createElement("select");
    nightsSelect.setAttribute("class", "bookingSelect");
    for (i = 0; i < 30; i++) {
        theOption = document.createElement("OPTION");
        theText = document.createTextNode(i + 1);
        theOption.appendChild(theText);
        theOption.setAttribute("value", i + 1);
        nightsSelect.appendChild(theOption);
    }
    bookingForm.appendChild(nightsSelect);


    roomText = document.createTextNode(" Camere: ");
    bookingForm.appendChild(roomText);

    var roomSelect = document.createElement("select");
    roomSelect.setAttribute("class", "bookingSelect");
    for (i = 0; i < parseInt(rooms); i++) {
        theOption = document.createElement("OPTION");
        theText = document.createTextNode(i + 1);
        theOption.appendChild(theText);
        theOption.setAttribute("value", i + 1);
        roomSelect.appendChild(theOption);
    }

    var roomsForm = document.createElement("form");
    
    bookingForm.appendChild(roomSelect);

    bookingPara.appendChild(bookingForm);

    roomSelect.onchange = AddPeople;
    
    AddPeople();

    bookingPara.appendChild(roomsForm);
    
    var buttonForm = document.createElement("form");

    parPeople= document.createElement("p");
    buttonForm.appendChild(parPeople);

    bookingButton = document.createElement("BUTTON");
    bookingButton.setAttribute("class", "bookingButton");
    theText = document.createTextNode("Prenota");

    bookingButton.appendChild(theText);
    bookingButton.onclick = bookingButtonClick;

    buttonForm.appendChild(bookingButton);

    bookingPara.appendChild(buttonForm);
    


    function bookingButtonClick(e) {

        //la variabile lingua deve essere o IT o GB
        if (language == "uk" || language == "UK") {
            language = "GB";
        }
        //indica l'indirizzo della pagina
        var folder = (portal == "0000") ? "wbenew" : "portale";
        //var host = "http://localhost:4736/CRS/" + folder + "/PreSelection.aspx"
        var host = "https://netbooking.gpdati.com/CRS/" + folder + "/PreSelection.aspx"
        var w = 750;
        var h = 580;

        var ind;
        var arrivalDate = new Date(arrivalYearSelect.options[arrivalYearSelect.selectedIndex].value, arrivalMonthSelect.selectedIndex, arrivalDaySelect.options[arrivalDaySelect.selectedIndex].value);
        var departureDate = new Date(arrivalYearSelect.options[arrivalYearSelect.selectedIndex].value, arrivalMonthSelect.selectedIndex, parseInt(arrivalDaySelect.options[arrivalDaySelect.selectedIndex].value) + parseInt(nightsSelect.options[nightsSelect.selectedIndex].value));

        var roomDetails = new String("!");

        for (k = 0; k < roomSelect.options[roomSelect.selectedIndex].value; k++) {
            adultSelect = document.getElementById("adultSelect-" + k);
            roomDetails += adultSelect.options[adultSelect.selectedIndex].value;
            childSelect = document.getElementById("childSelect-" + k);
            if (childSelect.options[childSelect.selectedIndex].value != "0") {
                roomDetails += "-" + childSelect.options[childSelect.selectedIndex].value;

                for (l = 0; l < childSelect.options[childSelect.selectedIndex].value; l++) {
                    var ageTextbox = document.getElementById("childTextbox-" + k + l);
                    if (isNaN(parseInt(ageTextbox.value))) {
                        alert("Nan");
                        return;
                    }
                    roomDetails += "-" + ageTextbox.value;
                }
            }

            if (k != parseInt(roomSelect.options[roomSelect.selectedIndex].value) - 1) {
                roomDetails += "*";
            }
        }

            ind = host + "?hotel=" + hotel;
        ind = ind + "&lingua=" + language;
        ind = ind + "&portale=" + portal;
        ind = ind + "&arrivo=" + arrivalDate.getFullYear() + "-" + padNum(arrivalDate.getMonth() + 1) + "-" + padNum(arrivalDate.getDate()) + "&partenza=" + departureDate.getFullYear() + "-" + padNum(departureDate.getMonth() + 1) + "-" + padNum(departureDate.getDate()) + "&camere=" + roomSelect.options[roomSelect.selectedIndex].value + roomDetails;
        //window.alert(date);
        //return ind;		
        //alert(ind);

        if (open_type == "1") {
            location.href = ind;
            return false;
        }
        else  {
            window.open(ind, "Selezione", "toolbar=yes,location=no,scrollbars=yes,resizable=yes");
        }
    }


    function AddPeople(e) {

        //debugger;

        if (roomsForm.hasChildNodes()) {
            while (roomsForm.childNodes.length >= 1) {
                roomsForm.removeChild(roomsForm.firstChild);
            }
        }

        for (i = 0; i < parseInt(roomSelect.options[roomSelect.selectedIndex].value); i++) {

            parBreak = document.createElement("p");
            roomsForm.appendChild(parBreak);

            roomText = document.createTextNode("Camera " + (parseInt(i) + 1));
            roomsForm.appendChild(roomText);

            parBreak = document.createElement("p");
            roomsForm.appendChild(parBreak);

            roomText = document.createTextNode("Adulti: ");
            roomsForm.appendChild(roomText);

            var adultSelect = document.createElement("select");
            adultSelect.setAttribute("class", "bookingSelect");
            for (j = 0; j < 4; j++) {
                theOption = document.createElement("OPTION");
                theText = document.createTextNode(j + 1);
                theOption.appendChild(theText);
                theOption.setAttribute("value", j + 1);
                adultSelect.appendChild(theOption);
            }
            adultSelect.setAttribute("id", "adultSelect-" + i);
            roomsForm.appendChild(adultSelect);

            roomText = document.createTextNode(" Bambini: ");
            roomsForm.appendChild(roomText);

            var childSelect = document.createElement("select");
            childSelect.setAttribute("class", "bookingSelect");
            for (j = 0; j < 3; j++) {
                theOption = document.createElement("OPTION");
                theText = document.createTextNode(j);
                theOption.appendChild(theText);
                theOption.setAttribute("value", j);
                childSelect.appendChild(theOption);
            }

            childSelect.setAttribute("id", "childSelect-" + i);
            childSelect.onchange = function() { AddChildAges(this.getAttribute("id")); }
            roomsForm.appendChild(childSelect);

            var childAgeForm = document.createElement("form");
            childAgeForm.setAttribute("id", "childAgeForm-" + i)
            roomsForm.appendChild(childAgeForm);
        }

        function AddChildAges(id) {

            var s = new String(id);
            var i = s.split("-")[1];
            
            var myForm = document.getElementById("childAgeForm-" + i);
            if (myForm.hasChildNodes()) {
                while (myForm.childNodes.length >= 1) {
                    myForm.removeChild(myForm.firstChild);
                }
            }

            var myChildSelect = document.getElementById("childSelect-" + i);
            for (j = 0; j < parseInt(myChildSelect.options[myChildSelect.selectedIndex].value); j++) {
                childAgeText = document.createTextNode(" Età bimbo " + (parseInt(j) + 1) + " ");
                myForm.appendChild(childAgeText);
                var childAgeTextBox = document.createElement("input");
                childAgeTextBox.setAttribute("class", "bookingTextBox");
                childAgeTextBox.setAttribute("id", "childTextbox-" + i + j)
                myForm.appendChild(childAgeTextBox);
            }
        }
    }
}

function padNum(inNum) {
    var outNum = inNum.toString();
    while (outNum.length < 2) {
        outNum = "0" + outNum;
    }
    return outNum;
}

String.prototype.lpad = function(padString, length) {
    var str = this;
    while (str.length < length)
        str = padString + str;
    return str;
}


