jQuery.noConflict();

function replaceBlock(url, div)
{
	new Ajax.Updater(div, url, {method: 'get', evalScripts: true});
}

function loading(div)
{
	document.getElementById(div).innerHTML = "<br /><img src=\"images/loading.gif\" alt=\"Loading...\" /><br />";
}

function loading2(div)
{
	document.getElementById(div).innerHTML = "<span style=\"display:inline-block;width:150px;text-align:center;\"><img src=\"images/loading2.gif\" alt=\"Loading...\" /></span>";
}

function change_attrib(div, display)
{
	document.getElementById(div).setAttribute("style", display);
}

function writediv(div, text)
{
	document.getElementById(div).innerHTML = text;
}

function chgloginInput (type, lang, value)
{	
	if(type == "username")
	{
		if(value == lang)
			document.getElementById("loginUsernameInput").value = "";
		else if(value == "")
			document.getElementById("loginUsernameInput").value = lang;
		else
			document.getElementById("loginUsernameInput").value = value;
	}
}

function checkRechercheDetailleeCanton(canton)
{
	if(canton != "")
	{
		document.forms.rechercheDetaillee.action2.disabled=false;
		loading2('rechercheVille');
		replaceBlock('requetes_ajax.php?action=rechercheDetailleeVilles&idCanton='+canton, 'rechercheVille');
		document.forms.rechercheDetaillee.action3.disabled=true;
		document.forms.rechercheDetaillee.action3.value="";
		document.forms.rechercheDetaillee.rechercheValider.disabled=false;
	}
	else
	{
		document.forms.rechercheDetaillee.action2.disabled=true;
		document.forms.rechercheDetaillee.action2.value="";
		document.forms.rechercheDetaillee.action3.disabled=true;
		document.forms.rechercheDetaillee.action3.value="";
		document.forms.rechercheDetaillee.rechercheValider.disabled=true;
	}
}

function checkRechercheDetailleeVille(ville)
{
	if(ville != "")
	{
		document.forms.rechercheDetaillee.action3.disabled=false;
		document.forms.rechercheDetaillee.rechercheValider.disabled=false;
		loading2('rechercheStation');
		replaceBlock('requetes_ajax.php?action=rechercheDetailleeStations&idVille='+ville, 'rechercheStation');
	}
	else
	{
		document.forms.rechercheDetaillee.action3.disabled=true;
		document.forms.rechercheDetaillee.action3.value="";
		document.forms.rechercheDetaillee.rechercheValider.disabled=true;
	}
}

// Evalutation station
var done=0;
var evalutation=0;
var pic = new Array();
pic[0]=new Image();
pic[0].src="images/star_grey.png";
pic[1]=new Image();
pic[1].src="images/star.png";
 
function stationRate(level)
{
	if (done)
		return false;
	
	for(i = 1; i < 6; i++)
	{
		document.getElementById('_'+i).src=(level<i)?pic[0].src:pic[1].src;
		evalutation = level;
	}
}
  
function stationRateValider()
{
	done=evalutation;
}

function stationRateRAZ()
{
	done=0;
	evalutation=0;
}

function prixStationEditionPrixValider(idStation, sp95_nombre, sp95_decimale, sp98_nombre, sp98_decimale, diesel_nombre, diesel_decimale)
{
	loading('prixAfficherStationDroite');
	replaceBlock('requetes_ajax.php?action=afficherDetailsStation&id='+idStation+'&sp95_nombre='+sp95_nombre+'&sp95_decimale='+sp95_decimale+'&sp98_nombre='+sp98_nombre+'&sp98_decimale='+sp98_decimale+'&diesel_nombre='+diesel_nombre+'&diesel_decimale='+diesel_decimale+'&msgId=3', 'prixAfficherStationDroite');
}

function prixStationEditionServicesValider(idStation, automate, bombonesGaz, garageMeca, gonflageRoues, jetLavage, chargeVehiculesE, tunnelLavage, wifi)
{
	loading('prixAfficherStationDroite');
	replaceBlock('requetes_ajax.php?action=afficherDetailsStation&id='+idStation+'&automate='+automate+'&bombonesGaz='+bombonesGaz+'&garageMeca='+garageMeca+'&gonflageRoues='+gonflageRoues+'&jetLavage='+jetLavage+'&chargeVehiculesE='+chargeVehiculesE+'&tunnelLavage='+tunnelLavage+'&wifi='+wifi+'&evaluation='+done+'&msgId=4', 'prixAfficherStationDroite');
}

function checkEditStationCanton(canton, ville)
{
	if(canton != "")
	{
		loading2('modifierStationVille');
		replaceBlock('requetes_ajax.php?action=modifierStationVilles&idCanton='+canton+'&idVille='+ville, 'modifierStationVille');
	}
	else
	{
		loading2('modifierStationVille');
		replaceBlock('requetes_ajax.php?action=modifierStationVilles', 'modifierStationVille');
	}
}

function prixStationEditionValider(idStation, champsRequis, nomStation, description, personneContact, ville, adresse, email, siteInternet, telephone, fax)
{
	if(nomStation == "" || ville == "")
	{
		alert(champsRequis);
	}
	else
	{
		loading('prixAfficherStationDroite');
		replaceBlock('requetes_ajax.php?action=modifierStationValider&id='+idStation+'&nomStation='+nomStation+'&description='+description+'&personneContact='+personneContact+'&ville='+ville+'&adresse='+adresse+'&email='+email+'&siteInternet='+siteInternet+'&telephone='+telephone+'&fax='+fax, 'prixAfficherStationDroite');
	}
}

function stationTransfererPrix (valeur, input)
{
	document.getElementsByName(input).item(0).value=valeur;
}

// Slide effect in "Aide"
function aide_slideup(number)
{
	for (i=1; i<=number; i++)
	{
		jQuery("#vertical_slide"+i+"").slideUp("fast");
	}
}

function aide_slide(number)
{
	jQuery("#vertical_slide"+number+"").slideToggle("slow");
}

function loadGoogleMap(positionX, positionY, nomStation) {

	//var position = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
	var position = new google.maps.LatLng(positionY, positionX);
	var map;
	var markerImage = 'http://www.carburants.ch/images/icone_station_small.png';
	
	var myOptions = {
		zoom: 15,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};

	var marker = new google.maps.Marker({
		position: position,
		title: nomStation,
		icon: markerImage
	});
	
	map = new google.maps.Map(document.getElementById("prixStationLocalisationCarte"), myOptions);
	map.setCenter(position);
	
	// To add the marker to the map, call setMap();
	marker.setMap(map);  
}
