var ListeFiche;
var BaseImg="/images/skins/skin_01/images/";
var TimeEnd;
var ladate = new Date();
function ds_getleft(el) {
	var tmp = el.offsetLeft;
	el = el.offsetParent
	while(el) {
		tmp += el.offsetLeft;
		el = el.offsetParent;
	}
	return tmp;
}

function Init(){

	var Noeuds = new Array('fonction','lieu');
	var time = ladate.getMilliseconds();
	var myAjax = "";

	myAjax = new Ajax.Request(
      '/exports/xml_catalogue.asp?start=0&limit=3&sid=8f178a6e30300301946b19ac8c253c71&date='+time,
      {
        method: 'get',
        parameters: {},
        onSuccess: function (xhr)
          {
			ListeFiche = new Array();
			var xml = xhr.responseXML;
			var nodeExports=xml.getElementsByTagName('export')[0];
			var Fiches = nodeExports.getElementsByTagName('fiche');
			for(var i=0;i<Fiches.length;i++)
			{

				var Indice = ListeFiche.length;
				var Fiche = Fiches[i];
				var attributes = Fiche.attributes;
				ListeFiche[i] = new Array();
				for(var j=0;j<attributes.length;j++)
				{
					ListeFiche[Indice][attributes[j].name]= attributes[j].nodeValue;
				}
				for(var j=0;j<Noeuds.length;j++)
				{
					
					ListeFiche[Indice][Noeuds[j]] = typeof(Fiche.getElementsByTagName(Noeuds[j])[0].text)=="undefined"?Fiche.getElementsByTagName(Noeuds[j])[0].textContent:Fiche.getElementsByTagName(Noeuds[j])[0].text;
				}
			}

			buildIt();

		 },
		onFailure: function(xhr)
		{

			buildIt();
		}
      }
    );
};

function buildIt()
{
	var container = $('hp_news_box');
	
	container.innerHTML = "";
	
	for(var i=0;i<ListeFiche.length;i++)
	{


		var div = el("div",container);
		div.addClassName("hp_jobs");

		var divlink = el("div",div);
		divlink.addClassName("hp_jobs_txt");

		var a =el("a",divlink);
		a.href = "/index.asp?ID=386&IDF="+ListeFiche[i]['id'];
		a.innerHTML = ListeFiche[i]['fonction']+"<br/>"+ListeFiche[i]['lieu'];

	}
}


function getTime()
{
	return ladate.getTime();
}

function in_array(val,array)
{
	for(var i=0;i<array.length;i++)
		if(val==array[i])
			return true;
	return false;
}

function el(type,attach)
{
	var el = document.createElement(type);
	Element.extend(el);
	if(typeof(attach)!="undefined")
		attach.appendChild(el);
	return el;
}
setTimeout("Init()",200);
