

  function $(id) {return document.getElementById(id); }  
  function reqdtm() { with( new Date() ) return "&reqdtm="+getTime(); }
  
  // class HTTP
  function HTTP(aAction) {
    if (aAction==undefined) { aAction='index.php'; }
    this.FHttp = null;
    try { this.FHttp = new ActiveXObject("Msxml2.XMLHTTP");}
  	catch(e) {
	   	try { this.FHttp = new ActiveXObject("Microsoft.XMLHTTP");}
		  catch(oc) { this.FHttp = null;}
	  }
  	if(!this.FHttp && typeof XMLHttpRequest != "undefined") { this.FHttp = new XMLHttpRequest();}
  	this.Http=this.FHttp;
    this.Action=aAction;
    return this;
  }
  
  HTTP.prototype.call=function(params,postdata) {
	if (this.FHttp.readyState!=0&&this.FHttp.readyState!=4) {
		substitute=new HTTP(this.Action); 
	  	return substitute.call(params,postdata);
	}
        
  	if (postdata==undefined) postdata="";
  	if (params==undefined) params="";
     	//params+=reqdtm();
	
	//window.alert(this.Action);
	if (postdata=="") {
		this.FHttp.open('GET',this.Action+params,false);
		this.FHttp.setRequestHeader("Method", "GET " + this.Action + " HTTP/1.1");
	} else {
		this.FHttp.open('POST',this.Action+params,false);
		this.FHttp.setRequestHeader("Method", "POST " + this.Action + " HTTP/1.1");
	}
   	this.FHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    this.FHttp.onreadystatechange=function() {}
	this.FHttp.send(postdata);
	return this.FHttp.responseText;
	    
  }
  
  HTTP.prototype.get=function(params,handler) {
	if (this.Http.readyState!=0&&this.Http.readyState!=4) { 
		substitute=new HTTP(this.Action); 
	  	return substitute.get(params,handler);
		
	}    
    with (this) {       	
      	params+=reqdtm();
		Http.open('GET',Action+params,true);
    	Http.onreadystatechange=function() {
    		if (Http.readyState!=4) return;
    		//if (Http.status!=200) return;
    		if (handler!=undefined) handler(Http.responseText);
		}
    	Http.send(null);
    	return Http;
    }
  }
  

  HTTP.prototype.post=function(params,frm,handler) {
	if (this.Http.readyState!=0&&this.Http.readyState!=4) { 
		substitute=new HTTP(this.Action); 
	  	return substitute.post(params,frm,handler);		
	}    
	var PostData = "";
	var sendall=false;	
	if (frm!=null)
    for(var i = 0 ; i < frm.elements.length ; i++) {
    	e=frm.elements[i];    	
    	if ((e.name=="myodb_object")&&(e.value=="")) sendall=true;
		if ((e.modified==undefined)&&(e.name!="myodb_class")&&(e.name!="myodb_object")&&(!sendall)&&(e.type!="checkbox")&&e.type!="hidden") continue;
      	if (e.type=="radio") {
			if (e.checked) {
			  if (PostData != "") PostData += "&";
			  PostData +=e.name +"="+e.value;
			}
			continue;
		} 
		
	 	if (PostData != "") PostData += "&";    	
    	PostData += e.name;
 		PostData += "=";
		if (e.type=="checkbox") {
        	PostData += (e.checked)?"1":"0";
      	} else {
		    PostData += encodeURIComponent(e.value);
		}
		
  	}
  	  	
    with (this) {
      
      Http.open("POST", Action + params , true);
	  //w=window.open();w.document.write("<pre>"+PostData+"</pre>");w.document.close();
      Http.setRequestHeader("Method", "POST " + Action + " HTTP/1.1");
      Http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      Http.onreadystatechange = function() {
		if(Http.readyState != 4) return;
    		//if (Http.status!=200) return;
    		if (handler!=undefined) handler(Http.responseText);
	  }	  

  	  Http.send(PostData); 
  	  return Http;
  	}
  }  

  // class end


  // base64
  var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
                
  function encode64(input) {
      var output = "";if (input=="") { return output;}
      var chr1, chr2, chr3 = "";
      var enc1, enc2, enc3, enc4 = "";
      var i = 0;
      do {
         chr1 = input.charCodeAt(i++);
         chr2 = input.charCodeAt(i++);
         chr3 = input.charCodeAt(i++);

         enc1 = chr1 >> 2;
         enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
         enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
         enc4 = chr3 & 63;
         if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64;}
         output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4);
         chr1 = chr2 = chr3 = "";
         enc1 = enc2 = enc3 = enc4 = "";
      } while (i < input.length);

      return output;
   }

   function decode64(input) {
      var output = "";if (input=="") { return output;}
      var chr1, chr2, chr3 = "";
      var enc1, enc2, enc3, enc4 = "";
      var i = 0;

      // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
      var base64test = /[^A-Za-z0-9\+\/\=]/g;
      if (base64test.exec(input)) {
         alert("There were invalid base64 characters in the input text.\n" +
               "Valid base64 characters are A-Z, a-z, 0-9, '+', '/', and '='\n" +
               "Expect errors in decoding.");
      }
      input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

      do {
         enc1 = keyStr.indexOf(input.charAt(i++));
         enc2 = keyStr.indexOf(input.charAt(i++));
         enc3 = keyStr.indexOf(input.charAt(i++));
         enc4 = keyStr.indexOf(input.charAt(i++));

         chr1 = (enc1 << 2) | (enc2 >> 4);
         chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
         chr3 = ((enc3 & 3) << 6) | enc4;

         output = output + String.fromCharCode(chr1);

         if (enc3 != 64) {
            output = output + String.fromCharCode(chr2);
         }
         if (enc4 != 64) {
            output = output + String.fromCharCode(chr3);
         }

         chr1 = chr2 = chr3 = "";
         enc1 = enc2 = enc3 = enc4 = "";

      } while (i < input.length);

      return output;
  }

	function  HTTPSimple(aurl,ainterface) {
	
		t = location.pathname.split("/");
		a = aurl.split("/");
		y = -1;
		i = 0;
		for (i=0;i<a.length;i++ )  
		  if (a[i] && document.getElementById(a[i])) {
			if (!ainterface) ainterface= a[i];	
			//window.alert(ainterface);			
			y = i-1;
			break;
		}
		test="";
		for (i=0; i<=y; i++) if (a[i]) test += "/"+a[i];
		hash="";
		for (i=y+1; i<a.length; i++) if (a[i]) hash += "/"+a[i]; 		
		//window.alert(test +"|"+hash);

		if (test!=location.pathname) {				
			window.location = test +'#'+hash;
			return;
		}
		
		location.hash = hash;
		
		if (ainterface) aurl+=".ajax="+ainterface; 
		
		h=new HTTP(aurl);
		result=h.call("");		
		delete h;
		
		if (ainterface==undefined) return result;
		
		div=document.getElementById(ainterface);
		oldstyle=div.style.color;
		div.style.color="white";
		
		div.style.color=oldstyle;
		div.innerHTML=result;
		if (XMask) XMask.Initialize();
	}
	function CheckAjaxHash(active) {
		
		if (location.hash) {			
			aurl = location.pathname + location.hash.substring(1);			
			//window.alert(1);
			if (active) HTTPSimple( aurl );else window.location = aurl;
		}
		
	}	