//--------------------------------------------------------------------------------------------------------------//
//													AJAX Functions
//--------------------------------------------------------------------------------------------------------------//
// SEND A GET REQUEST AND EXECUTE PROCESS FUNCTION
function ajaxGET(url, func){

	var _t=this; var moz;
	if (window.XMLHttpRequest){this.xmlreq = new XMLHttpRequest(); moz=1;}
	else if (window.ActiveXObject){this.xmlreq = new ActiveXObject("Microsoft.XMLHTTP"); moz=0;}
	else return false;
	this.xmlreq.onreadystatechange = (function() {
		if (_t.xmlreq.readyState == 4){
			clearTimeout(_t.xmlto);
			if (_t.xmlreq.status==200){
				var x = _t.xmlreq.responseXML;
				if(x){
					var n = x.getElementsByTagName("n")[0].firstChild.nodeValue;
					var r = x.getElementsByTagName("r")[0].firstChild.nodeValue;
					if (r == 'session expired') msgSessExp();
					else if (r == 'ok') ajaxProcess(x, func, n);
				}
			}
		}
	});
	this.xmlreq.open("GET",url,true);
	if (moz==1) this.xmlreq.send(null); else this.xmlreq.send();
}

// ROCESS REQUEST AND EXECUTE TARGET FUNCTION
function ajaxProcess(x, func, total){
	msg_conv = new Array();
	var m = x.getElementsByTagName("m")[0];
	var mc = m.childNodes.length;
	var data = new Array();

	for (var i = 0; i < mc; i++) {
		mn = m.childNodes[i];
		if (mn.nodeName.indexOf('id_') != 0) continue;
		
		var ctc=mn.childNodes.length;
		for (var ci = 0; ci < ctc; ci++) {
	
			n=mn.childNodes[ci];
			data[n.nodeName] = n.firstChild.nodeValue;
		}
		func.call(this, data, i, total);
	}
}
//------------------------------------------------------------------------------------------------------------------------
//											Post Character Encoding Functions
//------------------------------------------------------------------------------------------------------------------------
function msgSend(fid) {
	var mtype=msgValue('msg-new-type-'+fid);
	var mpr=mtype+'='+msgValue('msg-new-to-'+fid);
	mpr+='&title='+enc(msgValue('msg-new-title-'+fid));
	mpr+='&text='+enc(msgValue('msg-new-text-'+fid));
	if (mtype=='conv') new msgPostReq(msg_xml_path+'send.php',mpr,msgSendConv);
	else new msgPostReq(msg_xml_path+'send.php',mpr,msgSendTo);
}

function ajaxEncode(s) {ss='';for (i=0;i<s.length;i++){c=s.charAt(i);
if (c=='a'||c=='b'||c=='c'||c=='d'||c=='e'||c=='f'||c=='g'||c=='h'||c=='i'||c=='j'||c=='k'||c=='l'||c=='m'||
c=='n'||c=='o'||c=='p'||c=='q'||c=='r'||c=='s'||c=='t'||c=='u'||c=='v'||c=='w'||c=='x'||c=='y'||c=='z'||
c=='A'||c=='B'||c=='C'||c=='D'||c=='E'||c=='F'||c=='G'||c=='H'||c=='I'||c=='J'||c=='K'||c=='L'||c=='M'||
c=='N'||c=='O'||c=='P'||c=='Q'||c=='R'||c=='S'||c=='T'||c=='U'||c=='V'||c=='W'||c=='X'||c=='Y'||c=='Z'||
c=='0'||c=='1'||c=='2'||c=='3'||c=='4'||c=='5'||c=='6'||c=='7'||c=='8'||c=='9') ss=ss+c;
else if (c=='?') ss=ss+'%E0';else if (c=='?') ss=ss+'%E1';else if (c=='?') ss=ss+'%E2';else if (c=='?') ss=ss+'%E3';
else if (c=='?') ss=ss+'%E4';else if (c=='?') ss=ss+'%E5';else if (c=='?') ss=ss+'%E6';else if (c=='?') ss=ss+'%E7';
else if (c=='?') ss=ss+'%E8';else if (c=='?') ss=ss+'%E9';else if (c=='?') ss=ss+'%EA';else if (c=='?') ss=ss+'%EB';
else if (c=='?') ss=ss+'%EC';else if (c=='?') ss=ss+'%ED';else if (c=='?') ss=ss+'%EE';else if (c=='?') ss=ss+'%EF';
else if (c=='?') ss=ss+'%F0';else if (c=='?') ss=ss+'%F1';else if (c=='?') ss=ss+'%F2';else if (c=='?') ss=ss+'%F3';
else if (c=='?') ss=ss+'%F4';else if (c=='?') ss=ss+'%F5';else if (c=='?') ss=ss+'%F6';else if (c=='?') ss=ss+'%F7';
else if (c=='?') ss=ss+'%F8';else if (c=='?') ss=ss+'%F9';else if (c=='?') ss=ss+'%FA';else if (c=='?') ss=ss+'%FB';
else if (c=='?') ss=ss+'%FC';else if (c=='?') ss=ss+'%FD';else if (c=='?') ss=ss+'%FE';else if (c=='?') ss=ss+'%FF';
else if (c=='?') ss=ss+'%C0';else if (c=='?') ss=ss+'%C1';else if (c=='?') ss=ss+'%C2';else if (c=='?') ss=ss+'%C3';
else if (c=='?') ss=ss+'%C4';else if (c=='?') ss=ss+'%C5';else if (c=='?') ss=ss+'%C6';else if (c=='?') ss=ss+'%C7';
else if (c=='?') ss=ss+'%C8';else if (c=='?') ss=ss+'%C9';else if (c=='?') ss=ss+'%CA';else if (c=='?') ss=ss+'%CB';
else if (c=='?') ss=ss+'%CC';else if (c=='?') ss=ss+'%CD';else if (c=='?') ss=ss+'%CE';else if (c=='?') ss=ss+'%CF';
else if (c=='?') ss=ss+'%D0';else if (c=='?') ss=ss+'%D1';else if (c=='?') ss=ss+'%D2';else if (c=='?') ss=ss+'%D3';
else if (c=='?') ss=ss+'%D4';else if (c=='?') ss=ss+'%D5';else if (c=='?') ss=ss+'%D6';else if (c=='?') ss=ss+'%D7';
else if (c=='?') ss=ss+'%D8';else if (c=='?') ss=ss+'%D9';else if (c=='?') ss=ss+'%DA';else if (c=='?') ss=ss+'%DB';
else if (c=='?') ss=ss+'%DC';else if (c=='?') ss=ss+'%DD';else if (c=='?') ss=ss+'%DE';else if (c=='?') ss=ss+'%DF';
else if (c==' ') ss=ss+'+';else if (c=='\n') ss=ss+'%0A';else if (c=='!') ss=ss+'%21';else if (c=='@') ss=ss+'%40';
else if (c=='#') ss=ss+'%23';else if (c=='$') ss=ss+'%24';else if (c=='%') ss=ss+'%25';else if (c=='^') ss=ss+'%5E';
else if (c=='&') ss=ss+'%26';else if (c=='=') ss=ss+'%3D';else if (c=='+') ss=ss+'%2B';else if (c=='-') ss=ss+'%2D';
else if (c=='*') ss=ss+'%2A';else if (c=='_') ss=ss+'%5F';else if (c=='/') ss=ss+'%2F';else if (c=='\\') ss=ss+'%5C';
else if (c=='|') ss=ss+'%7C';else if (c=='`') ss=ss+'%60';else if (c=='"') ss=ss+'%22';else if (c=="'") ss=ss+'%27';
else if (c=='.') ss=ss+'%2E';else if (c==',') ss=ss+'%2C';else if (c==':') ss=ss+'%3A';else if (c==';') ss=ss+'%3B';
else if (c=='?') ss=ss+'%3F';else if (c=='~') ss=ss+'%7E';else if (c=='(') ss=ss+'%28';else if (c==')') ss=ss+'%29';
else if (c=='[') ss=ss+'%5B';else if (c==']') ss=ss+'%5D';else if (c=='{') ss=ss+'%7B';else if (c=='}') ss=ss+'%7D';
else if (c=='<') ss=ss+'%3C';else if (c=='>') ss=ss+'%3E';}return ss;}

