/* Affiche ou Cache l'élément */

nbpieces = 0;
nbselected = 0;


function toggle( targetId ){
  if ( (document.getElementById) && ( target = document.getElementById( targetId ) ) ){
  		target = document.getElementById( targetId );
  			if (target.style.display == "block"){
  				target.style.display = "none";
  			} else {
				 target.style.display = "block";			 
  			}
  	}
}

function showTab( element ) {
	
	if ( document.getElementById( 'p' + element ).style.display == 'none' ) {

		hideTab( 'composition' );
		hideTab( 'conseil' );
		hideTab( 'conservation' );
		document.getElementById( 'p' + element ).style.display	= 'block';
		document.getElementById( 'l' + element).className		= 'active';

	} else {
		
		hideTab( 'composition' );
		hideTab( 'conseil' );
		hideTab( 'conservation' );
	}

}

function hideTab( element ) {

	if (document.getElementById('p' + element))
		document.getElementById('p' + element).style.display	= 'none';

	if (document.getElementById('l' + element))
		document.getElementById('l' + element).className		= '';

}

function showNav( element ) {
		


	//	document.getElementById('nav-hevin').style.display		= 'none';
		document.getElementById('nav-hevin2').style.display		= 'none';
		document.getElementById('nav-maison').style.display		= 'none';
		document.getElementById('nav-produits').style.display	= 'none';
		document.getElementById('nav-club').style.display		= 'none';
		document.getElementById('nav-actu').style.display		= 'none';
		document.getElementById('nav-presse').style.display		= 'none';
		document.getElementById('nav-contact').style.display	= 'none';
		document.getElementById('nav-entreprise').style.display	= 'none';

		if ( element != 'NULL' )
			document.getElementById( element ).style.display	= 'block';

}

function confirmDelete() {
		
		var agree = confirm ( str_delete_from_cart );	
		return agree;
}


function jph_error( msg , mod ) {
	
	if ( !mod ) {

		if ( msg != '' )
			msg = '<img style="vertical-align:middle" src="img/check_off.png" width="12" height="12" border="0" alt=""> ' + msg;

		document.getElementById('errormsg').innerHTML = msg;
		document.getElementById('errormsg').style.color = 'red';
		document.getElementById('errormsg').style.fontWeight = 'bold';

	} else {

		if ( msg != '' )
			msg = '<img style="vertical-align:middle" src="img/check_on.png" width="12" height="12" border="0" alt=""> ' + msg;
		document.getElementById('errormsg').innerHTML = msg;
		document.getElementById('errormsg').style.color = 'green';
		document.getElementById('errormsg').style.fontWeight = 'bold';
	}
	
}


function chooseBox( nb ) {

	jph_error('');
	nbpieces = nb;

}


/* Cette fonction est utilisée pour le choix des boîtes */

function updateBox ( element ) {
	
	i=0;

	while( element.options[i] ) {
		key = element.options[i].value;
		document.getElementById( 'infos-' + key ).style.display = "none";
		i++;
	}

	key = element.options[element.selectedIndex].value;
	document.getElementById( 'infos-' + key ).style.display = "block";


}


/* ---------------- Tablettes ---------------- */

function submitTablettes() {


	//alert( 'nbpieces : ' + nbpieces );

	if ( nbpieces == 0 ) {

		jph_error( str_choose_a_box , false );
		return false;

	} else {

		input = document.getElementsByTagName("input");
		
		i=0;
		nbselected = 0;
		while( input[i] ) {
			if( input[i].className == 'tablette' ) nbselected += eval( input[i].value );
			i++;
		}

		//alert( 'nbselected : ' + nbselected );
		
		if ( nbpieces == nbselected) {

			jph_error("" , true );
			return true;

		} else if ( nbpieces < nbselected ) {
			
			inttrop = nbselected - nbpieces;
			if ( inttrop == 1 ) strtrop = "1 tablette"; else strtrop = inttrop + " tablettes";

			jph_error( "Vous avez selectionné "  + strtrop + " de trop par rapport à la boîte choisie !" , false );
			return false;
			
		} else {
			
			intencore = nbpieces - nbselected

			if ( intencore == 1 ) strencore = "1 tablette"; else strencore = intencore + " tablettes";

			jph_error( str_box_not_full + " " + strencore + "." , false );
			return false;
			
		}

	}
	

}

function view_box( url ) {
	box = window.open( url , 'box' , 'width=300,height=300,resize=0,scrollbars=0' );
	return false;
}
function view_prod2( lurl ) {
	prod = window.open( lurl , 'prod' , 'width=411,height=218,resize=0,scrollbars=0' );
	return false;
}

function view_desc( url ) {
	desc = window.open( url , 'desc' , 'width=300,height=300,resize=0,scrollbars=1' );
	return false;
}

function view_poemes( url ) {
	element = document.getElementById("poeme");
	url = url + "?id=" + element.options[element.selectedIndex].value
	poemes = window.open( url , 'poemes' , 'width=500,height=500,resize=0,scrollbars=0' );
	return false;
}

function open_surmesure( url ) {
	surmesure = window.open( url , 'surmesure' , 'width=760,height=450,resize=0,scrollbars=0,status=0' );
	return false;
}

function popup_open( url ) {
	pop = window.open( url + '&popup=1' , 'pop' , 'width=400,height=500,resize=1,scrollbars=1' );
	return false;
}

function popupami_open( url ) {
	pop = window.open( url + '?popup=1' , 'pop' , 'width=370,height=600,resize=1,scrollbars=1' );
	return false;
}

function add2favorite() {
	window.external.AddFavorite('http://www.jphevin.com/','Jean-Paul Hévin - Chocolatier');
	return false;
}


function frlink( url ) {
	
	 var isLocalhost = url.search(/localhost.+/);
	 var isRemotehost = url.search(/www.jphevin.com.+/);
	 var isPdf = url.search(/pdf/);
	 var isPopup = url.search(/popup/);
	 
	 if( isPopup != - 1 ) {
		string_return = popup_open( url );
	 } else if( isPdf != -1 ) {
		window.open( url ); string_return = false;
	 } else if( isLocalhost != -1 || isRemotehost != -1 ) {
		  string_return = true;
	 } else {
		window.open( url ); string_return = false;
	 }

	return string_return;
	
}

/*
function word_count( chaine ) {

	var exp = new RegExp("[a-zA-Z0-9éèêëàáâäóòôöíìîïçÉÈÊËÀÁÂÄÒÓÔÖÌÍÎÏÇ-]+","g");
	var mots = chaine.match(exp);

	nbmots = mots.length;

	if (nbmots <= 300 )
		jph_error( 'Votre texte fait ' + nbmots + ' mots' , 1 );
	else
		jph_error( 'Votre texte fait ' + nbmots + ' mots' , 0 );

}
*/

function submitProduit() {

		input = document.getElementsByTagName("input");
		
		quantt = 0;
		i=0;
		while( input[i] ) {
			if( input[i].className == 'quantite' ) quantt += eval( input[i].value );
			i++;
		}

		if ( quantt == 0 ) {
			alert( str_no_selected_quantity );
			return false;

		} else {
			return true;
		}



}

function verif(){
	if (confirm("Etes vous sûr ?")) { // Clic sur OK
           return true;
       }
	   else{return false;}
}
