<!--
function confirmDiv(message, content, effect, query){
	var div = $(content);
	div.innerHTML  = '<p class="menu">'+message+'<br><br></p>';
	div.innerHTML += '<a href="'+query+'" class="gros">Oui</a>&nbsp;&nbsp;<a href="#" class="gros" onclick="Element.hide(\''+effect+'\'); return false;">Non</a>';
	new Element.show(effect);
}

function confirmNoChange(msg){
	return confirm(msg);
}

function fermerDivErreur(div){
	Element.hide(div);
	return false;
}    


var Validation = {
  permisquebec : function(str) {
    return str.match(/^[a-zA-Z]{1}[0-9]{4}-[0-9]{6}-[0-9]{2}$/);
  },
  
  email : function(str) {
    return str.match('^[-a-z0-9!#$%&\'*+/=?^_<{|}~]+(\.[-a-zA-Z0-9!#$%&\'*+/=?^_<{|}~]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9-]{2,}$');
  },
  
  number : function(str) {
    return str.match(/^[0-9]+$/);
  },
  
  numberNegative : function(str) {
    return str.match(/^-?[0-9]+$/);
  },
  
  numberPositive : function(str) {
  	return str.match(/^[1-9]{1}[0-9]*$/);
  },
  
  string : function(str) {
    return str.match(/^[A-Za-zàÀèÈùÙâÂêÊîÎôÔûÛéÉçÇ -]+[A-Za-zàÀèÈùÙâÂêÊîÎôÔûÛéÉçÇ -\.?]*$/);
  },
  
  question : function(str) {
  	return str.match(/^[A-Za-zàÀèÈùÙâÂêÊîÎôÔûÛéÉçÇ'\,\:\? -]+$/);
  },
    
  numEntrepriseQuebec: function(str) {
    return str.match(/^[0-9]{10}$/);
  },
  
  NIR : function(str) {
    return str.match(/^[R][-][0-9]{6}[-][0-9]$/);
  },
  
  date : function(str) {
    return str.match(/^[0-9]{2}[-][0-9]{2}[-][0-9]{4}$/);
  },
  
  telephone : function(str) {
    return str.match(/^[0-9]{3,3}[-][0-9]{3,3}[-][0-9]{4,4}$/);
  },
  
  codePostal : function(str) {
    return str.match(/^[A-Za-z][0-9][A-Za-z] [0-9][A-Za-z][0-9]$/);
  },
  
  notEmpty : function(str) {
    return str != '';
  },
  
  nothing: function(){
  	return true;
  },
  
  nas: function(str){
	return str.match(/^[0-9]{3} [0-9]{3} [0-9]{3}$/);
  },
  
  float: function(str){
  	return str.match(/^[-]?[0-9]+(\.[0-9]{2})?$/i);
  },
  
  posFloat: function(str){
  	return str.match(/^[0-9]+(\.[0-9]{1,2})?$/i);
  },
  
  negFloat: function(str){
  	return str.match(/^[-][0-9]+(\.[0-9]{2})?$/i);
  }
}



Abstract.inputRegister = function(){};
Abstract.inputRegister.prototype = {
	form : null,
	inputs: new Array(),
	register: new Array(),
	
	initialize: function(trigger) {
		this.register = new Array();
	    inputs = $A(this.inputs);
	    for(i=0; i < inputs.length; i++){
	    	input = inputs[i];
			if(input){
			 	this.registerinput(input[0], input[1], input[2]);
			}
	    }
    	
    	this.form = this.form ? $(this.form) : document.forms[0];
    	
    	this.form.onreset = function(){
    								this.clearError();
    								this.clearErrorSpecial();
    								Element.scrollTo(this.form);
    						   }.bind(this);
		this.form.onsubmit = function(){
									var valid  = this.trigger('onblur');
									var valid2 = this.validateSpecial();
									if(valid &&  valid2){
										return this.onSubmit();
									}else{
										alert('Une erreur est survenue dans le formulaire...');
										Element.scrollTo(this.form);
										return false;		
									}
									
								}.bind(this);
		
		if(trigger){
			this.trigger('');
		}
  	},
	
	trigger: function(event){
		var valid = true;
		for(i=0; i<this.register.length; i++){
			if(!this.register[i].onblur()){
				valid = false;
			}
		}
		return valid;
	},
	
	validateSpecial: function (){
		return true;
	},
	
	onSubmit: function (){
		return true;
	},

	validInputText: function () {
	   	var div = this.errDiv ? $(this.errDiv) : null;
   		if( this.validType(this.value) ){
   		
   			this.className = 'inputnormal';
	   		if(this.errMsg && div){
   				Element.hide(this.errDiv);
   			}
	   		return true;
   		}else{
	   		if(this.errMsg){
	   			this.className = 'inputerror';   
				Element.show(this.errDiv);
				return false;
   			}else{
   				this.className = 'inputnormal';   
   				return true;
   			}
   		}
	},
	
	inputFocusText: function(){
		this.className = 'inputover'; 
		if(this.errMsg){
			if($(this.errDiv)){
		   		Element.hide(this.errDiv);
			}
		}
	},
	
	registerinput: function (element, validFunc, errMsg){
		var el = $(element);
		var nbtd = $A(el.parentNode.getElementsByTagName('td')).length;
		//var nbtd = el.parentNode.parentNode.childNodes.length;
		var tr;
		var td;
		//var td2 = document.createElement('td');
		var div;
		
		el.className = 'inputnormal';
		el.validType = validFunc;
		el.errMsg = errMsg;
		el.errDiv = 'err'+element; 
		el.onfocus = this.inputFocusText;
		el.onblur  = this.validInputText;
				
		if(errMsg){
			div = document.createElement('div');
			div.id = el.errDiv;
			div.className = 'error';
			div.innerHTML = el.errMsg;
			div.setAttribute('align', 'right');

			td = document.createElement('td');
			td.setAttribute('colspan', nbtd);
			//td.colspan= nbtd;
			td.setAttribute('align', 'right');
			td.appendChild(div);
			
			tr = document.createElement('tr');
			tr.setAttribute('height', '15px');
			tr.setAttribute('align', 'right');
			
			/*for(var i=0; i < nbtd; i++){
				alert(i);
				tr.appendChild(td2);
			}*/
			tr.appendChild(td);
			
			//tr.innerHTML = '<td colspan="100%" align="right"><div class="error" id="'+el.errDiv+'">'+el.errMsg+'</div></td>'; 
			
			el.parentNode.parentNode.parentNode.insertBefore(tr, el.parentNode.parentNode);
			Element.hide(el.errDiv);
		}

		this.register.push(el);
	},
	
	clearError: function(){
		for(i=0; i<this.register.length; i++){
			if(this.register[i].errMsg){
				Element.hide(this.register[i].errDiv);
			}
			this.register[i].className = 'inputnormal';
		}
	},
	
	clearErrorSpecial: function(){}
}


DivTitle = Class.create();
DivTitle.prototype = {
	initialize: function(element, msg, maxWidth) {
    	this.maxWidth = !isNaN(maxWidth) ? maxWidth : 300;
        this.element = $(element);
    
    	var div = document.createElement('div');
	    div.id = 'divtitle'+ this.element.id;
    	div.style.display = 'none';
	    div.style.position = 'absolute';
	    div.style.width = this.maxWidth + 'px';
    
		//alert((this.element.offsetTop + 20)+'px'+ (this.element.offsetLeft + 20)+'px');
    
	    var table = document.createElement('table');
	    table.style.border = '1px solid #000000';
    	table.style.background = '#FFFFFF';
    	var tbody = document.createElement('tbody');
	    var tr = document.createElement('tr');
    	var td = document.createElement('td');

	    td.innerHTML = msg;
    	tr.appendChild(td);    
	    tbody.appendChild(tr);
    	table.appendChild(tbody);
		div.appendChild(table)
    	document.body.appendChild(div);

		var a = Element.getDimensions(div.id);
		//alert(a.width + ' ' + a.height);    
		div.style.left =  (findPosX(this.element) + 20)+'px';
    	div.style.top = (findPosY(this.element) - 5 - a.height)+'px';
    
	    this.element.onmouseover = this.onmouseover.bind(this);
    	this.element.onmouseout  = this.onmouseout.bind(this);
    
	  },
  
	onmouseover: function() {
  		this.timer = setTimeout('Element.show(\'divtitle'+ this.element.id +'\');', 500);
	},
  
	onmouseout: function() {
		clearTimeout(this.timer);
		Element.hide('divtitle'+ this.element.id)
	}
  
}

function resetDiv(divname){var d = $(divname);d.innerHTML = '';} 
function loadDiv(divname, loaddiv){
	var thediv = $(divname);
	var div = $(loaddiv);	
	if(!thediv){
		alert('DIV ' + divname + ' not found ...');
		return;
	}
	if(!div){
		alert('DIV ' + loaddiv + ' not found ...');
		return;
	}
	thediv.innerHTML = div.innerHTML;
} 

var Util = new Object();

Util.fermerdiv = function (div){
	Element.hide(div);
	
	return false;
}

Util.selectBoxFinder = Class.create();
Util.selectBoxFinder.prototype = {
	options: new Array(),
	select : null,
	inputtext : null,
	
	initialize: function(selectElement, inputElement) {
		this.select = $(selectElement);
		this.inputtext = $(inputElement);
		this.options = new Array();

	    var op = $A(this.select.getElementsByTagName('option'));
	    for(i=0; i < op.length; i++){
	        this.options[i] = op[i].innerHTML;
	    }
		this.inputtext.onkeyup = this.find_in_select_box.bind(this);
	},
  
	find_in_select_box: function(){
		var needle = this.inputtext.value;
		for(i=0;i<this.options.length;i++){
			if(needle.toLowerCase() == (this.options[i].substr(0,needle.length)).toLowerCase()){
				this.select.selectedIndex = i;
				return true;
			}
		}
		this.select.selectedIndex = -1;
		return false;
	}
}

var toggleInfo = {
	toggle: function(idinfo, idimg, suffix){
		if(!suffix) suffix = '';
		if(Element.visible(idinfo)){
			Element.hide(idinfo);
			$(idimg).src='images/fleche_bas'+suffix+'.gif';
			setcookie('__'+idinfo, 0, null, '/');
		}else{
			Element.show(idinfo);
			$(idimg).src='images/fleche_haut'+suffix+'.gif';		
			setcookie('__'+idinfo, 1, null, '/');
		}
	},
	
	checkCookie: function(id){
		var cookie = getcookie('__'+id);
		$(id+'Img').src = 'images/' + (cookie == '1' ? 'fleche_haut.gif' : 'fleche_bas.gif');
		$(id).style.display = cookie == '1' ? '':'none';
	}
}


Util.ErrorMsgBox = Class.create();
Util.ErrorMsgBox.prototype = {
	id : '',
	message: new Array(),
	innerhtml : '',
	
	initialize: function(id, msg) {
		this.id = $(id);
		//TODO if this.id is span or div, otherwise, position absolute?
		this.message = msg;
		this.id.style.display = msg.length == 0 ? 'none':'inline'; 
		this.id.onclick = function() {this.id.style.display = 'none'}.bind(this);
		
		this.innerhtml = '<div align="center" class="divmessages">' + msg + '</div>';
		this.id.innerHTML = this.innerhtml;
		//TODO if Rico
		Rico.Corner.round(this.id.firstChild);
	},
	
	update: function(msg){
		this.id.innerHTML = '<div align="center" class="divmessages">' + msg + '</div>';
		this.id.style.display = '';
		Rico.Corner.round(this.id.firstChild);
	}
}

Util.AjaxResponse = function(req){
	var response = req.responseText.stripScripts();
    var split = response.split('::');
    if(split[0].indexOf('ok') == 0  ){
    	window.location.href = split[1];
    }else{
    	alert(split[1]);
    }
}

-->