var invitationUpdateInterval = 15000;	
var onlineUpdateInterval = 60000;	
var domain = "http://www.rowiw.com";

	function init(cmd){
		room_action(cmd);
	}

	
	
	
	function init_2(uid){
		refresh_invitations(uid);
		refresh_online_friends(uid);
		check_sound();
	}
	
	
	function check_sound(){		
		if(readCookie('checked')=='true' || readCookie('checked')==null) {document.getElementById('mute').checked = true;}
	}
	
	
	
	function chat_init(){
		chat_online_friends();
	}
	
	
  function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function setc()
{
  if(document.getElementById('mute').checked)
  {
  eraseCookie('checked');
  createCookie('checked','true',5);
  }
  else
  {
  eraseCookie('checked');
  createCookie('checked','false',5);
  }
}
	
	
function room_action(cmd)
	{
									
		var url =domain + "/chat/action.php?cmd=" + cmd + "&random=" + 10000 + Math.round(Math.random() * 99999);
		
	    // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;

        document.body.appendChild(jsel);
   		    
	}

	
	
	
function refresh_invitations(uid)
	{
	
		var	cmd = "CheckInvitation";
						
		var url =domain + "/chat/action.php?cmd=" + cmd + "&uid=" + uid + "&random=" + 10000 + Math.round(Math.random() * 99999);

        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;

        document.body.appendChild(jsel);
    			    
		window.setTimeout('refresh_invitations(' + uid + ')',invitationUpdateInterval);
	}
	

function refresh_online_friends(uid)
	{
			
		var	cmd = "OnlineFriends";
						
		var url =domain + "/chat/action.php?cmd=" + cmd + "&uid=" + uid + "&random=" + 10000 + Math.round(Math.random() * 99999);
		
        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;

        document.body.appendChild(jsel);
    	
		window.setTimeout('refresh_online_friends('+ uid +')',onlineUpdateInterval);
	}


function chat_online_friends(uid,channel_id)
	{
			
		var	cmd = "ChatOnlineFriends";
						
		var url =domain + "/chat/action.php?cmd=" + cmd + "&uid=" + uid + "&channel_id=" + channel_id + "&random=" + 10000 + Math.round(Math.random() * 99999);
		
        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;

        // Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild(jsel);
    	
		//document.getElementById('tmp_message').value = "";
		    
		window.setTimeout('chat_online_friends(' + uid + ',"' + my_folder + '","' + channel_id + '")',onlineUpdateInterval);
	}



	
	
	function ConferenceInvitation(friend_id,uid,channel_id,lang){

		var url = domain + "/chat/action.php?cmd=ConferenceInvitation&friend_id=" + friend_id + "&uid=" + uid + "&channel_id=" + channel_id + "&random=" + 10000 + Math.round(Math.random() * 99999);
				//alert(url);
        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;

        // Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild(jsel);
		
		if(lang == 'hu'){
			alert('A meghívást elküldtük!');
		}else{
			alert('Please wait!');			
		}
	}

	
	
	function NotAcceptInvitation(channel_id){

		var url =domain + "/chat/action.php?cmd=NotAcceptInvitation&channel_id=" + channel_id + "&random=" + 10000 + Math.round(Math.random() * 99999);
				
        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;

        document.body.appendChild(jsel);

	}
	
	

function hideInvitationsDiv(){
	document.getElementById('chat_invitation_div').style.display = "none";
	document.getElementById('chat_invitation').style.display = "none";
}

