/*************************
 * FONCTION JAVASCRIPT
  *************************/

function changeUrl( formulaire )
{
	location.href = formulaire.ListeURL.options[formulaire.ListeURL.selectedIndex].value;
}

function popup( url, width, height, nom )
{
	var marg = 30;
	var width = ( width ? width + marg : 800 + marg );
	var height = ( height ? height + marg : 600 + marg );
	var nom = ( nom ? nom : 'popup' );
	window.open ( url, nom, config='toolbar=0, scrollbars=1, location=0, statusbar=0, menubar=0, resizable=1, width='+width+', height='+height+', left=50, top=50' );
}

function hide_block( val1, val2, val3 )
{
	isIE = ( document.all );
	isNN6 = ( !isIE ) && ( document.getElementById );
	
	if (isIE)
	{
		if ( val1 ) hide1 = document.all['hide_' + val1];
		if ( val2 ) hide2 = document.all['hide_' + val2];
		if ( val3 ) hide3 = document.all['hide_' + val2];
	}
	else if (isNN6)
	{
		if ( val1 ) hide1 = document.getElementById( 'hide_' + val1 );
		if ( val2 ) hide2 = document.getElementById( 'hide_' + val2 );
		if ( val3 ) hide3 = document.getElementById( 'hide_' + val3 );
	}
	
	if ( hide1.style.display == "none" )
	{
		if ( val1 ) hide1.style.display = "";
		if ( val2 ) hide2.style.display = "none";
		if ( val3 ) hide3.style.display = "none";
		//document.images['puce_' + val].src='img/puce_moins.gif';
	}
	else
	{
		if ( val1 ) hide1.style.display = "none";
		//document.images['puce_' + val].src='img/puce_plus.gif';
	}
}

function insert_block( text, formulaire, block )
{
	var caretPos = null;
	var txtarea  = document.forms[formulaire].elements[block];
	text = '' + text + '';
	
	if ( txtarea.selectionEnd >= 0 && txtarea.setSelectionRange )
	{
		caretPos = ( txtarea.selectionEnd + text.length );
		var before = txtarea.value.substring( 0, txtarea.selectionStart );
		var after = txtarea.value.substring( txtarea.selectionEnd, txtarea.textLength );
		txtarea.value = before + text + after;
		txtarea.setSelectionRange( caretPos, caretPos );
	}
	else if ( txtarea.createTextRange && txtarea.caretPos ) {
		caretPos = txtarea.caretPos;
		caretPos.text = ( caretPos.text.charAt(caretPos.text.length - 1) == '' ? caretPos.text + text + '' : caretPos.text + text );
	}
	else
	{
		txtarea.value += text;
	}
	txtarea.focus();
}

function clicMenu( num )
{
	isIE = ( document.all )
	isNN6 = ( !isIE ) && ( document.getElementById )
	if ( isIE ) menu = document.all['menu' + num];
	if ( isNN6 ) menu = document.getElementById( 'menu' + num );
	
	if ( menu.style.display == 'none' )
	{
		menu.style.display = '';
		//document.images['image'+num].src = 'img/moins.gif';
	}
	else
	{
		menu.style.display = 'none';
		//document.images['image'+num].src = 'img/plus.gif';
	}
}

// ajout d'image au block
function add_tag( element_, val )
{
	var element = $(element_);
	
	element.value += val;
}

function insert_menu( menu_, element_ )
{
	var menu = $(menu_);
	var element = $(element_);
	var i = menu.selectedIndex;
	
	element.value += " {" + menu.options[i].value + "} ";
}

function changeVal( element_, mod, calc )
{
	var element = $(element_);
	var val = Number( element.value );
	
	if ( mod == "more" )
	{
		val += 1;
	}
	else if ( mod == "less" )
	{
		val -= 1;
	}
	
	element.value = val;
	
	if ( calc )
	{
		$( 'j_' + calc ).value = ( Number( $F( 'g_' + calc ) ) + Number( $F( 'n_' + calc ) ) + Number( $F( 'p_' + calc ) ) );
		$( 'dif_' + calc ).value = ( Number( $F( 'bp_' + calc ) ) - Number( $F( 'bc_' + calc ) ) );
	}
}
