	function delay_url(url, delay_sec) {
	  setTimeout("top.location.href = '" + url + "'", delay_sec*1000);
	}
	
	function open_window(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable) {
	  toolbar_str = toolbar ? 'yes' : 'no';
	  menubar_str = menubar ? 'yes' : 'no';
	  statusbar_str = statusbar ? 'yes' : 'no';
	  scrollbar_str = scrollbar ? 'yes' : 'no';
	  resizable_str = resizable ? 'yes' : 'no';
	  window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
	}
	function showImg(url) {
		titre="Image agrandie - audiovideohd.fr";
		w=open("",'image','width=400,height=400,toolbar=no,scrollbars=no,resizable=yes');	
		w.document.write("<html><head><title>"+titre+"</title></head>");
		w.document.write("<script language=javascript>function checksize()  { if (document.images[0].complete) {  window.resizeTo(document.images[0].width+12,document.images[0].height+52); window.focus();} else { setTimeout('check()',0) } }</"+"script>");
		w.document.write("<body onload='checksize()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0><a href='javascript:{self.close();}' title='Fermer la fenêtre'><img src='"+url+"' border='0'/></a>");
		
		w.document.write("</body></html>");
		w.document.close();
	}
	
	function gotoanchor(anchor) {
		setTimeout("location.href='#"+anchor+"'",500);
	}
	
	function addTag() {
		var html = '';
		var elm = document.createElement("div");
		html += '<p><label>mot-clé ' + newsTagIndex + '</label><input name="tags[]" id="tag' + newsTagIndex + '" autocomplete="off" type="text" value=""/></p>'; 
		html += '<div class="autocomplete" id="taglist' + newsTagIndex + '"  style="display: none; "></div>'; 
		
		elm.innerHTML = html;
		$('tagFields').appendChild(elm);

		completer[newsTagIndex] = new Autocompleter.Local($('tag'+newsTagIndex), tagList, {
				'delay': 0,
				'maxChoices': 10,
				'filterTokens': function() {
					var regex = new RegExp('^' + this.queryValue.escapeRegExp(), 'i');
					return this.tokens.filter(function(token){
						return (regex.test(token[0]) || regex.test(token[1]));
					});
				},
				'injectChoice': function(choice) {
					var el = new Element('li')
						.setHTML(this.markQueryValue(choice[0]))
						.adopt(new Element('span', {'class': 'example-info'}).setHTML(this.markQueryValue(choice[1])));
					el.inputValue = choice[0];
					this.addChoiceEvents(el).injectInside(this.choices);
				}
			});
		newsTagIndex++;
	}
	
	
	function repeatLastIp() {
		lastip_repeatition = setInterval("switchLastIp('default')",3500);
	}
	
	function clearLastIp() {
		clearTimeout(lastip_repeatition);
	}
	
	function switchLastIp(next) {
			lastipindex = lastipindex ? lastipindex : 1;
			if(next===true || next=='default') {
				if(lastipindex==5) lastipindex = 1;
				else lastipindex ++; 
			} else {
				if(lastipindex==1) lastipindex = 5;
				else lastipindex --; 
			}
		
			titleFx = $('lastipahref').effect('opacity', {duration: 250, transition: Fx.Transitions.linear});
			titleFx.custom.pass([.9,0], titleFx).delay(0);
			setTimeout("$('lastipahref').innerHTML = lastip[lastipindex]['title'];",300);
			$('lastipahref').href = lastip[lastipindex]['href'];
			
			viewFx = new Fx.Style('lastipimg', 'opacity', {duration: 500,transition: Fx.Transitions.quartInOut});
			viewFx.custom.pass([1,0], viewFx).delay(250);
			
			if(next===true) {
				viewFx = new Fx.Style('lastipnext', 'opacity', {duration: 500,transition: Fx.Transitions.quartInOut});
				viewFx.custom.pass([0.9,0.01], viewFx).delay(250);
			} else if(next===false){
				viewFx = new Fx.Style('lastipprev', 'opacity', {duration: 500,transition: Fx.Transitions.quartInOut});
				viewFx.custom.pass([0.9,0.01], viewFx).delay(250);
			}
			
			setTimeout("$('lastipimg').src = lastip[lastipindex]['src'];",650);
			
			if(next===true) {
				viewFx = new Fx.Style('lastipnext', 'opacity', {duration: 500,transition: Fx.Transitions.quartInOut});
				viewFx.custom.pass([0.01,0.9], viewFx).delay(750);
			} else if(next===false) {
				viewFx = new Fx.Style('lastipprev', 'opacity', {duration: 500,transition: Fx.Transitions.quartInOut});
				viewFx.custom.pass([0.01,0.9], viewFx).delay(750);
			}
			
			viewFx = new Fx.Style('lastipimg', 'opacity', {duration: 500,transition: Fx.Transitions.quartInOut});
			viewFx.custom.pass([0,1], viewFx).delay(750);
			
			titleFx = $('lastipahref').effect('opacity', {duration: 500, transition: Fx.Transitions.linear});
			titleFx.custom.pass([0,.9], titleFx).delay(1250);
			
			
	}
	
	function showHideNextPrev(nextprev,show) {
		
		nextprevFx = $('lastip'+nextprev).effect('opacity', {duration: 250, transition: Fx.Transitions.linear});
		
		if(show) {
			nextprevFx.custom.pass([0.01,.9], nextprevFx).delay(0);
			clearLastIp();
		}
		else {
			nextprevFx.custom.pass([.9,0.01], nextprevFx).delay(0);
			repeatLastIp();
		}
	}
	
	// XML HTTP REQUEST
	xhrTab = new Array();
	
	function xhrIpSecondLine(comboSelect,oldComboSelect,id,url,params){
		
		params = 'comboSelect=' + comboSelect + params;
		//$(id + '_filters').innerHTML = url+ '&' + params;
		if(!xhrTab[id]) { 
			xhrTab[id] = new XHR({
				method: 'get',
				onSuccess: xhrResponseIpSecondLine,
				encoding : 'iso-8859-1'
			});
			xhrTab[id].id = id;
			xhrTab[id].oldComboSelect = oldComboSelect;
		}
		xhrTab[id].comboSelect = comboSelect;
		xhrTab[id].send(url,params);
		
	}
	
	function xhrResponseIpSecondLine(){
		html = this.response['text'];
		
		$(this.id + '_filters').innerHTML = html;
		var regexp=new RegExp("^[0-9]+$","gi");
		if( regexp.test(this.comboSelect) ) {
			$(this.id + '_filters').style.display = 'block';
			
			if(this.oldComboSelect!=this.comboSelect) {
				$(this.id + '_productlist').style.display = 'none';
				$(this.id + '_productlist').innerHTML = '';
			}
			//alert(this.oldComboSelect + ' ' + this.comboSelect);
			this.oldComboSelect = this.comboSelect;
			
		} else {
			$(this.id + '_filters').style.display = 'none';
			$(this.id + '_productlist').style.display = 'none';
			$(this.id + '_productlist').innerHTML = '';
		}
		
		
	}
	
	function xhrIpThirdLine(id,url,filterButton){
		
		var parentNode = filterButton.parentNode;
		var childrens = parentNode.childNodes;
		var params = '';
		for(var i=0; i< childrens.length; i++) {
			if(childrens[i].tagName == 'SELECT') {
				var select = childrens[i];
				params += '&filter[]=' + select.options[select.selectedIndex].value;
			}
		}
		
		productList = new XHR({
			method: 'get',
			onSuccess: xhrResponseIpThirdLine,
			encoding : 'iso-8859-1'
		});
		productList.id = id;
		productList.send(url,params);
	}
	function xhrResponseIpThirdLine() {
		html = this.response['text'];
		
		$(this.id + '_productlist').innerHTML = html;
		$(this.id + '_productlist').style.display = 'block';
		
	}
	
	
	numRows = new Array();
	function xhrAddIpProd(id,params) {
		
		var productIndex = ++numRows[id];
		params += '&productIndex=' + productIndex;
		addIpProd = new XHR({
			method: 'get',
			onSuccess: xhrResponseAddIpProd,
			encoding : 'iso-8859-1'
		});
		addIpProd.id = id;
		
		addIpProd.send('http://www.audiovideohd.fr/xhr.php?a=addProd',params);

	}
	
	function xhrResponseAddIpProd(){
		var html = "";

		var elm = document.createElement("div");
		elm.id = this.id + numRows[this.id];
		elm.className = 'productline';
		
		html += '<a class="rightmore" href="javascript:{delIpProd(\'' + this.id + numRows[this.id] + '\')}" title="Supprimer ce produit">x</a>';
		html += this.response['text'];
		html += '<div id="' + this.id + numRows[this.id] + '_filters" class="ipfilters" style="display: none;"></div>'; 
		html += '<div id="' + this.id + numRows[this.id] + '_productlist" class="ipproductlist" style="display: none;"></div>'; 
		
		elm.innerHTML = html;
		document.getElementById(this.id).appendChild(elm);
	}
	
	function delIpProd(id) {
		var elm = document.getElementById(id);
		if (elm) elm.parentNode.removeChild(elm);
	}
	
	
	function xhrSwitchPrices(id,photoId) {
		
		if(photoId=='')$('productPhoto').innerHTML = '';
		else $('productPhoto').innerHTML = '<img src="' + photoId + '" />';
		
		$('productId'+oldProductId).className = '';
		oldProductId = id;
		$('productId'+id).className = 'strong';
		priceList = new XHR({
			method: 'get',
			onSuccess: xhrResponseSwitchPrices,
			encoding : 'iso-8859-1'
		});
		priceList.send('http://www.audiovideohd.fr/xhr.php?a=priceList','productId='+id);
	}
	function xhrResponseSwitchPrices(){
		html = this.response['text'];
		$('pricelist').innerHTML = html;
	}
	
	document.onclick=check;

	oldRootDiv = null;
	function check(e){
		/*var divs = new Array('loginBlock','searchBlock');
		
		var target = (e && e.target) || (event && event.srcElement);
		switch(target.id) {
			
			case 'loginButton' : 
				var showDiv = 'loginBlock'; 
				var rootDiv = 'loginRoot'; 
			break;
			case 'loginLink' : 
				var showDiv = 'loginBlock'; 
				var rootDiv = 'loginRoot'; 
			break;
			case 'searchButton' : 
				var showDiv = 'searchBlock'; 
				var rootDiv = 'searchRoot'; 
			break;
			default : 
				var showDiv = false; 
				var rootDiv = ''; 

			break;
		}
		
		
		for(var i=0; i<divs.length; i++) {
			
			//alert(divs[i].id);
			if(divs[i] == showDiv) $(divs[i]).style.display='block';
			else if(checkParent(target)) $(divs[i]).style.display='none';
		}
		
		 if(rootDiv != '')oldRootDiv = $(rootDiv);*/
	}
	function checkParent(t) {
		
		while(t.parentNode) {

			if ( oldRootDiv!= null && t == oldRootDiv ) return false;
			t = t.parentNode;			
		}
		return true;
	}
	
	function urlrewrite(txt) {
		var before = "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿ :;|@&(){}%?!µ'\\*?\"/<>_[]#~§,"; 
		var after  = "AAAAAAACEEEEIIIIdnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyyby-------------------------------";
		var text = txt;
		var debug = '';
		for(var i=0; i<before.length; i++) {
			var regexp = new RegExp("\\"+before.charAt(i)+"","g");
			text = text.replace(regexp,after.charAt(i));
		}
		
		text = text.replace(/€/g,'-euros-');
		text = text.replace(/&/g,'-et-');
		text = text.replace(/\$/g,'-dollars-');
		
		text = text.replace(/[-]+/g,'-');
		text = text.replace(/^-/g,'');
		text = text.replace(/-$/g,'');
		
		return text;
	}
	
	function changeTagsFilterFormAction(){
		
		var tags = new Array();
		for(var i=1; i<newsTagIndex; i++) {
			if($('tag'+i).value != '') tags[tags.length] = urlrewrite($('tag'+i).value);
		}
		
		$('tagFilter').action = '/actualites/' + tags.join(',') + '/';
	}
	
	function changeSearchFormAction(form){
		
		var q = form.id=='searchForm' ? $('query').value : $('queryg').value;
		q = q.replace(/^\s+|\s+$/, ''); 
		q = q.replace(/["]{0,1}([\p{L}]+)([\-\/&])([\p{L}]+)["]{0,1}/, '$1$2$3'); 
		q = q.replace(/\s+/, '+');
		q = escape(q)
		
		
		
		//var section = $('section').options[$('section').selectedIndex].value;
		var section = form.id=='searchForm' ? $('section').value : $('sectiong').value;
		
		switch(section) {
			case 'all' : form.action = 'http://www.audiovideohd.fr/recherche-' + q + '/'; break;
			case 'cdp' : form.action = 'http://prix.audiovideohd.fr/recherche-' + q + '/'; break;
			default : break;
		}
		
		
	}
	
	function changeBlurayFormAction(params){
		
		var filtres = document.forms['formcdpfilters'].elements['filtre'];
		
		var oldKey = '';
		var urlFilters = '';
		var index = 0;
		
		if(filtres.length==37) {
			if(filtres.options[filtres.selectedIndex] && filtres.options[filtres.selectedIndex].value != '') {
	
				var temp = filtres.options[filtres.selectedIndex].value.split('|');
				
				if(oldKey != temp[0]) {
					if(index>0)urlFilters += '--'
					urlFilters += temp[0]+','+myEncode(temp[1]);
					index++;
				}
				else urlFilters += ','+myEncode(temp[1]);
				
				oldKey = temp[0];
			}
		} else for(var i=0; i<filtres.length; i++) {
			
			if(filtres[i].options[filtres[i].selectedIndex] && filtres[i].options[filtres[i].selectedIndex].value != '') {
	
				var temp = filtres[i].options[filtres[i].selectedIndex].value.split('|');
				
				if(oldKey != temp[0]) {
					if(index>0)urlFilters += '--'
					urlFilters += temp[0]+','+myEncode(temp[1]);
					index++;
				}
				else urlFilters += ','+myEncode(temp[1]);
				
				oldKey = temp[0];
			}
		}
		
		var url='/blu-ray';
		if(urlFilters != '')url += '---'+urlFilters;
		
		if($('titre').value != '' && $('titre').value != 'Rechercher par titre')url += (url.test(/---/) ? '--' : '---')+'titre,'+myEncode($('titre').value);
		if($('acteur').value != '' && $('acteur').value != 'Rechercher par acteur')url += (url.test(/---/) ? '--' : '---')+'acteur,'+myEncode($('acteur').value);
		if($('realisateur').value != '' && $('realisateur').value != 'Rechercher par réalisateur')url += (url.test(/---/) ? '--' : '---')+'realisateur,'+myEncode($('realisateur').value);
		
		
		if($('prix-min').value != '')url += (url.test(/---/) ? '--' : '---')+'prix-min,'+myEncode($('prix-min').value);
		if($('prix-max').value != '')url += (url.test(/---/) ? '--' : '---')+'prix-max,'+myEncode($('prix-max').value);
		
		
		url += '/'+params;
		document.forms['formcdpfilters'].action = url;
	}
	
	function changeCdpFormAction(gid,gtitle,params){
		
		var filters = new Array();
		var filtres = document.forms['formcdpfilters'].elements['filtre'];

		var oldKey = '';
		var urlFilters = '';
		var index = 0;
		for(var i=0; i<filtres.length; i++) {
			if(filtres[i].options[filtres[i].selectedIndex].value != '') {
	
				var temp = filtres[i].options[filtres[i].selectedIndex].value.split('|');
				
				if(oldKey != temp[0]) {
					if(index>0)urlFilters += '--'
					urlFilters += temp[0]+','+myEncode(temp[1]);
					index++;
				}
				else urlFilters += ','+myEncode(temp[1]);
				
				oldKey = temp[0];
			}
		}
		
		var url='/'+gid+'-'+gtitle;
		if(urlFilters != '')url += '---'+urlFilters;
		
		if(gid==118) {
			if($('titre').value != '' && $('titre').value != 'Rechercher par titre')url += (url.test(/---/) ? '--' : '---')+'titre,'+myEncode($('titre').value);
			if($('acteur').value != '' && $('acteur').value != 'Rechercher par acteur')url += (url.test(/---/) ? '--' : '---')+'acteur,'+myEncode($('acteur').value);
			if($('realisateur').value != '' && $('realisateur').value != 'Rechercher par réalisateur')url += (url.test(/---/) ? '--' : '---')+'realisateur,'+myEncode($('realisateur').value);
		}
		
		if($('prix-min').value != '')url += (url.test(/---/) ? '--' : '---')+'prix-min,'+myEncode($('prix-min').value);
		if($('prix-max').value != '')url += (url.test(/---/) ? '--' : '---')+'prix-max,'+myEncode($('prix-max').value);
		
		
		url += '/'+params;
		document.forms['formcdpfilters'].action = url;
	}

	function ConfirmSuivi(suivi) {
	 	if(suivi==1)
		{
			text = "Voulez vous vraiment être averti par e-mail lorsque une nouvelle version du logiciel est disponible ?";
			if(confirm(text))document.forms['form_suivi'].submit();
		}
		else
		{
			text = "Voulez vous vraiment renoncer à l'avertissement par e-mail lorsque une nouvelle version du logiciel est disponible ?";
			if(confirm(text))document.forms['form_suivi'].submit();
		}
	}
	
	function myEncode(t) {
		t = t.replace(/\//g, '-SLA-').replace(/%2C/g, '-VIR-').replace(/%26/g, '-ET-').replace(/%27/g, '-APO-').replace(/\+/g, '-PLUS-');
		return escape(t);
	}