/*******************
	framework
********************/
//Add Events
function addEvent( obj, type, fn ) {
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}


/* $: shortcut for document.getElementById*/
function $(obj) {
	if(typeof obj == "string") {
		return document.getElementById(obj);
	} else {
		return obj;
	}
}

/* ajouter une classe a l'element */
function addClass(elm, klass){
	elm.className += " " + klass;
}

/* enlever une classe a l'element */
function removeClass(elm, klass){
	var re = new RegExp('\\b'+klass+'\\b',"g");
	elm.className = elm.className.replace(re,"");
}

function hasClass(elm,klass){
	var re = new RegExp('\\b'+klass+'\\b',"g");
	return re.test(elm.className);
}


// getStyle : retourne la valeur d'une propriete CSS appliquee   un element
function getStyle(oElm, strCssRule){
    var strValue = "";
    if(document.defaultView && document.defaultView.getComputedStyle) {
		try{ strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule); }
		catch(e) { strValue = ""; }
    }
    else if(oElm.currentStyle) {
        try{
			strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
	            return p1.toUpperCase();
	        });
	        strValue = oElm.currentStyle[strCssRule];
		} catch(e) {
			strValue = "";
		}
    }
    return strValue;
}
/*retourne la valeur entiere d'un style*/
function intStyle(oElm, strCSSRule) {
	var val = parseInt(getStyle(oElm, strCSSRule));
	if (isNaN(val)) val=0;
	return val;
}

/*getElementsByClassName: return an array of Objects with specified className*/
function getElementsByClassName(oElm, sTagName, sClassName){
    var aElements = (sTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(sTagName);
	var aReturnElements = new Array();
    sClassName = sClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + sClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i < aElements.length; i++){
    	oElement = aElements[i];
		if(oRegExp.test(oElement.className))
            aReturnElements.push(oElement);
    }
	return aReturnElements
}

/********************
* site functions
***********************/
/* Menu fonction */
function initmenu() {
	var currentLink = null;
	var menu = $("menu");
	if (!menu) return;
	var li = menu.getElementsByTagName("li");
	for (var i=0; i<li.length; i++) {
		var child = li[i].childNodes;
		var a = li[i].getElementsByTagName("a");
		if (a.length>0) {
			for (var j=0; j<child.length; j++) {
				if (child[j].nodeName=="UL") {
					a[0].theUL = child[j];
					a[0].onclick=function() {
						var ul = this.theUL;
						ul.style.display = ul.style.display == "none" ? "" : "none";
					}
					if (!li[i].className.match(/\bcurrent\d?\b/)) child[j].style.display="none";
					if (a[0].className.match(/\bcurrent2\b/)) {
						child[j].style.display="";
						//a[0].onclick=function() {return false}
					}
				}
            }
		}
	}
    var as = menu.getElementsByTagName("a");
    for(var i=0; i<as.length; i++) {
        if (as[i].className.match(/\bcurrent3\b/)) {
            currentLink=as[i];
            break;
        }
    }
    if (currentLink) {
		var node=currentLink;
		while(node!=menu) {
            if (node.nodeName=="UL") {
                node.style.display="";
            }
            node=node.parentNode;
		}
	}
}

var ie = document.all && window.print && !window.opera && /MSIE [56]/.test(navigator.userAgent);
var ie7 = document.all && window.print && !window.opera && /MSIE [789]/.test(navigator.userAgent);

function JSForCSS() {
	if (document.body) {
		document.body.className+=" IS_IE";
	} else {
		setTimeout("JSForCSS()",10);
	}
}
if (ie) JSForCSS();

/* gestion des textes de remplissage des formualires*/
function firstText(inp,defaultText) {
   if (!inp.oldFirstText) {
       if (defaultText) {
           inp.oldFirstText = defaultText
       } else {
           inp.oldFirstText = inp.value;
       }
   }
   if (inp.value==inp.oldFirstText) {
       inp.value="";
   }
   inp.onblur=function() {
       if (inp.value=="") {
           inp.value=inp.oldFirstText;
       }
   }
}


/******* scrolling  functions ******/
var scrollBoxTimer = null;
var scrollBlock = null;
var scrollBt = null;
function scrollbox(elm, sens) {
	var box = elm;
	document.onselectstart = function() {return false;}
	elm.onmouseup = function() {
		clearTimeout(scrollBoxTimer);
		document.onselectstart = function() {}
	}
	elm.onmouseout = function() {
		clearTimeout(scrollBoxTimer);
	}
	while(box.parentNode && !box.className.match(/\bscrollbox\b/)) box = box.parentNode;
	var div = getElementsByClassName(box,'div','scrollElement');
	if (div.length>0) {
		div = div[0];
		scrollBlock = div;
		scrollStart(sens);
	}
}
function scrollStart(sens) {
	scrollBlock.scrollTop += 2*sens;
	scrollBt.style.top = Math.round(71*scrollBlock.scrollTop/(scrollBlock.scrollHeight-101))+22+'px';
	scrollBoxTimer = setTimeout('scrollStart('+sens+')',15);
}
function scrollPos(){
	var bt = getElementsByClassName(document,'div','scrollBt');
	var div = getElementsByClassName(document,'div','scrollElement');
	if (bt.length>0) scrollBt = bt[0];
	if (div.length>0) scrollBlock = div[0];
	if (scrollBt){
		scrollBt.style.top = Math.round(intStyle(scrollBt,'top')+(71*scrollBlock.scrollTop/(scrollBlock.scrollHeight-101)))+'px';
	}
}
/******  /scrolling functions ******/

/**** Tabpanes *****/
var tab={
	tab:0,
	setTab : function (index) {
		tab.tab = index;
		var p = document.getElementById('confirmBox');
		if (p) document.getElementById('formulaireContact').removeChild(p);
	},
	getTab : function () {return tab.tab;}
};

/* changeTab : Change les onglets */
function changeTab(elm) {
	var li = elm.parentNode;
	var ul = li.parentNode;
	var tabindex=0;
	var lis = ul.getElementsByTagName("li");	
	
	for (var i=0; i<lis.length; i++) {
		var o = lis[i];
		if (o==li) {
			o.className+=" current";
			tabindex = i;
		} else {
			o.className=o.className.replace(/\bcurrent\b/g,"");
		}
	}

	var globctn = elm;
	while(globctn.parentNode && !/\btabs\b/.test(globctn.className)) globctn = globctn.parentNode;
	var blockContainer = getElementsByClassName(globctn, "div", "bkg_ctt");
	if (blockContainer.length>0) blockContainer=blockContainer[0]; else return;
	var child = blockContainer.firstChild;
	var ContainerCounter = 0;
	while(child) {
		if (child.nodeName=="DIV" && child.className.match(/\btabcontent\b/)) {
			if (ContainerCounter==tabindex) {
				child.className+=" tabcurrent";
			} else {
				child.className=child.className.replace(/\btabcurrent\b/g,"");
			}
			ContainerCounter++;
		}
		child = child.nextSibling;
	}
	tab.setTab(tabindex);
	elm.blur();
	fixColumns();
}

function previous(prev){
	changeTab(document.getElementById(prev));
}

/***************
fixcorners functions
****************/
var CSSBottomCorners=[];
function cssRight(elm) {
	elm.style.right=(parseInt(elm.currentStyle.right)-elm.parentNode.offsetWidth%2)+"px";
}
function cssBottom(elm, pushElement) {
	if (pushElement && !elm.CSSBottomAlreadyCSS) {
		CSSBottomCorners.push(elm);
		elm.CSSBottomAlreadyCSS=true;
	}
	elm.style.bottom=(parseInt(elm.currentStyle.bottom)-elm.parentNode.offsetHeight%2)+"px";
}
function fixCorners() {
	if (ie)  {
		for (var i=0; i<CSSBottomCorners.length; i++) {
			CSSBottomCorners[i].style.bottom="";
		}
	} else {
		if (/safari/i.test(navigator.userAgent)) {
			document.body.className+=" hidecorners";
			setTimeout("fixCornersClean()",10);
		}
	}
}
function fixCornersClean() {
	document.body.className = document.body.className.replace(/\bhidecorners\b/g,"");
}

/* fix columns */
function fixColumns() {
	fixColumnsToMin();
	var blocLeft = $("blocLeft");
	if (!blocLeft) return;
	var menu = $("menu");
	var blocContenu = $("blocContenu");
	var blocContenuContent = $("blocContenuContent");
	var height = blocLeft.offsetHeight>blocContenu.offsetHeight ? blocLeft.offsetHeight : blocContenu.offsetHeight;

	var tmp = blocLeft.offsetHeight-menu.offsetHeight;
	var newHeight = height-tmp-(intStyle(menu,"padding-top")+intStyle(menu,"padding-bottom")+intStyle(menu,"border-top-width")+intStyle(menu,"border-bottom-width"))+"px";
	menu.style[ie ? "height" : "minHeight"] = newHeight;
	var tmp = blocContenu.offsetHeight-blocContenuContent.offsetHeight;
	newHeight = height-tmp-(intStyle(blocContenuContent,"padding-top")+intStyle(blocContenuContent,"padding-bottom")+intStyle(blocContenuContent,"border-top-width")+intStyle(blocContenuContent,"border-bottom-width"))+"px";
	blocContenuContent.style[ie ? "height" : "minHeight"] = newHeight;
	fixCorners();
}

function fixColumnsToMin() {
	var menu = $("menu");
	if (!menu) return;
	var blocContenuContent = $("blocContenuContent");
	blocContenuContent.style[ie ? "height" : "minHeight"]=menu.style[ie ? "height" : "minHeight"]="1%";
}

function sizeDefinedBlocks() {
	var div = getElementsByClassName(document, 'div', 'mustbesized');
	for (var i=0; i<div.length; i++) {
		var par = div[i].parentNode;
		var firstHeight = par.offsetHeight;
		if (par.parentNode && par.nodeName!="TD") {
			var parent = par.nodeName=="TD" ? par.parentNode.parentNode : par.parentNode;
			par.style.height = parent.offsetHeight-(intStyle(par,'margin-top')+intStyle(par,'margin-bottom')+intStyle(par,'padding-top')+intStyle(par,'padding-bottom')+intStyle(parent,'padding-top')+intStyle(parent,'padding-bottom'))+"px";
		}
		var blkctnctt = getElementsByClassName(div[i], 'div', 'blk_ctn_ctt');
		
		if (blkctnctt.length>0){
			blkctnctt = blkctnctt[0];
			var tmpHeight = par.offsetHeight-(par.nodeName=="TD" ? div[i].offsetHeight : firstHeight);
			blkctnctt.style[ie ? "height" : "minHeight"] = blkctnctt.offsetHeight+tmpHeight-(intStyle(blkctnctt,'padding-top')+intStyle(blkctnctt,'padding-bottom'))+"px";
		}
		//alert(blkctnctt.offsetHeight+tmpHeight-(intStyle(blkctnctt,'padding-top')+intStyle(blkctnctt,'padding-bottom'))+"px";/)
	}
	fixCorners();
}
/*
var addClass = function(elem, sClass){
	elem.className += ' ' + sClass;
	return elem;
}

var removeClass = function(elem, sClass){
	elem.className = elem.className.replace(sClass, '');
	return elem;
}*/
var hasClass = function(elem, sClass){
	var oReg = new RegExp("(^|\\s)" + sClass + "(\\s|$)");
	if(oReg.test(elem.className)) return true;
	
}

function toggleClass(elem, classe){
	if (hasClass(elem, classe)){
		removeClass(elem, classe);
	}else{
		addClass(elem, classe);
	}
}

function setClick(elem){
	addEvent(elem.baseClicToggle, 'click', function(){
			toggleClass(elem, 'toggled')
	return false;
		});
}

function init() {
	initmenu();
	sizeDefinedBlocks();
	fixColumns();
	scrollPos();	
	
	var aCheckbox = getElementsByClassName(document,'label','checkbox');
	for(var i=0,l=aCheckbox.length;i<l;i++){
		var checkbox = aCheckbox[i];
		skinCheckableInput(checkbox);
	}
	
	var blockToggles = getElementsByClassName(document,'div','blockToggle');
	for(var i=0; i<blockToggles.length;i++){
		var blockToggle = blockToggles[i];
		blockToggle.titleBlockToggle = getElementsByClassName(blockToggle,'div','titleBlockToggle')[0];
		blockToggle.baseClicToggle = getElementsByClassName(blockToggle.titleBlockToggle,"a", "toggleBase")[0]
		blockToggle.unitBlockToggle = getElementsByClassName(blockToggle,'div','unitsToggle')[0];
		
		setClick(blockToggle);
	}
	
	addClass(blockToggles[0], 'toggled');
}

addEvent(window, 'load', init);


/* formval : Objet qui permet de checker un formulaire
use : formval.check('formulaireId');
return : retourne false si un des champs n'est pas bon;
classes utilisables :
	-champs ncessaires : frm_needed
	-champs de type email : frm_email
	-champs de type confirmation email : frm_confEmail
	-champs de type groupe de box : frm_needed sur le titre du groupe
	-champs de type box avec champs input(text) needed : gotoAssociatedText sur la box et frm_other sur le input(text)
ex : <input type="text" class="frm_needed frm_email">
ex2:
*/
formval={
	error:false,
	form:function(formParam,next){
		var error = formval.error;
		var form = typeof(formParam)=="string" ? document.getElementById(formParam) : formParam;
		if (!form) error = true;

		var inpTxt = formval.getAllInput(form,'text');
		for (i=0;i<inpTxt.length;i++){
			var x=inpTxt[i];
			if (x.className.match(/\bfrm_needed\b/) && formval.checkText(x)){
				formval.focusElm(x,"label",false).className += " hasAnError";
				error=true;
			}else if (x.className.match(/\bfrm_needed\b/) && !formval.checkText(x)){
				formval.focusElm(x,"label",false).className = formval.focusElm(x,"label",false).className.replace(/hasAnError/g,"");

				if (x.className.match(/\bfrm_num\b/) && formval.checkNum(x)){
					formval.focusElm(x,"label",false).className += " hasAnError";
					error=true;
				}else if (x.className.match(/\bfrm_num\b/) && !formval.checkNum(x)){
					formval.focusElm(x,"label",false).className = formval.focusElm(x,"label",false).className.replace(/hasAnError/g,"");			
				}
				if(x.className.match(/\bfrm_zipcode\b/) && formval.checkZip(x)){
					formval.focusElm(x,"label",false).className += " hasAnError";
					error=true;
				}else if (x.className.match(/\bfrm_zipcode\b/) && !formval.checkZip(x)){
					formval.focusElm(x,"label",false).className = formval.focusElm(x,"label",false).className.replace(/hasAnError/g,"");
				}
				if (x.className.match(/\bfrm_confEmail\b/) && (x.value!=document.getElementById('email').value || formval.checkMail(x))){
					formval.focusElm(x,"label",false).className += " hasAnError";
					error=true;
				}else if (x.className.match(/\bfrm_confEmail\b/) && x.value==document.getElementById('email').value && !formval.checkMail(x)){
					formval.focusElm(x,"label",false).className = formval.focusElm(x,"label",false).className.replace(/hasAnError/g,"");
				}
				if (x.className.match(/\bfrm_email\b/) && formval.checkMail(x)){
					formval.focusElm(x,"label",false).className += " hasAnError";
					error=true;
				}else if (x.className.match(/\bfrm_email\b/) && !formval.checkMail(x)){
					formval.focusElm(x,"label",false).className = formval.focusElm(x,"label",false).className.replace(/hasAnError/g,"");
				}

				if (x.className.match(/\bfrm_date\b/) && formval.checkDate(x)){
					formval.focusElm(x,"label",false).className += " hasAnError";
					error=true;
				}else if (x.className.match(/\bfrm_date\b/) && !formval.checkDate(x)){
					formval.focusElm(x,"label",false).className = formval.focusElm(x,"label",false).className.replace(/hasAnError/g,"");
				}
				
				if (x.className.match(/\bfrm_ville\b/) && formval.checkMinCarac(x,3)){
					formval.focusElm(x,"label",false).className += " hasAnError";
					error=true;
				}else if (x.className.match(/\bfrm_ville\b/) && !formval.checkMinCarac(x,3)){
					formval.focusElm(x,"label",false).className = formval.focusElm(x,"label",false).className.replace(/hasAnError/g,"");
				}
				if (x.className.match(/\bfrm_name\b/) && formval.checkMinCarac(x,2)){
					formval.focusElm(x,"label",false).className += " hasAnError";
					error=true;
				}else if (x.className.match(/\bfrm_name\b/) && !formval.checkMinCarac(x,2)){
					formval.focusElm(x,"label",false).className = formval.focusElm(x,"label",false).className.replace(/hasAnError/g,"");
				}
				var phoneError = document.getElementById("frm_phoneError");
				if (x.className.match(/\bfrm_phone\b/) && formval.checkPhone(x)){
					formval.focusElm(x,"label",false).className += " hasAnError";
					phoneError.className = phoneError.className.replace(/displayNn/g,"");
					error=true;
				}else if (x.className.match(/\bfrm_phone\b/) && !formval.checkPhone(x)){
					phoneError.className = phoneError.className += " displayNn";
					formval.focusElm(x,"label",false).className = formval.focusElm(x,"label",false).className.replace(/hasAnError/g,"");
				}
			}
		}

		var inpPass = formval.getAllInput(form,'password');
		for (i=0;i<inpPass.length;i++){
			var x=inpPass[i];

			if (x.className.match(/\bfrm_needed\b/) && formval.checkText(x)){
				formval.focusElm(x,"label",false).className += " hasAnError";
				error=true;
			}else if (x.className.match(/\bfrm_needed\b/) && !formval.checkText(x)){
				formval.focusElm(x,"label",false).className = formval.focusElm(x,"label",false).className.replace(/hasAnError/g,"");
			}

			if (document.getElementById('nouveauMdp') && document.getElementById('nouveauMdp').value!=""){
				if (x.className.match(/\bfrm_ancMdp\b/) && x.value==""){
					formval.focusElm(x,"label",false).className += " hasAnError";
					error=true;
				}else if (x.className.match(/\bfrm_ancMdp\b/) && x.value!=""){
					formval.focusElm(x,"label",false).className = formval.focusElm(x,"label",false).className.replace(/hasAnError/g,"");
				}
				if (x.className.match(/\bfrm_confMdp\b/) && (x.value!=document.getElementById('nouveauMdp').value )){
					formval.focusElm(x,"label",false).className += " hasAnError";
					error=true;
				}else if (x.className.match(/\bfrm_confMdp\b/) && x.value==document.getElementById('nouveauMdp').value){
					formval.focusElm(x,"label",false).className = formval.focusElm(x,"label",false).className.replace(/hasAnError/g,"");
				}
				if (x.className.match(/\bfrm_confMdp\b/) && (x.value!=document.getElementById('nouveauMdp').value )){
					formval.focusElm(x,"label",false).className += " hasAnError";
					error=true;
				}else if (x.className.match(/\bfrm_confMdp\b/) && x.value==document.getElementById('nouveauMdp').value){
					formval.focusElm(x,"label",false).className = formval.focusElm(x,"label",false).className.replace(/hasAnError/g,"");
				}
			}
		}

		var inpCheck = formval.getAllInput(form,'checkbox');
		for (i=0;i<inpCheck.length;i++){
			var x=inpCheck[i];

			if (x.className.match(/\bfrm_needed\b/) && x==document.getElementById('conditions') ){
				var elm = document.getElementById('frm_cgiError');
				if (!formval.checkBox(x)){
					elm.className = elm.className.replace(/displayNn/g,"");
					formval.focusElm(x,"label",true).className += " hasAnError";
					error=true;
				}else{
					elm.className = elm.className+=" displayNn";
					formval.focusElm(x,"label",true).className = formval.focusElm(x,"label",true).className.replace(/hasAnError/g,"");
				}
			}
		}

		var allGp = formval.getAllGroup(form);
		for (i=0;i<allGp.length;i++){
			var x=allGp[i][0];
			if (document.getElementById(x.getAttribute('name'))) {
				var title = document.getElementById(x.getAttribute('name'));
				if (title.className.match(/\bfrm_needed\b/) && !formval.checkGroup(allGp[i])){
					title.className += " hasAnError";
					error=true;
				}else if (title.className.match(/\bfrm_needed\b/) && formval.checkGroup(allGp[i])){
					title.className = title.className.replace(/hasAnError/g,"");
				}
			}
		}

		var allSel = formval.getAllSel(form);
		for (i=0;i<allSel.length;i++){
			var x=allSel[i];
			if (x.className.match(/\bfrm_needed\b/) && formval.checkSelect(x)){
				formval.focusElm(x,"label",false).className += " hasAnError";
				error=true;
			}else if (x.className.match(/\bfrm_needed\b/) && !formval.checkSelect(x)){
				formval.focusElm(x,"label",false).className = formval.focusElm(x,"label",false).className.replace(/hasAnError/g,"");
			}
		}

		var allTxt = formval.getAllTextarea(form);
		for (i=0;i<allTxt.length;i++){
			var x=allTxt[i];
			if (x.className.match(/\bfrm_needed\b/) && formval.checkText(x)){
				formval.focusElm(x,"label",false).className += " hasAnError";
				error=true;
			}else if (x.className.match(/\bfrm_needed\b/) && !formval.checkText(x)){
				formval.focusElm(x,"label",false).className = formval.focusElm(x,"label",false).className.replace(/hasAnError/g,"");
			}
		}

		if (formval.checkVal(form)){
			error=formval.checkVal(form);
		}

		if (!error){
			var divErr = getElementsByClassName(form,'div','frm_error');
			for (i=0;i<divErr.length;i++){
				divErr[i].className += " displayNn";
			}
			divErr = getElementsByClassName(form,'div','frm_errorV');
			for (i=0;i<divErr.length;i++){
				divErr[i].className += " separation";
			}
			if (document.getElementById(next)){
				changeTab(document.getElementById(next));
			}else{
				document.forms[0].submit();
			}
		}else{
			var divErr = getElementsByClassName(form,'div','frm_error');
			for (i=0;i<divErr.length;i++){
				divErr[i].className = divErr[i].className.replace(/displayNn/g,"");
			}
			divErr = getElementsByClassName(form,'div','frm_errorV');
			for (i=0;i<divErr.length;i++){
				divErr[i].className = divErr[i].className.replace(/separation/g,"");
			}
		}
	},

	checkText:function(inp){
		var val = (inp.value) ? inp.value : "";
		if (val=="") {
			return true;
		}else{
			return false;
		}
	},

	checkNum:function(inp){
		var val = inp.value;
		if (isNaN(val) || val<=0){
			return true;
		}else{
			return false;
		}
	},
	
	checkMail:function(inp){
		var val = (inp.value) ? inp.value : "";
        return !/[\w\-\÷]+(\.[\w\-\÷]+)*@[\w\-]+(\.[\w\-]+)*\.[\w\-]{2,}$/i.test(val);
	},

	checkDate:function(inp){
		var val = (inp.value) ? inp.value : "";
		return !/([012]\d|3[01])\/(0\d|1[012])\/(200[789]|20[123][0\d])/.test(val);
	},
	
	checkPhone:function(inp){
		var val = (inp.value) ? inp.value : "";
		return !/^[+\w](\d){6,12}$/.test(val);
		},

	checkZip:function(inp){
		inp.value = (inp.value) ? inp.value : "";
		if (inp.value.length==4){
			inp.value= "0"+inp.value;
			dept(inp,'region');
		}
		return !/(\d\d\d\d\d)|(2[ABab]\d\d\d)/.test(inp.value);
	},
		
	checkSelect:function(sel){
		var val = (sel.selectedIndex) ? sel.selectedIndex : 0;
		if (val==0){
			return true;
		}else{
			return false;
		}
	},

	checkBox:function(inp){
		var x=inp;
		var check;
		if (!x.checked){
			check = false;
		}else{
			check = true;
		}

		return check;
	},

	checkGroup:function(gp){
		var j=0;
		var allCheck = formval.checkBox(gp[j]);
		for (j=0;j<gp.length;j++){
			var x=gp[j];

			if (!formval.checkBox(x) && !allCheck){
				allCheck = false;
			}else if (formval.checkBox(x) && !allCheck){
				allCheck = true;
			}

			if (formval.checkBox(x) && x.className.match(/\bgotoAssociatedText\b/)){
				var label = x.getAttribute('id');
				var inp = formval.focusElm(x,'input');

				if (inp.getAttribute('type') == "text" && inp.className.match(/\bfrm_other\b/)){
					if (inp.value == ""){
						formval.focusElm(x,'label').className += " hasAnError";
						allCheck = false;
					}else{
						formval.focusElm(x,'label').className = formval.focusElm(x,'label').className.replace(/hasAnError/g,"");
						allCheck = true;
					}
				}
			}else if(!formval.checkBox(x) && x.className.match(/\bgotoAssociatedText\b/)){
				var inp = formval.focusElm(x,'input');
				formval.focusElm(x,'label').className = formval.focusElm(x,'label').className.replace(/hasAnError/g,"");
				if (inp.getAttribute('type') == "text" && inp.className.match(/\bfrm_other\b/)){
					inp.value="";
				}
			}
		}

		return allCheck;
	},

	checkVal:function(form){
		var inp=formval.getAllInput(form,'text');
		var error = false;

		if (inp.in_array($('spr')) && inp.in_array($('spu')) && inp.in_array($('pli')) && inp.in_array($('ent')) && inp.in_array($('pme')) && inp.in_array($('tpe')) && inp.in_array($('gco'))){

			var inpT = new Array($('spr'),$('spu'),$('pli'),$('ent'),$('pme'),$('tpe'),$('gco'));
			var inpTN = new Array();

			for (m=0;m<inpT.length;m++){
				if (isNaN(inpT[m].value)){
					error=true;
					console.log(formval.focusElm(inpT[m],'label',true).className,inpT[m]);
					formval.focusElm(inpT[m],'label',true).className+=" hasAnError";
					console.log(formval.focusElm(inpT[m],'label',true).className,inpT[m]);
					inpTN[m] = false;
				}else{
					inpTN[m] = true;
					formval.focusElm(inpT[m],'label',true).className=formval.focusElm(inpT[m],'label',true).className.replace(/hasAnError/g,"");
				}
			}

			var spr = new Number($('spr').value);
			var spu = new Number($('spu').value);
			var pli = new Number($('pli').value);
			var ent = new Number($('ent').value);
			var pme = new Number($('pme').value);
			var tpe = new Number($('tpe').value);
			var gco = new Number($('gco').value);

			if (inpTN[0] && inpTN[1] && (spr+spu)>100){
				formval.focusElm($('spr'),'label',true).className+=" hasAnError";
				formval.focusElm($('spu'),'label',true).className+=" hasAnError";
				error=true;
			}else if (inpTN[0] && inpTN[1] && (spr+spu)<=100){
				formval.focusElm($('spr'),'label',true).className=formval.focusElm($('spr'),'label',true).className.replace(/hasAnError/g,"");
				formval.focusElm($('spu'),'label',true).className=formval.focusElm($('spu'),'label',true).className.replace(/hasAnError/g,"");
			}

			if (inpTN[2] && inpTN[3] && (pli+ent)>100){
				formval.focusElm($('pli'),'label',true).className+=" hasAnError";
				formval.focusElm($('ent'),'label',true).className+=" hasAnError";
				error=true;
			}else if (inpTN[2] && inpTN[3] && (pli+ent)<=100){
				formval.focusElm($('pli'),'label',true).className=formval.focusElm($('pli'),'label',true).className.replace(/hasAnError/g,"");
				formval.focusElm($('ent'),'label',true).className=formval.focusElm($('ent'),'label',true).className.replace(/hasAnError/g,"");
			}

			if (inpTN[4] && inpTN[5] && inpTN[6] && (pme+tpe+gco)>100){
				formval.focusElm($('pme'),'label',true).className+=" hasAnError";
				formval.focusElm($('tpe'),'label',true).className+=" hasAnError";
				formval.focusElm($('gco'),'label',true).className+=" hasAnError";
				error=true;
			}else if (inpTN[4] && inpTN[5] && inpTN[6] && (pme+tpe+gco)<=100){
				formval.focusElm($('pme'),'label',true).className=formval.focusElm($('pme'),'label',true).className.replace(/hasAnError/g,"");
				formval.focusElm($('tpe'),'label',true).className=formval.focusElm($('tpe'),'label',true).className.replace(/hasAnError/g,"");
				formval.focusElm($('gco'),'label',true).className=formval.focusElm($('gco'),'label',true).className.replace(/hasAnError/g,"");
			}
		}

		return error;
	},

	checkNbrCarac:function(inp,nbr){
		var val = inp.value;
		if (val.length!=nbr){
			return true;
		}else{
			return false;
		}
	},
	
	checkMinCarac:function(inp,nbr){
		var val = inp.value;
		if (val.length<nbr){
			return true;
		}else{
			return false;
		}
	},
	
	checkMaxCarac:function(inp,nbr){
		var val = inp.value;
		if (val.length>nbr){
			return true;
		}else{
			return false;
		}
	},

	getAllInput:function(form,type){
		var inpT = new Array();
		var inp = form.getElementsByTagName("input");
		for (k=0;k<inp.length;k++){
			var x=inp[k];
			if (x.getAttribute("type")==type){
				inpT.push(x);
			}
		}
		return inpT;
	},

	getAllSel:function(form){
		return form.getElementsByTagName("select");
	},

	getAllTextarea:function(form){
		return form.getElementsByTagName("textarea");
	},

	getAllGroup:function(form){
		var allGp = new Array();
		var gp = new Array();
		var gpName;
		var inp = formval.getAllInput(form,'checkbox');
		for (l=0;l<inp.length;l++){
			var x=inp[l];
			if (l==0){
				gpName = x.getAttribute('name');
				gp.push(x);
			}else{
				if (x.getAttribute('name') == gpName){
					gp.push(x);
				}else{
					gpName = x.getAttribute('name');
					allGp.push(gp);
					gp = new Array();
					gp.push(x);
				}
			}
		}
		if (gp.length>0) allGp.push(gp);
		
		return allGp;
	},
	
	focusElm:function(elm,baliseName,after, id){
		if (after==null) after=true;
		if (id==null) id="";
		var returnElm = elm;
		var arret = false;
		baliseName = baliseName.toUpperCase();
		
		if (id==null || id==""){
			while (!arret){
				(after) ? returnElm=returnElm.nextSibling : returnElm=returnElm.previousSibling;
				if (returnElm.nodeName==baliseName){
					return returnElm;
					arret=true;
				}
			}
		}else{
			return $(id);
		}
	},
	
	mailExist:function (elm,bool){
		formval.error=bool;
		var arr = getElementsByClassName(document,'div','frm_emailError');
		if (bool){
			elm.value="";
			formval.focusElm(elm,'label',false).className+=" hasAnError";
			for (i=0;i<arr.length;i++){
				arr[i].className = arr[i].className.replace(/displayNn/g,"");
			}
		}else{
			formval.focusElm(elm,'label',false).className = elm.className.replace(/hasAnError/g,"");
			for (i=0;i<arr.length;i++){
				arr[i].className = arr[i].className+=" displayNn";
			}
		}
	}
}

Array.prototype.in_array = function(valeur) {
	var i = 0;
	while (i < this.length) {
		if (this[i] == valeur) break;
			else i++;
	}
	return !(i == this.length);
}

/*calcul command point*/
function calc(nbr1,nbr2){
	if (nbr1 && nbr2 && !isNaN(nbr1) && !isNaN(nbr2)){
		var sel = document.getElementById('nbrUnite');
		var err = document.getElementById('error');
		var total = sel.options[sel.selectedIndex].value*nbr1;
		var exist=true;
		
		document.getElementById('ppu').value = total;
		if(err.className.match(/\bdisplayNn\b/) == null){
			exist=false;
		}
		if (total<=nbr2 && !exist){
			err.className += " displayNn";
					document.getElementById('submit').setAttribute("onclick","document.getElementById('showOrderForm').submit(); return false;");
		}else if(total>nbr2 && exist){
			err.className = err.className.replace(/displayNn/g,'');
			document.getElementById('submit').setAttribute("onclick","");
			return false;
		}
	}else{
		return false;
	}
}

function stopEvent(e) {
	if(e && e.stopPropagation && e.preventDefault) {
		e.stopPropagation();
		e.preventDefault();
	}
	else if(e && window.event) {
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
	return false;
}

function skinCheckableInput(label){
	var For = label.getAttribute("for") || label.htmlFor;
	var input = $(For);
	addEvent(input,'click', function(){
		if(typeof(this.onclick) == "function"){
			this.onclick();
		}
	});
	
	var className = "check"; 
	
	if(input.checked) addClass(label,className);
	else removeClass(label,className);
	
	addEvent(label,'click',function(e){
		if(input.getAttribute("type") == "radio"){
			stopEvent(e);
			var name = input.getProperty("name");
			var inputs = this.getParent("form").getElements("input[name="+name+"]")
			
			// si l'element est deja checked
			if (hasClass(this,className)) {
				removeClass(this,className);
				input.checked = false;
			} 
			// sinon
			else {
				inputs.each(function(inp){
					var lab = inp.get('for') ? $(getLabel(inp)) : inp.getParent();
					if(hasClass(lab,className)) removeClass(lab,className);
					inp.checked = false;
					if(typeof(inp.onclick) == "function") inp.onclick();
				});
				addClass(this,className);
				input.checked = true;
			}
		// si input type="checkbox"
		} else if(input.getAttribute("type") == "checkbox"){			
			stopEvent(e);
			// si l'element est deja checked
			if(hasClass(this,className)){
				removeClass(this,className);
				input.checked = false;
			}
			// sinon
			else{
				addClass(this,className);
				input.checked = true;
			}
		}
	});
}