﻿function General_DoubleClick_OnSubmitFunction(returnVal) {
    // Page_BlockSubmit=true (pouze na IE!) a Page_IsValid=false, pokud std. ASP validatory nepovoli submit
    if (typeof(returnVal) != 'undefined' && returnVal === false) return false;
    if (typeof(returnVal) == 'undefined' && typeof (Page_IsValid) != 'undefined' && Page_IsValid === false) return false;
    if(Gordic_General_WebApplication_DoubleClickSubmitted === false) {
        Gordic_General_WebApplication_DoubleClickSubmitted = true; 
        if (typeof(SetStatusLoading) != 'undefined') SetStatusLoading();
        return true;
    } else {
        window.alert(Gordic_General_WebApplication_DoubleClickMessage);
        return false;
    }
}

// AJAX doplneni - po dokonceni AJAX (PartialPageLoad) pozadavku se znovu vyresetuje Gordic_General_WebApplication_DoubleClickOnSubmit
function ApplicationLoadHandler() {
    if(typeof(Sys.WebForms)!='undefined' && typeof(Sys.WebForms.PageRequestManager)!='undefined')
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(new Function("Gordic_General_WebApplication_DoubleClickSubmitted = false;"));
}
if (typeof(Sys) != 'undefined') Sys.Application.add_load(ApplicationLoadHandler); // AJAX
// END AJAX

function DefaultKeypress(ev) { 
    if ((ev.keyCode == 27) && (typeof(ExitButton) != 'undefined') && (ExitButton != null) && (ExitButton.disabled != true)) 
        ExitButton.click(); 
    else if ((ev.keyCode == 27) && (typeof(CancelButton) != 'undefined') && (CancelButton != null) && (CancelButton.disabled != true)) 
        CancelButton.click(); 
    else if (typeof(DebugKeypress) != 'undefined') DebugKeypress(ev);
    return true; 
}

document.oncontextmenu = new Function("ev", "if (ev && ev.preventDefault) ev.preventDefault(); else event.returnValue = false; return false;"); // IE + FF
document.onkeypress = new Function("ev", "if (ev) return DefaultKeypress(ev); else return DefaultKeypress(window.event);"); // IE + FF

var Gordic_General_WebApplication_DoubleClickSubmitted = false;
if (document.forms.length > 0) {
    var form = document.forms[0];

    // pretizeni onsubmit
    var oldSubmit = new Function();
    if (typeof(Sys)=='undefined' || typeof(Sys.WebForms)=='undefined' || typeof(Sys.WebForms.PageRequestManager)=='undefined') {
        if(form.onsubmit != null) oldSubmit = form.onsubmit;
        form.onsubmit = function () { return General_DoubleClick_OnSubmitFunction(oldSubmit()); }
    } else {
        if (Sys.WebForms.PageRequestManager.getInstance()._onsubmit != null) oldSubmit = Sys.WebForms.PageRequestManager.getInstance()._onsubmit; 
        Sys.WebForms.PageRequestManager.getInstance()._onsubmit = function () { return General_DoubleClick_OnSubmitFunction(oldSubmit()); } 
    }
    
    // pretizeni onload    
    var oldLoad = new Function();
    if(window.onload != null) oldLoad = window.onload;
    window.onload = 
        function () { 
            oldLoad();
            if (typeof (GWP_UserAfterLoad) == "function") GWP_UserAfterLoad(); 
            if (typeof (GWP_UserAsyncLoad) == "function") window.setTimeout(GWP_UserAsyncLoad, 1);
        }
    
    // pretizeni onunload    
    var oldUnload = new Function();
    if(window.onunload != null) oldUnload = window.onunload;
    window.onunload = 
        function () { 
            if (typeof(GWP_UserBeforeUnload) == "function") GWP_UserBeforeUnload(); 
            oldUnload(); 
            if (typeof(GWP_UserPageClose) == "function" && Gordic_General_WebApplication_DoubleClickSubmitted === false) GWP_UserPageClose(); 
        }
}

