/*************************
 * FONCTION JAVASCRIPT
*************************/

function montre(id) {
	var d = document.getElementById(id);
		for (var i = 1; i<=10; i++) {
			if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
		}
	if (d) {d.style.display='block';}
}

function changeUrl( formulaire )
{
	location.href = formulaire.ListeURL.options[formulaire.ListeURL.selectedIndex].value;
}

function popup_old( 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 popup(img, width, height, titre) {
	var marg = 10;
	var width = ( width ? width + marg : 800 + marg );
	var height = ( height ? height + marg : 600 + marg );
		w = open("",'image','width='+width+',height='+height+',toolbar=no,scrollbars=no,resizable=no');	
		w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE></HEAD>");
		/*w.document.write("<SCRIPT language=javascript>function checksize()  { if (document.images[0].complete) {  window.resizeTo(document.images[0].width+12,document.images[0].height+30); window.focus();} else { setTimeout('check()',250) } }</"+"SCRIPT>");*/
		/*onload='checksize()' */
		w.document.write("<BODY onClick='window.close()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0><IMG src='"+img+"' alt='"+titre+"' border=0>");
		w.document.write("");
		w.document.write("</BODY></HTML>");
		w.document.close();
}

function FitPic() {
       iWidth = document.body.clientWidth;
       iHeight = document.body.clientHeight;
       iWidth = document.images[0].width - iWidth;
       iHeight = document.images[0].height - iHeight;
       window.resizeBy(iWidth, iHeight);
       self.focus();
}

function hide_block( admin, val, 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";
		if (admin) document.images['puce_' + val].src='images/moins.gif';
	}
	else
	{
		if ( val1 ) hide1.style.display = "none";
		if (admin) document.images['puce_' + val].src='images/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 ) ) );
	}
}
