function waitingImageShowSS(divPointer) {
	waitingImageShowSS2(divPointer, "<img src=\"/images/ajax-loader-square-new.gif\"/>");
}
function waitingImageShowSS2(divPointer, waitingImagePath) {
	document.getElementById(divPointer).innerHTML = waitingImagePath;
    document.getElementById(divPointer).style.display = 'block';
}

function waitingImageHide(divPointer) {
    document.getElementById(divPointer).style.display = 'none';
}

function createAjaxObjectFrameWork(url, callbackFunction) {
	var that = this;
    this.updating = false;
    this.path = url;
    this.xmlHttp = null;
    this.callback = callbackFunction || function () {
    }

    this.updateMPost = function(passData, divPointer) {
        this.update(passData, null, 'POST', divPointer, false);
    }

 
	this.updatePassToCallBack = function(passData, passToCallBackData, divPointer) {		
        this.update(passData, passToCallBackData, 'POST', divPointer, false);
    }
	
	this.updatePassToCallBack = function(passData, passToCallBackData, divPointer, isControlPanel) {
        this.update(passData, passToCallBackData, 'POST', divPointer, isControlPanel);
    }

    this.update = function(passData, passToCallBackData, postMethod, divPointer, isControlPanel) {
		if (divPointer != null) {	
			waitingImageShowSS(divPointer);
		}
        if (that.updating == true) {
            return false;
        }
        that.updating = true;

        try {
            xmlHttp = new XMLHttpRequest();
        }
        catch (e) {
            try {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
                try {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e) {
                    alert("Your browser does not support AJAX!");
                    return false;
                }
            }
        }
        if (xmlHttp == null) {
            return false;
        } else {
            xmlHttp.onreadystatechange = function() {
                if (xmlHttp.readyState == 4) {
                    that.updating = false;
                    var resp = xmlHttp.responseText;                    
                    if (divPointer != null)
						waitingImageHide(divPointer);
                    if (resp.match('Session Time out. Please Login Again') != null) {
						if(!isControlPanel) {							
                        	window.location = '/sessionout.do';
						}
						else
							window.location = '/admin/login.do?sessionout=1';
                    }
                    else if (resp.indexOf('The server is about to reboot.The server will be available after') != -1) {
                        window.location.href = '/warning.jsp';
                    }
					if(isControlPanel == true){
						if(passToCallBackData != null)
	          	  			that.callback(xmlHttp.responseText, passToCallBackData, xmlHttp.status);
			  			else
							that.callback(xmlHttp.responseText, xmlHttp.status);
					}
					else {
						if (passToCallBackData != null) {
                         }
                    	else {
                        window[callbackFunction](xmlHttp.responseText, xmlHttp.status);
                        }
						
					}
						
                    delete xmlHttp;
                }
            }

            if (postMethod == 'POST') {
                xmlHttp.open("POST", this.path, true);
                xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
                xmlHttp.send(passData);
            } else {
                xmlHttp.open("GET", this.path, true);
                xmlHttp.send(null);
            }
            return true;
        }
    }
}

