﻿//
// Util.js : Util functions
//


/// <summary>
/// specify a default Button to submit when the user hits the enter key in a TextBox. 
/// Call this function in the keypress event of the TextArea.
/// Ex: onkeypress="return clickButton(event,'Button1');"
/// </summary>
/// <param name="TextArea">Reference to the TextArea control</param>
/// <param name="Button">Reference to the Button control</param>
function clickButton(e, buttonid)
{ 
      var evt = e ? e : window.event;
      var bt = document.getElementById(buttonid);
      if (bt){ 
          if (evt.keyCode == 13){
              bt.click();
              setHourglass();
                return false; 
          } 
      }
  }

  function setHourglass() {
      document.body.style.cursor = 'wait';
  }

  function openPopup(link, pTitle, pWidth, pHeight, pTop, pLeft) {
      eval("window.open('" + link + "','" + pTitle + "','height=" + pHeight + ",width=" + pWidth + ",scrollbars=no,resizable=no,status=no,left=" + pLeft + ",top=" + pTop + ",menubar=no,toolbar=no,location=no')");

  }

  function openPopupDuJour(laFile, pFolder, pImg, pTitle, pInfos, initDate, finalDate) {

      /* ---------- Prend la date actuelle ------------ */
      /*EXEMPLE: 
      laFile = no_file; l'information pImg contien une image
      laFile = file; l'information pImg contient un nom de fichier	 openPopupDuJour("no_file","assets/infocorp/NQE/images/","Avis-inventaire-FR.gif","Banni�re","toolbar=0,menubar=0,resizable=0,dependent=0,status=0,width=216,height=288",200802290900,200803031600)*/

      var currentTime = new Date();
      var year = currentTime.getFullYear();
      var month = currentTime.getMonth() + 1;

      if (month < 10) {
          month = "0" + month;
      }
      var day = currentTime.getDate();
      if (day < 10) {
          day = "0" + day;
      }
      var hours = currentTime.getHours();
      if (hours < 10) {
          hours = "0" + hours;
      }
      var minutes = currentTime.getMinutes();
      if (minutes < 10) {
          minutes = "0" + minutes;
      }

      var actualDate = year + "" + month + "" + day + "" + hours + "" + minutes;

      /* ---------- Fin de Prend la date actuelle ------------ */

      /*alert(initDate + " <: " + actualDate + "<: " + finalDate);*/

      if (initDate <= actualDate && finalDate > actualDate) {
          if (laFile == "no_file") {
              /* ---------- Créer la page html qui affiche l'image ------------ */
              var html = '<html><head><title>' + pTitle + '</title></head><body onBlur="top.close()" leftmargin=0 marginwidth=0 topmargin=0 marginheigth=0><img src="' + pFolder + '' + pImg + '" border="0" name="' + pTitle + '"></body></html>';
              /* ---------- Fin de Créer la page html qui affiche l'image ------------ */

              var OpenWindow = window.open("", '_blank', pInfos);
              OpenWindow.document.open();
              OpenWindow.document.write(html);
              OpenWindow.document.close();
          }
          else if (laFile == "file") {
              window.open(pImg, '_blank', pInfos);
          }
      }
  }

	function openManufacturer(pShow, nbTypeManufacturers)
	{	
		for(x=0;x<=nbTypeManufacturers;x++){eval("document.getElementById(['"+x+"']).style.display = 'none'");}
		if(pShow!='all') {
			document.getElementById([pShow]).style.display = "block";
		} else {
			for(x=0;x<=nbTypeManufacturers;x++){eval("document.getElementById(['"+x+"']).style.display = 'block'");}
		}
	}

// Galery of event javascript code
var imgWidth = 80;
var imgMarginRight = 5;
var affichePicture=1;
function img1()
{
	document.getElementById('img_group').style.width= nbPicture*(imgWidth+imgMarginRight) + "px";
	eval("document.getElementById('img_change').src='http://www.nedco.ca/promo/noe/events/gallery_"+num_dossier+"/01.jpg'");
}
function pictureNext() {
	affichePicture++;
	if(affichePicture>nbPicture){affichePicture=1;}	
	if(affichePicture <=9){affichePicture="0"+affichePicture;}
	eval("document.getElementById('img_change').src='http://www.nedco.ca/promo/noe/events/gallery_"+num_dossier+"/"+affichePicture+".jpg'");
}

function picturePrevious() {
	affichePicture--;
	if(affichePicture<=0){affichePicture=nbPicture;}
	if(affichePicture <=9){affichePicture="0"+affichePicture;}
	eval("document.getElementById('img_change').src='http://www.nedco.ca/promo/noe/events/gallery_"+num_dossier+"/"+affichePicture+".jpg'");
}
function pictureChange(requiredPicture)
{
	if(requiredPicture <=9){requiredPicture="0"+requiredPicture;}
	eval("document.getElementById('img_change').src='http://www.nedco.ca/promo/noe/events/gallery_"+num_dossier+"/"+requiredPicture+".jpg'");	
}