// ====================================================
// (c) 2000 Concepto enr.
// 
// Déclaration des fonctions JavaScript globales à 
// l'application
//====================================================

// -------------------------------------------------
// Ouvre une fenêtre
// -------------------------------------------------

function gf_PopUpWindow(URL, WindowName, WindowWidth, WindowHeight) {
	PosX = Math.round(screen.availWidth / 2) - (WindowWidth / 2) 
	PosY = Math.round(screen.availHeight / 2) - (WindowHeight / 2) - 20
	
	popupwin = window.open(URL,WindowName,"scrollbars=yes,resizable=yes,directories=no,menubar=no,screenx=" + PosX + ",screeny=" + PosY + ",left=" + PosX + ",top=" + PosY + ",status=no,titlebar=yes,toolbar=no,height=" + WindowHeight + ",width=" + WindowWidth )
    popupwin.focus();
    return(popupwin);
	}
	

// -------------------------------------------------
// S'assure qu'un champ n'est pas vide
// -------------------------------------------------

function gf_CheckIfEmpty( sData, sDescription ) {
	if (sData.length < 1) {
		alert("Le champ «" + sDescription + "» est obligatoire.")
		return(false)
		}
	return(true)
	}

function gf_CheckIfNumeric( sData, sDescription ) {
	if (isNaN(sData)) {
		alert("Le champ «" + sDescription + "» doit être numérique.")
		return(false)
		}
	return(true)
	}

// -------------------------------------------------
// Ouvre les differentes popups d<edition
// -------------------------------------------------

function gf_UserForm( ID ) {
	gf_PopUpWindow( "users_e.asp?PK=" + ID, "UserForm", 600, 320 );
	}
function gf_CategorieForm( ID ) {
	gf_PopUpWindow( "categorie_e.asp?PK=" + ID, "CategorieForm", 615, 400 );
	}
function gf_TypeProduitForm( ID, CatId ) {
	gf_PopUpWindow( "TypeProduit_e.asp?PK=" + ID + "&CatId=" + CatId, "TypeProduitForm", 615, 350 );
	}
function gf_LogoForm( ID ) {
	gf_PopUpWindow( "Compagnie_e.asp?PK=" + ID, "CompagnieForm", 500, 400 );
	}
function gf_ProduitForm( ID ) {
	gf_PopUpWindow( "produit_e.asp?PK=" + ID, "ProduitForm", 600, 590 );
	}
function gf_LienForm( ID ) {
	gf_PopUpWindow( "Lien_e.asp?PK=" + ID, "LienForm", 600, 260 );
	}
	
function gf_NouvelleForm( ID ) {
	gf_PopUpWindow( "Nouvelle_e.asp?PK=" + ID, "NouvelleForm", 600, 460 );
	}
	
function gf_CouponsForm( ID ) {
	gf_PopUpWindow( "coupons_e.asp?PK=" + ID, "CouponsForm", 600, 460 );
	}
	
function gf_CouponsPrint() {
	var WindowWidth = 600;
	var WindowHeight = 400;
	
	PosX = Math.round(screen.availWidth / 2) - (WindowWidth / 2) 
	PosY = Math.round(screen.availHeight / 2) - (WindowHeight / 2) - 20
	
	popupwin = window.open("coupons_print.asp","CouponsPrintForm","scrollbars=yes,resizable=yes,directories=no,menubar=yes,screenx=" + PosX + ",screeny=" + PosY + ",left=" + PosX + ",top=" + PosY + ",status=no,titlebar=yes,toolbar=no,height=" + WindowHeight + ",width=" + WindowWidth )
    popupwin.focus();
	}

// -----------------------------------------------
// Function servant a afficher un tooltip
// -----------------------------------------------

function showtip(current,e,text)
{
   // Test pour savoir quel navigateur on utilise
   // Document.all n'est implenté que par Internet Explorer
   // Alors que document.layers n'est implenté que par Netscape
   if (document.all)
   {
      thetitle=text.split('<br>')
      if (thetitle.length > 1)
      {
        thetitles=""
        for (i=0; i<thetitle.length; i++)
           thetitles += thetitle[i] + "\r\n"
        current.title = thetitles
      }
      else current.title = text
   }

   else if (document.layers)
   {
       document.tooltip.document.write( 
           '<layer bgColor="#FFFFE7" style="border:1px ' +
           'solid black; font-size:12px;color:#000000;">' + text + '</layer>')
       document.tooltip.document.close()
       document.tooltip.left=e.pageX+5
       document.tooltip.top=e.pageY+5
       document.tooltip.visibility="show"
   }
}

function hidetip()
{
    if (document.layers)
        document.tooltip.visibility="hidden"
}

// -------------------------------------------------
// Ouvre une boite d'assitant de création de code HTML
// -------------------------------------------------

// -------------------------------------------------
// Ouvre une boite d'assitant de création de code HTML
// -------------------------------------------------

function gf_Id3HtmlEdit(FieldName) {

	var popupwin
	var PosX
	var PosY
	var WindowWidth
	var WindowHeight

	WindowWidth = 485
	WindowHeight = 315
	
	PosX = Math.round(screen.availWidth / 2) - (WindowWidth / 2) 
	PosY = Math.round(screen.availHeight / 2) - (WindowHeight / 2) - 20
	
	popupwin = window.open("./inc/Id3HtmlEdit/HtmlEditor.asp?FieldName="+FieldName,"ID3HtmlEdit","scrollbars=no,resizable=no,directories=no,menubar=no,screenx=" + PosX + ",screeny=" + PosY + ",left=" + PosX + ",top=" + PosY + ",status=no,titlebar=yes,toolbar=no,height=" + WindowHeight + ",width=" + WindowWidth )
    popupwin.focus();
}

	
// -------------------------------------------------
// Validation d'une date
// -------------------------------------------------
function gf_ValideDate ( FormObj,fieldName,Description )
	{
	var jour = 0
	var mois = 0
	var annee = 0
	var dateOK = false

	annee = parseInt( eval("FormObj." + fieldName + "Y.value") )
	mois = parseInt( eval("FormObj." + fieldName + "M.value") )
	jour = parseInt( eval("FormObj." + fieldName + "D.value") )

	dateOK = !( jour < 1 || jour > 32 || mois < 1 || mois > 12 ) &&
			 !( ( (annee % 4 == 0 && annee % 100 != 0 || annee % 400 == 0) && mois == 2 && jour > 29 ) ||
				( !(annee % 4 == 0 && annee % 100 != 0 || annee % 400 == 0) && mois == 2 && jour > 28 ) ) &&
			 !( ( mois==3 || mois==4 || mois==6 || mois==9 || mois==11 ) && jour > 30 ) &&
			 !( annee < 1900 ) &&
			 !( isNaN(annee) ) &&
			 !( isNaN(mois) ) &&
			 !( isNaN(jour) )

	if (!dateOK)
		{
		alert("Le format de date du champ «" + Description + "» est invalide.")
		return(false)
		}
	return(true)
	}
	
// -------------------------------------------------
// Fonctions utilisé par la librairie Concepto
// -------------------------------------------------
 
function CTOASP_DBSL_AddOption (SelectListObj, MaxLength) {
 var TmpText;
 
 if (SelectListObj.options.selectedIndex == (SelectListObj.options.length - 1)) {
  TmpText = prompt('','');
  if (TmpText == null || TmpText == "") {
   SelectListObj.options.selectedIndex = 0;
  }
  else {
   SelectListObj.options.length = SelectListObj.options.length + 1;
   SelectListObj.options[SelectListObj.options.length - 1].value = SelectListObj.options[SelectListObj.options.selectedIndex].value;
   SelectListObj.options[SelectListObj.options.length - 1].text = SelectListObj.options[SelectListObj.options.selectedIndex].text;
   if (MaxLength <= 0) {
    SelectListObj.options[SelectListObj.options.selectedIndex].value = TmpText;
    SelectListObj.options[SelectListObj.options.selectedIndex].text = TmpText;
   }
   else {
    SelectListObj.options[SelectListObj.options.selectedIndex].value = TmpText.substring(0, MaxLength);
    SelectListObj.options[SelectListObj.options.selectedIndex].text = TmpText.substring(0, MaxLength);
   }
  }
 }
}

// //////////////////////////////////////////////////////////////////
// Gère les Upload/Download
// //////////////////////////////////////////////////////////////////

// ------------------------------------
// Ouvre la fènetre de d'upload
// 
function gf_FileAdd(iNbData, sListe) {
		if (eval("document.forms[0].Fichier" + sListe + ".length") <= iNbData){
			gf_PopUpWindow( "./actionFile_fs.asp?DisplayPage=addFile.asp&ActionPage=addFile_process.asp&sListe=" + sListe, "AddFile", 400, 138 );
		}else{
			alert("Vous avez atteint le maximum de fichier prévu à télécharger (" + (eval("document.forms[0].Fichier" + sListe + ".length") - 1) + "/" + iNbData + ")")
		}
}

// -----------------------------------
// Ouvre la fenetre de delete
//
function gf_FileDelete(sListe) {
	var FilId = eval("document.forms[0].Fichier" + sListe + ".value")
	var OK = true
	if (FilId < 1) {
		alert("Vous devez sélectionner un fichier avant d'effectuer cette opération.")
		OK = false
	}
			
	if (OK) gf_PopUpWindow( "./actionFile_fs.asp?DisplayPage=deleteAnim.htm&ActionPage=actionFile.asp&Action=DELETE&FilId=" + FilId + "&sListe=" + sListe,"ActionFile", 400, 138);
}

// ----------------------------------
// Ouvre la fenetre de donwload
//
function gf_FileDownload(sListe) {
	var FilId = eval("document.forms[0].Fichier" + sListe + ".value;")
	var OK = true
	
	if (FilId < 1) {
		alert("Vous devez sélectionner un fichier avant d'effectuer cette opération.")
		OK = false
	}
	
	if (OK) gf_PopUpWindow( "./actionFile_fs.asp?DisplayPage=downloadAnim.htm&ActionPage=actionFile.asp&Action=DOWNLOAD&FilId=" + FilId + "&sListe=" + sListe,"ActionFile", 400, 138);
}

// -------------------------------------------------
// Supprime un fichier de la liste
// -------------------------------------------------
function lf_DeleteItemOfSL(oSelectList)
{
	var i = 0;
	var j = 0;

	for (i=0 ; i<oSelectList.length ; i++)
	{
		if ( !(oSelectList.options[i].selected))
		{
            oSelectList.options[j].value = oSelectList.options[i].value
			oSelectList.options[j].text = oSelectList.options[i].text
			j = j + 1
		}
	}

	Modif=true;
	oSelectList.length = j
}

// --------------------------------------------------
// Ajoute un fichier dans la liste
// --------------------------------------------------
function lf_AddFileValue(oHiddenList,sValue)
{
	if (oHiddenList.value != "")
	{
		oHiddenList.value = oHiddenList.value + "|"
	}
	
	oHiddenList.value = oHiddenList.value + sValue;
}

function lf_AddItemToSL(oSelectList,sValue,sText)
{
	var ExisteDeja = false;
	var i = 0;
	var j = 0;
	
	if (oSelectList.length > 0)
		if (oSelectList.options[0].value == "")
			oSelectList.length = 0

	for (i=0 ; i<oSelectList.length ; i++)
	{
		if (oSelectList.options[i].value == sValue)
		{
			ExisteDeja = true;
		}
	}
	
	if (!ExisteDeja)
	{
		Modif=true;
		oSelectList.length = oSelectList.length + 1
		if (oSelectList.length - 1 > 0)
		{
			oSelectList.options[oSelectList.length - 1].value = sValue;
			oSelectList.options[oSelectList.length - 1].text = sText;
		}
	}		
}

//----------------------------------------
// Changer l'ordre d'affichage des données
//----------------------------------------
function moveOrder( sOrdre, ID, sTable, sField, iCatId ) {
	document.MainForm.sTable.value = sTable;
	document.MainForm.sField.value = sField;
	document.MainForm.OrdreID.value = ID;
	document.MainForm.Ordre.value = sOrdre;
	document.MainForm.CatId.value = iCatId;
	document.MainForm.submit();
}

// -----------------------------------------------------------
// (c) 2001 ID-3 Technologies inc.
// ID: 1034 LMD: 2001-03-20
// -----------------------------------------------------------

function funIsValidURL (sText)
{
	if ( sText.indexOf("http://") == 0 || sText.indexOf("ftp://") == 0  )
	{
		return(true);
	}
	else
	{
		return(false);
	}	
}
