var novUtils = {
	
	logAlert : function(mess,type) {
		if (type=="") type="log";
		if (window.console) window.console.type(message);
		else alert (message);
	},
	
	addEvent : function(oElem, sEvType, fn) {
		return oElem.addEventListener?oElem.addEventListener(sEvType, fn, false):oElem.attachEvent?oElem.attachEvent('on' + sEvType, fn):oElem['on' + sEvType] = fn;
	},
	
	removeEvent : function(oElem, sEvType, fn) {
		return oElem.removeEventListener?oElem.removeEventListener(sEvType, fn, false):oElem.attachEvent?oElem.detachEvent('on' + sEvType, fn):oElem['on' + sEvType] = fn;
	},
	
	getLeft : function(l) {
		if (l.offsetParent) return (l.offsetLeft + novUtils.getLeft(l.offsetParent));
  		else return (l.offsetLeft);	
	},
	getTop : function(l) {
		if (l.offsetParent) return (l.offsetTop + novUtils.getTop(l.offsetParent));
	  	else return (l.offsetTop);
	},
	$ : function() {
		var elements = new Array();
		for (var i = 0; i < arguments.length; i++)
		{
			var element = arguments[i];
			if (typeof element == 'string')
			element = document.getElementById(element);

			if (arguments.length == 1) return element;
			elements.push(element);
		}
		return elements;
	},

	faitFondre : function(id_div,left,top,opacityDeb,opacityFin,intervalMilliSec,intervalDec,tempsAffichagePlein,persistant) {
		var wait;
		var valOpacite=parseInt(opacityDeb);
		var leDiv=novUtils.$(id_div);
		leDiv.style.top=parseInt(top)+"px";
		leDiv.style.left=parseInt(left)+"px";
		if (parseInt(intervalDec)<0)
		{
			leDiv.style.display="block";
			setTimeout(function () { wait=setInterval(function () { degrade() } , parseInt(intervalMilliSec)) }, parseInt(tempsAffichagePlein)*1000);
		}else
		{
			leDiv.style.filter="alpha(opacity="+parseInt(opacityDeb)+")";
			leDiv.style.opacity=parseInt(opacityDeb)/100;
			leDiv.style.display="block";
			wait=setInterval(function () { degrade() } , parseInt(intervalMilliSec));
		}
		function degrade()
		{
			leDiv.style.filter="alpha(opacity="+parseInt(valOpacite)+")";
			leDiv.style.opacity=(parseInt(valOpacite)/100);
			if (parseInt(intervalDec)<0)
			{
				if (parseInt(valOpacite)<=parseInt(opacityFin)) {
					clearInterval(wait);
					leDiv.style.filter="alpha(opacity="+parseInt(opacityFin)+")";
					leDiv.style.opacity=parseInt(opacityFin)/100;
					if (parseInt(persistant)==0)
						leDiv.style.display="none";
				}
				else
					valOpacite=parseInt(valOpacite)+(parseInt(intervalDec));
			}else
			{
				if (parseInt(valOpacite)>=parseInt(opacityFin)) {
					clearInterval(wait);
					leDiv.style.filter="alpha(opacity="+parseInt(opacityFin)+")";
					leDiv.style.opacity=parseInt(opacityFin)/100;
					if (parseInt(persistant)==0)
						setTimeout(function () { leDiv.style.display="none";},(parseInt(tempsAffichagePlein)*1000));
				}else
					valOpacite=parseInt(valOpacite)+(parseInt(intervalDec));
					
			}
		}
	},
	
	novAlert : function(mess,classDiv,temps,left,top,arrondi,idVouluForBgColor)	{
		var tempsPlein=temps;
		var alertDiv=document.createElement("div");
		var idUnique=Math.round(Math.random(0)*500)+1;
		alertDiv.style.display='none';
		alertDiv.setAttribute('id',"novaLert_"+idUnique);
		alertDiv.innerHTML=mess;
		alertDiv.className=classDiv;
		if ( (idVouluForBgColor) && (idVouluForBgColor.length>0))
			novUtils.$(idVouluForBgColor).appendChild(alertDiv);
		else
			document.body.appendChild(alertDiv);
		if (arrondi==1)
			Nifty("div."+classDiv,"transparent");
		// Si left==droite alors le top est la largeur et top vaut 0
		if (left=="droite")
		{
			left=((window.innerWidth||document.body.clientWidth)-top)+"px";
			alertDiv.style.width=(top-5)+"px";
			top="0px";
		}
		// Si left==id alors le top = id:+left:+top
		if (left=="id")
		{
			var champs=top.split(':');
			left=(parseInt(novUtils.getLeft(novUtils.$(champs[0])))+parseInt(champs[1]))+"px";
			top=(parseInt(novUtils.getTop(novUtils.$(champs[0])))+parseInt(champs[2]))+"px";
		}
		
		novUtils.faitFondre("novaLert_"+idUnique,left,top,0,100,5,2,tempsPlein,1);
		novUtils.faitFondre("novaLert_"+idUnique,left,top,100,0,5,-2,tempsPlein,0);
	},
	
	preload : function (listenomimage, chemin) {
	 if (listenomimage.length > 0) {
	  var taille=listenomimage.length;
	  for(i=0; i<taille; i++) {
	   document.image_chargee = new Image();
	   document.image_chargee.src = chemin + listenomimage[i];
	  }
	 }
	},
	
	/* Fonction qui permet de stopper la propagation des evenements */
	cancelBubble : function(netEvent) {
	    if (document.all) window.event.cancelBubble = true;
	    else netEvent.cancelBubble = true;
	},
	
	getEvtTarget : function(e) {
		var targ;
		e= e||window.event;
		if (e.target) targ = e.target;
		else if (e.srcElement) targ = e.srcElement;
		if (targ.nodeType == 3) /* defeat Safari bug */ targ = targ.parentNode;
		return targ;
	},
	
	// Detects if the browser supports Ajax 
    browserSupportsAjax : function()
    {
        if (typeof XMLHttpRequest == "undefined" && typeof ActiveXObject == "undefined" && window.createRequest == "undefined")
            return false;
        return true
    },
    // Detects if the browser can use ActiveX if necessary
    ActiveXEnabledOrUnnecessary : function()
    {
        if (typeof ActiveXObject != "undefined")
        {
            var xhr = null;
            try{ xhr=new ActiveXObject("Msxml2.XMLHTTP");
            }catch (e){
                try{ xhr=new ActiveXObject("Microsoft.XMLHTTP");
                }catch (e2){
                    try{ xhr=new ActiveXObject("Msxml2.XMLHTTP.4.0");
                    }catch (e3){xhr=null;}
                }
            }
            if (xhr == null) return false
        }
        return true;
    }
};

var novFormUtils = {
	
	check : function(tabToCheck) {
		var taille=tabToCheck.length;
		var tabErrors=new Array();
		for(var i=0;i<taille;i++)
		{
			var field=tabToCheck[i];
			var erreur=false;
			var mustType=field[1];
			var objectForm=field[0];
			var errorMess=field[2];
			
			if (typeof mustType == 'function') 
				erreur=!mustType(objectForm);
			else
			{
				if (objectForm.tagName=="INPUT")
				{
					var attrType=objectForm.getAttribute("type");
					switch(attrType) {
						case "text":
							if (!novFormUtils.validValue(objectForm.value,mustType)) 
								erreur=true;
						break;
						case "checkbox":
							if (mustType=="filled")
								if (!novFormUtils.isCheckBoxChecked(objectForm))
									erreur=true;
						break;
						case "radio":
							if (mustType=="filled")
								if (!novFormUtils.isRadioChecked(objectForm))
									erreur=true;
						break;
					}
				}
				if (objectForm.tagName=="TEXTAREA")
					if (!novFormUtils.validValue(objectForm.value,mustType)) 	
						erreur=true;
						
				if (objectForm.tagName=="SELECT")
					if (!novFormUtils.validValue(objectForm.value,mustType)) 	
						erreur=true;
			}
			if (erreur)	tabErrors[tabErrors.length]=errorMess;
		}
		return tabErrors;
	},
	
	validValue : function(value,type)
	{
		var temp=type.split(":");
		var t_type=temp[0];
		var t_options=new Array();
		for(var i=1;i<temp.length;i++) t_options[i-1]=temp[i];
		switch(t_type)
		{
			case "filled":
				if (value.length>0) 
				{
					if (t_options[0])
					{	
						if (t_options[0].indexOf("=")>=0)
						{ 
							var temp=t_options[0].split("=");
							if (value.length==temp[1]) return true; 
						}
						else if (t_options[0].indexOf("<")>=0) 
						{ 
							var temp=t_options[0].split("<");
							if (value.length<temp[1]) return true; 
						}
						else if (t_options[0].indexOf(">")>=0) 
						{ 
							var temp=t_options[0].split(">");
							if (value.length>temp[1]) return true; 
						}else
						{ 
							if (value.length<=t_options[0]) 
								return true; 
						}
					}else
						return true;
				}
			break;
			case "email":
				if (novFormUtils.isEmail(value)) return true;
			break;
			case "double":
				if (novFormUtils.isDouble(value)) return true;
			break;
			case "date":
				if (novFormUtils.isDate(value)) return true;
			break;
			case "integer":
				if (novFormUtils.isInteger(value))
				{
					if (t_options[0])
					{	
						if (t_options[0].indexOf("=")>=0)
						{ 
							var temp=t_options[0].split("=");
							if (value.length==temp[1]) return true; 
						}
						else if (t_options[0].indexOf("<")>=0) 
						{ 
							var temp=t_options[0].split("<");
							if (value.length<temp[1]) return true; 
						}
						else if (t_options[0].indexOf(">")>=0) 
						{ 
							var temp=t_options[0].split(">");
							if (value.length>temp[1]) return true; 
						}else
						{ 
							if (value.length<=t_options[0]) 
								return true; 
						}
					}else
						return true;
				}
			break;
			default:
			break;
		}
		return false;
	},
	
	isRadioChecked :  function(radioObj) {
		for (var i = 0; i < radioObj.length; i++)
			if (radioObj[i].checked) return true ;
		return false ;
	},
	
	isCheckBoxChecked : function(cBoxObj) {
		return cBoxObj.checked;
	},
	
	isEmail : function(eml)	{
		a = eml.search(/^[-a-z0-9_]+([-._]+[-a-z0-9_]+)*@[a-z0-9]([.-]?[a-z0-9])*\.[a-z]{2,4}$/i);
		if(a!=-1)
			return true
		else
			return false
	},
	
	isInteger : function(value) {
		var exp = new RegExp("^[0-9]*$");
		 
		if(exp.test(value))
			return true
		else
			return false
	},
	
	isDouble : function(value) {
		var exp = new RegExp("^[0-9\.]*$");
		if(exp.test(value))
			return true
		else
			return false
	},
	
	isInputEmpty : function(inputObj) {
		return (inputObj.value.length == 0) ;
	},

	isDate : function(val) {
		var virt={ value:val }
		return novFormUtils.isDateValid(virt);
	},
	
	isDateValid : function(dateObj) {
		str = dateObj.value ;
		format = "jj-mm-aaaa" ;
		posj=format.search(/jj/i)
		posm=format.search(/mm/i)
		posa=format.search(/aaaa/i)
		poss=format.search(/\W/)
		poss2=format.substring(poss+1, format.length).search(/\W/)+poss+1
		s1=format.substring(poss, poss+1)
		s2=format.substring(poss2, poss2+1)
		s_jj=str.substring(posj, posj+2)
		s_mm=str.substring(posm, posm+2)
		s_aaaa=str.substring(posa, posa+4)
		jj=parseInt(s_jj*1)
		mm=parseInt(s_mm*1)
		aaaa=parseInt(s_aaaa*1)
		sep1=str.substring(poss, poss+1)
		sep2=str.substring(poss2, poss2+1)
		if(
			(
				isNaN(jj) || isNaN(mm) || isNaN(aaaa)
				|| jj<1 || jj>31 || mm<1 || mm>12 || aaaa<1900 || aaaa>3000
				|| s1!=sep1 || s2!=sep2
				|| s_jj.indexOf(" ")!="-1" || s_mm.indexOf(" ")!="-1" || s_aaaa.indexOf(" ")!="-1"
			)
		)
			return false ;
		return true ;
	}
};

var NovTableSort  = {
	iColSel : null,
	col : null,
	tableauHTML : null,
	/* Tri ascendant sur cha�nes de caract�res */
	TrierColAsc :  function(x1,x2) { return (x1[NovTableSort.iColSel] < x2[NovTableSort.iColSel])? -1 : 1; },   
	// Tri descendant sur cha�ne de caract�res
	TrierColDesc : 	function(x1,x2) { return (x1[NovTableSort.iColSel] > x2[NovTableSort.iColSel])? -1 : 1; },
	// Tri ascendant sur nombre
	TrierColNbAsc :  function(x1,x2) { return parseInt(x1[NovTableSort.iColSel])-parseInt(x2[NovTableSort.iColSel]); },  
	 // Tri descendant sur nombre
	TrierColNbDesc : function(x1,x2) { return parseInt(x2[NovTableSort.iColSel])-parseInt(x1[NovTableSort.iColSel]); },
	goSort :  function(type, idCol, order)
    {
	    this.iColSel = idCol;
		if (type=="int")	
		{
			if (order=="asc")
				this.col.sort(this.TrierColNbAsc);
			else
				this.col.sort(this.TrierColNbDesc);
		}
		if (type=="string")	
		{
			if (order=="asc")
				this.col.sort(this.TrierColAsc);
			else
				this.col.sort(this.TrierColDesc);
		}
	},
	init : function(tabHTML) {
		this.tableauHTML=tabHTML;
		var col=new Array();
		this.tableauHTML.find('tr:gt(0)').each(function(i){
			col[i]=new Array();
			$(this).find('>td').each(function(j) {
				col[i][j]=$(this).html();
			});
		});
		this.col=col;
		
	},
	remake : function() {
		var col=this.col;
		this.tableauHTML.find('tr:gt(0)').each(function(i){
			$(this).find('>td').each(function(j) {
				$(this).html(col[i][j])
			});
		});
	}
	
};

/** JQUERY plugins **/

/** Plugins COOKIE **/
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + options.path : '';
        var domain = options.domain ? '; domain=' + options.domain : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
/**/
/** Plugins GET */
/* Recuperer en Javascript les parametres en GET */
jQuery.GET = function(key) {
  var paramsArray = new Array();
		if (location.href.split('?').length > 1) 
			paramsArray = location.href.split('?')[1].split('&');
		var paramsArrayCount = paramsArray.length;
		var resultArray = new Array();
		if (paramsArrayCount != 0) for (var i = 0; i<paramsArrayCount; i++) {
			var keyAndValue = paramsArray[i].split('=');
			if ((keyAndValue[0]==key) && (keyAndValue[0]!="")) { return keyAndValue[1]; }
			var hash  = {
				key    : keyAndValue[0],
				value  : keyAndValue[1]
			}
			resultArray.push(hash);
		}
		return resultArray;
};