/*-------------------------------------------*/
/* Last update : 2009-03-23 Raynald Bertrand */
/* - add 2 function (flashinfo code of Denis Hamel) */
/*-------------------------------------------*/

//----------------------------------------------------
// Si la propriété [prop] existe dans l'objet [obj]
// retour la valeur de la prorpiété autrement retourne
// un chaine vide.
//----------------------------------------------------
function CheckProperties(obj,prop) {		
	if (typeof(obj[prop]) == "undefined") { 
		return "";						
	} 
	else {
		return obj[prop];
	}
}
// ???
//----------------------------------------------------
// Retourne true si stringToFind est retouve dans textSearch
//----------------------------------------------------
function SearchString( textToSearch, stringToFind) {
	var text = textToSearch.toString() ;
	var maReg = new RegExp( stringToFind, "gi") ;
	if ( text.search( maReg ) == -1 )
		return 0;
	else
		return 1;
}

//-----------------------------------------
// Affiche propriété et valeur d'un objet
//
// obj		: objet à parser
//
// lstprop	: Liste des properties à dumper
//            si vide dump l'emsemble des 
//			  properties.
//
//            ex. 'banane,pomme,orange,'
//-----------------------------------------
function showProperties(obj,lstprop) {
	var props = [];
	for (var prop in obj) {
		if (SearchString(lstprop,prop) || lstprop == '')
		{				
			if (prop == 'm' || prop == 't' || prop == 'n' || prop == 'co' || prop == 'u' || prop == 'un' || prop == 'oun' )
			{
				
			} else {
				props.push('<br>'+prop+' : '+obj[prop]);
			}
		}
	}
	document.write(props.join(', '));
}

//------------------------------------
// Retourne true si [VarStr] est numeric
//------------------------------------
function IsNumeric(VarStr) {
	var RegExp = /^(\d*)$/;
	var result = VarStr.match(RegExp);
	return result;
}


//---------------------------------------
// Debug dumper objet
//
// ex.
//
// if(typeof debugDumpVar == 'function') {
// 	debugDumpVar(s,'testdumpvar=on','OMNITURE',',pageName,account,channel,server,
//  srcsite,linkInternalFilters,pageType,prop1,prop2,prop3,prop4,prop5,prop6,prop7
//  ,prop22,prop23');
// }
//---------------------------------------
function debugDumpVar (obj,hidecode,lbl,filter) {	
	var url_racine_param = document.location.href.toLowerCase().split("?");
	if (url_racine_param.length > 1)
	  {
		  var list_param=url_racine_param[1].split('&')

		  for (i = 0; i <= list_param.length; i++) {
			  
			  var par = list_param[i];

			  if (par == hidecode)
			  {
				//---------------------------------------------------
				// Affiche les propriétées de l'objet 
				//---------------------------------------------------					
				document.write('<hr><strong>Dump variable -> '+lbl+' ['+filter+']:</strong><br>');
				showProperties(obj,filter);
				document.write('<br><br>Fin...');
			  }
		  }
	  }	
}


//----------------------------------------------
// Recupération d'un parametre d'un query string
//
// ex. http://localhost/GetParams/test.html?code=zzz
//     alert(qs('code')); -> zzz
//----------------------------------------------
function qs(TheKey) {
 var query = window.location.search.substring(1);
 var parms = query.split('&');
 for (var i=0; i<parms.length; i++) {
  var pos = parms[i].indexOf('=');
  if (pos > 0) {
	var key = parms[i].substring(0,pos);
	var val = parms[i].substring(pos+1);
	if (TheKey == key) {
		return val;
	}		
  }
 }
}

//---------------------------------------------
//- Function : ObjArrNbr(n,m,q,t)
//
//- Description : Permet de générer un array de nombre
// d'une certaine dimension et dans un certain ordre
//
//- paramêtres :	n -> Numérique, début de la séquence
//-					m -> Numérique, fin de la séquence
//-					q -> Numérique, Quantité de nombre désiré
//-					t -> String, type de tri désiré 
//-						 a : Ascendant
//-						 d : Descendant
//-						 r : Random
//- Ex. MyArr = new ObjArray(1,10,5,'r');
//		MyArr.BuildArr();
//- 
//---------------------------------------------
function ObjArrNbr(n,m,q,t) {
	this.GlbArray = new  Array();
	this.n = n;	//Séquence de départ
	this.m = m; //Séquence de fin
	this.q = q; //Quantité de nombre désiré (not used)
	this.t = t; //Type de tri désiré (a,d,r)

	//- Tri l'objet GlbArray random
	this.SortRand = function(a, b) {
		return (Math.round(Math.random()) - 0.5); 
	}

	//- Tri l'objet GlbArray Ascendant
	this.SortAsc = function (a, b){ 
		return (a-b); 
	}

	//- Tri l'objet GlbArray Descendant
	this.SortDesc = function (a, b){ 
		return (b-a); 
	}
	
	//- Popule l'objet GlbArray
	this.BuildArr = function() {
		for (x=this.n; x<=this.m; x++) {
			this.GlbArray.push(x);
		}

		switch (this.t)
		{
		  case 'a':
			 this.GlbArray.sort(this.SortAsc);
		   break;
		  case 'd':
			 this.GlbArray.sort(this.SortDesc);
			break;
		  case 'r':
			 this.GlbArray.sort(this.SortRand);
			break;
		  default:
		   break;
		}
	}	
} 

//---------------------------------------------
//- Function : ConcatWB(ConcatString, delimit)
//
//- Description : Concatene avec un delimiteur 
//- 
//---------------------------------------------
function ConcatWB (ConcatString, delimit) {
		if (!ConcatString == '')
		{
			return delimit + ConcatString;
		} else {
			return '';
		}	
}

//---------------------------------------------
//- Functions : crawlerForFlashInfo et popupFlashInfoWindow
//
//- Description : crawl pour faire un rel flashinfo et popup une fenêtre
//- 
//---------------------------------------------

 function crawlerForFlashInfo(){
		for (var i=0; i<document.getElementById('flashinfobody').getElementsByTagName('a').length; ++i) {
			var link = document.getElementById('flashinfobody').getElementsByTagName('a')[i];
		
		if ( link.rel == 'flashinfo') {
			link.onclick = function(){ return popupFlashInfoWindow('argent',this.href,950,690); }
		}
	}
}

function popupFlashInfoWindow(popupName,url,popupWidth,popupHeight){
	win = window.open(url, popupName,"width=" + popupWidth + ",height=" + popupHeight + ",resizable=no,scrollbars=no,toolbar=no,status=no,location=no,directories=no");
	//bug de NN4 quand focus trop vite, attend 0,25 sec
	setTimeout('win.focus();',250);
	return false;
}

