﻿function AssignUniqueToClassSifr(){
	var arSifr = new Array();
	arSifr  = getElementsByClassName("sifr");
	var i =0;
	for (i=0;i<arSifr.length;i++){
		arSifr[i].id=arSifr[i].id + "_" + parseInt(i+1);
	}
}


function getElementsByClassName(classname, node){    
if(!node) node = document.getElementsByTagName("body")[0];    
	var a = [];    
	var re = new RegExp('\\b' + classname + '\\b');    
	var els = node.getElementsByTagName("*");    
  
	for(var i=0,j=els.length; i<j; i++)        
		if(re.test(els[i].className))
			a.push(els[i]);    
		
		
		return a;
}

function VerifyUniqueToClassSifr(){
	var arSifr = new Array();
	arSifr  = getElementsByClassName("sifr");
	var i =0;
	for (i=0;i<arSifr.length;i++){
		alert(arSifr[i].id)
	}

}

function o(url,name,options) {
	var wnd = window.open(url, name, options);
}



//window.onload=function(){AssignUniqueToClassSifr();
//VerifyUniqueToClassSifr();
//}



function changeproduct(dropdown) {
	var key = dropdown.getAttribute("id")
	//alert($("#"+key).attr("value"))
	//alert($("#"+key).html())
	
	
	var selIndex = dropdown.selectedIndex;
	
	//Path Immagine da visualizzare
	
	var imagePath = dropdown.options[selIndex].getAttribute("imgPath");
	//Url del contenuto 
	var Url= dropdown.options[selIndex].getAttribute("cntUrl");
	var cntTitle= dropdown.options[selIndex].value;
	var htmlString= "<a href='"+Url+"'><img src='"+imagePath +"' border='0'></img></a><br/><p><a href='"+Url+"'><img border='0' src='/includes/img/scheda_dettaglio.gif' class='scheda_dettaglio'></a></p>"
	//In base alla classe catprod
	//determino input type select e cambio il selezionato tranne quello corrente	
	var arrProductHtml=getElementsByClassName("catprod");
	for (i=0;i<arrProductHtml.length;i++){
		if (arrProductHtml[i].childNodes.length>0){
			 for(j=0;j<arrProductHtml[i].childNodes.length;j++){
				if (arrProductHtml[i].childNodes[j].tagName=="SELECT"){
						if(arrProductHtml[i].childNodes[j].id!=dropdown.id){
							arrProductHtml[i].childNodes[j].selectedIndex=0;
						}
				}
			 
			 }
		
		}
	}	
	var source=new String("");

	//document.getElementById("productselected") ==null indica la ricerca viene fatta nel dettagglio del prodotto
	if (document.getElementById("productselected") != null) {
	    if(cntTitle=='')
	        $("#searchproduct").css("background-image", "url(/includes/css/img/bg_cercaprodotto_ON.gif)");
	    else
	        $("#searchproduct").css("background-image", "url(/includes/css/img/bg_cercaprodotto_OFF.gif)");
		$("#producttitle").html(cntTitle);
		/*if (document.getElementById("product_on")!=null){
			//change l'immagine per indicare se  stato selezionato un prodotto
					
			source=(document.getElementById("product_on").getAttribute("src"));
			source=source.replace("product_off","product_on");
			document.getElementById("product_on").setAttribute("src",source);
	  }*/
		if ((imagePath!="/")&&(imagePath!=""))
			$("#productselected").html(htmlString);
		else{
					//change l'immagine a quella di default
					
					source=(document.getElementById("product_on").getAttribute("src"));
					source=source.replace("product_on","product_off");
					document.getElementById("product_on").setAttribute("src",source);
					$("#productselected").html("");
				
			}
	}
	else
	{
		if (Url!="")
			document.location.href=Url;	
	}			

}


function searchpromo(dropdown) {
	var key = dropdown.getAttribute("id")
	//alert($("#"+key).attr("value"))
	//alert($("#"+key).html())
	
	
	var selIndex = dropdown.selectedIndex;
	
	//Path Immagine da visualizzare
	
	var imagePath = dropdown.options[selIndex].getAttribute("imgPath");
	//Url del contenuto 
	var Url= dropdown.options[selIndex].getAttribute("cntUrl");
	var cntTitle= dropdown.options[selIndex].value;
	var htmlString= "<a href='"+Url+"'><img src='"+imagePath +"' border='0'></img></a><br/><p><a href='"+Url+"'><img border='0' src='/includes/img/scheda_dettaglio.gif' class='scheda_dettaglio'></a></p>"
	//In base alla classe catprod
	//determino input type select e cambio il selezionato tranne quello corrente	
	var arrProductHtml=getElementsByClassName("catprod");
	for (i=0;i<arrProductHtml.length;i++){
		if (arrProductHtml[i].childNodes.length>0){
			 for(j=0;j<arrProductHtml[i].childNodes.length;j++){
				if (arrProductHtml[i].childNodes[j].tagName=="SELECT"){
						if(arrProductHtml[i].childNodes[j].id!=dropdown.id){
							arrProductHtml[i].childNodes[j].selectedIndex=0;
						}
				}
			 
			 }
		
		}
	}	
	
	$("#linksearchresult").attr({href:Url})
	
}

function viewThems(dropdown) {

	//Url del contenuto 
	var selIndex = dropdown.selectedIndex;
	var Url= dropdown.options[selIndex].getAttribute("cntUrl");
	
	if (Url!="")
		document.location.href=Url;	
	
}

function RedirectPage(Url) {
  document.location.href=Url;
}
