
function showLegal(){
	newPopup( {
					'url':'legal.php',
					'className':'alphacube',
					'title': 'www.est-occaz.fr',
					'statusbar':'&nbsp;',
					'showCenter':true,
					'width':600,
					'height':500,
					'id':'showLegal'
				}
			);
}
function showPartenaires(){
	newPopup( {
					'url':'ajax.partenaires.php',
					'className':'alphacube',
					'title': 'www.est-occaz.fr',
					'statusbar':'&nbsp;',
					'showCenter':true,
					'width':700,
					'height':300,
					'id':'showPartenaires'
				}
			);
}
function showNameo(){
	newPopup( {
					'url':'http://www.nameo.fr/',
					'iframe':true,
					'className':'alphacube',
					'title': 'www.nameo.fr',
					'statusbar':'&nbsp;',
					'showCenter':true,
					'maximize':false,
					'width':1050,
					'height':680,
					'id':'showNameo'
				}
			);
}
function updateModele2(options){
	document.body.style.cursor = 'wait';
	value = options[(options.selectedIndex)].value;
	new Ajax.Updater(	'upd_modele',
						"ajax.updateselect.modele2.php?value="+value,
						{	method:'post',
							asynchronous:true,
							onSuccess: function(t) { },
							onComplete: function(){
								Effect.DropOut('modele',{afterFinish:function(){
									document.body.style.cursor = 'default';
									Effect.Appear('modele');
								}});
							},
							evalScripts:true
						}
					);
	return false;
}
function showContact(id){

	var win = newPopup( {
							'url':'ajax.contact.php?id='+id,
							'className':'alphacube',
							'title': "Contact",
							'statusbar':'&nbsp;',
							'showCenter':true,
							'maximizable':true,
							'width':880,
							'height':700,
							'id':'showContact'+id
						}
					);
}
function showContactBasket(){

	var win = newPopup( {
							'url':'ajax.contact.basket.php',
							'className':'alphacube',
							'title': "Contact",
							'statusbar':'&nbsp;',
							'showCenter':true,
							'maximizable':true,
							'width':880,
							'height':700,
							'id':'showContactBasket'
						}
					);
}
function showVoiture(id, _args){
	var _title = _args != undefined && _args['title'] != undefined	? _args['title'] 	: "Est-Occaz";

	var win = newPopup( {
							'url':'ajax.detail.voiture.php?id='+id,
							'className':'alphacube',
							'title': _title,
							'statusbar':'&nbsp;',
							'showCenter':true,
							'maximizable':false,
							'width':880,
							'height':700,
							'id':'showVoiture'+id
						}
					);
}
function ajaxContact(F, id, Windows, event){

	document.body.style.cursor = 'wait';
	new Ajax.Request(	"ajax.contact.submit.php",
						{	method:'post',
							asynchronous:false,
							parameters:Form.serialize(F),
							onSuccess: function(t) {
								if(t.responseText != ""){alert(t.responseText);}
								else{
									alert('Message transmis');
									if(id > 0)
										Windows.close('showContact'+id, event);
									else
										Windows.close('showContactBasket', event);
								}
							},
							onComplete: function(){
								document.body.style.cursor = 'default';
							},
							evalScripts:true
						}
					);
	return false;
}
function showBasket(){

	var win = newPopup( {
							'url':'ajax.basket.php',
							'className':'alphacube',
							'title': "Mon panier",
							'statusbar':'&nbsp;',
							'showCenter':true,
							'maximizable':true,
							'width':420,
							'height':500,
							'id':'showBasket'
						}
					);
}
function addBasket(id){
	document.body.style.cursor = 'wait';
	new Ajax.Request(	"ajax.basket.add.php?id="+id,
						{	method:'post',
							asynchronous:true,
							onSuccess: function(t) { },
							onComplete: function(){
								document.body.style.cursor = 'default';
								if(!($('showBasket'))) showBasket();
								else updateBasket();
							},
							evalScripts:true
						}
					);
	return false;
}
function updateBasket(){
	new Ajax.Updater(	'mybasket',
						"ajax.basket.lst.php",
						{	method:'post',
							asynchronous:true,
							onSuccess: function(t) { },
							onComplete: function(){
								document.body.style.cursor = 'default';
							},
							evalScripts:true
						}
					);
}
function newBasket(){
	if(confirm('Etes-vous sur de vouloir vider votre panier ?')){
		document.body.style.cursor = 'wait';
		new Ajax.Request(	"ajax.basket.new.php",
							{	method:'post',
								asynchronous:true,
								onSuccess: function(t) { },
								onComplete: function(){
									document.body.style.cursor = 'default';
									updateBasket();
								},
								evalScripts:true
							}
						);
	}
	return false;
}
function rmBasket(id){
	if(confirm('Etes-vous sur de vouloir supprimer cette voiture du panier ?')){
		document.body.style.cursor = 'wait';
		new Ajax.Request(	"ajax.basket.rm.php?id="+id,
							{	method:'post',
								asynchronous:true,
								onSuccess: function(t) { },
								onComplete: function(){
									document.body.style.cursor = 'default';
									updateBasket();
								},
								evalScripts:true
							}
						);
	}
	return false;
}
	function showOptions(){
		if($('options').style.width == "36px")
			new Effect.Morph('options', {style:{width:'312px'}});
		else
			new Effect.Morph('options', {style:{width:'36px'}});
		return false;
	}
	function changePrix(v){
		$('innerPrix').innerHTML='Prix entre '+v[0]+' et '+v[1]+' &euro;'
		$('prix_min').value = v[0];
		$('prix_max').value = v[1];
	}
	function changePuis(v){
		$('innerPuis').innerHTML='Puissance entre '+v[0]+' et '+v[1]+' ch.'
		$('puis_min').value = v[0];
		$('puis_max').value = v[1];
	}
	function changeKm(v){
		$('innerKm').innerHTML='Entre '+v[0]+' et '+v[1]+' km'
		$('km_min').value = v[0];
		$('km_max').value = v[1];
	}
	function voituresTrier(ct, st){
		$('ct').value = ct;
		$('st').value = st;
		updateDatas();
	}
	function voituresGoTo(pg_cour){
		$('pg_cour').value = pg_cour;
		updateDatas();
	}
	function updateDatas(){
		var ct 			= $('ct').value;
		var st 			= $('st').value;
		var pg_cour 	= $('pg_cour').value;
		var prix_min 	= $('prix_min').value;
		var prix_max 	= $('prix_max').value;
		var puis_min 	= $('puis_min').value;
		var puis_max 	= $('puis_max').value;
		var km_min 		= $('km_min').value;
		var km_max 		= $('km_max').value;
		var marque 		= $('marque').value;
		var modele 		= $('modele').value;
		var categorie 	= $('categorie').value;
		var carburant 	= $('carburant').value;
		var fourn	 	= $('fourn') ? $('fourn').value : '';
	//	var type	 	= $('type') ? $('type').value : '';
		var pict	 	= $('pict') ? $('pict').checked : false;
		var porte 		= $('porte').value;
		var options		= getChkValues('option').join(',');
		var type="";
		if($('type_occasion') || $('type_neuve')){
			if($('type_neuve') && $('type_neuve').value == "N") type="N";
//			else if($('type_neuve').checked) type="N";
			else if($('type_occasion').checked) type="O";
			else if($('type_premium').checked) type="P";
			else type="";
		}
		document.body.style.cursor = 'wait';
		$('ajaxLoading2').style.display="block";
		/*
		new Effect.Morph('tabRes',{
		  style:'background:#ddd;',
		  duration:0.8
		});
		*/
		new Ajax.Updater(	'tabRes',
							"ajax.array.vehicules.php",
							{	method:'get',
								parameters:'ct='+ct
											+'&st='+st
											+'&pg_cour='+pg_cour
											+'&prix_min='+prix_min
											+'&prix_max='+prix_max
											+'&puis_min='+puis_min
											+'&puis_max='+puis_max
											+'&km_min='+km_min
											+'&km_max='+km_max
											+'&marque='+marque
											+'&fourn='+fourn
											+'&type='+type
											+'&pict='+(pict ? 1 : 0)
											+'&modele='+modele
											+'&categorie='+categorie
											+'&carburant='+carburant
											+'&porte='+porte
											+'&options='+options,
								asynchronous:true,
								onSuccess: function(t) { },
								onComplete: function(){
									document.body.style.cursor = 'default';
									$('ajaxLoading2').style.display="none";
									/*
									new Effect.Morph('tabRes',{
									  style:'background:#fff;',
									  duration:0.8
									});
									*/
								},
								evalScripts:true
							}
						);
		return false;
	}
	function getChkValues(id) {
		var res = new Array();
		var j = 0;
		try {
			var options = $$('input[id^='+id+']');
			options.each(function(option) {	if(option.checked) res[j++] = option.value;	});
		} catch (e) { /* alert(e); */	}
		return res;
	}
	function updateModele(options){
		document.body.style.cursor = 'wait';
		value = options[(options.selectedIndex)].value;
		new Ajax.Updater(	'upd_modele',
							"ajax.updateselect.modele.php?value="+value,
							{	method:'post',
								asynchronous:true,
								onSuccess: function(t) { },
								onComplete: function(){
									Effect.DropOut('modele',{afterFinish:function(){
										document.body.style.cursor = 'default';
										Effect.Appear('modele');
										updateDatas();
									}});
								},
								evalScripts:true
							}
						);
		return false;
	}
	function updateModele3(options){
		document.body.style.cursor = 'wait';
		value = options[(options.selectedIndex)].value;
		new Ajax.Updater(	'voitures_modele',
							"ajax.updateselect.modele3.php?value="+value,
							{	method:'post',
								asynchronous:true,
								onSuccess: function(t) { },
								onComplete: function(){
									Effect.DropOut('Vmodele',{afterFinish:function(){
										document.body.style.cursor = 'default';
										Effect.Appear('Vmodele');
										prepareInputsForHints();
									}});
								},
								evalScripts:true
							}
						);
		return false;
	}
	function switchPict(lib, href, id){
		$(id).setAttribute("onclick","return false;");
//		$(lib).style.display="none";
		new Effect.Fade(lib,{duration:0.3, afterFinish:function(){
			$(lib).src=href;
			new Effect.Appear(lib,{duration:0.5, afterFinish:function(){$(id).setAttribute("onclick","switchPict('"+lib+"', '"+href+"', '"+id+"');return false;");}});
		}});
	}
/* Gestion des Hints */
	function prepareInputsForHints() {
		var inputs = document.getElementsByTagName("input");
		for (var i=0; i<inputs.length; i++){
			// test to see if the hint span exists first
			if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
				// the span exists!  on focus, show the hint
				inputs[i].onfocus = function () {
					this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
				}
				// when the cursor moves away from the field, hide the hint
				inputs[i].onblur = function () {
					this.parentNode.getElementsByTagName("span")[0].style.display = "none";
				}
			}
		}
		var inputs = document.getElementsByTagName("textarea");
		for (var i=0; i<inputs.length; i++){
			// test to see if the hint span exists first
			if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
				// the span exists!  on focus, show the hint
				inputs[i].onfocus = function () {
					this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
				}
				// when the cursor moves away from the field, hide the hint
				inputs[i].onblur = function () {
					this.parentNode.getElementsByTagName("span")[0].style.display = "none";
				}
			}
		}

		// repeat the same tests as above for selects
		var selects = document.getElementsByTagName("select");
		for (var k=0; k<selects.length; k++){
			if (selects[k].parentNode.getElementsByTagName("span")[0]) {
				selects[k].onfocus = function () {
					this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
				}
				selects[k].onblur = function () {
					this.parentNode.getElementsByTagName("span")[0].style.display = "none";
				}
			}
		}
	}
