﻿	// BROWSER DETECTION
	function BrowserCheck() {
		var b = navigator.appName
		if (b=="Netscape") this.b = "ns"
		else if (b=="Microsoft Internet Explorer") this.b = "ie"
		else this.b = b
		this.version = navigator.appVersion
		this.v = parseInt(this.version)
		this.ns = (this.b=="ns" && this.v>=4)
		this.ns4 = (this.b=="ns" && this.v==4)
		this.ns5 = (this.b=="ns" && this.v==5)
		this.ns6 = (this.b=="ns" && this.v==6)
		this.ie = (this.b=="ie" && this.v>=4)
		this.ie4 = (this.version.indexOf('MSIE 4')>0)
		this.ie5 = (this.version.indexOf('MSIE 5')>0)
		this.min = (this.ns||this.ie)
	}
	is = new BrowserCheck();
	
	
	// INPUT ACTIONS
	function enterInput(obj,text) {
		if (obj.value == text) {
			obj.value = "";
		}
	}
	
	function leaveInput(obj,text) {
		if (obj.value == "") {
			obj.value = text;
		}
	}
	
	// COOKIE FUNCTIONS	
	var date_cookie = new Date;
	var chargement = false;
	date_cookie.setFullYear(date_cookie.getFullYear() + 10);

	function writeCookie(nom, valeur)	{
		var argv = writeCookie.arguments;
		var argc = writeCookie.arguments.length;
		var expires = (argc > 2) ? argv[2] : null;
		var path = (argc > 3) ? argv[3] : null;
		var domain = (argc > 4) ? argv[4] : null;
		var secure = (argc > 5) ? argv[5] : false;
		document.cookie = nom + "=" + escape(valeur) +
		((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
		((path==null) ? "" : ("; path="+path))+
		((domain==null) ? "" : ("; domain="+domain))+
		((secure==true) ? "; secure" : "");
	}
	
	function getCookieVal(offset) {
		var endstr = document.cookie.indexOf(";", offset);
		if (endstr == -1)
			endstr = document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr)); 
	}
	
	function readCookie(nom) {
		var arg = nom + "=";
		var alen = arg.length;
		var clen = document.cookie.length;
		var i = 0;
		while (i < clen)	{
			var j = i + alen;
			if (document.cookie.substring(i, j) == arg)
				return getCookieVal(j);
			i = document.cookie.indexOf(" ",i) + 1;
			if (i == 0)
				break;
		}
		return null; 
	}
	

	// MAIN MENU ROLLOVER
	function enterInput(obj,text) {
		if (obj.value == text) {
			obj.value = "";
		}
	}
	
	function leaveInput(obj,text) {
		if (obj.value == "") {
			obj.value = text;
		}
	}
	
	var timerMenu = new Array();
	var isMenuOpen = new Array();
	var isOverMenu = false;
	
	function showMenu(idx) {
		//alert(eval("document.all.smenu" + idx + ".style.visibility"));
		if (!isMenuOpen[idx]) {
			document.getElementById('smenu' + idx).style.display = "block";
			document.getElementById('menu' + idx).className = "mainmenuover";
			if (typeof timerMenu[idx] != "undefined") clearTimeout(timerMenu[idx]);
			isOverMenu = true;
			//hideObjectWhenMainNavIsOpened(true);
		}
	}
	
	function hideMenu(idx) {
		//alert(idx);
		isOverMenu = false;
		doHideMenu(idx);
		document.getElementById('menu' + idx).className = "";		
	}
	
	function doHideMenu(idx) {
		clearTimeout(timerMenu[idx]);
		document.getElementById('smenu' + idx).style.display = "none";
		isMenuOpen[idx] = false;
		//if (!isOverMenu) hideObjectWhenMainNavIsOpened(false);
	}
	
	

		
	
	// POPUP FUNCTION
	var zoomwindow;
	
	function deplace(window,width,height)
	{
		var scr_x = screen.width;
		var scr_y = screen.height;
		if (is.v >= 4)
		{
			if (is.ns)
			{
				window.moveTo((scr_x/2)-(width/2), (scr_y/2)-(height/2));
			}
			else
			{
				window.moveTo(parent.window.screenLeft+300, parent.window.screenTop+50);
			}
		}
	}
		
	var movePopup = true;
	var scrollPopup = 1;
	
	function popup(url, width, height)
	{
		if (url != "")
		{
			var features;
			var windowName = "ZOOMWINDOW";
			
			movePopup = true;
			scrollPopup = 1;
			if (popup.arguments.length >= 4)
			{
				if (popup.arguments[3])
				{
					movePopup = true;
				}
				else
				{
					movePopup = false;
				}
			}
			if (popup.arguments.length >= 5)
			{
				if (popup.arguments[4] == 0 || popup.arguments[4] == 1)
				{
					scrollPopup = popup.arguments[4];
				}
			}
			if (popup.arguments.length >= 6)
			{
				zoomwindow = popup.arguments[5];
				windowName = zoomwindow;
			} else
			{
				if (zoomwindow != null)
				{
					if (!zoomwindow.closed)
						zoomwindow.close();
				}
			}
			
			features = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=" + scrollPopup + ",resizable=0,width=" + width + ",height=" + height + "'";
			zoomwindow = window.open(url,windowName,features);
			
			if (zoomwindow != null)
			{
				if (is.v >= 3)
				{
					zoomwindow.focus();
				}
				if (movePopup)
				{
					deplace(zoomwindow,width,height);
				}
			}
		}
	}

	// SETFONT FUNCTION
	var font_size = 1; //base font-size
	var font_size_MAX = 1.4;
	var font_size_MIN = 0.8;
	
	function setFontLarger()
	{
		font_size = font_size + 0.2;
		if (font_size > font_size_MAX)
		{
			font_size = font_size_MAX;
		}
		SetFontSize();
	}
	
	function setFontSmaller()
	{
		font_size = font_size - 0.2;
		if (font_size < font_size_MIN)
		{
			font_size = font_size_MIN;
		}
		SetFontSize();
	}
	
	function SetFontSize() {
		var oDoc = document.getElementById("pagecontent");
		if (oDoc)
			oDoc.style.fontSize = font_size + "em";
	}	

	function Form_Erreur(message_erreur) {
		alert(message_erreur);
		return false;	
	}
	
	function Valeur(obj, obj_type) {
		if (obj_type == "TEXT" || obj_type == "PASSWORD") {
	    	if (obj.value.length == 0) 
	      		return false;
	    	else 
	      		return true;
	    } else if (obj_type == "SELECT") {
	        for (i = 0; i < obj.length; i++) {
				if (obj[0].selected)
					return false;
				else
					return true;
			}
		} else if (obj_type == "EMAIL") {
			//if((obj.value.indexOf("@") == -1) || (obj.value.charAt(0) == ".") || (obj.value.charAt(0) == "@") ||(obj.value.length < 6) || (obj.value.indexOf(".") == -1) || (obj.value.charAt(obj.value.indexOf("@")+1) == ".") || (obj.value.charAt(obj.value.indexOf("@")-1) == ".") || (obj.value.charAt(obj.value.length-1) == "@") || (obj.value.charAt(obj.value.length-1) == ".")) {
			var emailCheck = /^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[\w-\.]*[a-zA-Z0-9]\.[a-zA-Z]{2,7}$/i;
			if (!emailCheck.test(obj.value)) {
				return false;
			} else {
				return true;
			}
		} else if (obj_type == "ONERADIO" || obj_type == "ONECHECKBOX") {
			if (obj.checked == false) {
				return false;
			} else {
				return true;
			}
		} else if (obj_type == "RADIO" || obj_type == "CHECKBOX") {
			for (i = 0; i < obj.length; i++) {
				if (obj[i].checked == true)
					return true;
			}
			return false;
		} else if (obj_type == "NUMERIC") {
			if (obj.value.length == 0) {
				return false;
			} else {
				theValue = obj.value;
				if (theValue.indexOf(',') > -1) {
					theValue = theValue.replace(",", ".");
					theValue = parseFloat(theValue);
				}
				if (isNaN(theValue)) {
					return false;
				} else {
					return true;
				}
			}
		}
	}
	
	function showError(obj)
	{
		if (typeof obj[0] != "undefined" && obj.tagName != "SELECT")
		{
			for (i = 0; i < obj.length; i++)
			{
				obj[i].style.backgroundColor = "#FFE5E5";
			}
		}
		else
		{
			obj.style.backgroundColor = "#FFE5E5";
		}
	}
	
	function showDefault(obj)
	{
		if (typeof obj[0] != "undefined" && obj.tagName != "SELECT")
		{
			for (i = 0; i < obj.length; i++)
			{
				obj[i].style.backgroundColor = "#cdebec";
			}
		}
		else
		{
			obj.style.backgroundColor = "#cdebec";
		}
	}		
	