// JavaScript Document
var sAgent = navigator.userAgent.toLowerCase() ;
if (sAgent.indexOf("msie") == -1) {
  var IE = 0;
} else { var IE = 1; }

var mouseX = 0;
var mouseY = 0;
function getMouseXY() {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  /*mouseX = tempX;
  mouseY = tempY;*/
  return {x:tempX, y:tempY};
  //alert(mouseX+'x'+mouseY);
}
var mousePos;
if (!IE) { document.onmousemove = mouseMove; }
function mouseMove(ev){
	ev           = ev || window.event;
	mousePos = mouseCoords(ev);
}

function mouseCoords(ev){
	if(ev.pageX || ev.pageY){
		return {x:ev.pageX, y:ev.pageY};
	}
	return {
		x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
		y:ev.clientY + document.body.scrollTop  - document.body.clientTop
	};
}

// surcharge de la fonction getElementById pour simplifer le codage
function _Elem(id) {
  return document.getElementById(id);
}

function Show() {
	for (var i = 0; i < arguments.length; ++i) {
		_Elem(arguments[i]).style.display = 'block';
		_Elem(arguments[i]).style.visibility = 'visible';
	}
}

function Hide() {
	for (var i = 0; i < arguments.length; ++i) {
		_Elem(arguments[i]).style.display = 'none';
		_Elem(arguments[i]).style.visibility = 'hidden';
	}
}

function showHide(id) {
	if (_Elem(id).style.display != 'none')
		Hide(id);
	else
		Show(id);
		
}

function ucFirst(str) {
   return str.substr(0,1).toUpperCase() + str.substr(1,str.length);
}

function checkMail(adresse){

var regEx = /([a-z0-9]+([-_]?[a-z0-9]+)*.)*[a-z0-9]+([-_]?[a-z0-9]+)*@([a-z0-9]+([-_]?[a-z0-9]+)*.)+[a-z]{1,4}/gi;  

if (adresse.match(regEx) != adresse ) {

 return false;

} else {

 return true;

}

}

var cp = '';
var old_cp = '';
var villePrx = '';
function doVilles(prx) {
	var remoteVilles = new villes(villesCallBack);
  cp = _Elem(prx+'code_postal').value;
  if (cp != old_cp){
    if (cp) { remoteVilles.getvilles(cp); }
    old_cp = cp ;
	villePrx = prx;
  }
}

var villesCallBack = {
  getvilles: function (aryVilles) {
    var sel = _Elem(villePrx+'ville_id');
    sel.length=0;

	if (!aryVilles) {
		var res = document.createElement('option');
        res.value=0;
        res.innerHTML='Pas de villes pour ce Code postal';
        sel.appendChild(res);
	}
    else {
      for (var i = 0; i < aryVilles.length; ++i) {
        var res = document.createElement('option');
        res.value=aryVilles[i]['ville_id'];
        res.innerHTML=aryVilles[i]['commune'];
        sel.appendChild(res);
      }
      }
    }
  }

function checkMaquette() {
  nbErr = 0;
  fieldToFocus = 'none';
  aryReq = new Array('nom','telephone','email','delais');
  for (i=0; i<aryReq.length; i++) {
    if (_Elem(aryReq[i]).value) {
      _Elem(aryReq[i]).style.borderColor = "#666666";
    } else {
      _Elem(aryReq[i]).style.borderColor = "#cc0000";
      nbErr++;
      if (fieldToFocus == 'none') fieldToFocus = aryReq[i];
    }
  }
  
  if (nbErr > 0) _Elem(fieldToFocus).focus();
  else return true;
  return false;
}

function checkContact() {
  nbErr = 0;
  fieldToFocus = 'none';
  aryReq = new Array('nom','telephone','email','message');
  for (i=0; i<aryReq.length; i++) {
    if (_Elem(aryReq[i]).value) {
      _Elem(aryReq[i]).style.borderColor = "#000000";
		_Elem(aryReq[i]).style.backgroundColor = "#ffffff";
    } else {
      _Elem(aryReq[i]).style.borderColor = "#ff0000";
		_Elem(aryReq[i]).style.backgroundColor = "#EACEB5";
      nbErr++;
      if (fieldToFocus == 'none') fieldToFocus = aryReq[i];
    }
  }
  
  if (nbErr > 0) _Elem(fieldToFocus).focus();
  else return true;
  return false;
}

function checkTarif() {
  nbErr = 0;
  fieldToFocus = 'none';
  aryReq = new Array('nom','telephone','email','code_postal','sujet');
  aryDef = new Array('nom','telephone','email','code postal','sans sujet');
  for (i=0; i<aryReq.length; i++) {
    if (_Elem(aryReq[i]).value != aryDef[i]) {
      _Elem(aryReq[i]).style.borderColor = "#000000";
	  _Elem(aryReq[i]).style.backgroundColor = "#ffffff";
    } else {
      _Elem(aryReq[i]).style.borderColor = "#ff0000";
	  _Elem(aryReq[i]).style.backgroundColor = "#EACEB5";
      nbErr++;
      if (fieldToFocus == 'none') fieldToFocus = aryReq[i];
    }
  }
  
  if (nbErr > 0) _Elem(fieldToFocus).focus();
  else return true;
  return false;
}

function checkBdc() {
  nbErr = 0;
  fieldToFocus = 'none';
  aryReq = new Array('bdc_nom', 'bdc_prenom', 'bdc_adresse', 'bdc_code_postal', 'bdc_ville',
                     'bdc_telephone', 'bdc_email', 'bdc_destination', 'bdc_date_depart', 'bdc_date_retour', 'bdc_frais_consulaires', 'bdc_frais_retour');
  for (i=0; i<aryReq.length; i++) {
    if (_Elem(aryReq[i])) {
      if (_Elem(aryReq[i]).value) {
        _Elem(aryReq[i]).style.borderColor = "#000000";
      } else {
        _Elem(aryReq[i]).style.borderColor = "#ff0000";
        nbErr++;
        if (fieldToFocus == 'none') fieldToFocus = aryReq[i];        
      }
    }
  }
  
  // frais consulaires..
  if (_Elem('bdc_frais_consulaires').value && (_Elem('bdc_frais_consulaires').value*1 == _Elem('bdc_frais_consulaires').value)) {
    _Elem('bdc_frais_consulaires').style.borderColor = "#000000";
  } else {
    _Elem('bdc_frais_consulaires').style.borderColor = "#ff0000";
    nbErr ++;
    if (fieldToFocus == 'none') fieldToFocus = 'bdc_frais_consulaires';    
  }
  
  if (_Elem('bdc_frais_retour').value && (_Elem('bdc_frais_retour').value*1 == _Elem('bdc_frais_retour').value)) {
    _Elem('bdc_frais_retour').style.borderColor = "#000000";
  } else {
    _Elem('bdc_frais_retour').style.borderColor = "#ff0000";
    nbErr ++;
    if (fieldToFocus == 'none') fieldToFocus = 'bdc_frais_retour';    
  }
  
  if (nbErr > 0) { _Elem(fieldToFocus).focus(); return false; }
  else return true;
}


function imgOpacity(obj,alpha) {
    if (obj.firstChild.className == 'offreLienOff') {
    obj.firstChild.style.opacity = alpha;
    obj.firstChild.style.MozOpacity = alpha;
    obj.firstChild.style.filter = "alpha(opacity="+(alpha*100)+")";
    }
}

function changeFraisRetour(val) {
  tmp = val.split(':');
  if (tmp[1] *1 > 0) {
    _Elem('bdc_mode_expedition').value = tmp[0];
  _Elem('bdc_frais_retour').value = tmp[1];
  
  } else {
    _Elem('bdc_mode_expedition').value = tmp[0];
    _Elem('bdc_frais_retour').value = 'nous consulter';
  }
}

function Move(id, X, Y) {
         _Elem(id).style.left = X;
         _Elem(id).style.top = Y;
}
function createAkisiBulle() {
         tmp = document.createElement('div');
         tmp.id = 'AkisiBulleDiv';
         tmp.style.position = 'absolute';
         tmp.style.zIndex = '1000';
         document.body.appendChild(tmp);
         if (IE) {
         tmp2 = document.createElement('iframe');
         tmp2.id = 'AkisiBulleIframe';
         tmp2.style.position = 'absolute';
         tmp2.style.height = '25px';
         tmp2.style.zIndex = '999';
         document.body.appendChild(tmp2);
         }         
}
function HideAkisiBulle() {_Elem('AkisiBulleDiv').innerHTML = ''; Hide('AkisiBulleDiv'); if (IE) Hide('AkisiBulleIframe'); }
function AkisiBulleFollowMouse() {
 if (IE) mousePos = getMouseXY();
 Move('AkisiBulleDiv',mousePos.x+5, mousePos.y+5);
 if (IE) {
 _Elem('AkisiBulleIframe').style.width = _Elem('AkisiBulleDiv').clientWidth; 
 _Elem('AkisiBulleIframe').style.height = _Elem('AkisiBulleDiv').clientHeight;
 Move('AkisiBulleIframe',mousePos.x+5, mousePos.y+5);
 }
}
function AkisiBulle(obj, texte) {
 if (!_Elem('AkisiBulleDiv')) { createAkisiBulle() ;}
 Show('AkisiBulleDiv') 
 if (IE) Show('AkisiBulleIframe');
 if (IE) { 
    document.onmousemove = AkisiBulleFollowMouse;
    obj.onmouseout = HideAkisiBulle;
 } else {
    document.addEventListener('mousemove', AkisiBulleFollowMouse, true);
    obj.addEventListener('mouseout', HideAkisiBulle, true);
  } 
 _Elem('AkisiBulleDiv').innerHTML = texte;
}

var Texte = new Array();
Texte['date'] = 'Entrez une date au format:<br>jj/mm/aaaa';
Texte['frais_consulaires'] = 'Indiquez ici le montnant des frais consulaires pour votre visa. Vous le trouverez dans la partie <b>Tarifs</b> de notre site.';
Texte['frais_retour'] = 'Indiquez ici le montnant des frais de retour qui varient suivant le mode de livraison de votre visa. Vous le trouverez dans la partie <b>Tarifs</b> de notre site.';

function Status(msg) {
  return void(0);
}