﻿function RedirectPageUrl() {
    try {
        var l = isMainPage;
    }
    catch (ex) {//если переменная не определена
        isMainPage = false;
    }
    if (isMainPage == true) {
        WebApplication.Services.InfoService.GetRedirectUrlLogin(OnRequestComplete, OnError);
    } else {
        window.location.reload();
    }
}
function OnRequestComplete(url) {
    if (url == null || url == 'undefined' || window.location.pathname== url)
        window.location.reload();
    else
        window.location = url;
}
function OnError() {
    alert("Ошибка загрузки");
}
function OnEnter() {
    $('div.unauth').toggle();
    $('div#blockAuthorizationContainer').toggle();

    document.getElementById('loginDiv').style.overflow = 'hidden';
    document.getElementById('forLinksContainer').style.overflow = 'hidden';

    if (document.getElementById('blockAuthorizationContainer') != null) {
        document.getElementById('forLinksContainer').style.display = '';
        document.getElementById("divCancel").style.display = '';
    }
    else {
        document.getElementById('ServiceOff').style.display = '';
        document.getElementById("divCancel").style.display = 'none';
    }    
    var err = getElementsByClass('blockAuthorizationError', document.getElementById('blockAuthorizationContainer'),'div');
    if ( err.length > 0) {
        document.getElementById("divCancel").style.top = '19px';
    }
    else
        document.getElementById("divCancel").style.top = '2px'; 
    return false;
}
function OnReg() {
    if (document.getElementById('blockAuthorizationContainer') == null) {
        document.getElementById('ServiceOff').style.display = '';
        $('div.unauth').toggle();
    }
    else{
        window.location = 'http://web.kurortmag.ru/login.aspx';
    }
}
function OnCancel() {
    $('div.unauth').toggle();
    $('div#blockAuthorizationContainer').toggle();

    document.getElementById('loginDiv').style.overflow = '';
    document.getElementById('forLinksContainer').style.overflow = '';

    document.getElementById('forLinksContainer').style.display = 'none';
    document.getElementById("divCancel").style.display = 'none';
}

function OnClientAuthorizationSuccess() {
    document.getElementById('forLinksContainer').style.display = 'none';
    document.getElementById('divCancel').style.display = 'none';
    RedirectPageUrl();
}
function OnClientLogout() {    
    $('div.unauth').toggle();
    $('div#blockAuthorizationContainer').toggle();
    document.getElementById('forLinksContainer').style.display = 'none'; 
    RedirectPageUrl();
}
