/////////////////////////////////////////////////////////////////////////////////
// popups
/////////////////////////////////////////////////////////////////////////////////
function tfo_openPopup(urlx,namex,wx,hx){
	var fenetreOpener = window.open(urlx,namex,'height=' + hx+ ',width=' + wx +',toolbar=no,menubar=yes,scrollbars=yes,Status=no,resizable=yes');
	fenetreOpener.focus();
}

function tfo_openVueAerienne(adressePostale){
	adressePostale=adressePostale.replace(" ","+");
	var tempUrl="http://maps.google.com/maps?f=q&hl=fr&geocode=&q="+ adressePostale + "&t=h&z=13&iwloc=addr";
	//alert(tempUrl);
	tfo_openPopup(tempUrl,"vueGoogle",760,500);
}

function tfo_openItineraire(adressePostale){
	adressePostale=adressePostale.replace(" ","+");
	var tempUrl="http://maps.google.com/maps?f=q&hl=fr&geocode=&q="+ adressePostale + "&z=13&iwloc=addr";
	//alert(tempUrl);
	tfo_openPopup(tempUrl,"itiGoogle",760,500);
	//alert("lien direct vers le calcul d'itineraire google");
}
function tfo_printAll(){
	//firefox sur mac ou pc s'imprime a partir de window.self.print();
	if (navigator.platform.substring(0,3)=="Win" || navigator.appVersion.indexOf("safari")==-1 ){
		window.self.print();
	}
	else{
		window.alert("Appuyez sur Pomme + P, pour imprimer cette page");
	}
}
function tfo_hautPage(){
	var url = new String(window.parent.location);
	//premier fois que l'on veut remonter
	if(url.indexOf('haut')==-1){
		window.parent.location = window.parent.location+'#haut';
	}else{
		window.parent.location = window.parent.location;
	}
}
/////////////////////////////////////////////////////////////////////////////////
// diaporama
/////////////////////////////////////////////////////////////////////////////////
function creatediv(id, html, width, height, left, top) {
   DIVtoRemove = window.top.document.getElementById(id);
   if(DIVtoRemove!=null)
   {
  	 window.top.document.body.removeChild(DIVtoRemove);
   }
   var newdiv = window.top.document.createElement('div');
   newdiv.setAttribute('id', id);
   if (width) {
       newdiv.style.width = width+'px';
   }
   if (height) {
       newdiv.style.height = height+'px';
   }
   if ((left || top) || (left && top)) {
       newdiv.style.position = "absolute";
       if (left) {
           newdiv.style.left = left + 'px';
       }
       if (top) {
           newdiv.style.top = top + 'px';
       }
   }
   newdiv.style.background = "#333333";
   newdiv.style.border = "1px solid #000";
   if (html) {
       newdiv.innerHTML = html;
   } else {
       newdiv.innerHTML = "nothing";
   }
  window.top.document.body.appendChild(newdiv);
}

function tfo_openDiaporamaPopup(urlDiaporama){
	urlTfoSansGet=urlDiaporama.substring(0,urlDiaporama.indexOf('/diaporama/index.php'))+'/diaporama.php';
	urlTfoGet=urlDiaporama.substring(urlDiaporama.indexOf('?'),urlDiaporama.length);
	urlDiapoIframe=urlTfoSansGet+urlTfoGet;
	urlDiapoIframe = urlDiapoIframe.substring(1);
	var iframe = document.createElement('iframe');
	iframe.src = urlDiapoIframe;
	iframe.width ='';
	iframe.height ='';
	iframe.scrolling="no";
	iframe.marginwidth="0";
	iframe.marginheight="0";
	iframe.frameborder="0";
	iframe.style.border="0px none";
	iframe.style.display="block";
	iframe.style.height = "450px";
	iframe.style.position = "absolute";
	iframe.style.width="600px";
	iframe.name = "tfoIfrDiap";
	iframe.id = "tfoIfrDiap";
	var posx = 30;
	var posy = 150;
	posy =  window.top.document.documentElement.scrollTop+window.top.document.body.scrollTop+50;
	var strHtml = '<a class="tfoFermerDiaporama" href="javascript:tfo_fermerDiaporama();">x fermer</a>';
	creatediv("tfoDiapoFlash", strHtml, 600, 470, posx, posy);
	mainDiv = window.top.document.getElementById('tfoDiapoFlash');
	mainDiv.style.zIndex = 100;
	mainDiv.appendChild(iframe);
}
function tfo_openDiaporamaPopupPreview(){
	var div = document.createElement('div');
	div.width ='';
	div.height ='';
	div.scrolling="no";
	div.marginwidth="0";
	div.marginheight="0";
	div.frameborder="0";
	div.style.border="0px none";
	div.style.display="block";
	div.style.height = "450px";
	div.style.position = "absolute";
	div.style.width="600px";
	div.name = "tfoIfrDiap";
	div.id = "tfoIfrDiap";
	var posx = 30;
	var posy = 150;
	posy =  window.top.document.documentElement.scrollTop+window.top.document.body.scrollTop+50;
	var strHtml = '<a class="tfoFermerDiaporama" href="javascript:tfo_fermerDiaporama();">x fermer</a><div id="animationVisuel"></div>';
	creatediv("tfoDiapoFlash", strHtml, 600, 470, posx, posy);
	mainDiv = window.top.document.getElementById('tfoDiapoFlash');
	mainDiv.style.zIndex = 120;
	mainDiv.appendChild(div);
}

function tfo_fermerDiaporama(){
	DIVtoRemove = window.top.document.getElementById("tfoDiapoFlash");
	if(DIVtoRemove){
	 window.top.document.body.removeChild(DIVtoRemove);
	}
	else{
		window.top.close();
	}
}
/**
 * conversion hexadecimal vers sexagesimal
 * @access public
 * @return void
 **/
function versSexagesimal(hexadecimal){
	var hexa =  hexadecimal.split('.',2);
	// avant la virgule les degres
	var degre = hexa[0];
	// apres la virgule
	var tmpMin = hexa[1].length;
	tmpMin = Math.pow(10, tmpMin);
	tmpMin = hexa[1]/tmpMin*60;
	tmpMin = tmpMin.toString();
	tmpMin = tmpMin.split('.',2);
	var min = tmpMin[0];
	// apres la virgule
	var tmpSec = tmpMin[1].length;
	tmpSec = Math.pow(10, tmpSec);
	tmpSec = Math.round(tmpMin[1]/tmpSec*60);
	var sec = tmpSec.toString();
	return degre +'&deg;' + min + "'" + sec + "\"";

}
 /*
	parseUri 1.2.1
	(c) 2007 Steven Levithan <stevenlevithan.com>
	MIT License
*/

function parseUri (str) {
	var	o   = parseUri.options,
		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
};

parseUri.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};


/**
 *
 * @access public
 * @return void
 **/
function tfo_trackExterne(href, classification){
	var domaine = parseUri(window.location.href).host;
	var pos = domaine.lastIndexOf('.');
	var local = domaine.substr(pos)=='.loc';
	//alert(local);
	if(!local){
		// on cherche le nom du client
		var dir  = parseUri(window.location.href).directory;
		var tmp = dir.split('/');

		var queries  = parseUri(window.location.href).queryKey;
		var host = parseUri(href).host;
		var labelClassif=new Array();
		labelClassif['02.01.01']='activites';
		labelClassif['02.01.02']='degustation';
		labelClassif['02.01.03']='manifestation';
		labelClassif['02.01.04']='hebergement_locatif';
		labelClassif['02.01.05']='hotellerie';
		labelClassif['02.01.06']='hotellerie_plein_air';
		labelClassif['02.01.11']='patrimoine_culturel';
		labelClassif['02.01.12']='patrimoine_naturel';
		labelClassif['02.01.13']='restauration';
		labelClassif['02.01.14']='hebergement_collectif';
		labelClassif['02.01.15']='produits_touristiques';

		var str = 'CaravelisLE';
		//str += '/' + queries['key'];
		str += '/' + tmp[2];
		str += '/' + labelClassif[classification];
		//str += '/' + queries['lang'];
		str += '/' + host;

	    // creation d'une balise script
	    var script = document.createElement('script');
	    script.type = 'text/javascript';
	    // construction de la commande analytics
	    var varGA = 'pageTrackerCaravelis';
        var commandeJS = '';
        commandeJS += 'var ' + varGA + ' = _gat._getTracker("UA-5657143-5");';
        commandeJS += varGA + '._trackPageview("' + str + '");';
        commandeJS = 'try {' + commandeJS + '} catch(err) {}';

	    //script.text = "alert('" + commandeJS + "');";
	    script.text = commandeJS;
	    document.body.appendChild(script);

		//alert(commandeJS);
	}
}