/*
** tools.js :: TLMODIF
*/
function mm(name)
{
  var m1 = m2 = str = "";
	if (name == "co") { // contact
    m1="u:/c@etls .a-firdmh\"o>n=<";
    m2="H;9B?5=GCA;>76D13DF6;3645@>6>DF8<65??5<@5<70A>5?5:3DACE3DF6;3645@>6>DF8<65??5<@5<70A>5?5:3DAH2;E";
	} else if (name == "cos") { // contact suisse
    m1=">\":e ah.outbil<r=@cm/wnf";
    m2=">546?3G@1C5<=:825=<89A;=93E<F7B6105=<89A;=93E<F7B6>D50";
	} else if (name == "coq") { // contact québec
    m1="ot\"i.urdanclhe= fqm</:@-s>";
    m2="C8?<6=@>2B83;10E:0918:14A:F=731309HG1=66=G7=G;5B3=6=4:0B2I:0918:14A:F=731309HG1=66=G7=G;5B3=6=4:0BCD8I";
	} else if (name == "com") { // commande
    m1="/@\"ts rd:c.nh<>-e=ulfiamo";
    m2="=F5<6@DA2GFEC3H89HGGF;7@1@7E3EH;4?3@66@?7@?CBGE@6@:9HG2>9HGGF;7@1@7E3EH;4?3@66@?7@?CBGE@6@:9HG=0F>";
	} else if (name == "comq") { // commande québec
    m1="cnoqdlr/>uim=:et@<.-saf\" h";
    m2="AEHI6>F<G;E:5?2=02;;E14>B30@>4:?:21DC?>66>C4>C59;:>6>B02;G802;;E14>B30@>4:?:21DC?>66>C4>C59;:>6>B02;A7E8";
	} else if (name == "coms") { // commande suisse
    m1="io<l.tf=r-d> :saecn/um@h\"";
    m2="2?<G8@67HE?0351=A1EE?B:@4AGF@:0501B>95@88@9:@93DE0@8@4A1EH;A1EE?B:@4AGF@:0501B>95@88@9:@93DE0@8@4A1E2C?;";
	} else if (name == "cop") { // servicepresse
    m1="r\"fep<d/c-ml=nota u@>s:vi.h";
    m2="5@AJ032<1:@H;?>FE30GH83403EE3C36H?H>=E9?30039639;B:H303I8>:1DE30GH83403EE3C36H?H>=E9?30039639;B:H303I8>:57@D";
	} else if (name == "cofr") { // foreign rights
    m1="@><alcftmsi-uon=.g\"rh:/de ";
    m2="23IDCH6?B83:47=E6=CH:A>@C:AD790HG:7:=>9;7HCCH;GH;4<8:HCH@5=8B16=CH:A>@C:AD790HG:7:=>9;7HCCH;GH;4<8:HCH@5=82F31";
	} else if (name == "copq") { // servicepresse QC
    m1=".>rm-=fcne@dv :<l\"iqpuota/sh";
    m2="?H=K2965A3HB@GF>J92<B79D29JJ90C7:9;BGBF8J4G92294;94@E3B92907F3A1J92<B79D29JJ90C7:9;BGBF8J4G92294;94@E3B92907F3?IH1";
	} else if (name == "coag") { // agentlitteraire
    m1="s<>d\".netom/g -hia=@cul:rf";
    m2="1A=?H7IB4:A@F89GA<768F@887HA@H7C73@8@960>87HH7>37>FE:@7H75D9:42A<768F@887HA@H7C73@8@960>87HH7>37>FE:@7H75D9:1;A2";
	} else if (name == "coa") { // auteurs
    m1="t./hie>g@mlr=s-<f\"a c:ndou";
    m2="?BC3;5@<A9B4:0HE7;BB:4B85G404HF=>05;;5>G5>:I945;51DH9A67;BB:4B85G404HF=>05;;5>G5>:I945;51DH9?2B6";
	} else if (name == "col") { // lucidaelle
    m1="n@: iar=o/>feumhl<\"tsc.-d";
    m2="A53?6<;7B>54@C82@=E4H5<@@<1<H4C480DGC<66<GH<G@=>4<6<FE8>B:@=E4H5<@@<1<H4C480DGC<66<GH<G@=>4<6<FE8>A95:";
	} else if (name == "con") { // nikobella
    m1="</lkad@thf\"oi=n >c-mr.ub:es";
    m2="04?8DI9=:C4<27;H><3;GI2246I5<7<;>JB7IDDIB5IB2FC<IDIEA;C:@><3;GI2246I5<7<;>JB7IDDIB5IB2FC<IDIEA;C014@";
	} else if (name == "cof") { // fgarneau
    m1="<dh-n e=rs.go:mc@tu>\"l/fai";
    m2="0H5286G7D>HIEA<=G:;H846HB@61IAI<493A68863163EB>I686:?<>DCG:;H846HB@61IAI<493A68863163EB>I686:?<>0FHC";
	} else if (name == "cor") { // rachel
    m1="c<-\"uefgnds/h:or@a >m.it=ly";
    m2="1AB<?56H3DAFIG>=?E7>J@59FGF>8:2G5??52952I4DF5?5E0>D3C?E7>J@59FGF>8:2G5??52952I4DF5?5E0>D1;AC";
	} else if (name == "mde") { // martine deloupy
    m1="o\"< hniae.ctpmryfd=>u:l/@";
    m2="2734>8@B1=76F;0E=7>;658HA8F0D<?9:0=1C=7>;658HA8F0D<?9:0=2G7C";
	}
 	for (j = 0; j < m2.length; j++)
   	str += m1.charAt(m2.charCodeAt(j)-48);
	return(str);
}
function repre(id) {
	var wnd=window.open(baseDir+'TL/libraires/'+id+'.php', '_blank', 'menubar=no,scrollbars=yes,resizable=yes,width=700,height=290');
}
function flippage(id) {
	var wnd=window.open(baseDir+'TL/book/'+id, '_blank', 'menubar=no,scrollbars=yes,resizable=yes,width=950,height=670');
}
function flippresse(id) {
	var wnd=window.open(baseDir+'TL/dossiers-de-presse/'+id, '_blank', 'menubar=no,scrollbars=yes,resizable=yes,width=950,height=670');
}
function showImg(type) {
	if (type == 1) window.open(baseDir+'TL/lucidaelle/img.php?i=1', '_blank', 'menubar=no,toolbar=no,scrollbars=no,resizable=no,status=no,width=420,height=620');
	else if (type == 2) window.open(baseDir+'TL/lucidaelle/img.php?i=2', '_blank', 'menubar=no,toolbar=no,scrollbars=no,resizable=no,status=no,width=396,height=620');
	else if (type == 3) window.open(baseDir+'TL/lucidaelle/img.php?i=3', '_blank', 'menubar=no,toolbar=no,scrollbars=no,resizable=no,status=no,width=530,height=775');
	else if (type == 4) window.open(baseDir+'TL/lucidaelle/img.php?i=4', '_blank', 'menubar=no,toolbar=no,scrollbars=no,resizable=no,status=no,width=904,height=620');
	else if (type == 5) window.open(baseDir+'TL/lucidaelle/img.php?i=5', '_blank', 'menubar=no,toolbar=no,scrollbars=no,resizable=no,status=no,width=461,height=620');
	else if (type == 6) window.open(baseDir+'TL/lucidaelle/img.php?i=6', '_blank', 'menubar=no,toolbar=no,scrollbars=no,resizable=no,status=no,width=437,height=648');
	else if (type == 7) window.open(baseDir+'TL/lucidaelle/img.php?i=7', '_blank', 'menubar=no,toolbar=no,scrollbars=no,resizable=no,status=no,width=597,height=775');
	else if (type == 8) window.open(baseDir+'TL/lucidaelle/img.php?i=8', '_blank', 'menubar=no,toolbar=no,scrollbars=no,resizable=no,status=no,width=530,height=775');
	else if (type == 9) window.open(baseDir+'TL/lucidaelle/img.php?i=9', '_blank', 'menubar=no,toolbar=no,scrollbars=no,resizable=no,status=no,width=530,height=757');
}
/*
** Prestashop starts here
*/
function ps_round(value, precision)
{
	if (typeof(roundMode) == 'undefined')
		roundMode = 2;
	if (typeof(precision) == 'undefined')
		precision = 2;
	
	method = roundMode;
	if (method == 0)
		return ceilf(value, precision);
	else if (method == 1)
		return floorf(value, precision);
	precisionFactor = precision == 0 ? 1 : Math.pow(10, precision);
	return Math.round(value * precisionFactor) / precisionFactor;
}

function	autoUrl(name, dest)
{
	var loc;
	var id_list;

	id_list = document.getElementById(name);
	loc = id_list.options[id_list.selectedIndex].value;
	if (loc != 0)
		location.href = dest+loc;
	return ;
}

function	autoUrlNoList(name, dest)
{
	var loc;

	loc = document.getElementById(name).checked;
	location.href = dest + (loc == true ? 1 : 0);
	return ;
}

/*
** show or hide element e depending on condition show
*/
function toggle(e, show)
{
	e.style.display = show ? '' : 'none';
}

function toggleMultiple(tab)
{
    var len = tab.length;

    for (var i = 0; i < len; i++)
        if (tab[i].style)
            toggle(tab[i], tab[i].style.display == 'none');
}

/**
* Show dynamicaly an element by changing the sytle "display" property
* depending on the option selected in a select.
*
* @param string $select_id id of the select who controls the display
* @param string $elem_id prefix id of the elements controlled by the select
*   the real id must be : 'elem_id'+nb with nb the corresponding number in the
*   select (starting with 0).
*/
function showElemFromSelect(select_id, elem_id)
{
	var select = document.getElementById(select_id);
	for (var i = 0; i < select.length; ++i)
	{
	    var elem = document.getElementById(elem_id + select.options[i].value);
		if (elem != null)
			toggle(elem, i == select.selectedIndex);
	}
}

/**
* Get all div with specified name and for each one (by id), toggle their visibility
*/
function openCloseAllDiv(name, option)
{
	var tab = $('*[name='+name+']');
	for (var i = 0; i < tab.length; ++i)
		toggle(tab[i], option);
}

/**
* Toggle the value of the element id_button between text1 and text2
*/
function toggleElemValue(id_button, text1, text2)
{
	var obj = document.getElementById(id_button);
	if (obj)
		obj.value = ((!obj.value || obj.value == text2) ? text1 : text2);
}

function addBookmark(url, title)
{
	if (window.sidebar)
		return window.sidebar.addPanel(title, url, "");
	else if ( window.external )
		return window.external.AddFavorite( url, title);
	else if (window.opera && window.print)
		return true;
	return true;
}

function writeBookmarkLink(url, title, text, img)
{
	var insert = '';
	if (img)
		insert = writeBookmarkLinkObject(url, title, '<img src="' + img + '" alt="' + escape(text) + '" title="' + escape(text) + '" />') + '&nbsp';
	insert += writeBookmarkLinkObject(url, title, text);
	document.write(insert);
}

function writeBookmarkLinkObject(url, title, insert)
{
	if (window.sidebar || window.external)
		return ('<a href="javascript:addBookmark(\'' + escape(url) + '\', \'' + escape(title) + '\')">' + insert + '</a>');
	else if (window.opera && window.print)
		return ('<a rel="sidebar" href="' + escape(url) + '" title="' + escape(title) + '">' + insert + '</a>');
	return ('');
}

function checkCustomizations()
{
	var tmp;
	var pattern = new RegExp(' ?filled ?');
	for (var i = 0; i < customizationFields.length; i++)
		/* If the field is required and empty then we abort */
		if (parseInt(customizationFields[i][1]) == 1 && $('#' + customizationFields[i][0]).val() == '' && !pattern.test($('#' + customizationFields[i][0]).attr('class')))
			return false;
	return true;
}

function ceilf(value, precision)
{
	if (typeof(precision) == 'undefined')
		precision = 0;
	var precisionFactor = precision == 0 ? 1 : Math.pow(10, precision);
	var tmp = value * precisionFactor;
	var tmp2 = tmp.toString();
	// If the current value has already the desired precision
	if (tmp2.indexOf('.') === false)
		return (value);
	if (tmp2.charAt(tmp2.length - 1) == 0)
		return value;
	return Math.ceil(tmp) / precisionFactor;
}

function floorf(value, precision)
{
	if (typeof(precision) == 'undefined')
		precision = 0;
	var precisionFactor = precision == 0 ? 1 : Math.pow(10, precision);
	var tmp = value * precisionFactor;
	var tmp2 = tmp.toString();
	// If the current value has already the desired precision
	if (tmp2.indexOf('.') === false)
		return (value);
	if (tmp2.charAt(tmp2.length - 1) == 0)
		return value;
	return Math.floor(tmp) / precisionFactor;
}

function setCurrency(id)
{
		$('form#setCurrency input#id_currency').val(id);  // TLMODIF la nouveauté ne met pas à jour la page (ajax) 
  	$('form#setCurrency').submit();
		/*
  	$.ajax({
		type: 'POST',
		url: baseDir + 'changecurrency.php',
		data: 'id='+id,
		success: function(msg)
		{
			alert("currency = " + id);
			location.reload(true);
		}
	});
		*/
}

