/* créateur du site : Netalapage (c)2006 www.netalapage.com, sites personnalisés */
/* nom de la page   : artiste-20080905.js                                                 */
/* protégé par SARL : Netalapage - création des sites Internet uniques, pas cher */

function addCodes(codeBox, codeOpen, codeClose, codeText) { // insert open and closing codes to selection in textarea

// variables needed for this function
var areas, selects, txtarea, image, couleur, taille, arriere
var theSelection, replaced, startPos, endPos
var scrollTop, myText, cpos, defaultText

	if (codeBox == 'FR' && document.form1) {
	// processing first code box and document.form understood by browser
		txtarea = document.form1.texteFR;
		image = document.form1.image1.value;
	} else if (codeBox == 'EN' && document.form2) {
	// processing second code box and document.form understood by browser
		txtarea = document.form2.texteEN;
		image = document.form2.image2.value;
	} else {
	// document.form method not understood by browser, so use different method
		areas = document.getElementsByTagName('textarea');
		selects = document.getElementsByTagName('select');
		if (codeBox == 'FR') {
		// first code box
			txtarea = areas[0];
			image = selects[0].value;
		} else if (codeBox == 'EN') {
		// second code box
			txtarea = areas[1];
			image = selects[1].value;
		}
	}

	// set default value between start and end tags depending on passed parameter
	if (codeText == '1') {
		defaultText = 'INSEREZ';
	} else if (codeText == '2') {
		defaultText = image;
	} else {
		defaultText = '';
	}
	
	// Code for Internet Explorer browser
	if (document.selection  && !is_gecko) {
		theSelection = document.selection.createRange().text;
		if (!theSelection) theSelection=defaultText;
		txtarea.focus();
		if (theSelection.charAt(theSelection.length - 1) == " ") { // exclude ending space char, if any
			theSelection = theSelection.substring(0, theSelection.length - 1);
			document.selection.createRange().text = codeOpen + theSelection + codeClose + " ";
		} else {
			document.selection.createRange().text = codeOpen + theSelection + codeClose;
		}

	// Code for Mozilla type browsers
	} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
		replaced = false;
		startPos = txtarea.selectionStart;
		endPos = txtarea.selectionEnd;
		if (endPos-startPos) replaced = true;
		scrollTop = txtarea.scrollTop;
		myText = (txtarea.value).substring(startPos, endPos);
		if (!myText) myText = defaultText;
		if (myText.charAt(myText.length - 1) == " ") { // exclude ending space char, if any
			subst = codeOpen + myText.substring(0, (myText.length - 1)) + codeClose + " ";
		} else {
			subst = codeOpen + myText + codeClose;
		}
		txtarea.value = txtarea.value.substring(0, startPos) + subst +
			txtarea.value.substring(endPos, txtarea.value.length);
		txtarea.focus();
		//set new selection
		if (replaced) {
			cPos = startPos+(codeOpen.length+myText.length+codeClose.length);
			txtarea.selectionStart = cPos;
			txtarea.selectionEnd = cPos;
		} else {
			txtarea.selectionStart = startPos+codeOpen.length;
			txtarea.selectionEnd = startPos+codeOpen.length+myText.length;
		}
		txtarea.scrollTop = scrollTop;
	}
	
	// reposition cursor if possible
	if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();
}

function film(Page, Width, Height, Top, Left){
window.open(Page,'film',"width="+Width+",height="+Height+",scrollbars=no,resizable=no,top="+Top+",left="+Left)}
