function classValidForm(source,language,arg,mail,opt) { //ver 1.0
/*
Author: Vincent Germain
Usage : ['regexShort','regexLong','warning',optionnal]
-regexShort: Detect if the form object name contain a specific word
-regexLong: Filther the main regular expression
-warning: Call the error message in case user input fail verification (set in warningList)
-optionnal: Set to false if the input is optionnal

Specific:
-objList[0][1]: Exclude any other objList[i++][0]
*/
	var warningList = new Array();
	warningList['fr'] = ['Ce champs n\'est pas valide.','Le numéro de téléphone n\'est pas valide','Le numéro de fax n\'est pas valide','Votre courriel est invalide.','Le code postal n\'est pas valide','Le chiffre n\'est pas valide','L\'extension du fichier doit être .jpg','Ce nom d\'utilisateur n\'est pas valide','Les deux mots de passe diffèrent.','Vous devez accepter les termes du contrat pour vous inscrire.']
	warningList['en'] = ['This field is not valid','The phone number is not valid','The fax number is not valid','The mail is not valid','The postal code is not valid','The number is not valid','The extension must be .jpg','This username is not valid','The password is different','You must accept the term of use']
	var increment = 0;
	var objList = [['generic','^.{2,255}$',warningList[language][increment++]],['phone','^(?:\\([2-9]\\d{2}\\)\\ ?|[2-9]\\d{2}(?:\\-?|\\ ?))[2-9]\\d{2}[- ]?\\d{4}$',warningList[language][increment++]],['fax','^(?:\\([2-9]\\d{2}\\)\\ ?|[2-9]\\d{2}(?:\\-?|\\ ?))[2-9]\\d{2}[- ]?\\d{4}$',warningList[language][increment++]],['mail','^[0-9a-zA-Z][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$',warningList[language][increment++]],['postal','(^\\d{5}(-\\d{4})?$)|(^[ABCEGHJKLMNPRSTVXY]{1}\\d{1}[A-Z]{1} *\\d{1}[A-Z]{1}\\d{1}$)',warningList[language][increment++]],['quant','^[0-9]{1,}$',warningList[language][increment++]],['avatar','^(.*\\.(j|J)(p|P)(g|G))$',warningList[language][increment++]],['username','^[a-z0-9]{2,12}$',warningList[language][increment++]],['nolimit','^.{2,}$',warningList[language][0]]];
	
	var greenColorBox = '#FFF';
	var redColorBox = '#FFFEDD';
//Don't edit beyond this point
	var warningDiv = document.getElementsByTagName('span');
	var sendFlag = true;
	function validForm() {
		for (var i=0;i<source.length;i++) {
			if (source[i].type != 'button' && source[i].type != 'submit' && source[i].type != 'hidden' && source[i].type != 'radio' && source[i].type != 'checkbox') {
				for (var j=0;j<objList.length;j++) {
					var shortRegex = new RegExp(objList[j][0],'i');
					if (source[i].name != null && source[i].name.search(shortRegex) != -1) {
						if (source[i].name.search(/true/i) != -1 || source[i].value != '') {
							var longRegex = new RegExp(objList[j][1],'i');
							if (source[i].value.search(longRegex) != -1) {
								queryResult(i,greenColorBox,'');
							} else {
								queryResult(i,redColorBox,objList[j][2]);
								sendFlag = false;
							}
						} else {
							queryResult(i,greenColorBox,'');
						}
					}
				}
			}
		}
		if (sendFlag == true) {
			return true;
		} else {
			return false;
		}
	}
	if (arg == 1) {
		verifCheck(language);
		verifPass(language);
	} else if (arg == 2) {
        if (document.getElementById('desc').value.length > 5000 || document.getElementById('desc').value == '') {
            if (language == 'fr') {
                document.getElementById('war_desc').innerHTML = 'Ce champ n\'est pas valide';
            } else {
                document.getElementById('war_desc').innerHTML = 'This field is not valid';
            }
           sendFlag = false;
        } else {
			document.getElementById('war_desc').innerHTML = '';
		}
	}
	function queryResult(x,color,warning) {
		source[x].style.background = color;
		document.getElementById('war_'+source[x].name).innerHTML = warning;
	}
    
    function verifPass(x) {
		if (source.pass.value != source.generic_password_true.value || source.pass.value == '') {
			source.pass.style.background = redColorBox;
			document.getElementById('war_pass').innerHTML = warningList[x][8];
            sendFlag = false;
		} else {
			source.pass.style.background = greenColorBox;
			document.getElementById('war_pass').innerHTML = '';
		}
	}

    function verifCheck(x) {
		if (source.term.checked == false) {
			source.term.style.background = redColorBox;
			document.getElementById('war_term').innerHTML = warningList[x][9];
			sendFlag = false;
		} else {
			document.getElementById('war_term').innerHTML = '';
		}
    }
	
	return validForm();
} // END classValidForm()

function Form() { //ver 1.0
/*
Author: Vincent Germain
Usage : ['regexShort','regexLong','warning',optionnal]
-regexShort: Detect if the form object name contain a specific word
-regexLong: Filther the main regular expression
-warning: Call the error message in case user input fail verification (set in warningList)
-optionnal: Set to false if the input is optionnal

Specific:
-objList[0][1]: Exclude any other objList[i++][0]
*/

	//Constructor
	this.language = 'fr';
	this.warningTag = 'div';
	this.greenColorBox = '#fff';
	this.redColorBox = '#ccc';
	this.ajax = false;
	//Initializing
	var warningList = new Array();
	warningList["fr"] = ["Ce champ n'est pas valide","Le numéro de téléphone n'est pas valide","Le numéro de fax n'est pas valide","Votre courriel est invalide","Le code postal n'est pas valide","Ce champ n'est pas valide","L'extension du fichier doit être .jpg","Ce nom d'utilisateur n'est pas valide","Ce lien n'est pas valide","Le message est invalide","Vous devez accepter les termes du contrat pour vous inscrire.","Les deux mots de passe diffèrent.","Ce champ doit être une valeur monétaire"];
	warningList["en"] = ["This field is not valid","The phone number is not valid","The fax number is not valid","The mail is not valid","The postal code is not valid","This field is not valid","The extension must be .jpg","This username is not valid","This link is not valid","Your message is invalid","You must accept the term of use","The password is different","This field must be a currency value"];
	//Validate form
	Form.prototype.create = function(source) {
		for (var i=0;i<source.length;i++) source[i].insertAdjacentHTML('afterEnd',' <span id="war_'+source[i].id+'" class="error"></span>');
	}
	Form.prototype.validForm = function(source) {
		this.action = source.action;
		var increment = 0;
		var sendFlag = true;
		var warningDiv = document.getElementsByTagName(this.warningTag);
		var objList = [['generic','^.{2,255}$',warningList[this.language][increment++]],['phone','^(?:\\([2-9]\\d{2}\\)\\ ?|[2-9]\\d{2}(?:\\-?|\\ ?))[2-9]\\d{2}[- ]?\\d{4}$',warningList[this.language][increment++]],['fax','^(?:\\([2-9]\\d{2}\\)\\ ?|[2-9]\\d{2}(?:\\-?|\\ ?))[2-9]\\d{2}[- ]?\\d{4}$',warningList[this.language][increment++]],['mail','^[a-zA-Z][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$',warningList[this.language][increment++]],['postal','(^\\d{5}(-\\d{4})?$)|(^[ABCEGHJKLMNPRSTVXY]{1}\\d{1}[A-Z]{1} *\\d{1}[A-Z]{1}\\d{1}$)',warningList[this.language][increment++]],['quant','^[0-9]{1,}$',warningList[this.language][increment++]],['avatar','^(.*\\.(j|J)(p|P)(g|G))$',warningList[this.language][increment++]],['username','^[a-z0-9]{2,12}$',warningList[this.language][increment++]],['link','(http://|https://)([a-zA-Z0-9]+\\.[a-zA-Z0-9\\-]+|[a-zA-Z0-9\\-]+)\\.[a-zA-Z\\.]{2,6}(/[a-zA-Z0-9\\.\\?=/#%&\\+-]+|/|)',warningList[this.language][increment++]],['message','^.{2, }$',warningList[this.language][increment++]], ['check','^.{2, }$',warningList[this.language][increment++]], ['clone','^.{254,255}$',warningList[this.language][increment++]], ['money','^\\$?\\d{1,3}([ ,]?\\d{3})*(\\.\\d{0,2})?$',warningList[this.language][increment++]]]
		function queryResult(x,color,warning) {
			source[x].style.background = color;
			if (document.getElementById('war_'+source[x].id)) document.getElementById('war_'+source[x].id).innerHTML = warning;
			else if (warning != '') alert(warning);
			if (warning != '') sendFlag = false;
		}
		for (var i=0;i<source.length;i++) {
			if (source[i].type != 'button' && source[i].type != 'submit' && source[i].type != 'hidden' && source[i].type != 'radio') {
				for (var j=0;j<objList.length;j++) {
					var shortRegex = new RegExp(objList[j][0],'i');
					if (source[i].id != null && source[i].id.search(shortRegex) != -1) {
						if (source[i].id.search(/true/i) != -1 || ((source[i].type == 'checkbox' && source[i].checked == true) || (source[i].type != 'checkbox' && source[i].value != ''))) {
							var longRegex = new RegExp(objList[j][1],'i');
							if (source[i].value.search(longRegex) != -1 || (objList[j][0] == 'clone' && source[i].value == source[i+1].value && source[i].value != '') || (objList[j][0] == 'message' && source[i].value.length < 5000 && source[i].value != '') || (source[i].type == 'checkbox' && source[i].checked == true)) {
								if (source[i].type == 'select-one' && source[i].value == 'xxx') {
									queryResult(i,this.redColorBox,objList[j][2]);
									if (objList[j][0] == 'clone') queryResult(i+1,this.redColorBox,objList[j][2]);									
								} else {
									queryResult(i,this.greenColorBox,'');
									if (objList[j][0] == 'clone') queryResult(i+1,this.greenColorBox,'');
								}
							} else {
								queryResult(i,this.redColorBox,objList[j][2]);
								if (objList[j][0] == 'clone') queryResult(i+1,this.redColorBox,objList[j][2]);
							}
						} else queryResult(i,this.greenColorBox,'');
					}
				}
			}
		}
		if (sendFlag == true) {
			if (this.ajax == true) {
				callAjax(source,this.action);
				return false;
			} else return true;
		}
		return false;
	}
	Form.prototype.generateInputForm = function(name,ident,type,req) {
		ident = typeof(ident) != 'undefined' ? ident : 'generic';
		type = typeof(type) != 'undefined' ? type : 'text';
		req = typeof(req) != 'undefined' ? req : '';
		if (req != '') req = '_true';
		document.write('<input name="'+ident+'_'+name+req+'" type="'+type+'" id="'+ident+'_'+name+req+'" /><'+this.warningTag+' id="war_'+ident+'_'+name+req+'"></'+this.warningTag+'>');
	}
} // END classValidForm()

function initForms(x,y) {
	x = typeof(x) != 'undefined' ? x : 'validate';
	y = typeof(y) != 'undefined' ? y : 'en';
	var source = document.getElementsByClassName(x);
	form = new Array();
	for (var i=0;i<source.length;i++) {
		form[i] = new Form();
		form[i].create(source[i]);
		form[i].language = y;
		source[i].onsubmit = new Function("return form["+i+"].validForm(this);");
	}
}

function seeTrought(x) {
	if (navigator.appVersion.search('MSIE 6.0') != -1) {
		for (i=0;i<document.getElementsByTagName('select').length;i++) {
			document.getElementsByTagName('select')[i].style.visibility = x;
		}
	}
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

function generateInput (x,y,z,name,target) {
	target = typeof(target) != 'undefined' ? target : 'target';
	var val;
	var list = new Array();
	var html = '';
	var num = name.length;
	for (j=0;j<num;j++) list[j] = new Array();
	if (document.getElementById(target)) {
		if (x.value < 1) document.getElementById(target).style.display = 'none';
		else document.getElementById(target).style.display = 'block';
		for (i=0;i<x.value;i++) {
			for (j=0;j<num;j++) {
				if (document.getElementById(y+j+'_'+i)) list[j].push(document.getElementById(y+j+'_'+i).value);
			}
		}
		document.getElementById(target).innerHTML = '';
	}
	if (x.value > 0) {
		html = '<div class="target" id="'+target+'"><div class="generatedInp"><label></label>';
		for (j=0;j<num;j++) html += '<p>'+name[j]+'</p> ';
		html += '</div></div>';
		//x.insertAdjacentHTML('afterEnd',html);
		document.getElementById('timed').insertAdjacentHTML('afterEnd',html);
	}
	html = '';
	var locked = '';
	for (i=0;i<x.value;i++) {
		html += '<p class="generatedInp"><label>'+(i+1)+'.</label> ';
		for (j=0;j<num;j++) {
			if (list[j][i] != undefined) val = list[j][i];
			else if (list[j][i-1] != undefined) {
				val = list[j][i-1];
				locked = i-1;
			} else {
				if (locked != '') val = list[j][locked];
				else val = '';
			}
			html += '<input name="'+y+j+'_'+i+'" type="'+z+'" id="'+y+j+'_'+i+'" value="'+val+'" />';
		}
		html += ' min.</p>';
	}
	if (document.getElementById(target)) document.getElementById(target).innerHTML += html;
}

function flashInput (x,y,z) {
	for (i=0;i<x;i++) document.getElementById(y+'2_'+i).value = z;
}

//Trust me, leave a space here

function callAjax(variable,target,script,header,type) {
	if (typeof(type) == 'undefined' || type == '') type = 'POST';
	if (typeof(target) == 'undefined' || target == '') target = 'content';
	if (typeof(script) == 'undefined' || script == '') script = root+'query.php';
	if (typeof(vphp) == 'undefined' || vphp == '') vphp = 'vphp';
	if (typeof(header) == 'undefined' || header == '') header = 'application/x-www-form-urlencoded';
	if (document.getElementById(target)) x = document.getElementById(target);
	if (document.getElementById(target)) x.innerHTML = 'Please wait...'
	if (variable == '[object HTMLFormElement]') {
		list = new Array();
		var url = '';
		for (var i=0;i<variable.length;i++) {
			if (i < variable.length-1) opt = '&'; else opt = '';
			url += variable[i].id+'='+variable[i].value+opt;
		}
		variable = url;
	} else {
		variable = variable.replace(/amp;/gi, "");
		variable = unescape(variable);
	}
	var xmlhttp = false;
	/** Special IE only code ... */
	/*@cc_on
	  @if (@_jscript_version >= 5)
		  try {
			  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		  } catch (e) {
			  try {
				  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			  } catch (E) {
				  xmlhttp = false;
			  }
		 }
	  @else
		 xmlhttp = false;
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp = false;
		}
	}
	xmlhttp.open(type,script,true);
	xmlhttp.onreadystatechange = function () {
		if(xmlhttp.readyState == 4) {
			if (document.getElementById(target)) x.innerHTML = xmlhttp.responseText;
			var scripts = [];
			var script_sources = xmlhttp.responseText.split(/<script.*?>/);
			for (var i=1; i < script_sources.length; i++) scripts.push(script_sources[i].split(/<\/script>/)[0]);
           	for (var i=0; i<= scripts.length; i++) eval(scripts[i]);
		}
	}
	xmlhttp.setRequestHeader('Content-Type',header);
	//xmlhttp.setRequestHeader('Content-Type','application/x-download');
	//xmlhttp.setRequestHeader("Content-Type","text/html; charset=utf-8");
	xmlhttp.send(variable);
	return false;
}
//Trust me, leave a space here

function addItem(x,y,z) {
	/*
	a = document.getElementById(y);
	a = a.getElementsByTagName('input');
	var str = a[0].name;
	var tmp = '';
	str = str.substring(0, str.length-1);
	for (i=0;i<a.length;i++) tmp += (i+1)+'. <input name="'+a[i].name+'" type="'+a[i].type+'" size="'+a[i].size+'" value="aaa" /><br />';
	tmp += x+'. <input name="'+str+x+'" type="'+a[0].type+'" size="'+a[0].size+'" />';
	document.getElementById(y).innerHTML = tmp;
	document.getElementById(z).value = x;
	*/
	a = document.getElementById(y);
	a = a.getElementsByTagName('input')[0];
	var str = a.name;
	str = str.substring(0, str.length-1);
	document.getElementById(y).innerHTML += '<br />'+x+'. <input name="'+str+x+'" type="'+a.type+'" size="'+a.size+'" />';
	document.getElementById(z).value = x;
}

function noReturn(e) {
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     

     return (key != 13);
}
