﻿// JScript File
function $(v_id) {
    return window.document.getElementById(v_id);
}

var v_disablebutton;
var v_showspan;
function f_disable_button(v_button, v_span) {
    v_disablebutton=v_button;
    v_showspan=v_span;
    v_start=window.setTimeout("v_disablebutton.disabled=true;$(v_showspan).style.visibility='visible';", 200);
}

function f_ActivateSSL() {
    if (top.location.href.indexOf("https:") == -1) {
        top.location.href = top.location.href.replace(/http:/, "https:");
    }
}

function f_more (v_which) {
    if ($(v_which).style.display=="block") {
        $(v_which).style.display="none";
    }
    else {
        $(v_which).style.display="block";
    }
}

function CalendarJS() {
    this.now = new Date();
    this.dayname = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"];
    this.monthname = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    this.tooltip = ["previous month", "next month", "current date", "close"];
    this.monthCell = document.createElement("th");
    this.tableHead = null;
    this.parEl = null;
    this.textbox = null;

    this.init = function(containerId, textboxId, parameters, initDate) {
        this.now = initDate ? initDate : new Date();
        if (parameters) {
            this.dayname = parameters[0];
            this.monthname = parameters[1];
            this.tooltip = parameters[2];
        }
        this.textbox = document.getElementById(textboxId);
        this.date = this.now.getDate();
        this.month = this.mm = this.now.getMonth();
        this.year = this.yy = this.now.getFullYear();
        this.monthCell.colSpan = 4;
        this.monthCell.appendChild(document.createTextNode(this.monthname[this.mm] + " " + this.yy));
        this.parEl = document.getElementById(containerId);
        this.tableHead = this.createTableHead();
        this.show();
        if (!initDate) this.checkDate();
    },

    this.checkDate = function() {
        var self = this;
        var today = new Date();
        if (this.date != today.getDate()) {
            this.date = today.getDate();
            if (this.mm == this.month && this.yy == this.year)
                this.switchMonth("current");
            this.month = today.getMonth();
            if (this.mm == this.month && this.yy == this.year)
                this.switchMonth("current");
            this.year = today.getFullYear();
            if (this.mm == this.month && this.yy == this.year)
                this.switchMonth("current");

        }
        window.setTimeout(function() { self.checkDate(); }, Math.abs(new Date(this.year, this.month, this.date, 24, 0, 0) - this.now));
    },

    this.removeElements = function(Obj) {
        for (var i = 0; i < Obj.childNodes.length; i++)
            Obj.removeChild(Obj.childNodes[i]);
        return Obj;
    },

    this.show = function() {
        this.parEl = this.removeElements(this.parEl);
        this.monthCell.firstChild.replaceData(0, this.monthCell.firstChild.nodeValue.length, this.monthname[this.mm] + " " + this.yy);
        var table = document.createElement("table");
        table.appendChild(this.createTableBody());
        table.appendChild(this.tableHead);
        this.parEl.appendChild(table);
        this.parEl.style.display = "block";
    },

    this.createTableHead = function() {
        var thead = document.createElement("thead");
        var tr = document.createElement("tr");
        var th = this.getCell("th", "\u00AB", "last_month")
        th.Instanz = this;
        th.onclick = function() { this.Instanz.switchMonth("prev"); };
        th.title = this.tooltip[0];
        try { th.style.cursor = "pointer"; } catch (e) { th.style.cursor = "hand"; }
        tr.appendChild(th);
        this.monthCell.Instanz = this;
        this.monthCell.onclick = function() { this.Instanz.switchMonth("current"); };
        this.monthCell.title = this.tooltip[2];
        try { this.monthCell.style.cursor = "pointer"; } catch (e) { this.monthCell.style.cursor = "hand"; }
        tr.appendChild(this.monthCell);
        th = this.getCell("th", "\u00BB", "next_month")
        th.Instanz = this;
        th.onclick = function() { this.Instanz.switchMonth("next"); };
        th.title = this.tooltip[1];
        try { th.style.cursor = "pointer"; } catch (e) { th.style.cursor = "hand"; }
        tr.appendChild(th);
        th = this.getCell("th", "x", "close")
        th.parentElement = this.parEl;
        th.closeCalendar = this.closeCalendar;
        th.onclick = function() {
            this.closeCalendar(this.parentElement);
        };
        th.title = this.tooltip[3];
        try { th.style.cursor = "pointer"; } catch (e) { th.style.cursor = "hand"; }
        tr.appendChild(th);
        thead.appendChild(tr);
        tr = document.createElement('tr');
        for (var i = 0; i < this.dayname.length; i++)
            tr.appendChild(this.getCell("th", this.dayname[i], "weekday"));
        thead.appendChild(tr);
        return thead;
    },

    this.createTableBody = function() {
        var dayspermonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
        var sevendaysaweek = 0;
        var begin = new Date(this.yy, this.mm, 1);
        var firstday = begin.getDay() - 1;
        if (firstday < 0)
            firstday = 6;
        if ((this.yy % 4 == 0) && ((this.yy % 100 != 0) || (this.yy % 400 == 0)))
            dayspermonth[1] = 29;
        var tbody = document.createElement("tbody");
        var tr = document.createElement('tr');
        if (firstday == 0) {
            for (var i = 0; i < this.dayname.length; i++) {
                var prevMonth = (this.mm == 0) ? 11 : this.mm - 1;
                tr.appendChild(this.getCell("td", dayspermonth[prevMonth] - 6 + i, "last_month"));
            }
            tbody.appendChild(tr);
            tr = document.createElement('tr');
        }

        for (var i = 0; i < firstday; i++, sevendaysaweek++) {
            var prevMonth = (this.mm == 0) ? 11 : this.mm - 1;
            tr.appendChild(this.getCell("td", dayspermonth[prevMonth] - firstday + i + 1, "last_month"));

        }

        for (var i = 1; i <= dayspermonth[this.mm]; i++, sevendaysaweek++) {
            if (this.dayname.length == sevendaysaweek) {
                tbody.appendChild(tr);
                tr = document.createElement('tr');
                sevendaysaweek = 0;
            }

            var td = null;
            if (i == this.date && this.mm == this.month && this.yy == this.year && (sevendaysaweek == 5 || sevendaysaweek == 6))
                td = this.getCell("td", i, "clickable today weekend");
            else if (i == this.date && this.mm == this.month && this.yy == this.year)
                td = this.getCell("td", i, "clickable today");
            else if (sevendaysaweek == 5 || sevendaysaweek == 6)
                td = this.getCell("td", i, "clickable weekend");
            else
                td = this.getCell("td", i, "clickable");

            td.setDate = this.setDate;
            td.dd = i;
            td.mm = this.mm;
            td.yy = this.yy;
            td.textbox = this.textbox;
            td.parentElement = this.parEl;
            td.onclick = function(e) {
                var currentDate = new Date(this.yy, this.mm, this.dd);
                this.setDate(currentDate, this.textbox, this.parentElement);
            };
            tr.appendChild(td);
        }

        var daysNextMonth = 1;
        for (var i = sevendaysaweek; i < this.dayname.length; i++)
            tr.appendChild(this.getCell("td", daysNextMonth++, "next_month"));

        tbody.appendChild(tr);

        while (tbody.getElementsByTagName("tr").length < 6) {
            tr = document.createElement('tr');
            for (var i = 0; i < this.dayname.length; i++)
                tr.appendChild(this.getCell("td", daysNextMonth++, "next_month"));
            tbody.appendChild(tr);
        }

        return tbody;

    },

    // processing of clicked date
    this.setDate = function(date, textbox, parentElement) {
        textbox.value = date.getDate() + "." + (date.getMonth() + 1) + "." + date.getFullYear();
        parentElement.style.display = "none";
    },

    this.closeCalendar = function(parentElement) {
        parentElement.style.display = "none";
    },

    this.getCell = function(tag, str, cssClass) {
        var El = document.createElement(tag);
        El.appendChild(document.createTextNode(str));
        if (cssClass != null)
            El.className = cssClass;
        return El;
    },

    this.switchMonth = function(s) {
        switch (s) {
            case "prev":
                this.yy = (this.mm == 0) ? this.yy - 1 : this.yy;
                this.mm = (this.mm == 0) ? 11 : this.mm - 1;
                break;

            case "next":
                this.yy = (this.mm == 11) ? this.yy + 1 : this.yy;
                this.mm = (this.mm == 11) ? 0 : this.mm + 1;
                break;

            case "current":
                this.yy = this.year;
                this.mm = this.month;
                break;
        }
        this.show();
    }
}

function showCalendar(textbox, containerId, parameters, date) {
    if (textbox.value.length > 0 && !date) {
        matchDate = textbox.value.match(/^(\d+)\.(\d+)\.(\d+)$/);
        if (matchDate) {
            date = new Date();
            date.setDate(RegExp.$1);
            date.setMonth((RegExp.$2) - 1);
            date.setFullYear(RegExp.$3);
        }
        matchDate = textbox.value.match(/^(\d+)\/(\d+)\/(\d+)$/);
        if (matchDate) {
            date = new Date();
            date.setDate(RegExp.$2);
            date.setMonth((RegExp.$1) - 1);
            date.setFullYear(RegExp.$3);
        }
    }
    new CalendarJS().init(containerId, textbox.id, parameters, date);
}


var toolTipOffsetX = -30;
var toolTipOffsetY = 20;
var ie = document.all;
var ns6 = document.getElementById && !document.all;
var objToolTip = false;
var idToolTip = "divToolTip";

var ieTrueBody = (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;

function ShowToolTip(text, cssClass, width) {
    var divToolTip = document.createElement("div");
    divToolTip.setAttribute("id", idToolTip);
    divToolTip.appendChild(document.createTextNode(text));
    if (typeof width != "undefined") divToolTip.setAttribute("style", "width: " + width + "px;");
    if (typeof cssClass != "undefined" && cssClass != "") divToolTip.setAttribute("class", "tooltip " + cssClass);
    else divToolTip.setAttribute("class", "tooltip");
    window.document.getElementsByTagName("body")[0].appendChild(divToolTip);
    objToolTip = $(idToolTip);
    enableToolTip = true;
    document.onmousemove = PositionToolTip;
    return false;
}

function PositionToolTip(e) {
    if (objToolTip) {
        var currentX = (ns6) ? e.pageX : event.clientX + ieTrueBody.scrollLeft;
        var currentY = (ns6) ? e.pageY : event.clientY + ieTrueBody.scrollTop;

        // How far is the tool tip from the edge of the body?
        var rightEdge = (ie && !window.opera) ? ieTrueBody.clientWidth - event.clientX - toolTipOffsetX : window.innerWidth - e.clientX - toolTipOffsetX - 20;
        var bottomEdge = (ie && !window.opera) ? ieTrueBody.clientHeight - event.clientY - toolTipOffsetY : window.innerHeight - e.clientY - toolTipOffsetY - 20;
        var leftEdge = (toolTipOffsetX < 0) ? toolTipOffsetX * (-1) : -1000;

        // If right space to edge isn't enough for the tool tip, move the horizontal position of the tool tip to the left by its width.
        if (rightEdge < objToolTip.offsetWidth)
            objToolTip.style.left = ie ? ieTrueBody.scrollLeft + event.clientX - objToolTip.offsetWidth + "px" : window.pageXOffset + e.clientX - objToolTip.offsetWidth + "px";
        else if (currentX < leftEdge)
            objToolTip.style.left = "5px";
        else
            // Else, place the tool tip where the mouse is positioned.
            objToolTip.style.left = currentX + toolTipOffsetX + "px"

        // Now a similar procedure for the vertical position.
        if (bottomEdge < objToolTip.offsetHeight)
            objToolTip.style.top = ie ? ieTrueBody.scrollTop + event.clientY - objToolTip.offsetHeight - toolTipOffsetY + "px" : window.pageYOffset + e.clientY - objToolTip.offsetHeight - toolTipOffsetY + "px"
        else
            objToolTip.style.top = currentY + toolTipOffsetY + "px";
        
        // objToolTip.style.visibility = "visible";
    }
}

function HideToolTip(){
    document.onmousemove = null;
    objToolTip = false;
    window.document.getElementsByTagName("body")[0].removeChild($(idToolTip));
}

function f_showFieldset(v_id) {
    if (document.getElementById("div_" + v_id + "_open").style.display == "none") {
        document.getElementById("div_" + v_id + "_open").style.display = "block";
        document.getElementById("div_" + v_id + "_closed").style.display = "none";
        document.getElementById("img_Fieldset_" + v_id).src = "/images/fieldset_hide.gif";
    }
    else {
        document.getElementById("div_" + v_id + "_open").style.display = "none";
        document.getElementById("div_" + v_id + "_closed").style.display = "block";
        document.getElementById("img_Fieldset_" + v_id).src = "/images/fieldset_show.gif";
    }
}

var v_countdowntime;
var v_countdownelement;
function f_countdown(v_minutes, v_element) {
    v_countdowntime = new Array(Math.abs(v_minutes / 60), (v_minutes - (Math.abs(v_minutes / 60) * 60)), 0);
    v_countdownelement = $(v_element);
    f_countdowndate();
}

function f_countdowndate() {
    if (v_countdowntime[2] == 0) {
        if (v_countdowntime[1] == 0) {
            v_countdowntime[0]--;
            v_countdowntime[1] = 59;
        }
        else {
            v_countdowntime[1]--;
        }
        v_countdowntime[2] = 59;
    }
    else {
        v_countdowntime[2]--;
    }

    if (String(v_countdowntime[0]).length == 1) {
        v_countdowntime[0] = "0" + v_countdowntime[0];
    }
    if (String(v_countdowntime[1]).length == 1) {
        v_countdowntime[1] = "0" + v_countdowntime[1];
    }
    if (String(v_countdowntime[2]).length == 1) {
        v_countdowntime[2] = "0" + v_countdowntime[2];
    }
    v_countdownelement.innerHTML = v_countdowntime[0] + ":" + v_countdowntime[1] + ":" + v_countdowntime[2];
    if (v_countdowntime[0] > 0 || v_countdowntime[1] > 0 || v_countdowntime[2] > 0) {
        v_next = window.setTimeout("f_countdowndate();", 1000);
    }
}

function f_imagehover(v_img) {
    if ($(v_img).style.visibility == "hidden") {
        $(v_img).style.visibility = "visible";
    }
    else if (v_ImageStates[v_img] != 1) {
        $(v_img).style.visibility = "hidden";
    }
}

var v_ImageStates = new Object();
function f_ClickImage(v_img, v_checkbox) {
    if (v_ImageStates[v_img] != 1) {
        v_ImageStates[v_img] = 1;
        if (v_checkbox != null) {
            $(v_checkbox).checked = true;
        }
    }
    else {
        v_ImageStates[v_img] = 0;
        if (v_checkbox != null) {
            $(v_checkbox).checked = false;
        }
    }
}
