// The XMLHttpRequest class object

debug = false;

function getAddr1() {
  var url = window.location.href;
 // var url = this.url;
  url = url.split('/');

  var server = url[0] + url[1] + '//' + url[2] + "/" + url[3] ;

  return server;
}

function getAddr() {
  var url = window.location.href;
  url = url.split('/');

  var server = url[0] + url[1] + '//' + url[2] + "/";
//  alert("url3:" +url[3]);

  return url[3];
}

function Request (url,oFunction,type) {
	this.funct = "";
	// this.req = "";
	this.url = url;
	this.oFunction = oFunction;
	this.type = type;
	this.doXmlhttp = doXmlhttp;
	this.loadXMLDoc = loadXMLDoc;
}

function doXmlhttp() {
	//var funct = "";
	if (this.type == 'text') {
		this.funct = this.oFunction + '(req.responseText)';
	} else {
		this.funct = this.oFunction + '(req.responseXML)';
	}
	this.loadXMLDoc();
	return false;
}

function loadXMLDoc() {
	var functionA = this.funct;
	var req;
	req = false;
	
// alert(window.location);	
//window.location=getServer1();
// alert("server2:" + getServer1());	
// alert("server2:" + getAddr());	
//  index = getAddr().indexOf("admin.login") ;
// alert("server2:" + index);	
//  if( index != -1 )
//	{
//		window.location.href=this.url;
//		window.location=this.url;
//  }
//		window.location.href=getServer1();
// alert(window.location.href);	
// alert(window.location);	

	function processReqChange() {
		 //alert('reqChange is being called   '+this.url);
	    // only if req shows "loaded"
	    if (req.readyState == 4) {
	        // only if "OK"
	        if (req.status == 200) {
	            // ...processing statements go here...
	            eval(functionA);
	            if(debug){
					var debugWin = window.open('','aWindow','width=600,height=600,scrollbars=yes');
					debugWin.document.body.innerHTML = req.responseText;
				}
	        } else {
	            alert("There was a problem retrieving the data:\n" +
	                req.statusText + '\nstatus: ' + req.status);
				if(debug){
					var debugWin = window.open('','aWindow','width=600,height=600,scrollbars=yes');
					debugWin.document.body.innerHTML = req.responseText;
				}
	        }
	    	}
	}

    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
	        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
	        	try {
	          		req = new ActiveXObject("Microsoft.XMLHTTP");
	        	} catch(e) {
	          		req = false;
	        	}
		}
    }
	
	
  var index;
  var urlhost;
  index = getAddr().indexOf("admin.login") ;
//alert("==="+getAddr()+"@"+this.url.length);
  if( getAddr() == "" )
	{
		window.location=this.url;
	}
  if( index != -1 )
	{
//		window.location.href=this.url;
//		urlhost=this.url;
		window.location=this.url;
//	alert(this.url);
//		var hostaddr = getAddr1();
//		window.location=hostaddr;
//		this.url = urlhost;
//	alert(hostaddr);
//		window.location=getAddr1();
	}   

	if(req) {
var btype=getOs();
//alert(btype);
	req.onreadystatechange = processReqChange;
//req.onreadystatechange =(btype!="Firefox")?(processReqChange):(processReqChange());

		if(this.url.length > 2000){
			var urlSpl = this.url.split('?');
			req.open("POST",urlSpl[1],false);
			req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			req.send(urlSpl[2]);
		} else {
// alert("######"+this.url+"#"+this.url.length);	
// window.location = this.url;
//if(btype!="Firefox")
			//{
			req.open("GET", this.url, true);
			req.send("");
		//	}
//else{
//req.open("GET", this.url, true);
  //                      req.send(null);
//}
//req.onreadystatechange =(btype!="Firefox")?(processReqChange):(processReqChange());
		}
	}
}
function getOs()   
{   
   var OsObject = "";   
//alert(navigator.userAgent);
   if(navigator.userAgent.indexOf("MSIE")>0) {   
        return "MSIE";       
   }
   if(navigator.userAgent.indexOf("Firefox")>0){   
        return "Firefox";     
   }
   if(navigator.userAgent.indexOf("Safari")>0) {   
        return "Safari";      
   }
   if(navigator.userAgent.indexOf("Camino")>0){   
        return "Camino";   
   }
}

