function ajaxRouter(url, callBackFunctionName, isPlainText)
{
    postRequest(wrapURL(url), callBackFunctionName, isPlainText);
}
                    
function postRequest(strURL, callBackFunctionName, isPlainText)
{
    //alert("requested url is: " + strURL);
    var xmlHttp;
    if (window.XMLHttpRequest)  // Mozilla, Safari, ...
    { 
        xmlHttp = new XMLHttpRequest();         
    } 
    else if (window.ActiveXObject)  // IE
    { 
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlHttp.open('POST', strURL, true);
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                                
    xmlHttp.onreadystatechange = function()
    {
        if (xmlHttp.readyState == 4)
        {
            var response = xmlHttp.responseText;
            response = trim(response);
            if(!isPlainText)
                response = loadData(response);
                                            
            eval(callBackFunctionName+"(response)");
        }
    }
    xmlHttp.send(strURL);
}
                                
function loadData(xml)
{
    //alert("Ajax output: " + xml);
    xml = "<?xml version='1.0' ?>" + xml;
    var doc = null;
    if (window.ActiveXObject)
    {
        doc=new ActiveXObject("Microsoft.XMLDOM");
        doc.async="false";
        doc.loadXML(xml);
    }
    else
    {
        var parser=new DOMParser();
        doc=parser.parseFromString(xml,"text/xml");
    }
                                            
    return doc;
}
                                        
function updatePage(doc)
{
    var root = doc.getElementsByTagName('xmlData')[0];
    var totalRow = root.childNodes.length;  			
                                            
}
                                        
function wrapURL(url)
{
    //var rand = Math.random();
    var d = new Date();
    var rand = d.getTime();
    if(url.indexOf('?') == -1)
        url = url + "?" + "rand=" + rand;
    else
        url = url + "&" + "rand=" + rand;
    return url;
}
                                        
function LTrim( value ) {
    var re = /\s*((\S+\s*)*)/;
    return value.replace(re, "$1");
}
// Removes ending whitespaces
function RTrim( value ) {
    var re = /((\s*\S+)*)\s*/;
    return value.replace(re, "$1");
}
// Removes leading and ending whitespaces
function trim( value ) {
    return LTrim(RTrim(value));
}
