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('side-content');
	var newdiv = document.createElement('div');
	var divIdName = 'side-content';
	newdiv.setAttribute('id',divIdName);
	newdiv.innerHTML = '';
	newdiv.style.position='absolute';
	newdiv.style.border='1px dashed black';
	newdiv.style.background='#FFFFFF';
	newdiv.style.width='100px';
	newdiv.style.zIndex='99';
	newdiv.style.color='#6495ED';
	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());
}
function addSugestion(val)
{
	if(val.indexOf(' ') < 0)
	{
		val=val.replace(" ","");
		val=val.replace("%20","");
		var oldcook = getCookie('ymsgrsg');
		if(strpos(oldcook,val,0)!==false)return;
		var cook = oldcook + '1sep2' + escape(val);
		setCookie('ymsgrsg',cook,365);
	}
}
function delSugestion(val)
{
	var oldcook = getCookie('ymsgrsg');
	val = '1sep2'+escape(val);
	var cook = oldcook.replace(val,"");
	setCookie('ymsgrsg',cook,365);
	location.reload(true);
}
function clearall()
{
	setCookie('ymsgrsg',"",365);
	location.reload(true);
}
function show()
{
	document.getElementById('side-content').innerHTML ="";
	var sugestions = getCookie('ymsgrsg').split('1sep2');
	var str='<table>';
	for( var i=1;i<sugestions.length;i++ )
	{
		if(sugestions[i]!='')
			
				str = str + "<tr><td><div style='padding-left:10px;padding-right:20px' onmouseover='this.style.background=\"#66FFFF\";this.style.cursor=\"pointer\"' onmouseout='this.style.background=\"\"' onclick='document.getElementById(\"yid\").value=\"" + sugestions[i] + "\";check_all();'><b>" + sugestions[i]+ "</b></div></td><td><div onmouseover='this.style.background=\"#66FFFF\";this.style.cursor=\"pointer\"' onmouseout='this.style.background=\"\"' 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('side-content').style.display='none';
	else
	{
		document.getElementById('side-content').style.display='block';
		document.getElementById('side-content').innerHTML = str;
	}
	
}
function initMakeup()
{
	//alert("Hello, and sorry for this message, but we realy need your help to promote this website\nPlease tell about my website at least 2 friends.\nThis message will expire on: 28.03.2010 (And we are sorry for this message again)");
	addElement();
	document.getElementById('form1').setAttribute("autocomplete", "off");
	document.getElementById('form1').onsubmit = function() 
		{
			if(document.getElementById('yid').value!='Enter Yahoo ID')addSugestion(document.getElementById('yid').value);
			show();
			check_all();
			return false;
		}
	show();
	//document.getElementById('yid').focus();
	
}
