/*
 | -------------------------------------------------------------------
 |  Init
 | -------------------------------------------------------------------
 |
 |
 */

window.onload = function() {
	val_ini = document.getElementById('search_mini').value;
	document.getElementById('search_mini').onclick = function() {
		document.getElementById('search_mini').value = '';
		document.getElementById('search_mini').style.color = '#aaa';
	}
	document.getElementById('maincontent').onclick = function() {
		document.getElementById('search_mini').value = val_ini;
		document.getElementById('search_mini').style.color = '#aaa';
	}
	
	if (document.getElementById('search_form_id').value == 'Rechercher' | document.getElementById('search_form_id').value == 'Search')
	{
		document.getElementById('search_form_id').onclick = function() {
			document.getElementById('search_form_id').value = '';
		}
	}
		
}

/*
 | -------------------------------------------------------------------
 |  Divers
 | -------------------------------------------------------------------
 |
 |
 */


// Src : http://www.siteduzero.com/tutoriel-3-34703-insertion-de-balises-dans-une-zone-de-texte.html#ss_part_1
function insertTag(startTag, endTag, textareaId, tagType) {
        var field  = document.getElementById(textareaId); 
        var scroll = field.scrollTop;
        field.focus();
        if (window.ActiveXObject) { // IE
                var textRange = document.selection.createRange();            
                var currentSelection = textRange.text;
                
                textRange.text = startTag + currentSelection + endTag;
                textRange.moveStart("character", -endTag.length - currentSelection.length);
                textRange.moveEnd("character", -endTag.length);
                textRange.select();     
        }else{ // not IE
                var startSelection   = field.value.substring(0, field.selectionStart);
                var currentSelection = field.value.substring(field.selectionStart, field.selectionEnd);
                var endSelection     = field.value.substring(field.selectionEnd);
                
                field.value = startSelection + startTag + currentSelection + endTag + endSelection;
                field.focus();
                field.setSelectionRange(startSelection.length + startTag.length, startSelection.length + startTag.length + currentSelection.length);
        } 
        field.scrollTop = scroll; // et on redéfinit le scroll.
}

// Src : http://pallieter.org/Projects/insertTab/
function insertTab(o, e) 
{
	var kC = e.keyCode ? e.keyCode : e.charCode ? e.charCode : e.which;
	if (kC == 9 && !e.shiftKey && !e.ctrlKey && !e.altKey)
	{
		var oS = o.scrollTop;
		if (o.setSelectionRange)
		{
			var sS = o.selectionStart;
			var sE = o.selectionEnd;
			o.value = o.value.substring(0, sS) + "\t" + o.value.substr(sE);
			o.setSelectionRange(sS + 1, sS + 1);
			o.focus();
		}
		else if (o.createTextRange)
		{
			document.selection.createRange().text = "\t";
			e.returnValue = false;
		}
		o.scrollTop = oS;
		if (e.preventDefault)
		{
			e.preventDefault();
		}
		return false;
	}
	return true;
}


/*
 | -------------------------------------------------------------------
 |  File Manager
 | -------------------------------------------------------------------
 |  -> See application/js/ajax.js
 |
 */



