﻿function textToggler(id)
{
	if($(id+"Element") && $(id+"Toggler"))
	{
		$(id+"Element").addClass("hidden");
		$(id+"Toggler").addClass("text-toggler-plus");
		$(id + "Toggler").bind("click", function() {
		    //alert('scripts.js - textToggler - fonction mootools');
		    if (this.hasClass("text-toggler-plus")) {
		        this.removeClass("text-toggler-plus");
		        this.addClass("text-toggler-moins");
		    }
		    else {
		        this.removeClass("text-toggler-moins");
		        this.addClass("text-toggler-plus");
		    }
		    var m = $(id + "Element");
		    if (m.hasClass("visible")) {
		        m.removeClass("visible");
		        m.addClass("hidden");
		    }
		    else {
		        m.removeClass("hidden");
		        m.addClass("visible");
		    }
		});
	}
}

window.addEvent("domready",function(){
	textToggler("mention");
	textToggler("contribution");
	
	tabbedbox_init();
});


function openPopup(url, name, w, h)
{
  w += 32;
  h += 96;
  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  var win = window.open(url,
    name,
    'width=' + w + ', height=' + h + ', ' +
    'left=' + wleft + ', top=' + wtop + ', ' +
    'location=no, menubar=no, ' +
    'status=no, toolbar=no, scrollbars=auto, resizable=yes');
  win.resizeTo(w, h);
  win.moveTo(wleft, wtop);
  win.focus();
}

function popup(page, width, height)
{
	window.open(page,'', 'resizable=yes, location=no, width='+width + ', height='+ height +', menubar=no, status=no, scrollbars=no, menubar=no');
}

function openWindow(page, width, height)
{
    window.open(page,'', 'resizable=yes, location=yes, width='+width + ', height='+ height +', menubar=yes, status=yes, scrollbars=yes, menubar=yes');
}

function displayFAQ(id)
{
	answer = document.getElementById("answerFAQ"+id);
	if(answer.style.display == "none" || answer.style.display == "")
	{
		answer.style.display = "block";
	}
	else
	{
		answer.style.display = "none";
	}
}


/***
*   Tabbed Box Scripts
******/

var tabbedbox_maxTabs = 5;

function tabbedbox_init()
{
// l'appel à cette fonction provoque l'erreur javascript qui affecte les pages ne contenant pas les onglets "internet/ tv / téléphone" 
// -> pour corriger ça, avant de faire l'appel on vérifie que l'existence du tableau "tab1" en question...
    v = document.getElementById('tab1')

    if(v != null) tabbedbox_toggleTab('tab1'); 
}

function tabbedbox_toggleTab(id)
{
    tabbedbox_hideTabs();
    tabbedbox_showTab(id);
}

function tabbedbox_showTab(id)
{
    // tab
    document.getElementById(id).className = "tab on";
    // tab-content
    document.getElementById(id+"-content").style.display = "block";
}

function tabbedbox_hideTabs()
{
    for (var i=0; i < tabbedbox_maxTabs; i++)
    {
        var id = "tab" + i;
        var tab = document.getElementById(id);
        
        if (tab != null)
        {
            // tab
            tab.className = "tab off";
            // tab-content
            document.getElementById(id+"-content").style.display = "none";
        }
    }
}


/* utilisé pour les texbox pour mettre un texte par défaut
*/
function setDefaultText(input,text)
{
	if(input.value == text)
		input.value = "";
	input.onblur = function(){
		if(input.value == "")
			input.value = text;
	};
}
