// JavaScript Document
       
	   
	   
	   		 window.onload = function(){
				
				OpenedTabMenu("Menu");
				var a = getElementsByClassName(document, "A", "opengallery");

				if(a.length>0){
					for(var i=0; i<a.length; i++){
						a[i].href = "javascript:void(0);";
						a[i].onclick = function(){
									  var id = this.id.toString();
									  var type = id.substr(id.indexOf("_")+1);
									  var title = this.getElementsByTagName("SPAN")[0].innerHTML;
									  OpenGallery("showroom",type, title);
						}
					}
				}
			 
			 }
			 
			 
			 
		 function ChangeUrlSearch(rew){
			 
			      if(rew=="yes"){
				  
				  var theForm = document.forms["FormSearch"];
				  var lang = theForm.lang.value;
				  var host = theForm.host.value;
				  var id_cat = theForm.id_cat.options[theForm.id_cat.options.selectedIndex].value;
				  var id_mar = theForm.id_mar.options[theForm.id_mar.options.selectedIndex].value;
		
				  
				  if((id_cat!="") || (id_mar!="")){
					  
					  var url;
					  if((id_cat!="") && (id_mar=="")) url = 'http://'+host+'/'+lang+'/catalogo/'+id_cat+".php"; 
					  if((id_cat!="") && (id_mar!="")) url = 'http://'+host+'/'+lang+'/catalogo/'+id_cat+"/"+id_mar+".php"; 
					 
					  window.location.href=url;
				  }
				  
				  return false;
				  
				  }else{
					  
				  }
		 }
			 
			 
			 
		 function OpenedTabMenu(menuid){
			 
			 if(document.getElementById(menuid)){
			   
			   var menu = document.getElementById(menuid);
			   var ul = menu.getElementsByTagName("UL")[0];
			   var a =  menu.getElementsByTagName("A");
			   var page = window.location.toString().replace("#","");
			   var ss = false;
			   
			   for(var i=0; i<a.length; i++){
				   var href = a[i].href;
				   a[i].removeAttribute("class");
				   if((page.indexOf(href)>0) || (page==href)){
					var aactive = a[i];
				   }
			   }
			   
			   if(aactive){
				   aactive.setAttribute("class","active");
			   }
		   
			 }
		 
		 }
	   
	   
	    function CloseGallery(){
			if(document.getElementById("my-box-photogallery")){
				var box =  document.getElementById("my-box-photogallery");
			    box.style.display = "none";
				if(document.getElementById("opacity")){
				   var opacity 	= document.getElementById("opacity");
				   opacity.parentNode.removeChild(opacity);
				}
			}
		
		}


	    function OpenGallery(section, gallery, title){
		         
				 var box =  document.getElementById("my-box-photogallery");
				 var parentNode = box.parentNode;
				 
				 	if(opacity){
					
					}else{
					var opacity = document.createElement('div');
					parentNode.appendChild(opacity);
					opacity.id="opacity";
					opacity.onclick= function(){ CloseGallery(); }
					
						  var w = parentNode.offsetWidth;
						  var h = parentNode.offsetHeight;
						
						opacity.style.width=w+"px";
						opacity.style.height=h+"px";
						//alert(navigator.appName+" : "+w+" x "+h);

					}
				 
				 box.style.display = "block";
				 var h3 = box.getElementsByTagName("h3")[0];
				 var p = box.getElementsByTagName("P")[0];
				 //h3.innerHTML = "Galleria fotografica "+title;
				 h3.innerHTML = ""+title+"";
				 if((photo[gallery]) && (photo[gallery].length>0)){
				    var a =  "";
					for(var i=0; i<photo[gallery].length; i++){
					    var img = "http://www.heraclia.it/pictures/showroom/"+gallery+"/"+photo[gallery][i];
					    a += "<a href=\"javascript:loadPhoto('"+img+"');\">"+(i+1)+"</a>";
					
					}
				    p.innerHTML = a;
					loadPhoto("http://www.heraclia.it/pictures/showroom/"+gallery+"/"+photo[gallery][0]);
				 }
		
		}
		
		
		function loadPhoto(imgurl){
		         if((imgurl!="") && document.getElementById("my-content-photogallery")){
		         var box =  document.getElementById("my-content-photogallery");
				 var div = box.getElementsByTagName("DIV")[0];
				 div.innerHTML = "";
				 
				 if(newimg) div.removeChild(newimg);
				 	
					var rand = Math.floor(Math.random()*1001);
					
					var newimg=document.createElement('img');
					newimg.id="BigPhoto";
					div.appendChild(newimg);
					newimg.src=imgurl+"?"+rand;
			        newimg.style.display = "none";
					newimg.onload=function(){
					    
						$("#BigPhoto").fadeIn("slow");


						/*
					    var h = newimg.height;
						var w = newimg.width;
						
						if(navigator.appName == "Microsoft Internet Explorer"){
						newimg.style.marginTop=((hparent-h)/2);
						} else {
						newimg.style.marginTop=((hparent-h)/2)+"px";
						}
						
						///// disabilito il tasto destro dalla foto grande
						onLoadDisable('BigPhoto');
	                    */
					}
	
					

				 
				 }
				 
		}
		
	
	
	
	function ApriFormLogin(page, qstring){
	     if(page!=""){
			window.open(page+'?'+qstring,'miaFinestra','width=600,height=400 ,toolbar=no, location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
         }
}



function OpenPopup(url, w, h){

            if(url!=""){
			window.open(''+url+'','miaFinestra','width=200,height=200,top=50, left=50, toolbar=no, location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
         }

}
	
	
	
	
	function emailcheck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){//  alert("L'indirizzo E-mail non è valido!")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){//  alert("L'indirizzo E-mail non è valido!")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){//  alert("L'indirizzo E-mail non è valido!")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){//  alert("L'indirizzo E-mail non è valido!")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){//  alert("L'indirizzo E-mail non è valido!")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){//  alert("L'indirizzo E-mail non è valido!")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){//  alert("L'indirizzo E-mail non è valido!")
		    return false
		 }

 		 return true					
	}
  
		

  function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}
