// JavaScript Document

function init()
{
        var nav=document.getElementById('target');

        if(nav && nav.getElementsByTagName('tr')[0])
        {
            var tr = nav.getElementsByTagName('tr');
            for(var i=0;i<tr.length;i++)
            {
                    addEvent(tr[i],'mouseout',trOut,false);
                    addEvent(tr[i],'mouseover',trOver,false);
                    
                    
            }
        }
        
}
function cssjs(a,o,c1,c2)
{
    switch (a)
    {
        case 'swap':
        o.className=!cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
        break;
        case 'add':
        if(!cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
        break;
        case 'remove':
        var rep=o.className.match(' '+c1)?' '+c1:c1;
        o.className=o.className.replace(rep,'');
        break;
        case 'check':
        return new RegExp('b'+c1+'b').test(o.className)
        break;
    }
}
function addEvent(elm, evType, fn, useCapture){
        if (elm.addEventListener)
        {
            elm.addEventListener(evType, fn, useCapture);
            return true;
        } else if (elm.attachEvent) {
            var r = elm.attachEvent('on' + evType, fn);
            return r;
        } else {
            elm['on' + evType] = fn;
        }
    }
function getTarget(e){
        var target = window.event ? window.event.srcElement : e ? e.target : null;
        if (!target){return false;}
        return target;
    }
function trOver(e)
{
    var trTarget = getTarget(e);
    cssjs('swap',trTarget.parentNode,'over','out');
}
function trOut(e)
{
    var trTarget = getTarget(e);
      cssjs('swap',trTarget.parentNode,'out','over');
}
addEvent(window,'load',init, false);

function ApriImmagini(file) {
	if (typeof win1 != "undefined") 
	win1.close();
	var prop = "top=10, left=10, width=10, height=10";
	win1 = window.open(file, null, prop);
}


function controlla()
{
	
  var d = window.document.contatti
  var title_error = "ERRORE! Impossibile inviare la richiesta! \n\n"
  var error = ""
  
  if (d.email.value) { 
		if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test( d.email.value )) {
			error += "Il formato della email non è corretto.\n"
		}
	}
	  
  if (!d.nome.value)  error += "Inserire il vostro Nome e Cognome. \n"
  if (!d.email.value)  error += "Inserire l'indirizzo e-mail. \n"
  if (!d.privacy.checked)  error += "Acconsentire al trattamento dei dati personali\n"
  
  else { if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test( d.email.value ))  { error += "L'indirizzo e-mail inserito non è valido.\n" } }
  
  if (!d.captcha.value)  error += "Inserire il Codice di sicurezza. \n"

  if (error) {
	 alert(title_error + error); 
	 return(false);
  } else {
	  return(true);
  }
	
	
}

function conta(id_banner)
{
 		var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = 'click_banner.php?id_banner=' + id_banner ;
        window.document.body.appendChild (jsel);
}
function url(url){

	location.href= url;

}

function carrello(session_id, id_foto)
{
 		var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = 'ins_carrello.php?session_id=' + session_id  + '&id_foto=' + id_foto ;
        window.document.body.appendChild (jsel);
		qt_carrello++;
		document.form1.qt.value=qt_carrello;
}

function validator(url)
{
	if (window.confirm("ATTENZIONE: Sicuri di eliminare?"))
	{
		//they clicked Ok
		location.href=url;
	} else {
	  
	}
}
function controlla_ordine()
{
	
  var d = window.document.ordine
  var title_error = "ERRORE! Impossibile inviare l'ordine! \n\n"
  var error = ""
  
  if (d.email.value) { 
		if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test( d.email.value )) {
			error += "Il formato della email non è corretto.\n";
		}
	}
	  
  if (!d.nome.value)  error += "Inserire il vostro Nome. \n";
  if (!d.indirizzo.value)  error += "Inserire il vostro indirizzo. \n";
  if (!d.citta.value)  error += "Inserire la citta di appartenenza. \n";
  if (!d.prov.value)  error += "Inserire la provincia di appartenenza. \n";
  if (!d.tel.value)  error += "Inserire il vostro telefono. \n";
  if (!d.email.value)  error += "Inserire l'indirizzo e-mail. \n";
  if (!d.privacy.checked)  error += "Acconsentire al trattamento dei dati personali\n";
  
  else { if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test( d.email.value ))  { error += "L'indirizzo e-mail inserito non è valido.\n"; } }
  

  if (error) {
	 alert(title_error + error); 
	 return(false);
  } else {
	  return(true);
  }
	
	
}


