﻿function ShowLogoutPopup() {
    popupLogout.Show();
}

function ShowLoginPopup() {
    ShowLogin();
    ASPxClientEdit.ClearGroup('Login');
    lblStatus.SetText('');
    lblStatus.Visible = false;
    popupLogin.Show();
}

function ShowLogin() {
    rpLogin.SetHeaderText('Login');
    document.getElementById("trEmail").style.display = "block";
    document.getElementById("trPassword").style.display = "block";
    lblEmail.SetClientVisible(false);
    tbEmail.SetClientVisible(false);
    lblForgetPassword.SetClientVisible(true);
    btnLogin.SetClientVisible(true);
    lblForgotPasswordMessage.SetClientVisible(false);
    btnSubmit.SetClientVisible(false);
    btnLoginBack.SetClientVisible(false);
}

function ForgetPassword() {
    rpLogin.SetHeaderText('Lost password');
    document.getElementById("trEmail").style.display = "none";
    document.getElementById("trPassword").style.display = "none";
    lblEmail.SetClientVisible(true);
    tbEmail.SetClientVisible(true);
    lblForgetPassword.SetClientVisible(false);
    btnLogin.SetClientVisible(false);
    lblForgotPasswordMessage.SetText('Enter the email address associated with your account and we’ll send your password.');
    lblForgotPasswordMessage.SetClientVisible(true);
    btnSubmit.SetClientVisible(true);
}

function ForgotPasswordEndCallback(pass) {

    if (pass != "") {
        var email = tbUserName.GetText();
        var message = "An email has been sent to " + email + ". You should receive it shortly."
        lblForgotPasswordMessage.SetText(message);
        lblEmail.SetClientVisible(false);
        tbEmail.SetClientVisible(false);
        btnSubmit.SetClientVisible(false);
        btnLoginBack.SetClientVisible(true);
        lblStatus.SetText(' ');

    }
    else {
        lblStatus.SetText('Email not registered...');
    }
}

function CancelLogin() {
    ASPxClientEdit.ClearGroup('Login');
    lblStatus.SetText('');
    lblStatus.Visible = false;
    popupLogin.Hide();
}

function LoginCallbackComplete(s, e) {
    if (e.result === '') {
        popupLogin.Hide();
        LoadSignUpControl();
        LoginStatusPanel.PerformCallback();
        if (typeof (LoginRedirectUrl) !== 'undefined') {
            document.location = LoginRedirectUrl;
        }
        else {
            location.reload(true);
        }
    } else {
        lblStatus.SetText(e.result);
    }
}

function doLogin() {

    var isValid = ASPxClientEdit.ValidateGroup('Login');
    if (isValid) {
        lblStatus.SetText('Logging in.. please wait');
        lblStatus.Visible = true;
        loginCallback.PerformCallback();
    }
    else {
        lblStatus.Visible = true;
        lblStatus.SetText('Errors appeared..');
    }
}


function RefreshResults() {

    try {
        GridAirResults.Refresh();
    }
    catch (failed) {

        return;
    }

}

function LoadSignUpControl() {

    try {
        SignUpControlPanel.PerformCallback();
    }
    catch (failed) {

        return;
    }

}




function DeleteSegmentClick(keyValue) {
    SegmentGrid.PerformCallback('delete;' + keyValue);
}



function SendSegmentClick(keyValue) {
    SegmentGrid.PerformCallback('send;' + keyValue);
}

function ResizeImage(maxh, maxw, height, width) {
    var ratio = maxh / maxw;
    if (height / width > ratio) {
        // height is the problem
        if (height > maxh) {
            width = Math.round(width * (maxh / height));
            height = maxh;
        }
    }
    else {
        // width is the problem
        if (width > maxw) {
            height = Math.round(height * (maxw / width));
            width = maxw;
        }
    }
    return [height, width];
}




