    
    var xStatus = true;
    var reloadState = false;

    function blockit()
    {
        $.blockUI({ message: '<h1><img src="/images/busy.gif" /> Kérlek várj... ha sokáig nem megy, frissíts!</h1>' ,
            focusInput: true,
            showOverlay: false,
                css: { 
                    border: 'none', 
                    fadeIn: 0,
                    top: '20%',
                    padding: '15px', 
                    backgroundColor: '#000', 
                    '-webkit-border-radius': '10px', 
                    '-moz-border-radius': '10px', 
                    opacity: .8, 
                    color: '#fff' 
                }
            }
        ); 
    }

    function errorDialog(error, title)
    {
        if(title == undefined) title = "Hiba";
        $("#dialog-error").dialog("destroy");
        $("#dialog-error #error").html(error);
        $("#dialog-error").dialog({
            modal: true,
            title: title,
            hide: "explode",
            buttons: {
                Ok: function() {
                    $(this).dialog('close');
                }
            }
        });
        return asux = false;
    }

    function messageDialog(message, title)
    {
        if(title == undefined) title = "Üzenet";
        $("#dialog-highlight").dialog("destroy");
        $("#dialog-highlight #highlight").html(message);
        $("#dialog-highlight").dialog({
            modal: true,
            title: title,
            hide: "explode",
            buttons: {
                Ok: function() {
                    $(this).dialog('close');
                    
                    if(reloadState) 
                    {
                        document.location.href = document.location.href;
                        reloadState = false;
                    }
                }
            }
        });
        return true;
    }

    function newsletterDialog()
    {
        $("#dialog-newsletter").dialog("destroy");
        $("#dialog-newsletter").dialog({
            modal: true,
            hide: "explode",
            width: 550
        });
        return asux = false;
    }
        
 
// pre-submit callback 
function showRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
    //alert('About to submit: \n\n' + queryString); 
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true; 
} 
 
// post-submit callback 
function showResponse(responseText, statusText, xhr, $form)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 
    if(responseText.error != undefined)
    {
        errorDialog(responseText.message);
        xStatus = false;
    }
        
    if(responseText.success != undefined)
    {
        messageDialog(responseText.message);  
    }
        
        
    if(responseText.target != undefined)
    {
        $(responseText.target).html(responseText.message);
        if(responseText.trReg != undefined && responseText.trReg != false)
        {
            $.cookie("trid[" + responseText.trReg +"]", true, { expires: 50 });
        }
    }
        
    /*
    alert(responseText.error);
    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
        '\n\nThe output div should have already been updated with the responseText.'); 
        */
}     
            
        
    $(document).ready(function()
    {
   var options = { 
        target:        '.completeTrReg',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse  // post-submit callback 
 
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        ,dataType:  'json'        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 

        $("#language_selector").change(function() {
            window.location.href = "/" + $(":selected",this).val();
        });

        $(".nav .nav").hide();
        
        $(".nav li").live("mouseover mouseout", function(event) {
            if (event.type == 'mouseover') {
                $(this).children(".nav").show();
                //console.log("Over %o", $(this).children(".nav"));
                //$("this > .nav").show();
            }
            else
            {
                //$("this > .nav").hide();
                $(this).children(".nav").hide();
                //console.log("NOver %o", $(this).children(".nav"));
            }
        });
        
        $(".showTrRegForm").live("click", function(e) {
            e.preventDefault();
            $(this).closest(".module").find(".trainingRegistration").slideDown();
        });

        $(".cancelTrReg").live("click", function(e) {
            e.preventDefault();
            $(this).closest(".module").find(".trainingRegistration").slideUp();
        });
     
        $(".sendTrReg").live("click", function(e) {
            e.preventDefault();
            var x = $(this).closest(".module").find(".trainingRegistrationForm");
            
            if(x.validationEngine({
                returnIsValid:              true, 
                /*inlineValidation:           true,*/
                validationEventTriggers:    "keyup blur", 
                promptPosition:             "centerRight"})
            )
            {
                x.ajaxSubmit(options);
                if(xStatus)
                {
                    $(this).closest(".module").find(".completeTrReg").slideDown();
                    $(this).closest(".module").find(".trainingRegistration").slideUp();
                }
                
            }

        });
        
        $("#openNewsletter, .openNewsletter").click(newsletterDialog);
        
        $("#nlSubs").click(function(e) {
            e.preventDefault();
            var x = $("#newsletterSubscribeForm");
            
            if(x.validationEngine({
                returnIsValid:              true, 
                scroll:                     false,
                containerOverflowDOM:"#newsletterSubscribeForm",
                containerOverflow:true,
                /*inlineValidation:           true,*/
                validationEventTriggers:    "keyup blur", 
                promptPosition:             "centerRight"})
            )
            {
                x.ajaxSubmit(options);
                if(xStatus)
                {
                    $("#dialog-newsletter").dialog("close");
                }
            }
        });

        $("#nlUnsubs").click(function(e) {
            e.preventDefault();
            var x = $("#newsletterSubscribeForm");
            
            if($("[name=email]", x).val())
            {
                $("[name=c]", x).val("newsletterUnsubscriptionConfirm");
                x.ajaxSubmit(options);
                if(xStatus)
                {
                    $("#dialog-newsletter").dialog("close");
                }
            }
        });
        
        $("button, .button").button();
     
        
     
    });

     
