// JavaScript Document

var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)

document.onmousemove = getMouseXY;
//document.onmouseup = getPosXY;

var tempX = 0
var tempY = 0

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  
   //document.getElementById("coord").innerHTML="x&rsaquo;"+tempX +" y&rsaquo;"+ tempY;
   
	  
	  H=document.getElementById("simg").offsetHeight;
	  document.getElementById("simg").style.position="absolute";
      document.getElementById("simg").style.top = tempY-(H+10) +"px";
	  document.getElementById("simg").style.left = tempX +"px";
   
   
  return true
}



function showDiv_cat(param, p_img, p_w, p_h)
{
    if(p_img!="")
	{
		st=document.getElementById(param).style.display;
		
		
		if (st=="none")
		document.getElementById(param).style.display="block";
		else
		document.getElementById(param).style.display="none";
		
		w=120;
		h=(p_h/p_w) * w;
		
		document.getElementById("simg").innerHTML="<div style='width:"+w+"px; height:"+h+"px;'><img src='"+p_img+"' alt='' width='120' /></div>";
		
		
	}
}


function login_cart2()
{
	 
	if (document.log_ut2.user.value!="" && document.log_ut2.psw.value!="")
	{
       document.log_ut2.submit();
	}
}


function livella()
{
	

	harray=new Array();
	harray[0]=0;
	harray[1]=document.getElementById("menu").offsetHeight;
	harray[2]=document.getElementById("co_tx").offsetHeight;
	//harray[3]=document.getElementById("campernews").offsetHeight;
		
	parray=new Array();
	parray[0]=0;
	parray[1]=document.getElementById("navigation").offsetHeight;
	parray[2]=document.getElementById("co_tx").offsetHeight;
	//parray[3]=document.getElementById("extra").offsetHeight;
	
	H=0;
	for(i=1; i<=parray.length-1; i++)
	{
		if (parray[i]>H)
		  H=parray[i];
	}
		

    document.getElementById("menu").style.height=(harray[1]+(H-parray[1])+2) + "px";
	document.getElementById("co_tx").style.height=(harray[2]+(H-parray[2])) + "px";
	//document.getElementById("campernews").style.height=(harray[3]+(H-parray[3])) + "px";
		
}


function valida_registrazioni()
{
	 mail_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

	Arr_campi=new Array("nome","cognome","email","tel","data_consegna");
	Arr_risp=new Array("Nome","Cognome","e-mail","Telefono","Data Consegna");
	
    for (i=0; i<=Arr_campi.length-1; i++)
	 {
		campo=eval("document.registra."+Arr_campi[i]+".value");
		 if (campo=="")
		 {
		  alert("Inserire i dati nel campo " +Arr_risp[i]); return false
		 }
	 }
	 
 
	 if (document.registra.email.value!="")
	 {
		  mail=document.registra.email.value;
		  if (!mail_reg_exp.test(mail) || (mail == "undefined")) 
             {
            	alert("Indirizzo e-mail non corretto."); return false;
   		     }

	 }
	 
	 if (document.registra.tel.value!="")
	  {
	   ct=Number(document.registra.tel.value);
       if (isNaN(ct))
	      {
		    alert("Inserire valori numerici nel campo telefono. Niente trattini lettere o spazi.");
	        return false;
	      }

	  }
	 
 
	 if (!document.registra.privacy.checked)
	 {
       	alert("Per proseguire e' necessario accettare la normativa sulla privacy"); return false;
	 }

	 if (!navigator.cookieEnabled)
	 {
       alert("Non è possibile procedere.\nIl tuo browser non ha i cookies abilitati.\n---------------------- : ( ----------------------"); return false;
	 }

	  document.registra.submit();

}

function ctrl_orders(param)
{
	
/*	if (param.indexOf(",") != (-1))
		param=param.replace(",",".");
	
	
	if (param>=15)
	  document.location.href='dati.php'
	else
	  alert("importo minimo per ordine 15 euro"); return false;*/


	document.location.href='dati.php'
}

function valida_contatti()
{
	mail_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

	Arr_campi=new Array("nome","cognome", "mittente");
	Arr_risp=new Array("Nome","Cognome", "e-mail");
	
    for (i=0; i<=Arr_campi.length-1; i++)
	 {
		campo=eval("document.registra."+Arr_campi[i]+".value");
		 if (campo=="")
		 {
		  alert("Inserire i dati nel campo " +Arr_risp[i]); return false
		 }
	 }
	 
	  mail=document.registra.mittente.value; 
	 if (mail!="")
	 {
		  if (!mail_reg_exp.test(mail) || (mail == "undefined")) 
             {
            	alert("Indirizzo e-mail non corretto."); return false;
   		     }

	 }
	 
	

	 
	

	
	 
	 document.registra.submit();

}


//================================================================================================================================
// FUNZIONI GENERICHE (cioè che possono essre richiamate da script in pagine diverse)

function checkall(param)   //select all checkbox
  {
   sa=false;
  if(eval("document."+param+".check_all.checked"))
    sa=true;

  for (i=0;i<eval("document."+param+".elements.length");i++)
    {
   
      if(sa)
         eval("document."+param+".elements["+i+"].checked=true");
      else
         eval("document."+param+".elements["+i+"].checked=false");
    }
  }
