/*
 * Gadget : Fader sur la transparence,
 * La classe sur gecko engine
 * CSS3 only...
 */
function fadeDisplay(obj) {
	obj_copy = obj ;
	faderInterval = setInterval("faderhight(obj_copy)",50) ;
}

function faderhight(obj){
	if (obj.style.opacity<1)
		obj.style.opacity=parseFloat(obj.style.opacity)+0.05
	else if(window.faderInterval)
					clearInterval(faderInterval)
}

document.getElementsByClassName = function(className) {
	var children = document.getElementsByTagName('*') || document.all;
	var elements = new Array();

	for (var i = 0; i < children.length; i++) {
		var child = children[i];
		var classNames = child.className.split(' ');
		for (var j = 0; j < classNames.length; j++) {
			if (classNames[j] == className) {
				elements.push(child);
				break;
			}
		}
	}
	return elements;
}

function popup(file,width,height)
{
  var top,left ;
  top = (screen.height - height) / 2 ;
  left = (screen.width - width) / 2 ;

  window.open(file+".php","","top="+top+",left="+left+",width="+width+",height="+height+",toolbars=no,resizable=no,scrollbars=no,modal=yes") ;
  return null ;
}

function jsPopup(id,width,height)
{
  //calcul du milieu
  var top,left ;
  left = (screen.width - width) / 2 ;
  top = (screen.height - height) / 2 ;

  img = document.getElementById(id) ;
  img.style.width = width + "px" ;
  img.style.height = height + "px" ;
  img.style.top = (top-100) + "px" ;
  img.style.left = (left-20) + "px" ;
  img.style.display = "block" ;
	img.style.opacity = 0;
	fadeDisplay(img) ;
}

function selectActivite()
{
  //ouvre la fenetre de selection d'activite en popup
  var  url = "/php/selection_activite.php" ;
  var width=640;
  var height=540;
  var top ;
  var left ;

  left = (screen.availWidth-width)/2 ;
  top = (screen.availHeight-height)/2 ;

  selection_window = window.open(url,"selection_window","width="+width+",height="+height+",left="+left+",top="+top+",modal=yes") ;
}

function submitme()
{
  selection = document.forms["listeActivite_form"].submit() ;
}

function jsClose(img)
{
  document.getElementById(img).style.display='none' ;
}

//initialisation du formulaire de contact
function initContactForm()
{
	var inputfields = document.getElementsByClassName("inputfield") ;
	for(i=0;i<inputfields.length;i++)
	{
		inputfields[i].onfocus = function() {
			this.style.backgroundColor = '#fca301' ;
			this.style.color="#b03e00" ;
		}

		inputfields[i].onblur = function() {
			this.style.backgroundColor = "#fff" ;
			this.style.color = "#000" ;
		}
	}
}

/*********************
 * mise en place des
 * graphs du CAC40
 *********************/
function setCAC(id,name)
{
	//récupération des images
	var img1 = document.getElementById("img_cac_1") ;
	var img2 = document.getElementById("img_cac_2") ;

	//récupération du titre
	var title_cac = document.getElementById("title_cac") ;

	//attribution des propriétés src et alt de l'image
	//en fonction des paramètres
	img1.src = "http://fr.ichart.yahoo.com/t?s=" + id ;
	img1.alt = name ;

	img2.src = "http://fr.ichart.yahoo.com/v?s=" + id ;
	img2.alt = name ;

	title_cac.innerHTML = name ;
}

/****
 * Switch Carte Meteo
 *********************/
function switchWeatherMap(delay)
{
var weather_map = document.getElementById("weather_map") ;
weather_map.src="http://www.meteoconsult.fr/image/meteodirect/md_france" + delay +"h.gif" ;
}

/******************************************************************************/


/*******************************************************************************
 * City_cp autocompleter
 ******************************************************************************/

var city_cp_selected = false ;
var city_cp_buffer = "" ;

/**
 * Callback function called after the element in the autocompleter list has been
 * updated
 * @param {Object} input input type text
 * @param {Object} li  li from the unordered list
 */
 function setSelectedCityCp(input, li){
  city_cp_selected = true ;
  city_cp_buffer = li.title ;
  input.value = li.title ;
  document.getElementById("submit_searchForm").focus() ;
 }

 function blurCityCpField(input){
  if(!city_cp_selected
     ||
     (city_cp_selected && input.value != city_cp_buffer))
  input.value = "" ;
 }


/*******************************************************************************
 * Activity autocompleter
 ******************************************************************************/

var activity_selected = false ;
var activity_buffer = "" ;
function setSelectedActivity(input, li){
  activity_selected = true ;
  activity_buffer = li.title ;
	var hash = li.id.split("_") ;
  input.value = li.title ;
	$("id_activity").value = hash[1] ;
}