

function SwitchSizePhotoEd(sizetxt, nometxt, prz, swidth, sheight)
{
    if (document.getElementById('small')) {document.getElementById('small').style.border = ""; document.getElementById('small').style.width = "280px"; }
    if (document.getElementById('medium')) {document.getElementById('medium').style.border = ""; document.getElementById('medium').style.width = "280px"; }
    if (document.getElementById('large')) {document.getElementById('large').style.border = ""; document.getElementById('large').style.width = "280px"; }
    if (document.getElementById(sizetxt)) {document.getElementById(sizetxt).style.border = "2px solid #6C0000"; document.getElementById(sizetxt).style.width = "276px"; }
    
    if (document.getElementById('size_acq')) 
    {
            var row_to_insert;
            row_to_insert = "<div style='width:280px; background-color:#e9e9e9;'>";
            row_to_insert +="<div style='float:left; width:197px; border-right: solid 3px #ffffff'><div style='padding-top:5px; padding-bottom:5px; padding-left:5px; padding-right:px;'><b>Formato " + sizetxt.toUpperCase() + "</b><br /><span style='font-style:italic'>" + nometxt + "</span></div></div>";
            row_to_insert +="<div style='float:left; width:80px; text-align:right; white-space: nowrap;  '><div style='padding-top:5px; padding-bottom:5px; padding-right:5px; font-weight:bold; font-size:13px; '> " + prz + " &euro;</div></div>";
            row_to_insert +="<div style='clear:both; width:280px; background-color: #ffffff; height:1px; overflow:hidden; font-size:1px;'></div>";
            row_to_insert +="</div>";
            row_to_insert +="<div style='clear:both; width:280px; height:3px; overflow:hidden; font-size:1px;'></div>";
            $('#size_acq').html(row_to_insert);
            if (document.getElementById('formato_sel')) document.getElementById('formato_sel').value = sizetxt;
            if (document.getElementById('formato_price_sel')) document.getElementById('formato_price_sel').value = prz;
            if (document.getElementById('formato_width_sel')) document.getElementById('formato_width_sel').value = swidth;
            if (document.getElementById('formato_height_sel')) document.getElementById('formato_height_sel').value = sheight;
    }
    
    //Draw Cornice
    DrawCornice();
    
    //Ricalcolo Totale
    TotCartPhotoEdition();
    
}

function TotCornicePrice()
{
    if (isNaN(document.getElementById('cornice_sel').value) == true) return 0; 
    if (document.getElementById('cornice_sel').value == '0') return 0;
    if (isNaN(document.getElementById('cornice_price_sel').value) == true) return 0;
    if (document.getElementById('cornice_price_sel').value == '0') return 0;
    if (isNaN(document.getElementById('formato_width_sel').value) == true) return 0;
    if (document.getElementById('formato_width_sel').value == '0') return 0;
    if (isNaN(document.getElementById('formato_height_sel').value) == true) return 0;
    if (document.getElementById('formato_height_sel').value == '0') return 0;   
    
    var price_cornice = parseFloat(document.getElementById('cornice_price_sel').value);
    var width_cornice = parseFloat(document.getElementById('formato_width_sel').value);
    var height_cornice = parseFloat(document.getElementById('formato_height_sel').value);
    return Math.ceil(((price_cornice * width_cornice)*2) + ((price_cornice * height_cornice)*2));
    
}


function HideAllSchedeCornici()
{
    
    $("#all_schede_cornici").children().each(function(index) {
        $(this).css({'display': 'none'});
    });

    
    $('#all_small_cornici img').each(function(index) {
        $(this).css({'border': '0'});
    });

}

function DrawCornice()
{
    var width_cm = 0;
    var height_cm = 0;
    var width_px = 0;
    var height_px = 0;
    //Resetto Opera
    if (document.getElementById('original_img_width')) width_px = document.getElementById('original_img_width').value;
    if (document.getElementById('original_img_height')) height_px = document.getElementById('original_img_height').value;


    if(document.getElementById('cornice_spessore_sel').value == '0') {
        $('#preview_cornice').css({'width' : width_px + 'px', 'height' : height_px + 'px', 'border': '0'});
        $('#preview_passpartou').css({'width' : width_px + 'px', 'height' : height_px + 'px', 'border': '0'});
        $('#preview_photo').width(width_px + 'px');
        $('#preview_photo').height(height_px + 'px');
         return;
    }
    if (document.getElementById('formato_width_sel')) width_cm = document.getElementById('formato_width_sel').value;
    if (document.getElementById('formato_height_sel')) height_cm = document.getElementById('formato_height_sel').value;
    if (document.getElementById('original_img_width')) width_px = document.getElementById('original_img_width').value;
    if (document.getElementById('original_img_height')) height_px = document.getElementById('original_img_height').value;
    
    var border_cm = 0;
    var border_color = '';
    if (document.getElementById('cornice_spessore_sel')) border_cm = document.getElementById('cornice_spessore_sel').value;
    if (document.getElementById('cornice_hexcolor_sel')) border_color = document.getElementById('cornice_hexcolor_sel').value;    
    
    var border_px = 0;
    if(width_px > height_px)
        border_px = parseInt((parseFloat(width_px) * parseFloat(border_cm))/ parseFloat(width_cm), 10);
    else
        border_px = parseInt((parseFloat(height_px) * parseFloat(border_cm))/ parseFloat(height_cm), 10);
        
    var passpartou_cm = 0;
    var passpartou_color = '';
    if (document.getElementById('passpartou_spessore_sel')) passpartou_cm = document.getElementById('passpartou_spessore_sel').value;
    if (document.getElementById('passpartou_hexcolor_sel')) passpartou_color = document.getElementById('passpartou_hexcolor_sel').value;
    
    var passpartou_px = 0;
    if(width_px > height_px)
        passpartou_px = parseInt((parseFloat(width_px) * parseFloat(passpartou_cm))/ parseFloat(width_cm), 10);
    else
        passpartou_px = parseInt((parseFloat(height_px) * parseFloat(passpartou_cm))/ parseFloat(height_cm), 10);
  
    
    
    //nuove dimensioni immagine
    var single_border_cornice = parseInt((border_px/2), 10);
    var single_border_passpartou = parseInt((passpartou_px/2), 10);
    $('#preview_photo').width((width_px - ((single_border_cornice*2) + (single_border_passpartou * 2))) + 'px');
    $('#preview_photo').height((height_px - ((single_border_cornice*2) + (single_border_passpartou * 2))) + 'px');
    $('#preview_cornice').css({'width' :  (width_px - (single_border_cornice*2)) + 'px','height': (height_px - (single_border_cornice*2)) +'px', 'border':  single_border_cornice + 'px solid ' + border_color});
    $('#preview_passpartou').css({'width' : ((width_px - (single_border_cornice*2)) - (single_border_passpartou*2)) + 'px','height' : ((height_px - (single_border_cornice*2)) - (single_border_passpartou*2)) + 'px', 'border':  single_border_passpartou + 'px solid ' + passpartou_color});
    
}

function SwitchCornicePhotoEd(idcornice, nome_cornice, hex_color, spessore_cm, prz_cmlineare)
{
    HideAllSchedeCornici();
    if (document.getElementById("cornice" + idcornice))  document.getElementById("cornice" + idcornice).style.display = '';
    if (document.getElementById("imgsmall" + idcornice)) document.getElementById("imgsmall" + idcornice).style.border = "2px solid #6C0000";
    if (document.getElementById("cornice_sel")) document.getElementById("cornice_sel").value = idcornice;
    if (document.getElementById("cornice_price_sel")) document.getElementById("cornice_price_sel").value = prz_cmlineare;
    if (document.getElementById("cornice_spessore_sel")) document.getElementById("cornice_spessore_sel").value = spessore_cm;
    if (document.getElementById("cornice_hexcolor_sel")) document.getElementById("cornice_hexcolor_sel").value = hex_color;
    
    if (document.getElementById("cornice_acq")) $('#cornice_acq').replaceWith("");
    if (document.getElementById("cornicespacer_acq")) $('#cornicespacer_acq').replaceWith("");
    if (idcornice != '0')
    {
        row_to_insert = "<div id='cornice_acq' style='width:280px; background-color:#e9e9e9;'>";
        row_to_insert +="<div style='float:left; width:197px; border-right: solid 3px #ffffff'><div style='padding-top:5px; padding-bottom:5px; padding-left:5px; padding-right:px;'><b>Cornice</b><br /><span style='font-style:italic'>" + nome_cornice + "</span></div></div>";
        row_to_insert +="<div style='float:left; width:80px; text-align:right; white-space: nowrap;  '><div style='padding-top:5px; padding-bottom:5px; padding-right:5px; font-weight:bold; font-size:13px; '><span id='corniceprice_acq'>" + TotCornicePrice() + "</span> &euro;</div></div>";
        row_to_insert +="<div style='clear:both; width:280px; background-color: #ffffff; height:1px; overflow:hidden; font-size:1px;'></div>";
        row_to_insert +="</div>";
        row_to_insert +="<div id='cornicespacer_acq' style='clear:both; width:280px; height:3px; overflow:hidden; font-size:1px;'></div>";
        $('#opz_acq').append(row_to_insert);       
    }
    else
    {
        //Tolgo anche il vetro
        if (document.getElementById('sel_vetro')) 
        { 
            cmbvetro = document.getElementById('sel_vetro'); 
            cmbvetro[0].selected = true; 
            idvetro = '0';
            if(document.getElementById("vetro_sel")) document.getElementById("vetro_sel").value = idvetro;
            if(document.getElementById("vetro_price_sel")) document.getElementById("vetro_price_sel").value = '0';
    
            if(document.getElementById("vetro_acq")) $('#vetro_acq').replaceWith("");
            if(document.getElementById("vetrospacer_acq")) $('#vetrospacer_acq').replaceWith("");
        }
        
        //Tolgo anche il passpartou
        if (document.getElementById("passpartou_sel"))
        {
            idpasspartou = '0';
            HideAllSchedePasspartou();
            if (document.getElementById("passpartou" + idpasspartou))  document.getElementById("passpartou" + idpasspartou).style.display = '';
            if (document.getElementById("imgpass" + idpasspartou)) document.getElementById("imgpass" + idpasspartou).style.border = "2px solid #6C0000";
            if (document.getElementById("passpartou_sel")) document.getElementById("passpartou_sel").value = idpasspartou;
            if (document.getElementById("passpartou_price_sel")) document.getElementById("passpartou_price_sel").value = '0';
            if (document.getElementById("passpartou_spessore_sel")) document.getElementById("passpartou_spessore_sel").value = '0';
            if (document.getElementById("passpartou_hexcolor_sel")) document.getElementById("passpartou_hexcolor_sel").value = '';
            
            if (document.getElementById("passpartou_acq")) $('#passpartou_acq').replaceWith("");
            if (document.getElementById("passpartouspacer_acq")) $('#passpartouspacer_acq').replaceWith("");
        }
    }
    
    //Draw Cornice
    DrawCornice();
    
    //Ricalcolo Totale
    TotCartPhotoEdition();
}

function ChangeCarta()
{
    var cmbcarta;
    if (document.getElementById('sel_carta'))
    {
        cmbcarta = document.getElementById('sel_carta');
        SwitchCartaPhotoEd(cmbcarta.value, cmbcarta.options[cmbcarta.selectedIndex].text, arr_carta_price[cmbcarta.value]);
         
    }
}

function SwitchCartaPhotoEd(idcarta, nome_carta, prz_carta)
{
    HideAllSchedeCarta();
    if (document.getElementById("carta" + idcarta))  document.getElementById("carta" + idcarta).style.display = '';
    if(document.getElementById("carta_sel")) document.getElementById("carta_sel").value = idcarta;
    if(document.getElementById("carta_price_sel")) document.getElementById("carta_price_sel").value = prz_carta;
    
    if(document.getElementById("carta_acq")) $('#carta_acq').replaceWith("");
    if(document.getElementById("cartaspacer_acq")) $('#cartaspacer_acq').replaceWith("");
    if (idcarta != '0')
    {
        row_to_insert = "<div id='carta_acq' style='width:280px; background-color:#e9e9e9;'>";
        row_to_insert +="<div style='float:left; width:197px; border-right: solid 3px #ffffff'><div style='padding-top:5px; padding-bottom:5px; padding-left:5px; padding-right:px;'><b>Carta</b><br /><span style='font-style:italic'>" + nome_carta + "</span></div></div>";
        row_to_insert +="<div style='float:left; width:80px; text-align:right; white-space: nowrap;  '><div style='padding-top:5px; padding-bottom:5px; padding-right:5px; font-weight:bold; font-size:13px; '><span id='cartaprice_acq'>" + prz_carta + "</span> &euro;</div></div>";
        row_to_insert +="<div style='clear:both; width:280px; background-color: #ffffff; height:1px; overflow:hidden; font-size:1px;'></div>";
        row_to_insert +="</div>";
        row_to_insert +="<div id='cartaspacer_acq' style='clear:both; width:280px; height:3px; overflow:hidden; font-size:1px;'></div>";
        $('#opz_acq').append(row_to_insert);   
    }
    
    //Ricalcolo Totale
    TotCartPhotoEdition();
}

function HideAllSchedePasspartou()
{
    
    $("#all_schede_passpartou").children().each(function(index) {
        $(this).css({'display': 'none'});
    });
    
    $('#all_small_passpartou img').each(function(index) {
        $(this).css({'border': '0'});
    });

}

function HideAllSchedeCarta()
{
    
    $("#all_schede_carta").children().each(function(index) {
        $(this).css({'display': 'none'});
    });

}

function HideAllSchedeVetro()
{
    
    $("#all_schede_vetro").children().each(function(index) {
        $(this).css({'display': 'none'});
    });

}

function SwitchPasspartouPhotoEd(idpasspartou, nome_passpartou, hex_color, spessore_cm, prz_tot)
{
    //Puoi scegliere il passpartou solo con la cornice
    if(document.getElementById("cornice_sel"))
    {
        if (document.getElementById("cornice_sel").value == '0')
        {
            buildAlert('/images/fieldErr.png', "Il passepartout e\' acquistabile solo in abbinamento ad una cornice!", 450, 190 ); 
            buildOverlayAlert(); 
            $(window).scroll(function(){ CustomCenter(); });
            return false;
        }
    }
    
    HideAllSchedePasspartou();
    if (document.getElementById("passpartou" + idpasspartou))  document.getElementById("passpartou" + idpasspartou).style.display = '';
    if (document.getElementById("imgpass" + idpasspartou)) document.getElementById("imgpass" + idpasspartou).style.border = "2px solid #6C0000";
    if (document.getElementById("passpartou_sel")) document.getElementById("passpartou_sel").value = idpasspartou;
    if (document.getElementById("passpartou_price_sel")) document.getElementById("passpartou_price_sel").value = prz_tot;
    if (document.getElementById("passpartou_spessore_sel")) document.getElementById("passpartou_spessore_sel").value = spessore_cm;
    if (document.getElementById("passpartou_hexcolor_sel")) document.getElementById("passpartou_hexcolor_sel").value = hex_color;
    
    if (document.getElementById("passpartou_acq")) $('#passpartou_acq').replaceWith("");
    if (document.getElementById("passpartouspacer_acq")) $('#passpartouspacer_acq').replaceWith("");
    if (idpasspartou != '0')
    {
        row_to_insert = "<div id='passpartou_acq' style='width:280px; background-color:#e9e9e9;'>";
        row_to_insert +="<div style='float:left; width:197px; border-right: solid 3px #ffffff'><div style='padding-top:5px; padding-bottom:5px; padding-left:5px; padding-right:px;'><b>Passepartout</b><br /><span style='font-style:italic'>" + nome_passpartou + "</span></div></div>";
        row_to_insert +="<div style='float:left; width:80px; text-align:right; white-space: nowrap;  '><div style='padding-top:5px; padding-bottom:5px; padding-right:5px; font-weight:bold; font-size:13px; '><span id='passpartouprice_acq'>" + prz_tot + "</span> &euro;</div></div>";
        row_to_insert +="<div style='clear:both; width:280px; background-color: #ffffff; height:1px; overflow:hidden; font-size:1px;'></div>";
        row_to_insert +="</div>";
        row_to_insert +="<div id='passpartouspacer_acq' style='clear:both; width:280px; height:3px; overflow:hidden; font-size:1px;'></div>";
        $('#opz_acq').append(row_to_insert);
    }
    
    //Draw Cornice
    DrawCornice();
    
    //Ricalcolo Totale
    TotCartPhotoEdition();
}

function ChangeVetro()
{
    var cmbvetro;
    if (document.getElementById('sel_vetro'))
    {
        cmbvetro = document.getElementById('sel_vetro');
        return SwitchVetroPhotoEd(cmbvetro.value, cmbvetro.options[cmbvetro.selectedIndex].text, arr_vetro_price[cmbvetro.value]);
         
    }
    return true;
}

function SwitchVetroPhotoEd(idvetro, nome_vetro, prz_vetro)
{
    //Puoi scegliere il vetro solo con la cornice
    if(document.getElementById("cornice_sel"))
    {
        if (document.getElementById("cornice_sel").value == '0')
        {
            cmbvetro = document.getElementById('sel_vetro'); 
            cmbvetro[0].selected = true;
            buildAlert('/images/fieldErr.png', "Il vetro e\' acquistabile solo in abbinamento ad una cornice!", 450, 190 ); 
            buildOverlayAlert(); 
            $(window).scroll(function(){ CustomCenter(); });
            return false;
        }
    }
    HideAllSchedeVetro();
    if (document.getElementById("vetro" + idvetro))  document.getElementById("vetro" + idvetro).style.display = '';
    if(document.getElementById("vetro_sel")) document.getElementById("vetro_sel").value = idvetro;
    if(document.getElementById("vetro_price_sel")) document.getElementById("vetro_price_sel").value = prz_vetro;
    
    if(document.getElementById("vetro_acq")) $('#vetro_acq').replaceWith("");
    if(document.getElementById("vetrospacer_acq")) $('#vetrospacer_acq').replaceWith("");
    if (idvetro != '0')
    {
        row_to_insert = "<div id='vetro_acq' style='width:280px; background-color:#e9e9e9;'>";
        row_to_insert +="<div style='float:left; width:197px; border-right: solid 3px #ffffff'><div style='padding-top:5px; padding-bottom:5px; padding-left:5px; padding-right:px;'><b>Vetro</b><br /><span style='font-style:italic'>" + nome_vetro + "</span></div></div>";
        row_to_insert +="<div style='float:left; width:80px; text-align:right; white-space: nowrap;  '><div style='padding-top:5px; padding-bottom:5px; padding-right:5px; font-weight:bold; font-size:13px; '><span id='vetroprice_acq'>" + TotVetroPrice() + "</span> &euro;</div></div>";
        row_to_insert +="<div style='clear:both; width:280px; background-color: #ffffff; height:1px; overflow:hidden; font-size:1px;'></div>";
        row_to_insert +="</div>";
        row_to_insert +="<div id='vetrospacer_acq' style='clear:both; width:280px; height:3px; overflow:hidden; font-size:1px;'></div>";
        $('#opz_acq').append(row_to_insert);   
    }
    
    //Ricalcolo Totale
    TotCartPhotoEdition();
    return true;
}

function TotVetroPrice()
{
    if (isNaN(document.getElementById('vetro_sel').value) == true) return 0; 
    if (document.getElementById('vetro_sel').value == '0') return 0;
    if (isNaN(document.getElementById('vetro_price_sel').value) == true) return 0;
    if (document.getElementById('vetro_price_sel').value == '0') return 0;
    if (isNaN(document.getElementById('formato_width_sel').value) == true) return 0;
    if (document.getElementById('formato_width_sel').value == '0') return 0;
    if (isNaN(document.getElementById('formato_height_sel').value) == true) return 0;
    if (document.getElementById('formato_height_sel').value == '0') return 0;   
    
    var price_vetro = parseFloat(document.getElementById('vetro_price_sel').value);
    var width_formato = parseFloat(document.getElementById('formato_width_sel').value);
    var height_formato = parseFloat(document.getElementById('formato_height_sel').value);
    return Math.ceil(price_vetro * (width_formato * height_formato));
    
}



function TotCartPhotoEdition()
{
    var totprice_formato = 0;
    var totprice_cornice = 0;
    var totprice_carta = 0;
    var totprice_vetro = 0;
    var totprice_passpartou = 0;
    
    //Formato
    if(document.getElementById('formato_price_sel'))
     {
        if(!isNaN(document.getElementById('formato_price_sel').value))
        {
            totprice_formato = Math.ceil(parseFloat(document.getElementById('formato_price_sel').value));
        }
     }
     
     //Cornice
     totprice_cornice = TotCornicePrice();
     if (document.getElementById('corniceprice_acq'))  $('#corniceprice_acq').html(totprice_cornice);
     
     //Carta
     if(document.getElementById('carta_price_sel'))
     {
        if(!isNaN(document.getElementById('carta_price_sel').value))
        {
            totprice_carta = Math.ceil(parseFloat(document.getElementById('carta_price_sel').value));
        }
     }
     
     //Passpartou
     if(document.getElementById('passpartou_price_sel'))
     {
        if(!isNaN(document.getElementById('passpartou_price_sel').value))
        {
            totprice_passpartou = Math.ceil(parseFloat(document.getElementById('passpartou_price_sel').value));
        }
     }
     
     //Vetro
     totprice_vetro = TotVetroPrice();
     if (document.getElementById('vetroprice_acq'))  $('#vetroprice_acq').html(totprice_vetro);
     
     
     if (document.getElementById('totacq_cart'))
      $('#totacq_cart').html(totprice_formato + totprice_cornice + totprice_carta + totprice_vetro + totprice_passpartou);
}


function AddCartPe(idart)
{   
    var allselacc = "";
    if(document.getElementById('formato_sel'))
    {
        switch(document.getElementById('formato_sel').value)
        {
            case "small":
                allselacc += "|S";
                break;
            case "medium":
                allselacc += "|M";
                break;
            case "large":
                allselacc += "|L";
                break;
            default:
                allselacc += "|S";
        }
    }
    
    //<IDOPERA>|(S|M|L)|<IDCARTA>|<IDCORNICE>|<IDPASSPARTOU>|<IDVETRO>
    if (document.getElementById('carta_sel'))
    {
        if(isNaN(document.getElementById('carta_sel').value))
            allselacc += "|0"
        else
            allselacc += "|" + document.getElementById('carta_sel').value
    }
    else
        allselacc += "|0"
        
    
    if (document.getElementById('cornice_sel'))
    {
        if(isNaN(document.getElementById('cornice_sel').value))
            allselacc += "|0"
        else
            allselacc += "|" + document.getElementById('cornice_sel').value
    }
    else
        allselacc += "|0"
    
    if (document.getElementById('passpartou_sel'))
    {
        if(isNaN(document.getElementById('passpartou_sel').value))
            allselacc += "|0"
        else
            allselacc += "|" + document.getElementById('passpartou_sel').value
    }
    else
        allselacc += "|0"
    
    if (document.getElementById('vetro_sel'))
    {
        if(isNaN(document.getElementById('vetro_sel').value))
            allselacc += "|0"
        else
            allselacc += "|" + document.getElementById('vetro_sel').value
    }
    else
        allselacc += "|0"

    
    params = "idart=" + idart + allselacc + "&idtip=4&rnd=" + randomString();
    //$("body").append(params);
    //return;
    $.ajax({
        type: "GET",
        url: "addcart.aspx",
        data: params,
        //timeout: 10000,  //10 secondi
		success: function(msg){
            arr_msg = msg.split("|"); 
			if(arr_msg[0] != "OK") {CartError(arr_msg[1]); return false;}
		    setTimeout("successStep('1')", 2000);
		},
		beforeSend: function(xmlobj){
		    buildAlert('/images/cartOK.png', "Aggiungo il prodotto al carrello ...", 450, 130 ); 
            buildOverlayAlert(); 
            $(window).scroll(function(){ CustomCenter(); });
            $('#my_close').css({'visibility': 'hidden'});
		},
		error: function(xmlobj, msg, errobj) {
		    $('#my_close').css({'visibility': 'visible'});
		    $('#my_error').html('<img src="/images/cartKO.png" border="0" /><br /><br />Non e\' stato possibile aggiungere il prodotto al carrello');
		} 
    
    
    });
        
}





function SubmitArtCol(idpag, firstlett)
{
       var sgoto ="/artista.aspx?id=" + idpag;
       if (firstlett != "") sgoto = sgoto + "&let=" + firstlett;
       sgoto = sgoto + "&sc=" + document.getElementById("src_col").value;
       window.location.href = sgoto;
}

function SubmitArtPeCol(idpag, firstlett)
{
       var sgoto ="/artistape.aspx?id=" + idpag;
       if (firstlett != "") sgoto = sgoto + "&let=" + firstlett;
       sgoto = sgoto + "&sc=" + document.getElementById("src_col").value;
       window.location.href = sgoto;
}

  function externallinks()
    {
    var c=document.body;
    if(c)
    {
        var ls=c.getElementsByTagName('a');
        for(var i=0;i<ls.length;i++){
            if(ls[i].getAttribute('rel')=='external')
            {
                ls[i].className+=ls[i].className?' extlink':'extlink';
                ls[i].title+=' (opens in new window)';
                ls[i].onclick=function(){window.open(this.href);return false}
            }
        }
    }
   }

function LogOut()
{
    var frm = document.getElementById('aspnetForm')
    frm.action = "/logout.aspx";
    frm.submit();
}

function ShowInfo(id) {
    var  iheight = $('#info_over' + id).height();
    imiddlepos = parseInt(iheight / 2, 10) - 6;
    $('#info_over' + id).css({"display":"block", "top" : -imiddlepos});
    $('#row_over' + id).css({"display": "block" });
}

function HideInfo(id) {

    $('#info_over' + id).css({"display": "none"});
    $('#row_over' + id).css({"display":"none"});

}

   var focusedlogin = false;
   var focusedartista = false;
   var focusedlibri = false;
   
$(window).load( function() { 
       if(document.getElementById("usrtop"))
       {
            document.getElementById("usrtop").onfocus=function() {
            focusedlogin=true;
            };
            document.getElementById("usrtop").onblur=function() {
            focusedlogin=false;
            };
       }
       
       if(document.getElementById("pwdtop"))
       {
            document.getElementById("pwdtop").onfocus=function() {
            focusedlogin=true;
            };
            document.getElementById("pwdtop").onblur=function() {
            focusedlogin=false;
            };
       }
       
       if(document.getElementById("artnome"))
       {
            document.getElementById("artnome").onfocus=function() {
            focusedartista=true;
            };
            document.getElementById("artnome").onblur=function() {
            focusedartista=false;
            };
       }
       
       if(document.getElementById("libnome"))
       {
            document.getElementById("libnome").onfocus=function() {
            focusedlibri=true;
            };
            document.getElementById("libnome").onblur=function() {
            focusedlibri=false;
            };
       }
       
       if(document.getElementById("libedit"))
       {
            document.getElementById("libedit").onfocus=function() {
            focusedlibri=true;
            };
            document.getElementById("libedit").onblur=function() {
            focusedlibri=false;
            };
       }
       
   });
    
    
	document.onkeydown = checkKeycode  
    function checkKeycode(e) {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    
        if (keycode == 13 && focusedlogin == true)
        {
            if (typeof SubmitLogin == "function") SubmitLogin();
            return;
        }
        
        if (keycode == 13 && focusedartista == true)
        {
            if (typeof submitArtSearch == "function") submitArtSearch();
            return;
        }
        
        if(keycode == 13 && focusedlibri == true)
        {
            if (typeof submitLibSearch == "function") submitLibSearch()();
            return;
        }
        
   
    return true;
}

var buildAlert = function(imageTodisplay, textTodisplay, cWidth, cHeight) {
$('body').append('<div class="CustomPopin"><div id="my_close" style="padding-top:6px; text-align:right; padding-right:6px; display:none;"><a href="#" onclick="closePopin(); return false;" title="Chiudi"><img src="/images/b_close.gif" border="0" /><\/a><\/div><div class="CustomContent"><div id="my_error" style="text-align:center; font-weight:bold;"><img src="' + imageTodisplay + '" border="0" /><br /><br />' + textTodisplay + '<\/div><div class="CustomContent-container"><\/div><\/div><\/div>');
$c = $('.CustomPopin .CustomContent .CustomContent-container'); 

var scrollPos = CustomScroll();

				cpopinWidth = 250;
				cpopinHeight =  100;
				if (!isNaN(cWidth) && cWidth >= cpopinWidth) cpopinWidth = cWidth;
				if (!isNaN(cHeight) && cHeight >= cpopinHeight) cpopinHeight = cHeight;
				$c.parent().parent().find('#my_close').show();
				$('.CustomPopin').width(cpopinWidth).height(cpopinHeight).css({
					'top': ($(window).height()/2) + scrollPos['scrollTop'] - (cpopinHeight/2),
					'left': ($(window).width()/2) + scrollPos['scrollLeft'] - (cpopinWidth/2)
				}).show().fadeIn(1000);
		
};


var closePopin = function() {
		$('#overlay').fadeOut(1000,function(){ $(this).remove(); });
		$('.CustomPopin').fadeOut(1000,function(){ $(this).remove(); });
		if(typeof ExtendClose == 'function') ExtendClose(); 
};

		
var buildOverlayAlert = function() {
				$('body').append('<div id="overlay"><\/div>');
				$('#overlay').css('height',$(document).height());
				$('#overlay').css('opacity',0).fadeTo(1000, 0.5);
			
			};
			
function CustomScroll(){
			scrollTop = $(window).scrollTop();
			scrollLeft = window.pageXOffset || document.documentElement.scrollLeft || 0;
			return {scrollTop:scrollTop,scrollLeft:scrollLeft};
};

function CustomCenter() {
			if(!$('.CustomPopin')) return;
			var scrollPos = CustomScroll();

			if($.browser.opera) {
				windowHeight = window.innerHeight;
				windowWidth = window.innerWidth;
			}else{
				windowHeight = $(window).height();
				windowWidth = $(window).width();
			};

			projectedTop = ($(window).height()/2) + scrollPos['scrollTop'] - ($('.CustomPopin').height()/2);
			if(projectedTop < 0) {
				projectedTop = 10;
				_followScroll = false;
			}else{
				_followScroll = true;
			};

			$('.CustomPopin').css({
				'top': projectedTop,
				'left': ($(window).width()/2) + scrollPos['scrollLeft'] - ($('.CustomPopin').width()/2)
			});	
};

function AdjustLineOpere()
{
			kn = 0;
			max_piece_height = 0;
			while(kn <= 100)
			{
				if(document.getElementById('operatxt' +  kn))
				{
					if( max_piece_height < $('#operatxt' + kn).height()) max_piece_height = $('#operatxt' + kn).height();
				}
				else
				    break;
				kn++;
			}
			
		    kn = 0;
		    while(kn <= 100)
			{
				if(document.getElementById('operatxt' +  kn))
					$('#operatxt' + kn).height(max_piece_height);
				else
				    break;
				kn++;
			}
}

function AdjustLinePrimoPiano()
{
			kn = 0;
			max_piece_height = 0;
			while(kn <= 100)
			{
				if(document.getElementById('primopiano' +  kn))
				{
					if( max_piece_height < $('#primopiano' + kn).height()) max_piece_height = $('#primopiano' + kn).height();
				}
				else
				    break;
				kn++;
			}
			
		    kn = 0;
		    while(kn <= 100)
			{
				if(document.getElementById('primopiano' +  kn))
					$('#primopiano' + kn).height(max_piece_height);
				else
				    break;
				kn++;
			}
}


function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 10;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

function CleanUser()
{
    if( $('#usrtop').val() == "Username") $('#usrtop').val("");
}

function CleanPwd()
{
    if( $('#pwdtop').val() == "Password") $('#pwdtop').val("");
}

function SubmitLogin()
{
    var frm = document.getElementById("aspnetForm");
    if (frm.usrtop.value == "")
    {
          buildAlert('/images/fieldErr.png', "Devi inserire una username", 450, 130 ); 
          buildOverlayAlert(); 
          $(window).scroll(function(){ CustomCenter(); });
          return false;
    }
    
    if (frm.pwdtop.value == "")
    {
          buildAlert('/images/fieldErr.png', "Devi inserire una password", 450, 130 ); 
          buildOverlayAlert(); 
          $(window).scroll(function(){ CustomCenter(); });
          return false;
    }
    
    frm.action = "/login.aspx";
    frm.submit();
    return false;
}

function submitSearch(lang)
{
            var urlredir = "";
            urlredir += "/Ricerca-tra-le-opere_opsc_19_2_0_1_0_0";
            
            if ($('#collezione').val() != "") 
                urlredir += "_" +$('#collezione').val();
            else
                urlredir += "_0";
            
            if ($('#anno').val() != "") 
                urlredir += "_" + $('#anno').val();
            else
                urlredir += "_0";
            
            if($('#prezzo').val() != "")
                urlredir += "_" + $('#prezzo').val();
            else
                urlredir += "_0";
               
            urlredir += "_" + lang + ".aspx";
            
            window.location.href = urlredir;
            
}

function LogOut()
{
    var frm = document.getElementById('aspnetForm')
    frm.action = "/logout.aspx";
    frm.submit();
}

function AddCartLock()
{
    buildAlert('/images/cartKO.png', "Per poter acquistare e\' necessario<br />essere registrati ed effettuare il login!", 450, 150 ); 
    buildOverlayAlert(); 
    $(window).scroll(function(){ CustomCenter(); });
    return false;
}

function successStep(idstep)
{
    switch(idstep)
    {
        case "1":
            $('#my_error').html('<img src="/images/CartAdd.png" border="0" /><br /><br />Il prodotto e\' stato aggiunto al carrello');
            setTimeout("successStep('2')", 2000);
            break;
        case "2":
            $('#overlay').fadeOut(1000, function(){ $(this).remove(); });
            $('.CustomPopin').fadeOut(1000, function(){ $(this).remove(); });
            break;
    }

}

function CartError(msg)
{
    $('#my_close').css({'visibility': 'visible'});
    $('#my_error').html('<img src="/images/cartKO.png" border="0" /><br /><br />' +  msg);
}

function AddCartDvd(idart)
{   
    params = "idart=" + idart + "&idtip=3&rnd=" + randomString();
    $.ajax({
        type: "GET",
        url: "addcart.aspx",
        data: params,
        //timeout: 10000,  //10 secondi
		success: function(msg){
            arr_msg = msg.split("|"); 
			if(arr_msg[0] != "OK") {CartError(arr_msg[1]); return false;}
		    setTimeout("successStep('1')", 2000);
		},
		beforeSend: function(xmlobj){
		    buildAlert('/images/cartOK.png', "Aggiungo il prodotto al carrello ...", 450, 130 ); 
            buildOverlayAlert(); 
            $(window).scroll(function(){ CustomCenter(); });
            $('#my_close').css({'visibility': 'hidden'});
		},
		error: function(xmlobj, msg, errobj) {
		    $('#my_close').css({'visibility': 'visible'});
		    $('#my_error').html('<img src="/images/cartKO.png" border="0" /><br /><br />Non e\' stato possibile aggiungere il prodotto al carrello');
		} 
    
    
    });
        
}

function AddCartLibro(idart)
{   
    params = "idart=" + idart + "&idtip=2&rnd=" + randomString();
    $.ajax({
        type: "GET",
        url: "addcart.aspx",
        data: params,
        //timeout: 10000,  //10 secondi
		success: function(msg){
            arr_msg = msg.split("|"); 
			if(arr_msg[0] != "OK") {CartError(arr_msg[1]); return false;}
		    setTimeout("successStep('1')", 2000);
		},
		beforeSend: function(xmlobj){
		    buildAlert('/images/cartOK.png', "Aggiungo il prodotto al carrello ...", 450, 130 ); 
            buildOverlayAlert(); 
            $(window).scroll(function(){ CustomCenter(); });
            $('#my_close').css({'visibility': 'hidden'});
		},
		error: function(xmlobj, msg, errobj) {
		    $('#my_close').css({'visibility': 'visible'});
		    $('#my_error').html('<img src="/images/cartKO.png" border="0" /><br /><br />Non e\' stato possibile aggiungere il prodotto al carrello');
		} 
    
    
    });
        
}

function AddCart(idart)
{   
    var allselacc = "";
    for(m=1; m <= 10; m++)
    {
        if (document.getElementById("acc" + m))
        {
            if ($('#acc' + m + ':checked').val() !== undefined)
            {
                    allselacc += "|" + document.getElementById("opz_id" + m).value;
            }
        }
    }
    
    params = "idart=" + idart + allselacc + "&idtip=1&rnd=" + randomString();

    $.ajax({
        type: "GET",
        url: "addcart.aspx",
        data: params,
        //timeout: 10000,  //10 secondi
		success: function(msg){
            arr_msg = msg.split("|"); 
			if(arr_msg[0] != "OK") {CartError(arr_msg[1]); return false;}
		    setTimeout("successStep('1')", 2000);
		},
		beforeSend: function(xmlobj){
		    buildAlert('/images/cartOK.png', "Aggiungo il prodotto al carrello ...", 450, 130 ); 
            buildOverlayAlert(); 
            $(window).scroll(function(){ CustomCenter(); });
            $('#my_close').css({'visibility': 'hidden'});
		},
		error: function(xmlobj, msg, errobj) {
		    $('#my_close').css({'visibility': 'visible'});
		    $('#my_error').html('<img src="/images/cartKO.png" border="0" /><br /><br />Non e\' stato possibile aggiungere il prodotto al carrello');
		} 
    
    
    });
        
}

function AddWishLock()
{
    buildAlert('/images/fieldErr.png', "Per poter inserire oggetti nella wish list e\'<br />necessario essere registrati ed effettuare il login!", 450, 180 ); 
    buildOverlayAlert(); 
    $(window).scroll(function(){ CustomCenter(); });
    return false;
}

function WishError(msg)
{
    $('#my_close').css({'visibility': 'visible'});
    $('#my_error').html('<img src="/images/fieldErr.png" border="0" /><br /><br />' +  msg);
}

function AddWishDvd(idart)
{   
    params = "iddvd=" + idart + "&rnd=" + randomString();
    $.ajax({
        type: "GET",
        url: "addwish.aspx",
        data: params,
        //timeout: 10000,  //10 secondi
		success: function(msg){
            arr_msg = msg.split("|"); 
			if(arr_msg[0] != "OK") {WishError(arr_msg[1]); return false;}
		    setTimeout("successStepWish('1')", 2000);
		},
		beforeSend: function(xmlobj){
		    buildAlert('/images/wishico.png', "Aggiungo il prodotto alla wish list ...", 450, 130 ); 
            buildOverlayAlert(); 
            $(window).scroll(function(){ CustomCenter(); });
            $('#my_close').css({'visibility': 'hidden'});
		},
		error: function(xmlobj, msg, errobj) {
		    $('#my_close').css({'visibility': 'visible'});
		    $('#my_error').html('<img src="/images/wishico.png" border="0" /><br /><br />Non e\' stato possibile aggiungere il prodotto alla wish list');
		} 
    
    
    });
        
}

function AddWishLibro(idart)
{   
    params = "idlib=" + idart + "&rnd=" + randomString();
    $.ajax({
        type: "GET",
        url: "addwish.aspx",
        data: params,
        //timeout: 10000,  //10 secondi
		success: function(msg){
            arr_msg = msg.split("|"); 
			if(arr_msg[0] != "OK") {WishError(arr_msg[1]); return false;}
		    setTimeout("successStepWish('1')", 2000);
		},
		beforeSend: function(xmlobj){
		    buildAlert('/images/wishico.png', "Aggiungo il prodotto alla wish list ...", 450, 130 ); 
            buildOverlayAlert(); 
            $(window).scroll(function(){ CustomCenter(); });
            $('#my_close').css({'visibility': 'hidden'});
		},
		error: function(xmlobj, msg, errobj) {
		    $('#my_close').css({'visibility': 'visible'});
		    $('#my_error').html('<img src="/images/wishico.png" border="0" /><br /><br />Non e\' stato possibile aggiungere il prodotto alla wish list');
		} 
    
    
    });
        
}

function AddWish(idart)
{   
    params = "idart=" + idart + "&rnd=" + randomString();
    $.ajax({
        type: "GET",
        url: "addwish.aspx",
        data: params,
        //timeout: 10000,  //10 secondi
		success: function(msg){
            arr_msg = msg.split("|"); 
			if(arr_msg[0] != "OK") {WishError(arr_msg[1]); return false;}
		    setTimeout("successStepWish('1')", 2000);
		},
		beforeSend: function(xmlobj){
		    buildAlert('/images/wishico.png', "Aggiungo il prodotto alla wish list ...", 450, 130 ); 
            buildOverlayAlert(); 
            $(window).scroll(function(){ CustomCenter(); });
            $('#my_close').css({'visibility': 'hidden'});
		},
		error: function(xmlobj, msg, errobj) {
		    $('#my_close').css({'visibility': 'visible'});
		    $('#my_error').html('<img src="/images/wishico.png" border="0" /><br /><br />Non e\' stato possibile aggiungere il prodotto alla wish list');
		} 
    
    
    });
        
}

function successStepWish(idstep)
{
    switch(idstep)
    {
        case "1":
            $('#my_error').html('<img src="/images/wishico.png" border="0" /><br /><br />Il prodotto e\' stato aggiunto alla wish list');
            setTimeout("successStepWish('2')", 2000);
            break;
        case "2":
            $('#overlay').fadeOut(1000, function(){ $(this).remove(); });
            $('.CustomPopin').fadeOut(1000, function(){ $(this).remove(); });
            break;
    }

}

function DecheckAll()
{
    for(i=1; i<100; i++)
    {
        if(document.getElementById('acc' + i))
        {
            if (document.getElementById('opz_price' + i) && document.getElementById('opz_type' + i))
            {
                if ($('#opz_price' + i).val() == "0" && $('#opz_type' + i).val() == "1") continue;
                $('#acc' + i).attr("checked", false);
            }
        }
        else
            break;
    }
}

function addproduct(idnum, nome, price, iscornice)
{
    var stype = "";
    stype = "ACCESSORIO"
    if(iscornice) stype = "CORNICE"
    var row_to_insert;
    row_to_insert = "<div id='cartacc" + idnum + "'  style='width:280px; background-color:#e9e9e9;'>";
    row_to_insert +="<div style='float:left; width:197px; border-right: solid 3px #ffffff'><div style='padding-top:5px; padding-bottom:5px; padding-left:5px; padding-right:px;'><b>" + stype + "</b><br /><span style='font-style:italic'>" + nome + "</span></div></div>";
    row_to_insert +="<div style='float:left; width:80px; text-align:right; white-space: nowrap;  '><div style='padding-top:5px; padding-bottom:5px; padding-right:5px; font-weight:bold; font-size:13px; '> " + price + " &euro;</div></div>";
    row_to_insert +="<div style='clear:both; width:280px; background-color: #ffffff; height:1px; overflow:hidden; font-size:1px;'></div>";
    row_to_insert +="</div>";
    row_to_insert +="<div id='cartspace" + idnum + "' style='clear:both; width:280px; height:3px; overflow:hidden; font-size:1px;'></div>";
    
    $('#opz_acq').append(row_to_insert);
    var tot_price = 0;
    var old_price = $('#totacqcart').html();
    old_price = old_price.replace(".", "");
    old_price = old_price.replace(",", ".");
    if (!isNaN(old_price))
    {
        price = price.replace(".", "");
        price = price.replace(",", ".");
        tot_price = Math.round((parseFloat(old_price) + parseFloat(price)) * 100)/100;
        $('#totacqcart').html(String(tot_price).replace(".", ","));
    }
}

function removeproduct(idnum, price)
{
    $('#cartacc' + idnum).replaceWith("");
    $('#cartspace' + idnum).replaceWith("");
    
    var tot_price = 0;
    var old_price = $('#totacqcart').html();
    old_price = old_price.replace(".", "");
    old_price = old_price.replace(",", ".");
    if (!isNaN(old_price))
    {
        price = price.replace(".", "");
        price = price.replace(",", ".");
        tot_price = Math.round((parseFloat(old_price) - parseFloat(price)) * 100)/100;
        $('#totacqcart').html(String(tot_price).replace(".", ","));
    }
}

function DeselectOtherCornici(idnum)
{
    for(i=1; i<100; i++)
    {
        if (idnum == i) continue; 
        if(document.getElementById('acc' + i))
        {
           if ($('#opz_type' + i).val() == "1") 
           {
                if ($('#acc' + i + ':checked').val() !== undefined)
                {
                    $('#acc' + i).attr("checked", false);
                    removeproduct(i, $('#opz_price' + i).val());
                }
           }
        }
        else
            break;
    }
}


function AddAccLock()
{
    buildAlert('/images/cartKO.png', "Per poter usufruire delle opzioni di acquisto e\' necessario essere registrati!", 450, 150 ); 
    buildOverlayAlert(); 
    $(window).scroll(function(){ CustomCenter(); });
    return false;
}

function SwitchAccessorio(idnum, nome, price, iscornice, js_login)
{
    if (js_login != '1')
    {
        $('#acc' + idnum).attr("checked", false);
        AddAccLock();
        return false;
    }
      
    if ($('#acc' + idnum + ':checked').val() !== undefined)
        addproduct(idnum, nome, price, iscornice);
    else
        removeproduct(idnum, price);
        
    DeselectOtherCornici(idnum);
}

function AdjustLineVideo()
{
			kn = 0;
			max_piece_height = 0;
			while(kn <= 8)
			{
				if(document.getElementById('videotxt' +  kn))
				{
					if( max_piece_height < $('#videotxt' + kn).height()) max_piece_height = $('#videotxt' + kn).height();
				}
				kn++;
			}
			
		    kn = 0;
		    while(kn <= 8)
			{
				if(document.getElementById('videotxt' +  kn))
					$('#videotxt' + kn).height(max_piece_height);
				kn++;
			}
}

function AdjustLineProgetti()
{
			kn = 0;
			max_piece_height = 0;
			while(kn <= 8)
			{
				if(document.getElementById('progettotxt' +  kn))
				{
					if( max_piece_height < $('#progettotxt' + kn).height()) max_piece_height = $('#progettotxt' + kn).height();
				}
				kn++;
			}
			
		    kn = 0;
		    while(kn <= 8)
			{
				if(document.getElementById('progettotxt' +  kn))
					$('#progettotxt' + kn).height(max_piece_height);
				kn++;
			}
}


function AdjustLineOpereArt()
{
			kn = 0;
			max_piece_height = 0;
			while(kn <= 100)
			{
				if(document.getElementById('operatxt' +  kn))
				{
					if( max_piece_height < $('#operatxt' + kn).height()) max_piece_height = $('#operatxt' + kn).height();
				}
				else break;
				kn++;
			}
			
		    kn = 0;
		    while(kn <= 100)
			{
				if(document.getElementById('operatxt' +  kn))
					$('#operatxt' + kn).height(max_piece_height);
				else
				    break;
				kn++;
			}
}

function AdjustLineOpereArtista()
{
			kn = 0;
			max_piece_height = 0;
			while(kn <= 100)
			{
				if(document.getElementById('operaart' +  kn))
				{
					if( max_piece_height < $('#operaart' + kn).height()) max_piece_height = $('#operaart' + kn).height();
				}
				else
				    break;
				kn++;
			}
			
		    kn = 0;
		    while(kn <= 100)
			{
				if(document.getElementById('operaart' +  kn))
					$('#operaart' + kn).height(max_piece_height);
				else
				    break;
				kn++;
			}
}

function submitLibSearch()
{
    $('#libricerca').val("1");
    var frm = $('#aspnetForm');
    frm.submit(); 
}

function submitArtSearch()
{
    $('#artricerca').val("1");
    var frm = $('#aspnetForm');
    frm.submit(); 
}

/* ---- Registrazione ------ */

function SalvaAnagrafica()
{
    ResetHighlight();
    if(document.getElementById("nome").value == "")
    {
        buildAlert('/images/fieldErr.png', "Devi selezionare un nome valido!", 450, 130 ); 
        buildOverlayAlert(); 
        $(window).scroll(function(){ CustomCenter(); });
        HighlightError('nome');
        extParams[0] = "nome";
        return false;
    }
    
    if(document.getElementById("cognome").value == "")
    {
        buildAlert('/images/fieldErr.png', "Devi selezionare un cognome valido!", 450, 130 ); 
        buildOverlayAlert(); 
        $(window).scroll(function(){ CustomCenter(); });
        HighlightError('cognome');
        extParams[0] = "cognome";
        return false;
    }
  
    if (document.getElementById("email").value == "")
    {
          buildAlert('/images/fieldErr.png', "Devi selezionare una email valida!", 450, 130 ); 
          buildOverlayAlert(); 
          $(window).scroll(function(){ CustomCenter(); });
          HighlightError('email');
          extParams[0] = "email";
          return false;
    }
    
     if (document.getElementById("piva").value != "")
     {
        var partiva = document.getElementById("piva").value;
        if(isNaN(partiva) || partiva.length != 11)
        {
            buildAlert('/images/fieldErr.png', 'Devi inserire una partita iva valida!', 450, 130 ); 
            buildOverlayAlert(); 
            $(window).scroll(function(){ CustomCenter(); });
            HighlightError('piva');
            extParams[0] = "piva";
            return false;
        }
     }
     
    if (document.getElementById("codfis").value != "")
    {
        var msg = ControllaCF(document.getElementById("codfis").value)
        if(msg != "")
        {        
            buildAlert('/images/fieldErr.png', msg, 450, 170 ); 
            buildOverlayAlert(); 
            $(window).scroll(function(){ CustomCenter(); });
            HighlightError('codfis');
            extParams[0] = "codfis";
            return false;
        }
     }
     
     if (document.getElementById("cap").value != "" && isNaN(document.getElementById("cap").value) )
    {
          buildAlert('/images/fieldErr.png', "Devi selezionare un cap valido!", 450, 130 ); 
          buildOverlayAlert(); 
          $(window).scroll(function(){ CustomCenter(); });
          HighlightError('cap');
          extParams[0] = "cap";
          return false;
    }
    
    Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
    if (!(Filtro.test(document.getElementById("email").value))){
		buildAlert('/images/fieldErr.png', "Controlla l\'indirizzo e-mail inserito", 450, 130 ); 
        buildOverlayAlert(); 
        $(window).scroll(function(){ CustomCenter(); });
        HighlightError('email');
        extParams[0] = "email";
		return false;
	}
    
    if(document.getElementById("usr").value == "")
    {
            buildAlert('/images/fieldErr.png', "Devi selezionare un username valida!", 450, 130 ); 
            buildOverlayAlert(); 
            $(window).scroll(function(){ CustomCenter(); });
            HighlightError('usr');
            extParams[0] = "usr";
            return false;
    }
    
    if(document.getElementById("pwd").value == "")
    {
            buildAlert('/images/fieldErr.png', "Devi selezionare una password valida!", 450, 130 ); 
            buildOverlayAlert(); 
            $(window).scroll(function(){ CustomCenter(); });
            HighlightError('pwd');
            extParams[0] = "pwd";
            return false;
    }   
    

    if ($('#chk_norma').is(':checked') == false)
    {
            buildAlert('/images/fieldErr.png', "Devi dare il consenso al trattamento dei dati personali!", 450, 200 ); 
            buildOverlayAlert(); 
            $(window).scroll(function(){ CustomCenter(); });
            return false;
    }
 
    
    var frm = $('#aspnetForm');
    frm.submit(); 
}

function ControllaCF(cf)
{
    return "";
    var validi, i, s, set1, set2, setpari, setdisp;
    if( cf == '' )  return '';
    cf = cf.toUpperCase();
    if( cf.length != 16 )
        return "La lunghezza del codice fiscale non e'"
        +"corretta:<br /> il codice fiscale dovrebbe essere lungo<br />"
        +"esattamente 16 caratteri.";
    validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    for( i = 0; i < 16; i++ ){
        if( validi.indexOf( cf.charAt(i) ) == -1 )
            return "Il codice fiscale contiene un carattere non valido `" +
                cf.charAt(i) +
                "'.<br />I caratteri validi sono le lettere e le cifre.\n";
    }
    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) )
        return "Il codice fiscale non e' corretto:<br />"+
            "il codice di controllo non corrisponde.<br />";
    return "";
}

function HighlightError(idfield)
{
    document.getElementById(idfield).style.backgroundColor = "#e25353";
}

function ResetHighlight()
{
    document.getElementById("nome").style.backgroundColor = "#E9E9E9";
    document.getElementById("cognome").style.backgroundColor = "#E9E9E9";
    document.getElementById("email").style.backgroundColor = "#E9E9E9";
    document.getElementById("usr").style.backgroundColor = "#E9E9E9";
    document.getElementById("pwd").style.backgroundColor = "#E9E9E9";
     
}

/* ---- End Registrazione ---- */

/* ---- Lost Password ----- */

function SendKey()
{
    ResetHighlightLost();
    
        if (document.getElementById("lostpwd").value == "")
        {
              buildAlert('/images/fieldErr.png', "Devi inserire un email valida!", 450, 130 ); 
              buildOverlayAlert(); 
              $(window).scroll(function(){ CustomCenter(); });
              HighlightError('lostpwd');
              extParams[0] = "lostpwd";
              return false;
        }
        Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
        if (!(Filtro.test(document.getElementById("lostpwd").value))){
		    buildAlert('/images/fieldErr.png', "Controlla l\'indirizzo e-mail inserito!", 450, 130 ); 
            buildOverlayAlert(); 
            $(window).scroll(function(){ CustomCenter(); });
            HighlightError('lostpwd');
            extParams[0] = "lostpwd";
		    return false;
	    }
	    
	var frm = $('#aspnetForm');
    frm.submit(); 
}

function ResetHighlightLost()
{
    document.getElementById("lostpwd").style.backgroundColor = "#E9E9E9";
}

/* ---- End Lost Password ---- */

/* ---- Spedizione ---- */

function ConfirmSpedizione(idpag)
{
    ResetHighlightSped();
    if(document.getElementById("nome").value == "")
    {
        buildAlert('/images/fieldErr.png', "Devi selezionare un nome valido!", 450, 130 ); 
        buildOverlayAlert(); 
        $(window).scroll(function(){ CustomCenter(); });
        HighlightError('nome');
        extParams[0] = "nome";
        return false;
    }
    
    if(document.getElementById("cognome").value == "")
    {
        buildAlert('/images/fieldErr.png', "Devi selezionare un cognome valido!", 450, 130 ); 
        buildOverlayAlert(); 
        $(window).scroll(function(){ CustomCenter(); });
        HighlightError('cognome');
        extParams[0] = "cognome";
        return false;
    }

   if(document.getElementById("codfis").value == "" && document.getElementById("piva").value == "")
    {
        buildAlert('/images/fieldErr.png', "Devi selezionare un codice fiscale valido oppure una partita iva!", 450, 160 ); 
        buildOverlayAlert(); 
        $(window).scroll(function(){ CustomCenter(); });
        HighlightError('codfis');
        extParams[0] = "codfis";
        return false;
    }
    
    if (document.getElementById("codfis").value != "")
    {
        var msg = ControllaCF(document.getElementById("codfis").value)
        if(msg != "")
        {        
            buildAlert('/images/fieldErr.png', msg, 450, 170 ); 
            buildOverlayAlert(); 
            $(window).scroll(function(){ CustomCenter(); });
            HighlightError('codfis');
            extParams[0] = "codfis";
            return false;
        }
     }
     
     if (document.getElementById("piva").value != "")
     {
        var partiva = document.getElementById("piva").value;
        if(isNaN(partiva) || partiva.length != 11)
        {
            buildAlert('/images/fieldErr.png', 'Devi inserire una partita iva valida!', 450, 130 ); 
            buildOverlayAlert(); 
            $(window).scroll(function(){ CustomCenter(); });
            HighlightError('piva');
            extParams[0] = "piva";
            return false;
        }
     }
    
    
    if(document.getElementById("indirizzo").value == "")
    {
        buildAlert('/images/fieldErr.png', "Devi selezionare un indirizzo valido!", 450, 130 ); 
        buildOverlayAlert(); 
        $(window).scroll(function(){ CustomCenter(); });
        HighlightError('indirizzo');
        extParams[0] = "indirizzo";
        return false;
    }

    if(document.getElementById("nazione").value == "38")
    {
        if (document.getElementById("provincia").value == "")
        {
            buildAlert('/images/fieldErr.png', "Devi selezionare dalla combo una provincia valida!", 450, 150 ); 
            buildOverlayAlert(); 
            $(window).scroll(function(){ CustomCenter(); });
            HighlightError('provincia');
            extParams[0] = "provincia";
            return false;
        }
    }
    
    if (document.getElementById("citta").value == "")
    {
          buildAlert('/images/fieldErr.png', "Devi selezionare una citta valida!", 450, 130 ); 
          buildOverlayAlert(); 
          $(window).scroll(function(){ CustomCenter(); });
          HighlightError('citta');
          extParams[0] = "citta";
          return false;
    }
    
    if (document.getElementById("cap").value == "" || isNaN(document.getElementById("cap").value))
    {
          buildAlert('/images/fieldErr.png', "Devi selezionare un cap valido!", 450, 130 ); 
          buildOverlayAlert(); 
          $(window).scroll(function(){ CustomCenter(); });
          HighlightError('cap');
          extParams[0] = "cap";
          return false;
    }
    
    if (document.getElementById("email").value == "")
    {
          buildAlert('/images/fieldErr.png', "Devi selezionare una email valida!", 450, 130 ); 
          buildOverlayAlert(); 
          $(window).scroll(function(){ CustomCenter(); });
          HighlightError('email');
          extParams[0] = "email";
          return false;
    }
    
    if(document.getElementById("telefono").value == "")
    {
        buildAlert('/images/fieldErr.png', "Devi selezionare un telefono valido!", 450, 130 ); 
        buildOverlayAlert(); 
        $(window).scroll(function(){ CustomCenter(); });
        HighlightError('telefono');
        extParams[0] = "telefono";
        return false;
    }

    Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
    if (!(Filtro.test(document.getElementById("email").value))){
		buildAlert('/images/fieldErr.png', "Controlla l\'indirizzo e-mail inserito", 450, 130 ); 
        buildOverlayAlert(); 
        $(window).scroll(function(){ CustomCenter(); });
        HighlightError('email');
        extParams[0] = "email";
		return false;
	}
    
    
    if(document.getElementById("chk_stIndirizzoFatt").checked == false)
    {
    
        if(document.getElementById("snome").value == "")
        {
            buildAlert('/images/fieldErr.png', "Devi selezionare un nome valido!", 450, 130 ); 
            buildOverlayAlert(); 
            $(window).scroll(function(){ CustomCenter(); });
            HighlightError('snome');
            extParams[0] = "snome";
            return false;
        }
        
        if(document.getElementById("scognome").value == "")
        {
            buildAlert('/images/fieldErr.png', "Devi selezionare un cognome valido!", 450, 130 ); 
            buildOverlayAlert(); 
            $(window).scroll(function(){ CustomCenter(); });
            HighlightError('scognome');
            extParams[0] = "scognome";
            return false;
        }
        
        if(document.getElementById("sindirizzo").value == "")
        {
            buildAlert('/images/fieldErr.png', "Devi selezionare un indirizzo valido!", 450, 130 ); 
            buildOverlayAlert(); 
            $(window).scroll(function(){ CustomCenter(); });
            HighlightError('sindirizzo');
            extParams[0] = "sindirizzo";
            return false;
        }
        
        if(document.getElementById("snaz").value == "38")
        {
            if (document.getElementById("sprov").value == "")
            {
                buildAlert('/images/fieldErr.png', "Devi selezionare dalla combo una provincia valida!", 450, 150 ); 
                buildOverlayAlert(); 
                $(window).scroll(function(){ CustomCenter(); });
                HighlightError('sprov');
                extParams[0] = "sprov";
                return false;
            }
        }
        
        if (document.getElementById("scitta").value == "")
        {
               buildAlert('/images/fieldErr.png', "Devi selezionare una citta valida!", 450, 130 ); 
               buildOverlayAlert(); 
               $(window).scroll(function(){ CustomCenter(); });
               HighlightError('scitta');
               extParams[0] = "scitta";
              return false;
        }
        if (document.getElementById("scap").value == "")
        {
              buildAlert('/images/fieldErr.png', "Devi selezionare un cap valido!", 450, 130 ); 
              buildOverlayAlert(); 
              $(window).scroll(function(){ CustomCenter(); });
              HighlightError('scap');
              extParams[0] = "scap";
              return false;

        }
        
        if (document.getElementById("semail").value == "")
        {
              buildAlert('/images/fieldErr.png', "Devi selezionare un email valida!", 450, 130 ); 
              buildOverlayAlert(); 
              $(window).scroll(function(){ CustomCenter(); });
              HighlightError('semail');
              extParams[0] = "semail";
              return false;
        }
        Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
        if (!(Filtro.test(document.getElementById("semail").value))){
		     buildAlert('/images/fieldErr.png', "Controlla l\'indirizzo e-mail inserito", 450, 130 ); 
             buildOverlayAlert(); 
             $(window).scroll(function(){ CustomCenter(); });
             HighlightError('semail');
             extParams[0] = "semail";
		    return false;
	    }
    }
    
    var frm = $('#aspnetForm');
    $('#aspnetForm').attr("action", "/cart.aspx?id=" + idpag + "&act=rie");
    frm.submit(); 
}


function SwitchColor()
{
    var p = 'none';
    var dis = true;
    if(document.getElementById("chk_stIndirizzoFatt").checked == false) {
        p = ''; dis = false;
    }
    
    document.getElementById("snome").disabled = dis;
    document.getElementById("scognome").disabled = dis;
    document.getElementById("sindirizzo").disabled = dis;
    document.getElementById("scap").disabled = dis;
    document.getElementById("scitta").disabled = dis;
    document.getElementById("sprov").disabled = dis;
    document.getElementById("snaz").disabled = dis;
    document.getElementById("stelefono").disabled = dis;
    document.getElementById("semail").disabled = dis;
    document.getElementById("scellulare").disabled = dis;
    
    document.getElementById("row_spedtestata").style.display = p;
    document.getElementById("row_spedspacer").style.display = p;
    document.getElementById("row_snome").style.display = p;
    document.getElementById("row_scognome").style.display = p;
    document.getElementById("row_sindirizzo").style.display = p;
    document.getElementById("row_scap").style.display = p;
    document.getElementById("row_scitta").style.display = p;
    document.getElementById("row_sprov").style.display = p;
    document.getElementById("row_snaz").style.display = p;
    document.getElementById("row_stelefono").style.display = p;
    document.getElementById("row_semail").style.display = p;
    document.getElementById("row_scellulare").style.display = p;
    
    document.getElementById("row2_snome").style.display = p;
    document.getElementById("row2_scognome").style.display = p;
    document.getElementById("row2_sindirizzo").style.display = p;
    document.getElementById("row2_scap").style.display = p;
    document.getElementById("row2_scitta").style.display = p;
    document.getElementById("row2_sprov").style.display = p;
    document.getElementById("row2_snaz").style.display = p;
    document.getElementById("row2_stelefono").style.display = p;
    document.getElementById("row2_semail").style.display = p;
    document.getElementById("row2_scellulare").style.display = p;
}

function ResetHighlightSped()
{
    document.getElementById("nome").style.backgroundColor = "#E9E9E9";
    document.getElementById("cognome").style.backgroundColor = "#E9E9E9";
    document.getElementById("codfis").style.backgroundColor = "#E9E9E9";
    document.getElementById("indirizzo").style.backgroundColor = "#E9E9E9";
    document.getElementById("piva").style.backgroundColor = "#E9E9E9";
    document.getElementById("nazione").style.backgroundColor = "#E9E9E9";
    document.getElementById("provincia").style.backgroundColor = "#E9E9E9";
    document.getElementById("citta").style.backgroundColor = "#E9E9E9";
    document.getElementById("cap").style.backgroundColor = "#E9E9E9";
    document.getElementById("email").style.backgroundColor = "#E9E9E9";
    document.getElementById("telefono").style.backgroundColor = "#E9E9E9";
    document.getElementById("snome").style.backgroundColor = "#E9E9E9";
    document.getElementById("scognome").style.backgroundColor = "#E9E9E9";
    document.getElementById("sindirizzo").style.backgroundColor = "#E9E9E9";
    document.getElementById("snaz").style.backgroundColor = "#E9E9E9";
    document.getElementById("sprov").style.backgroundColor = "#E9E9E9";
    document.getElementById("scitta").style.backgroundColor = "#E9E9E9";
    document.getElementById("scap").style.backgroundColor = "#E9E9E9";
    document.getElementById("semail").style.backgroundColor = "#E9E9E9";
    document.getElementById("stelefono").style.backgroundColor = "#E9E9E9";
    document.getElementById("scellulare").style.backgroundColor = "#E9E9E9";
    SwitchColor();
     
}

/* ---- End Spedizione ---- */

function AdjustLineWhish()
{
			kn = 0;
			max_piece_height = 0;
			while(kn <= 9)
			{
				if(document.getElementById('whishtxt' +  kn))
				{
					if( max_piece_height < $('#whishtxt' + kn).height()) max_piece_height = $('#whishtxt' + kn).height();
				}
				kn++;
			}
			
		    kn = 0;
		    while(kn <= 9)
			{
				if(document.getElementById('whishtxt' +  kn))
					$('#whishtxt' + kn).height(max_piece_height);
				kn++;
			}
}

function AreYouSure()
{
    if(confirm("Sei sicuro di cancellare questo elemento?"))
        return true;
    else 
        return false;
}

function OperaNoExists()
{
      buildAlert('/images/fieldErr.png', "Spiacenti ma l'opera non &egrave; pi&ugrave; disponibile", 450, 130 ); 
      buildOverlayAlert(); 
      $(window).scroll(function(){ CustomCenter(); });
      return false;
}

function LibroNoExists()
{
      buildAlert('/images/fieldErr.png', "Spiacenti ma il libro non &egrave; pi&ugrave; disponibile", 450, 130 ); 
      buildOverlayAlert(); 
      $(window).scroll(function(){ CustomCenter(); });
      return false;
}

function DvdNoExists()
{
      buildAlert('/images/fieldErr.png', "Spiacenti ma il dvd non &egrave; pi&ugrave; disponibile", 450, 130 ); 
      buildOverlayAlert(); 
      $(window).scroll(function(){ CustomCenter(); });
      return false;
}
