var myAgent   = navigator.userAgent.toLowerCase();
var myVersion = parseInt(navigator.appVersion);

var is_ie   = ((myAgent.indexOf("msie") != -1)  && (myAgent.indexOf("opera") == -1));
var is_nav  = ((myAgent.indexOf('mozilla')!=-1) && (myAgent.indexOf('spoofer')==-1)
                && (myAgent.indexOf('compatible') == -1) && (myAgent.indexOf('opera')==-1)
                && (myAgent.indexOf('webtv') ==-1)       && (myAgent.indexOf('hotjava')==-1));

var is_win   =  ((myAgent.indexOf("win")!=-1) || (myAgent.indexOf("16bit")!=-1));
var is_mac    = (myAgent.indexOf("mac")!=-1);


function doInsert(ibTag, ibClsTag, isSingle)
{
	var isClose = false;
	var obj_ta = document.upform.texte_article;

	if ( (myVersion >= 4) && is_ie && is_win) // Ensure it works for IE4up / Win only
	{
		if(obj_ta.isTextEdit){ // this doesn't work for NS, but it works for IE 4+ and compatible browsers
			obj_ta.focus();
			var sel = document.selection;
			var rng = sel.createRange();
			rng.colapse;
			if((sel.type == "Text" || sel.type == "None") && rng != null){
				if(ibClsTag != "" && rng.text.length > 0)
					ibTag += rng.text + ibClsTag;
				else if(isSingle)
					isClose = true;
	
				rng.text = ibTag;
			}
		}
		else{
			if(isSingle)
				isClose = true;
	
			obj_ta.value += ibTag;
		}
	}
	else
	{
		if(isSingle)
			isClose = true;

		obj_ta.value += ibTag;
	}

	obj_ta.focus();
	
	// clear multiple blanks
//	obj_ta.value = obj_ta.value.replace(/  /, " ");

	return isClose;
}	



function tag_insert(tag,text_prompt,text)
{
    var FoundErrors = '';
    var enterTXT   = prompt(text_prompt, text);

    if (enterTXT=='') {
        FoundErrors = 1;
		alert("La boite de dialogue est vide!");
    }
    if (enterTXT==null) {
        FoundErrors = 1;
    }
    if (FoundErrors) {
        return;
    }
	doInsert("["+tag+"]"+enterTXT+"[/"+tag+"]", "", false);
}


function monteicons(zegif){
doInsert(zegif,"",false);
}







function id2element(id)
{
    if (!document.getElementById)return;
    if (document.all)return eval("document.all." + id);
    else
    return document.getElementById(id);
}



function toggle(id,type,collapse) 
{
	var x = window.document.getElementsByTagName(type);
		if(collapse==1){
			for (var i=0;i<x.length;i++){	x[i].style.display = 'none'; }
		}
	id2element(type + id).style.display = (id2element(type + id).style.display == "none" ? "block" : "none");
}

function comms_read(id)
{
	window.open('/read_comms.php?article='+id,'comms','width=480,height=440,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no');
}
function comms_add(id)
{
	window.open('/add_comms.php?article='+id,'comms','width=480,height=440,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no');
}

function blockrightclick(){
var message="";
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=new Function("return false")
}
