function ChooseSearch(option,obiect)
{
	for(i=0;i<4;i++)
	{
		$('ss'+i).className='';
	}
	$('sitesearch').value=option;
	$('ss'+obiect).className='activ';
	//alert(obiect.className);
}
function MessageDelete1(id)
{
	if (Delete())
	{
		new Ajax.Request('/messages/del1/'+id, {
			 asynchronous: false
			 });
		new Effect.Fade("mess_"+id, {duration: 0.5});	 
	}	
	return false;	
}
function MessageDelete2(id)
{
	if (Delete())
	{
		new Ajax.Request('/messages/del2/'+id, {
			 asynchronous: false
			 });
		new Effect.Fade("mess_"+id, {duration: 0.5});	 
	}	
	return false;	
}
function MessageRead(id)
{
	new Ajax.Updater(
		'message_body', 
		'/messages/read/'+id, 
		{
			asynchronous:true, 
			evalScripts:true
		}
	);
	var a="mess_"+id;
	$(a).className ="tr_mess1";
}
function MessageReadSentItems(id)
{
	new Ajax.Updater(
		'message_body', 
		'/messages/sent_items_read/'+id, 
		{
			asynchronous:true, 
			evalScripts:true
		}
	);
}

var div_email=new Object();
div_email=document.createElement("div");
div_email.style.zIndex = '1000';	
div_email.style.backgroundColor = "transparent";  
div_email.style.position = "absolute";
div_email.style.border = "1px solid #8EBBE8";
div_email.style.backgroundColor='#FFFFFF';
function BoxEmail(address)
{
	ttop=0;
	if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		ttop=window.pageYOffset;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		ttop=document.documentElement.scrollTop;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
		ttop=document.body.scrollTop;
	}

	l = (myWidth-50)/2;
	t = (myHeight-10)/2+ttop ; 
	
	div_email.style.left = l+'px';
	div_email.style.top = t+'px';
	div_email.style.display = "block"; 
	document.body.appendChild(div_email);
	div_email.innerHTML='<table cellpadding="0" cellspacing="0" width="300"><tr bgcolor="#0066CC"><td align="left" style="padding-left:10px; color:#FFFFFF" height="20"><strong>Trimite prin email</strong></td><td align="right" style="padding-right:10px;" height="20"><a href="javascript:CloseEmailPop()" class="close">x Inchide</a></td></tr><td colspan="2" align="center" style="padding:10px;"><div id="send_email"></div></td></tr></table>';
	
	update('send_email',address);
}

function Recommend()
{
	new Ajax.Updater('body_recommend','/games/recommend', {
	 parameters: $('recommend').serialize(true), asynchronous: false
	 });
}

function SendEmail(address)
{
	new Ajax.Updater('send_email',address, {
	 parameters: $('sendemail').serialize(true), asynchronous: false
	 });
}

function Broken(obiect,status,id)
{
	update(obiect,'/brokens/add/'+status+'/'+id);
}
function Ym(adresa)
{
	window.location=encodeURI('ymsgr:im?msg='+ escape(adresa));
}

var nr_book=0;
function AddBookmark(url)
{
	if (loggedin==true)
	{
		nr_book=nr_book+1;	
		var	newItem='<a name="bookmarkadd_'+nr_book+'"></a><div id="bookmark_'+nr_book+'" style="display:none"></div>';
		new Insertion.Bottom("bookmarks_body", newItem);	
		new Ajax.Updater(
			'bookmark_' + nr_book, 
			'/bookmarks/add/'+url, 
			{
				asynchronous:true, 
				evalScripts:true,
				onComplete : function(resp) { 
					Effect.Appear("bookmark_" + nr_book, { duration: 0.5 }); 
					document.location.href="#bookmarkadd_"+nr_book; 
				}
			}
		);
	}else{
		alert("Trebuie sa fi logat");
	}
}
function DeleteBookmark(id)
{
	if (Delete())
	{
		new Ajax.Request('/bookmarks/del/'+id, {
			 asynchronous: false
			 });
		new Effect.Fade("Book_"+id, {duration: 0.5});	 
	}	
	return false;	 
}

//-- for IE6 but not IE7, Moz, Safari, Opera...
try {
document.execCommand('BackgroundImageCache', false, true);
} catch(e) { /* unless it's not IE6... */ }

function Delete()
{
	return confirm('Sunteti sigur ?')?true:false;
}

var yt_video_width=425;
var yt_video_height=350;

function EchoVideo(id) {
    var embaded_video= '<' + 'object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="' + yt_video_width + '" height="' + yt_video_height + '"><param name="movie" value="http://www.youtube.com/v/' + id + '"></param><' +'embed src="http://www.youtube.com/v/' + id + '" type="application/x-shockwave-flash" width="' + yt_video_width + '" height="' + yt_video_height + '"></embed></object>';
	document.write(embaded_video);
}

function showVideo(id) {
    document.getElementById('yt_the_video').innerHTML = '<' + 'object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="' + yt_video_width + '" height="' + yt_video_height + '"><param name="movie" value="http://www.youtube.com/v/' + id + '"></param><' +'embed src="http://www.youtube.com/v/' + id + '" type="application/x-shockwave-flash" width="' + yt_video_width + '" height="' + yt_video_height + '"></embed></object>';
}

var yt_the_video=new Object();
yt_the_video=document.createElement("div");



function CreatePop(id,titlu)
{
	ttop=0;
	if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		ttop=window.pageYOffset;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		ttop=document.documentElement.scrollTop;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
		ttop=document.body.scrollTop;
	}
	
	/*if (width>myWidth-60) { width=myWidth-60;}
	if (height>myHeight-60) { height=myHeight-60;}*/
	
	l = (myWidth-550)/2;
	t = (myHeight-450-50)/2+ttop ; 
	
	//alert(myWidth+'    '+myHeight);
	
	var firefox = (navigator.appName=="Netscape")?'true':'false';
	
	
	yt_the_video.innerHTML='<table cellpadding="0" cellspacing="0" width="550"><tr bgcolor="#0066CC"><td align="left" style="padding-left:10px; color:#FFFFFF" height="20"><strong>'+titlu+'</strong></td><td align="right" style="padding-right:10px;"  height="20"><a href="javascript:ClosePop()" class="close">x Inchide</a></td></tr><td colspan="2" align="center" height="450"><' + 'object width="' + yt_video_width + '" height="' + yt_video_height + '"><param name="movie" value="http://www.youtube.com/v/' + id + '"></param><' +'embed src="http://www.youtube.com/v/' + id + '" type="application/x-shockwave-flash" width="' + yt_video_width + '" height="' + yt_video_height + '"></embed></object></td></tr></table>';
	yt_the_video.style.zIndex = '1000';	
	yt_the_video.style.backgroundColor = "transparent";  
	yt_the_video.style.position = "absolute";
	yt_the_video.style.border = "1px solid #8EBBE8";
	yt_the_video.style.left = l+'px';
	yt_the_video.style.top = t+'px';
	yt_the_video.style.backgroundColor='#FFFFFF';
	yt_the_video.style.display = "block"; 
	/*if(firefox=='false')
		xx.style.filter="alpha(opacity=50)";
	else	
		xx.style.MozOpacity=.5;*/
		
	document.body.appendChild(yt_the_video);
	
} 
function CloseEmailPop()
{
	div_email.style.display = "none"; 
	div_email.innerHTML='';
}
function ClosePop()
{
	yt_the_video.style.display = "none"; 
	yt_the_video.innerHTML='';
}


function update(dest,source){
	new Ajax.Updater(
		dest, 
		source, 
		{
			asynchronous:true, 
			evalScripts:true,
			onCreate : startLoading(dest)
			//onComplete : stopLoading
		}
	);
}

function startLoading(dest){
	var el = document.getElementById(dest);
	el.innerHTML='Loading. Please wait...';
 	//new Insertion.Top(dest, 'Loading. Please wait...');
}

function stopLoading() {
	Element.hide('loading_box');
	loaded = true;
}

function AddTags(id , tag_value)
{

	var tid = 'tags' + id;
	var dtid = 'str_tags_' + id;
	
	var tags = $(tid).value;
	
	var tags_array = [];
	var new_tags_array = [];
	var new_array = [];
	
	tags.scan(/\w+/, function(match){ tags_array.push(match[0]); });
	tag_value.scan(/\w+/, function(match){ new_tags_array.push(match[0]); });
	
	//current_tags.inspect();
	new_tags_array.each(function(newitem) {
  		var inarray = false;
		if ( (newitem.toString().length>=3) )
		{
			tags_array.each(function(item) {
				if(item.toString() == newitem.toString()){
					inarray = true;
				}  
			})
			//alert(inarray);
			if(!inarray){
				//alert("Add: " + newitem);
				tags_array.push(newitem.stripTags());
			}
		}

	});
	
	var str_result = "";
	var str_result1="";
  	tags_array.each(function(item) {
		str_result = str_result + item + ",";
		str_result1 = str_result1 + item + ", ";
	});
	
	$(tid).value = str_result.substring(0, str_result.length - 1);
	$(dtid).update(str_result1.substring(0, str_result1.length - 2));
	//alert($(dtid).innerHTML);
	
	
}
function DeleteTags(id)
{
	var tid = 'tags' + id;
	var dtid = 'str_tags_' + id;
	$(tid).value = "";
	$(dtid).update("");
	//document.getElementById("tags").value='';
	//document.getElementById("str_tags").innerHTML='';
}

/* Create portlet commands */