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 = 'span';
	this.greenColorBox = '#090';
	this.redColorBox = '#F00';
	this.ajax = true;
	this.pass = false;
	this.check = false;

	//Initializing
	var warningList = new Array();
	warningList['fr'] = ['<div><p>Ce champs n\'est pas valide</p></div>','<div><p>Le numéro de téléphone n\'est pas valide</p></div>','<div><p>Le numéro de fax n\'est pas valide</p></div>','<div><p>Votre courriel est invalide</p></div>','<div><p>Le code postal n\'est pas valide</p></div>','<div><p>La quantitée n\'est pas valide</p></div>','<div><p>L\'extension du fichier doit être .jpg</p></div>','<div><p>Ce nom d\'utilisateur n\'est pas valide</p></div>','<div><p>Ce lien n\'est pas valide</p></div>','<div><p>Ce prix n\'est pas valide</p></div>','<div><p>Les deux mots de passe diffèrent.</p></div>','<div><p>Vous devez accepter les termes du contrat pour vous inscrire.</p></div>'];
	warningList['en'] = ['<div><p>This field is not valid</p></div>','<div><p>The phone number is not valid</p></div>','<div><p>The fax number is not valid</p></div>','<div><p>The mail is not valid</p></div>','<div><p>The postal code is not valid</p></div>','<div><p>The quantity is not valid</p></div>','<div><p>The extension must be .jpg</p></div>','<div><p>This username is not valid</p></div>','<div><p>This link is not valid</p></div>','<div><p>This amount is not valid</p></div>','<div><p>The password is different</p></div>','<div><p>You must accept the term of use</p></div>'];
	//Validate form
	Form.prototype.validForm = function(source) {
		this.action = source.action;
		var increment = 0;
		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','^[ABCEGHJKLMNPRSTVXY]\\d[A-Z]\\ ?\\d[A-Z]\\d$',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++]],['price','^[0-9,.]{1,}$',warningList[this.language][increment++]],['nolimit','^.{2,}$',warningList[this.language][0]]];
		function queryResult(x,color,warning) {
			document.getElementById('war_'+source[x].name).style.color = color;
			//alert(document.getElementById('war_'+source[x].name).innerHTML);
			document.getElementById('war_'+source[x].name).innerHTML = warning;
			
		}
		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,this.greenColorBox,'');
							else {
								queryResult(i,this.redColorBox,objList[j][2]);
								sendFlag = false;
							}
						} else queryResult(i,this.greenColorBox,'');
					}
				}
			}
		}
		if (this.pass == true) verifPass(source,this.language);
		if (this.check == true) verifCheck(source,this.language);
		if (document.getElementById('region') && document.getElementById('region').value == '0') {
			document.getElementById('war_region').innerHTML = 'You must choose a region';
			document.getElementById('war_region').style.color = this.redColorBox;
			sendFlag = false;
		}
		if (sendFlag == true) {
			if (this.ajax == true) {
				callAjax(source,this.action);
				return false;
			} else return true;
		}
		return false;
	}
	function verifPass(source,lang) {
		if (source.pass.value != source.generic_password_true.value || source.pass.value == '') {
			//source.pass.style.background = this.redColorBox;
			document.getElementById('war_pass').innerHTML = warningList[lang][9];
            sendFlag = false;
		} else {
			//source.pass.style.background = this.greenColorBox;
			document.getElementById('war_pass').innerHTML = '';
		}
	}

    function verifCheck(source,lang) {
		if (source.term.checked == false) {
			//source.term.style.background = this.redColorBox;
			document.getElementById('war_term').innerHTML = warningList[lang][10];
			sendFlag = false;
		} else {
			//source.term.style.background = this.greenColorBox;
			document.getElementById('war_term').innerHTML = '';
			
		}
    }
	
	if (document.getElementById('comment')) {
		if (document.getElementById('comment').value.length > 100 || document.getElementById('comment').value == '') {
			if (this.language == 'fr') {
				document.getElementById('war_comment').innerHTML = '<div class="message"><p>Ce champ n\'est pas valide</div><p>';
			} else {
				document.getElementById('war_comment').innerHTML = '<div class="message warEN"><p>This field is not valid</div><p>';
			}
		   sendFlag = false;
		} else {
			document.getElementById('war_comment').innerHTML = '';
		}
	}
		
	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 singleConfirm(target,regex,msg) {
	var shortRegex = new RegExp(regex,'i');
	if (document.getElementById(target).value.search(shortRegex) != -1) return true;
	else {
		alert(msg);
		return false;
	}
}

function verifMail(x,y) {
	var longRegex = new RegExp('^[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]$','i');
	var warningList = new Array();
	warningList['fr'] = ['Le courriel entré est invalide'];
	warningList['en'] = ['The mail is not valid'];
	if (document.getElementById(x).value.search(longRegex) != -1) return true;
	else {
		alert(warningList[y][0]);
		return false;
	}
}

function callAjax(variable,target,id,type,vphp) {
	if (typeof(type) == 'undefined' || type == '') type = 'POST';
	if (typeof(id) == 'undefined' || id == '') id = 'content';
	if (typeof(target) == 'undefined' || target == '') target = root+'index.php';
	if (typeof(vphp) == 'undefined' || vphp == '') vphp = 'vphp';
	x = document.getElementById(id);
	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].name+'='+variable[i].value+opt;
		}
		variable = url;
	} else {
		//variable.replace(/&amp\;/, "&");
		variable = variable.replace(/amp;/gi, "");
		variable = unescape(variable);
	}
	//alert(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,target,true);
	xmlhttp.onreadystatechange = function () {
		if(xmlhttp.readyState == 4){
			if (document.getElementById('sub'+id)) {
				y = document.getElementById('sub'+id);
				y.innerHTML = '';
				y.innerHTML = xmlhttp.responseText;
			}
			z = document.getElementById(vphp);
			if (z.innerHTML == 'true') x.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	//xmlhttp.setRequestHeader("Content-Type","text/html; charset=utf-8");
	xmlhttp.send(variable);
	return false;
}

function activate(source,total,active,idle) {
	if (typeof(active) == 'undefined' || active == '') active = 'activeMenu';
	if (typeof(idle) == 'undefined' || idle == '') idle = 'idleMenu';
	for (i=0;i<total;i++) {
		if (source.id == 'ser_'+i) source.className = active;
		else if (document.getElementById('ser_'+i)) document.getElementById('ser_'+i).className = idle;
	}
}

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 initPost(x,y,z) {
		z = typeof(z) != 'undefined' ? z : document.hiddenPost;
		z.option.value = x;
		z.formId.value = y;
		z.submit();
}
//BrowserDetect.browser
//BrowserDetect.version
//BrowserDetect.OS
