﻿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 ValidateCompanyNumber(source, args)
{
//    args = new Object;
//    args.Value = '008380'; 

    var hdfCompanyId = document.getElementById(hdfCompanyIdId);
    var result = GetSynchronousJSONResponse('ValidationCalls.asmx/ValidateCompanyNumber',
                       '{"CompanyNumber":"' + args.Value + '","CompanyId":"'+ hdfCompanyId.value + '"}');
    result = eval('(' + result + ')');

    args.IsValid = result.d;    
}

