/*-----------------------------------------------------------------------------------------------*/
//
// Copyright (c) 2009 Agence Clark (http://www.agence-clark.com)
//
/*-----------------------------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------------------------*/
// Init Page
/*-----------------------------------------------------------------------------------------------*/
Event.observe(window, 'load', InitPage, false);
function InitPage(){
	//-- Rollover Input Image --//
	RollOverImage();

	// Diffusion
	if($('DifLien')) Event.observe($('DifLien'),'focus',function(){ $('DifLien').select(); });
	if($('DifCode')) Event.observe($('DifCode'),'focus',function(){ $('DifCode').select(); });
	if($('DifCode2')) Event.observe($('DifCode2'),'focus',function(){ $('DifCode2').select(); });

	// fix Hauteur
	if($('contenu')) setMaxHeight();

	//-- Bt Ajout ami -- //
	if($('add_ami')) ajoutAmi();

	// infoBulle
	if($('bt_infobulle')){
		var iB1 = new infoBulle('bt_infobulle',{
			iB_contenu : '<img src="/images/fr/repartitions.png" alt="" />',
			iB_ancrage : 'RB'
		});
	}

}

/*-----------------------------------------------------------------------------------------------*/
// Fonctions
/*-----------------------------------------------------------------------------------------------*/
var setMaxHeight = function(){
	if($('gauche')){
		var Gauche = $('gauche').down('.m');
		var CentreHeight = 0;
	} else {
		var Gauche = $('gauche2').down('.m');
		var CentreHeight = $('centre').getHeight();
	}
	var DroiteHeight = $('droite').getHeight();
	var GaucheHeight = Gauche.getHeight();

	if(GaucheHeight < CentreHeight || GaucheHeight < DroiteHeight){
		if(DroiteHeight > CentreHeight) Gauche.style.height = (DroiteHeight-66)+'px';
		else Gauche.style.height = (CentreHeight-82)+'px';
	}
};

//-- Ajout de champs email ami --//
var ajoutAmi = function(){
	var div = $('add_ami');
	var bt = $('bt_add_ami');
	Event.observe(bt, 'click', function(evt){
		if($$('#add_ami input').length < 4) {
			var nb = $$('#add_ami input').length;
			var valeur_template = {name: 'AmiEmailAmi[]'};
			var template = new Template('<div class="ligne destinataire"><input type="text" name="#{name}" /></div>');
			var nouveau = template.evaluate(valeur_template);
			new Insertion.Bottom(div, nouveau);
		}
	});
}

/*-----------------------------------------------------------------------------------------------*/
// Made By GFI Informatique
/*-----------------------------------------------------------------------------------------------*/

function change_prefix(string)
{
    switch ($(string + '_country_code').value)
    {
      case 'FRA':
        $(string + '_telephone_prefix').innerHTML = '<strong> (+33)</strong>';
        $(string + '_fax_prefix').innerHTML = '<strong> (+33)</strong>';
        break;
      case 'MCO':
        $(string + '_telephone_prefix').innerHTML = '<strong>(+377)</strong>';
        $(string + '_fax_prefix').innerHTML = '<strong>(+377)</strong>';
        break;
      default:
        break;
    }
}

function set_avg(id, min, max)
{
	var MyTab = new Array(5, 10, 15, 20, 20, 10, 15, 20, 30, 30);

console.log(id);
  
  if (id == 0)
  {
		var MyText = "Vous ne pouvez pas collecter de cr&eacute;dits.";
		$('SMS_avg').innerHTML = MyText;
  }
	else if (id < 5)
	{
		var MyText = "Vous pouvez obtenir jusqu'&agrave; <span style=\"color: #F9801D;\">"+ MyTab[id-1]*50 +"</span> cr&eacute;dits par mois.";
		$('SMS_avg').innerHTML = MyText;
	}
	else if (id == 5)
	{
		var MyText = "Vous pouvez obtenir au moins <span style=\"color: #F9801D;\">"+ MyTab[id-1]*min +"</span> cr&eacute;dits par mois.";
		$('SMS_avg').innerHTML = MyText;
	}

	else if (id > 5 && id < 10)
	{
		var MyText = "Vous pouvez obtenir jusqu'&agrave; <span style=\"color: #F9801D;\">"+ MyTab[id-1]*50 +"</span> cr&eacute;dits par mois.";
		$('EMAIL_avg').innerHTML = MyText;
	}
	else if (id == 10)
	{
		var MyText = "Vous pouvez obtenir au moins <span style=\"color: #F9801D;\">"+ MyTab[id-1]*min +"</span> cr&eacute;dits par mois.";
		$('EMAIL_avg').innerHTML = MyText;
	}
}