﻿

function GetXmlHttpObject(handler) { 
    var objXmlHttp = null;
    
    if (!window.XMLHttpRequest)
    {
        // Microsoft
        objXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else
    {
        // Mozilla | Netscape | Safari
        objXmlHttp = new XMLHttpRequest();
    }
    if (objXmlHttp != null)
    {
        objXmlHttp.onreadystatechange = handler;
    }
    return objXmlHttp; 
} 

function SendXmlHttpRequest(xmlhttp, url) {
    xmlhttp.open('POST', url, true); 
    xmlhttp.send(url);
}

function ExecuteCall(url, CallbackMethod) { 
var oHttp = null;
       
    try 
    {
        oHttp = GetXmlHttpObject(CallbackMethod);
        SendXmlHttpRequest(oHttp, url);
    }
    catch(e){alert(e);}
    
    return oHttp;
}

function CallbackMethod() 
{ 

    try
    {
        //readyState of 4 or 'complete' represents 
        //that data has been returned 
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
        {
            var response = xmlHttp.responseText;        
            if (response.length > 0)
            {
                //update page
 //    alert(response);
 //    alert(divTargetElement);
                document.getElementById(divTargetElement).innerHTML = response;   
          
                // clear the xmlhttp object now that we are done
                xmlHttp = null;
            } //else {alert('response.length is null or zero);}
        }
    }
    catch(e){}
}


function GetXmlHttpObject2(handler) { 
    var objXmlHttp = null;
    
    if (!window.XMLHttpRequest)
    {
        // Microsoft
        objXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else
    {
        // Mozilla | Netscape | Safari
        objXmlHttp = new XMLHttpRequest();
    }
    if (objXmlHttp != null)
    {
        objXmlHttp.onreadystatechange = handler;
    }
    return objXmlHttp; 
} 

function SendXmlHttpRequest2(xmlhttp1, url) {
    xmlhttp1.open('POST', url, true); 
    xmlhttp1.send(url);
}

function ExecuteCall2(url, CallbackMethod) { 
var oHttp1 = null;
       
    try 
    {
        oHttp1 = GetXmlHttpObject2(CallbackMethod2);
        SendXmlHttpRequest2(oHttp1, url);
     //   alert(xmlHttp1);
    }
    catch(e){alert(e);}
    
    return oHttp1;
}
function CallbackMethod2() 
{ 
    try
    {
        //readyState of 4 or 'complete' represents 
        //that data has been returned 
        if (xmlHttp1.readyState == 4 || xmlHttp1.readyState == 'complete')
        {
            var response = xmlHttp1.responseText;
            
            if (response.length > 0)
            {
                //update page
     alert(response);
                document.getElementById(divTargetElement1).innerHTML = response;   
          
                // clear the xmlhttp object now that we are done
                xmlHttp1 = null;
            } //else {alert('response.length is null or zero);}
        }
    }
    catch(e){}
}