//------------------------------------------------------------------------------------
// Script Notice légale
//------------------------------------------------------------------------------------
function showCPR(s) {
       var y = new Date().getYear();
       if (y<1900) y+=1900;
       if (s!=y)
          document.write(s + " - " + y);
	       else
          document.write(y);
}

//------------------------------------------------------------------------------------
// Script Anti-flash
//------------------------------------------------------------------------------------
function fixFlash(s) { document.write(s); }

//------------------------------------------------------------------------------------
// fonction TestParam()
//------------------------------------------------------------------------------------
function testRecherche()
{
var Form = document.forms["FormRecherche"]; //forms = tous les formulaires du document
	if (Form.eField0.value == "0" && Form.eField1.value == "0" && Form.eField2.value == "0" && Form.eField3.value == "0" && Form.ePrixMin.value == "0" && Form.ePrixMax.value == "0" && Form.eKmMin.value == "0" && Form.eKmMax.value == "0")
		{ alert("Merci de sélectionner au moins un critère pour votre recherche de véhicules d'occasion."); Form.eCategorie.focus(); return false; }
	Form.submit();
}

function isEmail(obj) 
{
       if (obj.value.indexOf(" ") + "" == "-1"
       && obj.value.indexOf("@") + "" != "-1"
       && (obj.value.lastIndexOf(".") > obj.value.indexOf("@"))
       && obj.value != "") return true;
       else return false;
}

function isTel(obj) {
	if (isNaN(obj.value)==false && obj.value.length==10)  return true;
	else return false;
}

function isCP(obj) {
	if (isNaN(obj.value)==false && obj.value.length==5)  return true;
	else return false;
}

function pad(value) {
	if (value<=9) return '0' + value;
	return value;
}

//------------------------------------------------------------------------------------
// Fin fonction menusw
//------------------------------------------------------------------------------------

var survolPuceTri = 0;
function chgePuce(id)
{
	var obj = $("puceTri_0"+id);
	
	if(survolPuceTri == 0){
		obj.src = '/Images/Recherche/puce_tri_on.gif';
		survolPuceTri = id;
	}else{
		obj.src = '/Images/Recherche/puce_tri.gif';
		survolPuceTri = 0;
	}
}

function overListe(id)
{
	var _o = $("detail" + id);
	_o.className = 'details_liste' + ((_o.className == 'details_liste') ? '_on' : '');
}

//------------------------------------------------------------------------------------
// Fonction pour changer la photo de l'annonce
//------------------------------------------------------------------------------------

function swapImage(image) {
	var _src  = $('image' + image);
	var _dest = $('image');
	// Inversement des images
	_dest.src = _src.src;
}

//------------------------------------------------------------------------------------
// Fonctions propres au formulaire de recherche
//------------------------------------------------------------------------------------

function updateSearchForm(field) {
	var _parent = null;
	// On incrémente le champs de 1 (celui que l'on doit mettre à jour)
	field++

	var _fieldName = ['Catégorie','Marque','Modèle','Energie'];

	var _f = $frm("FormRecherche");

	// On mets à jour les noeuds
	for (var _i=1; _i<=3; _i++) {
		// On récupère le champ à mettre à jour
		_o = _f['eField' + _i];
		// On efface les éléments des champs au dessus de field
		if (_i>=field) {
			_o.options.length = 0;
			_o.options[0] = new Option(_fieldName[_i],0);
		}
	}
	
	// On récupère le select à mettre à jour
	var _o = _f['eField' + (field-1)];
	
	// Si c'est pas le premier élément qui est sélectionné
	if (_o.selectedIndex!=0) {

		// On fait l'appel AJAX
		ajaxRequest("/procs/psUpdateSearchForm.asp", 
			"Field=" + field + 
			"&Field0=" + escape(getValue(0)) +
			"&Field1=" + escape(getValue(1)) +
			"&Field2=" + escape(getValue(2)) +
			"&parent=" + _parent, 
			ajaxResponse
		);
	}
}

function getValue(field) {
	var _f = $frm("FormRecherche");
	var _o = _f['eField' + field];
	return _o.options[_o.selectedIndex].value;
}

function $frm(form) {
	return document.forms[form]
}

function ajaxRequest(url, data, func) {
	var req = new Ajax(url, {
		onComplete: func,
		method: 'post',
		data: data
	});
	req.request();
}

function ajaxResponse(response) {
	var _j = Json.evaluate(response)
	var _field = _j.field;

	var _f = $frm("FormRecherche");

	// On récupère le select à mettre à jour
	var _o = _f['eField' + _field];

	// Pour chaque options renvoyées
	for (var _i=0;_i<_j.options.length;_i++)
		_o.options[_i+1] = new Option(_j.options[_i].value, _j.options[_i].key);
}

//------------------------------------------------------------------------------------
// GetId() - Fonction pour faire apparaître un sous menu comme dans plan du site
//------------------------------------------------------------------------------------
function GetID(Ctl) {
	return document.getElementById(Ctl);
}

function deroul(id)
{
//	alert (id);
	if (GetID("hist"+id).style.display=="none")
		{
			closeall();
			on = true;
			GetID("hist"+id).style.display="";
		}
	else
		GetID("hist"+id).style.display="none";
}
//------------------------------------------------------------------------------------
// TestParam Formulaire
//------------------------------------------------------------------------------------
function isEmail(obj) 
{
       if (obj.value.indexOf(" ") + "" == "-1"
       && obj.value.indexOf("@") + "" != "-1"
       && (obj.value.lastIndexOf(".") > obj.value.indexOf("@"))
       && obj.value != "") return true;
       else return false;
}

function isCP(obj) {
	if (isNaN(obj.value)==false && obj.value.length==5)  return true;
	else return false;
}

function isTel(obj) {
	if (isNaN(obj.value)==false && obj.value.length==10)  return true;
	else return false;
}

function TestParamContact()
{
	var Form = document.forms["FormContact"]; //forms = tous les formulaires du document
	if (Form.eNom.value == "")
		{ alert("Merci de renseigner le champ 'Nom'"); Form.eNom.focus(); return false; }
	if (Form.ePrenom.value == "")
		{ alert("Merci de renseigner le champ 'Prénom'"); Form.ePrenom.focus(); return false; }
	if (Form.eEmail.value == "" || !isEmail(Form.eEmail))
		{ alert("Merci de renseigner correctement le champ 'E-mail'"); Form.eEmail.focus(); return false; }
	if (Form.eEmail2.value == "")
		{ alert("Merci de confirmer votre adresse e-mail"); Form.eEmail2.focus(); return false; }
	if (Form.eEmail.value != Form.eEmail2.value)
		{ alert("Merci de confirmer votre adresse e-mail"); Form.eEmail2.focus(); return false; }
	if (Form.eCP.value != "" && !isCP(Form.eCP))
		{ alert("Merci de renseigner le champ 'Code postal'"); Form.eCP.focus(); return false; }
	if (Form.eTel.value != "" && !isTel(Form.eTel))
		{ alert("Merci de renseigner le champ 'Téléphone' correctement"); Form.eTel.focus(); return false; }
	if (Form.eMessage.value == "")
		{ alert("Merci de renseigner le champ 'Message'"); Form.eMessage.focus(); return false; }
	return true;
}
//------------------------------------------------------------------------------------
// Fonction CacheMail
//------------------------------------------------------------------------------------

function CacheMail(mail,domain) {
	this.location = 'mailto:' + mail + '@'+ domain;
	}
//------------------------------------------------------------------------------------
// Script Popup
//------------------------------------------------------------------------------------
function openCarte() {
		var catW = 640;
		var catH = 515;
		var url  = 'http:\/\/chanoine.projets.actisens.com/google_maps.asp';
		
		var ie4 = (document.all)? true:false;
		var dom = (document.getElementById)? true:false;
		var ns4 = (document.layers)? true:false;

		var w,h;
		if (ie4 || dom) {
			w = screen.width;
			h = screen.height;
		} else if (ns4) {
			w = window.outerWidth;
			h = window.outerHeight;
		}
		
		var x,y;
		x = (w-catW)/2;
		y = (h-catH)/2;
	
		var wnd = window.open(url, '', 
					'width=' + catW + 
					',height=' + catH + 
					',top=' + x + 
					',left=' + x + 
					',screenX=' + x +
					',screenY=' + y +
					',resizable=no, scrollbars=no, status=no, menubar=no');
		wnd.focus();
	}
	
/*------------------------------------------------------*/
/*----------------Fenêtre photos partie équipe----------------*/

function GetID(id) { return document.getElementById(id); } 

function montrerFenetre(src) {
    var overlay = GetID('overlay');
    overlay.style.visibility = "visible";

	var my_image = GetID('img');
	my_image.src = src;
	
	var my_window = GetID('window');
	my_window.style.visibility = "visible";
}

function cacherFenetre() {
    var overlay = GetID('overlay');
    overlay.style.visibility = "hidden";

	var my_window = GetID('window');
	my_window.style.visibility = "hidden";
}

//------------------------------------------------------------------------------------
// Palmarès
//------------------------------------------------------------------------------------

function overBouton(id, force){
	if (typeof force == 'undefined') force = false;
	var obj = $("btPalmares"+id);
	var date = $("date"+id);

	if(obj.className != 'palmares_on'){
		obj.className = 'palmares_on';
		date.className = 'date_select';
	}else{
		if(id != currentId || force){
			obj.className = 'palmares_off';
			date.className = 'date';
		}
	}
}
var currentId = 0;
function swapPalmares(id,param)
{	
	var obj = $("btPalmares"+id);
	var tab = $("tabPalmares"+id);
	var img = $("ombrePalmares");
	
	if(currentId != 0) overBouton(currentId, true);

	closeAll();
	
	if (tab.style.display == "none"){
		tab.style.display = "";
		currentId = id;
		if(param==true){
			img.style.visibility = "hidden";
		}else{
			img.style.visibility = "visible";
		}
	} else {
		currentId = 0;
		overBouton(id, true);
	}
}

function closeAll()
{
	var list = $$(".texteTab")
	list.each(function(el) { el.style.display="none" });
}

function trackVo(vo) {
	// on récupère l'instance du tracker
	var _tracker = _gat._getTracker("UA-3078584-18");
	// On track la page
	_tracker._trackPageview(vo);
}
//POPUP

function openPopup(url, width, height, scrollbars, resizeable){
 var posX;
 posX = 440;
 
 if (document.all) posX = parseInt((document.body.clientWidth-width)/2); 
  else posX = parseInt((window.innerWidth-width)/2); 
 
 window.open(url,'popup','top=140, left=' + posX + ', width='+width+', height='+height+', scrollbars='+scrollbars+', resizeable='+resizeable+'')
}

function openPopup1(url, width, height, scrollbars, resizeable){
    window.open(url,'popup1','width='+width+', height='+height+', scrollbars='+scrollbars+', resizeable='+resizeable+'')
}

function onloadf() {
  if ((location.href=="http://chanoine.projets.actisens.com/") || (location.href=="http://chanoine.projets.actisens.com/index.asp") || (location.href=="http://www.chanoine.fr/") || (location.href=="http://www.chanoine.fr/index.asp")) {
			openPopup('popup2.asp', 571, 319, 'no', 'no');
  }
}
		
					