/*
'---
'--- JSFonctions.js - Page de fonction en Javascript
'---
'--- Par JP Bernard
'---     CIBLE Solutions d'affaires
'---
'--- RÉVISION
 -- 2009/05/05 JPB-    Création
*/

//-------------------------------------------------------------------------------------
// Message d'avertissement temporaire
//-------------------------------------------------------------------------------------
function DoPupDeveloppement()
{
    alert("IMPORTANT!!!\nCette section du site Internet est présentement en développement.\nElle sera fonctionnelle dans le plus bref délai. Merci!\n\nJean-Philip Bernard\nProgrammeur Analyste\jean-philip.bernard@ciblesolutions.com");    		
}

//-------------------------------------------------------------------------------------
//trouve la référence pour l'objet document
//-------------------------------------------------------------------------------------
function GetReference(id)
{
	if(document.layers) return document.layers[id];
	if(document.all && !document.getElementById) return document.all[id];
	if(document.all && document.getElementById) return document.getElementById(id);
	if(!document.all && document.getElementById) return document.getElementById(id);
	return false;
}


//---------------------------------------------------------------------
//Ouvrir une fenêtre
//---------------------------------------------------------------------
function OuvrirFenetre(iNomPage, iTitre, iWidth, iHeight)
{
	fenetre = window.open(iNomPage, iTitre, "top=0, left=0, width=" + iWidth + ", height=" + iHeight + ", scrollbars=yes, location=no, toolbar=no, menubar=no");
	fenetre.focus()
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* OuvrirConfidentialite() - Ouvre la page pour les politiques de confidentialité
*/
function OuvrirConfidentialite()
{         
   OuvrirFenetre("", "CONFIDENTIALITE", 630, 580);
   FormConfidentialite.submit();
}


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* DoInsertCodeHTML() - Insère le code HTML créé dans l'éditeur
*/
function DoInsertCodeHTML(iControlName, iContenu)
{  
   // alert("oui");
    
   // alert(iControlName);
   // alert(iContenu);
    
	if(iControlName!='')
    {
        var ObjName=GetReference(iControlName);

		ObjName.value = iContenu;
    }
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* OuvrirEditeurHTML() - Ouvre l'éditeur HTML
*/
function OuvrirEditeurHTML(iControlName)
{
    var ObjName = GetReference(iControlName);
    var ObjTexte = GetReference("TexteContenu");
    var ObjCtrl = GetReference("Ctrl");
    
    ObjTexte.value = ObjName.value;
    ObjCtrl.value = iControlName;
    
    if(iControlName!='')
    {
	   OuvrirFenetre("", "EditeurTexte", 800, 600);
       document.EditeurHTML.submit();
    }
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * RemoveLineBreakJS() - Retourne la string sans les sauts de lignes ("\n" ou "\r\n")
 *
 *
 * Paramètres:
 *   iString - La chaine de caratère (type: String)
 *
 */
function RemoveLineBreakJS(iString)
{
    iString.replace("\r\n", "");
    iString.replace("\n", "");
    
    return iString;
}


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * JAVA_FormatStr() - Remplace les apostrophes (') par l'équivalent UNICODE \u0027
 *                 et les guillemets (") par l'équivalent UNICODE \u0022 pour
 *                 les fonctions JavaScript.
 */
function JAVA_FormatStr(iString)
{
    alert(iString);
    var chaine = new String(iString);

    remplace  = new RegExp("\'","g"),
    chaine = chaine.replace(remplace, "&#39;");

    remplace  = new RegExp('\"',"g"),
    chaine = chaine.replace(remplace, '&#39;');

    return chaine;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* ImprimerPage() - Lance l'impression de la fenêtre en cours
*/
function ImprimerPage(iLangue)
{       
    if (navigator.appVersion.indexOf("Mac",0)>0)
    {
        if (iLangue=="en")
            alert("This function is not available for Macintosh. Please use Apple-P.");
        else
            alert("Cette fonction n\'est pas réalisable sur Macintosh.\n\nUtilisez plutôt la combinaison de touches  « Pomme-P »");
    }
    else
    {
        window.print();
    }
}


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* OuvrirPrint() - Ouvre la page pour l'impression
*/
function OuvrirPrint()
{
   OuvrirFenetre("", "PRINTWINDOW", 610, 600);
   document.FormPrint.submit();
}



/* 
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
 * Tri les valeurs d'un SELECT
 *
 */
function sortArray()
{
    Liste= new Array();
    Obj= document.getElementById('SuggTous')

    for(i=0;i<Obj.options.length;i++)
    {
    Liste[i]=new Array()
    Liste[i][0]=Obj.options[i].value
    Liste[i][1]=Obj.options[i].text
    }

    Liste=Liste.sort()

    for(i=0;i<Obj.options.length;i++)
    {
    Obj.options[i].value=Liste[i][0]
    Obj.options[i].text=Liste[i][1]
    }
}
 






/* FIN : FONCTIONS POUR DÉTECTION DU TYPE DE BROWSER, VERSION ET OS */
/* Voici l'adresse du site Web ou j'ai trouvé ce script : 
// http://www.quirksmode.org/js/detect.html // */

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

/* FIN : FONCTIONS POUR DÉTECTION DU TYPE DE BROWSER, VERSION ET OS */


function ChangerBackgroundColor(objectTR, objectColor)
{
	document.getElementById(objectTR).style.backgroundColor = objectColor;
}



/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* ValiderFormulaire() - Fonction pour valider le formulaire de contact
*/
function ValiderFormulaire()
{		
	var Erreur = 0;
	
	// Courriel
	if(document.getElementById('Courriel').value == "" || document.getElementById("Courriel").value.indexOf("@") == -1 || document.getElementById("Courriel").value.indexOf(".") == -1)
	{
		Erreur = 1;
		document.getElementById('TD_MessageErreur').innerHTML = "Votre courriel est obligatoire";
		document.getElementById('Courriel').focus();
		return false;
	}
	else
	{
		Erreur = 0;
		document.getElementById('TD_MessageErreur').innerHTML = "&nbsp;";
	}
		
	
	if(Erreur == 0)
		return true;
	else
		return false;
}		





