/**
 * Fonction qui fait changer le texte dans la bande bleue au milieu
 */

function clignotement()
{
	clignotementIndex = ((clignotementIndex + 1) % clignotementTextes.length) ;
	document.getElementById('header-texte').innerHTML = clignotementTextes[clignotementIndex] ;
}

function navHover()
{
	var lis = document.getElementById('navmenu').getElementsByTagName('li') ;
	for (var i=0; i<lis.length; i++)
	{
		lis[i].onmouseover = function()
			{
				this.className += ' iehover' ;
			} ;
		lis[i].onmouseout = function()
			{
				this.className = this.className.replace(new RegExp("\\biehover\\b"), "") ;
			} ;
	}
}

function Chargement(el_img, el_block)
{
	// Propriétés
	this.img = el_img ;
	this.block = el_block ;
	// onunload
	this.desactiver = function()
		{
			this.block.style.display = 'none' ;
		} ;
	// onload
	this.activer = function()
		{
			var img = new Image ; 
			img.src = this.img.src ;
		} ;
	// onsubmit
	this.lancer = function()
		{
			this.block.style.display = 'block' ;
		} ;
}

/**
 * Affiche ou cache un élément
 * paramètres :
 *   var id : identifiant de l'élément à cacher ou à montrer
 *   var show : TRUE pour montrer, FALSE pour cacher, ommettre pour inverser
 */

function showhide(id, show)
{
	if(typeof show == 'undefined')
		show = document.getElementById(id).style.display != 'block' ;
	document.getElementById(id).style.display = show ? 'block' : 'none' ;
}

/**
 * Enregistre une aide dans un formulaire
 */
function set_aide(elId, lbId)
{
	el = document.getElementById(elId) ;
	lb = document.getElementById(lbId) ;
	lb.onmouseover = function() {showhide(elId, true)} ;
	lb.onmouseout = function() {showhide(elId, false)} ;
	showhide(elId, false) ;
}

/**
 * Compteur pour zone TEXTAREA
 */
// Intervalle du compteur
var interval_compteur ;

// Début du compteur
function initCompteur(id_textarea, id_compteur, maxlength)
{
	updateCompteur(id_textarea, id_compteur, maxlength) ;
	document.getElementById(id_textarea).onfocus = function()
		{
			interval_compteur = setInterval("updateCompteur('"+id_textarea+"', '"+id_compteur+"', "+maxlength+");", 100) ;
		}
	document.getElementById(id_textarea).onblur = function()
		{
			clearInterval(interval_compteur) ;
		}
}

// Exécution du compteur
function updateCompteur(id_textarea, id_compteur, maxlength)
{
	var actuallength = document.getElementById(id_textarea).value.length ;
	title = document.getElementById(id_compteur).title ;
	title = title.replace('%1\$s', (maxlength - actuallength)) ;
	title = title.replace('%2\$s', actuallength) ;
	title = title.replace('%3\$s', maxlength) ;
	document.getElementById(id_compteur).innerHTML = title ;
	document.getElementById(id_compteur).className = (actuallength > maxlength) ? 'compteur compteur-ko' : 'compteur compteur-ok' ;
}

/**
 * Change une photo
 */

function change_photo(photo, id, largeur, hauteur) {
	document.getElementById(id).src = photo ;
	document.getElementById(id).width = largeur ;
	document.getElementById(id).height = hauteur ;
}

/**
 * Fonction pour le crédit
 */

function getTaux()
{
	fTauxAnnuel = parseFloat(new MeilleursTaux().V111) / 100 ;
	//fTauxAnnuel = 10 / 100 ;
	return fTauxAnnuel ;
}

function writeTaux()
{
	document.write(Affiche.pourcent(getTaux(), 2)) ;
}

function getMensualite(prix)
{
	var fTauxAnnuel = getTaux() ;
	var fTauxPeriodique = Credit.tauxPeriodiqueActuariel(fTauxAnnuel) ;
	var iEcheances = Credit.echeancesNombreAnnees(20)
	var fMensualite = Credit.montantEcheanceConstant(prix, fTauxPeriodique, iEcheances) ;
	return fMensualite ;
}

function writeMensualite(prix)
{
	document.write(Affiche.prix(getMensualite(prix), 0)) ;
}
