var cpt=1;

if(session_commune=="") {
	document.observe('lightview:loaded', function() {
		getCommuneId();										  
	});											  
}
//Event.observe(window, 'load', );

Event.observe(window, 'load', function() {
	init();
});

function changeCity() {
   //'search_commune_header','the_cities_header'
   $('jacheteA').hide();
   $('search_commune_header2').show();
   $('autocomplete').focus();
   setModule('promotion');setActionType('liste_secteurs');
}

function viewIllustration(url, TheTitle) {
	Lightview.show({
	  href: url,
	  rel: 'image',
	  title: TheTitle,
	  topclose:false,
	  options: {
	    autosize: true,
	    topclose: false,
		menubar:true,
	    ajax: {
	      method: 'get'
	    }
	  }
	});

}

function setTiitle(Thetext) {
	alert("rr");
}
	
/*function getCommuneId() {
		Lightview.show({
		  href: 'index.php?module=home&actiontype=enter',
		  rel: 'iframe',
		  title: 'Bienvenue sur Jachetelocal',
		  caption: 'Choisir une ville',
		  options: {
		  	width:550,
		    height:450,
		    topclose:false,
			menubar:false,
		    ajax: {
		      method: 'get'
		    }
		  }
		});
	
}*/

function showOverlayout() {
	var trueHeight = document.body.clientHeight;
	$('overlayout').setStyle({
	  width: document.body.clientWidth+'px',
	  height: trueHeight+'px'
	});

	$('overlayout').show();
}

function hideOverlayout() {
	$('overlayout').hide();
}



function chbg(element,evt,prefix) {
	if(evt=='over') {
		$(element).setStyle({
		  backgroundImage: "url("+prefix+"public_html/jachetelocal/public/images/promo_over.jpg)"
		});
	}
	else {
		$(element).setStyle({
		  backgroundImage: "url("+prefix+"public_html/jachetelocal/public/images/promo.jpg)"
		});
	}
}

function chbg_generic(element,path) {

	$(element).setStyle({
	  backgroundImage: "url("+path+")"
	});

}

/*function getCities() {
	if(($('code_postal').value).length==5){
		
		$('the_cities').show();
		new Ajax.Updater(
			'listes_villes',
			'index.php?module=homePro&actiontype=getCities',
			{
				method: 'get',
				parameters: {code: $('code_postal').value},
				onComplete: function(transport) {
		    		Event.observe('commune_id', 'change', viewEnter);
					Event.observe('btn_enter', 'click', checkCity);
				}
			}
		);
		
		//alert($('commune_id').value);
	}
}*/

function getCities(id_search, id_res_search, id_select_liste, commune_id_value) {
	
	if(arguments[4]!="") var onchangeValue=arguments[4];
	else var onchangeValue="";
	
	if(!isNaN($(id_search).value)) {
		if(($(id_search).value).length==5) { // si c'est un nombre traitement par code postal
				new Ajax.Updater(
					id_select_liste,
					'index.php?module=homePro&actiontype=getCities',
					{
						method: 'get',
						parameters: {search_commune: $(id_search).value, search_type:'cp', commune_id_value:commune_id_value, onchangeValue:onchangeValue},
						onComplete: function(transport) {
				    		$(id_res_search).show();
							if(id_search=="code_postal_enter") {
								Event.observe('commune_id', 'change', viewEnter);
							}
							if(id_search=="search_commune")
				    			$('ajax-loader-getcities').hide();
						},
						onLoading: function(transport) {
							if(id_search=="search_commune")
				    			$('ajax-loader-getcities').show();
						}
					}
				);
	
		}
	}
	else
	{

			new Ajax.Updater(
				id_select_liste,
				'index.php?module=homePro&actiontype=getCities',
				{
					method: 'get',
					parameters: {search_commune: $(id_search).value, search_type:'label', commune_id_value:commune_id_value},
					onComplete: function(transport) {
						$(id_res_search).show();
						if(id_search=="code_postal_enter") {
								Event.observe('commune_id', 'change', viewEnter);
						}
						if(id_search=="search_commune")
				    			$('ajax-loader-getcities').hide();
					},
					onLoading: function(transport) {
			    		if(id_search=="search_commune")
				    			$('ajax-loader-getcities').show();
					}
				}
			);
		
		
	}

}




function checkCity() {
	if($('commune_id').value!="-1")
		goToJAL();
	else
		alert('Veuillez sélectionner une ville');
}

function goToJAL() {
	window.parent.location="index.php?module=home&actiontype=setCommuneId&commune_id="+$('commune_id').value;
	Lightview.hide();
}



function changeCityHeader() {
	
	if($F('commune_id2')=="") {
		// peut être que la personne n'a pas sélectionné la ville dans la lise
		// dans ce cas vérifier son existence 
		new Ajax.Request(
			'index.php?module=home&actiontype=checkCity',
			{
				method: 'post',
				parameters: {nom_commune: $F('autocomplete')},
				onComplete: function(transport) {
					if(transport.responseText!="false")
						goToParam('promotion','liste_secteurs','commune_id='+transport.responseText);
					else
						alert("Ville inexistante");
				}
			}
		);	
		
	}else{
		goToParam('promotion','liste_secteurs','commune_id='+$F('commune_id2'));
		//goTo('home','setCommuneId');
	}
}
	
