/**********************************************************
OKINTERACTIF - LIBRAIRIE DE FONCTIONS JAVASCRIPTS
Dernière modification : 3 juin 2008, Simon Racine-Chevalier
**********************************************************/

//-- RUBRIQUES ----------------------------------------------------------------------------------------
//---- WINDOW
//---- CSS
//---- FORMS
//---- QUERYSTRING
//---- COOKIES

//-- WINDOW -------------------------------------------------------------------------------------------
	function redirect(URLStr) { location = URLStr; }
	
	function fermer_fenetre() { window.close(); }
	
	function openFullScreen(url){
		var fullWindow = "width="+screen.width+",height="+screen.height+",directories,location,menubar,resizable,left=0,top=0,screenX=0,screenY=0,scrollbars,titlebar,toolbar,status";
		newwin = window.open(url,'',fullWindow);
	}
	function openPopup(url,width,height){
		var left = 	(screen.width - width)/2;
		var top = 	(screen.height - height)/2;
		var popup = "width="+width+",height="+height+",left="+left+",top="+top+",scrollbars,menubar,titlebar,status";
		newwin = window.open(url,'Crédits',popup);
	}
	function openPrintableScreen(url){
		var fullWindow = "width="+screen.width+",height="+screen.height+",menubar,resizable,left=0,top=0,screenX=0,screenY=0,scrollbars,titlebar,status";
		newwin = window.open(url,'',fullWindow);
	}
//-- IMG ----------------------------------------------------------------------------------------------
	// Needs Mootool 1.2 Core
	function generateRollOvers()
	{
		$$('img.rollOver').each(function(img) {
			var src = img.getProperty('src');
			var extension = src.substring(src.lastIndexOf('.'))
			img.addEvent('mouseenter', function() { img.setProperty('src',src.replace(/_up/, '_over')); });
			img.addEvent('mouseleave', function() { img.setProperty('src',src); });
		});
	}
	
//-- FORMS --------------------------------------------------------------------------------------------
	// Needs Mootool 1.2 Core
	function setInputDefaultValue(){	
		var inputs = $$('input');
		inputs.each(function(item, index){
			if(item.value != ''){
				item.defaultValue = item.value;
				item.addEvent('focus',function(){
					if(this.value == this.defaultValue) this.value = '';
				});
				item.addEvent('blur',function(){
					if(this.value == '') this.value = this.defaultValue;
				});
			}
		});
	}
	
	function valider_courriel(unCourriel){
		var regEmail = /^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$/;
 		return regEmail.test (unCourriel);
	}
	
//-- MATH ---------------------------------------------------------------------------------------------
	function randRange(min,max){
		return Math.floor(Math.random()*max)+min;
	}
	
//-- QUERYSTRING --------------------------------------------------------------------------------------
	function get_query_string_attribute(attr_name){
		var bol_replace = 	false;
		var qString = 		String(window.location);
		if(qString.indexOf('?')==-1) return '';
		var chaine = 		qString.substr(qString.indexOf('?')+1);
	
		(chaine.indexOf('&')>-1)
			?	value = chaine.substring(chaine.indexOf	(attr_name)+attr_name.length+1,chaine.indexOf('&',chaine.indexOf(attr_name)+attr_name.length))
			:	value = chaine.substring(chaine.indexOf(attr_name)+attr_name.length+1);
	
		while(!bol_replace){
			(value===value.replace('+',' ')) 
				? bol_replace = 	true
				: value = 			value.replace('+',' ');
		}
		
		return value;
	}
	
//-- COOKIES ------------------------------------------------------------------------------------------
	function getCookie( name ) {
		var start = document.cookie.indexOf( name + "=" );
		var len = start + name.length + 1;
		if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
			return null;
		}
		if ( start == -1 ) return null;
		var end = document.cookie.indexOf( ";", len );
		if ( end == -1 ) end = document.cookie.length;
		return unescape( document.cookie.substring( len, end ) );
	}
		
	function setCookie( name, value, expires, path, domain, secure ) {
		var today = new Date();
		today.setTime( today.getTime() );
		if ( expires ) {
			expires = expires * 1000 * 60 * 60 * 24;
		}
		var expires_date = new Date( today.getTime() + (expires) );
		document.cookie = name+"="+escape( value ) +
			( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
			( ( path ) ? ";path=" + path : "" ) +
			( ( domain ) ? ";domain=" + domain : "" ) +
			( ( secure ) ? ";secure" : "" );
	}
		
	function deleteCookie( name, path, domain ) {
		if ( getCookie( name ) ) document.cookie = name + "=" +
				( ( path ) ? ";path=" + path : "") +
				( ( domain ) ? ";domain=" + domain : "" ) +
				";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
	
//-- FIN DU DOCUMENT ----------------------------------------------------------------------------------