﻿if(typeof String.prototype.trim !== 'function') {
    String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g, ''); 
    }
}

function QueryString(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
    return "";
}

function GetHost() {
    var currentURL = window.location;
    return currentURL.protocol + "//" + currentURL.host;
}


function S4() {
    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
function GenerateGuid() {
    return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4() + S4());
}


function AjaxCall(paramBag) {
    paramBag = paramBag || {};
    
    paramBag.data = paramBag.data || '{}';
    paramBag.type = paramBag.type || 'POST';
    paramBag.contentType = paramBag.contentType || 'application/json; charset=utf-8';
    paramBag.dataType = paramBag.dataType || 'json';
    paramBag.success = paramBag.success || function() {};
    paramBag.error = paramBag.error || function(xhr, status, error) { alert(xhr.responseText); };
    
    $.ajax({
        type: paramBag.type,
        url: paramBag.url,
        data: paramBag.data,
        contentType: paramBag.contentType,
        dataType: paramBag.dataType,
        success: paramBag.success,
        error: paramBag.error
    });
}

String.format = function( text )
{
    //check if there are two arguments in the arguments list
    if ( arguments.length <= 1 )
    {
        //if there are not 2 or more arguments there’s nothing to replace
        //just return the original text
        return text;
    }

    //decrement to move to the second argument in the array
    var tokenCount = arguments.length - 2;
    for( var token = 0; token <= tokenCount; token++ )
    {
        //iterate through the tokens and replace their placeholders from the original text in order
        text = text.replace( new RegExp( "\\{" + token + "\\}", "gi" ), arguments[ token + 1 ] );
    }
    return text;
};

