// $Id$
var utils = new Object();
utils.popup = function (url, name, features) {
	if (!name) name = "_blank";
	if (features) {
		var width = parseInt (features.replace(/.*width=/, ""));
		var height = parseInt (features.replace(/.*height=/, ""));
		var newWindow = window.open(url, name, features);
		if (width && height) try {newWindow.resizeTo (width, height)} catch (e) {};
		try {newWindow.moveTo(0,0)} catch (e) {};
	} else var newWindow = window.open(url, name);
	newWindow.focus();
	return false;
}
utils.updateOpener = function (url) {
	if (window.opener) {
		window.opener.location = url;
		window.opener.focus();
		return false;
	} else {
		newWindow = window.open(url,'main');
		newWindow.focus();
		return false;
	}
}
utils.switchTab = function (tab) {
	var index = parseInt (tab.id.replace(/.*-/,""));
	var prefix = tab.id.replace(/-header-\d*$/,"");
	if (document.getElementById) {
		var i = 1;
		var tab_header = true;
		while (tab_header) {
			tab_header = document.getElementById(prefix + "-header-" + i);
			var tab = document.getElementById(prefix + "-" + i);
			if (tab_header) {
				if (i == index) {
					tab_header.className = "tab-current";
					tab.style.display = "block";
				} else {
					tab_header.className = "";
					tab.style.display = "none";
				}
			}
			i++;
		}
	}
}
utils.addBookmark = function (message) {
	if (window.external) window.external.AddFavorite(location.href, document.title);
	else alert (message);
}
utils.sendPage = function (path, name, features) {
	var url = path + "?page=" + escape(location.pathname + location.search);
	utils.popup(url, name, features);
}
utils.getCookie = function (name) {
	var cookies = document.cookie.split(";");
	var pattern = name + "="
	for (var i = 0; i < cookies.length; i++) {
		var index = cookies[i].indexOf(pattern);
		if (index >= 0) return unescape(cookies[i].substr(index + pattern.length));
	}
	return null;
}
utils.setCookie = function (name, value) {
	var arguments = this.setCookie.arguments;
	var cookie = name + "=" + escape(value);
	if (typeof arguments[2] == "object") cookie = cookie + "; expires=" + arguments[2].toGMTString();
	if (typeof arguments[3] == "string") cookie = cookie + "; path=" + arguments[3];
	if (typeof arguments[4] == "string") cookie = cookie + "; domain=" + arguments[4];
	if (arguments[5]) cookie = cookie + "; secure";
	document.cookie = cookie;
}
utils.switchLang = function (lang) {
	if (location.search) {
		var query = location.search.replace(/&?lang=[^=&]*/, "");
		location.search = (query == "?" || !query ? "" : query + "&") + lang.substr(1);
		return false;
	} else return true;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' semble ne pas être une adresse email valide.';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' doit contenir un numéro de téléphone de 10 chiffres.';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' est obligatoire !'; }
  } if (errors) alert('Attention, vous n\'avez pas correctement renseigné un champ :\n'+errors);
  document.MM_returnValue = (errors == '');
}
