// this file is for the calendarPicker
var objContainer;
var objInput;
var objXmlHttp;
var strCallBackFunction;
var intError = 0;    

document.onmousedown    = GetMouseCoordinates;

var mouseX = 0;
var mouseY = 0;
var strEv  = "";

function GetMouseCoordinates(e) {
    var IE = document.all ? true : false;

    if (!IE) document.captureEvents(Event.MOUSEMOVE);
    if (IE) {
        mouseX = event.clientX + document.body.scrollLeft - 325;
        mouseY = event.clientY + document.body.scrollTop + 10;
        strEv  = window.event.srcElement.id;
    } else {
        mouseX = e.pageX - 125;
        mouseY = e.pageY + 10;
        strEv  = e.target.id;
    }
};

function GetMouseClick(event) {
    if (objContainer.style.visibility == "visible") {
        objContainer.style.visibility = "hidden";
    }
};

function OpenCalendar(p_objContainer, p_strInputName, p_strCallBackFunction, p_intDaysSelectable) {
    objContainer    = document.getElementById(p_objContainer);
    objInput        = document.getElementById(p_strInputName);

    if (!objContainer.style.visibility || objContainer.style.visibility == "hidden") {
        GetCalendarData(p_objContainer, p_intDaysSelectable);
        objContainer.style.visibility     = "visible";
        objContainer.style.top            = mouseY + "px";
        objContainer.style.left           = mouseX + "px";
    } else {
        objContainer.style.visibility     = "hidden";
    }

    if (p_strCallBackFunction) {
        strCallBackFunction = p_strCallBackFunction;
    }
};

function CloseCalendar(p_objContainer) {
    var objCalendar    = document.getElementById(p_objContainer);

    objCalendar.style.visibility     = "hidden";
};

function GetCalendarData(p_objContainer, p_intDaysSelectable) {
    objXMLHttp = false;
    try {
        objXMLHttp = new XMLHttpRequest();
    } catch (exception) {
        try {
            objXMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (exception) {
            try {
                objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (exception) {
                objXMLHttp = false;
            }
        }
    }

    if (objXMLHttp) {
        objXMLHttp.open("get", "/fileadmin/template/scripts/getCalendar.php?L=&date=" + objInput.value + "&container=" + p_objContainer + (p_intDaysSelectable ? "&daysSelectable=" + p_intDaysSelectable : ""), true);
        objXMLHttp.onreadystatechange = UpdateCalendarData;
        objXMLHttp.send(null);
    }
};

function UpdateCalendarData() {
    if (objXMLHttp.readyState == 4)
        objContainer.innerHTML = objXMLHttp.responseText;
    };

function SwitchMonth(p_strTargetDate, p_objContainer, p_intDaysSelectable) {
    objInput.value = p_strTargetDate;

    GetCalendarData(p_objContainer, p_intDaysSelectable);
};

function SelectDate(p_strDate) {
    objInput.value = p_strDate;
    objContainer.style.visibility     = "hidden";

    if (strCallBackFunction != "") {
        eval(strCallBackFunction + ";");
    }
};

function ChangeRoutes(p_objSelect) {
    objSelect = document.getElementById("bookingRoute");
    objSelect.options.length = 0;

    switch(p_objSelect.selectedIndex) {
        case 2:
            objSelect.options[0] = new Option("Havneby - List", "HL");
            break;
        case 0:
        case 1:
            objSelect.options[0] = new Option("List - Havneby", "LH");
            objSelect.options[1] = new Option("Havneby - List", "HL");
            break;
    }
};