﻿
location.QueryArray = {

    create: function() {
        if (this._value != "undefined" && this._value != null) return this._value;
        var parts = window.location.href.split('?');
        if (parts.length > 1) {
            this._value = parts[1].split('&');
        }
        else {
            this._value = new Array();
        }
        return this._value;
    },

    clear: function() {
        this._value = new Array();
    },

    iscontain: function(name) {
        return this.indexOf(name) > -1;
    },

    indexOf: function(name) {
        for (var i = 0; i < this._value.length; i++) {
            if (this._value[i].indexOf(name + "=") > -1) {
                return i;
            }
        }
        return -1;
    },

    getValue: function(name) {
        var at = this.indexOf(name);
        if (at == -1)
            return "";
        var keyvalue = this._value[at].split('=');
        if (keyvalue.length < 2)
            return "";
        return keyvalue[1];
    },

    unset: function(name) {
        var at = this.indexOf(name);
        if (at == -1)
            return;
        this._value.splice(at, 1);
    },

    set: function(name, param) {
        var at = this.indexOf(name);
        var item = name + "=" + param;

        if (at == -1) {
            this._value.push(item);
        }
        else {
            this._value[at] = item
        }
    },

    toString: function() {
        var result = "";
        for (var i = 0; i < this._value.length; i++) {
            if (result == "") {
                result = this._value[i];
            }
            else {
                result = result.concat("&").concat(this._value[i]);
            }
        }
        return result;
    }
};

location.QueryArray.create();


function FormatHeightWidth(largeSize, width, height) {
    var result = [0, 0];

    if (Math.max(height, width) <= largeSize) {
        return [width, height];

    }
    else if (height > width) {
        result[0] = parseInt(width * (Number(largeSize) / height));
        result[1] = largeSize;
    }
    else {
        result[0] = largeSize;
        result[1] = parseInt(height * (Number(largeSize) / width));
    }
    return result;
}