﻿function General_DoubleClick_OnSubmitFunction() {
    var returnVal = Gordic_General_WebApplication_DoubleClickFormOnSubmitFunction();
    // Page_BlockSubmit=true (pouze na IE!) a Page_IsValid=false, pokud std. ASP validatory nepovoli submit
    if((typeof(returnVal) != 'undefined' && returnVal === false) || (typeof(Page_IsValid) != 'undefined' && Page_IsValid === false)) return false;
    if(!Gordic_General_WebApplication_DoubleClickSubmitted) {
        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;
var Gordic_General_WebApplication_DoubleClickFormOnSubmitFunction = new Function();

if (document.forms.length > 0) {
    var form = document.forms[0];
    if(form.onsubmit != null) Gordic_General_WebApplication_DoubleClickFormOnSubmitFunction = form.onsubmit;
    form.onsubmit = new Function("return General_DoubleClick_OnSubmitFunction();");
}

