

var G_SHOPREFINEMENT;
function displayRefinement(name) {
	if(G_SHOPREFINEMENT) {
		oldNode = G_SHOPREFINEMENT;
	
	} else {
		sub=$('rf01').getElementsByTagName('div');
		oldNode=sub[3];	
	}
	$(oldNode).hide();
	$('rf'+name).show();
	G_SHOPREFINEMENT=$('rf'+name);
	var menus=$('lim'+name).parentNode.getElementsByTagName('li');
	
	for(i=0;i<menus.length;i++) $(menus[i]).removeClassName('active');
		$('lim'+name).addClassName('active');


}



function closeAllRefinements() {
	$('pl01').show();
	$('pl02').parentNode.removeChild($('pl02'));
}

function _refinementsFunction(page, refinename) {
	var divtoshow='dzall_page'+page;
	if(refinename!=undefined && !refinename.blank()) {
		divtoshow='dzrf'+refinename+'_page'+page;
	}
	var content='pl01';
	$(content).hide();
	if($('pl02')) $('pl02').parentNode.removeChild($('pl02'));
	var elem=$(divtoshow).cloneNode(true);
	elem.id='pl02';
	new Insertion.Before($(content), elem);
	return true;
}

function displayHiddenRefinement(name) {
	closeAllRefinements();
	if(!$('lim'+name).visible()) {
		parentNode = $('lim'+name).parentNode;
		parentNode.getElementsByTagName('li').item(0).hide();
		oldNode = parentNode.removeChild($('lim'+name));
		parentNode.insertBefore(oldNode, parentNode.getElementsByTagName('li')[0]);
		$('lim'+name).show();
	}
	displayRefinement(name);
}





/////a netoyer



function applySearchFilter(url,field) {
	var sep='?'; if(url.indexOf('?') >= 0) sep='&';
	window.location.href=url+sep+$(field).name+'='+$F(field);
}

function changBrandTechnicalFilter(field) {
	if($F(field)!=0 && $F(field)!='') window.location.href=$F(field);
}

function changeTechnicalFilter() {
	var sep='?';
	form=document.forms['frmtekfilter']
	var url=form.action;
	if(url.indexOf('?')>=0) url=url.substring(0, url.indexOf('?'));
	elems=form.elements;
	for(i=0;i<elems.length;i++) {
		if(elems[i].name.substring(0,2)=='tf' && elems[i].value!='') {
			url=url+sep+elems[i].name+'='+elems[i].value;
			sep='&';
		}
	}
	window.location.href=url;
}

function submitReview(state) {
	if(state==1) {
		form=document.forms['review'];
		if(form.title.value.blank() || form.textreview.value.blank() || $F('rating')==-1) alert(G_LBLPLZFILLALL);
		else form.submit();
	} else if(state==2) {
		form=document.forms['reviewvalidate'];
		form.submit();
	}
}

function submitPhoto() {
	form=document.forms['photo'];
	if(form.legende.value.blank() || form.filename.value.blank()) alert(G_LBLPLZFILLALL);
	else form.submit();
}

function rateThistPhoto() {
	voted=0;
	form=document.forms['ratethisphoto'];
	for (var i=0;i<form.vote.length;i++) {
		if (form.vote[i].checked) {
			voted=form.vote[i].value;
			break;
		}
	}
	if(voted==0)
		alert(G_LBLPLZMAKEACHOICE);
	else {
		var url='/shopping/actions/dophotovote.jsp';
		var params='id='+$('img001').getAttribute('value')+'&rate='+voted;
		var myAjax=new Ajax.Updater('updater001',url,{method:'get',parameters:params}); 
		votebutton=$('submit001');
		votebutton.disabled=true;
	}
	return false;
}

function openFullScreenWnd(url) {
	return openCenterWnd(url,"fullscreenwnd",1000,800,"yes","yes");
}

function openCenterWnd(url,name,w,h,size,scroll){
 	var str="width="+w;
	str+=",height="+h;
	str+=",left="+(screen.width-w)/2;
	str+=",top="+(screen.height-h)/2;
	str+=",resizable="+((size) ? "yes" : "no");
	str+=",scrollbars="+((scroll) ? "yes" : "no");
	str+=",menubar=no,status=no,toolbar=no";
  	g_lastOpenedWnd=window.open(url,name,str);
	g_Window_Height=h;
	g_Window_Width=w;
	g_lastOpenedWnd.opener=window;
	g_NB_WAIT=0;
  	return g_lastOpenedWnd;
}

function nextVendors(id,type,producttype,sort,order,zipcode) {
	var url='/shopping/includes/iproductvendors.jsp';
	var params='rp='+id+'&type='+type+'&pt='+producttype+'&sort='+sort+'&order='+order+'&zipcode='+zipcode;
	if(!$('marchandBloc').visible())
		blocktoupdate='rtypecontent1';
	else {
		if($('marchand1')!=null && $('marchand1').visible()) blocktoupdate='marchand1';
		else blocktoupdate='marchand2';
	}
	var myAjax=new Ajax.Updater(blocktoupdate,url,{method:'get',parameters:params});
	return false;
}

function showMarchandTabs(on,off) {
	if($('marchand'+off)!=null) {
		$('marchand'+off).hide();
		$('marchantTab'+off).removeClassName('active');
	}
	if($('marchand'+on)!=null) {
		$('marchand'+on).show();
		$('marchantTab'+on).addClassName('active');
	}
	return false;
}

function switchOverviewTabs(id,producttype,contenttype,on,page,filter) {
	var zipcodeparam='';
	for(i=1;i<10;i++) {
		if($('rtype'+i)!=null) {
			if(i!=on) $('rtype'+i).removeClassName('active');
			else $('rtype'+i).addClassName('active');
		}
	}
	var url='/shopping/includes/ireviewslist.jsp';
	if(contenttype==0) url='/shopping/includes/ioverview.jsp';
	else if(contenttype==1) url='/shopping/includes/inewslist.jsp';
	else if(contenttype== 6015) url='/shopping/includes/ivideoslist.jsp';
	else if(contenttype==2) {
		if(on==8) { 
			contenttype=0;
			if($('zipcode01')!=undefined && !$F('zipcode01').blank()){
				zipcodeparam='&zipcode='+$F('zipcode01');
			}
		} else {
			contenttype=1;
		}
		url='/shopping/includes/iproductvendors.jsp';
	} else if(contenttype==6023) url='/shopping/includes/iphotoslist.jsp';
	if(filter==undefined) filter=0;
	var params='rp='+id+'&type='+contenttype+'&tabidx='+on+'&filter='+filter+'&page='+page+'&pt='+producttype+zipcodeparam;
	var myAjax=new Ajax.Updater('rtypecontent1',url,{method:'get',parameters:params});
	if($('marchandBloc')!=null) {
		if(on==8 || on==9) $('marchandBloc').hide();
		else if(!$('marchandBloc').visible()) $('marchandBloc').show();
	}
	return false;
}

function tooltipBigPhoto(img,caption) {
	image='<img src="'+img+'">';
	caption='<div style="height:100%;vertical-align:middle;padding:0 0 '+(Prototype.Browser.IE ? '3px' : '0')+' 1px;margin:0;font-size:9px;white-space:nowrap;"><img src="/shared/img/vote/wikio.gif" style="border:0;vertical-align:middle;" alt="">&nbsp;&nbsp;'+caption+'</div>';
	closeimg='<img src="/shared/gui/transpicons/del0.gif" style="border:0;vertical-align:bottom;">';
	return overlib(image,STICKY,DRAGGABLE,CLOSECLICK,CLOSETEXT,closeimg,CLOSETITLE,'',CAPTION,caption,HAUTO,VAUTO,
		BORDER,1,BGCOLOR,'#244665',CGCOLOR,'#244665',FGCOLOR,'#ffffff',CAPTIONPADDING,0);
}

var G_SHOPTIMEOUT;
function delayedShowAssocietedPhoto(block,id,elm) {
	G_SHOPTIMEOUT=top.setTimeout("showAssocietedPhoto("+block+","+id+","+elm+")",150);
}

function normalShowAssocietedPhoto(block,id,elm) {
	top.clearTimeout(G_SHOPTIMEOUT);
	if($('photo'+block+''+id)!=null)
		showAssocietedPhoto(block,id,elm);
}

function showAssocietedPhoto(block,id,elm) {
	for(i=0;i<5;i++) {
		if(i==id) {
			$('photo'+block+''+i).show();
			$('td'+block+''+i).style.backgroundColor='#FFFFFF';
			$('td'+block+''+i).style.fontWeight='bold';
		} else {
			if($('photo'+block+''+i) != null) {
				$('photo'+block+''+i).hide();
				$('td'+block+''+i).style.backgroundColor='#f2f2f2';
				$('td'+block+''+i).style.fontWeight='normal';
			}
		}
	}
}

function voteForThisProduct(id, type) {
	var url='/shopping/actions/doproductvote.jsp';
	var params='rp='+id+'&pt='+type;
	var content='votecontent'+id;
	$(content).onclick=function(){ return false; };
	$(content).addClassName('clicked');
	var myAjax=new Ajax.Updater(content,url,{method:'get',parameters:params});
	return false;
}

function openTrackingIPH(iphElementid) {
	window.open($('iphurl'+iphElementid).href);
}

function openTrackingIPV(ipvElementid) {
	window.open($('ipvurl'+ipvElementid).href);
}

function highlightPhoto(id, on) {
	if(on == true) $('photo'+id).setStyle('border: 1px solid #ccc;');
	else $('photo'+id).setStyle('border: 1px solid #edeef0;');
}

function shopSendToaFriend(id,type) {
	return sendToaFriend(id,type,'/shopping/includes/shared/istafcontent.jsp?rp='+id+'&pt='+type);
}

function sendToaFriend(id,type,srccontent) {
	var div='staf'+id;
	var params='rp='+id+'&pt='+type;
	var myAjax=new Ajax.Updater(div,'/shopping/includes/tools/itsendtoafriendform.jsp',{parameters:params,onComplete: function(transport){onCompleteSTAF(id,srccontent);}});
	$(div).show();
	return false;
}

function onCompleteSTAF(id,srccontent) {
	$('ifstaf'+id).src=srccontent+'&preview=true';
	$('stafrr'+id).value=document.location.href;
	var div='stafrc'+id;
	var params='rp='+id;
	var myAjax=new Ajax.Request(srccontent,{asynchronous:false,parameters:params});
	$(div).value=myAjax.transport.responseText;
	return false;
}

function submitSendToaFriend(id) {
	ok=true;
	form=document.forms['stafform'+id];
	elems=form.elements;
	for(i=0;i<elems.length;i++) {
		if(elems[i].value.blank()) {
			alert(G_LBLPLZFILLALL);
			elems[i].select();
			ok=false;
			break;
		}
	}

	if(ok) {
		if(elems['stafcaptcha'] && !checkCaptcha(elems['stafcaptcha'].value)) {
			ok=false;
			alert(G_LBLERRCAPTCHA);
			document.location.reload();
		} else {
			idoc = getFrameDocument($('ifstaf'+id));
			if(idoc && idoc.getElementById('stafmsg'+id)) {
				msg = idoc.getElementById('stafmsg'+id).innerHTML;
				msg = msg.strip().stripScripts().truncate(500);
				if(msg.startsWith('&nbsp;')) msg = msg.substring(6);
				if(msg.endsWith('&nbsp;')) msg = msg.substring(0,msg.length-6);
				content=$('stafrc'+id).value;
				i=content.indexOf('<body>');
				if(i>0) {
					content = content.substring(0,i+6)+msg+content.substring(i+6,content.length);
					$('stafrc'+id).value=content;
				}
			}
			document.body.style.cursor='wait';
			form.submit();
		}
	}
}

function getFrameDocument(iframe) {
	var doc=iframe.contentWindow || iframe.contentDocument;
    if(doc.document) doc=doc.document;
    return doc;
}

function checkCaptcha(code) {
	var r=false;
	var url='/shopping/actions/docontrolcaptcha.jsp';
	var params='code='+code;
	var myAjax=new Ajax.Request(url,{asynchronous:false,parameters:params});
	if(myAjax.transport.responseText=="OK") r=true;
	return r;
}

function cancelSendToaFriend(id) {
	var form='stafform'+id;
	$(form).parentNode.hide();
}

function activeEmbeddedVideo(id,url) {
	$('video-'+id).innerHTML='<span style="margin:3px 9px 10px 0pt;"><object width="150" height="115"><param name="movie" value="'+url+'"></param><param name="allowfullscreen" value="true"></param><embed src="'+url+'" type="application/x-shockwave-flash" width="150px" height="115px" allowfullscreen="true"></embed></object></span>';
}

function showAllRefinementValues(refinename,page) {
	return _refinementsFunction(page, refinename);
}

var G_SHOPREFINEMENT;


function showAllRefinements(page) {
	return _refinementsFunction(page);
}

function closeAllRefinements() {
	$('pl01').show();
	$('pl02').parentNode.removeChild($('pl02'));
}

function _refinementsFunction(page, refinename) {
	var divtoshow='dzall_page'+page;
	if(refinename!=undefined && !refinename.blank()) {
		divtoshow='dzrf'+refinename+'_page'+page;
	}
	var content='pl01';
	$(content).hide();
	if($('pl02')) $('pl02').parentNode.removeChild($('pl02'));
	
	var elem=$(divtoshow).cloneNode(true);
	elem.id='pl02';
	//alert(content);
	new Insertion.Before($(content), elem);
	return true;
}

function displayHiddenRefinement(name) {
	closeAllRefinements();
	if(!$('lim'+name).visible()) {
		parentNode = $('lim'+name).parentNode;
		parentNode.getElementsByTagName('li').item(0).hide();
		oldNode = parentNode.removeChild($('lim'+name));
		parentNode.insertBefore(oldNode, parentNode.getElementsByTagName('li')[0]);
		$('lim'+name).show();
	}
	displayRefinement(name);
}

function submitGistKeyword() {
	sep='?';
	url=$F('shurl01');
	if(url.indexOf('?')>0) sep='&';
	url=url+sep+'gk='+$F('shkeyword01');
	window.location.href=url;
}

function displayRestrictiveContent() {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+1);
	document.cookie="wsRestrictedContent=true;expires="+exdate.toGMTString();
}

