var width;
var height;
var widthBloc
var heightBloc;
var idElmt;
var idBouton;
var etat="open";

var timeRepet=80;
var palierWidth=18;
var palierHeight=18;
var widthMini=300;
var heightMini=20;

function calculer_resolution(){
	resolution = screen.width+'_'+screen.height;
	switch (resolution) {
		case '800_600':
		document.body.style.backgroundImage='url(habillage/classic/background/'+resolution+'.jpg)';	
		break;
		
		case '1024_768':
		document.body.style.backgroundImage='url(habillage/classic/background/'+resolution+'.jpg)';	
		break;
		
		case '1152_864':
		document.body.style.backgroundImage='url(habillage/classic/background/'+resolution+'.jpg)';	
		break;
		
		case '1280_768':
		document.body.style.backgroundImage='url(habillage/classic/background/'+resolution+'.jpg)';	
		break;
		
		case '1280_800':
		document.body.style.backgroundImage='url(habillage/classic/background/'+resolution+'.jpg)';	
		break;
		
		case '1280_960':
		document.body.style.backgroundImage='url(habillage/classic/background/'+resolution+'.jpg)';	
		break;
		
		case '1280_1024':
		document.body.style.backgroundImage='url(habillage/classic/background/'+resolution+'.jpg)';	
		break;
		
		case '1440_900':
		document.body.style.backgroundImage='url(habillage/classic/background/'+resolution+'.jpg)';	
		break;
		
		case '1680_1050':
		document.body.style.backgroundImage='url(habillage/classic/background/'+resolution+'.jpg)';	
		break;
		
		default: 
		document.body.style.backgroundImage='url(habillage/classic/background/1680_1050.jpg)';	
		break;
	}	
}

function calculer_resolution_forum(){
	resolution = screen.width+'_'+screen.height;
	switch (resolution) {
		case '800_600':
		document.body.style.backgroundImage='url(../../../v2/habillage/classic/background/'+resolution+'.jpg)';	
		break;
		
		case '1024_768':
		document.body.style.backgroundImage='url(../../../v2/habillage/classic/background/'+resolution+'.jpg)';	
		break;
		
		case '1152_864':
		document.body.style.backgroundImage='url(../../../v2/habillage/classic/background/'+resolution+'.jpg)';	
		break;
		
		case '1280_768':
		document.body.style.backgroundImage='url(../../../v2/habillage/classic/background/'+resolution+'.jpg)';	
		break;
		
		case '1280_800':
		document.body.style.backgroundImage='url(../../../v2/habillage/classic/background/'+resolution+'.jpg)';	
		break;
		
		case '1280_960':
		document.body.style.backgroundImage='url(../../../v2/habillage/classic/background/'+resolution+'.jpg)';	
		break;
		
		case '1280_1024':
		document.body.style.backgroundImage='url(../../../v2/habillage/classic/background/'+resolution+'.jpg)';	
		break;
		
		case '1440_900':
		document.body.style.backgroundImage='url(../../../v2/habillage/classic/background/'+resolution+'.jpg)';	
		break;
		
		case '1680_1050':
		document.body.style.backgroundImage='url(../../../v2/habillage/classic/background/'+resolution+'.jpg)';	
		break;
		
		default: 
		document.body.style.backgroundImage='url(../../../v2/habillage/classic/background/1680_1050.jpg)';	
		break;
	}	
}


function goTo(url){window.location.replace(url);}
function trim(chaine){return chaine.replace(/^\s*|\s*$/g, "");}
function confirmation(message,url){	if(confirm(message))goTo(url);}

var regexPseudo		= new RegExp(/^[a-zA-Z0-9][\.,a-zA-Z0-9]*[a-zA-Z0-9]$/);
var regexLettre 	= new RegExp(/^[a-zA-Z]+$/);
var regexChiffre 	= new RegExp(/^[0-9]+$/);
var regexEmail 		= new RegExp(/^[a-zA-Z0-9][a-zA-Z0-9-._]+@[a-zA-Z0-9-._]{2,}[.][a-zA-Z]{2,5}$/);
function goCaviste()
{
	if(trim(document.formulaireCaviste.searchCavisteDep.value)!='')
		return true;
	return false;
}
function goEscapade()
{
	if(trim(document.formulaireEscapade.rechercheEscapade.value)!='')
		return true;
	return false;
}

function deletePartenaire(id)
{
	confirmation('Etes vous sur de vouloir supprimer ce partenaire?','?fonction=traiteDelPartenaire&partenaire='+id);
}

function afficher_armagnac(){
	document.getElementById('armagnac').style.display="block";
	document.getElementById('blanche').style.display="none";
	document.getElementById('floc').style.display="none";
}

function afficher_blanche(){
	//document.getElementById('armagnac').style.display="none";
	document.getElementById('blanche').style.display="block";
	document.getElementById('floc').style.display="none";
}

function afficher_floc(){
	//document.getElementById('armagnac').style.display="none";
	document.getElementById('blanche').style.display="none";
	document.getElementById('floc').style.display="block";
}

function change_CocktailBlanche(new_image){
   	var page;
	document.getElementById('img_CocktailBlanche').src="habillage/classic/blanche/"+new_image+".jpg";
	switch(new_image)
	{
		case 'bulls_blood':
			page='printCocktailBlanche-fiche_bullsBlood.html';
			break;
		case 'white_pure':
			page='printCocktailBlanche-fiche_whitePure.html';
			break;
		case 'white_tonic':
			page='printCocktailBlanche-fiche_whiteTonic.html';
			break;
		default:
			page='printCocktailBlanche.html';
	}
	changeHref('lienImpression',page);
}

function change_CocktailArmagnac(new_image){
   var page;
    document.getElementById('img_CocktailArmagnac').src="habillage/classic/blanche/"+new_image+".jpg";
	switch(new_image)
	{
		case 'Armagnac_on_the_rocks':
			page='printCocktailArmagnac-fiche_armagnacRock.html';
			break;
		case 'Sweet_Armagnac':
			page='printCocktailArmagnac-fiche_sweetArmagnac.html';
			break;
		default:
			page='printCocktailArmagnac.html';
	}
	changeHref('lienImpression',page);
}

function changeHref(id,page)
{
	document.getElementById(id).href=page;	
}

function changeEtatBloc(idBloc){
    if(document.getElementById(idBloc).style.display=="none")
        document.getElementById(idBloc).style.display="block";
    else
        document.getElementById(idBloc).style.display="none";
}

function closeSite()
{
    if(document.getElementById('page').style.display=="none"){
        document.getElementById('page').style.display="block";
        document.getElementById('boutonOpenClose').innerHTML="Fermer le site";
    }
    else{
        document.getElementById('page').style.display="none";
        document.getElementById('boutonOpenClose').innerHTML="Ouvrir le site";
    }
}

function openBlocIdentifiactionAdherent()
{
	changeEtatBloc('blocIdentifiactionAdherent');
}


function initialisation(elmt,bouton)
{
    if(etat=="open")
    {
        etat="move";
        idElmt=document.getElementById(elmt);
        idBouton=document.getElementById(bouton);
        widthBloc=idElmt.offsetWidth;
        heightBloc=idElmt.offsetHeight;
        width=idElmt.offsetWidth;
        height=idElmt.offsetHeight;
        intervalRed = setInterval('reduire()',timeRepet);
    }
    else if(etat=="close")
    {
        etat="move";
        idElmt.style.display="block";
        intervalAug = setInterval('augmenter()',timeRepet);
    }
}

function reduireWindows(attribut,valeur)
{
    if(attribut=='width'){
        var newWidth=(width-valeur<0)?0:width-valeur;
        idElmt.style.width=newWidth;
        width=newWidth;
    }
    else if(attribut=='height'){
        var newHeight=(height-valeur<0)?0:height-valeur;
        idElmt.style.height=newHeight;
        height=newHeight;
    }
}

function augmenterWindows(attribut,valeur)
{
    if(attribut=='width'){
        var newWidth=(width+valeur>=widthBloc)?widthBloc:width+valeur;
        idElmt.style.width=newWidth;
        width=newWidth;
    }
    else if(attribut=='height'){
        var newHeight=(height+valeur>=heightBloc)?heightBloc:height+valeur;
        idElmt.style.height=newHeight;
        height=newHeight;
    }
}

function reduire(){
    /*if(width>widthMini){
        reduireWindows('width',palierWidth);
    }else*/ if(height>heightMini)
        reduireWindows('height',palierHeight);
    else{
        idElmt.style.width="1px";
        idElmt.style.height="1px";
        clearInterval(intervalRed);
        /*reduireWindows('width',widthMini+1);*/
        /*width=0;*/
        etat="close";
        idBouton.innerHTML="Ouvrir";
    }
}

function augmenter(){
    width=widthBloc;
    idElmt.style.width=width;
    
    if(height<heightBloc)
        augmenterWindows('height',palierHeight);
    else{
        clearInterval(intervalAug);
        augmenterWindows('width',palierWidth+1);
        width=widthBloc;
        etat="open";
        idBouton.innerHTML="X Fermer";
    }
    /*if(width<widthBloc){
        augmenterWindows('width',palierWidth);
    }
    else if(height<heightBloc)
        augmenterWindows('height',palierHeight);
    else{
        clearInterval(intervalAug);
        augmenterWindows('width',palierWidth+1);
        width=widthBloc;
        etat="open";
        idBouton.innerHTML="Fermer";
    }*/
}

/* Pour les fonds �crans */
var tabNom= new Array();
var tabWidth= new Array();
var tabHeight= new Array();
var tabFic= new Array();
var tabExt= new Array();
var pathPhoto;
var element;

function changeImage(numero){
    document.getElementById(element).innerHTML='<a href="dlFichier-type_fondEcran-fichier_'+tabFic[numero]+'-ext_'+tabExt[numero]+'.html" target="_blank" title="Telecharger le fond ecran"><img src="'+pathPhoto+"/"+tabNom[numero]+'" width="450" height="360" border="0" /></a>';
}

function initFondEcran(tabPhoto,path,elmt){
    pathPhoto=path;
    element=elmt;
    tabPhoto=tabPhoto.split("|");
    for(i=0; i<tabPhoto.length; i++)
    {
        param=tabPhoto[i].split("*");
        tabNom[i]=param[0];
		tabFic[i]=param[1];
		tabExt[i]=param[2];
        tabWidth[i]=param[3];
        tabHeight[i]=param[4];
    }
    changeImage(0,element);
}

function decocheTout(chaineTab){
    tabCheckbox=chaineTab.split(",");
    for(i=0; i<tabCheckbox.length; i++)
    {
            document.getElementById(tabCheckbox[i]).checked="";
    }
}


function openEvenenement()
{
	//window.open('habillage/classic/evenemenet/evenement.htm','Evenement', 'menubar=no, status=no, scrollbars=no, menubar=no,width=390,height=562');
	initPopup('popup.','F&ecirc;tes des P&egrave;res','390','562','#ffffff','<img src=\"habillage/classic/evenement/fete_des_peres.jpg\" />');
}

function displayErreur(tabErreur,message)
{
	if(tabErreur.length>0)
	{
		for(i=0; i<tabErreur.length; i++)
		{message+=" - "+tabErreur[i]+"\n";}
		alert(message);
		return(false);
	}
	return(true)
}

function verifAddRevuePresse()
{
	erreur=new Array();
	if(trim(document.formulaire.titre.value) == "")
		erreur.push('Le titre est vide');
	if(trim(document.formulaire.pdf.value) == "")
		erreur.push('Il n\'y a pas de fichier PDF');
	else
	{
		var lg=trim(document.formulaire.pdf.value).length;
		var ext=(trim(document.formulaire.pdf.value).substr(lg-4)).toLowerCase();
		if(ext!='.pdf')
			erreur.push('Le fichier n\'est pas un pdf');
	}
	
	if(trim(document.formulaire.miniature.value) == "")
		erreur.push('Il n\'y a pas de miniature');
	else
	{
		var lg=trim(document.formulaire.miniature.value).length;
		var ext=(trim(document.formulaire.miniature.value).substr(lg-4)).toLowerCase();
		if(ext!='.jpg' && ext!='.jpeg' && ext!='.gif' && ext!='.png' && ext!='.bmp')
			erreur.push('La miniature n\'est pas une image');
	}
	return displayErreur(erreur,'Ajout de la revue de presse impossible\n');
}

//popup
var etatBtClose=false;
function initPopup(id, name, width, height, backColor, texte, align)
{
	var widthSreen = screen.width;
	var heightScreen = screen.height;
	
	var btClose = document.createElement("img");
	var popup = document.createElement("div");
	var titre = document.createElement("div");
	var contenu = document.createElement("div");
	var titreText= document.createElement("span");
	
	
	btClose.src="habillage/classic/close_off.png";
	btClose.id='btClose';
	btClose.style.cursor="pointer";
	btClose.onmouseover=function(){
							if(etatBtClose==false){
								document.getElementById('btClose').src="habillage/classic/close_on.png";
								etatBtClose=true;
							}
							else{
								document.getElementById('btClose').src="habillage/classic/close_off.png";
								etatBtClose=false
							}
						}
						
	btClose.onmouseout=function(){
							if(etatBtClose==false){
								document.getElementById('btClose').src="habillage/classic/close_on.png";
								etatBtClose=true;
							}
							else{
								document.getElementById('btClose').src="habillage/classic/close_off.png";
								etatBtClose=false
							}
						}
						
	btClose.onclick = function(){
		document.body.removeChild(document.getElementById('popup'));
	}
	btClose.style.background="#660000";
	btClose.align="right";
	titreText.innerHTML='<img src="habillage/classic/16_actu.png" style="vertical-align:middle;" /> '+name;
	titreText.style.background="#660000";
	
	titre.appendChild(btClose);
	titre.appendChild(titreText);
	titre.style.background="#660000";
	titre.style.padding="2px 10px";
	titre.style.height="22px";
	titre.style.color="#ffffff";
	titre.setAttribute("font","Verdana");
	
	contenu.innerHTML=texte;
	contenu.style.height=height+"px";
	
	popup.id="popup";
	popup.style.background="#660000";
	popup.style.border="#000000 1px solid";
	popup.style.width=width+"px";
	popup.style.position="absolute";
	popup.style.top='20px';
	popup.style.left='20px';

	
	
	popup.appendChild(titre);
	popup.appendChild(contenu);
	document.body.appendChild(popup);
}


function changeBtClose(btClose)
{
	if(etatBtClose==false){
		document.getElementById('btClose').src="habillage/classic/close_on.png";
		etatBtClose=true;
	}
	else{
		document.getElementById('btClose').src="habillage/classic/close_off.png";
		etatBtClose=false
	}
}

function verifFormContact()
{
	var erreur = new Array();
	
	if(trim(document.formulaire.email.value)=="")
		erreur.push('L\'adresse e-mail est vide');
	else if(!regexEmail.test(trim(document.formulaire.email.value)))
		erreur.push('L\'adresse e-mail semble incorrecte');
	if(trim(document.formulaire.message.value)=="")
		erreur.push('Le message est vide');
	return displayErreur(erreur,'Envoi du message impossible\n');
}


var lastIdCliqueOpen=0; //Memorise le dernier id clique afin de pouvoir le fermer
var blocOpen=null;

function movePhoto(idTd,idActu,fonction,checks)
{
	if(checks=='1')var check1='checked';
	if(checks=='2')var check2='checked';
	document.getElementById(idTd).className="newFormTdOpen";
	document.getElementById(idTd).innerHTML='<form method="post" enctype="multipart/form-data" action="'+fonction+'" style="margin:0px; padding=0px;"><input type="radio" name="choix" value="1" '+check1+'>Gauche<input type="radio" name="choix" value="2" '+check2+'>Droite <input type="hidden" name="id" value="'+idActu+'"><input type="submit" value="Valider" name="movePhotoActu" class="boutonNewsForm" /></form>';
	modifLastId(idTd,'photo');
}

function addPhoto(idTd,idActu,fonction)
{
	document.getElementById(idTd).className="newFormTdOpen";
	document.getElementById(idTd).innerHTML='<form method="post" enctype="multipart/form-data" action="'+fonction+'" style="margin:0px; padding=0px;" onSubmit="return validAddPhoto();">Photo: <input type="file" id="fichier" name="fichier" class="boutonNewsForm" size="25"> <input type="hidden" name="id" value="'+idActu+'"><input type="submit" value="Ajouter" name="addPhotoActu" class="boutonNewsForm" /></form>';
	modifLastId(idTd,'photo');
}

function editTitre(idTd,idActu,fonction)
{
	document.getElementById(idTd).className="newFormTdOpen";
	document.getElementById(idTd).innerHTML='<form method="post" enctype="multipart/form-data" action="'+fonction+'" style="margin:0px; padding=0px;" onSubmit="return validAddPhoto();">Nouveau titre: <input name="titre" type="text" size="30" maxlength="128"> <input type="hidden" name="id" value="'+idActu+'"><input type="submit" value="Modifier" name="editTitre" class="boutonNewsForm" /></form>';
	modifLastId(idTd,'titre');
}

function changePdf(idTd,idActu,fonction)
{
	document.getElementById(idTd).className="newFormTdOpen";
	document.getElementById(idTd).innerHTML='<form method="post" enctype="multipart/form-data" action="'+fonction+'" style="margin:0px; padding=0px;" onSubmit="return validAddPhoto();">PDF: <input type="file" id="pdf" name="pdf" class="boutonNewsForm" size="25"> <input type="hidden" name="id" value="'+idActu+'"><input type="submit" value="Modifier" name="modifPdfActu" class="boutonNewsForm" /></form>';
	modifLastId(idTd,'pdf');
}

function addDocument(idTd,idActu,fonction)
{
	document.getElementById(idTd).className="newFormTdOpen";
	document.getElementById(idTd).innerHTML='<form method="post" enctype="multipart/form-data" action="'+fonction+'" style="margin:0px; padding=0px;" onSubmit="return validAddDocument();">Titre: <input type="text" id="titreAddDoc" name="titreAddDoc" style="margin-right:10px;">Document: <input type="file" id="fichier" name="fichier" class="boutonNewsForm" size="25"> <input type="hidden" name="id" value="'+idActu+'"><input type="submit" value="Ajouter" name="addPhotoActu" class="boutonNewsForm" /></form>';
	modifLastId(idTd,'document');
}

function destroyTd(id){
	document.getElementById(id).className="newFormTdClose";
	document.getElementById(id).innerHTML='';
}

function modifLastId(idTd,type){
	if(idTd!=lastIdCliqueOpen && lastIdCliqueOpen!=0|| (idTd==lastIdCliqueOpen && blocOpen==type))
	{
		destroyTd(lastIdCliqueOpen);
		if(idTd==lastIdCliqueOpen && blocOpen==type)
		{
			lastIdCliqueOpen=0;
		}
		else{
			lastIdCliqueOpen=idTd;
		}
		
		blocOpen=type;
	}
	else{
		lastIdCliqueOpen=idTd;
		blocOpen=type;
	}
}

function validAddPhoto(){
	if(document.getElementById('fichier').value.length==0){
		alert('Vous n\'avez pas sélectionné de photo');
		return false;
	}
}

function validAddDocument(){
	if(document.getElementById('titreAddDoc').value.length==0){
		alert('Vous n\'avez pas donné de titre au document');
		return false;
	}
	if(document.getElementById('fichier').value.length==0){
		alert('Vous n\'avez pas sélectionné de document');
		return false;
	}
	return true;

}

function verifAddPartenaire()
{
	var erreur = new Array();
	
	if(trim(document.formulaire.titre.value)=="")
		erreur.push('Le titre est vide');
	if(trim(document.formulaire.url.value)=="")
		erreur.push('L\'url du site est vide');
	if(trim(document.formulaire.logo.value)=="")
		erreur.push('Le logo est vide');
	return displayErreur(erreur,'Ajout du partenaire impossible\n');
}

function verifEditPartenaire()
{
	var erreur = new Array();
	
	if(trim(document.formulaire.titre.value)=="")
		erreur.push('Le titre est vide');
	if(trim(document.formulaire.url.value)=="")
		erreur.push('L\'url du site est vide');
	return displayErreur(erreur,'Modification du partenaire impossible\n');
}

function verifEnvoyerAmi()
{
	var erreur = new Array();
	if(trim(document.formulaireEnvoyerAmi.send_user_email.value)=="")
		erreur.push('Votre e-mail est vide');
	else if(!regexEmail.test(trim(document.formulaireEnvoyerAmi.send_user_destinataire.value)))
		erreur.push('Votre adresse e-mail semble incorrecte');
	if(trim(document.formulaireEnvoyerAmi.send_user_destinataire.value)=="")
		erreur.push('L\'e-mail du destinataire est vide');
	else if(!regexEmail.test(trim(document.formulaireEnvoyerAmi.send_user_destinataire.value)))
		erreur.push('L\'adresse e-mail du destinataire semble incorrecte');
	return displayErreur(erreur,'Envoi du message impossible\n');
}