function getNoCache()
{
 return ("" + Math.random()).slice(2, 8);
}
function ajaxHandler( elemid, options )
{
 var params = options.params || "";
 var meth = options.meth || "get";
 var async = options.async || true;
 var startfunc = options.startfunc || "";
 var endfunc = options.endfunc || "";
 var errorfunc = options.errorfunc || "";
 var req = false;
 var error = 0;
 var url='/handler.php';
 params = params + "&_nc=" + getNoCache();
 if( window.XMLHttpRequest )
 req = new XMLHttpRequest();
 else if( window.ActiveXObject )
 {
   try
   {
     req = new ActiveXObject( "Msxml2.XMLHTTP" );
   }
   catch (e)
   {
     req = new ActiveXObject( "Microsoft.XMLHTTP" );
   }
 }
 else
 {
 alert( "Your browser cannot perform the requested action. "+
 "Either your security settings are too high or your "+
 "browser is outdated. Try the newest version of "+
 "Internet Explorer or Mozilla Firefox." );
 return false;
 }
 if( startfunc != "" )
 eval( startfunc );
 req.open( meth, url+( params != "" ? "?"+params : "" ), async );
 req.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
 req.onreadystatechange =
 function()
 {
  if ( req.readyState == 4 )
  {
   if ( req.status == 200 )
   {
if (req.responseText=='nopoint') {alert('Nincs elég pontod!');error=1;}
if (req.responseText=='maxvoteable') {alert('Maximum 100 lehet a szavazhatóságod!');error=1;}
	if (error==0) document.getElementById(elemid).innerHTML = req.responseText;
	if( endfunc != "" )
      eval( endfunc );
     return true;
    }
   }
   else
   {
    if( endfunc != "" )
     eval( endfunc );
    if( errorfunc != "" )
     eval( errorfunc );
    return false;
   }
  }
 req.send(null);
}

function ajaxEval( elemid, options )
{
 var params = options.params || "";
 var meth = options.meth || "get";
 var async = options.async || true;
 var startfunc = options.startfunc || "";
 var endfunc = options.endfunc || "";
 var errorfunc = options.errorfunc || "";
 var req = false;
 var error = 0;
 var url='/handler.php';
 params = params + "&_nc=" + getNoCache();
 if( window.XMLHttpRequest )
 req = new XMLHttpRequest();
 else if( window.ActiveXObject )
 {
   try
   {
     req = new ActiveXObject( "Msxml2.XMLHTTP" );
   }
   catch (e)
   {
     req = new ActiveXObject( "Microsoft.XMLHTTP" );
   }
 }
 else
 {
 alert( "Your browser cannot perform the requested action. "+
 "Either your security settings are too high or your "+
 "browser is outdated. Try the newest version of "+
 "Internet Explorer or Mozilla Firefox." );
 return false;
 }
 if( startfunc != "" )
 eval( startfunc );
 req.open( meth, url+( params != "" ? "?"+params : "" ), async );
 req.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
 req.onreadystatechange =
 function()
 {
  if ( req.readyState == 4 )
  {
   if ( req.status == 200 )
   {
if (req.responseText=='nopoint') {alert('Nincs elég pontod!');error=1;}
if (req.responseText=='maxvoteable') {alert('Maximum 100 lehet a szavazhatóságod!');error=1;}
if (req.responseText=='open') {load_chat();document.getElementById('chat_container').style.visibility="visible";}

	if (error==0) eval( req.responseText );
	if( endfunc != "" )
      eval( endfunc );
     return true;
    }
   }
   else
   {
    if( endfunc != "" )
     eval( endfunc );
    if( errorfunc != "" )
     eval( errorfunc );
    return false;
   }
  }
 req.send(null);
}

function show_point(){
	ajaxHandler( "point", {params:"showprofile=point", endfunc:"nogo=''"});
}

function show_szavmeg(){
	ajaxHandler( "szavmeg", {params:"showprofile=szavmeg", endfunc:"nogo=''"});
	show_point();
}

function show_ranglist(gender){
	if (gender==1) var target="ranglist_man";
	if (gender==2) var target="ranglist_woman";
		ajaxHandler( target, {params:"ranglist=" + gender, endfunc:"nogo=''"});
		show_szavmeg();
	}

function voteboard(vote_user,user_usna,userid,usna,voteid,vote,gender,teamid){
	if (gender==1||gender==2)	{
		ajaxHandler( "voteboard", {params:"vote_user=" + vote_user + "&user_usna=" + user_usna + "&user_id=" + userid + "&name=" + usna + "&voteid=" + voteid + "&vote=" + vote + "&tid=" + teamid, endfunc:"nogo=''"});
		show_ranglist(gender);
	}
	else
		ajaxHandler( "voteboard", {params:"vote_user=" + vote_user + "&user_usna=" + user_usna + "&user_id=" + userid + "&name=" + usna + "&voteid=" + voteid + "&vote=" + vote, endfunc:"nogo=''"});
}

function user_page(user_page,param,submenu,step){
	 ajaxHandler( "user_box", {params:"user_page=" + user_page + "&param=" + param + "&submenu=" + submenu + "&step=" + step, endfunc:"nogo=''"});
	}

function remove_post(user_page,param,submenu,step,postid){
	 ajaxHandler( "user_box", {params:"user_page=" + user_page + "&param=" + param + "&submenu=" + submenu + "&step=" + step + "&postid=" + postid, endfunc:"nogo=''"});
	}

function add_smiley(smiley) {
	key = smiley;
	document.getElementById('post_area').value=document.getElementById('post_area').value+key
}

function wingame(game,type){
	ajaxHandler( "div-status", {params:"game=" + game + "&type=" + type, endfunc:"nogo=''"});
	show_point();
}

function update_mood(user,mood){
	ajaxHandler( "amount", {params:"user=" + user + "&mood=" + mood, endfunc:"nogo=''"});
}

function add_voteable(){
	ajaxHandler( "szavmeg", {params:"type=voteable", endfunc:"nogo=''"});
	show_point();
	show_szavmeg();
}

function upgrade_contact_level(id,user,level){
	ajaxEval( "contact_upgrade"+id, {params:"cuid=" + id + "&user=" + user + "&level=" + level, endfunc:"nogo=''"});
	show_point();
}

function choose_chat(user){
	 ajaxHandler( "active_chat", {params:"choose_chat=" + user, endfunc:"nogo=''"});
	 load_chat();
	}

function start_chat(user){
	 document.getElementById("chat_container").style.visibility="visible";
	 ajaxHandler( "active_chat", {params:"chat=" + user, endfunc:"nogo=''"});
	 load_chat();
	}

function send_text(user,text){
	ajaxHandler( "active_chat", {params:"chat=1" + "&text=" + text, endfunc:"nogo=''"});
	document.getElementById("send_chat").value = '';
	load_chat();
}

function load_chat(){
	if (document.getElementById('chat_container').style.visibility=="hidden") document.getElementById('chat_container').style.visibility="visible";
	ajaxHandler( "active_chat", {params:"load_chat=1", endfunc:"nogo=''"});
}

function popup_chat() {
	if (document.getElementById('chat_container').style.visibility=="visible") load_chat();
	else ajaxEval( "active_chat", {params:"analyze_chat=1", endfunc:"nogo=''"});
}

function close_chat() {
	document.getElementById('chat_container').style.visibility="hidden";
	ajaxHandler( "active_chat", {params:"load_chat=3", endfunc:"nogo=''"});
}
 

