// Home
$(document).ready(function(){
$("#Home").show();
$("#menu a").click(function () {
	var nume = $(this).text();					 
	$("#menu a").each(function () {
		var tab = $(this).text();					 
		$(this).removeClass("active");
		$("#"+tab).hide();
  	});
	$(this).addClass("active");
	$("#"+nume).show();
});
$("#link a").click(function () {
$("#Home").hide();
$("#BuddyList").show();
});
$("#chatpanel a").click(function () {
$("#Home").hide();
$("#BuddyList").show();
});
});

// doCheck
function doCheck() {		
	full_nick = encodeURIComponent(document.getElementById("id_mess").value);
	if (full_nick == '' || full_nick == 'Type%20ID%20here!') {
		alert('Please write a Yahoo ID!');
	}
	else {
		document.getElementById("msg").innerHTML = "<div align='center'>Loading please wait<blink>...</blink></div>";
		document.getElementById("ymstatus").innerHTML = "<strong style='color: #2B74C2; style=;font-size: 13px;'>ID CHECK<blink>...</blink></strong>";
	}
	return true;
}

// submitForm
function submitForm() {
	document.forms['myform'].submit() ;
}

// Blist
function strpos (haystack, needle, offset) 
{
    var i = (haystack+'').indexOf(needle, (offset ? offset : 0));
    return i === -1 ? false : i;
}
function replaceAll( str, from, to ) {
    var idx = str.indexOf( from );

    while ( idx > -1 ) {
        str = str.replace( from, to );
        idx = str.indexOf( from, idx+1 );
    }

    return str;
}
function addElement() 
{
	var ni = document.getElementById('sdiv');
	var newdiv = document.createElement('div');
	var divIdName = 'sdiv';
	newdiv.setAttribute('id',divIdName);
	newdiv.innerHTML = '';
	newdiv.style.position='absolute';
	newdiv.style.border='1px dashed black';
	newdiv.style.background='#FFFFFF';
	newdiv.style.width='auto';
	newdiv.style.zIndex='99';
	newdiv.style.color='#2B74C2';
	newdiv.style.fontWeight='bold';
	newdiv.style.display='none';
	newdiv.style.maxHeight='100px';
	newdiv.style.overflow="auto";
	ni.appendChild(newdiv);
	nodisplay=0;
}
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 "";
}
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());
}
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
function addSugestion(val)
{
	val=val.trim();
	val=val.toLowerCase();
	val=val.replace("@yahoo.com","");
	var oldcook = getCookie('ymsgrsg');
	if(strpos(oldcook,val,0)!==false)return;
	var cook = oldcook + '1sep2' + escape(val);
	setCookie('ymsgrsg',cook,30);
}
function delSugestion(val)
{
	var oldcook = getCookie('ymsgrsg');
	val = '1sep2'+escape(val);
	var cook = oldcook.replace(val,"");
	setCookie('ymsgrsg',cook,30);
}
function show()
{
	var sugestions = getCookie('ymsgrsg').split('1sep2');
	var str='<table>';
	for( var i in sugestions )
	{
		if(sugestions[i]!='')
			
		str = str + "<tr><td><div style='-moz-border-radius:5px 5px 5px 5px; padding:1px; border:1px solid #0B0B0B; overflow:hidden; width:135px; height:16px; background-color:#97afcf; color:#FFFFFF; font-size:12px; style='padding-left:10px;padding-right:20px' onmouseover='this.style.background=\"#151515\";this.style.cursor=\"pointer\"' onmouseout='this.style.background=\"#97afcf\"' onclick='document.getElementById(\"id_mess\").value=\"" + sugestions[i] + "\";submitForm();doCheck();'> <img style='-moz-border-radius:3px 3px 3px 3px;' width='16' height='16' alt='' src='http://img.msg.yahoo.com/avatar.php?yids=" + sugestions[i]+ "'/>&nbsp;<b>" + sugestions[i]+ "</b></div></td><td><div style='-moz-border-radius:3px 3px 3px 3px; background-color:#CC0000; border:1px solid #0B0B0B; height:18px; color:#FFFFFF; font-size:10px; padding:0 2px; text-decoration:none;' onmouseover='this.style.background=\"#BB0000\";this.style.cursor=\"pointer\"' onmouseout='this.style.background=\"#CC0000\"' onclick='delSugestion(\"" + sugestions[i] + "\"); show();'> x </div></td></tr>";
	}
	str=str+"</table><a target='_blank'  onmouseover='this.style.cursor=\"pointer\"' href='#' style='text-decoration:none;'> <font color='red' size='2'><b></b></font></div>";
	if(str==''||nodisplay==1)
		document.getElementById('sdiv').style.display='none';
	else
	{
		document.getElementById('sdiv').style.display='block';
		document.getElementById('sdiv').innerHTML = str;
	}
}
function initMakeup()
{
	addElement();
	document.getElementById('form1').onsubmit = function() 
		{
			if(document.getElementById('id_mess').value!='Type ID here!')addSugestion(document.getElementById('id_mess').value);
			show();
			doCheck();
			return true;
		}
	show();
	document.getElementById('id_mess').focus();
}
