// JavaScript Document


function hm_load_actueduc()
{
	addCSS("http://files.meteofrance.com/files/education/actus/educnews.css");
	
	this.http=new majax();	
	this.elmid="hm_actu_educ";
	document.writeln("<div id='"+this.elmid+"' class='educnews'></div>");		
	
	this.elements=new Object();
	this.colcount=0;
	this.now=new Date();
	this.parseDate=function(st)
	{
		
		if (st==null) return null;
		try	
		{
			var stp=st.split("/");
			var dt=new Date();
			dt.setUTCHours(0,0,0,0);			
			dt.setUTCFullYear(parseInt(stp[2],10),parseInt(stp[1],10)-1,parseInt(stp[0],10));
			return dt;
		} catch (ex)
		{
			return null;
		}							 						 
	}
	if (hm_urlparse.params.actumkdate) 
	{
		this.now=this.parseDate(hm_urlparse.params.actumkdate);
	}

	
	this.checkPeriod=function(tx)
	{
		var ptxt=tx.split(",");
		
		var dt1=parseDate(ptxt[0]);
		if (dt1!=null)
		{
			if (dt1.valueOf()>this.now.valueOf()) return false;
		}
		var dt2=parseDate(ptxt[1]);
		if (dt2!=null)
		{
			if (dt2.valueOf()<=this.now.valueOf()) return false;
		}
		return true;
	}
	this.examfile=function(tx,xm)
	{
		try
		{
			
			var tmd=new mxml(xm);	
			var tmap=tmd.childrenByPath("educnews/element");
			
			for(var it=0;it<tmap.childLength();it++)
			{
				var velm=tmap.childByIndex(it);			
				
				var isok=false;
				var colonne=null;
				var pers=velm.childrenByPath("period");			
				for(var pt=0;pt<pers.childLength();pt++)
				{
					var txp=pers.childByIndex(pt);
					var tx=txp.textContent();
					if (checkPeriod(tx)) 
					{
						isok=true;
						var st=txp.attributesByName("colonne").attributesValues()[0];
						if (st!="")	colonne=parseInt(st);					
					}					
				}
				if (isok)
				{
					if (colonne==null)
					{
						colonne=1;
						while(elements[colonne]!=null) colonne++;						
					}
					elements[colonne]=velm;
				}
								
			}						
			
		} catch(ex)
		{
			cnt.innerHTML="Une erreur inattendue s'est produite ("+ex+").";			
			
		}
	}
	this.displayelms=function()
	{
		try
		{
			var im=document.createElement("DIV");
			im.innerHTML="<img src='/content/2011/4/25423-43.gif' width='120'/>";
			cnt.appendChild(im);

			var cdv=document.createElement("DIV");
			cdv.className="container";

			

			var nob=document.createElement("NOBR");
			
			for(var cl=1;cl<4;cl++)
			{
				var elm;
				if ((elm=elements[cl])!=null)
				{
					var eid=elm.attributesByName("id").attributesValues()[0];

					var blc=document.createElement("DIV");
					blc.className="actued_block";

					var curl="http://logp.xiti.com/go.click?xts=379559&s2=25&p=focus"+eid+"&clic=T&type=click&url="+elm.childrenByName("link").textContent();

					var dv1=document.createElement("A");
					dv1.className="actued_mlink";
					dv1.href=curl;

					
					var hct=document.createElement("DIV");
					hct.className="actued_content";
					
					var spn=document.createElement("DIV");					
					spn.style.textAlign="center";
					var ims=elm.childrenByName("image").childByIndex(0);


					var dvc=document.createElement("A");
					dvc.href=curl;
					
					var timg=document.createElement("IMG");
					timg.src=ims.attributesByName("src").attributesValues()[0];

					dvc.appendChild(timg);
					hct.appendChild(dvc);
					

					
					
					spn=document.createElement("H3");					
					var stt=elm.childrenByName("titre").innerXML();
					spn.innerHTML=stt;
					hct.appendChild(spn);

					spn=document.createElement("SPAN");					
					spn.innerHTML=elm.childrenByName("text").innerXML();					
					hct.appendChild(spn);

			
					
					dv1.appendChild(hct);
					
					blc.appendChild(dv1);
					nob.appendChild(blc);
				} else
				{
					var blc=document.createElement("DIV");
					blc.className="actued_block";
					
					var hct=document.createElement("DIV");
					hct.className="actued_content";

					blc.appendChild(hct);
					
					nob.appendChild(blc);
				}
				
			}
			cdv.appendChild(nob);
			cnt.appendChild(cdv);
		}
		catch(ex)
		{
			cnt.innerHTML="Une erreur inattendue s'est produite ("+ex+").";			
			
		}
	}
	
	this.build=function(tx,xm)
	{
		cnt=document.getElementById(elmid);	
		examfile(tx,xm);
		displayelms();
	}

	this.http.action=this.build;
	this.http.load("/content/2011/4/25412-211.xml",null);	
	
}

