﻿var new_modal;
var thispath;

//MODAL OK+STORNO+DELETE ----------------------------------------------
function create_modal_okstornodel(id, width, height, title, id_item,typ,form_name) {
    new_modal = $(id);
    $(id).dialog({
        width: width,
        height: height,
        modal: true,
        title: title,
        resizable: false,
        buttons: {
            Uložit: function () { parent.if_upload.checkform(form_name); },
            Storno: function () { $(this).dialog("close"); },
            Odstranit: function () { delete_item(id_item,typ); }
        }

    });
}
//MODAL OK+STORNO ----------------------------------------------
function create_modal_okstorno(id, width, height, title,form_name) {
    new_modal = $(id);
    $(id).dialog({
        width: width,
        height: height,
        modal: true,
        title: title,
        resizable: false,
        buttons: {
            Uložit: function () { parent.if_upload.checkform(form_name); },
            Storno: function () {
                $(this).dialog("close");
            }
        }

    });
}
//MODAL STORNO ----------------------------------------------
function create_modal_storno(id, width, height, title) {
    new_modal = $(id);
    $(id).dialog({
        width: width,
        height: height,
        modal: true,
        title: title,
        resizable: false,
        buttons: {
            Storno: function () {
                $(this).dialog("close");
            }
        }

    });
}
//SKRYTI MODALU ----------------------------------------------
function HideUpload() {
    new_modal.dialog("close");
    //new_modal.html("<img src='img/oForm/loading2.gif' />");
}

//MODAL CONFIRM ----------------------------------------------
function create_modal_confirm(new_location, dialog_text, dialog_title) {
    $("#dialog-confirm-text").html(dialog_text);
    $("#dialog:ui-dialog").dialog("destroy");
    $("#dialog-confirm").dialog({
        resizable: false,
        height: 200,
        modal: true,
        title: dialog_title,
        buttons: {
            Potvrdit: function () {
                //$(this).dialog("close");
                location = new_location;
            },
            Zavřít: function () {
                $(this).dialog("close");
            }
        }
    });
}

//MODAL CONFIRM2 BEZ REDIREKTU ----------------------------------------------
function create_modal_confirm2(exec, dialog_text, dialog_title) {
    $("#dialog-confirm-text").html(dialog_text);
    $("#dialog:ui-dialog").dialog("destroy");
    $("#dialog-confirm").dialog({
        resizable: false,
        height: 200,
        modal: true,
        title: dialog_title,
        buttons: {
            Potvrdit: function () {
                //$(this).dialog("close");
                eval(exec);
                $(this).dialog("close");
            },
            Zavřít: function () {
                $(this).dialog("close");
            }
        }
    });
}
//AJAX POST FORMULARE ----------------------------------------------
function xmlhttpPost(strURL, formname, vElement, vLoadPage) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari/IE7+
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE6
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.setRequestHeader("charset", "utf-8");
    self.xmlHttpReq.onreadystatechange = function () {
        if (self.xmlHttpReq.readyState == 4 && self.xmlHttpReq.status == 200) {
            updatepage(vElement, vLoadPage);
        }
    }
    self.xmlHttpReq.send(getquerystring(formname));
    $(vElement).html("<img src='img/oForm/loading2.gif' />");
}

function getquerystring(formname) {
    var form = document.forms[formname];
    var qstr = "";

    function GetElemValue(name, value) {
        qstr += (qstr.length > 0 ? "&" : "")
            + encodeURIComponent(name).replace(/\+/g, "%2B") + "="
            + encodeURIComponent(value ? value : "").replace(/\+/g, "%2B");
        //+ escape(value ? value : "").replace(/\n/g, "%0D");
    }

    var elemArray = form.elements;
    for (var i = 0; i < elemArray.length; i++) {
        var element = elemArray[i];
        var elemType = element.type.toUpperCase();
        var elemName = element.name;
        if (elemName) {
            if (elemType == "TEXT"
                    || elemType == "TEXTAREA"
                    || elemType == "PASSWORD"
					|| elemType == "BUTTON"
					|| elemType == "RESET"
					|| elemType == "SUBMIT"
					|| elemType == "FILE"
					|| elemType == "IMAGE"
                    || elemType == "SEARCH"
                    || elemType == "HIDDEN")
                GetElemValue(elemName, element.value);
            else if (elemType == "CHECKBOX" && element.checked)
                GetElemValue(elemName,
                    element.value ? element.value : "On");
            else if (elemType == "RADIO" && element.checked)
                GetElemValue(elemName, element.value);
            else if (elemType.indexOf("SELECT") != -1)
                for (var j = 0; j < element.options.length; j++) {
                    var option = element.options[j];
                    if (option.selected)
                        GetElemValue(elemName,
                            option.value ? option.value : option.text);
                }
        }
    }
    return qstr;
}

function updatepage(vElement, vLoadPage) {
    //location = $.Params.set('ap', '1').toString();
    //location.reload();
    //pridat parametry pro ostatni seznamy.. dynamicky id divu, etc
    //$(vElement).load(vLoadPage + "?" + decodeURI(window.location.search.substring(1)));
    $(vElement).load(vLoadPage);

}
//ZMENA STAVU VSECH CHK ----------------------------------------------
function sel_all(stav, group_id) {
    $(group_id).find(':checkbox').attr('checked', stav);
}


//UZAMYKANI ZAZNAMU -------------------------------------------------
function record_lock_update(table, id_rec, id_user) {
    $.get("js_data/exchange.asp?page=RecordLock&table=" + table + "&id_rec=" + id_rec + "&id_user=" + id_user);
}
function start_lock_interval(table, id_rec, id_user) {
    window.setInterval("record_lock_update('"+table+"', "+id_rec+", "+id_user+")", 40000);
}
//OSTATNI ----------------------------------------------
//tabs
$(function () {
    $('#tabs').tabs();
});
//buttony
$(function () {
    $('input:submit, button, input:button, #Rec_nav a').button();
});

function googleTranslateElementInit() {
    new google.translate.TranslateElement({
        pageLanguage: 'cs'
    }, 'google_translate_element');
}

function getCalendar(datum) {
    $("#box_calendar").load(vAppPath+'/js_data/exchange.asp?page=getCalendar&datum=' + datum);
}
