
// system (prihlasovanie, autentifikacia, ...)
// posledne volana funkcia pred loginom
var _lf = null;
// kontrola prihlasenia bude prebiehat na serveri
function handleApp_registracia() {
    aShowRegistrationForm();
}

function handleApp_login() {
    aShowLoginForm();
}


// zobrazenie prihlasovacieho dialogu
function aShowLoginForm() {
    $('#app-container').attr('className', 'app-bcg');
    //$('#app-container').empty();
    $('#app-container-promo').hide();

    if ($('#app-container-login').length == 0) {
        // hlavny app kontainer pre login
        $('<div class="app-container-login" id="app-container-login"></div>').appendTo('#app-container');

        // chybove hlasky
        $('<div class="alert" id="error-login-alert" style="display:none"></div>').appendTo('#app-container-login');

        // kontainer s prihlasovacim boxom
        $('<div class="login" id="login-form-container"></div>').appendTo('#app-container-login');

        // kontainer s nejakym pokecom
        $('<div class="info-text">' + msg[5] + '</div>').appendTo('#app-container-login');
        $(' <a href="#" id="pass_reset">' + msg[53] + '</a>').appendTo('div.info-text');



        $('#login-form-container').html('<span class="">' + msg[3] + '</span>'
                + '<input type="text" value="" name="u" id="u" class="" /><br />'
                + '<span class="">' + msg[4] + '</span>'
                + '<input type="password" value="" name="p" id="p" class="" />'
		        //+ '<span class=""><img src="" id="captchaImg" /></span><input type="text" value="" name="c" id="c" class="" />'
                + '<a href="#" class="login-btn" id="login-btn"></a>'
                + '<a href="#" class="register-btn" id="register-btn"></a>');

        //$('<div class="info-text-heslo" id="captcha">' + msg[51] + '</div>').appendTo('#app-container-login');


        // zavesim na buttony akcie
        //alert($('a#register-btn').length);
        $('a#pass_reset').unbind('click');
        $('a#pass_reset').click(aShowResetForm);

        $('a#register-btn').unbind('click');
        $('a#register-btn').click(aShowRegistrationForm);
        $('input#c').keyup(function (event) {
            if (event.keyCode == 13) aDoLogin();
        });
        $('input#u').focus();
        $('a#login-btn').unbind('click');
        $('a#login-btn').click(aDoLogin);
    }
    var date = new Date();
    $('#captchaImg').removeAttr('src');
    $('#captchaImg').attr({ src: appBaseHref + "Captcha/?time=" + date.getTime() + "" });


    return false;
}

// odosle prihlasovacie udaje na server
function aDoLogin() {
    var post = { 'user': $('input#u').val(),
        'pass': $('input#p').val()
    };
    if ('' != post.user && '' != post.pass) {
        var url_main = secureBaseHref + 'Auth/';
        var url_addon = 'Login';
        var url_complete = url_main + url_addon;
        showLoader();
        $.post(url_complete, post, function (data) {
            //alert(data);
            //var data = new Array();
            //data.error = true;
            //data.captcha_error = true;
            aLoginResult(data);
            hideLoader();
        }, 'json');
    } else {
        // zobrazim alert, ze nevyplnil prihlasovacie udaje
        $('#error-login-alert').html(msg[6]);
        $('#error-login-alert').show();
    }
    return false;
}

// spracuje vysledok prihlasenia
function aLoginResult(res) {
    //alert (res.cp +'--'+ res.scp);
    var date = new Date();
    if (res != undefined) {
        if (res.error != undefined) {
            $('#error-login-alert').empty();
            $('<span>' + msg[2] + '</span>').appendTo('#error-login-alert');
            $('#captchaImg').removeAttr('src');
            $('#captchaImg').attr({ src: appBaseHref + "captcha/?time=" + date.getTime() + "" });
            $('#error-login-alert').show();
            $('input#p').val('');
            $('input#c').val('');
        } else if (res.captcha_error != undefined) {
            $('#error-login-alert').empty();
            $('<span>' + msg[52] + '</span>').appendTo('#error-login-alert');
            $('#captchaImg').removeAttr('src');
            $('#captchaImg').attr({ src: appBaseHref + "captcha/?time=" + date.getTime() + "" });
            $('#error-login-alert').show();
            $('input#p').val('');
            $('input#c').val('');

        } else if (res.valid != undefined && res.valid == true) {
            if (res.username != undefined) createCookie('user', res.username, 30);
            if (res.email != undefined) createCookie('email', res.email, 30);
            if (res.key != undefined) createCookie('key', res.key, 30);

            aShowLogoutBox(res.username);
            $('#app-container-login').hide();
            // teraz by som mal ist na obrazovku, kde som povodne potreboval ist
            //if (_lf != null) _lf();
            $('#app-container-login').remove();
            handleHashAndGo();
            /*if (_hash['action'] == 'promo') {
            setActiveMenu('promo');
            doAction('promo');
            }*/
        }
    }
}

// zobrazim buton na odhlasenie
function aShowLogoutBox(username) {
    $('#header-login').html('<a href="#action=profile" id="profile-btn">' + username
        + '</a> | <a href="#action=logout" id="logout-btn">' + texts[8] + '</a>');
    $('#logout-btn').click(aDoLogout);
    $('#profile-btn').click(aChangeProfile);
}

// zobrazim buton na prihlasenie
function aShowLoginBox() {
    $('#header-login').html('<a href="#action=login" id="box-login-btn">' + texts[18] + '</a>');
    $('#box-login-btn').click(aShowLoginForm);
}

// skontrolujem, ci je prihlaseny
function aCheckIsLogged() {
    var url_main = appBaseHref + 'Auth/';
    var url_addon = 'CheckLogin';
    var url_complete = url_main + url_addon;
    $.getJSON(url_complete, function (data) {
        if (data != undefined) {
            if (data.valid != undefined && data.valid == true) {
                // je prihlaseny
                if (data.username != undefined) createCookie('user', data.username, 30);
                if (data.email != undefined) createCookie('email', data.email, 30);
                if (data.key != undefined) createCookie('key', data.key, 30);
                aShowLogoutBox(data.username);
            } else {
                // nie je prihlaseny
                eraseCookie('user');
                eraseCookie('email');
                eraseCookie('key');
                eraseCookie('PHPSESSID');
                aShowLoginBox();
            }
        }
    });
}

// urobim odhlasenie
function aDoLogout() {
    var url_main = appBaseHref + 'Auth/';
    var url_addon = 'Logout';
    var url_complete = url_main + url_addon;
    //alert(url_complete);
    showLoader();
    $.getJSON(url_complete, function (data) {
        // nie je prihlaseny
        eraseCookie('user');
        eraseCookie('email');
        eraseCookie('key');
        sd = new Array();
        s = new Array();
        aShowLoginBox();
        navigation('promo');
        hideLoader();
    });
    return false;
}

// zobrazenie formulara registracie
function aShowRegistrationForm() {
    //setHash('action=registracia');
    $('#app-container').attr('className', 'app-bcg');
    //$('#app-container').empty();

    if ($('#app-container-register').length == 0) {
        // hlavny app kontainer pre registraciu
        $('<div class="app-container-register" id="app-container-register"></div>').appendTo('#app-container');
    } else {
        $('#app-container-register').empty();
    }

    // chybove hlasky
    $('<div class="alert" id="error-register-alert">' + msg[13] + '</div>').appendTo('#app-container-register');
    $('#error-register-alert').hide();

    // kontainer s prihlasovacim boxom
    $('<div class="register" id="register-form-container"></div>').appendTo('#app-container-register');

    $('#register-form-container').html('<span class="">' + msg[3] + ' *</span>'
        + '<input type="text" value="" name="ru" id="ru" class="" /><br />'
        + '<span class="">' + msg[4] + ' *</span>'
        + '<input type="password" value="" name="rp" id="rp" class="" /><br />'
        + '<span class="">' + msg[7] + ' *</span>'
        + '<input type="password" value="" name="rp2" id="rp2" class="" /><br />'
        + '<span class="">' + msg[8] + ' *</span>'
        + '<input type="text" value="" name="re" id="re" class="" /><br />'
        + '<span class="">' + msg[9] + ' *</span>'
        + '<input type="text" value="" name="rc" id="rc" class="" /><br />'
        + '<a href="#" class="submit-btn" id="register-submit-btn"></a>'
        + '<a href="#" class="cancel-btn" id="register-cancel-btn"></a>');

    // kontainer s pokecom k heslu
    $('<div class="info-text-heslo">' + msg[10] + '</div>').appendTo('#app-container-register');

    // kontainer s pokecom k emailu
    $('<div class="info-text-email">' + msg[11] + '</div>').appendTo('#app-container-register');

    // kontainer s pokecom k aktivacnemu kodu
    $('<div class="info-text-kod">' + msg[12] + '</div>').appendTo('#app-container-register');

    // chybova hlaska k uzivatelskemu menu
    $('<div class="alert" id="error-register-username">' + msg[14] + '</div>').appendTo('#app-container-register');
    // chybova hlaska k uzivatelskemu menu
    $('<div class="alert" id="error-register-username-already-created">' + msg[60] + '</div>').appendTo('#app-container-register');
    // chybova hlaska k heslu
    $('<div class="alert" id="error-register-password">' + msg[16] + '</div>').appendTo('#app-container-register');
    // chybova hlaska k potvrdeniu hesla
    $('<div class="alert" id="error-register-password2">' + msg[15] + '</div>').appendTo('#app-container-register');
    // chybova hlaska k emailovej adrese
    $('<div class="alert" id="error-register-email">' + msg[18] + '</div>').appendTo('#app-container-register');
    // chybova hlaska k autorizacnemu kodu
    $('<div class="alert" id="error-register-code">' + msg[19] + '</div>').appendTo('#app-container-register');

    // zavesim na buttony akcie
    $('a#register-submit-btn').click(aSendRegistration);
    $('a#register-cancel-btn').click(function () { $('#app-container-register').hide(); $('#app-container-register').remove(); });

    //$('input#ru').bind('change', function() {$('#error-register-alert').hide();});
    //$('input#rp').bind('change', function() {$('#error-register-alert').hide();});
    //$('input#rp2').bind('change', function() {$('#error-register-alert').hide();});
    //$('input#re').bind('change', function() {$('#error-register-alert').hide();});
    //$('input#rc').bind('change', function() {$('#error-register-alert').hide();});

    $('#app-container-register').show();
    return false;
}




// odosle registracne udaje na server
function aSendRegistration() {
    var post = { 'user': $('input#ru').val(),
        'pass': $('input#rp').val(),
        'pass2': $('input#rp2').val(),
        'email': $('input#re').val(),
        'code': $('input#rc').val()
    };
    //if ('' != post.user && '' != post.pass && '' != post.pass2 && '' != post.email && '' != post.code) {
    var url_main = secureBaseHref + 'Auth/';
    var url_addon = 'Register';
    var url_complete = url_main + url_addon;
    //alert(url_complete);
    showLoader();
    $.post(url_complete, post, function (data) {
        aRegistrationResponse(data);
        // alert(data);
        hideLoader();
    }, 'json');
    //} else {
    //$('#error-register-alert').empty();
    //$('<span>' + msg[13] + '</span><br />').appendTo('#error-register-alert');
    //$('#error-register-alert').show();
    //}
    return false;
}

// vysledok registracie
function aRegistrationResponse(res) {
    if (res != undefined) {
        if (res.error != undefined) {
            $('#error-register-alert').hide();
            $('#error-register-username').hide();
            $('#error-register-username-already-created').hide();
            $('#error-register-password').hide();
            $('#error-register-password2').hide();
            $('#error-register-email').hide();
            $('#error-register-code').hide();
            $('input#ru').attr('class', '');
            $('input#rp').attr('class', '');
            $('input#rp2').attr('class', '');
            $('input#re').attr('class', '');
            $('input#rc').attr('class', '');
            if (res.error.empty_fields != undefined && res.error.empty_fields == true) $('#error-register-alert').show();
            if (res.error.user != undefined && res.error.user == true) {
                $('#error-register-username').show();
                $('input#ru').attr('class', 'input-error');
            }
            if (res.error.user_already_created) {
                var el = $('#error-register-username-already-created');
                if (!el.dataOriginal)
                    el.dataOriginal = el.text();
                el.text(el.dataOriginal.replace(/\{login}/g, res.error.user_already_created));
                $('#error-register-username-already-created').show();
                $('input#ru').attr('class', 'input-error');
            }
            if (res.error.password_nomatch != undefined && res.error.password_nomatch == true) {
                $('#error-register-password2').show();
                $('input#rp2').attr('class', 'input-error');
            }
            if (res.error.password_invalid != undefined && res.error.password_invalid == true) {
                $('#error-register-password').text(msg[17]);
                $('#error-register-password').show();
                $('input#rp').attr('class', 'input-error');
            }
            if (res.error.password_short != undefined && res.error.password_short == true) {
                $('#error-register-password').text(msg[16]);
                $('#error-register-password').show();
                $('input#rp').attr('class', 'input-error');
            }
            if (res.error.password_long != undefined && res.error.password_long == true) {
                $('#error-register-password').text(msg[50]);
                $('#error-register-password').show();
                $('input#rp').attr('class', 'input-error');
            }
            if (res.error.email != undefined && res.error.email == true) {
                $('#error-register-email').show();
                $('input#re').attr('class', 'input-error');
            }
            if (res.error.code != undefined && res.error.code == true) {
                $('#error-register-code').show();
                $('input#rc').attr('class', 'input-error');
            }
            //$('#error-register-alert').show();
        } else if (res.result != undefined && res.result == 'ok') {
            showDialog(msg[20], function () { $('#app-container-register').hide(); $('#app-container-register').remove(); });
        }
    }
}


function handleApp_profile() {
    aChangeProfile();
}
// zmena profilu
function aChangeProfile() {
    handleHash();
    //alert('zmena profilu');
    $('#app-container').attr('className', 'app-bcg');
    $('#app-container-promo').hide();

    if ($('#app-container-profil').length == 0) {
        // hlavny app kontainer pre registraciu
        $('<div class="app-container-profil" id="app-container-profil"></div>').appendTo('#app-container');
    } else {
        $('#app-container-profil').empty();
    }


    // chybove hlasky
    $('<div class="alert" id="error-register-alert" style="display:none">' + msg[13] + '</div>').appendTo('#app-container-profil');

    // kontainer s prihlasovacim boxom
    $('<div class="register" id="register-form-container"></div>').appendTo('#app-container-profil');

    $('#register-form-container').html('<span class="">' + msg[3] + '</span>'
        + '<input type="text" readonly="readonly" value="' + readCookie('user') + '" name="ru" id="ru" class="" disabled="disabled"/><br />'
        + '<span class="">' + msg[4] + '</span>'
        + '<input type="password" value="" name="rp" id="rp" class="" /><br />'
        + '<span class="">' + msg[7] + '</span>'
        + '<input type="password" value="" name="rp2" id="rp2" class="" /><br />'
        + '<span class="">' + msg[8] + '</span>'
        + '<input type="text" value="' + readCookie('email') + '" name="re" id="re" class="" /><br />'
        + '<a href="#action=' + _hash['action'] + '" class="save-btn" id="profil-submit-btn"></a>'
        + '<a href="#action=' + _hash['action'] + '" class="cancel-btn" id="profil-cancel-btn"></a>');

    // kontainer s pokecom k heslu
    $('<div class="info-text-heslo">' + msg[26] + '</div>').appendTo('#app-container-profil');

    // kontainer s pokecom k emailu
    $('<div class="info-text-email">' + msg[27] + '</div>').appendTo('#app-container-profil');

    $('<div class="alert" id="error-register-username">' + msg[14] + '</div>').appendTo('#app-container-profil');
    $('<div class="alert" id="error-register-username-already-created">' + msg[60] + '</div>').appendTo('#app-container-profil');
    // chybova hlaska k heslu
    $('<div class="alert" id="error-register-password">' + msg[16] + '</div>').appendTo('#app-container-profil');
    // chybova hlaska k potvrdeniu hesla
    $('<div class="alert" id="error-register-password2">' + msg[15] + '</div>').appendTo('#app-container-profil');
    // chybova hlaska k emailovej adrese
    $('<div class="alert" id="error-register-email">' + msg[18] + '</div>').appendTo('#app-container-profil');


    // zavesim na buttony akcie
    $('a#profil-submit-btn').click(aSendProfileChange);
    $('a#profil-cancel-btn').click(aCancelProfile);
    jQuery.each(jQuery.browser, function (i) {
        if ($.browser.msie && $.browser.version < 7) {
            $('.iframe-ie6-overlay-fix').css("left", "0px");
            $('.iframe-ie6-overlay-fix').css("width", "320px");
            $('.iframe-ie6-overlay-fix').fadeIn("fast");
        }
    });

    //$('input#rp').bind('change', function() {$('#error-register-alert').hide();});
    //$('input#rp2').bind('change', function() {$('#error-register-alert').hide();});
    //$('input#re').bind('change', function() {$('#error-register-alert').hide();});

    return false;
}

function aCancelProfile() {
    $('#app-container-profil').empty();
    $('#app-container-profil').remove();
    $('.iframe-ie6-overlay-fix').fadeOut("fast");
    $('.iframe-ie6-overlay-fix').css("left", "230px");
    //$('.iframe-ie6-overlay-fix').width("400px");
    handleHashAndGo();

}

// odosle udaje na server
function aSendProfileChange() {
    var post = { 'pass': $('input#rp').val(),
        'pass2': $('input#rp2').val(),
        'email': $('input#re').val()
    };
    /*if (post.pass != post.pass2) {
    $('#error-register-alert').show();
    $('#error-register-alert').empty();
    $('<span>' + msg[28] + '</span><br />').appendTo('#error-register-alert');
    } else if ('' == post.email) {
    $('#error-register-alert').show();
    $('#error-register-alert').empty();
    $('<span>' + msg[29] + '</span><br />').appendTo('#error-register-alert');
    } else {*/
    showLoader();
    var url_main = secureBaseHref + 'Auth/';
    var url_addon = 'Profile';
    var url_complete = url_main + url_addon;
    $.post(url_complete, post, function (data) {
        aProfileResponse(data);
        // alert(data);
        hideLoader();
    }, 'json');
    //}
    return false;
}

// vysledok upravy profilu
function aProfileResponse(res) {

    if (res != undefined) {
        if (res.error != undefined) {
            $('#error-register-alert').hide();
            $('#error-register-username').hide();
            $('#error-register-username-already-created').hide();
            $('#error-register-password').hide();
            $('#error-register-password2').hide();
            $('#error-register-email').hide();

            $('input#ru').attr('class', '');
            $('input#rp').attr('class', '');
            $('input#rp2').attr('class', '');
            $('input#re').attr('class', '');

            if (res.error.empty_fields != undefined && res.error.empty_fields == true) $('#error-register-alert').show();
            if (res.error.user != undefined && res.error.user == true) {
                $('#error-register-username').show();
                $('input#ru').attr('class', 'input-error');
            }
            if (res.error.user_already_created) {
                var el = $('#error-register-username-already-created');
                if (!el.dataOriginal)
                    el.dataOriginal = el.text();
                el.text(el.dataOriginal.replace(/\{login}/g, res.error.user_already_created));
                $('#error-register-username-already-created').show();
                $('input#ru').attr('class', 'input-error');
            }
            if (res.error.password_nomatch != undefined && res.error.password_nomatch == true) {
                $('#error-register-password2').show();
                $('input#rp2').attr('class', 'input-error');
            }
            if (res.error.password_invalid != undefined && res.error.password_invalid == true) {
                $('#error-register-password').text(msg[17]);
                $('#error-register-password').show();
                $('input#rp').attr('class', 'input-error');
            }
            if (res.error.password_short != undefined && res.error.password_short == true) {
                $('#error-register-password').text(msg[16]);
                $('#error-register-password').show();
                $('input#rp').attr('class', 'input-error');
            }
            if (res.error.password_long != undefined && res.error.password_long == true) {
                $('#error-register-password').text(msg[50]);
                $('#error-register-password').show();
                $('input#rp').attr('class', 'input-error');
            }
            if (res.error.email != undefined && res.error.email == true) {
                $('#error-register-email').show();
                $('input#re').attr('class', 'input-error');
            }

        } else if (res.result != undefined && res.result == 'ok') {
            //alert(msg[30]);
            //navigation('promo');
            //$('#app-container-register').hide();
            showDialog(msg[47], function () {
                eraseCookie('email');
                if (res.email != undefined) createCookie('email', res.email, 30);
                $('#app-container-profil').empty();
                $('#app-container-profil').remove();
                handleHashAndGo();
            });

        }
    }
}
// koniec system









function handleApp_reset() {
    aDoReset();
}

function aDoReset() {
    var post = { 'hash': _hash['hash'] };

    var url_main = secureBaseHref + 'Auth/';
    var url_addon = 'ResetRead';
    var url_complete = url_main + url_addon;
    showLoader();
    $.post(url_complete, post, function (data) {

        if (data.error != undefined && (data.error.nomatch == true || data.error.neplatne == true)) {
            hideLoader();
            showDialog(msg[59], function () {
                setHash('action', 'promo');
                handleHashAndGo();
            });
        } else {

            if (data.username != undefined) createCookie('user', data.username, 30);
            if (data.email != undefined) createCookie('email', data.email, 30);
            if (data.key != undefined) createCookie('key', data.key, 30);

            aResetProfile(data);
            hideLoader();
        }
    }, 'json');
    return false;
}

// zobrazenie formulara registracie
function aShowResetForm() {
    //setHash('action=registracia');
    $('#app-container').attr('className', 'app-bcg');
    //$('#app-container').empty();

    if ($('#app-container-reset').length == 0) {
        // hlavny app kontainer pre registraciu
        $('<div class="app-container-reset" id="app-container-reset"></div>').appendTo('#app-container');
    } else {
        $('#app-container-reset').empty();
    }

    // chybove hlasky
    $('<div class="alert" id="error-reset-nomatch" style="left: 248px; top: 98px;"></div>').appendTo('#app-container-reset');
    $('#error-reset-nomatch').hide();

    // kontainer s prihlasovacim boxom
    $('<div class="register" id="register-form-container"></div>').appendTo('#app-container-reset');

    $('#register-form-container').html('<span class="">' + msg[3] + '</span>'
        + '<input type="text" value="" name="ru" id="ru" class="" /><br />'
        + '<span class="">' + msg[8] + '</span>'
        + '<input type="text" value="" name="re" id="re" class="" /><br />'
        + '<a href="#" class="save-btn" id="reset-submit-btn"></a>'
        + '<a href="#" class="cancel-btn" id="reset-cancel-btn"></a>');

    // kontainer s pokecom k emailu
    $('<div class="info-text" style="top: 230px;">' + msg[56] + '</div>').appendTo('#app-container-reset');

    // zavesim na buttony akcie
    $('a#reset-submit-btn').click(aSendReset);
    $('a#reset-cancel-btn').click(function () { $('#app-container-reset').hide(); $('#app-container-reset').remove(); });



    $('#app-container-reset').show();
    return false;
}

function aSendReset() {
    var post = { 'user': $('input#ru').val(),
        'email': $('input#re').val()
    };
    var url_main = secureBaseHref + 'Auth/';
    var url_addon = 'Reset';
    var url_complete = url_main + url_addon;
    //alert(url_complete);
    showLoader();
    $.post(url_complete, post, function (data) {
        aResetResponse(data);
        // alert(data);
        hideLoader();
    }, 'json');

    return false;
}


// vysledok registracie
function aResetResponse(res) {
    if (res != undefined) {
        if (res.error != undefined) {
            if (res.error.empty_fields != undefined && res.error.empty_fields == true) {
                $('#error-reset-nomatch').html(msg[57]);
                $('#error-reset-nomatch').show();
            }
            else if (res.error.nomatch != undefined && res.error.nomatch == true) {
                //$('#error-reset-nomatch').html(msg[54] + res.error.email + msg[55]);
                //$('#error-reset-nomatch').show();
                $('#error-reset-nomatch').hide();
                showDialog(msg[54] + res.error.email + msg[55], function () { return });
            }

        } else if (res.result != undefined && res.result == 'ok') {
            showDialog(msg[58] + res.email, function () { $('#app-container-reset').hide(); $('#app-container-reset').remove(); });
        }
    }
}


function aResetProfile(res) {
    handleHash();
    //alert('zmena profilu');
    $('#app-container').attr('className', 'app-bcg');
    $('#app-container-promo').hide();

    if ($('#app-container-reset').length == 0) {
        // hlavny app kontainer pre registraciu
        $('<div class="app-container-reset" id="app-container-reset"></div>').appendTo('#app-container');
    } else {
        $('#app-container-reset').empty();
    }


    // chybove hlasky
    $('<div class="alertReset" id="error-register-alert" style="display:none">' + msg[13] + '</div>').appendTo('#app-container-reset');

    // kontainer s prihlasovacim boxom
    $('<div class="register" id="register-form-container"></div>').appendTo('#app-container-reset');

    $('#register-form-container').html('<span class="">' + msg[3] + '</span>'
		+ '<input type="text" readonly="readonly" value="' + readCookie('user') + '" name="ru" id="ru" class="" disabled="disabled"/><br />'
		+ '<span class="">' + msg[4] + '*</span>'
		+ '<input type="password" value="" name="rp" id="rp" class="" /><br />'
		+ '<span class="">' + msg[7] + '*</span>'
		+ '<input type="password" value="" name="rp2" id="rp2" class="" /><br />'
		+ '<input type="hidden" value="' + _hash['hash'] + '" name="hash" id="hash" class="" /><br />'
		+ '<a href="#action=' + _hash['action'] + '" class="save-btn" id="profil-submit-btn"></a>'
		+ '<a href="#action=' + _hash['action'] + '" class="cancel-btn" id="profil-cancel-btn"></a>');


    $('<div class="alert" id="error-register-username">' + msg[14] + '</div>').appendTo('#app-container-reset');
    $('<div class="alert" id="error-register-username-already-created">' + msg[60] + '</div>').appendTo('#app-container-reset');
    // chybova hlaska k heslu
    $('<div class="alert" id="error-register-password">' + msg[16] + '</div>').appendTo('#app-container-reset');
    // chybova hlaska k potvrdeniu hesla
    $('<div class="alert" id="error-register-password2">' + msg[15] + '</div>').appendTo('#app-container-reset');



    // zavesim na buttony akcie
    $('a#profil-submit-btn').click(aSendProfileReset);
    $('a#profil-cancel-btn').click(aCancelResetProfile);
    jQuery.each(jQuery.browser, function (i) {
        if ($.browser.msie && $.browser.version < 7) {
            $('.iframe-ie6-overlay-fix').css("left", "0px");
            $('.iframe-ie6-overlay-fix').css("width", "320px");
            $('.iframe-ie6-overlay-fix').fadeIn("fast");
        }
    });



    return false;
}

function aCancelResetProfile() {
    $('#app-container-reset').empty();
    $('#app-container-reset').remove();
    $('.iframe-ie6-overlay-fix').fadeOut("fast");
    $('.iframe-ie6-overlay-fix').css("left", "230px");
    //$('.iframe-ie6-overlay-fix').width("400px");
    setHash('action', 'promo');
    handleHashAndGo();

}

// odosle udaje na server
function aSendProfileReset() {
    var post = { 'pass': $('input#rp').val(),
        'pass2': $('input#rp2').val(),
        'hash': $('input#hash').val()
    };
    /*if (post.pass != post.pass2) {
    $('#error-register-alert').show();
    $('#error-register-alert').empty();
    $('<span>' + msg[28] + '</span><br />').appendTo('#error-register-alert');
    } else if ('' == post.email) {
    $('#error-register-alert').show();
    $('#error-register-alert').empty();
    $('<span>' + msg[29] + '</span><br />').appendTo('#error-register-alert');
    } else {*/
    showLoader();
    var url_main = secureBaseHref + 'Auth/';
    var url_addon = 'ProfileReset';
    var url_complete = url_main + url_addon;
    $.post(url_complete, post, function (data) {
        aProfileResetResponse(data);
        // alert(data);
        hideLoader();
    }, 'json');
    //}
    return false;
}

// vysledok upravy profilu
function aProfileResetResponse(res) {

    if (res != undefined) {
        if (res.error != undefined) {
            $('#error-register-alert').hide();
            $('#error-register-username').hide();
            $('#error-register-username-already-created').hide();
            $('#error-register-password').hide();
            $('#error-register-password2').hide();

            $('input#ru').attr('class', '');
            $('input#rp').attr('class', '');
            $('input#rp2').attr('class', '');

            if (res.error.empty_fields != undefined && res.error.empty_fields == true) $('#error-register-alert').show();
            if (res.error.user != undefined && res.error.user == true) {
                $('#error-register-username').show();
                $('input#ru').attr('class', 'input-error');
            }
            if (res.error.user_already_created) {
                var el = $('#error-register-username-already-created');
                if (!el.dataOriginal)
                    el.dataOriginal = el.text();
                el.text(el.dataOriginal.replace(/\{login}/g, res.error.user_already_created));
                $('#error-register-username-already-created').show();
                $('input#ru').attr('class', 'input-error');
            }
            if (res.error.password_nomatch != undefined && res.error.password_nomatch == true) {
                $('#error-register-password2').show();
                $('input#rp2').attr('class', 'input-error');
            }
            if (res.error.password_invalid != undefined && res.error.password_invalid == true) {
                $('#error-register-password').text(msg[17]);
                $('#error-register-password').show();
                $('input#rp').attr('class', 'input-error');
            }
            if (res.error.password_short != undefined && res.error.password_short == true) {
                $('#error-register-password').text(msg[16]);
                $('#error-register-password').show();
                $('input#rp').attr('class', 'input-error');
            }
            if (res.error.password_long != undefined && res.error.password_long == true) {
                $('#error-register-password').text(msg[50]);
                $('#error-register-password').show();
                $('input#rp').attr('class', 'input-error');
            }


        } else if (res.result != undefined && res.result == 'ok') {
            //alert(msg[30]);
            //navigation('promo');
            //$('#app-container-register').hide();
            showDialog(msg[47], function () {
                $('#app-container-reset').empty();
                $('#app-container-reset').remove();
                setHash('action', 'promo');
                handleHashAndGo();
            });

        }
    }
}
// koniec system




