
window.onload = init;

var onLoads = new Array();

function init() {
    for (var i = 0; i < onLoads.length; i++) {
        eval(onLoads[i]);
    }
}

function addOnLoad(func) {
    onLoads[onLoads.length] = func;
}

function validatelimit(obj, length) {
    if (this.id) obj = this;
    if (obj.value.length > length) {
        obj.value = obj.value.substring(length, 0);
        return false;
    }
    else {
        return true;
    }
}

function trackOrder(url, strInvoiceNo) {
    if (strInvoiceNo == "") return false;
    window.open(url + strInvoiceNo, "track_order", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=600,height=500");
    return true;
}

function printContent(contentId, width, height) {
    var popup = window.open('', 'Print', 'width=' + width + ',height=' + height + ',top=200,left=250,toolbars=no,scrollbars=yes,status=no,resizable=no');
    popup.document.body.innerHTML = $('#' + contentId).html();
    popup.document.close(); popup.print(); popup.close();
}

function showContentInPopup(contentId, width, height) {
    var popup = window.open('', 'Print', 'width=' + width + ',height=' + height + ',top=200,left=250,toolbars=no,scrollbars=yes,status=no,resizable=no');
    popup.document.body.innerHTML = $('#' + contentId).html();
}

function popupContent(url, width, height) {
    var popup = window.open('', 'popup', 'width=' + width + ',height=' + height + ',top=200,left=250,toolbars=no,scrollbars=yes,status=no,resizable=yes,location=no');
    var result;
    $.ajax({
        url: url,
        type: "GET",
        processData: false,
        dataType: "html",
        timeout: 10000,
        success: function(response) {
            result = response;
        },
        error: function() {
            alert('error!');
            return;
        },
        async: false
    });
    popup.document.write('<html><head><title>Ellos</title></head><body>' + result + '</body></html>');
}

function registerForNewsletter(email) {

    var result = false;
    var url = "/Services/Customer.svc/RegisterForNewsLetter/" + email + "/json";
    $.ajax({
        url: url,
        type: "GET",
        processData: false,
        timeout: 10000,
        success: function(response) {
            result = (response == 'true');
        },
        error: function(request, status, errorThrown) {
            result = false;
        },
        async: false
    });
    return result;
}

function ResetScrollPosition() { 
    
    var scrollX = document.getElementById('__SCROLLPOSITIONX');
    var scrollY = document.getElementById('__SCROLLPOSITIONY');
    
    if (scrollX && scrollY) {
        scrollX.value = 0;
        scrollY.value = 0;
    }
}

