﻿var locale=""; // utilizzato per la navigazione globale
var curGender = "";
var myShow=null;
var timeslide=null;
var limite=0;
var intro=0;
var tmpid=0; // eliminazione prodotti carello
var spese=0;
var totalegenerale=0;
var curLine="";
var lineIdFromList="";//per lista prodotti
var catIdFromList="";//per lista prodotti
var curIDCat="";
var curIDDes="";
var curIDStyle="";
var curSeason="actual";
var curDescrCat = "";
var curDescrDes = "";
var curDescrStyle="";
var curCurrency;
var viewDesigner=false;
var dStyle= new Array();
var arrCategories= new Array();
var viewStyle=false;
var newsletter=false;
var onsale=false;
var img_mybagsel;
var img_stylesel;
var arr_image_style;
var arr_image_categ;
var agt = navigator.userAgent.toLowerCase();
var is_op = (agt.indexOf("opera") != -1);
var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_op;
var is_ie6 = (agt.indexOf("msie 6.")!=-1)
var is_mac = (agt.indexOf("mac") != -1);
var is_gk = (agt.indexOf("gecko") != -1);
var is_sf = (agt.indexOf("safari") != -1);
// Flash checking code adapted from Doc JavaScript information;
// see http://webref.com/js/column84/2.html
var is_Flash = false;
var is_FlashVersion = 0;

//var plugin = (navigator.mimeTypes &&
//navigator.mimeTypes["application/x-shockwave-flash"] &&
//navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin)?
//navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
//if (plugin) 
//{
//    is_Flash = true;
//    is_FlashVersion = parseInt(plugin.description.substring(plugin.description.indexOf(".")-1));
//}
 

var PAY_TYPE_VISAMASTER="135";
var PAY_TYPE_AMEEXP="AME";
var PAY_TYPE_PAYPAL="PPA";
var PAY_TYPE_BAKTRANSF="PAB";

var expectedHash = "";
var newHashIE="";
var directLoad = false;//la pagina e' stata caricata copiando un link nella barra degli indirizzi

var mekingHist = 0;
var fromInternalGest = false;

var fromSearch=false;

function IsNumeric(strString, strValidChars)
//  check for valid numeric strings	
{
    //var strValidChars = "0123456789.-";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;

    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++)
    {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
      {
         blnResult = false;
      }
    }
    return blnResult;
}

function IsInt(strString)
{
    var strValidChars = "0123456789";
    return IsNumeric(strString, strValidChars);
}



function isEmail(str)
{
    //validazione dell'indirizzo email
    var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)|(\\,)");
    var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
    var r3 = new RegExp(/^[a-z][a-z-_0-9\.]+@[a-z-_=>0-9\.]+\.[a-z]{2,3}$/i);
    return (!r1.test(str) && r2.test(str) && r3.test(str));
}

function CheckCFPIva(value)
{
//    if (value.length != 16 && value.length != 11)
//        return "Per favore inserire un Codice Fiscale valido o una partita IVA valida.";
//    if (value.length == 16)
//    {
        return CheckCF(value);
//    }
//    else if (value.length == 11)
//    {
//        return CheckPIVA(value);
//    }
}

function FormatPrz(value)
{
    var str ="";
    str=value+"";
    var idx = str.indexOf(".");
    
    if (idx<0)
        str = value +".00";
    else 
    {
        if (str.substring(idx+1).length==1)
            str = value +"0";
        else if (str.substring(idx+1).length==2)
            str = value;
        else
        {
            var dec = str.substring(idx+1,idx+3);
            str = str.substring(0,idx)+"."+dec;
        }
    }
    return str.replace(".",",");;
}
function CheckPIVA(pi)
{
//    if( pi == '' ) return '';
//    if( pi.length != 11 )
//        return "La lunghezza della partita IVA non è\n corretta: la partita IVA dovrebbe essere lunga\n esattamente 11 caratteri.\n";
    validi = "0123456789";
    for( i = 0; i < 11; i++ )
    {
        if( validi.indexOf( pi.charAt(i) ) == -1 )
        return "La partita IVA contiene un carattere non valido `" +
            pi.charAt(i) + "'.\nI caratteri validi sono le cifre.\n";
    }
    s = 0;
    for( i = 0; i <= 9; i += 2 )
        s += pi.charCodeAt(i) - '0'.charCodeAt(0);
    for( i = 1; i <= 9; i += 2 )
    {
        c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) );
        if( c > 9 ) c = c - 9;
        s += c;
    }
    if( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) )
        return "La partita IVA non è valida:\n il codice di controllo non corrisponde.\n";
    return '';
}
 
function CheckCF(cf)
{
    var validi, i, s, set1, set2, setpari, setdisp;
    if( cf == '' )  document.getElementById('errore').innerHTML='';
    cf = cf.toUpperCase();
    //In caso di attivazione Partita IVA eliminare la due righe seguenti
    if( cf.length != 16 )
        document.getElementById('errore').innerHTML='<font size=2 color=#FF0000>Attenzione: Per favore inserire un Codice Fiscale valido...</font>'; 
        
    validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    for( i = 0; i < 16; i++ ){
        if( validi.indexOf( cf.charAt(i) ) == -1 )
            document.getElementById('errore').innerHTML='<font size=2 color=#FF0000>Attenzione: Per favore inserire un Codice Fiscale valido...</font>'
    }
    set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
    setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
    s = 0;
    for( i = 1; i <= 13; i += 2 )
        s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
    for( i = 0; i <= 14; i += 2 )
        s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
    if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
         document.getElementById('errore').innerHTML='<font size=2 color=#FF0000>Attenzione: Per favore inserire un Codice Fiscale valido...</font>';
        
    var frstN =document.getElementById("nomeo").value;
    var lstN =document.getElementById("cognomeo").value;
    var chkLn =GetNameParCF(frstN.toUpperCase(), lstN.toUpperCase());
    if (cf.substring(0,3).toUpperCase() !=chkLn)
        document.getElementById('errore').innerHTML="<font size=2 color=#FF0000>Il codice fiscale deve corrispondere ai dati inseriti: <br/> Last Name - Cognome: "+lstN+"<br/>First name - Nome: "+frstN+" .";
    
     document.getElementById('errore').innerHTML='';
}

function GetNameParCF(firstName, lastName)
{
    var strcognome = "";
    var strnome = "";
  // Processa il cognome
  //----------------------------------------------------------------
    for (var i=0; i<lastName.length; i++) 
        {
        
         switch (lastName.charAt(i)) 
            {
              case 'A':
              case 'E':
              case 'I':
              case 'O':
              case 'U': break;            
              default : 
              if((lastName.charAt(i)<='Z')&& (lastName.charAt(i)>'A'))
               strcognome = strcognome + lastName.charAt(i);
            }
        }
   
    if (strcognome.length < 3) 
      {
       for (i=0; i<lastName.length; i++) 
          {
           switch (lastName.charAt(i)) 
             {
              case 'A':
              case 'E':
              case 'I':
              case 'O':
              case 'U': strcognome = strcognome + lastName.charAt(i);
             }
          }
       if (strcognome.length < 3) 
         {
          for (i=strcognome.length; i<=3; i++) 
             { strcognome = strcognome + 'X'; }
         }
      }
   strcognome = strcognome.substring(0,3);
 //------------------------------------------------------------ 



  // processa il nome
  //----------------------------------------------------------------
//    for (i=0; i<firstName.length; i++) 
//       {
//        switch (firstName.charAt(i)) 
//              {
//               case 'A':
//               case 'E':
//               case 'I':
//               case 'O':
//               case 'U': break;
//               default:
// if((firstName.charAt(i)<='Z')&& (firstName.charAt(i)>'A'))
//                  strnome = strnome + firstName.charAt(i);
//              }
//       }
//    if (strnome.length > 3) 
//      {
//        strnome = strnome.substring(0,1) + strnome.substring(2,4);
//      } 
//    else {
//          if (strnome.length < 3) 
//            {
//             for (i=0; i<firstName.length; i++) 
//                {
//                  switch (firstName.charAt(i)) 
//                        {
//                         case 'A':
//                         case 'E':
//                         case 'I':
//                         case 'O':
//                         case 'U': strnome = strnome + firstName.charAt(i);
//                        }
//                }
//             if (strnome.length < 3) 
//               {
//                for (i=strnome.length; i<=3; i++) 
//                   {strnome = strnome + 'X';}
//               }
//            }
//          strnome = strnome.substring(0,3);
//         }
    return strcognome +strnome;
}



function setLayerOpacity(el)
{
    var type="";
    
    if(typeof el.style.opacity != 'undefined')
    {
        type = 'w3c';
    }
    else if(typeof el.style.MozOpacity != 'undefined')
    {
        type = 'moz';
    }
    else if(typeof el.style.KhtmlOpacity != 'undefined')
    {
        type = 'khtml';
    }
    else if(typeof el.filters == 'object')
    {
        type = (el.filters.length > 0 && typeof el.filters.alpha == 'object' && typeof el.filters.alpha.opacity == 'number') ? 'ie' : 'none';
    }
    else
    {
        type = 'none';
    }
    switch(type)
    {
        case 'ie' :
	        el.filters.alpha.opacity = 85;
	        break;
			
        case 'khtml' :
	        el.style.KhtmlOpacity = 0.85;
	        break;
			
        case 'moz' : 
	        el.style.MozOpacity = 0.85;
	        break;
		case 'w3c' :
			el.style.opacity = 0.85;
        default : 
	        //nothing to do
    }
}

function limitInputToTelefNumber(evt)
{
    var charCode = evt.keyCode;
    var strList="+0123456789";
    
    if (charCode==0)
    {
        charCode = evt.which;
    }
    var strChar = String.fromCharCode(charCode);
    if (charCode==8 || charCode==9 || charCode==37 || charCode==39 || charCode==46 || charCode==116 || (strList.indexOf(strChar)!=-1))
    {
        return true;
    }
    else
    {
        return false;
    }

} 

function pause(millisecondi)
{
    var now = new Date();
    var exitTime = now.getTime() + millisecondi;
    while(true)
    {
       now = new Date();
       if(now.getTime() > exitTime) return;
    }  
}

function replaceSpecialChars(myValue)
{
    return myValue.replace("'","\\'").replace('\n', ' ', 'g').replace('\r', ' ', 'g').replace('&', '', 'g').replace('|', '', 'g').replace('%', '', 'g').replace('@', '', 'g').replace('#', '', 'g').replace('\\', '', 'g').replace('+', '%2b', 'g');
}


function max_disp(disqta)
{
	if (document.getElementById("qta").value > disqta) {
		      document.getElementById("msgbox").innerHTML="<font size=\"2\" color=\"#FF0000\">Attenzione: La disponibilità selezionata e maggiore di quella disponibile...</font>"
			  return false;
}
else
{
	document.getElementById("msgbox").innerHTML="";	
	return true;	
}
}
function verifica_data(input)
{
var regex = new RegExp("[/-]");
var date = input.split(regex);
var giorni = new Array('',31,28,31,30,31,30,31,31,30,31,30,31);
var result = true;
if ( date['0']%4 == 0 && date['0']%100 > 0 || date['0']%400 == 0 )//0
giorni['0'] = 29;

if( isNaN(date['2']) )
result=false;

if ( isNaN(date['1']) || date['1'] > 12 || date['1'] < 1 )
result=false;

if ( isNaN(date['0']) || date['0'] > giorni[Math.round(date['1'])] || date['0'] < 1 )
result=false;

if (!result){
result='';
alert (' Errore nel formato della data: Il formato da inserire è il seguente [giorno/mese/anno] ');
return result;
}
else
{
return input;
}
}
function google_adwords(tipo)
{	
	var temp=tipo.replace(/^\?/,'');
	if(temp !=""){
		show_vetrina(temp);
}
}
function ins_valid()
{
	theForm=document.moduloinvio;
	var bono=true;
	var pag=false;
	if ( bono==true && theForm.nomec.value.length < 1) {
		    
	         bono=false;
	      }
	if (bono==true && theForm.cognomec.value.length < 1) {
		    
	         bono=false;
	      }
	if (bono==true && theForm.telefonoc.value.length < 1) {
		     
	         bono=false;
	      }
	if (bono==true && theForm.provinciac.value.length < 1) {
		     
	         bono=false;
	      }  
		  if (bono==true && theForm.cittac.value.length < 1) {
		     
	         bono=false;
	      }  
		  if (bono==true && theForm.capc.value.length < 1) {
		     
	         bono=false;
	      }  
		   if (bono==true && theForm.indirizzoc.value.length < 1) {
		     
	         bono=false;
	      }  
		  if ( bono==true && theForm.nomeo.value.length < 1) {
		     
	         bono=false;
	      }
	if (bono==true && theForm.cognomeo.value.length < 1) {
		    
	         bono=false;
	      }
	if (bono==true && theForm.telefonoo.value.length < 1) {
		     
	         bono=false;
	      }
	if (bono==true && theForm.provinciao.value.length < 1) {
		     
	         bono=false;
	      }  
		  if (bono==true && theForm.cittao.value.length < 1) {
		     
	         bono=false;
	      }  
		  if (bono==true && theForm.capo.value.length < 1) {
		     
	         bono=false;
	      }  
		   if (bono==true && theForm.indirizzoo.value.length < 1) {
		    
	         bono=false;
	      }  
		  		   if (bono==true && theForm.codfiscale.value.length < 1) {
		    
	         bono=false;
	      }  
		  if (bono==true && theForm.email.value.length < 1) {
		    
	         bono=false;
	      }  
		   if (bono==true && theForm.privacy.checked==false) {
		    
	         bono=false;
	      }  
		   if (bono==true && theForm.contrassegno.checked==false & theForm.paypal.checked==false & theForm.postpay.checked==false & theForm.vaglia.checked==false & theForm.bonifico.checked==false) {		    
	         bono=false;
			 pag=true;
	      } 
		  	
	if (bono==false) 
	{
		if(!pag)
		{
	document.getElementById('errore').innerHTML='<font size=2 color=#FF0000>Attenzione: Verificare che tutti i campi richiesti siano completi e la privacy accettata...</font>';
		}
		else
		{
			document.getElementById('errore').innerHTML='<font size=2 color=#FF0000>Attenzione: Selezionare il tipo di pagamento...</font>';
		}
	}
	else
	{
	theForm.submit();
	}
}
function maximize()
{
top.window.moveTo(0,0);
if (document.all) {
top.window.resizeTo(screen.availWidth,screen.availHeight);
}
else if (document.layers||document.getElementById) {
if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
top.window.outerHeight = screen.availHeight;
top.window.outerWidth = screen.availWidth;
}
}
}