var Euronics = {
	
	swapImg : function(m, n){ /* swap per immagini */
	    m = m.getElementsByTagName("IMG");
	    m[0].src = n;
	},
	
	getElementsByClassName : function(cl){ /* trova classe */
	    var retnode = [];
	    var myclass = new RegExp('\\b' + cl + '\\b');
	    var elem = document.getElementsByTagName('*');
	    for (var i = 0; i < elem.length; i++) {
	        var classes = elem[i].className;
	        if (myclass.test(classes)) {
	            retnode.push(elem[i]);
	        }
	    }
	    return retnode;
	},
	
	showLabel : function(e){ /* mostra label (cellulare) */
	    if (e == 'one') {
	        document.getElementById('one').className = 'on';
	        document.getElementById('two').className = 'off';
			if(document.getElementById('three')){
				document.getElementById('three').className = 'off';
			}
	        document.getElementById('linkLabel').getElementsByTagName('li')[0].className = 'on';
	        document.getElementById('linkLabel').getElementsByTagName('li')[1].className = 'off';
	        if(document.getElementById('linkLabel').getElementsByTagName('li')[2]){
				document.getElementById('linkLabel').getElementsByTagName('li')[2].className = 'off';
			}
	    };
	    if (e == 'two') {
	        document.getElementById('one').className = 'off'; 
			if(document.getElementById('three')){
				document.getElementById('three').className = 'off';
			}
	        document.getElementById('two').className = 'on';
	        document.getElementById('linkLabel').getElementsByTagName('li')[0].className = 'off';
	        document.getElementById('linkLabel').getElementsByTagName('li')[1].className = 'on';
	        if(document.getElementById('linkLabel').getElementsByTagName('li')[2]){
				document.getElementById('linkLabel').getElementsByTagName('li')[2].className = 'off';
			}
	    };
	    if (e == 'three') {
	        document.getElementById('one').className = 'off';
			document.getElementById('two').className = 'off';
	        if(document.getElementById('three')){
				document.getElementById('three').className = 'on';
			}
	        document.getElementById('linkLabel').getElementsByTagName('li')[0].className = 'off';
	        document.getElementById('linkLabel').getElementsByTagName('li')[1].className = 'off';
	        if(document.getElementById('linkLabel').getElementsByTagName('li')[2]){
				document.getElementById('linkLabel').getElementsByTagName('li')[2].className = 'on';
			}
	    };
	},
	
	chStars : function(a,b){ /* cambia rank */
	    b.parentNode.className = 'stars ' + a;
	},
	
	resetStars : function(a,b){ /* resetta rank */
	    if (a) {
	        b.className = 'stars ' + a;
	    }
	    else {
	        b.className = 'stars';
	    }
	},
	
	zoomThis : function(a){		
		this.getElementsByClassName('on')[0].className = '';
		document.getElementById('photoZoom').src = a.firstChild.src.split('_th')[0]+a.firstChild.src.split('_th')[1];
		a.className = 'on';		
	},
	
	zoomThisImage : function(a){		
		this.getElementsByClassName('on')[0].className = '';
		var imagePath=a.firstChild.src.split('_th')[0]+a.firstChild.src.split('_th')[1];
		imagePath=imagePath.replace('width=78','width=500').replace('height=78','height=500').replace('undefined','');
		document.getElementById('photoZoom').src = imagePath;
		a.className = 'on';		
	},
	
	openWindow : function(url){		
		finestra=window.open(url,"popup","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=610,height=550");
		finestra.focus();	
	},
	
	submitCart : function(){		
		if(document.getElementById('accepted')){
			document.getElementById('errore').style.display = "block";		
			if(document.getElementById('accepted').checked){
				document.shoppingCart.submit();
			}else{
				document.getElementById('errore').style.display = "none";
				document.getElementById('erroreCond').style.display = "block";
			}		
		}		
	},
	
	openPop : function(a){
		if(navigator.appName == "Microsoft Internet Explorer"){
			offTop = document.documentElement.scrollTop+10;
		}else{				
			offTop = window.pageYOffset+10;						
		};		
		divCont = Builder.node('div',{id:'contPop',style:'display: block; position:absolute; top:0; left:0; z-index:100; background:red; filter:alpha(opacity=0);-moz-opacity:.0;opacity:.0; width:100%; height:'+document.body.clientHeight+'px;'});		
		popUp = Builder.node('div',{id:'popUp',style:'display: block; position: absolute; z-index: 101; top: '+offTop+'px; left: '+Math.ceil((document.body.clientWidth-790)/2)+'px; width:790px; height:390px; background:#eee; padding:10px; border-bottom:2px solid #666; border-right:2px solid #666;'});
		closeDiv = Builder.node('div',{id:'closeDiv',style:'display: block; width:790px; height:20px; text-align:right;'});
		btnClose = Builder.node('a',{href:'javascript:void(0);',id:'close'},'chiudi');
		btnPrint = Builder.node('a',{href:'javascript:void(0);',id:'print'},'stampa');
		popupLayer = Builder.node('div',{id:'popupLayer',style:'display: block; width:780px; height:355px; background:#fff; overflow:auto; padding:5px;'});
		stealth=Builder.node('iframe',{name:'popstampa',id:'popstampa',src:'',width:'1',height:'1',frameborder:'0'});
		
		$('content').appendChild(divCont);					
		closeDiv.appendChild(btnPrint);
		closeDiv.appendChild(btnClose);
		popUp.appendChild(stealth);
		popUp.appendChild(closeDiv);
		popUp.appendChild(popupLayer);
		$('content').appendChild(popUp);		
		url = a.href;
		$('popupLayer').innerHTML = '<div style="padding:80px 0;" align="center">Caricamento...<br /><img src="/acquistaonline/template-resources/i/loader.gif" alt="..." /></div>';
		new Ajax.Updater('popupLayer',url,{method:'get',evalScripts:true});
		$('popstampa').src=url;

		$('print').onclick  = function(){	
			window.frames['popstampa'].focus();
			window.frames['popstampa'].print();
		
			/* 
			http://www.sviluppo.euronics.it/acquistaonline/print-popup.ep?urlPopup=popup/navigare.html
			"/acquistaonline/template-resources/popup/navigare.html"
			"/pupup/navigare.html"
			*/
		}
		
		$('close').onclick = $('contPop').onclick = function(){
			Element.remove('contPop');
			Element.remove('popUp');
		}		
	},
	
	openWait : function(){
		if(navigator.appName == "Microsoft Internet Explorer"){
			offTop = document.documentElement.scrollTop+10;
		}else{				
			offTop = window.pageYOffset+10;						
		};		
		divCont = Builder.node('div',{id:'contPop',style:'display: block; position:absolute; top:0; left:0; z-index:100; background:#ffffff; filter:alpha(opacity=30);-moz-opacity:.3;opacity:.3; width:100%; height:'+document.body.clientHeight+'px;'});		
		popUp = Builder.node('div',{id:'popUp',style:'display: block; position: absolute; z-index: 101; top: '+offTop+'px; left: '+Math.ceil((document.body.clientWidth-460)/2)+'px; width:460px; height:270px; background:#fff; padding:10px; border:20px solid #eee; '});
		popupLayer = Builder.node('div',{id:'popupLayer',style:'display: block;  width:450px; height:235px;  overflow:auto; padding:5px;'});		
		$('content').appendChild(divCont);
		popUp.appendChild(popupLayer);
		$('content').appendChild(popUp);		
		
		$('popupLayer').innerHTML = '<div style="padding:80px 0;" align="center">Aggiornamento carrello...<br /><img src="/acquistaonline/template-resources/i/loader.gif" alt="..." /></div>';

	},	
	
	closeWait : function(){
			Element.remove('contPop');
			Element.remove('popUp');
	},	
	
	openInPop : function(a){
		url = a.href;
		$('popupLayer').innerHTML = '<div style="padding:80px 0;" align="center">Caricamento...<br /><img src="/acquistaonline/template-resources/i/loader.gif" alt="..." /></div>';
		new Ajax.Updater('popupLayer',url,{method:'get',evalScripts:true});
		$('popstampa').src=url;
	},	


	createLoad : function (txt){
		if(navigator.appName == "Microsoft Internet Explorer"){
			offTop = document.documentElement.scrollTop+10;
		}else{				
			offTop = window.pageYOffset+10;						
		};	
		var lbHeight = screen.height;	
		//alert("boxname:"+boxName+" | txt="+txt);
		var boxLoading = Builder.node('div',{className:'boxLoading', id: 'contLoader'});
//		document.body.style.overflow= "hidden";
		boxLoading.innerHTML = txt;
		//boxLoading.style.height = lbHeight+"px";	
		$('loader').style.top=offTop+"px";	
		$('loader').appendChild(boxLoading);
		Element.show('loader');
	},

	removeLoad : function (boxName){
		//alert("boxname:"+boxName);
		var myLoading = $(boxName).getElementsByClassName('boxLoading')[0];
		Element.hide(myLoading);
		$('contLoader').remove();
		Element.hide('loader');
		document.body.style.overflow = "auto";
	},
	accordion : function(a){
		nLi = Element.next(a).getElementsByTagName('li');		
		h = nLi.length*15;	
		if(Element.next(a).style.height.split('px')[0] == 0){
			Element.next(a).style.height = h+"px";
		}else{
			Element.next(a).style.height = "0px";
		}
	},
	
	trasforma : function (){
	if ($("keyWordsSearch").value.length<2)	{
		alert("Inserire una parola chiave con almeno 2 caratteri per effettuare la ricerca.");
		return false;
		} else {
	a=document.getElementById("keyWordsSearch").value;
	a=a.toUpperCase();
	document.getElementById("keyWordsSearch").value = a;
	return true;
		}
	},
		
	contrCell : function(a) {
		b=$("newAddress.prefCellulare").selectedIndex;
		if (a.value!="" && b==0) {
			alert("Inserire anche il prefisso del cellulare.");
			$("newAddress.prefCellulare").focus();
		}
	},
		
	contrCellSel : function(a) {
		a=a.selectedIndex;
		b=$("newAddress.cellulare").value;
		if (b=="" && a!=0) {
			alert("Inserire anche il numero di cellulare.");
			$("newAddress.cellulare").focus();
		}
	},
	
	/*metodo per tracciamento banner*/
	
	/* banner counter */
    call: function (a,p1,p2,p4,b) {

	
	var url = escape(a.href);
	var p2=window.location;
	var p3="commerce"
	if(b=='new'){a.target = '_blank'};
	var params = "id="+p4+"&bannerLancio="+p1+"&requestPath="+p2+"&sito="+p3+"&dest="+url;
	var urlServer="http://www.euronics.it/utility/banner_counter_commerce.jsp?"; 
	var urlBannerTrack=urlServer+params;
	/*
	new Ajax.Request(urlBannerTrack, {
			method: 'get',
			onComplete: function() {
				window.location.href = url;
			}
		});
	*/
	if(url.match(/\/newsletter\//)){
		var popup=window.open(a.href, '_popupW', 'width=560,height=400');
	}
	else{
		window.location.href = urlBannerTrack;
	}
	}
	
	/* fine metodi */
}

/* WORKAROUND FLASH PER IE (activx) */
function addFlash(path,larghezza,altezza,transp,variabili,name){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+larghezza+'" height="'+altezza+'" id="'+name+'">');
	document.write('<param name="bgcolor" value="#EDEDED">');
	document.write('<param name="movie" value="'+path+'">');
	document.write('<param name="quality" value="high">');
	if(transp=='yes'){
		document.write('<param name="wmode" value="transparent">');
	};
	if(variabili!=''){
		document.write('<param name="flashvars" value="'+variabili+'">');
	};
	document.write('<embed src="'+path+'" quality="high" width="'+larghezza+'" height="'+altezza+'" name="'+name+'" type="application/x-shockwave-flash"  ');
	if(transp=='yes'){
		document.write('wmode="transparent" ');
	};
	if(variabili!=''){
		document.write('flashvars="'+variabili+'" ');
	};		   
	document.write('pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"></embed></object>');
};

var $j = jQuery.noConflict();


var old_height = 0;
function toggleCategoriesBox(nome_campo,numero_record){
	var_duration = 75*numero_record;
	old_height = $j("."+nome_campo).height();
	var trueHeight = $j("."+nome_campo+" ul").height() + $j("."+nome_campo+" .title_tags").height();
	$j("."+nome_campo).animate({height:trueHeight}, { duration:var_duration });
	$j("#img_blocco_marchi_su_"+nome_campo).hide();
	$j("#img_blocco_marchi_giu_"+nome_campo).show();
}

function close_toggleCategoriesBox(nome_campo,numero_record)
{
	var trueHeight = old_height;
	var_duration = 75*numero_record;
	$j("."+nome_campo).animate({height:trueHeight}, { duration:var_duration });
	$j("#img_blocco_marchi_su_"+nome_campo).show();
	$j("#img_blocco_marchi_giu_"+nome_campo).hide();
}

function setCategoriesBoxHeight(nome_campo){
	var i = 0;
	var trueHeight = 0;
	for(i=0; i<9; i++)
	{
		trueHeight += $j("."+nome_campo+" li:eq(" + i + ")").height() + 4;
	}
	trueHeight += $j("."+nome_campo+" .title_tags").height() + 14;

	$j("."+nome_campo).css("height", trueHeight);
}

function checkRicerca()
{
	if(document.getElementById('query').value=="" || document.getElementById('query').value=="Inserire il nome di un prodotto")
	{
		document.getElementById('query').style.color="red";
		document.getElementById('query').value = "Inserire il nome di un prodotto";
	}
	else{
		document.getElementById('query_post').value = document.getElementById('query').value;
		document.doc.submit();
	}
}

function checkEnter(e){ 
	var characterCode 
	if(e && e.which){ 
		e = e
		characterCode = e.which 
	}
	else{
		e = event
		characterCode = e.keyCode
	}
	if(characterCode == 13){ 
		checkRicerca();
	}
}

function chk_value(){
	if(document.getElementById('query').value=="Inserire il nome di un prodotto")
			document.getElementById('query').value="";
}

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function sndReq() {  
	http.open('get', '/commons/template/carica_codice.php',true);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
		document.getElementById('popupLayer').innerHTML=response;
    }
}

function sndReq_autocomplete() {  
	http.open('get', '/commons/template/elenco_parole.php',true);
    http.onreadystatechange = handleResponse_autocomplete;
    http.send(null);
}

function get_ents(str){
var temp=document.createElement("pre");
temp.innerHTML=str;
return temp.firstChild.nodeValue;
}

function handleResponse_autocomplete() {
    if(http.readyState == 4){
		var response = http.responseText;
        var data = new Array();
        if(response.indexOf(" " != -1)) {
            data = response.split("|");
            $j("#query").autocomplete(data);
            }  
		
    }
}

