// MES FCTION DEBUT ------------
		function str_replace(a, b, str) {
		return str_replace2(str, a, b);
		}

		// Remplace toutes les occurences d'une chaine
		function replaceAll(str, search, repl) {
		while (str.indexOf(search) != -1)
		str = str.replace(search, repl);
		return str;
		}

		// Remplace les caractères accentués
		function AccentToNoAccent(str) {
		var norm = new Array('À','Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï', 'Ð','Ñ','Ò','Ó','Ô','Õ','Ö','Ø','Ù','Ú','Û','Ü','Ý','Þ','ß', 'à','á','â','ã','ä','å','æ','ç','è','é','ê','ë','ì','í','î','ï','ð','ñ', 'ò','ó','ô','õ','ö','ø','ù','ú','û','ü','ý','ý','þ','ÿ');
		var spec = new Array('A','A','A','A','A','A','A','C','E','E','E','E','I','I','I','I', 'D','N','O','O','O','0','O','O','U','U','U','U','Y','b','s', 'a','a','a','a','a','a','a','c','e','e','e','e','i','i','i','i','d','n', 'o','o','o','o','o','o','u','u','u','u','y','y','b','y');
		for (var i = 0; i < spec.length; i++)
		str = replaceAll(str, norm[i], spec[i]); // appelle replaceALL
		return str;
		} 

		function strtolower( str ) {
		// http://kevin.vanzonneveld.net
		// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// *     example 1: strtolower('Kevin van Zonneveld');
		// *     returns 1: 'kevin van zonneveld'
		if(str==undefined)
			return "";
		else
			return str.toLowerCase();
		}

		function str_replace2(SRs, SRt, SRu) {
		/*
		**  Replace a token in a string
		**    s  string to be processed
		**    t  token to be found and removed
		**    u  token to be inserted
		**  returns new String
		*/
		SRRi = SRs.indexOf(SRt);
		SRRr = '';
		if (SRRi == -1) return SRs;
		SRRr += SRs.substring(0,SRRi) + SRu;
		if ( SRRi + SRt.length < SRs.length)
		SRRr += str_replace2(SRs.substring(SRRi + SRt.length, SRs.length), SRt, SRu);
		return SRRr;
		}

		function code_url(artiste_semi_code, id_clip)
		{
			var str = artiste_semi_code;
			var brokenstring = str.split(' - ');

			var artiste = brokenstring[0]; // artiste	
			var titre = brokenstring[1]; // titre

			if(brokenstring.length>2)
				titre = brokenstring[1]+' - '+brokenstring[2];

			// Codage artiste
			artiste = str_replace('-', '', artiste);
			var artiste_explode = artiste.split(' ');

			artiste_explode[0]; // 1er piece

			if(artiste_explode[1]==undefined)
				;

			if(artiste_explode[1]== undefined) ; else artiste_explode[1] = "-"+artiste_explode[1]; 
			if(artiste_explode[2]== undefined) ; else artiste_explode[2] = "-"+artiste_explode[2]; 
			if(artiste_explode[3]== undefined) ; else artiste_explode[3] = "-"+artiste_explode[3];  
			if(artiste_explode[4]== undefined) ; else artiste_explode[4] = "-"+artiste_explode[4]; 
			if(artiste_explode[5]== undefined) ; else artiste_explode[5] = "-"+artiste_explode[5]; 
			if(artiste_explode[6]== undefined) ; else artiste_explode[6] = "-"+artiste_explode[6]; 
			if(artiste_explode[7]== undefined) ; else artiste_explode[7] = "-"+artiste_explode[7]; 
			
			var artiste_explode_final = strtolower(artiste_explode[0])+strtolower(artiste_explode[1])+strtolower(artiste_explode[2])+strtolower(artiste_explode[3])+strtolower(artiste_explode[4])+strtolower(artiste_explode[5])+strtolower(artiste_explode[6]);
			
			artiste_explode_final = AccentToNoAccent(artiste_explode_final);	

			// FIN codage artiste
			// debut codage titre
			titre = str_replace('-', '', titre);
			
			var titre_explode = titre.split(' ');
			// pour le nom deu fichier html 2eme partie
			titre_explode[0]; // 1er piece

			if(titre_explode[1]== undefined) ; else titre_explode[1] = "-"+titre_explode[1]; 
			if(titre_explode[2]== undefined) ; else titre_explode[2] = "-"+titre_explode[2]; 
			if(titre_explode[3]== undefined) ; else titre_explode[3] = "-"+titre_explode[3];  
			if(titre_explode[4]== undefined) ; else titre_explode[4] = "-"+titre_explode[4]; 
			if(titre_explode[5]== undefined) ; else titre_explode[5] = "-"+titre_explode[5]; 
			if(titre_explode[6]== undefined) ; else titre_explode[6] = "-"+titre_explode[6]; 
			if(titre_explode[7]== undefined) ; else titre_explode[7] = "-"+titre_explode[7];
			if(titre_explode[8]== undefined) ; else titre_explode[8] = "-"+titre_explode[8]; 
			if(titre_explode[9]== undefined) ; else titre_explode[9] = "-"+titre_explode[9]; 
			if(titre_explode[10]== undefined) ; else titre_explode[10] = "-"+titre_explode[10];
			if(titre_explode[11]== undefined) ; else titre_explode[11] = "-"+titre_explode[11]; 

			
			var titre_explode_final = strtolower(titre_explode[0])+strtolower(titre_explode[1])+strtolower(titre_explode[2])+strtolower(titre_explode[3])+strtolower(titre_explode[4])+strtolower(titre_explode[5])+strtolower(titre_explode[6])+strtolower(titre_explode[7])+strtolower(titre_explode[8])+strtolower(titre_explode[9])+strtolower(titre_explode[10])+strtolower(titre_explode[11]);
			
			titre_explode_final = str_replace("&","&amp;", titre_explode_final);
			titre_explode_final = str_replace("---","-", titre_explode_final);
			titre_explode_final = str_replace("/","-", titre_explode_final);
			titre_explode_final = str_replace("?","", titre_explode_final);
			titre_explode_final = str_replace("(","", titre_explode_final);
			titre_explode_final = str_replace(")","", titre_explode_final);
			titre_explode_final = str_replace("!","", titre_explode_final);
			titre_explode_final = str_replace("--","-", titre_explode_final);

			titre_explode_final = AccentToNoAccent(titre_explode_final);
			// fin codage titre

			var nom_page ="http://www.bestparoles.net/clips/clip-"+id_clip+"-"+artiste_explode_final+"-"+titre_explode_final+".html"; 
			nom_page = str_replace("--","-", nom_page);

			return nom_page;
		}
// MES FCTS FIN -------
	var ajaxBox_offsetX = 0;
	var ajaxBox_offsetY = 0;
	var ajax_list_externalFile = 'ajax-list-clips.php';	// Path to external file
	var minimumLettersBeforeLookup = 1;	// Number of letters entered before a lookup is performed.
	
	var ajax_list_objects = new Array();
	var ajax_list_cachedLists = new Array();
	var ajax_list_activeInput = false;
	var ajax_list_activeItem;
	var ajax_list_optionDivFirstItem = false;
	var ajax_list_currentLetters = new Array();
	var ajax_optionDiv = false;
	var ajax_optionDiv_iframe = false;

	var ajax_list_MSIE = false;
	if(navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('Opera')<0)ajax_list_MSIE=true;
	
	var currentListIndex = 0;
	
	function ajax_getTopPos(inputObj)
	{
		
	  var returnValue = inputObj.offsetTop;
	  while((inputObj = inputObj.offsetParent) != null){
	  	returnValue += inputObj.offsetTop;
	  }
	  return returnValue;
	}
	function ajax_list_cancelEvent()
	{
		return false;
	}
	
	function ajax_getLeftPos(inputObj)
	{
	  var returnValue = inputObj.offsetLeft;
	  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
	  
	  return returnValue;
	}
	
	function ajax_option_setValue(e,inputObj)
	{
		if(!inputObj)inputObj=this;
		var tmpValue = inputObj.innerHTML;
		if(ajax_list_MSIE)tmpValue = inputObj.innerText;else tmpValue = inputObj.textContent;
		if(!tmpValue)tmpValue = inputObj.innerHTML;
		ajax_list_activeInput.value = tmpValue;
		if(document.getElementById(ajax_list_activeInput.name + '_hidden'))document.getElementById(ajax_list_activeInput.name + '_hidden').value = inputObj.id; 
		ajax_options_hide();
		var nom_page = code_url(tmpValue,inputObj.id);
		window.open(nom_page,'_self');

	}
	
	function ajax_options_hide()
	{
		if(ajax_optionDiv)ajax_optionDiv.style.display='none';	
		if(ajax_optionDiv_iframe)ajax_optionDiv_iframe.style.display='none';
	}

	function ajax_options_rollOverActiveItem(item,fromKeyBoard)
	{
		if(ajax_list_activeItem)ajax_list_activeItem.className='optionDiv';
		item.className='optionDivSelected';
		ajax_list_activeItem = item;
		
		if(fromKeyBoard){
			if(ajax_list_activeItem.offsetTop>ajax_optionDiv.offsetHeight){
				ajax_optionDiv.scrollTop = ajax_list_activeItem.offsetTop - ajax_optionDiv.offsetHeight + ajax_list_activeItem.offsetHeight + 2 ;
			}
			if(ajax_list_activeItem.offsetTop<ajax_optionDiv.scrollTop)
			{
				ajax_optionDiv.scrollTop = 0;	
			}
		}
	}
	
	function ajax_option_list_buildList(letters,paramToExternalFile)
	{
		
		ajax_optionDiv.innerHTML = '';
		ajax_list_activeItem = false;
		if(ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()].length<=1){
			ajax_options_hide();
			return;			
		}
		
		
		
		ajax_list_optionDivFirstItem = false;
		var optionsAdded = false;
		for(var no=0;no<ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()].length;no++){
			if(ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()][no].length==0)continue;
			optionsAdded = true;
			var div = document.createElement('DIV');
			var items = ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()][no].split(/###/gi);
			
			if(ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()].length==1 && ajax_list_activeInput.value == items[0]){
				ajax_options_hide();
				return;						
			}
			
			
			div.innerHTML = items[items.length-1];
			div.id = items[0];
			div.className='optionDiv';
			div.onmouseover = function(){ ajax_options_rollOverActiveItem(this,false) }
			div.onclick = ajax_option_setValue;
			if(!ajax_list_optionDivFirstItem)ajax_list_optionDivFirstItem = div;
			ajax_optionDiv.appendChild(div);
		}	
		if(optionsAdded){
			ajax_optionDiv.style.display='block';
			if(ajax_optionDiv_iframe)ajax_optionDiv_iframe.style.display='';
			ajax_options_rollOverActiveItem(ajax_list_optionDivFirstItem,true);
		}
					
	}
	
	function ajax_option_list_showContent(ajaxIndex,inputObj,paramToExternalFile,whichIndex)
	{
		if(whichIndex!=currentListIndex)return;
		var letters = inputObj.value;
		var content = ajax_list_objects[ajaxIndex].response;
		var elements = content.split('|');
		ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()] = elements;
		ajax_option_list_buildList(letters,paramToExternalFile);
		
	}
	
	function ajax_option_resize(inputObj)
	{
		ajax_optionDiv.style.top = (ajax_getTopPos(inputObj) + inputObj.offsetHeight + ajaxBox_offsetY) + 'px';
		ajax_optionDiv.style.left = (ajax_getLeftPos(inputObj) + ajaxBox_offsetX) + 'px';
		if(ajax_optionDiv_iframe){
			ajax_optionDiv_iframe.style.left = ajax_optionDiv.style.left;
			ajax_optionDiv_iframe.style.top = ajax_optionDiv.style.top;			
		}		
		
	}
	
	function ajax_showOptions(inputObj,paramToExternalFile,e)
	{
		if(e.keyCode==13 || e.keyCode==9)return;
		if(ajax_list_currentLetters[inputObj.name]==inputObj.value)return;
		if(!ajax_list_cachedLists[paramToExternalFile])ajax_list_cachedLists[paramToExternalFile] = new Array();
		ajax_list_currentLetters[inputObj.name] = inputObj.value;
		if(!ajax_optionDiv){
			ajax_optionDiv = document.createElement('DIV');
			ajax_optionDiv.id = 'ajax_listOfOptions';	
			document.body.appendChild(ajax_optionDiv);
			
			if(ajax_list_MSIE){
				ajax_optionDiv_iframe = document.createElement('IFRAME');
				ajax_optionDiv_iframe.border='0';
				ajax_optionDiv_iframe.style.width = ajax_optionDiv.clientWidth + 'px';
				ajax_optionDiv_iframe.style.height = ajax_optionDiv.clientHeight + 'px';
				ajax_optionDiv_iframe.id = 'ajax_listOfOptions_iframe';
				
				document.body.appendChild(ajax_optionDiv_iframe);
			}
			
			var allInputs = document.getElementsByTagName('INPUT');
			for(var no=0;no<allInputs.length;no++){
				if(!allInputs[no].onkeyup)allInputs[no].onfocus = ajax_options_hide;
			}			
			var allSelects = document.getElementsByTagName('SELECT');
			for(var no=0;no<allSelects.length;no++){
				allSelects[no].onfocus = ajax_options_hide;
			}

			var oldonkeydown=document.body.onkeydown;
			if(typeof oldonkeydown!='function'){
				document.body.onkeydown=ajax_option_keyNavigation;
			}else{
				document.body.onkeydown=function(){
					oldonkeydown();
				ajax_option_keyNavigation() ;}
			}
			var oldonresize=document.body.onresize;
			if(typeof oldonresize!='function'){
				document.body.onresize=function() {ajax_option_resize(inputObj); };
			}else{
				document.body.onresize=function(){oldonresize();
				ajax_option_resize(inputObj) ;}
			}
				
		}
		
		if(inputObj.value.length<minimumLettersBeforeLookup){
			ajax_options_hide();
			return;
		}
				

		ajax_optionDiv.style.top = (ajax_getTopPos(inputObj) + inputObj.offsetHeight + ajaxBox_offsetY) + 'px';
		ajax_optionDiv.style.left = (ajax_getLeftPos(inputObj) + ajaxBox_offsetX) + 'px';
		if(ajax_optionDiv_iframe){
			ajax_optionDiv_iframe.style.left = ajax_optionDiv.style.left;
			ajax_optionDiv_iframe.style.top = ajax_optionDiv.style.top;			
		}
		
		ajax_list_activeInput = inputObj;
		ajax_optionDiv.onselectstart =  ajax_list_cancelEvent;
		currentListIndex++;
		if(ajax_list_cachedLists[paramToExternalFile][inputObj.value.toLowerCase()]){
			ajax_option_list_buildList(inputObj.value,paramToExternalFile,currentListIndex);			
		}else{
			var tmpIndex=currentListIndex/1;
			ajax_optionDiv.innerHTML = '';
			var ajaxIndex = ajax_list_objects.length;
			ajax_list_objects[ajaxIndex] = new sack();
			var url = ajax_list_externalFile + '?' + paramToExternalFile + '=1&letters=' + inputObj.value.replace(" ","+");
			ajax_list_objects[ajaxIndex].requestFile = url;	// Specifying which file to get
			ajax_list_objects[ajaxIndex].onCompletion = function(){ ajax_option_list_showContent(ajaxIndex,inputObj,paramToExternalFile,tmpIndex); };	// Specify function that will be executed after file has been found
			ajax_list_objects[ajaxIndex].runAJAX();		// Execute AJAX function		
		}
		
			
	}
	
	function ajax_option_keyNavigation(e)
	{
		if(document.all)e = event;
		
		if(!ajax_optionDiv)return;
		if(ajax_optionDiv.style.display=='none')return;
		
		if(e.keyCode==38){	// Up arrow
			if(!ajax_list_activeItem)return;
			if(ajax_list_activeItem && !ajax_list_activeItem.previousSibling)return;
			ajax_options_rollOverActiveItem(ajax_list_activeItem.previousSibling,true);
		}
		
		if(e.keyCode==40){	// Down arrow
			if(!ajax_list_activeItem){
				ajax_options_rollOverActiveItem(ajax_list_optionDivFirstItem,true);
			}else{
				if(!ajax_list_activeItem.nextSibling)return;
				ajax_options_rollOverActiveItem(ajax_list_activeItem.nextSibling,true);
			}
		}
		
		if(e.keyCode==13 || e.keyCode==9){	// Enter key or tab key
			if(ajax_list_activeItem && ajax_list_activeItem.className=='optionDivSelected')ajax_option_setValue(false,ajax_list_activeItem);
			if(e.keyCode==13)return false; else return true;
		}
		if(e.keyCode==27){	// Escape key
			ajax_options_hide();			
		}
	}
	
	
	document.documentElement.onclick = autoHideList;
	
	function autoHideList(e)
	{
		if(document.all)e = event;
		
		if (e.target) source = e.target;
			else if (e.srcElement) source = e.srcElement;
			if (source.nodeType == 3) // defeat Safari bug
				source = source.parentNode;		
		if(source.tagName.toLowerCase()!='input' && source.tagName.toLowerCase()!='textarea')ajax_options_hide();
		
	}