/**
 * specific scripts
 * 
 * This file contains some of the specific javascripts used on the site
 *
 * @author Antoine Morcos
 * @version 1.0
 */
 
/**
 * these functions are used to add code to message on forums 
 *
 * @author : Antoine Morcos
 * @date : 31/05/2008 18:28
 */

function wrapSelection(txtarea, lft, rgt)
{
	if (document.all)
	{
    	IEWrap(txtarea,lft, rgt);
    }
	else if (document.getElementById)
	{
		mozWrap(txtarea, lft, rgt);
    }
}

function IEWrap(txtarea, lft, rgt)
{
	strSelection = document.selection.createRange().text;

	if (strSelection!="")
	{
		document.selection.createRange().text = lft + strSelection + rgt;
	}
    else
	{
		txtarea.focus();
        if (document.selection)
		{
			txtarea.focus();
            sel = document.selection.createRange();
            sel.text = lft+rgt;
        }
    }
}

function mozWrap(txtarea, lft, rgt)
{
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd==1 || selEnd==2) selEnd=selLength;
	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + lft + s2 + rgt + s3;
}

function wrapSelectionWithLink(txtarea)
{
	var my_link = prompt("Entrez le lien :","http://");
	if (my_link != null)
	{
		lft="[url=" + my_link + "]";
		rgt="[/url]";
		wrapSelection(txtarea, lft, rgt);
	}
	return;
}

function wrapSelectionWithLinkVideo(txtarea)
{
	var my_link = prompt("Entrez le lien de la page où se trouve la vidéo :","http://");
	if (my_link != null)
	{
		lft="[video]" + my_link + "";
		rgt="[/video]";
		wrapSelection(txtarea, lft, rgt);
	}
	return;
}


