
function encodeMe(value) 
{

    try {
      return escape(value);
    } catch(e) {
       return encodeURIComponent(value);
    }
   
}
function QAjax_rev01() 
{
	this.ajaxReq;
	this.userID = ' ';
	this.pwd = ' '		
	var self = this;
 	if (window.XMLHttpRequest) { 
        self.ajaxReq = new XMLHttpRequest();
        if (self.ajaxReq.overrideMimeType) {
            self.ajaxReq.overrideMimeType('text/xml');
        } 
    } else if (window.ActiveXObject) { 
        try {
            self.ajaxReq = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
          try {
            self.ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (e) {
            alert('Giving up :( Cannot create an Microsoft.XMLHTTP instance');
            return false;
          }
        }
    }

    if (!self.ajaxReq) {
        alert('Giving up :( Cannot create XMLHttpRequest instance.');
        return false;
    }
    
    self.ajaxReq.onreadystatechange = function() {
         if ( self.ajaxReq.readyState == 4 ) {
           if ( self.ajaxReq.status == 200) {
                window.location = self.url;
           }
        }
    };

}

     
function QAjax() 
{
	this.ajaxReq;
	this.userID = ' ';
	this.pwd = ' '		
	var self = this;
    self.ajaxReq = new XMLHttpRequest;

    if (!self.ajaxReq) {
        alert('Giving up :( Cannot create XMLHttpRequest instance.');
        return false;
    }
    
    self.ajaxReq.onreadystatechange = function() {
         if ( self.ajaxReq.readyState == 4 ) {
           if ( self.ajaxReq.status == 200) {
                window.location = self.url;
           }
        }
    };

}


	QAjax.prototype.encode64 = function(input) {
       var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
       var 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);
       } while (i < input.length);

          return output;
    }
	
	
	QAjax.prototype.sndpgmmsg=function(msgText) {
	 	if  (this.ajaxReq.msgAreaDivision) {
             this.ajaxReq.msgAreaDivision.innerHTML = msgText;
        }
    };

    QAjax.prototype.getResponseXML=function() {
         return this.ajaxReq.responseXML;
    };
    
    QAjax.prototype.getResponseText=function() {
         return this.ajaxReq.responseText;
    };
    
    QAjax.prototype.getStatus=function() {
         return this.ajaxReq.status;
    };
    
    QAjax.prototype.getReadyState = function() {
         return this.ajaxReq.readyState;
    };

	QAjax.prototype.defaultReadyStateChange = function() {
         if ( this.ajaxReq.readyState == 4 ) {
           if ( this.ajaxReq.status == 200) {
				this.sndpgmmsg('<span style="color:green;">'+"Redirecting to " + this.url +'</span>');
				auth = this.ajaxReq.getResponseHeader("WWW-Authenticate");
				alert(this.url + " " + auth);
                window.location = this.url;
           }
        }
    };
   
	QAjax.prototype.setURL = function(szURL) {
		this.url = szURL;
	};

	QAjax.prototype.setParms = function(szParmData) {
		this.parmData = szParmData;
	};
	
	QAjax.prototype.setParmData = function(szParmData) {
		this.parmData = szParmData;
	};
	QAjax.prototype.setFormData = function(szParmData) {
		this.parmData = szParmData;
	};
	
	QAjax.prototype.setCallback = function(newCallBack) {
		this.ajaxReq.onreadystatechange = newCallBack;
	};
	
	QAjax.prototype.overrideMimeType=function(mimeType) {
		this.ajaxReq.overrideMimeType(mimeType);
	};
	
    QAjax.prototype.activate = function() {
		this.ajaxReq.open('POST', this.url, true);
	    this.ajaxReq.send(null);
	};

	QAjax.prototype.setMessageArea=function(divName) {
		if  (divName) {
		    this.msgAreaDivision = document.getElementById(divName);
		}
    };
 
	QAjax.prototype.setUser=function(theUser,thePWD) {
	    if (theUser) {
	        this.ajaxReq.userid = theUser;
	    }
	    if (thePWD) {
	        this.ajaxReq.pwd = thePWD;
	    }
	};
	
    QAjax.prototype.setUsrPrf=function(usr, pwd) {
    		// var secData = this.encode64(usr + ':' + pwd);
    		var secData = usr + ':' + pwd;
    		this.ajaxReq.setRequestHeader("Authorization", "Basic " + secData );
    }

 
    QAjax.prototype.SendSignOn=function(url, usr, pwd) {
    
		this.sndpgmmsg('<span style="color:green;">'+'Sign On in progress...'+'</span>');
    
        if (url) 
           this.url = url;
	    if (usr)
			this.userID = usr;
		if (pwd)
			this.pwd = pwd;

        this.ajaxReq.open("POST", this.url, true, this.userID, this.pwd);

		if (this.userID && this.pwd) {
			this.setUsrPrf(this.userID,this.pwd);
		}

		this.ajaxReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		if (!this.parmData) {
	         this.parmData = "USRPRF=" + encodeMe(this.userID) + "&PWD=" + encodeMe(this.pwd);
	    }     
	         
		this.ajaxReq.setRequestHeader("Content-length", this.parmData.length);
	    this.ajaxReq.send(this.parmData);
	};  

  
    QAjax.prototype.SendPost=function(url, params, usr, pwd) {
	    if (usr && pwd) {
			this.userID = usr;
			this.pwd = pwd;
		}
		if (this.userID && this.pwd) {
	        this.ajaxReq.open('POST', this.url, true, usr, pwd);
	    }
	    else {
	        this.ajaxReq.open('POST', this.url, true);
	    }  
    	this.ajaxReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
    	if (params) {
    		this.ajaxReq.setRequestHeader("Content-length", params.length);
    	}
    	if (params) {
		    this.ajaxReq.send(params);
		}
		else {
			this.ajaxReq.send(null);
		}
	};    

	
    QAjax.prototype.getXMLNodeText = function(myNode,i) {
       this.theNode = this.ajaxReq.responseXML.getElementsByTagName(myNode)[i];
       if  (this.theNode) {
            this.theNodeText  = this.theNode.childNodes[0];
           if  (this.theNodeText) {
	           return this.theNodeText.nodeValue;
           }
       }
    };
    QAjax.prototype.getXMLNode = function(myNode,i) {
       this.theNode = this.ajaxReq.responseXML.getElementsByTagName(myNode)[i];
       if  (this.theNode) {
            return this.theNode.childNodes[0];
       }
    };
    QAjax.prototype.getXMLNodeCount = function(myNode) {
       this.theNode = this.ajaxReq.responseXML.getElementsByTagName(myNode);
       if  (this.theNode) {
            return this.theNodeText.length;
       }
       return 0;
    };
    
    QAjax.prototype.getXMLNodeText = function(myNode) {
       this.theNode = this.ajaxReq.responseXML.getElementsByTagName(myNode)[0];
       if  (this.theNode) {
            this.theNodeText  = this.theNode.childNodes[0];
           if  (this.theNodeText) {
	           return this.theNodeText.nodeValue;
           }
       }
    };
          