//-----------------------------------------------------
// XITI : mesure de clic
//-----------------------------------------------------
function xt_clic(typecl,section,page,url,nvlle)
{
Xt_r = document.referrer;
Xt_h = new Date();
xt_img = new Image();
Xt_i = 'http://logi6.xiti.com/hit.xiti?s=124894&s2='+section;
Xt_i += '&p='+page+'&clic='+typecl+'&hl=' + Xt_h.getHours() + 'x' + Xt_h.getMinutes() + 'x' + Xt_h.getSeconds();
if(parseFloat(navigator.appVersion)>=4)
{Xiti_s=screen;Xt_i += '&r=' + Xiti_s.width + 'x' + Xiti_s.height + 'x' + Xiti_s.pixelDepth + 'x' + Xiti_s.colorDepth;}
Xt_i += '&ref=' + Xt_r.replace(/[<>"]/g, '').replace(/&/g, '$');
xt_img.src = Xt_i;
if ((url != null)&&(url!=undefined))
{ if ((nvlle=='')||(nvlle==null)) { document.location = url;} else {xfen = window.open(url,'xfen',''); xfen.focus();}}
else
{return;}
}


/* Effacement automatique des champs de saisie */
function auto_fill(o, i){
 if(i){
  if(o.refv==null)
   o.refv = o.value;
  if(o.value==o.refv)
   o.value='';
   o.select();
 }
 else{
  if(o.value=='')
   o.value=o.refv;
 }
}


/* Effacement automatique des champs de saisie */
function auto_fill_password(o, i){
 if(i){
	  if(o.refv==null)
	   o.refv = o.value;
	  if(o.value==o.refv)
	   o.value='';
	   
	   o.type='password';
	   o.select();
 }
 else{
	  if(o.value=='')
	  {
	   o.value=o.refv;
	   o.type='text';
	  }
 }
}

// Fonction permettant de limiter le nombre de caractères
// d'un textarea.
// à utiliser avec onKeyDown et onKeyUp dans la balise du textarea.
function textareaLimiter(field, maxlimit)
{
	// Si il y a plus de maxlimit caractères, on 
	if (field.value.length > maxlimit) 
		field.value = field.value.substring(0, maxlimit);
}

var curmap = null;

function show_map(o, mid, dir){
 if(document.layers)
  return;
 theobj = document.getElementById(mid);
 theobj.frm = theobj.getElementsByTagName("DIV").item(0);
 rcoords = findxy(document.getElementById(o.parentNode.name));
 coords = o.coords.split(",");
 if(curmap!=null){
  if(curmap==theobj)
   return;
  else
   hide_map();
 }
 if(dir==1){
  theobj.style.left = rcoords.x + parseInt(coords[2]) + 3 + 'px';
  theobj.style.top = rcoords.y + parseInt(coords[1]) + 1 + 'px';
 }
 else{
  theobj.style.left = rcoords.x + parseInt(coords[0]) - theobj.offsetWidth - 2 + 'px';
  theobj.style.top = rcoords.y + parseInt(coords[1]) + 1 + 'px';
 }
 theobj.frm.style.height = theobj.offsetHeight - 2 +'px';
 theobj.frm.style.width = theobj.offsetWidth - 2 +'px';
 theobj.style.visibility = 'visible';
 curmap = theobj;
}

function hide_map(){
 if(curmap==null)
  return;
 curmap.style.visibility = 'hidden';
 curmap = null;
}

function getmapxy(oid) {
 var rd = {x:0, y:0};
 o = document.getElementById(oid).getBoungingClietRect();
 rd.x += o.left;
 rd.y += o.top;
 return rd;
}

function findxy(o) {
 var rd = {x:0, y:0};
 tmp = o;
 rd.x += o.offsetLeft;
 rd.y += o.offsetTop;
 if(SAF)
  return rd;
 if(!MACIE5){
  while (o = o.offsetParent){
   rd.x += o.offsetLeft;
   rd.y += o.offsetTop;
  }
 }
 else{
  while ((o = o.offsetParent)&&(o.offsetParent.tagName!="BODY")){
   rd.x += o.offsetLeft;
   rd.y += o.offsetTop;
  }
 }
 return rd;
}

/* Ouverture Popup */
function popopen(u, w, h, l, t){
 var rcpop = window.open(u, 'rcpop', 'width='+w+', height='+h+', top='+t+', left='+l+', location=no, menubar=no, resizable=0, scrollbars=yes, status=no, toolbar=no, fullscreen=no');
 rcpop.focus();
 //return false;
}

/* Print */
function _print(){
 if(window.print)
  window.print();
 return false;
}

var SAF = (navigator.userAgent.toLowerCase().indexOf('safari')>=0);
var MACIE5 = (navigator.appVersion.indexOf("Mac") != -1)&&(document.all)&&(navigator.appVersion.indexOf("5.") != -1);

function init_button_MAC(){
 spcol = document.getElementsByTagName("SPAN");
 for(i=0;i<spcol.length;i++){
  if(spcol[i].className.indexOf('button')>=0){
   spcol[i].onmouseover = function(){
    this.refImage = this.style.backgroundImage;
    this.style.backgroundImage = 'url(p.gif)';
    this.childNodes[0].className = 'on';
   }

   spcol[i].onmouseout = function(){
    this.childNodes[0].className = 'off';
    this.style.backgroundImage = this.refImage;
   }

  }
 }
}

if(MACIE5){
 document.write('<link href="RelaisChateaux/mcover.css" rel="stylesheet" type="text/css" />');
 onload = init_button_MAC;
}
 
document.write('<style type="text/css">@import "RelaisChateaux/noscript.css";</style>');

/*

	GESTION DU FORMULAIRE CHECK AVAILABILITY

*/
function submitFormAvailability(nomForm)
{
	// Date d'arrivée...
	document.forms[nomForm].elements['arriveMonth'].value = document.forms[nomForm].elements['date_mois'].options[document.forms[nomForm].elements['date_mois'].selectedIndex].value - 1;
	document.forms[nomForm].elements['arriveDate'].value = document.forms[nomForm].elements['date_jour'].options[document.forms[nomForm].elements['date_jour'].selectedIndex].value;
	document.forms[nomForm].elements['arriveYear'].value = document.forms[nomForm].elements['date_annee'].options[document.forms[nomForm].elements['date_annee'].selectedIndex].value;


	var dateArrivee = new Date(document.forms[nomForm].elements['arriveYear'].value, document.forms[nomForm].elements['arriveMonth'].value, document.forms[nomForm].elements['arriveDate'].value);


	dateDepart = DateAdd(dateArrivee, parseInt(document.forms[nomForm].elements['arriveDate'].value,10), parseInt(document.forms[nomForm].elements['arriveMonth'].value,10), parseInt(document.forms[nomForm].elements['arriveYear'].value,10));

	alert(dateArrivee.toString() +' - - ' + dateDepart.toString());

	// Date de départ...
	document.forms[nomForm].elements['departMonth'].value = document.forms[nomForm].elements['date_mois'].options[document.forms[nomForm].elements['date_mois'].selectedIndex].value;
	document.forms[nomForm].elements['departDate'].value = document.forms[nomForm].elements['date_jour'].options[document.forms[nomForm].elements['date_jour'].selectedIndex].value;
	document.forms[nomForm].elements['departYear'].value = document.forms[nomForm].elements['date_annee'].options[document.forms[nomForm].elements['date_annee'].selectedIndex].value;

	alert(document.forms[nomForm].elements['arriveMonth'].value + ' -- ' + document.forms[nomForm].elements['arriveDate'].value + ' -- ' + document.forms[nomForm].elements['arriveYear'].value);
	// On submit le formulaire...
	document.forms[nomForm].submit();
}


function DateAdd(startDate, numDays, numMonths, numYears)
{
	var returnDate = new Date(startDate.getTime());
	var yearsToAdd = numYears;
	
	var month = returnDate.getMonth()	+ numMonths;
	if (month > 11)
	{
		yearsToAdd = Math.floor((month+1)/12);
		month -= 12*yearsToAdd;
		yearsToAdd += numYears;
	}
	returnDate.setMonth(month);
	returnDate.setFullYear(returnDate.getFullYear()	+ yearsToAdd);
	
	returnDate.setTime(returnDate.getTime()+60000*60*24*numDays);
	
	return returnDate;

}

function printPage() {
  if (window.print)
    window.print()
  else
    alert("Désolé, votre navigateur ne supporte pas cette fonction.");
}

// Permet d'ajouter la page aux favoris
function addFav(message) {
	if (document.all) 
		window.external.AddFavorite(location.href, document.title); 
	else 
		alert(message);
} 

//Verification de saisie d'un formulaire selon une expression reguliere
//a utiliser avec "verif()"
/*
function verify() {
 go = 1; msg = "";
 if (document.formulaire.EMAIL.value=="" || !controle(document.formulaire.EMAIL.value,"email","")) {
  msg += "- Veuillez entrer votre adresse mél\n   afin que nous puissions vous répondre.\n"; go = 0;
 }
 if (document.formulaire.NOM.value == "" || !controle(document.formulaire.NOM.value,"alpha","")) {
  msg += "- Veuillez entrer votre nom.\n"; go=0;
 }
 if (document.formulaire.PRENOM.value == "" || !controle(document.formulaire.PRENOM.value,"alpha","")) {
  msg += "- Veuillez entrer votre prénom.\n"; go=0;
 }
 if (document.formulaire.CIVILITE.options[0].selected == true) {
  msg += "- Veuillez choisir votre civilité.\n"; go=0;
 }
 if (go==0) {
  alert(msg);
  return;
 } else {
  document.formulaire.submit();
 }
}
*/
//avec le bouton de validation
//<a HREF="javascript:verify();"><font face="Arial" size="2">Valider ></font></a>
function controle(str,type,champs) {
 switch(type) {
  case "email":
   re = new RegExp("^([0-9a-zA-Z-_.]+)(@{1})([0-9a-zA-Z-_.]+)([.]{1})([a-zA-Z]{2,4})$");
  break;
  case "num":
   re = new RegExp("^([0-9]*)$");
  break;
  case "texte":
   re = new RegExp("^([\\x20-\\x7Fàâéèêîôùûçüïöäëñõ])*$");
  break;
  case "textarea":
   re = new RegExp("^([\\x20-\\x7F\\xA0\\xAB\\xBB\\x9C\\xB2\\xA3\\xA7\\xA4\\n\\ràâéèêîôùûçüïöäëñõÀÂÉÈÊÎÔÙÛÇÜÏÖÄËÑÕ€])*$");
  break;
  case "alnum":
   re = new RegExp("^([0-9a-zA-Z\(\)_ \-])*$");
  break;
  case "alpha":
   re = new RegExp("^([a-zA-Z\(\)_ \-])*$");
  break;
  case "lien":
   re = new RegExp("^([0-9a-zA-Z_./\:\-\?\&])*$");
  break;
  case "float":
   re = new RegExp("^([0-9]*[.]*[0-9]*)$");
  break
  case "reference":
   re = new RegExp("^([0-9]*[-]*[0-9]*[-]*[0-9]*)$");
  break
  default :
   re = '';
  break
 }
 if (re!='') {
  if (!re.test(str) && str != "") {
   return false;
  } else {
   return true;
  }
  return true;
 } 
}

/* Go */
function _go(u){
 location.href = u;
 return false;
}


var curform = null;

function init_forms(){
 var formcol = document.getElementsByTagName("FORM");
 for(f=0;f<formcol.length;f++){
  if(formcol[f].className=="allowentkey"){
   elmcol = get_form_elements(formcol[f]);
   for(i=0;i<elmcol.length;i++)
    elmcol[i].onkeydown = function(e){
     if(e==null)
      e = window.event;
     curform = this.prt;
     if(e.keyCode==13)
      curform.submit();
    }
  }
 }
}

function get_form_elements(f){
 var ret = new Array();
 var icol = f.getElementsByTagName("INPUT");
 for(i=0;i<icol.length;i++){
  icol[i].prt = f;
  ret[ret.length] = icol[i];
 }
 var scol = f.getElementsByTagName("SELECT");
 for(i=0;i<scol.length;i++){
  scol[i].prt = f;
  ret[ret.length] = scol[i];
 }
 return ret;
}

if(MACIE5){
 document.write('<link href="mcover.css" rel="stylesheet" type="text/css" />');
 onload = init_button_MAC;
}

/* Gestion hauteur Topnav IE */
var TN = null, TNSP = null, TNA = null, TNH = 0;

function IE_init_topnav(){
 if(!document.all)
  return;
 TN = document.getElementById("topnav");
 TNSP = TN.getElementsByTagName("SPAN");
 TNA = TN.getElementsByTagName("A");
 TN.onresize = IE_match_topnav;
}

function IE_match_topnav(){
 TNH = TN.offsetHeight;
 for(i=0;i<TNSP.length;i++)
  TNSP[i].style.marginTop = TNA[i].offsetHeight-TNH;
}
 
//document.write('<style type="text/css">@import "noscript.css";</style>');

onload = function(){ init_forms(); IE_init_topnav();}

