//Planetmedia global function Version 2.2
//24-03-2011 last update

function search_addsessionVariables(elem)
{
	var xmlhttp=new ajaxRequest();
	xmlhttp.onreadystatechange=function(){
	 if (xmlhttp.readyState==4){
	  if (xmlhttp.status==200 || window.location.href.indexOf("http")==-1){	
		//alert(xmlhttp.responseText);
	  }
	  else{
	   alert("An error has occured making the request")
	  }
	 }
	}

	value=$("#"+elem+"").val();
	var params = "action=know_session&svalue="+value;
	xmlhttp.open("POST","ajax_calls.php",true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send(params);
}

function search_removesessionVariables()
{
	var xmlhttp=new ajaxRequest();
	xmlhttp.onreadystatechange=function(){
	 if (xmlhttp.readyState==4){
	  if (xmlhttp.status==200 || window.location.href.indexOf("http")==-1){	

	  }
	  else{
	   alert("An error has occured making the request")
	  }
	 }
	}

	var params = "action=know_session_clear";
	xmlhttp.open("POST","ajax_calls.php",true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send(params);
}

function search_setSearch(elem,container,per_page,rows,lang,sterm,page_cont,page,searchto,category,cat_sel)
{
	value=$("#"+elem+"").val();
	if(value!="")
	{
		knowledge_showResults(elem,container,per_page,rows,lang,sterm,page_cont,page,searchto,category,cat_sel)
	}
	
}
function search_setSearchCat(elem,container,per_page,rows,lang,sterm,page_cont,page,searchto,category,cat_sel)
{
	value=$("#"+elem+"").val();
	if(value!="")
	{
		knowledge_showResults(elem,container,per_page,rows,lang,sterm,page_cont,page,searchto,category,cat_sel)
	}
	
}

function fetch_newsResults(container,counter,more_plc,cat_id,mode)
{
	var xmlhttp=new ajaxRequest();
	xmlhttp.onreadystatechange=function(){
	 if (xmlhttp.readyState==4){
	  if (xmlhttp.status==200 || window.location.href.indexOf("http")==-1){
		news_line=xmlhttp.responseText.split(".%.");
		 for(i=1;i<news_line.length-1;i++)
		 {
			html="";
			term=news_line[i].split("_|_");
			html=html+'<div style="margin: 10px; padding: 12px; ">';
			html=html+'<div class="newscontainer">';
			html=html+'<div style="float:left; margin-right:13px; width:130px;">';
			html=html+'<img src="/page-thumbs/news/'+parseInt(term[0])+'.'+term[3]+'" alt="'+term[1]+'" title="'+term[1]+'" style="width:130px; border:1px #444444 dashed;" />';
			html=html+'</div>';	
			html=html+'<div style="width:450px; float:left;">';	
			html=html+'<h3 style="margin:-2px 0px 5px 0px; padding:0px;">';	
			if(mode=="news")
			{
				html=html+'<a href="news.php?id='+parseInt(term[0])+'" class="newstitle">'+term[1]+'</a>';	
			}
			else
			{
				html=html+'<a href="articles.php?id='+parseInt(term[0])+'" class="newstitle">'+term[1]+'</a>';	
			}
			
			html=html+'</h3>';	
			html=html+term[2];				
			html=html+'<br />';	
			if(mode=="news")
			{
				html=html+'<a href="news.php?id='+parseInt(term[0])+'" style="font-size:9px;">περισσότερα &gt;&gt;</a>';
			}
			else
			{
				html=html+'<a href="articles.php?id='+parseInt(term[0])+'" style="font-size:9px;">περισσότερα &gt;&gt;</a>';
			}
			
			html=html+'</div>';		
			html=html+'</div>';	
			html=html+'</div>';	
			$("#"+container+"").append(html);
		}
		html="";
		if(news_line[0]>5)
		{	
			$("#"+more_plc+"").remove();
			value=parseInt(value)+parseInt(news_line[0]);
			html=html+'<div id="cnews_bottom_'+cat+'">';
			html=html+'<input type="text" id="news_count_'+cat+'" value="'+value+'" style="visibility:hidden;"/>';
			html=html+'<a style="cursor:pointer;" id="mcat_'+cat+'">Περισσότερα Αποτελέμσατα</a>';	
			html=html+'</div>';
			$("#"+container+"").append(html);
			document.getElementById(cat_id).setAttribute("onClick","fetch_newsResults('"+container+"','"+counter+"','"+more_plc+"','"+cat_id+"',"+mode+");");
		}
		else
		{
			$("#"+more_plc+"").html("");
		}
	  }
	  else{
	   alert("An error has occured making the request")
	  }
	 }
	}
	value=$("#"+counter+"").val();
	id=$("#"+cat_id+"").attr("id");
	id=id.split("_");
	cat=id[1];
	//alert(cat);
	var params = "action=news_search&limit="+encodeURIComponent(value)+"&cat="+cat;
	xmlhttp.open("POST","ajax_calls.php",true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	xmlhttp.send(params);	
	
	
}

