var upd, answer, game=0, chatid=0, reqtime=time(), quetime=0, received; intr=setInterval('valtime()',1000);
function delta() {
 var delta=window.open("http://www.hoteldelta.eu/tradepoll-ads/","delta","location=0,status=0,scrollbars=0,width=280,height=185");
 delta.blur();
}
function time() {
  var d=new Date();
  return Math.round(d.getTime()/1000);
}
function add(url,x,y,info) {
  document.write('<object width='+x+' height='+y+'>');
  document.write('<param name=movie value='+url+'><param name=wmode value=transparent><param name=flashvars value='+info+'>');
  document.write('<embed width='+x+' height='+y+' src='+url+' wmode=transparent flashvars='+info+'></embed></object>');
}
function denypaste() {
  var pressedKey=String.fromCharCode(event.keyCode).toLowerCase();
  if ((event.ctrlKey) && ((pressedKey=='c') || (pressedKey=='v'))) { event.returnValue=false; }
}
function valtime() {
  functime=time();
  tmr=reqtime-functime;
  if ((tmr>0) && (tmr<=10)) {
    if (tmr<10) { tmr='0'+tmr; }
	if (document.getElementById('countdown')) {
      document.getElementById('countdown').innerHTML=tmr;
	  document.getElementById('timertd').className='timeron';
	}
	else { clearInterval(intr); }
  }
  else if (document.getElementById('countdown')) {
    document.getElementById('countdown').innerHTML='00';
	document.getElementById('timertd').className='timeroff';
  }
  if (quetime>0) {
    quetime=quetime-1;
    if (quetime<10) { quetime='0'+quetime; }
	if (document.getElementById('que')) {
	  document.getElementById('que').innerHTML=quetime;
	  document.getElementById('quetd').className='timeron';
	}
	else { clearInterval(intr); }
  }
  else if (document.getElementById('que')) {
    document.getElementById('que').innerHTML='00';
    document.getElementById('quetd').className='timeroff';
  }
  else { clearInterval(intr); }
  if ((functime>=reqtime) || (!reqtime)) {
	reqtime=functime;
	if (document.getElementById('arena')) { ajaxcon(); }
  }
}
function trigger(raw) {
  reqtime=time();
  x=0;
  raw=raw.split("|");
  while (raw[x]) {
    itm=urldecode(raw[x]);
    if (itm.substr(itm.indexOf("@")+1)) {
	  divon=document.getElementById(itm.substr(0,itm.indexOf("@")));
      if (divon) {
	    if ((itm.substr(0,itm.indexOf("@"))=='arena') || (itm.substr(0,itm.indexOf("@"))=='chat')) {
	      if (divon.scrollHeight>=2000) { divon.innerHTML=''; }
	      if (divon.innerHTML) {
		    if (itm.substr(0,itm.indexOf("@"))=='chat') {
	          divon.innerHTML=divon.innerHTML+itm.substr(itm.indexOf("@")+1);
		      divon.scrollTop=divon.scrollHeight+1000;						
			}
	        else if (received!=itm.substr(itm.indexOf("@")+1)) {
	          divon.innerHTML=divon.innerHTML+itm.substr(itm.indexOf("@")+1);
		      divon.scrollTop=divon.scrollHeight+1000;
		      received=itm.substr(itm.indexOf("@")+1);
			  if (received.search(/ai primit/i)>0) { document.getElementById('award').src='binary/award.mp3'; }
		    }
		  }
		  else {
		    newinf=itm.substr(itm.indexOf("@")+1);
		    if (newinf.substr(0,8)=="<br><br>") { newinf=newinf.substr(8); }
		    else if (newinf.substr(0,4)=="<br>") { newinf=newinf.substr(4); }
		    divon.innerHTML=newinf;
			if (itm.substr(0,itm.indexOf("@"))=='arena') { received=itm.substr(itm.indexOf("@")+1); }
		  }
	    }
	    else { divon.innerHTML=itm.substr(itm.indexOf("@")+1); }
	  }
	  else if (itm.substr(0,itm.indexOf("@"))=='nexttime') { reqtime=reqtime+parseInt(itm.substr(itm.indexOf("@")+1)); }
	  else if (itm.substr(0,itm.indexOf("@"))=='chatid') { chatid=parseInt(itm.substr(itm.indexOf("@")+1)); }
	  else if (itm.substr(0,itm.indexOf("@"))=='quetime') { quetime=parseInt(itm.substr(itm.indexOf("@")+1)); }
	  else if (itm.substr(0,itm.indexOf("@"))=='location') { window.location=itm.substr(itm.indexOf("@")+1); }
	}
    x++;
  }
}
function ajaxrep() {
  if (upd.readyState==4) {
    if (upd.status==200) {
      if (upd.responseText) {
	    trigger(upd.responseText);
      }
    }
  }
}
function ajaxcon(answer,chatax) {
  if (document.rinput) { idata='r_usr='+document.rinput.r_usr.value+'&r_pwd='+document.rinput.r_pwd.value+'&r_eml='+document.rinput.r_eml.value+'&r_date='+mktime(0,0,0,document.rinput.r_month.value,document.rinput.r_day.value,document.rinput.r_year.value); }
  else if (document.oinput) { idata='c_eml='+document.oinput.c_eml.value+'&msg='+document.oinput.msg.value; }
  else if (document.pinput) { idata='p_eml='+document.pinput.p_eml.value; }
  else if (document.linput) { idata='l_usr='+document.linput.l_usr.value+'&l_pwd='+document.linput.l_pwd.value; }
  else if (document.ninput) { idata='c_pwd='+document.ninput.c_pwd.value+'&n_pwd='+document.ninput.n_pwd.value; }
  else if (document.kinput) { idata='k_eml='+document.kinput.k_eml.value; }
  else if (document.xinput) { idata='x_name='+document.xinput.x_name.value; }
  else {
    idata='game='+game+'&chatid='+chatid;
    if (answer) {
      if (answer=='getgame') { idata=idata+'&getgame=1'; }
	  else if (chatax) { idata=idata+'&chatmsg='+answer; }
	  else { idata=idata+'&answer='+answer; }
    }
  }
  if (window.XMLHttpRequest) { upd=new XMLHttpRequest(); }
  else if (window.ActiveXObject) { upd=new ActiveXObject("Microsoft.XMLHTTP"); }
  if (upd) {
    upd.onreadystatechange=ajaxrep;
    upd.open('POST','index.php',true);
    upd.setRequestHeader('Content-type','application/x-www-form-urlencoded'); upd.setRequestHeader('Content-length',idata.length); upd.setRequestHeader('Connection','close');
    upd.send(idata);
  }
}
function formque() {
  if (document.uinput) {
    if ((document.uinput.answer.value) && (document.uinput.answer.value.toLowerCase()!='da') && (document.uinput.answer.value.toLowerCase()!='nu')) { ajaxcon(document.uinput.answer.value); }
    document.uinput.answer.focus();
    document.uinput.answer.value='';
  }
}
function formchat() {
  if (document.cinput) {
    if (document.cinput.msg.value) { ajaxcon(document.cinput.msg.value,1); }
    document.cinput.msg.focus();
    document.cinput.msg.value='';
  }
}
function showgame() {
  document.getElementById('tgame').className='tabon';
  document.getElementById('arena').style.display='block';
  document.getElementById('arena').scrollTop=document.getElementById('arena').scrollHeight+1000;
  document.getElementById('tlist').className='taboff';
  document.getElementById('play').style.display='none';
}
function showlist() {
  document.getElementById('tgame').className='taboff';
  document.getElementById('arena').style.display='none';
  document.getElementById('tlist').className='tabon';
  document.getElementById('play').style.display='block';
  ajaxcon('getgame');
}
function init() {
  if (document.uinput) {
    if (document.uinput.answer) { document.uinput.answer.focus(); }
  }
}
function urldecode(input) { input=input.replace(new RegExp('\\+','g'),' '); return unescape(input); }
function urlencode(input) { input=escape(input); input=input.replace(new RegExp('\\+','g'),'%2B'); return input.replace(new RegExp('%20','g'),'+'); }
function inputval(formn) {
  if (formn=='register') {
    if ((!document.rinput.r_usr.value) || (!document.rinput.r_pwd.value) || (!document.rinput.r_eml.value) || (!document.rinput.r_day.value) || (!document.rinput.r_month.value) || (!document.rinput.r_year.value)) { document.getElementById('rerror').innerHTML='<div class=bad>Va rugam sa completati campurile necesare.</div>'; }
    else if (!document.rinput.r_usr.value.match(/^[a-z]+[0-9a-z]{1,14}$/gi)) { document.getElementById('rerror').innerHTML='<div class=bad>Numele de utilizator trebuie sa inceapa cu o litera si poate contine intre 2 si 15 caractere alfa numerice (numere si cifre).</div>'; }
    else if (!document.rinput.r_pwd.value.match(/^[a-z0-9\_\@\s\,\.\?\!\-\:\;\+\*\(\)]{6,30}$/gi)) { document.getElementById('rerror').innerHTML='<div class=bad>Parola poate contine intre 6 si 30 caractere alfa numerice, spatii si alte simboluri.</div>'; }
    else if (!document.rinput.r_eml.value.match(/^[a-z0-9]+([\.\_\-]?[a-z0-9]+){1,20}[@][a-z0-9]+([\.\-]?[a-z0-9]+){1,20}[\.][a-z]{2,4}$/gi)) { document.getElementById('rerror').innerHTML='<div class=bad>Specificati o adresa de email reala.</div>'; }
    else if (baddate(document.rinput.r_day.value,document.rinput.r_month.value,document.rinput.r_year.value)) { document.getElementById('rerror').innerHTML='<div class=bad>Specificati o data de nastere reala.</div>'; }
    else {
      document.getElementById('rerror').innerHTML='';
	  ajaxcon();
    }
  }
  else if (formn=='contact') {
    if ((!document.oinput.c_eml.value) || (!document.oinput.msg.value)) { document.getElementById('cerror').innerHTML='<div class=bad>Va rugam sa completati campurile necesare.</div>'; }
    else if (!document.oinput.c_eml.value.match(/^[a-z0-9]+([\.\_\-]?[a-z0-9]+){1,20}[@][a-z0-9]+([\.\-]?[a-z0-9]+){1,20}[\.][a-z]{2,4}$/gi)) { document.getElementById('cerror').innerHTML='<div class=bad>Specificati o adresa de email reala.</div>'; }
    else {
      document.getElementById('cerror').innerHTML='';
      ajaxcon();
    }
  }
  else if (formn=='pass') {
    if (!document.pinput.p_eml.value) { document.getElementById('perror').innerHTML='<div class=bad>Va rugam sa completati campurile necesare.</div>'; }
    else if (!document.pinput.p_eml.value.match(/^[a-z0-9]+([\.\_\-]?[a-z0-9]+){1,20}[@][a-z0-9]+([\.\-]?[a-z0-9]+){1,20}[\.][a-z]{2,4}$/gi)) { document.getElementById('perror').innerHTML='<div class=bad>Specificati o adresa de email reala.</div>'; }
    else {
      document.getElementById('perror').innerHTML='';
      ajaxcon();
    }
  }
  else if (formn=='newpass') {
    if ((!document.ninput.c_pwd.value) || (!document.ninput.n_pwd.value)) { document.getElementById('nerror').innerHTML='<div class=bad>Va rugam sa completati campurile necesare.</div>'; }
    else if ((!document.ninput.c_pwd.value.match(/^[a-z0-9_@\s\,\.\?\!-:;\+\*\(\)]{6,30}$/gi)) || (!document.ninput.n_pwd.value.match(/^[a-z0-9_@\s\,\.\?\!-:;\+\*\(\)]{6,30}$/gi))) { document.getElementById('nerror').innerHTML='<div class=bad>Parola poate contine intre 6 si 30 caractere alfa numerice, spatii si alte simboluri.</div>'; }
    else {
      document.getElementById('nerror').innerHTML='';
      ajaxcon();
    }
  }
  else if (formn=='kiss') {
    if (!document.kinput.k_eml.value) { document.getElementById('kerror').innerHTML='<div class=bad>Va rugam sa completati campurile necesare.</div>'; }
    else if (!document.kinput.k_eml.value.match(/^[a-z0-9]+([\.\_\-]?[a-z0-9]+){1,20}[@][a-z0-9]+([\.\-]?[a-z0-9]+){1,20}[\.][a-z]{2,4}$/gi)) { document.getElementById('kerror').innerHTML='<div class=bad>Specificati o adresa de email reala.</div>'; }
    else {
      document.getElementById('kerror').innerHTML='';
      ajaxcon();
    }
  }
  else if (formn=='login') {
    if ((!document.linput.l_usr.value) || (!document.linput.l_pwd.value)) { document.getElementById('lerror').innerHTML='<div class=bad>Va rugam sa completati campurile necesare.</div>'; }
    else if (!document.linput.l_usr.value.match(/^[a-z]+[0-9a-z]{1,14}$/gi)) { document.getElementById('lerror').innerHTML='<div class=bad>Numele de utilizator trebuie sa inceapa cu o litera si poate contine intre 2 si 15 caractere alfa numerice (numere si cifre).</div>'; }
    else if (!document.linput.l_pwd.value.match(/^[a-z0-9_@\s\,\.\?\!-:;\+\*\(\)]{6,30}$/gi)) { document.getElementById('lerror').innerHTML='<div class=bad>Parola poate contine intre 6 si 30 caractere alfa numerice, spatii si alte simboluri.</div>'; }
    else {
      document.getElementById('lerror').innerHTML='';
	  ajaxcon();
    }  
  }
  else if (formn=='round') {
    if (!document.xinput.x_name.value) { document.getElementById('xerror').innerHTML='<div class=bad>Va rugam sa completati campurile necesare.</div>'; }
	else if (!document.xinput.x_name.value.match(/^[a-z0-9\s]{2,50}$/gi)) { document.getElementById('xerror').innerHTML='<div class=bad>Numele unei runde de joc poate contine doar litere, cifre si spatii.</div>'; }
	else {
      document.getElementById('xerror').innerHTML='';
	  ajaxcon();
    }
  }
}
function baddate(day,month,year) {
  bad=0;
  if (!day.match(/^[0-9]{1,2}$/)) { bad=1; }
  if ((day<1) || (day>31)) { bad=1; }
  if (!month.match(/^[0-9]{1,2}$/)) { bad=1; }
  if ((month<1) || (month>12)) { bad=1; }
  if (!year.match(/^[0-9]{4,4}$/)) { bad=1; }
  if ((year<1900) || (year>2008)) { bad=1; }
  div=year/4-Math.floor(year/4);
  if ((month==2) && (div) && (day>28)) { bad=1; }
  else if ((month==2) && (!div) && (day>29)) { bad=1; }
  else if (((month==1) || (month==3) || (month==5) || (month==7) || (month==8) || (month==10) || (month==12)) && (day>31)) { bad=1; }
  else if (((month==4) || (month==6) || (month==9) || (month==11)) && (day>30)) { bad=1; }
  return bad;
}
function mktime() {
  var no,ma=0,mb=0,i=0,d=new Date(),argv=arguments,argc=argv.length;
  d.setHours(0,0,0); d.setDate(1); d.setMonth(1); d.setYear(1972);
  var dateManip={
    0: function (tt) { return d.setHours(tt); },
    1: function (tt) { return d.setMinutes(tt); },
    2: function (tt) { set=d.setSeconds(tt); mb=d.getDate()-1; return set; },
    3: function (tt) { set=d.setMonth(parseInt(tt)-1); ma=d.getFullYear()-1972; return set; },
    4: function (tt) { return d.setDate(tt+mb); },
    5: function (tt) { return d.setYear(tt+ma); }
  };
  for (i=0; i<argc; i++) {
    no=parseInt(argv[i]*1);
    if (no&&isNaN(no)) { return; }
	else if (no) {
      if (!dateManip[i](no)) { return; }
    }
  }
  return Math.floor(d.getTime()/1000);
}