var net = new Object();//Singleton Pattern
net.READY_STATE_UNINITIALIZED = 0;
net.READY_STATE_LOADING = 1;
net.READY_STATE_LOADED = 2;
net.READY_STATE_INTERACTIVE = 3;
net.READY_STATE_COMPLETE = 4;
function sendRequest(url,params,HttpMethod,syncType,handler){
    //alert("In sendRequest");
    this.req = null;
    this.url = url;
    this.HttpMethod = HttpMethod;
    this.params = params;
    this.syncType = syncType;
    this.handler = handler;
    this.loadXMLDoc(handler);
}

sendRequest.prototype.loadXMLDoc = function(handler){
    if(!this.HttpMethod){
        this.HttpMethod = "GET";
    }
    var HttpMethod = this.HttpMethod;
    this.req = this.initXMLHTTPRequest();
    var handler = this.handler;
    var req = this.req;
    var failCondition = "failure";
    var syncType = this.syncType;
    var params = this.params;
    var url = this.url;
    var obj = this;
    //alert("test1");
    if(req){
        req.open(this.HttpMethod,this.url,this.syncType);               
        req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
        req.onreadystatechange = function() {	                         
            if (req.readyState == 4) {							                                   
                try{		     
                    //alert("Response text "+req.responseText);                
                    eval("var data = "+req.responseText);                                        
                    handler(data);
                }catch(err){
                    //alert("inside catch" + err.description);
                    //handler(req.responseText);
                    //alert(" Error");                
                    //Errorhandler(err);
                    //handler(failCondition);
                }
                
                
            }else {
                //alert("Loading....."+req.readyState);
            }
        };
        //alert("test");
        req.send(this.params);
    }
}
sendRequest.prototype.initXMLHTTPRequest = function(){
    var xRequest = null;
    if (window.ActiveXObject) { // IE/Windows ActiveX version
        xRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }else if (window.XMLHttpRequest) {// native XMLHttpRequest object
        xRequest = new XMLHttpRequest();
    }
    return xRequest;
}

function Errorhandler(data){
    var url=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"));
    if(data=="Incorrect URL"){
        window.location.href=url+"/Invalid_URL.html";
    }else{
        alert(data);
    }
}