/*************************
 * FONCTION JAVASCRIPT
*************************/
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version
var is_ie = ((clientPC.indexOf('msie') != -1) && (clientPC.indexOf('opera') == -1));
var is_win = ((clientPC.indexOf('win')!=-1) || (clientPC.indexOf('16bit') != -1));

function addPhoto(instext) {
	var mess = document.textes.corps_texte;
	//IE support
	if (document.selection) {
		mess.focus();
		sel = document.selection.createRange();
		sel.text = instext;
		document.textes.focus();
	}
	//MOZILLA/NETSCAPE support
	else if (mess.selectionStart || mess.selectionStart == '0') {
		var startPos = mess.selectionStart;
		var endPos = mess.selectionEnd;
		var chaine = mess.value;

		mess.value = chaine.substring(0, startPos) + instext + chaine.substring(endPos, chaine.length);

		mess.selectionStart = startPos + instext.length;
		mess.selectionEnd = endPos + instext.length;
		mess.focus();
	} else {
		mess.value += instext;
		mess.focus();
	}
}

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( 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 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 ) ) );
	}
}

