function set_reclama() 
{ 
	setTimeout("reclama()", 10000); 
}
function reclama() 
{
	document.getElementById("ads").className = 'hide';
	document.getElementById("joc").className = '';
}

//----

function bookmarksite(title,url)
{
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)
	{
		window.external.AddFavorite(url, title);
	}
}

//---

function validare_cauta()
{
	var cuvant = document.getElementById("cuvant").value;	

	if(cuvant == "")
	{
		alert("Va rugam introduceti un cuvant pentru a putea efectua cautarea");
		
		return false;
	}
}

//---

function show_quick_list()
{
	$('#quick_list').show();
		
	//----------------------	
		
	var url_complet = 'quick_list.php';
			
	$.ajax({
	  url: url_complet,
	  cache: false,
	  success: function(html){
		$("#quick_list").html(html);
	  }
	});	
}

//---

function remove_quick_list()
{	
	 var zxcevt=window.event||arguments.callee.caller.arguments[0];
		 var obj=document.getElementById('quick_list');
	 if (zxcCkEventObj(zxcevt,obj))
	 {
		$('#quick_list').hide();	
	 }
}

//---

function remove_quick_list_c()
{	
	$('#quick_list').hide();	
}

//---

function adauga_in_quick_list(id_joc)
{
	var id_joc;
	
	//---
		
	var url_complet = 'functii_in_quick_list.php?status=adauga&id_joc=' + encodeURI(id_joc);
	
	$.ajax({
	  url: url_complet,
	  cache: false
	});	
	
	//---	
	
	$("#adauga_in_quick_list").fadeOut(300);
}

//---

function remove_din_quick_list(id_joc)
{
	var id_joc;
	
	var div_joc = '#div_' + id_joc;
	
	var url_complet = 'functii_in_quick_list.php?status=remove&id_joc=' + encodeURI(id_joc);
	
	$.ajax({
	  url: url_complet,
	  cache: false
	});	
		
	$(div_joc).fadeOut("slow");
}
	
	

//---

function zxcCkEventObj(zxce,zxcp)
{
	 if (!zxce) var zxce=window.event;
	 zxce.cancelBubble=true;
	 if (zxce.stopPropagation) zxce.stopPropagation();
	 if (zxce.target) zxceobj=zxce.target;
	 else if (zxce.srcElement) zxceobj=zxce.srcElement;
	 if (zxceobj.nodeType==3) zxceobj=zxceobj.parentNode;
	 var zxceobj=(zxce.relatedTarget)?zxce.relatedTarget:(zxce.type=='mouseout')?zxce.toElement:zxce.fromElement;
	 if (!zxceobj||zxceobj==zxcp) return false;
	 while (zxceobj.parentNode){
	  if (zxceobj==zxcp) return false;
	  zxceobj=zxceobj.parentNode;
	 }
	 return true;
}

//------------------------------------------------------------------------------------------------

var xmlHttp

function GetXmlHttpObject(){

var xmlHttp = null;

	try {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp = new XMLHttpRequest();
	  }
	catch (e) {
	  // Internet Explorer
	  try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e){
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	  
	return xmlHttp;

}

// Calculate the rating
function rate(rating,id,show5,showPerc,showVotes){

	xmlHttp = GetXmlHttpObject()
	
	if(xmlHttp == null){
		alert ("Your browser does not support AJAX!");
		return;
	  }

	xmlHttp.onreadystatechange = function(){
		
	var loader = document.getElementById('loading_'+id);
	var uldiv = document.getElementById('ul_'+id);
	
		if (xmlHttp.readyState == 4)
		{ 
			//loader.style.display = 'none';
			var res = xmlHttp.responseText;
			
			if(res == 'already_voted')
			{
				loader.style.display = 'block';
				loader.innerHTML = '<div class="voted_twice">Ai votat deja!</div>';
				
			} 
			else
			{
				
				loader.style.display = 'block';
				loader.innerHTML = '<div class="voted">Multumim pentru vot!</div>';

	document.getElementById('outOfFive_'+id).innerHTML=rating;

	
				if(show5 == true){
					var out = document.getElementById('outOfFive_'+id);
					var calculate = res/20;
					out.innerHTML = Math.round(calculate*100)/100; // 3.47;
					//out.innerHTML = Math.round((calculate*2),0)/2; // 3.5;
				} 
				
				if(showPerc == true){
					var perc = document.getElementById('percentage_'+id);
					//var newPerc = Math.round(Math.ceil(res/5))*5;
					var newPerc = res;
					perc.innerHTML = newPerc+'%';
				}
				
				else if(showPerc == false){
					var newPerc = res;
				}
				

					var votediv = document.getElementById('showvotes_'+id).firstChild.nodeValue;
					var splitted = votediv.split(' ');
					var newval = parseInt(splitted[0]) + 1;
					if(newval == 1){
						document.getElementById('showvotes_'+id).innerHTML = newval+' Vot';
						document.getElementById('outOfFive_'+id).innerHTML = rating;
					} else {
						document.getElementById('showvotes_'+id).innerHTML = newval+' Voturi';
					}


			
				
				var ulRater = document.getElementById('rater_'+id);
				ulRater.className = 'star-rating2';

				var all_li = ulRater.getElementsByTagName('li');

				
				
				if(navigator.appName == 'Microsoft Internet Explorer'){
					uldiv.style.setAttribute('width',(rating*20)+'%'); // IE
				 } else {
					uldiv.setAttribute('style','width:'+(rating*20)+'%'); // Everyone else
				 }
				
			}
		} else {
			loader.innerHTML = '<img src="img/stele/rating_loading.gif" alt="loading" />';	
		}
	
	}
	var url = "rating_process.php";
	var params = "id="+id+"&rating="+rating;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);

}

//-----------------------

$(document).ready(function()
{
	// Safely inject CSS3 and give the search results a shadow
	var cssObj = { 'box-shadow' : '#888 5px 10px 10px', // Added when CSS3 is standard
		'-webkit-box-shadow' : '#888 5px 10px 10px', // Safari
		'-moz-box-shadow' : '#888 5px 10px 10px'}; // Firefox 3.5+
	$("#suggestions").css(cssObj);
	
	// Fade out the suggestions box when not active
	 $("input").blur(function(){
	 	$('#suggestions').fadeOut();
	 });
});

function lookup(inputString) {
	if(inputString.length == 0) {
		$('#suggestions').fadeOut(); // Hide the suggestions box
	} else {
		$.post("rpc.php", {queryString: ""+inputString+""}, function(data) { // Do an AJAX call
			$('#suggestions').fadeIn(); // Show the suggestions box
			$('#suggestions').html(data); // Fill the suggestions box
		});
	}
}