var isNetscape4 = document.layers;
var isNetscape6 = document.getElementById && !document.all
var isNetscape = isNetscape4 || isNetscape6;
var isIE = document.all && !isNetscape;
var DHTML = document.getElementById || document.all || document.layers;


function flash(tag) { 
  document.write(tag);
}


function getStyle(nom) {
  if (isNetscape6)
    style = document.getElementById(nom).style;
  else if (isNetscape4)
    eval("style = document."+nom);
  else
    style = document.all[nom].style;
  return(style);
}


function clipping(nom, x1, y1, x2, y2) {
  if (isNetscape4) {
    getStyle(nom).clip.left = x1;
    getStyle(nom).clip.top = y1;
    getStyle(nom).clip.right = x2; 
    getStyle(nom).clip.bottom =  y2;
  }
  else if (isNetscape6)
    getStyle(nom).clip = "rect("+y1+" "+x1+" "+y2+" "+x2+")";
  else
    getStyle(nom).clip = "rect("+y1+" "+x2+" "+y2+" "+x1+")";
}

function deplacement_absolu(nom, abscisse, ordonnee) {
  if (!DHTML)
    return;
  getStyle(nom).left = abscisse;
  getStyle(nom).top = ordonnee;
}

function deplacement_relatif(nom, deltaX, deltaY) {
  if (!DHTML)
    return;
  getStyle(nom).left = parseInt(getStyle(nom).left) + deltaX;
  getStyle(nom).top = parseInt(getStyle(nom).top) + deltaY;
}

function findPos(obj) {
            var curleft = obj.offsetLeft || 0;
            var curtop = obj.offsetTop || 0;
            while (obj = obj.offsetParent) {
                    curleft += obj.offsetLeft
                    curtop += obj.offsetTop
            }
            return {x:curleft,y:curtop};
} 

function check_email(email) {
        b = true;
        if (email.lastIndexOf('@') < 1)
            b = false;
        if (email.lastIndexOf('@') > email.lastIndexOf('.'))
            b = false;
        if (email.lastIndexOf('@') == email.lastIndexOf('.')+1)
            b = false;
        if (email.length-email.lastIndexOf('.') < 3 || email.length-email.lastIndexOf('.') > 5)
            b = false;
        if (email.length<6)
            b = false;
        return(b);
    }


// retourne un objet xmlHttpRequest.
// méthode compatible entre tous les navigateurs (IE/Firefox/Opera)
function getXMLHTTP(){
  var xhr=null;
  if(window.XMLHttpRequest) // Firefox et autres
  xhr = new XMLHttpRequest();
  else if(window.ActiveXObject){ // Internet Explorer
    try {
      xhr = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e1) {
        xhr = null;
      }
    }
  }
  else { // XMLHttpRequest non supporté par le navigateur
    return null;
  }
  return xhr;
}


function ajoutPanier(PDT_ID, QUANTITE){
  //var xhr=getXMLHTTP();
  //xhr.open("GET", "panier.php?so=a&PDT_ID="+PDT_ID+"&QUANTITE="+QUANTITE, false);
  //xhr.send(null);
  //alert(xhr.responseText);

  //$('#articles').html('<img src="jquery/indicator.gif" alt="" />');
  $.get("panier.php", { PDT_ID: PDT_ID, QUANTITE: QUANTITE },
    function(data){ 
      //$('#articles').load('selection.php');
      jAlert(data, 'Information'); 
    }); 
}


function arrondiPrix(nombre){
  nombre = Math.round(nombre*100)/100 + 0.001;
  nombre += '';
  return nombre.substr(0, nombre.indexOf('.')+3);
}

function newImage(arg) {
  if (document.images) {
    rslt = new Image();
    rslt.src = arg;
    return rslt;
  }
}

function changeImages() {
  if (document.images && (preloadFlag == true)) {
    for (var i=0; i<changeImages.arguments.length; i+=2) {
      document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
    }
  }
}

var preloadFlag = false;
function preloadImages() {
  if (document.images) {
    preloadFlag = true;
  }
}

function lance() {
  preloadImages();
  if (document.images) {
  preloadFlag = true;
  }
}

/**
* Méthode qui sera appelée à chaque fois qu'une touche est relachée dans la recherche d'évènement
*/
function new_search()
{
    var xhr = getXMLHTTP();
    xhr.onreadystatechange = function(){
        if(xhr.readyState == 4 && xhr.status == 200){
            leselect = xhr.responseText;
            document.getElementById('event_liste').innerHTML = leselect;
        }
    }
    xhr.open("POST", debut_url+"events_search.php",true);
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    sel = document.getElementById('event').value;
    xhr.send("search="+sel);
}

/* Ajout hotel à la selection */
function ajoutSelectionSimple(hot_id)
{
    $.get(debut_url+'ajax_selection.php', {so: "a", HOT_ID: hot_id}, function(data){
        if(data != 'OK') {
            alert(data);
        } else {
            $("#nb_hotel").load(debut_url+"ajax_selection.php", {so: "nb"});
            $(".lien-add-selection-"+hot_id).hide();
            $(".lien-delete-selection-"+hot_id).show();
        }
    });
}

function retireSelectionSimple(hot_id)
{
    $.get(debut_url+'ajax_selection.php', {so: "s", HOT_ID: hot_id}, function(data){
        if(data != 'OK') {
            alert(data);
        } else {
            $("#nb_hotel").load(debut_url+"ajax_selection.php", {so: "nb"});
            $(".lien-delete-selection-"+hot_id).hide();
            $(".lien-add-selection-"+hot_id).show();
        }
    });
}