﻿/// <reference path="../../../Scripts/jquery-1.4.1.min-vsdoc.js" />
/// <reference path="../Namespace/NameSpace.js" />

AMV.JavaScript.Logic.Utilities.GetRootUrl = function(domain) {
    var host = document.location.hostname;
    var w = '';
    if (host.toString().indexOf("www", 0) != -1) {
        w = "www.";
    }
    host = host.toString().toLowerCase().replace('www.', '');
    if (host == "localhost") {
        switch (domain) {
            case "admin":
                return "http://localhost:61295/Tryckalster.Admin.Web/";
                break;

            case "files":
                return "http://localhost:61295/Tryckalster.Admin.Web/";
                break;

            case "site":
                return "http://localhost:54247/";
                break;
        }
    }
    else if (host.toString().indexOf("Tryckalster.projekt.andremedvanner.se") >= 0) {
        switch (domain) {
            case "admin":
                return "http://" + w + "admin.tryckalster.projekt.andremedvanner.se/";
                break;

            case "files":
                return "http://" + w + "files.tryckalster.projekt.andremedvanner.se/";
                break;

            case "site":
                return "http://" + w + "tryckalster.projekt.andremedvanner.se/";
                break;
        }
    }
    else {
        switch (domain) {
            case "site":
                return "http://" + w + "tryckalster.se/";
                break;

            case "admin":
                return "http://" + w + "admin.tryckalster.se/";
                break;

            case "files":
                return "http://" + w + "files.tryckalster.se/";
                break;
        }
    }
 }

 AMV.JavaScript.Logic.Utilities.GetRowClass = function(rowIndex) {
    return rowIndex % 2 == 0 ? "RowAltItem" : "RowItem";
}

AMV.JavaScript.Logic.Utilities.AlertSuccessTime = function() {
    return 1000;
}
AMV.JavaScript.Logic.Utilities.AlertErrorTime = function() {
    return 2000;
}

AMV.JavaScript.Logic.Utilities.S4 = function(){
    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
AMV.JavaScript.Logic.Utilities.Guid = function() {
    return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
}

AMV.JavaScript.Logic.Utilities.PageQuery = function(q) {
    if (q.length > 1) this.q = q.substring(1, q.length);
    else this.q = null;
    this.keyValuePairs = new Array();
    if (q) {
        for (var i = 0; i < this.q.split("&").length; i++) {
            this.keyValuePairs[i] = this.q.split("&")[i];
        }
    }
    this.getKeyValuePairs = function() { return this.keyValuePairs; }
    this.getValue = function(s) {
        for (var j = 0; j < this.keyValuePairs.length; j++) {
            if (this.keyValuePairs[j].split("=")[0] == s)
                return this.keyValuePairs[j].split("=")[1];
        }
        return false;
    }
    this.getParameters = function() {
        var a = new Array(this.getLength());
        for (var j = 0; j < this.keyValuePairs.length; j++) {
            a[j] = this.keyValuePairs[j].split("=")[0];
        }
        return a;
    }
    this.getLength = function() { return this.keyValuePairs.length; }
}

AMV.JavaScript.Logic.Utilities.queryString = function(key) {
    var page = new PageQuery(window.location.search);
    return unescape(page.getValue(key));
}

