function newbuddy(roomId,username,status,fullname,pic) {

			var chat_status = "display:none;";
			var box_status = "display:none;";
				
			if(status == "1"){
				chat_status = "visibility:visible; display:;";
				box_status = "visibility:visible; display:;";
			}
			if(status == "2"){
				chat_status = "visibility:hidden;";
				box_status = "";
			}
			if(status == "0"){
				chat_status = "display:none;";
				box_status = "display:none;";
			}
			
			if(document.getElementById('box_'+roomId) != null && status == "1"){
			    document.getElementById('box_'+roomId).style.visibility = 'visible'
    		 	document.getElementById('box_'+roomId).style.display = '';
    		 	document.getElementById('chat_'+roomId).style.visibility = 'visible'
    		 	document.getElementById('chat_'+roomId).style.display = '';
			}
			
			if(document.getElementById("box_"+roomId) == null){

				table_box=document.getElementById('bottom_chat');
				new_row_box=table_box.rows[0];
		
				if(document.all) { //IE
					new_row_box.insertCell().innerHTML="<div id=\"box_"+ roomId +"\" style=\""+box_status+"\">\
					<td>\
					<div id=\"bottom_title\">\
					<div class=\"text_bottom\">\
					<a href=\"javascript:void(0)\" onclick=\"hide_box('"+ roomId +"','open','"+ username +"');\" class=\"text_normal\">"+ fullname +"</a> <img src=\"chat/onlineuser.gif\" id=\"type_"+ roomId +"\">\
					</div>\
					<a href=\"javascript:void(0)\" onclick=\"hide_box('"+ roomId +"','close','"+ username +"');\"><img src=\"chat/window_close.gif\" style=\"border:0px;\"></a>\
					</div>\
					</td>\
					</div>";

				}
				else { 
					new_row_box.innerHTML += "\
					<td>\
					<div id=\"box_"+ roomId +"\" style=\""+box_status+"\">\
					<div id=\"bottom_title\">\
					<div class=\"text_bottom\">\
					<a href=\"javascript:void(0)\" onclick=\"hide_box('"+ roomId +"','open','"+ username +"');\" class=\"text_normal\">"+ fullname +"</a> <img src=\"chat/onlineuser.gif\" id=\"type_"+ roomId +"\">\
					</div>\
					<a href=\"javascript:void(0)\" onclick=\"hide_box('"+ roomId +"','close','"+ username +"');\"><img src=\"chat/window_close.gif\" style=\"border:0px;\"></a>\
					</div>\
					</div>\
					</td>\n";
				}

			table=document.getElementById('header_chat');
			new_row=table.rows[0];
		
				if(document.all) { //IE
					new_row.insertCell().innerHTML="<div id=\"chat_"+ roomId +"\" style=\""+chat_status+"\">\
					<td>\
					<div id=\"chat\">\
					<div class=\"chat_username\">\
					<div style=\"float:right;width:50px;\"><a href=\"profile.php?userId="+roomId+"\"><img src=\""+pic+"\" style=\"width:45px;height:45px;padding: 3px 0px 0px 0px;\" title=\"לעמוד הפרופיל\"></a></div>\
					<div style=\"float:right;width:98px;\"><a href=\"profile.php?userId="+roomId+"\" style=\"color:#FFFFFF;text-decoration:none\">"+ fullname +"</a></div>\
					<a href=\"javascript:void(0)\" onclick=\"hide_box('"+ roomId +"','open','"+ username +"');\"><img src=\"chat/chat_min.gif\" style=\"border:0px;\"></a>\
					<a href=\"javascript:void(0)\" onclick=\"hide_box('"+ roomId +"','close','"+ username +"');\"><img src=\"chat/chat_close.gif\" style=\"border:0px;\"></a>\
					<div class=\"typemess\" style=\"display:none;\" id=\"typemess_"+ roomId +"\">"+ fullname +" מקליד...</div>\
					</div>\
					<div id=\"room_"+ roomId +"\" style=\"width:180px;height:180px;overflow-y:scroll;overflow-x:hidden;\"></div>\
					<div style=\"background:url(chat/line_input.gif) no-repeat;height:2px;width:100%;\"></div>\
					<div style=\"margin:0px;padding:3px;height:17px;\">\
					<input type=\"text\" class=\"text_input\" style=\"float:right;\" id=\"input_"+ roomId +"\" onsubmit=\"return false;\" onKeyPress=\"if(enter_pressed(event)){ type_message('"+roomId+"','"+ username +"',this.value,'2') } else { type_message('"+roomId+"','"+ username +"',this.value,'1') }\">\
					<img src=\"chat/chat_window.gif\"  style=\"float:right;border:0px;\">\
					</div>\
					</div>\
					</td>\
					</div>\n";

				}
				else { 
					new_row.innerHTML += "\
					<td id=\"chat_"+ roomId +"\" style=\""+chat_status+"\">\
					<div id=\"chat\">\
					<div class=\"chat_username\">\
					<div style=\"float:right;width:50px;\"><a href=\"profile.php?userId="+roomId+"\"><img src=\""+pic+"\" style=\"width:45px;height:45px;padding: 3px 0px 0px 0px;\"></a></div>\
					<div style=\"float:right;width:98px;\"><a href=\"profile.php?userId="+roomId+"\" style=\"color:#FFFFFF;text-decoration:none\">"+ fullname +"</a></div>\
					<a href=\"javascript:void(0)\" onclick=\"hide_box('"+ roomId +"','open','"+ username +"');\"><img src=\"chat/chat_min.gif\" style=\"border:0px;\"></a>\
					<a href=\"javascript:void(0)\" onclick=\"hide_box('"+ roomId +"','close','"+ username +"');\"><img src=\"chat/chat_close.gif\" style=\"border:0px;\"></a>\
					<div class=\"typemess\" style=\"display:none;\" id=\"typemess_"+ roomId +"\">"+ fullname +" מקליד...</div>\
					</div>\
					<div id=\"room_"+ roomId +"\" style=\"width:180px;height:180px;overflow-y:scroll;overflow-x:hidden;\"></div>\
					<div style=\"background:url(chat/line_input.gif) no-repeat;height:2px;width:100%;\"></div>\
					<div style=\"margin:0px;padding:3px;height:17px;\">\
					<input type=\"text\" class=\"text_input\" style=\"float:right;\" id=\"input_"+ roomId +"\" onsubmit=\"return false;\" onKeyPress=\"if(enter_pressed(event)){ type_message('"+roomId+"','"+ username +"',this.value,'2') } else { type_message('"+roomId+"','"+ username +"',this.value,'1') }\">\
					<img src=\"chat/chat_window.gif\"  style=\"float:right;border:0px;\">\
					</div>\
					</div>\
					</td>\n";
										
				}
			}
			
			if(roomId > 0){
				to = setTimeout("history("+roomId+")", 250);
			}
			
	}
	
	
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}



function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

