//initialize ajax

function ajaxRequest() 
{
};

ajaxRequest.prototype.init = function() 
{
	try 
	{
		// Mozilla / Safari
		this._xh = new XMLHttpRequest();
	} 
	catch (e) 
	{
		// Explorer
		var _ieMode = new Array(
		'MSXML2.XMLHTTP.5.0',
		'MSXML2.XMLHTTP.4.0',
		'MSXML2.XMLHTTP.3.0',
		'MSXML2.XMLHTTP',
		'Microsoft.XMLHTTP'
		);
		var success = false;

		try
		{
			for (var i=0;i < _ieMode.length && !success; i++) 
			{
				try 
				{
					this._xh = new ActiveXObject(_ieMode[i]);
					success = true;
				} 
				catch (e) 
				{
				// exceptions go here 
				}
			}

		} 
		catch (e) 
		{

		}
	
		if ( !success ) 
		{
			// execptions go here
			return false;
		}
		return true;
	}
}

ajaxRequest.prototype.work = function() 
{
	currentState = this._xh.readyState;
	return (currentState && (currentState < 4));
}

ajaxRequest.prototype.processing = function() 
{
	if (this._xh.readyState == 4 && this._xh.status == 200) 
	{
		this.processComplete = true;
	}
}

ajaxRequest.prototype.dispatchXML = function(urlget,data) 
{
	if (!this._xh) 
	{
		this.init();
	}

	if (!this.work()) 
	{
		this._xh.open("GET",urlget,false);
		this._xh.send(data);
		if (this._xh.readyState == 4 && this._xh.status == 200) 
		{
		
			//var message = this._xh.responseXML.getElementsByTagName("responseText")[0];
			//var message = this._xh.responseXML.getElementsByTagNameNS("*", "*");
			//var message = this._xh.responseXML.documentElement;
			//return message.childNodes[0].nodeValue;
			return this._xh.responseXML;
		}
		
	}
	return false;
}

ajaxRequest.prototype.dispatchHTML = function(urlget,data) 
{
	if (!this._xh) 
	{
		this.init();
	}

	if (!this.work()) 
	{
		this._xh.open("GET",urlget,false);
		this._xh.send(data);
		if (this._xh.readyState == 4 && this._xh.status == 200) 
		{
		
			//var message = this._xh.responseXML.getElementsByTagName("responseText")[0];
			//var message = this._xh.responseXML.getElementsByTagNameNS("*", "*");
			//var message = this._xh.responseXML.documentElement;
			//return message.childNodes[0].nodeValue;
			return this._xh.responseText;
		}
		
	}
	return false;
}

// END AJAX

// START BASE64 ENCODE

function base64() 
{
}

base64.chars = new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/');
base64.convert = "";
base64.count = 0;
base64.setCadena = function (str)
{
    base64.convert = str;
    base64.count = 0;
}

base64.read = function ()
{    
    if (!base64.convert) return "END_OF_INPUT";
    if (base64.count >= base64.convert.length) return "END_OF_INPUT";
    var c = base64.convert.charCodeAt(base64.count) & 0xff;
    base64.count++;
    return c;
}

base64.prototype.encode = function (str)
{
    base64.setCadena(str);
    var result = '';
    var inBuffer = new Array(3);
    var lineCount = 0;
    var done = false;
    while (!done && (inBuffer[0] = base64.read()) != "END_OF_INPUT"){
        inBuffer[1] = base64.read();
        inBuffer[2] = base64.read();
        result += (base64.chars[ inBuffer[0] >> 2 ]);
        if (inBuffer[1] != "END_OF_INPUT"){
            result += (base64.chars [(( inBuffer[0] << 4 ) & 0x30) | (inBuffer[1] >> 4) ]);
            if (inBuffer[2] != "END_OF_INPUT"){
                result += (base64.chars [((inBuffer[1] << 2) & 0x3c) | (inBuffer[2] >> 6) ]);
                result += (base64.chars [inBuffer[2] & 0x3F]);
            } else {
                result += (base64.chars [((inBuffer[1] << 2) & 0x3c)]);
                result += ('=');
                done = true;
            }
        } else {
            result += (base64.chars [(( inBuffer[0] << 4 ) & 0x30)]);
            result += ('=');
            result += ('=');
            done = true;
        }
        lineCount += 4;
        if (lineCount >= 76){
            result += ('\n');
            lineCount = 0;
        }
    }
    return result;
}



