﻿var textboxValues = [];
var aspDotNetPrefix = 'ctl00_MainContent_';
var selectedLogin = false;
    
function $(id) {
    return document.getElementById(id);
}

function logout() {
    if(confirm("Are you sure you want to logout?"))
        window.location = "/login/logout.aspx";
}

function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
       return false;
    return true;
}

function pageKeyDown(evt) {
    if(evt.keyCode == 13 && selectedLogin) {
        $('ctl00_LoginButton').click();
        return false;
    }
}

var promptBoxBackgroundCount = 0;

function showPromptDiv(id) {
    promptBoxBackgroundCount++;
    $(id).style.display = "block";
    $('promptBoxBackground').style.display = "block";
    $(id).style.zIndex = promptBoxBackgroundCount*2;
    $('promptBoxBackground').style.zIndex = (promptBoxBackgroundCount*2)-1;
}

function hidePromptDiv(id) {
    promptBoxBackgroundCount--;
    $(id).style.display = "none";
    if(promptBoxBackgroundCount <= 0)
        $('promptBoxBackground').style.display = "none";
    $('promptBoxBackground').style.zIndex = (promptBoxBackgroundCount*2)-1;
}

function editTextboxes(textboxArray) {
    for(var i = 0; i < textboxArray.length; i++) {
        var textbox = $(aspDotNetPrefix + textboxArray[i]);
        textbox.disabled = false;
        textbox.className = 'accountinfotextbox';
        
        if(textbox.tagName == "SPAN" || textbox.tagName == "DIV")
            textboxValues[i] = textbox.innerHTML;
        else
            textboxValues[i] = textbox.value;
    }
    
    $(aspDotNetPrefix + 'SubmitButton').style.display = 'inline';
    $('cancelButton').style.display = 'inline';
    $('editButton').style.display = 'none';
}

function resetTextboxes(textboxArray) {
    for(var i = 0; i < textboxArray.length; i++) {
        var textbox = $(aspDotNetPrefix + textboxArray[i]);
        textbox.disabled = true;
        textbox.className = 'accountinfolabel';
        
        if(textbox.tagName == "SPAN" || textbox.tagName == "DIV")
            textbox.innerHTML = textboxValues[i];
        else
            textbox.value = textboxValues[i];
    }
    
    $(aspDotNetPrefix + 'SubmitButton').style.display = 'none';
    $('cancelButton').style.display = 'none';
    $('editButton').style.display = 'inline';
}

function masterPageLoad() {
    blurTextBox($('ctl00_Email'), 'Email address');
    blurTextBox($('ctl00_PasswordTb'), 'Password');
}

function focusTextBox(element, placeholder) {
    if(element == null) return;
    
    if(element.value == placeholder) element.value = "";
    element.style.color = "black";
}

function blurTextBox(element, placeholder) {
    if(element == null) return;
    
    if(element.value == "") {
        element.style.color = "#999";
        element.value = placeholder;
    } else {
        element.style.color = "black";
    }
}

function showPasswordPb() {
    $('ctl00_PasswordTb').style.display = 'none';
    $('ctl00_PasswordPb').style.display = 'inline';
    $('ctl00_PasswordPb').focus();
}
