// Liens externes --------------------------------------------------------------

function openSite(strLocationURL) {
    var siteWindow = null;
    siteWindow = window.open(strLocationURL);
}
function checkExternalLinks() {
    var objLinks = document.getElementsByTagName("a");
    for (i=0; i < objLinks.length; i++) {
        if (objLinks[i].href.length > 0) {
            if (objLinks[i].href.indexOf(document.domain) == -1 && objLinks[i].href.indexOf("javascript:") == -1 && objLinks[i].href.indexOf("mailto:") == -1 ) {
                objLinks[i].setAttribute('onclick', "javascript:openSite(this.href); return false;");
            }
        }
    }
}
try {
    window.addEventListener("load", checkExternalLinks, true);
}
catch(ex) {
    window.attachEvent("onload", checkExternalLinks);
}



// Checkbox --------------------------------------------------------------------

function Warp(obj, id){
  obj.className=(obj.className=='unchecked')?'checked':'unchecked';
  mycheck=document.getElementById(id);
  mycheck.checked=!mycheck.checked;
}



// Afficher/Masquer ------------------------------------------------------------

function Afficher(){
  var Obj;
  Obj = document.getElementById('fiche');
  if( Obj){
    with( Obj.style){
      display="block";
    }
  }
}
function Masquer(){
  var Obj;
  Obj = document.getElementById('fiche');
  if( Obj){
    with( Obj.style){
      display="none";
    }
  }
}

function AfficherAvancee(){
  var Obj;
  var Obj2;
  var Obj3;
  var Obj4;
  Obj = document.getElementById('recherche_avancee');
  Obj2 = document.getElementById('identification');
  Obj3 = document.getElementById('afficher');
  Obj4 = document.getElementById('masquer');
  if( Obj){
    with( Obj.style){
      display="block";
    }
  }
  if( Obj2){
    with( Obj2.style){
      display="none";
    }
  }
  if( Obj3){
    with( Obj3.style){
      display="none";
    }
  }
  if( Obj4){
    with( Obj4.style){
      display="block";
    }
  }
}
function MasquerAvancee(){
  var Obj;
  var Obj2;
  var Obj3;
  var Obj4;
  Obj = document.getElementById('recherche_avancee');
  Obj2 = document.getElementById('identification');
  Obj3 = document.getElementById('afficher');
  Obj4 = document.getElementById('masquer');
  if( Obj){
    with( Obj.style){
      display="none";
    }
  }
  if( Obj2){
    with( Obj2.style){
      display="block";
    }
  }
  if( Obj3){
    with( Obj3.style){
      display="block";
    }
  }
  if( Obj4){
    with( Obj4.style){
      display="none";
    }
  }
}



// Afficher/Masquer Bloc -------------------------------------------------------
 
function AfficherBloc(id) {
	var Obj;
  Obj = document.getElementById(id);
  if(Obj.style.display == "none"){
    Obj.style.display = "block";
  } else {
    Obj.style.display = "none";
  }
}



// Galerie & Info bulle --------------------------------------------------------

jQuery().ready(function() {
  $("#slider").easySlider({
  	controlsBefore:	'<p id="controls">',
  	controlsAfter:	'</p>',
  	prevId: 'prevBtn',
  	nextId: 'nextBtn'
  });
  /*
  $('#blocListe .content').tooltip({ 
      track: true, 
      delay: 0, 
      showURL: false, 
      showBody: " - ", 
      fade: 250 
  });
  */
  $('#container').tabs({
    //fxAutoHeight: false,
    //fxSlide: true,
    fxFade: true
  });
});



// CSS Browser Selector --------------------------------------------------------

var css_browser_selector = function() {
  var ua=navigator.userAgent.toLowerCase(),is=function(t){
    return ua.indexOf(t) != -1;
  },
  h=document.getElementsByTagName('html')[0],b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?'gecko ff2':is('firefox/3')?'gecko ff3':is('gecko/')?'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';var c=b+os+' js'; h.className += h.className?' '+c:c;
}();



// Panier ----------------------------------------------------------------------

var http_request = false;
function makePOSTRequest(url, parameters) {
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
     http_request = new XMLHttpRequest();
     if (http_request.overrideMimeType) {
     	// set type accordingly to anticipated content type
        //http_request.overrideMimeType('text/xml');
        http_request.overrideMimeType('text/html');
     }
  } else if (window.ActiveXObject) { // IE
     try {
        http_request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
        try {
           http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
     }
  }
  if (!http_request) {
     alert('Cannot create XMLHTTP instance');
     return false;
  }
  
  http_request.onreadystatechange = alertContents;
  http_request.open('POST', url, true);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request.setRequestHeader("Content-length", parameters.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(parameters);
}

function alertContents() {
  if (http_request.readyState == 4) {
     if (http_request.status == 200) {
        //alert(http_request.responseText);         
     } else {
        alert('There was a problem with the request.');
     }
  }
}

function maj_panier(obj,id){
var poststr = 'id=' + id + '&qte=' + encodeURI( document.getElementById("quantite_"+id).value );
makePOSTRequest('maj_panier.php', poststr);
}

function supprArticles(){
if(confirm('Souhaitez-vous supprimer ces articles de votre panier ?'))
	document.modif_panier.submit();
}

function validerCommande(){
if(confirm('Êtes-vous sûr de vouloir valider votre demande ?')){
	return true;
}
else
	return false
}


// Menu déroulant --------------------------------------------------------------

jQuery().ready(function() {
	jQuery('#leftmenu_int').accordion({
		active: false,
		header: 'h3',
		navigation: true,
		animated: 'slide',
		alwaysOpen: false,
		autoheight: false
	});
});

function initMenu() {
  jQuery("#leftmenu_int #selected").addClass("selected");
  jQuery("#leftmenu_int #selected h3").addClass("selected");
  jQuery('#leftmenu_int .conteneur').click(
    function() {
      jQuery("#leftmenu_int #selected h3").removeClass();
    }
  );
}
$(document).ready(function() {initMenu();});
