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()
{
	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() == '')
			return false;
	return true;
}

/************************************/ 
/* Usefull javascript functions		*/
/* Cedwik's quick					*/
/************************************/ 

// return the value of an element by its id
function val(id){
	return document.getElementById(id).value;	
}

// set the value of an element by its id
function setVal(id, val){
	if(isset(id))
		document.getElementById(id).value = val;
}

// display an element by its id
function block(id){
	if(isset(id))
		document.getElementById(id).style.display="block";	
}

// undisplay an element by its id
function none(id){
	if(isset(id))
		document.getElementById(id).style.display="none";	
}

function display(id){
	if(!isset(id))
		return;
	if(document.getElementById(id).style.display=="none")
		block(id);
	else
		none(id);
}

// undisplay an element by its id
function isset(id){
	if(document.getElementById(id)) 
		return true;
	else 
		return false
}

function isChecked(id){
	return 	document.getElementById(id).checked;
}

/********************************************************
BUT : Modifier la position horizontal d'une balise (gauche)

PARAMETRES : 
	> id : document à afficher 
	> nb : nb de pixels de déplacement
	> speed : vitesse
********************************************************/
function left(id,nb,width,len,speed,module_extension){
	none("arrow_left"+module_extension);
	var left = document.getElementById(id).offsetLeft;
	if(parseInt(nb) < parseInt(width)){
		left += parseInt(len);
		nb = parseInt(nb) + parseInt(len);
		document.getElementById(id).style.left = left+"px";
		setTimeout("left('"+id+"', '"+nb+"', '"+width+"', '"+len+"', '"+speed+"', '"+module_extension+"')",speed);
	}else if(document.getElementById(id).offsetLeft != 0){
		block("arrow_left"+module_extension);
	}else{
		none("arrow_left"+module_extension);
	}
	block("arrow_right"+module_extension);
}

/********************************************************
BUT : Modifier la position horizontal d'une balise (gauche)

PARAMETRES : 
	> id : document à afficher 
	> nb : nb de pixels de déplacement
	> width : largeur maxi
	> speed : vitesse
********************************************************/
function right(id,nb,width,len,speed,nb_parts,module_extension){
	none("arrow_right"+module_extension);
	if(parseInt(nb) < parseInt(width)){
		var left = document.getElementById(id).offsetLeft;
		left -= parseInt(len);
		nb = parseInt(nb) + parseInt(len);
		document.getElementById(id).style.left = left+"px";
		setTimeout("right('"+id+"', '"+nb+"', '"+width+"', '"+len+"', '"+speed+"', '"+nb_parts+"', '"+module_extension+"')",speed);
	}else if(document.getElementById(id).offsetLeft*-1 != (nb_parts-1)*width){
		block("arrow_right"+module_extension);
	}else{
		none("arrow_right"+module_extension);
	}
	block("arrow_left"+module_extension);
}

function autoLoop(id,nb,width,len,speed,nb_parts,module_extension,direction,id_status,execTime){
	
	if(nb_parts > 0 && nb == 0)
		block("arrow_right"+module_extension);

		
	if(isset(id_status) && val(id_status)=="true" && nb_parts > 1){
		if(direction == "right" && document.getElementById("arrow_right"+module_extension).style.display == "block"){
			right(id,0,width,len,speed,nb_parts,module_extension);
			nb++;
		}else if(direction == "left" && document.getElementById("arrow_left"+module_extension).style.display == "block"){
			left(id,0,width,len,speed,module_extension);
			nb--;
		}else if(direction == "left"){
			right(id,0,width,len,speed,nb_parts,module_extension);
			direction = "right";
			nb++;
		}else{ 
			left(id,0,width,len,speed,nb_parts,module_extension);
			direction = "left";
			nb--;
		}
		
		if(nb == 0){
			none("arrow_left"+module_extension);
			block("arrow_right"+module_extension);
		}else if(nb == nb_parts-1){
			block("arrow_left"+module_extension);
			none("arrow_right"+module_extension);
		}else{
			block("arrow_left"+module_extension);
			block("arrow_right"+module_extension);
		}
	}
	setTimeout("autoLoop('"+id+"', '"+nb+"', '"+width+"', '"+len+"', '"+speed+"', '"+nb_parts+"', '"+module_extension+"', '"+direction+"', '"+id_status+"', '"+execTime+"')",execTime);
}
