var htmlobj_comunicate; 

var comunicate;

function init_comunicate()
{
	try {
		comunicate=new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			comunicate=new ActiveXObject("Microsoft.XMLHTTP");
		} catch (oc) {
			comunicate=null;
		}
	}
	if(!comunicate && typeof XMLHttpRequest != "undefined")
		comunicate = new XMLHttpRequest();			
}
init_comunicate();
function httpdo_get(url, target) {
	comunicate.open('GET',url,true);
	document.getElementById('loader').style.display='';
	if(target!='')
	{
		htmlobj_comunicate = document.getElementById(target);
		comunicate.onreadystatechange=httpresponse;
	}
	/*comunicate.setRequestHeader("Content-Type", "text/html; charset=ISO-8859-15"); */
	comunicate.send('');
}

function httpdo_postform(url, form, target) {
	comunicate.open('POST',url,true);
	comunicate.setRequestHeader('MessageType','CALL');
	comunicate.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); 

	if(target!='')
	{
		htmlobj_comunicate = document.getElementById(target);
		comunicate.onreadystatechange=httpresponse;
	}
	comunicate.send(get_form_vars(form));	
}

function httpdo_postform(form, target) {
	init_comunicate();
	comunicate.open('POST',form.action,true);
	comunicate.setRequestHeader('MessageType','CALL');
	comunicate.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); 
	document.getElementById('loader').style.display='';
	if(target!='')
	{
		htmlobj_comunicate = document.getElementById(target);
		comunicate.onreadystatechange=httpresponse;
	}
	comunicate.send(get_form_vars(form));	
	return false;
}

function httpresponse() {
	if (comunicate.readyState==4) {
		text = comunicate.responseText;
	    htmlobj_comunicate.innerHTML=text;	
		document.getElementById('loader').style.display='none';
	}
} 

function get_form_vars(fobj) 
{ 
	elements = fobj.elements;
	var pairs = new Array();
	
	for (var i = 0; i < elements.length; i++) {
		if (elements[i].type=='checkbox')
			if (!elements[i].checked )
				continue;
			
		if ((name = elements[i].name) && (value = elements[i].value))
			pairs.push(name + "="+ encode64(value));
	}
	pairs.push("encoded64=1");
	return pairs.join("&");
}

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + //all caps
"abcdefghijklmnopqrstuvwxyz" + //all lowercase
"0123456789+/="; // all numbers plus +/=

//Heres the encode function
function encode64(inp)
{
	var out = ""; //This is the output
	var chr1, chr2, chr3 = ""; //These are the 3 bytes to be encoded
	var enc1, enc2, enc3, enc4 = ""; //These are the 4 encoded bytes
	var i = 0; //Position counter

	do { //Set up the loop here
		chr1 = inp.charCodeAt(i++); //Grab the first byte
		chr2 = inp.charCodeAt(i++); //Grab the second byte
		chr3 = inp.charCodeAt(i++); //Grab the third byte

		//Here is the actual base64 encode part.
		//There really is only one way to do it.
		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;
		}

		//Lets spit out the 4 encoded bytes
		out = out + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) +
		keyStr.charAt(enc4);

		// OK, now clean out the variables used.
		chr1 = chr2 = chr3 = "";
		enc1 = enc2 = enc3 = enc4 = "";

	} while (i < inp.length); //And finish off the loop

	//Now return the encoded values.
	return out;
}
