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=300').replace('height=78','height=400').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=420,height=500");
		finestra.focus();	
	},
	
	submitCart : function(){		
		if(document.getElementById('condizioni')){		
			if(document.getElementById('condizioni').checked){
				document.shoppingCart.submit();
			}else{
				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-400)/2)+'px; width:388px; height:420px; background:#eee; padding:10px; border-bottom:2px solid #666; border-right:2px solid #666;'});
		closeDiv = Builder.node('div',{id:'closeDiv',style:'display: block; width:380px; 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');
                imgLogo = Builder.node('img',{src:'/i/tecnopedia.gif',id:'imgTecnopedia',align:'left'});
		popupLayer = Builder.node('div',{id:'popupLayer',style:'display: block; width:380px; height:330px; background:#fff; overflow:auto; padding:5px;'});		
		$('content').appendChild(divCont);
		closeDiv.appendChild(imgLogo);					
		closeDiv.appendChild(btnPrint);
		closeDiv.appendChild(btnClose);
		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="/i/loader.gif" alt="..." /></div>';
		new Ajax.Updater('popupLayer',url,{method:'get',evalScripts:true});		

		$('print').onclick  = function(){			
			window.print();		
		}
		
		$('close').onclick = $('contPop').onclick = 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="/i/loader.gif" alt="..." /></div>';
		new Ajax.Updater('popupLayer',url,{method:'get',evalScripts:true});		
	},	


	createLoad : function (boxName,txt){
		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').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";
		}
	}
	/* fine metodi */
}

/* layer login */
showLogin = function(a){
	if($('login2').style.height=='77px'){
		new Effect.Morph('login2',{
				style:'height:0px;',
				duration:0.4,
				afterFinishInternal:function(){
					a.style.background = "url(http://www.euronics.it/export/sites/default/i/logReg_bg.gif) repeat-x left top";
					a.style.borderBottom = "1px solid #e4d301";
					}
				}
			);
	}else{
		a.style.background = "#FFEB00";
		a.style.borderBottom = "1px solid #feed01";
		new Effect.Morph('login2',{style:'height:77px;',duration:0.6});
	}
}

/* layer login New */
showLoginNew = function(a){
	if($('login2').style.height=='97px'){
		new Effect.Morph('login2',{
				style:'height:0px;',
				duration:0.4,
				afterFinishInternal:function(){
					//a.style.background = "url(http://www.euronics.it/export/sites/default/i/logReg_bg.gif) repeat-x left top";
					//a.style.borderBottom = "1px solid #e4d301";
					}
				}
			);
	}else{
		//a.style.background = "#FFEB00";
		//a.style.borderBottom = "1px solid #feed01";
		new Effect.Morph('login2',{style:'height:97px;',duration:0.6});
	}
}
