var AjaxRequest;
var PostAjaxSuccessFunctionCall;
var AjaxToReturnXml;

function AjaxHTTPRequestObjectCreate()
{
     if ( window.XMLHttpRequest )
     {
        return new XMLHttpRequest();   
     }
     else
     {
        return new ActiveXObject("Microsoft.XMLHTTP");
     }
}


function AjaxDoConnection( Url , OnloadFunc , CallMethod , SendVars , ReturnXml )
{
    if ( CallMethod == '' ) CallMethod = 'GET';
    if ( SendVars == '' ) SendVars = null;

    if ( ReturnXml )
    {
        AjaxToReturnXml = true;
    }
    else
    {
        AjaxToReturnXml = false;   
    }

    PostAjaxSuccessFunctionCall = OnloadFunc;
    
    AjaxRequest = AjaxHTTPRequestObjectCreate();

    AjaxRequest.onreadystatechange = AjaxEventHandler;
    AjaxRequest.open( CallMethod , Url , true );  
    AjaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    AjaxRequest.send( SendVars );
}


function AjaxEventHandler()
{

    if ( AjaxRequest.readyState == 4 )
    {
        if ( AjaxToReturnXml )
        {
            ResponseValue = AjaxRequest.responseXML;
        } 
        else
        {
            ResponseValue = AjaxRequest.responseText;
        } 
        
        eval ( PostAjaxSuccessFunctionCall + '(  ResponseValue );' );       
    }
}


function EncodeSendVarsChars( EncodedChars )
{
     EncodedChars = EncodedChars.replace(/=/g,"%3D");
     EncodedChars = EncodedChars.replace(/&/g,"%26");
     EncodedChars = EncodedChars.replace(/@/g,"%40");
     return EncodedChars;
}

function AjaxResponseText( AjaxObj )
{
    return AjaxObj.responseText;
}


function AjaxResponseXML( AjaxObj )
{
    return AjaxObj.responseXML;
}


function GetSimpleNodeValue( XMLResponse , Tagname , TagNodeId , ChildNodeId )
{
    if ( TagNodeId == '' )   TagNodeId = 0;
    if ( ChildNodeId == '' ) ChildNodeId = 0;
    
    try
    {
        return XMLResponse.getElementsByTagName( Tagname )[TagNodeId] . childNodes[ ChildNodeId ] . nodeValue; 
    }
    catch( e )
    {
        return '';
    }
    
   
}