/***********************************
Natacha Mercure (natacha_mercure@radio-canada.ca)
Grille horaire
1er février 2005
Modifications : 4 avril 2005
Modifications : 11 avril 2005
Modifications : 22 février 2006
************************************/
function GH_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.GH_pgW=innerWidth; document.GH_pgH=innerHeight; onresize=GH_reloadPage; }}
  else if (innerWidth!=document.GH_pgW || innerHeight!=document.GH_pgH) location.reload();
}
GH_reloadPage(true);

function GH_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function GH_showHideLayers() { //v6.0
  var i,p,v,obj,args=GH_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=GH_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function GH_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function GH_swapImage() { //v3.0
  var i,j=0,x,a=GH_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=GH_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

 function ghFermerFenetre(){
 	 GH_showHideLayers('ghMesEmissions','','hide');
 }
 
 function ghOuvrirFenetre(){
 	 GH_showHideLayers('ghMesEmissions','','show');
 }
  /*
 Lorsque l'usager a cliqué sur "Mes émissions", puis sur
 "Effacer" afin de retirer des émissions de sa liste
 */
 function ghEffacerEmission(){
	 var vGhForm;
	 var ghOk;
	 ghOk = true
	 vGhForm = document.ghFormulaire;
		 //S'il y a plus d'une émission dans la liste
		 if ( vGhForm.ghRetireEmission.length ){
			 //Remettre le champ des préférences d'émission vide
			 vGhForm.ghPreference.value = "";
			 for( var ghI = 0; ghI < vGhForm.ghRetireEmission.length; ghI++ ){
				 if ( vGhForm.ghRetireEmission[ghI].checked ){
					 /*S'assurer que l'usager a compris qu'il fallait
					 cocher des émissions pour pouvoir les effacer...
					 Sinon, un message d'alerte le lui rappelera*/
					 ghOk = false;
				 }else{
					 if ( vGhForm.ghPreference.value == "" ){
						 vGhForm.ghPreference.value = vGhForm.ghRetireEmission[ghI].value;
					 }else{
						 vGhForm.ghPreference.value = vGhForm.ghPreference.value + "," + vGhForm.ghRetireEmission[ghI].value;
					 }
				 }
			 }
				if ( vGhForm.ghPreference.value == "" ){
					vGhForm.ghPreference.value = "vide";
				}
				if ( ghOk ){
					alert("Vous devez cocher la case située à côté du titre de l'émission pour la retirer de votre liste.");
				}
				vGhForm.submit();
		 }
		 //S'il y a seulement une émission dans la liste
		 else{
			if ( vGhForm.ghRetireEmission.checked ){
				 vGhForm.ghPreference.value = "vide";
				 vGhForm.submit();
			}else{
				alert("Vous devez cocher la case située à côté du titre de l'émission pour la retirer de votre liste.");
			}
		 }	 
 }
 /*
 Lorsque l'usager a cliqué sur un pictogramme pour ajouter
 une émission à sa liste de préférences
 */
 function ghVersAjoutEmission(ghIdEmisison){
	 //Récupération du paramètre correspondant au numéro de l'émission à
	 //ajouter
	 var vGhIdEmission = ghIdEmisison;
	 //Formulaire
	 var vGhForm;
	 vGhForm = document.ghFormulaire;
		 if (vGhForm.ghPreference.value == "" ){
		 	vGhForm.ghPreference.value = vGhIdEmission;
		 }else{
		 	 vGhForm.ghPreference.value = vGhForm.ghPreference.value + "," + vGhIdEmission;
		 }
	 vGhForm.submit();
 }
 
/************************************/
/*
Lorsque l'usager a choisi un genre et/ou une région, la grille horaire
doit être refaite avec les critères choisis
De plus, si l'usager a choisi d'enregister ses préférences de genre et de région,
celles-ci doivent être enregistrées
*/

function ghVersFiltres(ghDeQui){
	//Les variables sont toujours appelées :
	//v[variable] + Gh[guide horaire] + nom de l'élément
	var vGhForm;
	//Formulaire
	vGhForm = document.ghFormulaire;
	var vGhGenre, vGhRegions, vGhPrefs
	//Quel genre a été sélectionné?
	vGhGenre = vGhForm.ghGenres.options[vGhForm.ghGenres.selectedIndex].value;
	//Quelle région a été sélectionnée? --> Suppression
	//vGhRegions = vGhForm.ghRegions.options[vGhForm.ghRegions.selectedIndex].value;
	//vGhForm.ghTitreRegion.value = vGhForm.ghRegions.options[vGhForm.ghRegions.selectedIndex].text;
	//Remettre la période à journée s'il s'agit d'un flitre genre
	//1 = région; 2 = genre
	if ( ghDeQui == 2 ){
		vGhForm.ghPeriode.value = "journee";
	}
	vGhForm.submit();
}

function ghVersFiltresJeunesse(ghDeQui){
	//Les variables sont toujours appelées :
	//v[variable] + Gh[guide horaire] + nom de l'élément
	var vGhForm;
	//Formulaire
	vGhForm = document.ghFormulaire;
	var vGhGenre, vGhRegions, vGhPrefs
	//Quel genre a été sélectionné?
	//vGhGenre = vGhForm.ghGenres.options[vGhForm.ghGenres.selectedIndex].value;
	//Quelle région a été sélectionnée?
	vGhRegions = vGhForm.ghRegions.options[vGhForm.ghRegions.selectedIndex].value;
	vGhForm.ghTitreRegion.value = vGhForm.ghRegions.options[vGhForm.ghRegions.selectedIndex].text;
	//Remettre la période à journée s'il s'agit d'un flitre genre
	//1 = région; 2 = genre
	if ( ghDeQui == 2 ){
		vGhForm.ghPeriode.value = "journee";
	}
	vGhForm.submit();
}

/*
Lorsque l'usager a choisi un jour de la semaine, voire la semaine complète,
la grille horaire doit être réaffichée avec la date choisie
### Attention! ###
Si des filtres ont été sélectionnés, il faut les garder!
*/
function ghVersDate(vGhDate, vGhDate2){
	var vGhForm;
	//Formulaire
	vGhForm = document.ghFormulaire;
	vGhForm.ghDate.value = vGhDate;
	vGhForm.ghDate2.value = vGhDate2;
	vGhForm.action = "ghHoraires.asp";
//	vGhForm.action = "guide_horaire.asp";
	vGhForm.submit();
	
}

/*
Lorsque l'usager a choisi une période de la journée,
la grille horaire doit être réaffichée avec la période choisie
### Attention! ###
Si des filtres ont été sélectionnés, il faut les garder!
*/
function ghVersPeriode(vGhPeriode){
	var vGhForm;
	//Formulaire
	vGhForm = document.ghFormulaire;
	vGhForm.ghPeriode.value = vGhPeriode;
	vGhForm.action = "ghHoraires.asp";
	vGhForm.submit();
}

/*
Lorsque l'usager a choisi une recherche par mots-clés
*/
function ghRecherche() {
    var vGhForm;
	//Formulaire
	vGhForm = document.ghFormulaire;
	vGhQuery = vGhForm.ghRechercheBox.value;
	vGhRegion = FindRegionAttribut(oProfile.radioregionid, "diohrid"); //vGhForm.ghRegions.options[vGhForm.ghRegions.selectedIndex].value;
	vGhIDChaine = vGhForm.ghChaine.value;
	
	if ( vGhQuery != "" ){
	    location.href = "ghResultats.asp?query=" + vGhQuery + "&idChaine=" + vGhIDChaine+"&idRegion="+vGhRegion;
	}else{
		alert("Merci de saisir un mot-clé dans le champ approprié.");
		vGhForm.ghRechercheBox.focus();
	}
}

