﻿///
/// Copyright © 2009, ayondo GmbH.
/// All rights reserved.
/// http://www.ayondo.com
///
/// Redistribution and use in source and binary forms, with or without
/// modification, is strictly prohibited.
///
var DialogBg1 = new Image();
DialogBg1.src = "Images/DialogBackground.png";
var DialogClosePic = new Image();
DialogClosePic.src = "Images/DialogClose.gif";

var showLanguageMenuFlag = false;
//
// Page Load event
//
function pageLoad() {

    getScreen();
    TOOL = $create(ayondo.Tool, { id: "TOOL" }, null, null, null);
    TOOLTIP = $create(ayondo.ToolTip, { id: "TOOLTIP" }, null, null, null);

    checkBrowser();
    //  move to main page
    ///  checkFlashPlayer();

    var userLoginBox = $get("UserLogin");
    var passwordLoginBox = $get("PasswordLogin");




    $addHandler(userLoginBox, "keypress", CheckInput);
    $addHandler(passwordLoginBox, "keypress", CheckInput);

    if ($get("LoginButton") != null) {
        $get("LoginButton").onclick = function() {
            doLogin();
        }
    }


    $get("mainContainer").onclick = function() {
        if (!showLanguageMenuFlag) {
            $get("LangMenuPanel").style.visibility = "hidden";
        } else {
            showLanguageMenuFlag = false;
        }
    }


    var tmpcookie = new Date();
    chkcookie = (tmpcookie.getTime() + '');
    document.cookie = "chkcookie=" + chkcookie + "; path=/";
    if (document.cookie.indexOf(chkcookie, 0) < 0) {
        createCookieDialog();
    }

    var more = $get("TeaserRealMoneyBtn_comingSoon");
    TOOLTIP.Text = Loc.Dat.login.comingSoon;

    $addHandler(more, "mouseover", TOOLTIP.show);
    $addHandler(more, "mouseout", TOOLTIP.hide);


    var video = $get("TeaserVideoBtn_comingSoon");

    $addHandler(video, "mouseover", TOOLTIP.show);
    $addHandler(video, "mouseout", TOOLTIP.hide);

    var fp = getparams("fp");
    if (fp == 1) {
        showPasswordChangedResponse(true);
    }
    else if (fp == 2) {
        showPasswordChangedResponse(false);
    }










    if (showDoubleLoginErrorMessage == "true") showErrorMessage(Loc.Dat.login.OnlyOneLoginAllowed);
    else if (showAccountInvalidErrorMessage == "true") showErrorMessage(Loc.Dat.login.AccountInvalid);





    var test = TOOL.get_url_param("reg");
    if (test != "") {
        location.href = "Default.aspx?lang=de&id=gratis-registrierung";
    }


    if ($get("RegisterNowBtn")) initRegister();


    if ($get("ContactSend")) initContactHandler();

    if (FirstLogin == "true") {
        $get("GuidedTour").style.visibility = "visible";
        var bounds = Sys.UI.DomElement.getBounds($get("UserLogin"));
        var welcomeText = "<b>" + Loc.Dat.login.loginGuide.head + "</b>" + "<br>" + Loc.Dat.login.loginGuide.copy;
        TOOLTIP.addDisplayWidget("welcome", bounds.x - 210, bounds.y - 20, "e", welcomeText);
        $get("GuidedTour").onclick = function() {
            $get("GuidedTour").style.visibility = "hidden";
        }
    }

    if (ThankYou == "true") {
        $get("GuidedTour").style.visibility = "visible";
        var bounds = Sys.UI.DomElement.getBounds($get("UserLogin"));
        var thankYouText = "<b>" + Loc.Dat.click_accept_thanks + "</b>";
        TOOLTIP.addDisplayWidget("welcome", bounds.x - 210, bounds.y - 20, "e", thankYouText);
        $get("GuidedTour").onclick = function() {
            $get("GuidedTour").style.visibility = "hidden";
        }
    }
    else if (ThankYou == "false") {
        $get("GuidedTour").style.visibility = "visible";
        var bounds = Sys.UI.DomElement.getBounds($get("UserLogin"));
        var thankYouText = "<b>" + Loc.Dat.click_accept_failed + "</b>";
        TOOLTIP.addDisplayWidget("welcome", bounds.x - 210, bounds.y - 20, "e", thankYouText);
        $get("GuidedTour").onclick = function() {
            $get("GuidedTour").style.visibility = "hidden";
        }
    }
    
}
function initContactHandler() {
    $get("ContactSend").onclick = function() {
        var success = true;
        clearContactErrorFields();
        var ContactEMail = $get("ContactEMail").value;
        var ContactName = $get("ContactName").value;
        var ContactSubject = $get("ContactSubject").value;
        var ContactMessage = $get("ContactMessage").value;

        if (!TOOL.checkField(ContactName, "ErrLabelName", "name", 2, Loc.Dat.Errors.e12)) success = false;
        if (!TOOL.checkField(ContactSubject, "ErrLabelSubject", "text", 2, Loc.Dat.Errors.e17)) success = false;
        if (!TOOL.checkField(ContactMessage, "ErrLabelMsg", "text", 2, Loc.Dat.Errors.e15)) success = false;

        if (!TOOL.checkEMail(ContactEMail)) {
            TOOL.showError("ErrLabelEmail", Loc.Dat.Errors.e13);
            success = false;
        }

        if (success) {
            LoginService.SendContactMessage(ContactEMail, ContactName, ContactSubject, ContactMessage, ContactResult, callError);
        }

    }
    $get("ContactDelFields").onclick = function() {
        clearContactInputFields();
        clearContactErrorFields()
    }
    $get("BackBtn").onclick = function() {
        location.href = "Default.aspx";
    }


}

// call page function / pageId has to be registered in conctent.js  - setupPage
function callPage(pageId) {

    var title = eval("Loc.Dat.pageTitles." + pageId);
    Sys.Application.addHistoryPoint({ h: pageId }, "ayondo | " + title);
}

function checkFlashPlayer() {
    playerVersion = swfobject.getFlashPlayerVersion();
    if (playerVersion.major < 9) {
        createDialog(1, 300, 300);
        $get("DialogTitle").innerHTML = Loc.Dat.login.Errors.PlayerVersion;
        var CH = $get("DialogContent");
        CH.style.backgroundColor = "#ffffff";
        var PlayerWarningDiv = document.createElement("DIV");
        PlayerWarningDiv.style.backgroundColor = "#ffffff";
        PlayerWarningDiv.style.padding = "5px";
        PlayerWarningDiv.style.paddingTop = "20px";
        PlayerWarningDiv.style.paddingBottom = "20px";
        PlayerWarningDiv.innerHTML = Loc.Dat.login.Errors.Warning; +"<br><br>";
        CH.appendChild(PlayerWarningDiv);
        var img = document.createElement("IMG");
        img.src = "Images/getFlashPlayer.gif";
        img.style.margin = "20px";
        img.style.cursor = "pointer";
        img.onclick = function() {
            var win = window.open("http://get.adobe.com/de/flashplayer/");
        }
        PlayerWarningDiv.appendChild(img);
    }
}

function checkBrowser() {
    //var browser = String.format("Your browser is {0} {1}", Sys.Browser.name, Sys.Browser.version);
    if (Sys.Browser.agent == Sys.Browser.Firefox && Sys.Browser.version < 3) {
        createBrowserDialog();
    } else if (Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version < 7) {
        createBrowserDialog();
    } else if (Sys.Browser.agent == Sys.Browser.Safari && Sys.Browser.version < 4) {
        createBrowserDialog();
    } else if (Sys.Browser.agent == Sys.Browser.Opera && Sys.Browser.version < 9) {
        createBrowserDialog();
    } else if (Sys.Browser.agent == !Sys.Browser.Opera && Sys.Browser.agent == !Sys.Browser.Firefox && Sys.Browser.agent == !Sys.Browser.InternetExplorer && Sys.Browser.agent == !Sys.Browser.Safari) {
        createBrowserDialog();
    }
}

function createWarningDialog(header, text) {
    createDialog(1, 300, 300);
    $get("DialogTitle").innerHTML = header;
    var CH = $get("DialogContent");
    CH.style.backgroundColor = "#ffffff";
    var Div = document.createElement("DIV");
    Div.style.backgroundColor = "#ffffff";
    Div.style.padding = "5px";
    Div.style.paddingTop = "20px";
    Div.style.paddingBottom = "20px";
    var c = "<p>" + text + "</p>";

    Div.innerHTML = c;
    CH.appendChild(Div);
}

function createCookieDialog() {

    createDialog(1, 300, 300);
    $get("DialogTitle").innerHTML = Loc.Dat.login.cookieAlertHead;
    var CH = $get("DialogContent");
    CH.style.backgroundColor = "#ffffff";
    var Div = document.createElement("DIV");
    Div.style.backgroundColor = "#ffffff";
    Div.style.padding = "5px";
    Div.style.paddingTop = "20px";
    Div.style.paddingBottom = "20px";
    var c = "<p>" + Loc.Dat.login.cookieAlert + "</p>";

    Div.innerHTML = c;
    CH.appendChild(Div);
}


function createWelcomeDialog() {
    createDialog(1, 300, 300);
    $get("DialogTitle").innerHTML = Loc.Dat.login.FirstLoginHead;
    var CH = $get("DialogContent");
    CH.style.backgroundColor = "#ffffff";
    var Div = document.createElement("DIV");
    Div.style.backgroundColor = "#ffffff";
    Div.style.padding = "5px";
    Div.style.paddingTop = "20px";
    Div.style.paddingBottom = "20px";
    var c = "<p>" + Loc.Dat.login.FirstLoginCopy1 + "</p>";
    c += "<p>" + Loc.Dat.login.FirstLoginCopy2 + "</p>";
    c += "<p>" + Loc.Dat.login.FirstLoginCopy3 + "</p>";
    Div.innerHTML = c;
    CH.appendChild(Div);
}

function createBrowserDialog() {
    createDialog(1, 300, 300);
    $get("DialogTitle").innerHTML = Loc.Dat.login.BrowserVersion;
    var CH = $get("DialogContent");
    CH.style.backgroundColor = "#ffffff";
    var PlayerWarningDiv = document.createElement("DIV");
    PlayerWarningDiv.style.backgroundColor = "#ffffff";
    PlayerWarningDiv.style.padding = "5px";
    PlayerWarningDiv.style.paddingTop = "20px";
    PlayerWarningDiv.style.paddingBottom = "20px";
    var c = Loc.Dat.login.YourBrowser + "<br><br>";
    c += Sys.Browser.name + " " + Sys.Browser.version + "<br><br>";
    c += Loc.Dat.login.Aproved + "<br><br>";
    for (var i = 0; i < Loc.Dat.login.Browser.item.length; i++) {
        c += "<a class='button' href='" + Loc.Dat.login.Browser.item[i].download + "' target='_blank' >";
        c += Loc.Dat.login.Browser.item[i].label + " </a> <br/>";
    }
    PlayerWarningDiv.innerHTML = c;
    CH.appendChild(PlayerWarningDiv);
}

// ==== MD5 Hash ====

function array(n) {
    for (i = 0; i < n; i++) this[i] = 0;
    this.length = n;
}

function integer(n) { return n % (0xffffffff + 1); }

function shr(a, b) {
    a = integer(a);
    b = integer(b);
    if (a - 0x80000000 >= 0) {
        a = a % 0x80000000;
        a >>= b;
        a += 0x40000000 >> (b - 1);
    } else
        a >>= b;
    return a;
}

function shl1(a) {
    a = a % 0x80000000;
    if (a & 0x40000000 == 0x40000000) {
        a -= 0x40000000;
        a *= 2;
        a += 0x80000000;
    } else
        a *= 2;
    return a;
}

function shl(a, b) {
    a = integer(a);
    b = integer(b);
    for (var i = 0; i < b; i++) a = shl1(a);
    return a;
}

function and(a, b) {
    a = integer(a);
    b = integer(b);
    var t1 = (a - 0x80000000);
    var t2 = (b - 0x80000000);
    if (t1 >= 0)
        if (t2 >= 0)
        return ((t1 & t2) + 0x80000000);
    else
        return (t1 & b);
    else
        if (t2 >= 0)
        return (a & t2);
    else
        return (a & b);
}

function or(a, b) {
    a = integer(a);
    b = integer(b);
    var t1 = (a - 0x80000000);
    var t2 = (b - 0x80000000);
    if (t1 >= 0)
        if (t2 >= 0)
        return ((t1 | t2) + 0x80000000);
    else
        return ((t1 | b) + 0x80000000);
    else
        if (t2 >= 0)
        return ((a | t2) + 0x80000000);
    else
        return (a | b);
}

function xor(a, b) {
    a = integer(a);
    b = integer(b);
    var t1 = (a - 0x80000000);
    var t2 = (b - 0x80000000);
    if (t1 >= 0)
        if (t2 >= 0)
        return (t1 ^ t2);
    else
        return ((t1 ^ b) + 0x80000000);
    else
        if (t2 >= 0)
        return ((a ^ t2) + 0x80000000);
    else
        return (a ^ b);
}

function not(a) {
    a = integer(a);
    return (0xffffffff - a);
}


var state = new array(4);
var count = new array(2);
count[0] = 0;
count[1] = 0;
var buffer = new array(64);
var transformBuffer = new array(16);
var digestBits = new array(16);

var S11 = 7;
var S12 = 12;
var S13 = 17;
var S14 = 22;
var S21 = 5;
var S22 = 9;
var S23 = 14;
var S24 = 20;
var S31 = 4;
var S32 = 11;
var S33 = 16;
var S34 = 23;
var S41 = 6;
var S42 = 10;
var S43 = 15;
var S44 = 21;

function F(x, y, z) {
    return or(and(x, y), and(not(x), z));
}

function G(x, y, z) {
    return or(and(x, z), and(y, not(z)));
}

function H(x, y, z) {
    return xor(xor(x, y), z);
}

function I(x, y, z) {
    return xor(y, or(x, not(z)));
}

function rotateLeft(a, n) {
    return or(shl(a, n), (shr(a, (32 - n))));
}

function FF(a, b, c, d, x, s, ac) {
    a = a + F(b, c, d) + x + ac;
    a = rotateLeft(a, s);
    a = a + b;
    return a;
}

function GG(a, b, c, d, x, s, ac) {
    a = a + G(b, c, d) + x + ac;
    a = rotateLeft(a, s);
    a = a + b;
    return a;
}

function HH(a, b, c, d, x, s, ac) {
    a = a + H(b, c, d) + x + ac;
    a = rotateLeft(a, s);
    a = a + b;
    return a;
}

function II(a, b, c, d, x, s, ac) {
    a = a + I(b, c, d) + x + ac;
    a = rotateLeft(a, s);
    a = a + b;
    return a;
}

function transform(buf, offset) {
    var a = 0, b = 0, c = 0, d = 0;
    var x = transformBuffer;

    a = state[0];
    b = state[1];
    c = state[2];
    d = state[3];

    for (i = 0; i < 16; i++) {
        x[i] = and(buf[i * 4 + offset], 0xff);
        for (j = 1; j < 4; j++) {
            x[i] += shl(and(buf[i * 4 + j + offset], 0xff), j * 8);
        }
    }

    a = FF(a, b, c, d, x[0], S11, 0xd76aa478); /* 1 */
    d = FF(d, a, b, c, x[1], S12, 0xe8c7b756); /* 2 */
    c = FF(c, d, a, b, x[2], S13, 0x242070db); /* 3 */
    b = FF(b, c, d, a, x[3], S14, 0xc1bdceee); /* 4 */
    a = FF(a, b, c, d, x[4], S11, 0xf57c0faf); /* 5 */
    d = FF(d, a, b, c, x[5], S12, 0x4787c62a); /* 6 */
    c = FF(c, d, a, b, x[6], S13, 0xa8304613); /* 7 */
    b = FF(b, c, d, a, x[7], S14, 0xfd469501); /* 8 */
    a = FF(a, b, c, d, x[8], S11, 0x698098d8); /* 9 */
    d = FF(d, a, b, c, x[9], S12, 0x8b44f7af); /* 10 */
    c = FF(c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
    b = FF(b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
    a = FF(a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
    d = FF(d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
    c = FF(c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
    b = FF(b, c, d, a, x[15], S14, 0x49b40821); /* 16 */

    a = GG(a, b, c, d, x[1], S21, 0xf61e2562); /* 17 */
    d = GG(d, a, b, c, x[6], S22, 0xc040b340); /* 18 */
    c = GG(c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
    b = GG(b, c, d, a, x[0], S24, 0xe9b6c7aa); /* 20 */
    a = GG(a, b, c, d, x[5], S21, 0xd62f105d); /* 21 */
    d = GG(d, a, b, c, x[10], S22, 0x2441453); /* 22 */
    c = GG(c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
    b = GG(b, c, d, a, x[4], S24, 0xe7d3fbc8); /* 24 */
    a = GG(a, b, c, d, x[9], S21, 0x21e1cde6); /* 25 */
    d = GG(d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
    c = GG(c, d, a, b, x[3], S23, 0xf4d50d87); /* 27 */
    b = GG(b, c, d, a, x[8], S24, 0x455a14ed); /* 28 */
    a = GG(a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
    d = GG(d, a, b, c, x[2], S22, 0xfcefa3f8); /* 30 */
    c = GG(c, d, a, b, x[7], S23, 0x676f02d9); /* 31 */
    b = GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */

    a = HH(a, b, c, d, x[5], S31, 0xfffa3942); /* 33 */
    d = HH(d, a, b, c, x[8], S32, 0x8771f681); /* 34 */
    c = HH(c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
    b = HH(b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
    a = HH(a, b, c, d, x[1], S31, 0xa4beea44); /* 37 */
    d = HH(d, a, b, c, x[4], S32, 0x4bdecfa9); /* 38 */
    c = HH(c, d, a, b, x[7], S33, 0xf6bb4b60); /* 39 */
    b = HH(b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
    a = HH(a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
    d = HH(d, a, b, c, x[0], S32, 0xeaa127fa); /* 42 */
    c = HH(c, d, a, b, x[3], S33, 0xd4ef3085); /* 43 */
    b = HH(b, c, d, a, x[6], S34, 0x4881d05); /* 44 */
    a = HH(a, b, c, d, x[9], S31, 0xd9d4d039); /* 45 */
    d = HH(d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
    c = HH(c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
    b = HH(b, c, d, a, x[2], S34, 0xc4ac5665); /* 48 */

    a = II(a, b, c, d, x[0], S41, 0xf4292244); /* 49 */
    d = II(d, a, b, c, x[7], S42, 0x432aff97); /* 50 */
    c = II(c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
    b = II(b, c, d, a, x[5], S44, 0xfc93a039); /* 52 */
    a = II(a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
    d = II(d, a, b, c, x[3], S42, 0x8f0ccc92); /* 54 */
    c = II(c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
    b = II(b, c, d, a, x[1], S44, 0x85845dd1); /* 56 */
    a = II(a, b, c, d, x[8], S41, 0x6fa87e4f); /* 57 */
    d = II(d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
    c = II(c, d, a, b, x[6], S43, 0xa3014314); /* 59 */
    b = II(b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
    a = II(a, b, c, d, x[4], S41, 0xf7537e82); /* 61 */
    d = II(d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
    c = II(c, d, a, b, x[2], S43, 0x2ad7d2bb); /* 63 */
    b = II(b, c, d, a, x[9], S44, 0xeb86d391); /* 64 */

    state[0] += a;
    state[1] += b;
    state[2] += c;
    state[3] += d;

}

function init() {
    count[0] = count[1] = 0;
    state[0] = 0x67452301;
    state[1] = 0xefcdab89;
    state[2] = 0x98badcfe;
    state[3] = 0x10325476;
    for (i = 0; i < digestBits.length; i++)
        digestBits[i] = 0;
}

function update(b) {
    var index, i;

    index = and(shr(count[0], 3), 0x3f);
    if (count[0] < 0xffffffff - 7)
        count[0] += 8;
    else {
        count[1]++;
        count[0] -= 0xffffffff + 1;
        count[0] += 8;
    }
    buffer[index] = and(b, 0xff);
    if (index >= 63) {
        transform(buffer, 0);
    }
}

function finish() {
    var bits = new array(8);
    var padding;
    var i = 0, index = 0, padLen = 0;

    for (i = 0; i < 4; i++) {
        bits[i] = and(shr(count[0], (i * 8)), 0xff);
    }
    for (i = 0; i < 4; i++) {
        bits[i + 4] = and(shr(count[1], (i * 8)), 0xff);
    }
    index = and(shr(count[0], 3), 0x3f);
    padLen = (index < 56) ? (56 - index) : (120 - index);
    padding = new array(64);
    padding[0] = 0x80;
    for (i = 0; i < padLen; i++)
        update(padding[i]);
    for (i = 0; i < 8; i++)
        update(bits[i]);

    for (i = 0; i < 4; i++) {
        for (j = 0; j < 4; j++) {
            digestBits[i * 4 + j] = and(shr(state[i], (j * 8)), 0xff);
        }
    }
}


function hexa(n) {
    var hexa_h = "0123456789abcdef";
    var hexa_c = "";
    var hexa_m = n;
    for (hexa_i = 0; hexa_i < 8; hexa_i++) {
        hexa_c = hexa_h.charAt(Math.abs(hexa_m) % 16) + hexa_c;
        hexa_m = Math.floor(hexa_m / 16);
    }
    return hexa_c;
}


var ascii = "01234567890123456789012345678901" +
          " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
          "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";

function MD5(input) {
    var l, s, k, ka, kb, kc, kd;

    init();
    for (k = 0; k < input.length; k++) {
        l = input.charAt(k);
        update(ascii.lastIndexOf(l));
    }
    finish();
    ka = kb = kc = kd = 0;
    for (i = 0; i < 4; i++) ka += shl(digestBits[15 - i], (i * 8));
    for (i = 4; i < 8; i++) kb += shl(digestBits[15 - i], ((i - 4) * 8));
    for (i = 8; i < 12; i++) kc += shl(digestBits[15 - i], ((i - 8) * 8));
    for (i = 12; i < 16; i++) kd += shl(digestBits[15 - i], ((i - 12) * 8));
    s = hexa(kd) + hexa(kc) + hexa(kb) + hexa(ka);
    return s;
}

function CheckInput(e) {
    if (e.charCode == 13) {
        var userLoginBox = $get("UserLogin");
        var passwordLoginBox = $get("PasswordLogin");
        var ul = userLoginBox.value;
        var pl = passwordLoginBox.value;

        if (pl != "" && ul != "") doLogin();
    }
}

function resetTextBox() {
    this.select();
    this.value = "";
    this.style.color = "#474747";
}


//============================================================================================
var TK = "";
function doLogin() {
    var userLoginBox = $get("UserLogin");
    var passwordLoginBox = $get("PasswordLogin");
    var uname = userLoginBox.value;
    var pword = passwordLoginBox.value;
    if (!TOOL.checkLogin(uname)) {
        $get("ErrLabelLogin").innerHTML = Loc.Dat.Errors.e8;
    } else {
        if (!TOOL.checkLogin(pword)) {
            $get("ErrLabelLogin").innerHTML = Loc.Dat.Errors.e23;
        }
    }
    var md5 = MD5($get("PasswordLogin").value);
    LoginService.GetSecurityToken(userLoginBox.value, md5, "", onCreateSecurityTokenSuccess);
}
///createWarningDialog(header, text)
function onCreateSecurityTokenSuccess(result) {
    if (Number(result) == -2) {
        $get("ErrLabelLogin").innerHTML = Loc.Dat.Errors.e22;
    }
    else if (Number(result) == -1) {
        $get("ErrLabelLogin").innerHTML = Loc.Dat.Errors.e21;
    }
    else {
        this.TK = result;
        Sys.Services.AuthenticationService.login(
            $get("UserLogin").value,
            $get("PasswordLogin").value,
            false,
            null,
            null,
            loginComplete,
            loginError,
            "login");
    }
}

function loginComplete(result, context) {
    if (result) {
        if (ServerEnvironment == "Local")
            location.href = "http://" + window.location.host +  "/_ayondo/Main.aspx?s=" + this.TK;

        if (ServerEnvironment == "Development")
            location.href = "http://" + window.location.host + "/_ayondo/Main.aspx?s=" + this.TK;

        if (ServerEnvironment == "Production")
            location.href = "https://www.ayondo.com/_ayondo/Main.aspx?s=" + this.TK;

    } else {
        $get("ErrLabelLogin").innerHTML = Loc.Dat.login.Errors.LogError;
    }
}
function loginError(result, context) {
    $get("UserLogin").value =
   "Could not " + context + " (" +
   result.get_message() + ").";
}
function PasteAction() {
    save = this.value;
    PasteFlag = true;
    
    
}
function clearPasteAction(_id) {
    if (PasteFlag) {
        $get(_id).value = save;
        PasteFlag = false;
    }
}
var PasteFlag = false;

function callError(result) {

    Sys.Debug.trace("ERROR: " + result._stackTrace.toString());
}

function showCreateUserResult(result) {
    $get("Msg").innerHTML = "User " + $get("UserName").value + " ist registriert<br>" + result;
    if (result == "OK") {
        Sys.Services.AuthenticationService.login(
           $get("UserName").value,
           $get("Password").value,
           false,
           null,
           null,
           loginComplete,
           loginError,
           "login");
    }
}

// TODO: Implement!
function forgotPassword() {
    var c = "<p style=''font-size:12px;>" + Loc.Dat.login.PWForgotten.Header + "</p>";
    c += "<input id='PWF_Email'  class='RegTextBox' type='text' style='width: 375px;' /><br>";
    c += "<div id='PWF_Error' style='color:#f00;'>&nbsp;</div><br><br>";
    c += '<div id="PWF_send" style="cursor: pointer;" onclick="getPassword()">';
    c += '<table cellspacing="0" cellpadding="0" border="0" class="RedBtnTable" style="border-collapse: collapse;">';
    c += '<tbody>';
    c += '<tr>';
    c += '<td class="RedBtnCell" align="center" valign="middle">' + Loc.Dat.login.PWForgotten.BtnLabel + '</td>';
    c += '</tr>';
    c += '</tbody>';
    c += '</table>';
    c += '</div>';
    $get("LoginContent").innerHTML = c;
    $get("AdditionalContent").innerHTML = "";
}
function getparams(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
}
function showPasswordChangedResponse(success) {
    createDialog(1, 300, 300);
    $get("DialogTitle").innerHTML = "";
    var CH = $get("DialogContent");
    CH.style.backgroundColor = "#ffffff";
    if (success)
        CH.innerHTML = Loc.Dat.login.PWForgotten.Emailsent;
    else
        CH.innerHTML = Loc.Dat.login.PWForgotten.Emailerror;
}
function getPassword() {
    var email = $get("PWF_Email").value;
    if (TOOL.checkEMail(email)) {
        LoginService.ResetPassword(email, PWRequestUserInfo, callError);
        $get("PWF_send").style.visibility = "hidden";
    } else {
        $get("PWF_Error").innerHTML = Loc.Dat.login.Errors.Email;
    }

}
function PWRequestUserInfo(result) {
    if (result) {
        location.href = location.href + "?fp=1";
        //$get("LoginContent").innerHTML = Loc.Dat.login.PWForgotten.Emailsended;
    } else {
        location.href = location.href + "?fp=2";
        //$get("PWF_Error").innerHTML = Loc.Dat.login.Errors.PWF_not_found;
    }

}
function TextBoxSelect(obj) {
    obj.style.color = "#666";
    obj.select();
}

function clearContactErrorFields() {
    $get("ContactResponse").innerHTML = "";
    $get("ErrLabelName").style.visibility = 'hidden';
    $get("ErrLabelMsg").style.visibility = 'hidden';
    $get("ErrLabelSubject").style.visibility = 'hidden';
    $get("ErrLabelEmail").style.visibility = 'hidden';
}
function clearContactInputFields() {
    $get("ContactEMail").value = "";
    $get("ContactName").value = "";
    $get("ContactSubject").value = "";
    $get("ContactMessage").value = "";
}
function ContactResult(result) {
    if (result == 0) {
        $get("ContactResponse").innerHTML = Loc.Dat.login.Errors.ContactError;
    } else {
        $get("LoginContent").innerHTML = Loc.Dat.login.Contact.Confirm;
    }
}
function showLanguageMenu() {

    var bounds = Sys.UI.DomElement.getBounds($get("langTable_0_1"));
    $get("LangMenuPanel").style.left = (bounds.x - 85) + "px";
    $get("LangMenuPanel").style.top = (bounds.y + 20) + "px";
    $get("LangMenuPanel").style.visibility = "visible";
    showLanguageMenuFlag = true;
}

function switchLanguage(lang) {

    if (ServerEnvironment == "Local")
        location.href = "http://" + window.location.host +  "/Default.aspx?lang=" + lang + "&id=home";

    var country = lang;
    if (country == "en") country = "uk";

    if (ServerEnvironment == "Development")
        location.href = "http://" + window.location.host + "/Default.aspx?lang=" + lang + "&id=home";

    if (ServerEnvironment == "Production")
        location.href = "http://www.ayondo.com/" + lang + "-" + country + "/home";
}

function showTop5Table(content) {
    TOOL.getDomElement("Top5Content").innerHTML = content;
}

function showStaticContent(content) {
    $get("LoginContent").innerHTML = content;

    if ($get("BackBtn") != null) {
        $get("BackBtn").onclick = function() {
            createHome();
        }
    }
}

function backToRegisterPage() {


    $get("LoginContent").innerHTML = Register;
    fillRegisterForm();
    addCallbacks();
    Register = "";
    $addHandler($get("RegisterNowBtn"), "click", registerUser);
    //	$addHandler($get("RegDelFields"), "click", clearRegisterFields);

}

//===========================================================================
//  modules
//===========================================================================
function createLoader(Holder, Height) {
    Holder.innerHTML = "";
    var HolderHeight = Sys.UI.DomElement.getBounds(Holder).height;
    if (Height > 0) HolderHeight = Height - 50;

    var LoaderDiv = document.createElement("DIV");
    LoaderDiv.className = "loader";
    LoaderDiv.setAttribute("style", "text-align:center");

    var Loader = document.createElement("IMG");
    Loader.src = "Images/ajax-loader.gif";
    Loader.style.marginTop = parseInt(HolderHeight / 2 - 15) + "px";
    LoaderDiv.appendChild(Loader);
    Holder.appendChild(LoaderDiv);
}

var DialogBg2 = new Image();
DialogBg2.src = "Images/DialogBackground_2.png";

function createDialog(BgId, Width, Height) {
    $get("DialogLayer").style.display = "block";
    $get("DialogLayer").style.height = "100%";
    $get("DialogBox").style.height = "3000px";

    $get("DialogBox").style.display = "block";
    var DB = $get("DialogBox");
    var DialogCon = document.createElement("DIV");
    DialogCon.style.position = "absolute";
    DialogCon.style.left = (screenWidth - Width - 50) / 2 + "px";

    var pageOffset = (window.pageY) ? window.pageYOffset : document.documentElement.scrollTop;
    DialogCon.style.top = (screenHeight - Height - 50) / 2 + pageOffset + "px";

    DialogCon.style.width = Width + "px";
    DialogCon.style.height = Height + "px";
    DialogCon.id = "DialogCon";

    DialogCon.innerHTML = (BgId == 2) ? "<img src='" + DialogBg2.src + "' width='" + Width + "' height='" + Height + "' />"
        : "<img src='" + DialogBg1.src + "' width='" + Width + "' height='" + Height + "' />";

    var DialogHeader = document.createElement("DIV");
    DialogHeader.className = "DialogHeader";
    DialogCon.style.width = Width + "px";
    DialogHeader.id = "DialogHeader";
    DialogCon.appendChild(DialogHeader);

    var HeaderHead = document.createElement("DIV");
    HeaderHead.style.marginLeft = "20px";
    HeaderHead.style.marginTop = "10px";
    HeaderHead.id = "DialogTitle";
    DialogHeader.appendChild(HeaderHead);
    var CHolder = document.createElement("DIV");
    CHolder.className = "DialogContent";
    CHolder.style.width = (Width - 50) + "px";
    CHolder.style.height = (Height - 110) + "px";
    CHolder.id = "DialogContent";
    DialogCon.appendChild(CHolder);
    var Footer = document.createElement("DIV");
    Footer.className = "DialogFooter";
    Footer.id = "DialogFooter";
    Footer.style.width = Width + "px";
    DialogCon.appendChild(Footer);
    var DialogAction = document.createElement("DIV");
    DialogAction.className = "DialogAction";
    DialogAction.id = "DialogAction";
    Footer.appendChild(DialogAction);
    var DialogClose = document.createElement("IMG");
    DialogClose.className = "DialogClose";
    DialogClose.src = DialogClosePic.src;
    DialogHeader.appendChild(DialogClose);
    DialogClose.onclick = function() {
        closeDialog();
    }
    DB.appendChild(DialogCon);
}

function closeDialog() {
    $get("DialogBox").innerHTML = "";
    $get("DialogBox").style.display = "none";
    $get("DialogLayer").style.display = "none";
}

var screenWidth, screenHeight, minHeight;
function getScreen() {
    var ie = false;
    if (self.innerHeight) // all except Explorer
    {
        screenWidth = self.innerWidth - 20;
        screenHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    // Explorer 6 Strict Mode	
    {
        ie = true;
        screenWidth = document.documentElement.clientWidth;
        screenHeight = document.documentElement.clientHeight;
    }
    else if (document.body) // other Explorers
    {
        ie = true;
        screenWidth = document.body.clientWidth;
        screenHeight = document.body.clientHeight;
    }


}
// creates 1 button with specified properties
function createButton(ForeColor, BtnLabel, ID) {
    var Button = document.createElement("Table");
    Button.id = ID;
    Button.className = (ForeColor == "Red") ? "RedBtnTable" : "GreyBtnTable";
    var Tbody = document.createElement("TBody");
    var TR = document.createElement("TR");
    var TD = document.createElement("TD");
    TD.className = (ForeColor == "Red") ? "RedBtnCell" : "GreyBtnCell";
    cspan = document.createAttribute("valign");
    cspan.nodeValue = "middle";
    TD.setAttributeNode(cspan);
    TD.innerHTML = BtnLabel;
    TR.appendChild(TD);
    Tbody.appendChild(TR);
    Button.appendChild(Tbody);
    return Button;
}

function showErrorMessage(Message) {
    createDialog(1, 300, 270);
    $get("DialogTitle").innerHTML = "Login Error";
    var CH = $get("DialogContent");
    CH.style.backgroundColor = "#ffffff";
    var PlayerWarningDiv = document.createElement("DIV");
    PlayerWarningDiv.style.backgroundColor = "#ffffff";
    PlayerWarningDiv.style.padding = "5px";
    PlayerWarningDiv.style.paddingTop = "20px";
    PlayerWarningDiv.style.paddingBottom = "20px";
    PlayerWarningDiv.innerHTML = Message + "<br><br>";
    CH.appendChild(PlayerWarningDiv);
    //==============================================================================

}
function showFrontPageContent() {

    $get("LastParagraph").style.visibility = "visible";
    $get("LastParagraph").style.height = "";
    $get("moreBtn").innerHTML = "<br>";

}


if (typeof (Sys) != "undefined") { Sys.Application.notifyScriptLoaded(); }