function AJAXCommon(){
    var xmlHttp=null;
    this.busy = false;

    function getXMLDoc(text){
        var xmlDoc = null;
        try{
            xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async="false";
            xmlDoc.loadXML(text);
        }catch(e){
            try{
                parser=new DOMParser();
                xmlDoc=parser.parseFromString(text,"text/xml");
            }catch(e){
                return null;
            }
        }

        return xmlDoc;
    }

    this.GetXmlHttpObject = function(){
        try{
            xmlHttp=new XMLHttpRequest();
        }catch (e){
            try{
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }catch (e){
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
        }
        return xmlHttp;
    }

    this.SendingRequest = function(url, parameter, handler){
        var column = new Array();
        var data = new Array();
        var rowCount = 0;

        xmlHttp = this.GetXmlHttpObject();
        xmlHttp.onreadystatechange=function(){
            if(xmlHttp.readyState==4)
            {
                xmlDoc = getXMLDoc(xmlHttp.responseText);
                rowCount = xmlDoc.getElementsByTagName("rows")[0].childNodes[0].nodeValue;
                if(rowCount <= 0){
                    handler(null,null,rowCount);
                }

                rowData = xmlDoc.getElementsByTagName("row");
                for(i = 0; i < rowData.length; i++){
                    data[i] = new Array();
                    for(j = 0; j < rowData[0].childNodes.length; j++){
                        if(i == 0){
                            column[j] = rowData[i].childNodes[j].nodeName;
                        }
                        data[i][j] = rowData[i].childNodes[j].childNodes[0].nodeValue;
                    }
                }
                
                handler(column,data,rowCount);
                this.busy = false;
            }
        }

        xmlHttp.open("GET",url+"?"+parameter,true);
        xmlHttp.send(null);
        this.busy = true;
    }

    this.SendingRequestToDiv = function(url, divId, nextFunc, message){
        xmlHttp = this.GetXmlHttpObject();
        xmlHttp.onreadystatechange=function(){
            if(xmlHttp.readyState==4){
                nextFunc(divId, xmlHttp.responseText);
                this.busy = false;
            }
        }

        if(message){
            document.getElementById(divId).innerHTML = message;
        }else{
            document.getElementById(divId).innerHTML = 'Loading . . .';
        }
        if(url.lastIndexOf("?") < 0){
            xmlHttp.open("GET",url+"?x123="+Date(),true);
        }else{
            xmlHttp.open("GET",url+"&x123="+Date(),true);
        }
        xmlHttp.send(null);
        this.busy = true;
    }
}

function defaultAjaxHandlerToDiv(divId, responseText){
    
    document.getElementById(divId).innerHTML = responseText;
}

function aboutUsMenuAjaxListener(divId, responseText){
    document.getElementById(divId).innerHTML = responseText;
    ajax.SendingRequestToDiv('../page.php?url=about_us&f=about_us.php','content_layer',defaultAjaxHandlerToDiv,'Loading ...');
}

function galleryMenuAjaxListener(divId, responseText){
    document.getElementById(divId).innerHTML = responseText;
    ajax.SendingRequestToDiv('../page.php?url=gallery&f=/user_page/view_event.php&menu_id=2','content_layer',defaultAjaxHandlerToDiv,'Loading ...');
}

function newsMenuAjaxListener(divId, responseText){
    document.getElementById('menu_layer').innerHTML = responseText;
    ajax.SendingRequestToDiv('includes/news.php','content_layer',defaultAjaxHandlerToDiv,'Loading ...');
}

function eventsMenuAjaxListener(divId, responseText){
    document.getElementById('menu_layer').innerHTML = responseText;
    ajax.SendingRequestToDiv('includes/events.php','content_layer',defaultAjaxHandlerToDiv,'Loading ...');
}

var ajax = new AJAXCommon();
