﻿function GetSynchronousJSONResponse(url, postData) {
    var xmlhttp = null;
    if (window.XMLHttpRequest)
        xmlhttp = new XMLHttpRequest();
    else if (window.ActiveXObject) {
        if (new ActiveXObject("Microsoft.XMLHTTP"))
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        else
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    // to be ensure non-cached version of response
    url = url + "?rnd=" + Math.random();

    xmlhttp.open("POST", url, false); //false means synchronous
    xmlhttp.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    xmlhttp.send(postData);
    var responseText = xmlhttp.responseText;
    return responseText;
}

function openPopUpWindow(url,title,width,height) {
    var oWnd = radopen(url, title, null);
    oWnd.set_behaviors(Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Resize + Telerik.Web.UI.WindowBehaviors.Maximize);
    //oWnd.setSize($(window).width() * .97, $(window).height() * .97);
    oWnd.setSize(width, height);
    oWnd.set_modal(true);
    //oWnd.maximize();
    return false;
}

function jsTrim(sText) {
    //Remove leading spaces

    while (sText.substring(0, 1) == ' ')
        sText = sText.substring(1, sText.length);

    //Remove trailing spaces 
    while (sText.substring(sText.length - 1, sText.length) == ' ')
        sText = sText.substring(0, sText.length - 1);

    return sText;
}

var submitting = false;
function diableSubmit() {
    if (submitting) {
        alert('Page already submitted. Please wait.');
        return false;
    }
    submitting = true;
    return true;
}