function reloadDetails(id) {
  var xmlhttp = new XMLHttpRequest();
  var url = "details.php?photo=no&id="+id;
  xmlhttp.open("GET", url, true);
  xmlhttp.onload=function() { 
    var details_small = document.getElementById("details_small");
    var image_small = document.getElementById("image");
	var titresearch = document.getElementById("titresearch");

    details_small.innerHTML = xmlhttp.responseText;
    details_small.style.display = 'block';
	titresearch.style.display = 'block';
    image_small.style.display = 'block';
  }
  xmlhttp.send(null);
}

function imageLoader(id, image, smallimage) {
  if (!document.photos) { document.photos = new Array(); }
  if (!document.smallphotos) {document.smallphotos = new Array(); }
  if(!document.photos[id]) {
    document.photos[id] = new Image();
    document.photos[id].src = image;
  }
  if(!document.smallphotos[id]) {
    document.smallphotos[id] = new Image();
    document.smallphotos[id].src = smallimage;
  }
}

var pinid = null;
var activeid = null;
function imageChanger(id) {
  reloadDetails(id);

  if (pinid==null) {
    if (document.photos[id]) {
      var photoElement = document.getElementById('photo');
      photoElement.src = document.smallphotos[id].src;
      blankat = photoElement.src.lastIndexOf('blank.png');
      if (blankat>-1) {
        photoElement.src = photoElement.src.substr(0, blankat)+'blank.png';
      }
    } 
    var marker;
    if (activeid) {
      marker = document.getElementById('marker'+activeid);
      if (marker)
        marker.parentNode.parentNode.className = 'nonactiverow';
    }
    marker = document.getElementById('marker'+id);
    if (marker) {
      marker.parentNode.parentNode.className = 'activerow';
    }
    activeid = id;
  }
}

function showSelects(show) {
  if (show==true) {
    document.search.style.display = 'block';
    document.getElementById("voitures").style.display = 'block';
	document.getElementById("titresearch").style.display = 'block';
    //document.getElementById("download").style.display = 'block';
  } else {
    document.search.style.display = 'none';
    document.getElementById("voitures").style.display = 'none';
    document.getElementById("download").style.display = 'none';
  }
}

function hideSmallDetails() {
  var details_small = document.getElementById("details_small");
  var titresearch = document.getElementById("titresearch");
  var image_small = document.getElementById("image");
  details_small.style.display = 'none';
  titresearch.style.display = 'none';
  image_small.style.display = 'none';
  
}

function imagePinRow(id) {
  if (pinid==id) {
    pinid = null;
  } else {
    pinid = null;
    imageChanger(id);
    pinid = id;
  }
}

function imageMax() {
  detailsClose();
  document.getElementById('bigphoto').src = document.smallphotos[pinid].src;
  pinid = null;
//  document.getElementById('bigphoto').src = document.getElementById('photo').src;

  hideSmallDetails();
}

function detailsMax(id) {
  var xmlhttp = new XMLHttpRequest();
  var url = "details.php?id="+id;
  xmlhttp.open("GET", url, true);
  xmlhttp.onload=function() {
    var details_c = document.getElementById('details_c');

    details_c.style.display = 'block';
    details_c.innerHTML = xmlhttp.responseText;
  
    hideSmallDetails();
    showSelects(false);
  }
  xmlhttp.send(null);

}

function detailsClose() {
  document.getElementById('details_c').style.display = 'none';
  showSelects(true);
}

function devisVoiture(dossier) {
  // show the form for a devis
 // var xmlhttp = new XMLHttpRequest();
  var url = "devis.php?id="+dossier;
  window.open(url);
//  xmlhttp.open("GET", url, true);
//  xmlhttp.onload=function() {
//    var details_c = document.getElementById('details_c');

//    details_c.style.display = 'block';
//    details_c.innerHTML = xmlhttp.responseText;
//  }
//  xmlhttp.send(null);
}

function reserveVoiture(dossier) {
  var xmlhttp = new XMLHttpRequest();
  var url = "caddie.php?add="+dossier;
  xmlhttp.open("GET", url, true);
  xmlhttp.onload=function() {
    var caddie = document.getElementById('caddie');
    caddie.innerHTML = xmlhttp.responseText;
    document.getElementById('details_c').style.display = 'none';
    showSelects(true);
  }
  xmlhttp.send(null);
}
function unreserveVoiture(dossier) {
  var xmlhttp = new XMLHttpRequest();
  var url = "caddie.php?delete=" + dossier;
  xmlhttp.open("GET", url, true);
  xmlhttp.onload=function() {
    var caddie = document.getElementById('caddie');
    caddie.innerHTML = xmlhttp.responseText;
  }
  xmlhttp.send(null);
}

function printVoiture(dossier) {
  var url = "impression.php?dossier="+dossier+"&template=voiture";
  window.open(url, 'Devis');
}

function printDevis(dossier) {
  //with (document.devis) {
  //var get = 'name='+name.value+
  //          '&addr1='+addr1.value+
  //          '&addr2='+addr2.value+
  //          '&postcode='+postcode.value+
  //          '&ville='+ville.value+
  //          '&prixpublic='+prixpublic.value+
  //          '&prixoptions='+prixoptions.value+
  //          '&options='+options.value+
  //          '&apport='+apport.value+
  //          '&credit='+credit.value+
  //          '&reprise='+reprise.value+
  //          '&ext=.pdf';
  //}
  //var url = "impression_devis.php?dossier="+dossier+"&template=devis&"+get;
  //window.open(url, 'Devis');
  document.devis.submit();
}
