﻿//----- Class Definition ------------------------------

var OrderInformation = Class.create({

    initialize: function() {
    },

    GetContentDuration: function(url) {
        return this.setOrderInformation('/Orders/GetContentDuration?url=' + url);
    },

    GetUserProjects: function() {
        return this.setOrderInformation('/Orders/GetUserProjects');
    },

    GetVideo: function(pageUrl, title) {
        return this.setOrderInformation('/Orders/GetVideo?pageUrl=' + pageUrl + '&title=' + title);
    },

    addCommas: function(nStr) {
        nStr += '';
        x = nStr.split('.');
        x1 = x[0];
        x2 = x.length > 1 ? '.' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1)) {
            x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        return x1 + x2;
    },

    onLanguageSelect: function(id) {

    },

    setOrderInformation: function(url) {
        var objVideoInfo;
        new Ajax.Request(url, {
            method: 'post',
            asynchronous: false,
            onSuccess: function(transport) {
                objVideoInfo = transport.responseText.evalJSON();
            },
            onFailure: function(transport) {
                objVideoInfo = null;
            }
        });
        return objVideoInfo;
    }
});

function addCommas(nStr) {
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '.00';
    if (x2.length > 3)
        x2 = x2.substring(0, 3);
    if (x2.length < 3)
        x2 = x2 + '0';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}

function onLanguageSelect(id, hid) {
    var currentSelections;
    var selection;
    currentSelections = new String($(hid).value);
    selection = $(id).value + "|";
    if ($(id).checked) {
        currentSelections = currentSelections + selection;
    } else {
        currentSelections = currentSelections.replace(selection, '');
    }
    $(hid).value = currentSelections;
}

