/* *********** commonFunctions.js : fonctions communes à tous les pages ************* */



/* *** Détection du navigateur *** */
var browser=navigator.appName
var b_version=navigator.appVersion
var version=parseFloat(b_version)
if(browser.match('Internet Explorer') && version < 7){
	//alert('Navigateur =' + browser);
	var browserName = 'msie';
	document.write('<link rel="stylesheet" href="msie.css" type="text/css">');
}

/*
if(!navigator.cookieEnabled){
	alert("Vous devez autoriser les cookies sur votre ordinateur afin de pouvoir naviguer sur le site beTobe.");
}
*/



/* *** Transparence alpha des png sous Internet Explorer *** */
/* Warning: the 'position:relative' attribute is required for png transparency and links to work in IE. */

function pngTransparencyForIE(){

	var pngBgImgArray=new Array(
	'../images/haut_menu.png',
	'../images/bas_menu.png',
	'../images/presentation.png',
	'../images/volontaire.png',
	'../images/entreprise.png',
	'../images/association.png',
	'../images/haut_corps.png',
	'../images/bas_corps.png',
	'../images/haut_membre.png',
	'../images/bas_membre.png',
	'../images/haut_actualite.png',
	'../images/bas_actualite.png',
	'../images/haut_actualite_entreprise.png',
	'../images/bas_actualite_entreprise.png',
	'../images/haut_mission.png',
	'../images/bas_mission.png',
	'../images/haut_newsletter.png',
	'../images/bas_newsletter.png'
	);
	//'../images/recherche.png',

	var pngBgImgId=new Array(
	'haut_menu',
	'bas_menu',
	'presentationTab',
	'volontaireTab',
	'entrepriseTab',
	'associationTab',
	'haut_corps',
	'bas_corps',
	'haut_membre',
	'bas_membre',
	'haut_actualite',
	'bas_actualite',
	'haut_actualite_entreprise',
	'bas_actualite_entreprise',
	'haut_mission',
	'bas_mission',
	'haut_newsletter',
	'bas_newsletter'
	);
	//'search_bar',

	// Is the browser compliant with the DOM?
	if(document.getElementById) {
		// Is the browser capable of managing runtimeStyle?
		for(var x=0; x<pngBgImgArray.length; x++){
			thisId=pngBgImgId[x];
			thisImage=pngBgImgArray[x];
			if(document.getElementById(thisId) && document.getElementById(thisId).runtimeStyle) {
				// Delete current background.
				document.getElementById(thisId).style.backgroundImage = 'none';
				// Apply PNG background with alpha transparency filtering.
				document.getElementById(thisId).style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + pngBgImgArray[x] + '")';
			}
		}
	}
}

/* *** /Transparence alpha des png sous Internet Explorer *** */



// Function by Breaking Par Consulting, Inc.
// Remplace tous les doubles espaces en un seul espace; renvoie une chaîne vide si le résultat est lui-même un espace.
function trim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = / +/g;
   temp = temp.replace(obj, ' ');
   if (temp == ' ') { temp = ''; }
   return temp;
}


// Returns true if the string contains only whitespace
// Cannot check a password type input for whitespace
function isWhitespace(str){
	var re = /[\S]/i
	if (re.test(str)) return false;
	return true;
}

// Removes any whitespace from the string and returns the result
// The value of "replacement" will be used to replace the whitespace (optional)
function stripWhitespace(str, replacement){// NOT USED IN FORM VALIDATION
	if (replacement == null) replacement = '';
	var result = str;
	var re = /\s/g
	if(str.search(re) != -1){
		result = str.replace(re, replacement);
	}
	return result;
}

function isEmpty(str){
  return (str == null) || (str.length == 0);
}

/* *** Suppression du cookie utilisateur *** */
function writeCookie(cookiename, cookievalue){
	var argv=writeCookie.arguments;
	var argc=writeCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=cookiename+"="+escape(cookievalue)+
	((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
	((path==null) ? "" : ("; path="+path))+
	((domain==null) ? "" : ("; domain="+domain))+
	((secure==true) ? "; secure" : "");
}

function deconuser(url){
	date=new Date;
	date.setFullYear(date.getFullYear()-1);
	writeCookie('VEM-ConnectedUser',null,date,'/');
	window.location.replace(url);
}


/* *** Check/Uncheck all checkboxes *** */
function check_uncheck_all(form_id, check_value){
	var el = document.getElementById(form_id);
	for(var i = 0; i < el.elements.length; i++){
		el.elements[i].checked = check_value;
	}
}
/* *** /Check uncheck all checkboxes *** */




/* *** ids des items sélectionnés d'une liste select dont l'id est passé en paramètre (retourne un array de string) *** */
function getSelectedItemsIdsArray(selectList){
	var selectedItemsIds = new Array();
	var x = document.getElementById(selectList);
	var j = 0;
	for(i=0; i<x.length; i++){
		if (x.options[i].selected === true && x.options[i].value){
			selectedItemsIds[j] = x.options[i].value; // On récupère les ids inclus dans chaque valeur de champ pour chaque élément <option>
			j++;
		}
	}
	//alert('selectedItemsIds = ' + selectedItemsIds);
	return selectedItemsIds;
}


// Compatibilité des versions JS
Array.prototype.indexOf=function(n){for(var i=0;i<this.length;i++){if(this[i]===n){return i;}}return -1;}
Array.prototype.lastIndexOf=function(n){var i=this.length;while(i--){if(this[i]===n){return i;}}return -1;}
Array.prototype.forEach=function(f){var i=this.length,j,l=this.length;for(i=0;i<l;i++){if((j=this[i])){f(j);}}};
Array.prototype.insert=function(i,v){if(i>=0){var a=this.slice(),b=a.splice(i);a[i]=value;return a.concat(b);}}
Array.prototype.shuffle=function(){var i=this.length,j,t;while(i--){j=Math.floor((i+1)*Math.random());t=arr[i];arr[i]=arr[j];arr[j]=t;}}
Array.prototype.unique=function(){var a=[],i;this.sort();for(i=0;i<this.length;i++){if(this[i]!==this[i+1]){a[a.length]=this[i];}}return a;}
if(typeof Array.prototype.concat==='undefined'){Array.prototype.concat=function(a){for(var i=0,b=this.copy();i<a.length;i++){b[b.length]=a[i];}return b;};}
if(typeof Array.prototype.copy==='undefined'){Array.prototype.copy=function(a){var a=[],i=this.length;while(i--){a[i]=(typeof this[i].copy!=='undefined')?this[i].copy():this[i];}return a;};}
if(typeof Array.prototype.pop==='undefined'){Array.prototype.pop=function(){var b=this[this.length-1];this.length--;return b;};}
if(typeof Array.prototype.push==='undefined'){Array.prototype.push=function(){for(var i=0,b=this.length,a=arguments;i<a.length;i++){this[b+i]=a[i];}return this.length;};}
if(typeof Array.prototype.shift==='undefined'){Array.prototype.shift=function(){for(var i=0,b=this[0];i<this.length-1;i++){this[i]=this[i+1];}this.length--;return b;};}
if(typeof Array.prototype.slice==='undefined'){Array.prototype.slice=function(a,c){var i=0,b,d=[];if(!c){c=this.length;}if(c<0){c=this.length+c;}if(a<0){a=this.length-a;}if(c<a){b=a;a=c;c=b;}for(i;i<c-a;i++){d[i]=this[a+i];}return d;};}
if(typeof Array.prototype.splice==='undefined'){Array.prototype.splice=function(a,c){var i=0,e=arguments,d=this.copy(),f=a;if(!c){c=this.length-a;}for(i;i<e.length-2;i++){this[a+i]=e[i+2];}for(a;a<this.length-c;a++){this[a+e.length-2]=d[a-c];}this.length-=c-e.length+2;return d.slice(f,f+c);};}
if(typeof Array.prototype.unshift==='undefined'){Array.prototype.unshift=function(a){this.reverse();var b=this.push(a);this.reverse();return b;};}
