var articles_temporary=new Object;
function putValue(sel,to) {
	var opts=sel.getElementsByTagName('option');
	for (i=0;i<opts.length;i++)
	    {
	    if (sel.value==opts[i].value)
		   {
		   document.getElementById(to).innerHTML=opts[i].innerHTML;
		   }
	    }
	}
function addImage(id) {
	var newdiv=document.createElement('div');
	document.getElementById(id).appendChild(newdiv);
	newdiv.innerHTML="<input type='file' name='image[]' onchange=\"addImage('images_holder');\">";
	}
function addVideo(id) {
	var newdiv=document.createElement('div');
	document.getElementById(id).appendChild(newdiv);
	newdiv.innerHTML="<p style=\"display:inline-block; margin-right:15px;\"><input class=\"text-input large-input\" type=\"text\" id=\"large-input\" name=\"video_desc[]\" /></p><p style=\"display:inline-block\"><input type=\"file\" name=\"video[]\" /></p><p style=\"display:inline-block\">"+(document.getElementById('remote_videos').innerHTML)+"</p><p style=\"display:inline-block\"><input type=\"file\" name=\"video_thumb[]\" /></p>";
	}
function playVideo(id,so) {
	so.addVariable('data','xml/data_article.php?id='+id);
    so.write("flash");
	}
function ucfirst(str) {
    var f = str.charAt(0).toUpperCase();
    return f + str.substr(1);
}
function ajaxFunction(id,id2,img)
        {
        var xmlHttp;
        try
          {
          xmlHttp=new XMLHttpRequest();
          }
        catch (e)
          {
          try
            {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }
          catch (e)
            {
            try
              {
              xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
              }
            catch (e)
              {
              alert("Your browser does not support AJAX!");
              return false;
              }
            }
          }
          xmlHttp.onreadystatechange=function()
            {
            if(xmlHttp.readyState==4)
              {
              img.parentNode.removeChild(img);
              }
            }
          xmlHttp.open("GET","articles.php?remove_img="+id+"&id="+id2,true);
          xmlHttp.send(null);
          }
function putHoroscope(sign)
        {
        var xmlHttp;
        try
          {
          xmlHttp=new XMLHttpRequest();
          }
        catch (e)
          {
          try
            {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }
          catch (e)
            {
            try
              {
              xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
              }
            catch (e)
              {
              alert("Your browser does not support AJAX!");
              return false;
              }
            }
          }
          xmlHttp.onreadystatechange=function()
            {
            if(xmlHttp.readyState==4)
              {
			  response=xmlHttp.responseText.split('||');
              document.getElementById('horoscope').innerHTML=response[0];
              document.getElementById('shadowHoroscope').innerHTML="<div style='width:100%; min-height:100%; background-color:#FFF; color:#474747;'><div style='padding:5px; text-align:justify;'>"+response[1]+"</div></div>";
              document.getElementById('horoscope_sign').src='images/'+sign.toLowerCase()+'.png';
              document.getElementById('more_info_link').setAttribute('title',sign);
              }
            }
          xmlHttp.open("GET","library/ajax_actions.php?get_horoscope="+sign,true);
          xmlHttp.send(null);
          }
function setContent(id,aid,color)
        {
	    if (articles_temporary[aid]!==undefined)
		   {
		   document.getElementById(id).innerHTML=articles_temporary[aid];
		   }
		else
		   {
			var xmlHttp;
			try
			  {
			  xmlHttp=new XMLHttpRequest();
			  }
			catch (e)
			  {
			  try
				{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
				}
			  catch (e)
				{
				try
				  {
				  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				  }
				catch (e)
				  {
				  alert("Your browser does not support AJAX!");
				  return false;
				  }
				}
			  }
			  xmlHttp.onreadystatechange=function()
				{
				if(xmlHttp.readyState==4)
				  {
				  document.getElementById(id).innerHTML=xmlHttp.responseText;
				  articles_temporary[aid]=xmlHttp.responseText;
				  }
				}
			  xmlHttp.open("GET","library/ajax_actions.php?get_content="+aid+"&color="+color,true);
			  xmlHttp.send(null);
		   }
        }
function putWeather(city,root)
        {
        var xmlHttp;
        try
          {
          xmlHttp=new XMLHttpRequest();
          }
        catch (e)
          {
          try
            {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }
          catch (e)
            {
            try
              {
              xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
              }
            catch (e)
              {
              alert("Your browser does not support AJAX!");
              return false;
              }
            }
          }
          xmlHttp.onreadystatechange=function()
            {
            if(xmlHttp.readyState==4)
              {
			  var resp=xmlHttp.responseText.split('||');
              document.getElementById('temp').innerHTML=resp[0];
              document.getElementById('temp_city').innerHTML=ucfirst(city);
              document.getElementById('temp_img').src=root+'library/showImage.php?filename=../images/weather/'+resp[1]+'&crop=true&w=40&h=40&crop_from=left';
              document.getElementById('temp_span1').innerHTML="<strong>V&#226;nt</strong>: "+resp[2]+"<br /><strong>Umiditate</strong>: "+resp[3]+"<br />";
              document.getElementById('temp_span2').innerHTML="<strong>Vizibilitate</strong>: "+resp[4]+"<br /><strong>Presiune</strong>: "+resp[5]+"<br />";
              }
            }
          xmlHttp.open("GET","library/ajax_actions.php?get_weather="+city+'&root='+root,true);
          xmlHttp.send(null);
          }
function openHoroscope(clicked_link) {
	Shadowbox.open({content:document.getElementById('shadowHoroscope').innerHTML,player:'html',title:clicked_link.title,height:250,width:350});
	return false;
	}
function countClick(id)
        {
        var xmlHttp;
        try
          {
          xmlHttp=new XMLHttpRequest();
          }
        catch (e)
          {
          try
            {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }
          catch (e)
            {
            try
              {
              xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
              }
            catch (e)
              {
              alert("Your browser does not support AJAX!");
              return false;
              }
            }
          }
          xmlHttp.onreadystatechange=function()
            {
            if(xmlHttp.readyState==4)
              {
			  return true;
              }
            }
          xmlHttp.open("GET","library/ajax_actions.php?count_click="+id,true);
          xmlHttp.send(null);
          }
function toogleCh(bool,aid) {
	if (bool.checked) {
	    $.ajax({type: "POST", url: "/library/ajax_actions.php", data: "action=toogleCh&value=1&aid="+aid, success: function(html){ eval('response='+html); if (response.error) {alert(response.error); bool.checked=false;} } });
		}
	else {
	    $.ajax({type: "POST", url: "/library/ajax_actions.php", data: "action=toogleCh&value=0&aid="+aid, success: function(html){ eval('response='+html); if (response.error) {alert(response.error); bool.checked=false;} } });
		}
	}
function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";}
function doMove(cat) {
	var articles='';
	var i=0;
	$('.articles_checked').each(function(){
		if ($(this).is(':checked')) {
			if (i!=0)articles+=', ';
			articles+=$(this).val();
			i++;
			}
		});
	$.ajax({
			url: '/admin/articles.php',
			dataType: 'json',
			type: 'POST',
			data: {cid:cat,articles:articles,action:'update_articles'},
			success: function(data, textStatus, XMLHttpRequest) {
				if (data.valid) {
					window.location="/admin/articles.php?cid="+cat;
					}
				else {
					}
				},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				}
			});
	}
