﻿function manualValidate(groupName) {
    return Page_ClientValidate(groupName);
}
function evalWebMethodResponse(object) {
    if (object.d == '')
        return;
        
    var json = eval('(' + object.d + ')');
    return json;
}
function handleKeyPress(e)
{
    var key=e.keyCode || e.which;
    if (key==13) {
    }
}
function extendItem(itemid, years)
{
    $.ajax({
        type: 'POST',
        url: 'EditMailItem.aspx/Extend',
        data: '{"mailitemid":"' + itemid + '","length":"' + years + '"}',
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        beforeSend: function() {

        },
        success: function(response) {
            javascript: parent.location.reload();
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert('Error: ' + textStatus);
        },
        complete: function() {

        }
    });
}
function login(email, password) {
    if (!manualValidate('login'))
        return;

    $(document).ready(function() {
        $.ajax({
            type: 'POST',
            url: secureServer + '/account.aspx/Login',
            data: '{"email":"' + email + '","password":"' + escape(password) + '"}',
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            beforeSend: function() {
                $('#loginRes').hide();
                $('#loginLock').hide();
                $('#loginPrgBar').show();
            },
            success: function(response) {
                if (typeof (response) == 'undefined')
                    $('#loginRes').show();
                else {
                    var login = response.d;
                    if (login == 0)
                        location.replace(secureServer + '/transreport.aspx');
                    else if (login == -1)
                        $('#loginRes').show();
                    else if (login == -2)
                        $('#loginLock').show();
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert('Error: ' + textStatus);
            },
            complete: function() {
                $('#loginPrgBar').hide();
            }
        });
    });
}
function getFormData() {
    var formData = '';
    var form = $('#aspnetForm');
    var formItems = $(':input', form);

    formItems.each(function() {
        var type = this.type, tag = this.tagName.toLowerCase(), id = this.id, val = escape(this.value);
        if (type == 'checkbox' && !this.checked)
            val = 'off';
        else if (type == 'radio' && !this.checked)
            val = '';

        if (id.substring(0, 1) != '_') {
            if (formData.length == 0)
                formData = id + '=' + val;
            else
                formData += '&' + id + '=' + val;
        }
    });
    
    return formData;
}
function updateCredit() {
    $.ajax({
        type: 'POST',
        url: secureServer + '/account.aspx/GetCredit',
        data: '{}',
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        beforeSend: function() {
        },
        success: function(response) {
            if (typeof (response) != 'undefined') {
                $('#updCredit').html(response.d);
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert('Error: ' + textStatus);
        }
    });
}
function randomString(length) {
    chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
    str = "";
    for (x = 0; x < length; x++) {
        i = Math.floor(Math.random() * 62);
        str += chars.charAt(i);
    }
    return str;
}