var Heure;
var SequenceInfo=60;// 6*10s 
var TimerInfo;
var JourEmission=8,HeureEmission=50;
var indexInfo;
//var DateLille=new Date();
var TimerEmission=10;
var TimezoneOffset = 7200000;//3600000;  //  time zone de Lille =1 * 3600000(hiver 36 éte 72)

var maxInfo;

 /* a function that convert one char to its html code if needed */
 /* return a String */
 
 tableau= new Array(); /* tableau global */
//function genarray()
// {
 
/* tableau['"']= "&quot;" ;
 tableau["&"]= "&amp;" ;
 tableau["?"]= "&euro;" ;
 tableau["?"]= "&#129;" ;
 tableau[","]= "&#130;" ;
 tableau["f"]= "&#131;" ;
 tableau["\""]= "&#132;" ;
 tableau["."]= "&#133;" ;
 tableau["?"]= "&#134;" ;
 tableau["?"]= "&#135;" ;
 tableau["^"]= "&#136;" ;
 tableau["?"]= "&#137;" ;
 tableau["S"]= "&#138;" ;
 tableau["<"]= "&lt;" ;
 tableau["O"]= "&#140;" ;
 tableau["?"]= "&#141;" ;
 tableau["Z"]= "&#142;" ;
 tableau["?"]= "&#143;" ;
 tableau["?"]= "&#144;" ;
 tableau["'"]= "&#145;" ;
 tableau["'"]= "&#146;" ;
 tableau["\""]= "&#147;" ;
 tableau["\""]= "&#148;" ;
 tableau["."]= "&#149;" ;
 tableau["-"]= "&#150;" ;
 tableau["-"]= "&#151;" ;
 tableau["~"]= "&#152;" ;
 tableau["T"]= "&#153;" ;
 tableau["s"]= "&#154;" ;
 tableau[">"]= "&gt;" ;
 tableau["o"]= "&oelig;" ;
 tableau["?"]= "&#157;" ;
 tableau["z"]= "&#158;" ;
 tableau["Y"]= "&Yuml;" ;
 tableau["espace"]= "&nbsp;" ;
 tableau["¡"]= "&iexcl;" ;
 tableau["¢"]= "&cent;" ;
 tableau["£"]= "&pound;" ;
 tableau["¤"]= "&curren;" ;
 tableau["¥"]= "&yen" ;
 tableau["¦"]= "&brvbar;" ;
 tableau["§"]= "&sect;" ;
 tableau["¨"]= "&uml;" ;
 tableau["©"]= "&copy;   " ;
 tableau["ª"]= "&ordf;" ;
 tableau["«"]= "&laquo;" ;
 tableau["¬"]= "&not;" ;
 tableau["­"]= "&shy;" ;
 tableau["®"]= "&reg;" ;
 tableau["¯"]= "&masr;" ;
 tableau["°"]= "&deg;" ;
 tableau["±"]= "&plusmn;" ;
 tableau["²"]= "&sup2;" ;
 tableau["³"]= "&sup3;" ;
 tableau["´"]= "&acute;" ;
 tableau["µ"]= "&micro;" ;
 tableau["¶"]= "&para;" ;
 tableau["·"]= "&middot;" ;
 tableau["¸"]= "&cedil;" ;
 tableau["¹"]= "&sup1;" ;
 tableau["º"]= "&ordm;" ;
 tableau["»"]= "&raquo;" ;
 tableau["¼"]= "&frac14;" ;
 tableau["½"]= "&frac12;" ;
 tableau["¾"]= "&frac34;" ;
 tableau["¿"]= "&iquest;" ;
 tableau["À"]= "&Agrave;" ;
 tableau["Á"]= "&Aacute;" ;
 tableau["Â"]= "&Acirc;" ;
 tableau["Ã"]= "&Atilde;" ;
 tableau["Ä"]= "&Auml;" ;
 tableau["Å"]= "&Aring;" ;
 tableau["Æ"]= "&Aelig" ;
 tableau["Ç"]= "&Ccedil;" ;
 tableau["È"]= "&Egrave;" ;
 tableau["É"]= "&Eacute;" ;
 tableau["Ê"]= "&Ecirc;" ;
 tableau["Ë"]= "&Euml;" ;
 tableau["Ì"]= "&Igrave;" ;
 tableau["Í"]= "&Iacute;" ;
 tableau["Î"]= "&Icirc;" ;
 tableau["Ï"]= "&Iuml;" ;
 tableau["Ð"]= "&eth;" ;
 tableau["Ñ"]= "&Ntilde;" ;
 tableau["Ò"]= "&Ograve;" ;
 tableau["Ó"]= "&Oacute;" ;
 tableau["Ô"]= "&Ocirc;" ;
 tableau["Õ"]= "&Otilde;" ;
 tableau["Ö"]= "&Ouml;" ;
 tableau["×"]= "&times;" ;
 tableau["Ø"]= "&Oslash;" ;
 tableau["Ù"]= "&Ugrave;" ;
 tableau["Ú"]= "&Uacute;" ;
 tableau["Û"]= "&Ucirc;" ;
 tableau["Ü"]= "&Uuml;" ;
 tableau["Ý"]= "&Yacute;" ;
 tableau["Þ"]= "&thorn;" ;
 tableau["ß"]= "&szlig;" ;*/
 tableau["à"]= "&agrave;" ;
 tableau["á"]= "&aacute;" ;
 tableau["â"]= "&acirc;" ;
 tableau["ã"]= "&atilde;" ;
 tableau["ä"]= "&auml;" ;
 tableau["å"]= "&aring;" ;
 tableau["æ"]= "&aelig;" ;
 tableau["ç"]= "&ccedil;" ;
 tableau["è"]= "&egrave;" ;
 tableau["é"]= "&eacute;" ;
 tableau["ê"]= "&ecirc;" ;
 tableau["ë"]= "&euml;" ;
 tableau["ì"]= "&igrave;" ;
 tableau["í"]= "&iacute;" ;
 tableau["î"]= "&icirc;" ;
 tableau["ï"]= "&iuml;" ;
 tableau["ð"]= "&eth;" ;
 tableau["ñ"]= "&ntilde;" ;
 tableau["ò"]= "&ograve;" ;
 tableau["ó"]= "&oacute;" ;
 tableau["ô"]= "&ocirc;" ;
 tableau["õ"]= "&otilde;" ;
 tableau["ö"]= "&ouml;" ;
 tableau["÷"]= "&divide;" ;
 tableau["ø"]= "&oslash;" ;
 tableau["ù"]= "&ugrave;" ;
 tableau["ú"]= "&uacute;" ;
 tableau["û"]= "&ucirc;" ;
 tableau["ü"]= "&uuml;" ;
 tableau["ý"]= "&yacute;" ;
 tableau["þ"]= "&thorn;" ;
 tableau["ÿ"]= "&yuml;" ;
// }
 
function convert(text)
 {
 					var converted_text="";

 					for (i=0;i<text.length;i++)
 					{
 					 		if(tableau[text.charAt(i)]!=undefined)
 							{
 							 converted_text+=tableau[text.charAt(i)];
 							 }
 							 else{converted_text+=text.charAt(i);}
 					}
					
 return converted_text;
 
 }
 
function accentTOhtmlcode(character)
 {
 
 
 if(tableau[character]!=undefined)
 {
 return(tableau[text.value.charAt(i)]);
 }
 else {return(character);}
 
 }



function startTime()
{
  var localTime = new Date();
  var ms = localTime.getTime() 
             + (localTime.getTimezoneOffset() * 60000)
             + TimezoneOffset;

var today=new Date(ms);

var CurHour=today.getHours();
var CurMinute=today.getMinutes();
	Heure = CurHour*60+CurMinute;
	
	EmissionEnCours();

	t=setTimeout('startTime()',10000);  //toutes les 10s
	TimerInfo --;

}

function ConvertitTemps(ss)
{
    var s="";
        var h,m;
        j=0;i=0;
        while(j<ss.length)
        {
                c=ss.charAt(j);
                if(((c>='0')&&(c<='9')) || (c==':')) s=s+c;
                j++;
        };
    var p=s.indexOf(":");
        if((s[0]=='0') && (p==2))
            h=parseInt(s.substring(1,p));
        else
        h=parseInt(s.substring(0,p),10);
        m=parseInt(s.substring(p+1,s.length ),10);//.substring(0,p));
        return((h*60) + m);
}

function EmissionEnCours()
{
var r,n=0,ideb,ifin;
    var d = new Date();  //aujourd'hui
    r = d.getDay();
   //r=parent.Haut.D;	//le jour
	r -=1;
	if(r<0) r+= 7;

	while(Prog[r][n])
	{
        ideb= ConvertitTemps(Prog[r][n][1]);
        ifin=ConvertitTemps(Prog[r][n][2]);
				if((ifin<ideb)&&(Heure >= ideb))break;											 //dernière heure
		if((Heure >= ideb)&& (Heure < ifin)) break;
		else n++;
	};

	if((Prog[r][n]) && ((JourEmission != r) || (HeureEmission != n)))
    {
	 JourEmission = r;
	 HeureEmission = n;
        hde=Prog[r][n][6];
				
        if(hde==undefined)
		{ 
		    st="Un programme musical <br>(";
			hde=Prog[r][n][0];
			hde = convert(hde);
			//convert(s,hde);
			st = st + hde.substring(1,hde.length )+")";
		}
        else
        {
            hde=Prog[r][n][0];
						hde = convert(hde);
						//convert(s,hde);    
            if(hde!="") st = hde+ "<br>pr&eacute;sent&eacute; par<br> ";
            hde=Prog[r][n][3];
						hde = convert(hde);
						//convert(s,hde);    
            if(hde!="") st=st+hde+"<br>";
         }
		var sa;
        sa="<table width=\"100%\" cellspacing=\"0\" cellpadding=\"1\" border=\"0\">";
		sa = sa + "<tr valign=\"top\"><td width=\"102\">" + "<div style=\"font: 10px verdana, sans-serif; color: #000000;  padding: 3px;\">"+st + "</div></td></tr>";
		sa =sa + "<tr><td align=\"center\">";
        st=Prog[r][n][10];
				
        var ha=0;
        if((st=="") ||(st==undefined) ||(st.substring(0,7)=="Inconnu"))
		    sa = sa +"&nbsp;</td>";
        else
		{
		 	Photo = new Image();
            Photo.src = "/photos/" + st;
            sa =sa + "<img  height=\"120\" width=\"100\" src=\""+Photo.src+"\"></td>";
			ha=1;
		}
			
       // var obj1=document.getElementById("Infos").cbe;
		obj2=window.document.getElementById("Infos");
		
        obj2.innerHTML=sa;//
		//if(ha==1) obj2.style.height=180;
		//else obj2.style.height=60;
        //obj1.show();
    }
	
}
function Annonce(c) {
	
    if(c=='0') {indexInfo = indexInfo-1; if(indexInfo <0) indexInfo=maxInfo;}
	if(c=='1') {indexInfo =indexInfo+1; if(indexInfo > maxInfo) indexInfo=0;}
	if(!I[indexInfo]) indexInfo=0;
	document.getElementById('frmInfo').src= "Infos/"+ I[indexInfo];
	TimerInfo=SequenceInfo;

}

function windowOnload() {
	//compter les infos
	TimerInfo=0;
	startTime();
	//genarray();
}