﻿function GLB_SignOut() {
    $.ajax({
        type: "POST",
        url: "/websike/MasterPageWs.asmx/Signout",
        contentType: "application/json; charset=utf-8",
        data: "{}",
        dataType: "json",
        success: function() {
            window.location = window.location + '';
        }
    });
}
function GLB_AttemptLogin(userName, password, successMethod, failureMethod) {
    $.ajax({
        type: "POST",
        url: "/websike/MasterPageWs.asmx/AttemptLogin",
        contentType: "application/json; charset=utf-8",
        data: "{'username':'" + userName + "','password':'" + password + "'}",
        dataType: "json",
        success: successMethod,
        error: failureMethod
    });
}
function GLB_ValidateEmail(elementValue) {
    return /^([a-zA-Z0-9._-]{3,50})+@([a-zA-Z0-9.-]{3,50})+\.([a-zA-Z.]{2,5})$/.test(elementValue);
}
function GLB_KeyValuePair(key, value) {
    this.Key = key;
    this.Value = value;
}
function GLB_GetValueByKey(arrayOfKvp, keyToFind) {
    for (var i in arrayOfKvp) {
        if (arrayOfKvp[i].Key == keyToFind) {
            return arrayOfKvp[i].Value;
        }
    }
}
function GLB_GetIndexByKey(arrayOfKvp, keyToFind) {
    for (var i in arrayOfKvp) {
        if (arrayOfKvp[i].Key == keyToFind) {
            return i;
        }
    }
} 
function GLB_CheckedValueIs(radioName, radioValue) {
    return $("input[name='" + radioName + "']:checked").val() == radioValue;
}

var glb_defaultControlTexts = [];
var glb_defaultControlTextsFocus = [];
function GLB_RegisterDefaultText(inputId) {
    glb_defaultControlTexts.push(new GLB_KeyValuePair(inputId, $('#' + inputId).val()));
    glb_defaultControlTextsFocus.push(new GLB_KeyValuePair(inputId, false));

    $('#' + inputId).click(function() {
        if ($(this).val() == GLB_GetValueByKey(glb_defaultControlTexts, $(this).attr('id'))) {
            $(this).val('').removeClass('exampleText');
        } else {
            if (GLB_GetValueByKey(glb_defaultControlTextsFocus, $(this).attr('id')) === false) {
                $(this).select();
                glb_defaultControlTextsFocus[GLB_GetIndexByKey(glb_defaultControlTextsFocus, $(this).attr('id'))].Value = true;
            }
        }
    }).blur(function() {
        glb_defaultControlTextsFocus[GLB_GetIndexByKey(glb_defaultControlTextsFocus, $(this).attr('id'))].Value = false;
        if ($(this).val() == "") {
            $(this).val(GLB_GetValueByKey(glb_defaultControlTexts, $(this).attr('id'))).addClass('exampleText');
        }
    }).addClass('exampleText');
}
function GLB_GetDefaultControlText(inputId) {
    return GLB_GetValueByKey(glb_defaultControlTexts, inputId);
}
function GLB_ValidEmailAddressInput(strToCompare, id) {
    return strToCompare != '' && strToCompare != GLB_GetDefaultControlText(id) && GLB_ValidateEmail(strToCompare);
}
function GLB_AjaxFail(result) {
    debugger;
}
function ApplyIntegerOnlyRules() {
    throw "not implemented";
    $('.IntegerOnly').keyup(function () {
        $(this).val(parseInt($(this).val()));
    });
}
function ApplyDecimalOnlyRules() {
    throw "not implemented";
    $('.DecimalOnly').keyup(function () {
        $(this).val(parseFloat($(this).val()));
    });
}
