function check_form(form)	{
	if (form.checkin_date.value == '') return false;
	if (form.checkout_date.value == '') return false;
	return true;
}

//------------------------------------------------------------------------------

var cal1;
var cal2;
function init() {
	this.today = new Date();

	var thisMonth = this.today.getMonth();
	var thisDay = this.today.getDate();
	var thisYear = this.today.getFullYear();

	cal1 = new YAHOO.widget.Calendar1up("cal1","container1","tb_checkin",(thisMonth+1)+"/"+thisYear);
	cal1.minDate = new Date();
	cal1.Options.NAV_ARROW_LEFT = 'http://www.engadinbooking.ch/minibooking/img/callt.gif';
	cal1.Options.NAV_ARROW_RIGHT = 'http://www.engadinbooking.ch/minibooking/img/calrt.gif';
	cal1.render();

	cal2 = new YAHOO.widget.Calendar1up("cal2","container2","tb_checkout");
	cal2.minDate = YAHOO.widget.DateMath.add(new Date(), YAHOO.widget.DateMath.DAY, 1);
	cal2.Options.NAV_ARROW_LEFT = 'http://www.engadinbooking.ch/minibooking/img/callt.gif';
	cal2.Options.NAV_ARROW_RIGHT = 'http://www.engadinbooking.ch/minibooking/img/calrt.gif';
	cal2.render();
}

//------------------------------------------------------------------------------

function showCalendar1() {
	if (cal1.oDomContainer.style.display=='block') cal1.hide();
	else	{
		cal2.hide();
		if (cal2.getSelectedDates() != '')	{
			cal1.maxDate = cal2.getSelectedDates()[0];
			if (cal1.getSelectedDates() == '') cal1.setMonth(cal2.getSelectedDates()[0].getMonth());
			cal1.render();
		}
		cal1.sinc();
		cal1.showAt('dateLink1');
	}
}

//------------------------------------------------------------------------------

function showCalendar2() {
	if (cal2.oDomContainer.style.display=='block') cal2.hide();
	else	{
		cal1.hide();
		if (cal1.getSelectedDates() != '')	{
			cal2.minDate = cal1.getSelectedDates()[0];
			cal2.maxDate = YAHOO.widget.DateMath.add(cal1.getSelectedDates()[0], YAHOO.widget.DateMath.DAY, 30);
			if (cal2.getSelectedDates() == '') cal2.setMonth(cal1.getSelectedDates()[0].getMonth());
			cal2.render();
		}
		cal2.sinc();
		cal2.showAt('dateLink2');
	}
}

//------------------------------------------------------------------------------

function translate(lang) {
    if(lang == "2") {
        document.getElementById("arrival_text").innerHTML = "Arrival:";
        document.getElementById("departure_text").innerHTML = "Departure:";
        document.getElementById("search_text").value = "Search";
        
    }
    else if(lang == "1") {
        document.getElementById("arrival_text").innerHTML = "Arrivo:";
        document.getElementById("departure_text").innerHTML = "Partenza:";
        document.getElementById("search_text").value = "Ricerca";
        
    }
}

//------------------------------------------------------------------------------

window.onload = function() {
    init();
    /*
    document.getElementById("hotel_id_input").value = get_url_param("id");
    document.getElementById("lang_input").value = get_url_param("lang");
    document.getElementById("short_input").value = get_url_param("short");
    */
    translate(get_url_param("l"));
}

//------------------------------------------------------------------------------

function popup(form,w,h)
{
	if (!window.focus)return true;
	var d = new Date();

	windowname = d.getTime();
	tFeatures  = "width=" + w + ",height=" + h + ",location=no,status=no,resizable=yes,scrollbars=yes";
	if (screen.height && screen.width) {
		h = parseInt((screen.height - h)/2)
		if (h<0) h = 0;
		w = parseInt((screen.width - w)/2)
		if (w<0) w = 0;
		tFeatures  = "left=" + w + ",top=" + h + "," + "screenX=" + w + ",screenY=" + h + "," + tFeatures;
	}
	window.open('', windowname, tFeatures);
	form.target=windowname;
	return true;
}

//------------------------------------------------------------------------------

function get_url_params() {
    var ret = new Array();

    if(location.search.indexOf("?") >= 0) {
        pairs = location.search.split("?")[1].split("&");
        for(i = 0; i < pairs.length; ++i) {
            pair = pairs[i].split("=");
            if(pair.length == 2) {
                ret.push(new Array(pair[0], decodeURIComponent(pair[1])));
            }
        }
    }

    return ret;
}

//------------------------------------------------------------------------------

function get_url_param(name) {
    arr = get_url_params();
    for(i = 0; i < arr.length; ++i) {
        if(arr[i][0] == name) return arr[i][1];
    }

    return "";
}
