/*****************************************************************************
 * FRAMEWORK
 ****************************************************************************/

var Tmp = {}
,N = {
	_tagId:"bdy"
	,_php:".php"
	,_cmp:".cmp.php"
	,_exe:".cmp.exe.php",_exepth:"/_cmp/exe/"
	//,_inc:".cmp.inc.php"
	,_mnu:".cmp.mnu.php"
	,_fct:""/*Nom de répertoire de la fonctionnalité courante : accueil, service, contact, etc.*/

	/*
	Affecte à tous les liens filtrés par f, l'évènement click pour la gestion Ajax.
	c comme click.
	*/
	,c:function(f) {
	  var re = new RegExp("(" + (N.bSec() ? N.https : N.http) + ")", "i");
	  $$(f).each(function(el) {
			if(!/#a\d/.test(el.href)&&!el.hasClass("na")&&re.test(el.href)) el.addEvent("click", function(e) {
				var o = e.target;
				while(o!=null&&o.tagName.toUpperCase()!="A") o = o.parentNode;
				return o==null ? true : N.t(o);
			})
		});
		/*
		var re = new RegExp("(" + (N.bSec() ? N.https : N.http) + ")", "i");
	  $$(f).each(function(el) {
			if(!/#a\d/.test(el.href)&&!el.hasClass("na")) el.addEvent("click", function(e) {
				var o = e.target;
				while(o!=null&&o.tagName.toUpperCase()!="A") o = o.parentNode;
				return o==null ? true : N.t(o);
			})
		});
		*/
	}
	/*
	,init:function(p) {
		if(p) for(var i in p) eval("N."+i+"=p."+i+";");
		N.c("a");
	}
	*/
	
	/*
	Détermine si le lien est sécurisé.
	*/
	,bSec:function(s) {
		return (s ? s : parent.location.href).substr(0,7)=="https:/";
	}
	
	/*
	Retourne l'url de base : http[s]://ndd/.
	*/
	,root:function() {
		return (N.bSec() ? N.https : N.http)+"/";
	}
	,nok:function(r) {
		alert(r.status+" - "+r.statusText);
	}
	
	/*
	Tous les liens doivent avoir onclick="return N.t(this)" pour la gestion Ajax.
	Utiliser N.c(f) qui va affecter tous les liens.
	t comme to.
	*/
	,t:function(o,p) {
		//Détermine le chemin et la ressource à appeler
		var url = o.href ? o.href : o,
			t = url.split("?"),
			/*
			l = t.length,
			bSec1 = N.bSec(),
			bSec2 = N.bSec(url),
			*/
			s = t[0].replace(new RegExp("(" + N.http + "\/)|(" + N.https + "\/)|(" + N._php + ")", "gi"), "")
			/*
			s = t[0]
				.replace(N._php, "")
				.replace((bSec2?N.https:N.http)+"/", ""),
			*/
			i = s.lastIndexOf("/"),
			pth = s.substr(0, i),
			rsc = s.substr(i+1, s.length),
			u1 = parent.location.href.substr(0,5),
			u2 = url.substr(0,5),
			c = (u1=="https" ? N.https : N.http) + "/" + pth + "/_cmp/";

		//Initialise les paramètres
		/*
		if(!p) p = {};
		if(!p.tagId) p.tagId = N._tagId;
		if(!p.parameters) p.parameters = l>1?t[1]:""; else if(l>1) p.parameters += "&"+t[1];
		if(!p.method) p.method = l>1 ? "get" : "post";
		*/
		
		//Change de protocole
		if(u1!=u2) {
			//Recharge toute la page
			//parent.location.href = N.root(bSec2)+pth+"/"+rsc+N._php+(p.parameters!=""?"?"+p.parameters:"");
			parent.location.href = url;
			return false;
		}

		/*
		if(bSec1!=bSec2) {
			//Recharge toute la page
			parent.location.href = N.root(bSec2)+pth+"/"+rsc+N._php+(p.parameters!=""?"?"+p.parameters:"");
			return false;
		}
		*/

		//Prépare la ressource à charger destinée à l'utilisation d'Ajax
		//url = N.root(bSec1)+pth+"/_cmp/"+rsc+N._cmp;
		url = c+rsc+N._cmp;

		//Construit l'identifiant de la page pour le cache
		//var uri = url+"?"+p.parameters;

		//Annule le chargement de la ressource si elle est déjà appelée précédemment
		//if(N.curi==uri) return false;

		//_curi = uri;
		//Charge le contenu
		new Request.HTML({
			url:t.length>1 ? url+"?"+t[1] : url
			/*
			,update:p.tagId
			,method:p.method
			*/
			,update:N._tagId
			,onSuccess:function(s) {
				/*
			  var o = $(p.tagId);
				o.set("text", '');
				o.adopt(s);
				*/
				
				//Initialise tous les liens filtrés pour l'utilisation d'AJAX
				N.c("#bdy a");
				
				//Remonte au sommet de la page
				window.scrollTo(0,0);
			}
			,onFailure:N.nok
    }).send();
		//}).send(p.parameters);
    
		//Active la tabulation
		var fct = Tab.on(pth), m = $("cm");
		
		//Charge son menu
		if(m) {
	    if(N._fct!=fct) {
//alert("trace chargement menu:"+pth);
	      //Charge le menu de la nouvelle fonctionnalité en cours
	      new Request.HTML({
					//url:N.root(bSec1)+pth+"/_cmp/mnu/menu"+N._mnu
					url:c+"mnu/menu"+N._mnu
					,update:"cm"
					,onSuccess:function(s) {
					  /*
					  var o = $("cm");
					  if(o) {
							o.set("text", '');
							o.adopt(s);
							N.c("#cm a");
						}
						*/
						N.c("#cm a");
					}
				}).send();

				//Mémorise la nouvelle fonctionnalité en cours
		    N._fct = fct;
			}
		}
		
		return false
	}
	,popup:function(o) {
		window.open(o.href, "p", "directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=1041,height=600");
		return false;
	}
	,win:function(o) {
		window.open(o.href, "w");
		return false;
	}
	/*
	f : filtre (ex : "")
	m : popup|win
	*/
	/*
	,js:function(f, m) {
		$$(f).each(function(el) {
		  el.href = "javascript:Js."+m+"(this,'"+el.href+"')";
		});
	}
	*/
}
/*
,Cache = {
	//curi:"",
	list:[],
	add:function(k,v){this.list[k]=v},
	clear:function(){delete this.list;this.list=[]},
	remove:function(k){delete this.list[k]},
	get:function(k){var s=this.list[k];return s?s:""},
	exists:function(k){return this.list[k]}
}
*/
,Frm = {
	/*Renseigne l'attribut name à la valeur id*/
	name:function() {
	  $("f").getElements("input,select,textarea", true).each(function(el) {
			if(!el.name) el.name = el.id;
		});
	}
	/*Pour les checkbox, value="0" et onclick="this.value = this.checked ? 1 : 0"*/
	,chk:function() {
	  $$("#f input.chk").each(function(el) {
	 		el.value = "0";
			el.onclick = function(e) {
				var o = e.target;
				o.value = o.checked ? 1 : 0;
			}
		});
	}
/*
	,select:{
		set:function(o, t, v) {
			//Vide la liste
			var l = o.length, i = 0;
			while(i++<l) o.options[0] = null;

			//Remplit la liste
			if(v) o[0] = new Option(v.lbl, v.id);
			l = t.length;
			i = 0;
			while(i<l) o[i+1] = new Option(t[i][1], t[i++][0]);
		},
		byValue:function(o, v) {
			var l = o.length, i = 0;
			while(i<l) if(o.options[i++].value==v) {
				o.selectedIndex = i-1;
				break;
			}
		}
	}
*/
}
/*
,Js = {
	popup:function(o, lnk) {
		window.open(lnk, o.title, "directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=1024,height=600");
	}
	,win:function(o, lnk) {
		window.open(lnk, o.title);
	}
}
*/
,Data = {
	alert:function(msg, tit, fld) {
		alert((tit?tit+"\n\n":"")+msg.replace(/<br \/>/gi,"\n"));
		try {$(fld).focus()} catch(e) {}
	}
}

/*****************************************************************************
 * MODULES
 ****************************************************************************/

/*Tips*/
,Tool = {
	tip:function(filter) {
		new TipsX3($$(filter), {
			onShow:function(tip){tip.setStyle("opacity", 0.9)}
			,offsets:{x:-10, y:15}
		})
	}
}

/*Onglets*/
,Tab = {
	id:"",
	on:function(fct) {
		var c = "active", id = Tab.id;
		try {
			if(id!="") $(id).removeClass(c);
			fct = fct.split("/");
			$(Tab.id = "tab"+fct[0]).addClass(c)
		} catch(e) {
			try {
				$(Tab.id = "tabaccueil").addClass(c);
			} catch(x) {
				//Pour éviter une erreur s'il n'y a pas d'onglet (par défaut c'est l'accueil)
				return "accueil";
			}
		}
		return fct[0];
	}
}

/*****************************************************************************
 * GOOGLE
 ****************************************************************************/

,G = {
	ads:function(n, w, h) {
/*
		var o = $(id), ifr = "<iframe id='ga" + i + "' name='ga" + i + "' src='"
			+ Nav.getRoot() + "__data/ad/keyword/" + fn + ".ads.php?t=" + (new Date()).getTime() + p
			+ "' width='" + w + "' height='" + h + "' scrolling='no' frameborder='0' marginwidth='0' marginheight='0' />";
		if(o) o.innerHTML = ifr; else window.addEvent("domready", function() {var o = $(id); if(o) o.innerHTML = ifr});
*/
    GG.id = "ads_"+n;
		google_ad_slot = n;
		google_ad_width = w;
		google_ad_height = h;
/*
		var t = document.createElement("script");
		t.type = "text/javascript";
		t.src = "http://pagead2.googlesyndication.com/pagead/show_ads.js";
		document.body.appendChild(t);
*/
		var d = $("ads_" + n);
		if(d) {
			var s = d.getElementsByTagName("iframe");
			if(s && s.length) {
			  //s[0].location = s[0].src + "&" + new Date().getTime();
			  
				s[0].src = s[0].src + "&" + new Date().getTime();
				
				//var src = (s[0].src.split(/&xtime=/))[0];
				//s[0].src = src + '&xtime='+new Date().getTime();
			}
		}
/*
	  GG.id = "ads_"+n;
	
		//google_ad_client = "pub-1750103503959505";
		google_ad_slot = n;
		google_ad_width = w;
		google_ad_height = h;

		var t = document.createElement("script");
		t.type = "text/javascript";
		t.src = "http://pagead2.googlesyndication.com/pagead/show_ads.js";
		document.body.appendChild(t);

  	document.write = function(s) {
			var d = $(GG.id);
			if(d) d.innerHTML += s;
			else document.body.innerHTML += s;
		}
*/
	}
}

/*****************************************************************************
 * GOOGLE ANALYTICS ET AIDICE TRACKER
 ****************************************************************************/
 
/*Tracker*/
,T = {
	/*
	Des paramètres sont à récupérer depuis Tmp.ot
	*/
	p:function(s) {
	  if(s==undefined) s = Tmp.ot[0];

	  //Page Tracker pour Aidice
		try{
			new Request({
				url:N.root()+"statistiques"+N._exepth+"page"+N._exe
				,method:"post"
				//,onComplete:function(s){alert("T.p:"+s)}
				//,onFailure:N.nok
				,evalResponse:true
			}).send("_w="+screen.width+"&_h="+screen.height+"&_from="+escape(Tmp.ot[2])+"&_url="+s+"&_p="+escape(Tmp.ot[1]));
		} catch(e) {alert("trace2:"+e)}

		//Page Tracker View pour Google
		try{pageTracker._trackPageview(s)} catch(e) {}
	}
}

/*****************************************************************************
 * PAGES PERSONNALISEES
 ****************************************************************************/
 
/*Contact*/
,Cnt = {
	init:function() {
	  //Tool.tip("#f .ttp");
	  $("ok").onclick = function() {
			new Request({
				url:N.root()+"contact"+N._exepth+"contact"+N._exe
				,method:"post"
				//,onComplete:function(s) {alert(s);}
				//,onFailure:N.nok
				,evalResponse:true
			}).send($("f").toQueryString());
			return false;
		};
	  $("civid").focus();
	  Frm.name();
	}
}

/*Soumission site web*/
,SSW = {
	init:function() {
	  //Tool.tip("#f .ttp");
	  $("ok").onclick = function() {
			new Request({
				url:N.root()+"annuaire"+N._exepth+"soumettre-site-web"+N._exe
				,method:"post"
				//,onComplete:function(s) {alert(s);}
				//,onFailure:N.nok
				,evalResponse:true
			}).send($("f").toQueryString());
			return false;
		};
	  $("civid").focus();
	  Frm.name();
	}
}

/*Commande*/
,Cmd = {
	init:function() {
		/*
		$("vndd").onclick =  function() {
			new Request({
				url:N.root()+"solution"+N._exepth+"disponibilite-ndd"+N._exe
				,method:"post"
				//,onComplete:function(s) {alert(s);}
				//,onFailure:N.nok
				,evalResponse:true
			}).send("ndd="+$("ndd").value+"&ext="+$("ext").value);
			return false;
		};
		*/
		$("ok").onclick = function() {
			new Request({
				url:N.root()+"solution"+N._exepth+"devis-commande-en-ligne"+N._exe
				,method:"post"
				//,onComplete:function(s) {alert(s);}
				//,onFailure:N.nok
				,evalResponse:true
			}).send($("f").toQueryString());
			return false;
		};
		$("civid").focus();
		Frm.name();
		Frm.chk();
	}
};