// Ce fichier contient les fonctions suivantes:
//   function CreeProduitGfa(region)
//   function GenerCondVol()
//   function GenerVolcan()
//   function hideshow(id, obj, text1, text2)
//   function MAJ_Zone(zone, langue)
//   function SauveRequete()
//   function show_hide(obj, show)


// Fonction utilisee dans les pages gfacn et gfacn-map pour la generation
// dynamique de la page suivante:  gfa.
function CreeProduitGfa(region)
   {
   document.CreeProduitGfa.Region.value=region;
   document.CreeProduitGfa.submit();
   }

// Fonction utilisee dans les pages forecast-observation(v) pour 
// l'appel au programme condvol.pl .
function GenerCondVol()
   {
   document.CreeProduit.Produit.value= "";
   document.CreeProduit.action = "/cgi-bin/convol.pl";
   document.CreeProduit.submit();
   }


// Fonction utilisee dans la page forecast-observationv (volcanique) pour 
// l'appel au programme vol.cgi.
function GenerVolcan()
   {
   document.CreeProduit.Produit.value= "";
   document.CreeProduit.action = "/cgi-bin/Fore-obs/vol.cgi";
   document.CreeProduit.submit();
   }
   
// Fonction utilisee dans la page forecast-observation pour 
// l'appel au programme vfr.cgi.
function GenerVfr()
   {
   document.CreeProduit.Produit.value= "";
   document.CreeProduit.action = "/cgi-bin/Fore-obs/vfr.cgi";
   document.CreeProduit.submit();
   }

// Fonction utilisee pour le bouton CND TURB FCST afin
// d'appeler le script qui determine si on affiche directement
// le produit ou encore si on affiche une page intermediaire.
//
function GenerCanTurbFcst()
   {
   document.CreeProduit.Produit.value= "CanTurbFcst"; 
   document.CreeProduit.action = "/cgi-bin/GenerCanTurbFcst.pl";
   document.CreeProduit.submit();
   }


// Hide or show an object - Used in briefings (volcanic ash)
// Function added by DEV25 - Environment Canada - CMDS - Dorval, Quebec 2006-04
// Params: id: Object id of element to show/hide
//    Obj: Element to alternate text value from text1 to text2 (optionals)
function hideshow(id, obj, text1, text2)
   {    
   var x;
   if ( document.getElementById )
      {
      x = document.getElementById(id);
      }
   else if ( document.all )
      {
      x = document.all[id];
      }
   else
      {
      return false;
      }
   if (x.style.display=="none")
      {
      x.style.display="block";
      if (obj && text1)
         {
         obj.value = text1;
         }
      }
   else
      {
      x.style.display="none";
      if (obj && text2)
         {
         obj.value = text2;
         }
      }
   return;
   }


// Fonction utilisee dans les pages "version graphique" des briefings
// afin d'afficher la region selectionnee dans une boite.
function MAJ_Zone(zone, langue)
{
document.Produit.Region.value = zone;
var valeur = "";     // Texte à afficher
if (zone == '31')
{
    if (langue == 'a')
       valeur = "Pacific (GFACN" + zone + ")";
	else if (langue == 'f')
	   valeur = "Pacifique (GFACN" + zone + ")";
}
else if (zone == '32')
{
	if (langue == 'a')
		valeur = "Prairies (GFACN" + zone + ")";
	else if (langue == 'f')
		valeur = "Prairies (GFACN" + zone + ")";
}		
else if (zone == '33')
{
	if (langue == 'a')
		valeur = "Ontario - Quebec (GFACN" + zone + ")";
	else if (langue == 'f')
		valeur = "Ontario - Québec (GFACN" + zone + ")";
}     
else if (zone == '34')
{
	if (langue == 'a')
		valeur = "Atlantic (GFACN" + zone + ")";  
	else if (langue == 'f')
		valeur = "Atlantique (GFACN" + zone + ")";   
}
else if (zone == '35')
{
	if (langue == 'a')
		valeur = "Yukon & NWT (GFACN" + zone + ")";
	else if (langue == 'f')
		valeur = "Yukon & TNO (GFACN" + zone + ")";
}
else if (zone == '36')
{
	if (langue == 'a')
		valeur = "Nunavut (GFACN" + zone + ")";
	else if (langue == 'f')
	    valeur = "Nunavut (GFACN" + zone + ")";
}
else if (zone == '37')
{
	if (langue == 'a')
		valeur = "Arctic (GFACN" + zone + ")";
	else if (langue == 'f')
		valeur = "Arctique (GFACN" + zone + ")";
}
document.Produit.Zone.value = valeur;
}


// Fonction associee au bouton "Save this request" 
// de la page de produit generee dynamiquement
function SauveRequete()
   {
   document.Produit.action = "/cgi-bin/saveRequest.cgi";
   document.Produit.submit();
   }


function show_hide(obj, show) {
   // Show or Hide an object - Used with NOTAM
   // Function added by DEV25 - Environment Canada - CMDS - Dorval, Quebec 2006-05
   // Params: obj: Object with information on action to take
   //    show: (optional) State of show (true) or hide(false). If empty, toggle state.
   var objLie, objType, browIE;
   browIE = (document.all && !window.opera && navigator.appName == "Microsoft Internet Explorer");
   if (! obj) return false; // No parameter - Do nothing
   if ( document.getElementById ) {
      objLie = document.getElementById(obj.getAttribute("objLie"));      
   } else if ( document.all ) {
      objLie = document.all[obj.getAttribute("objLie")];   
   } else {
      return false;
   }
   if (! objLie) return false; // No linked object - Do nothing
   // If "show" is specified, change the linked object to it, otherwise toggle state
   // Si parametre "show" non specifie, on prend l'etat du "checked" ou on inverse l'etat actuel
   if (!show && show != false) {
      if (obj.type == "checkbox" || obj.type == "radio") {
         show = obj.checked;
      } else {
         show = (objLie.style.display=="none");
      }
   }
   if (show) { // Show linked object
      // Evaluate liked object type: block, inline, table-row, ...
      switch (objLie.nodeName) {
      case "TR":
         objType = browIE ? "block" : "table-row"; break;
      case "SPAN":
         objType = "inline"; break;
      default:
         objType = "block"; break;
      }
      objLie.style.display=objType;
      eval(obj.getAttribute("action_show"));   // If linked action, execute it
      if (obj.getAttribute("text_show")) obj.value = obj.getAttribute("text_show");
   } else { // Hide linked object
      objType = "none";
      objLie.style.display=objType;
      eval(obj.getAttribute("action_hide"));   // If linked action, execute it
      if (obj.getAttribute("text_hide")) obj.value = obj.getAttribute("text_hide");
   }
   return true;
}

