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 = 'none';
	this.redColorBox = 'inline';
	this.ajax = false;
	//Initializing
	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","La quantitée 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."];
	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 quantity 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"];
	//Validate form
	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','^[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++]],['message','^.{2, }$',warningList[this.language][increment++]], ['check','^.{2, }$',warningList[this.language][increment++]], ['clone','^.{254,255}$',warningList[this.language][increment++]]]
		function queryResult(x,color,warning) {
			//source[x].style.display = color;

			if (document.getElementById('war_'+source[x].name)) {
				document.getElementById('war_'+source[x].name).style.display = color;
				document.getElementById('war_'+source[x].name).title = 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].name != null && source[i].name.search(shortRegex) != -1) {
						if (source[i].name.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)) {
								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(ident,type,style,row) {
		ident = typeof(ident) != 'undefined' ? ident : 'generic';
		type = typeof(type) != 'undefined' ? type : 'text';
		style = typeof(style) != 'undefined' ? style : 'intext';
		row = typeof(row) != 'undefined' ? row : 5;
		if (type == 'textarea') opt = '<textarea name="'+ident+'" rows="'+row+'" class="'+style+'" id="'+ident+'" cols="" style="overflow:auto;" ></textarea>';
		else opt = '<input name="'+ident+'" type="'+type+'" id="'+ident+'" class="'+style+'" />';
		document.write(opt+'<'+this.warningTag+' id="war_'+ident+'" class="error"></'+this.warningTag+'><br />');
	}
} // END classValidForm()

function showAlert(x,a,y,z) {
		a = typeof(a) != 'undefined' ? a : '';
		x = typeof(x) != 'undefined' ? x : '';
		y = typeof(y) != 'undefined' ? y : 'alertContent';
		z = typeof(z) != 'undefined' ? z : 'alertBox';
		BrowserDetect.init();
		if (BrowserDetect.browser == 'Explorer' && BrowserDetect.version < 7) document.getElementById(z).style.height = screen.height-170+'px';
		if (document.getElementById(z).style.visibility == 'hidden') {
			document.getElementById(z).style.visibility = 'visible';
			document.getElementById(y).style.visibility = 'visible';
			document.getElementById(z).style.filter = 'alpha(opacity=80)';
			document.getElementById(y).innerHTML = '<div>'+x+'</div><div id="messageClose">	<form method="post" action=""><input type="button" value="Fermer" class="loginBtn" onclick="showAlert()" /></form></div>';	
		} else {
			document.getElementById(z).style.visibility = 'hidden';
			document.getElementById(y).style.visibility = 'hidden';
		}
}

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 confirmOperation(x,y,z) {
	z = typeof(z) != 'undefined' ? z : '';
	if (confirm(z) == false) return false;
	x.option.value = y;
	x.submit();
}

function callAjax(variable,target,script,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';
	x = document.getElementById(target);
	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 = 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) 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;
}
//Trust me, leave a space here

function Folder() {
	this.img = 'smile.gif';
	this.href = '';
	this.contain = 'content';
	this.height = 36;
	this.width = 36;
	Folder.prototype.display = function() {
		root = typeof(root) != 'undefined' ? root : '/';
		var x = document.getElementById(this.contain);
		var y = document.createElement('div');
		//y.setAttribute('id',id);
		y.setAttribute('style','position: relative; width: '+this.width+'px;');
		y.setAttribute('ondblclick',this.href);
		//y.outerHTML = '<div>aaaa</div>';
		y.innerHTML = '<img src="'+root+'images/'+this.img+'" height="'+this.height+'" width="'+this.width+'" alt="">';
		//alert(y.getElementsByTagName('img')[0].src);

		//y.setAttribute('onclick',this.swapImg());
		x.appendChild(y);
		DragHandler.attach(y);
	}
	/*Folder.prototype.swapImg = function() {
		this.inheritFrom = superClass;
  this.inheritFrom();
		var src = y.getElementsByTagName('img')[0].src;
		alert(src);
	}*/
}

//Browser detection
//BrowserDetect.browser
//BrowserDetect.version
//BrowserDetect.OS

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 Clickheretoprint(x) {
 x = typeof(x) != 'undefined' ? x : 'printer';
 var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,";
     disp_setting+="scrollbars=yes,width=1024, height=768, left=100, top=25";
 var content_vlue = document.getElementById(x).innerHTML;

 var docprint=window.open("","",disp_setting);
  docprint.document.open();
  docprint.document.write('<html><head><title>Poker League</title>');
  docprint.document.write('<link rel="stylesheet" href="/<?=ROOT_PATH?>css/print.css"/></head><body onLoad="self.print()"><left>');
  docprint.document.write(content_vlue);           
  docprint.document.write('<p class="close"><a href="javascript:window.close();">Close window</p></left></body></html>');
  docprint.document.close();
  docprint.focus();
}
