var simple_url = "/simple_client/";
var bVisible = false;
var channels = new Array();
var rooms = new Array();
var winChat = null;
//var webclient = parent.az_client; //popup Çü½Ä¿¡¼± »ç¿ëÇÏÁö ¾ÊÀ½

//room °´Ã¼¸¦ »ý¼ºÇÏ´Â ÇÔ¼ö
function room_info(channel_id, room_no, room_title, max_user) {
	//this.user_count = users.length;
	this.channel_id = channel_id;
	this.room_no = room_no;
	this.title = room_title;
	this.max_user = max_user;
	this.users = new Array();
	//this.users = users;
	//this.addUser = addUser
}

//user °´Ã¼¸¦ »ý¼ºÇÏ´Â ÇÔ¼ö
function room_user(face_icon, userid, name, age, sex, area) {
	this.face_icon = face_icon;
	this.userid = userid;
	this.name = name;
	this.age = age;
	this.sex = sex;	
	this.area = area ; //Á¢¼ÓÁö¿ª
	this.purpose = 'Ä£±¸¸¸³²'; //Á¢¼ÓÀÇµµ,
}

//»ç¿ëÀÚ¸¦ Ãß°¡ÇÑ´Ù.
function addUser(channel_id, room_no, face_icon, userid, name, age, sex, area) {
	var key = channel_id + "_" + room_no;
	if(rooms[key] != null) {
		users = rooms[key].users;
		count = users.length;
		users[count++] = new room_user(face_icon, userid, name, age, sex, area);
	} else {
		//alert('rooms[' + room_id + '] is null');
	}
}

//¹æÀ» Ãß°¡ÇÑ´Ù.
function addRoom(channel_id, room_no, room_title, max_user) {
	
	var key = channel_id + "_" + room_no;
	if(rooms[key] == null) {
		rooms[key] = new room_info(channel_id, room_no, room_title, max_user);
	} else {

		alert('rooms[' + room_no + '] is not null');
	}
}

function showUserMenu(id, name) {
	alert('id : ' + id + '   name : ' + name);
}

//alert('rooms[0].users.length : ' + rooms["001"].users.length);

function showRoomInfo(ch_id, room_no, e) { 
	
	var key = ch_id + "_" + room_no;
	var room_info = rooms[key]; //no¿¡ µû¸¥ ¹æ Á¤º¸¸¦ °¡Á®¿Â´Ù.
	
	/*
		¹æ¹øÈ£ no¸¦ ÆÄ¶ó¸ÞÅÍ·Î ¹Þ¾Æ rooms °´Ã¼¿¡¼­ ÇØ´ç noÀÇ room_info¸¦ ÃßÃâÇÑ´Ù.
		Â÷ÈÄ¿¡ À½¾Ç¹æÀÇ À¯¹«¿Í ºñ¹Ð¹æÀ» Ã¼Å©ÇÏ±â À§ÇØ room_info¿¡ Á¤º¸¸¦ Ãß°¡ÇÏµµ·Ï ÇÑ´Ù.
	*/
	
	var channel_id = room_info.channel_id; //Ã¤³Î id
	var room_no = room_info.room_no; //¹æ¹øÈ£
	var title = room_info.title;  //¹æÁ¦¸ñ
	var users = room_info.users;  //¹æ»ç¿ëÀÚ
	var max_user = room_info.max_user; //ÃÖ´ë»ç¿ëÀÚ
	var cur_user = users.length; //ÇöÀç ¹æÀÎ¿ø

	var go_chat = "<a href=\"#\" onclick=\"join_room('" + channel_id + "','" + room_no+ "')\">";

	str = '<table border=0 cellpadding=1 cellspacing=0 width=350>'
		+ '<tr>'
		    	+ '<td bgcolor=#999999>'
				+ '<table border=0 cellpadding=0 cellspacing=0>'
				+ '<tr bgcolor=#E7EFFF height="30">'
						+ '<td width=350>'
						+ '&nbsp;&nbsp;<font color=#01738A><b>'
						+ unescape(title) + '</b> ('+ cur_user + '/' + max_user + ')</font>'
						+ '</td>'
						+ '<td width=74 align=right>'
						+ go_chat
						+ '<img src=\"/simple_client/images/entry_button.gif\" border=0></a>'
						+ '</td>'
						+ '<td width=26 align=center>'
						+ '<a href=\"javascript:;\" onClick=\"HideRoomInfo(); return false;\">'
						+ '<img src=\"/simple_client/images/close_button.gif\" border=0></a>'
						+ '</td>'
				+ '</tr>'
				+ '<tr bgcolor=#FFFFFF>'
						+ '<td colspan=5>'
						+ '<table border=0 cellpadding=0 cellspacing=0 width=350>'
						+ '<tr align=center height=20>'
								+ '<td width=300 colspan=2><B>»ç¿ëÀÚ</B></td>'
								+ '<td width=100><B>³ªÀÌ</B></td>'
								+ '<td width=100><B>¼ºº°</B></td>'
								
						+ '</tr>';

	max = users.length;

	for(i=0; i < max; i++) {
		var sex = '';
		var age = '';
		if(users[i].sex == 'M' || users[i].sex == "³²¼º") sex = '³²ÀÚ';
		else sex = '¿©ÀÚ';
		age = (users[i].age == 0) ? "ºñ°ø°³" : users[i].age;
		umenu = '<span onClick=\"show_menu(\'' + users[i].userid + '\', \'' + users[i].name + '\''
			+  ')\" onMouseOver=onMOver(this) onMouseOut=\"onMOut(this, \'black\')\">' 
			+  users[i].name + '(' + users[i].userid + ')</span>'
		
		str	+= '<tr>'
			+ '<td colspan=5 align=center height=1 bgcolor=#999999></td>'
			+ '</tr>'
			+ '<tr height=31><td> &nbsp; <img src=/simple_client/face_icon/' + users[i].face_icon + '></td>'
			+  '<td>'
			+ umenu
			+	'</td>'
			+  '<td align=center>' + age + '</td>'
			+  '<td align=center>' + sex + '</td>'
			+  '</tr>';	
	}

	if(max == 0) { //¹æ¿¡ »ç¿ëÀÚ°¡ ¾ø´Ù¸é,,,
		str += '<tr><td colspan=5 align=center height=1 bgcolor=#999999></td></tr>'
		    + '<tr height=31><td colspan=5 align=center><b>ÇöÀç ¹æ¿¡ »ç¿ëÀÚ°¡ ¾ø½À´Ï´Ù.</b></td></tr>';
			
	}
	
					
	str +=				  '</table>'
						+ '</td>'
				+ '</tr>'
				+ '</table>'
				+ '</td>'
		+ '</tr>'
		+ '</table>';
	
	roomInfoFrame.innerHTML = str;
		
	//·¹ÀÌ¾î°¡ º¸¿©Áú À§Ä¡ ÁöÁ¤
	roomInfoFrame.style.left = e.x - 140;
	//roomInfoFrame.style.left = e.x;
	//roomInfoFrame.style.top  = e.y  + document.body.scrollTop;
	roomInfoFrame.style.top  = e.y  + document.body.scrollTop;
	
	//À§Ä¡º¸Á¤
	/*
	if(roomInfoFrame.style.pixelTop + roomInfoFrame.offsetHeight > document.body.clientHeight + document.body.scrollTop)
		roomInfoFrame.style.top = (document.body.clientHeight + document.body.scrollTop) - roomInfoFrame.offsetHeight;	
	*/	
	roomInfoFrame.style.visibility = 'visible';	
}

//room info layer¸¦ ¼û±ä´Ù.


function HideRoomInfo() {
	roomInfoFrame.style.visibility = 'hidden';	
}

//¸¶¿ì½º°¡ onOver ÀÏ¶§(onMouseOver) ¼Ó¼ºÀ» º¯°æÇÑ´Ù.
function onMOver(obj) {
	with(obj.style) {
		cursor = 'hand';
		color  = '#ff8800';
	}
}

//¸¶¿ì½º°¡ onOutÀÏ¶§ (onMouseOut) ¼Ó¼ºÀ» º¯°æÇÑ´Ù.
function onMOut(obj, orgColor) {
	obj.style.color = orgColor;
}

//¸¶¿ì½º Å¬¸¯½Ã¿¡ Æ¯Á¢ popup ·¹ÀÌ¾î¸¦ ¾ø¾Ø´Ù.
function procMouse() {
	var obj = popupmenu;
	if(bVisible) {
		obj.style.visibility = 'hidden';
		bVisible = false;
	}		
}


//document.onmousedown=procMouse; //¸¶¿ì½º¹öÆ°´Ù¿îÀÌº¥Æ®¸¦ Ä¸Ãç...


/*
//Ã¤ÆÃ °ü·Ã ½ºÅ©¸³Æ®
function joinRoom(channel_id, room_no) {
	openChatWindow(channel_id, room_no);
}

*/

function join_room(channel_id, room_no) {
	if(channel_id == '500') {
		alert('Å¬·´ ¿¡¼­¸¸ ÀÔÀåÇÏ½Ç¼ö ÀÖ½À´Ï´Ù.');
		return;
	}
	HideRoomInfo();
	simple_client.openChatWindow(channel_id, room_no, '');
}



function openChatWindow(channel_id, room_no) {
	//winChat = parent.az_main;
	
	if(winChat == null || winChat == 'undefinded' || winChat.closed == true) {
		var url = "./chat_frame.php?channel_id="+channel_id +"&room_no=" + room_no;
		winChat = window.open(url, "chatwin", "width=700 height=600 scrollbars=no resizable=yes");
	} else {
		alert('Ã¤ÆÃÃ¢ÀÌ ¶°ÀÖ½À´Ï´Ù. Ã¢À» ´ÝÀº ÈÄ ´Ù½Ã ½ÃµµÇÏ¼¼¿ä.');
	}
		
	//winChat.location.replace("/webmemo/chat/chat_main.php?channel_id=" + channel_id + '&room_no=' + room_no);
}

function joinPassRoom(channel_id, room_no, room_pass) {
	openPassChatWindow(channel_id, room_no, room_pass);
}
