var netreq=new Object();
netreq.READY_STATE_UNINITIALIZED=0;
netreq.READY_STATE_LOADING=1;
netreq.READY_STATE_LOADED=2;
netreq.READY_STATE_INTERACTIVE=3;
netreq.READY_STATE_COMPLETE=4;
netreq.ContentLoader=function(url,onload,onerror){
   this.url=url;
   this.req=null;
   this.onload=onload;
   this.onerror=(onerror) ? onerror : this.defaultError;
   this.loadXMLDoc(url);
}

netreq.ContentLoader.prototype={

   loadXMLDoc:function(url){
      if (window.XMLHttpRequest){
         this.req=new XMLHttpRequest();
      } else if (window.ActiveXObject){
         this.req=new ActiveXObject("Microsoft.XMLHTTP");
      }
      
      
        
      if (this.req){
         try{
         	
            var loader=this;
            this.req.onreadystatechange=function(){
                 loader.onReadyState.call(loader);
            }
            this.req.open('GET',url,true);
            this.req.setRequestHeader("Content-Type", "text/xml;charset=utf-8");
            this.req.send(null);
        }catch (err){
            this.onerror.call(this);
        }
      }
   },
   onReadyState:function(){
      var req=this.req;
      var ready=req.readyState;
      if (ready==netreq.READY_STATE_COMPLETE){
         var httpStatus=req.status;
         if (httpStatus==200 || httpStatus==0){
            this.onload.call(this);
         }else{
            this.onerror.call(this);
         }
      }
   },
   defaultError:function(){
     /* alert("error fetching data!"
              +"\n\nreadyState:"+this.req.readyState
      +"\nstatus: "+this.req.status
      +"\nheaders: "+this.req.getAllResponseHeaders());
      */
   }
}


function cb_mailaddr(){
   if(this.req.responseText == "OK"){
   	alert(netreq_cb_mailaddr_1);
   }else{
   	alert(netreq_cb_mailaddr_2);
   }
}
 
function savemailaddr(a){   
    if (a == "") { 
    	alert(netreq_savemailaddr);
    }else{
      var loader=new netreq.ContentLoader("mailmain?type=savemailaddr&mailaddr=" + a,cb_mailaddr);       
   }
}

function cb_mailbl(){
   if(this.req.responseText == "OK"){
   	alert(netreq_cb_mailbl_1);
   }else{
   	alert(netreq_cb_mailbl_2);
   }
}
 
function savemailbl(a){   
    if (a == "") { 
    	alert(netreq_savemailbl);
    }else{
      var loader=new netreq.ContentLoader("mailmain?type=savemailbl&mailaddr=" + a,cb_mailbl);       
   }
}

function cb_mailwl(){
   if(this.req.responseText == "OK"){
   	alert(netreq_cb_mailwl_1);
   }else{
   	alert(netreq_cb_mailwl_2);
   }
}

function savemailwl(a){   
    if (a == "") { 
    	alert(netreq_savemailwl);
    }else{
      var loader=new netreq.ContentLoader("mailmain?type=savemailwl&mailaddr=" + a,cb_mailwl);       
   }
}

function cb_setnotification(){
   if(this.req.responseText == "OK"){   	
   }else{   	
   }
}

function setnotification(mbid,mbtype,msgid){
	 var loader=new netreq.ContentLoader("mailmain?type=setnotification&mbid=" + mbid + "&mbtype=" + mbtype + "&msgid=" + msgid,cb_setnotification); 
}

function cb_autonotification(){
   if(this.req.responseText == "OK"){   	
   }else{   	
   }
}

function autonotification(mbid,mbtype,msgid){
	 var loader=new netreq.ContentLoader("mailmain?type=autonotification&mbid=" + mbid + "&mbtype=" + mbtype + "&msgid=" + msgid,cb_autonotification); 
}

function cb_checkusernameexist(){
   if(this.req.responseText == "OK"){
   	alert(netreq_cb_checkusernameexist_1);
   }else{
   	alert(netreq_cb_checkusernameexist_2);
   }
}
 
function nq_checkusernameexist(user,domain){       
   var loader=new netreq.ContentLoader("mailmain?type=checkusernameexist&username=" + user + "&domain=" + domain,cb_checkusernameexist);          
}


function cb_refresh(){
}

var t_refresh = 60*1000;

function refreshClient(){
	//if need to not timeout for ever, uncomment the following
  /* var loader=new netreq.ContentLoader("mailmain?type=refreshclient",cb_refresh);  
   
   setTimeout("refreshClient(  )", t_refresh);  // 60000 ms is one minute
   */
}

function nr_parseLines(a){
    return a.split("\r\n");
}


function nr_parseParams(a){
    return a.split("\t");
}


function cb_checkspam(){
   alert(this.req.responseText);   
}
 
function checkspam(a){   
    if (a == "") { 
    	alert(netreq_checkspam);
    }else{
      var loader=new netreq.ContentLoader("mailmain?type=checkspam&spammsgid=" + a,cb_checkspam);       
   }
}
