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 = '#f1edea';
	this.redColorBox = '#f1edea';
	this.ajax = true;
	//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>'];
	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>'];
	//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++]],['nolimit','^.{2,}$',warningList[this.language][0]]];
		function queryResult(x,color,warning) {
			source[x].style.background = color;
			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 (document.getElementById('desc')) {
			if (document.getElementById('desc').value.length > 5000 || document.getElementById('desc').value == '') {
				if (this.language == 'fr') {
					document.getElementById('war_desc').innerHTML = '<div class="message"><p>Ce champ n\'est pas valide</div><p>';
				} else {
					document.getElementById('war_desc').innerHTML = '<div class="message warEN"><p>This field is not valid</div><p>';
				}
			   sendFlag = false;
			} else {
				document.getElementById('war_desc').innerHTML = '';
			}
		}
		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 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);
	}*/
}

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 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+'process.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;
			CSBfleXcroll('mycustomscroll4');
		}
	}
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	//xmlhttp.setRequestHeader("Content-Type","text/html; charset=utf-8");
	xmlhttp.send(variable);
	return false;
}

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 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;
	}
}

function showAlert(x,a,b,y,z,k) {
		a = typeof(a) != 'undefined' ? a : '';
		x = typeof(x) != 'undefined' ? x : '';
		b = typeof(b) != 'undefined' ? b : '';
		k = typeof(k) != 'undefined' ? k : 'Fermer';
		if (b =='') {
			c = '';
			d = '';
		} else {
			c = '<a href="'+b+'" target="_blank">';	
			d = '</a>';
		}
		var f = '';
		if (b != '') f = '<a href="'+b+'" target="_blank" class="url">'+b+'</a>';
		else b = '#';
		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).innerHTML = '<div id="titleItem"><h2>'+a+'</h2></div><div id="imgContainer">'+c+'<img src="'+x+'" />'+d+'</div><div id="bottomContainer"><p>'+f+'<a href="#" class="close" onclick="showAlert()">'+k+'</a></p></div>';	
			fade(y,z);
		} else {
			document.getElementById(z).style.visibility = 'hidden';
			document.getElementById(y).style.visibility = 'hidden';
			//alert(a);
			//if (a != '') location.href=a;
		}
}

function fade(y,z){
	opa = typeof(opa) != 'undefined' ? opa : 0;
	opa += .1;
	if (opa < '.7'){
		document.getElementById(z).style.opacity = opa;
		document.getElementById(z).style.filter='alpha(opacity='+(opa*100)+')'	
		anime =  window.setTimeout("fade('"+y+"','"+z+"')",0.1);
		
	} else {
		document.getElementById(y).style.visibility = 'visible';
		opa = 0;
	}
}

function Clickheretoprint(x) {
 x = typeof(x) != 'undefined' ? x : 'printContent';
 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>&deg;&bull;Influenza marketing&bull;&deg;</title>');
  docprint.document.write('<link rel="stylesheet" href="/css/print.css"/></head><body onLoad="self.print()">');
  docprint.document.write('<div id="header"><p><img src="/images/layout/logo.jpg" />Influenza Marketing<br />4020 St-Ambroise, Suite 261<br />Montr&eacute;al (QC) H4C 2C7<br />t.: 514 846-1047</p></div>');
  docprint.document.write('<div id="content">'); 
  docprint.document.write(content_vlue); 
  docprint.document.write('</div>'); 
  docprint.document.write('<p class="close"><a href="javascript:window.close();">Fermer la fen&ecirc;tre</a></p></body></html>');
  docprint.document.close();
  docprint.focus();
}

// Alterning Rows
function alternateRows(x) {
el = document.getElementById(x);
rw = el.getElementsByTagName("tr");
  for (i=1; i<rw.length; i++) rw[i].className = "row" + (i % 2);
  for (z=1; z<rw.length; z++) {
	  rw[z].onmouseover = function () {
		  this.className += " ruled"; return false
		  }
	  rw[z].onmouseout = function () {
		  this.className = this.className.replace("ruled", ""); return false
		  }
	  }
}