

function setCookie(c_name,value,expireHours)
{var exhour=new Date();exhour.setHours(exhour.getHours()+12);document.cookie=c_name+"="+escape(value)+
((expireHours==null)?"":";expires="+exhour.toGMTString());}
function getCookie(c_name)
{if(document.cookie.length>0)
{c_start=document.cookie.indexOf(c_name+"=");if(c_start!=-1)
{c_start=c_start+c_name.length+1;c_end=document.cookie.indexOf(";",c_start);if(c_end==-1)c_end=document.cookie.length;return unescape(document.cookie.substring(c_start,c_end));}}
return"";}
function scrollTo(selector,speed){if(!speed)speed=500;var targetOffset=$(selector).offset().top;$('html,body').animate({scrollTop:targetOffset-80},speed);}
$(function(){var w=$("html").width();if(w<1010&&w>850){$("body").css({overflowX:"hidden"});}
if(getCookie('aicel_c')!='set')
{var pos=parseInt($(window).scrollTop())+parseInt($(window).height());$('#aicel').css("top",pos-310+"px");$('#aicel').show();$(window).scroll(function()
{var pos=parseInt($(window).scrollTop())+parseInt($(window).height());$('#aicel').animate({top:pos-310+"px"},{queue:false,duration:500});});}
$('#close_message').click(function()
{$('#aicel').animate({top:"-=15px",opacity:0},"slow");setCookie('aicel_c','set',1);});});function ajaxInit(){$.ajaxSetup({type:"POST",dataType:"json",beforeSend:onStartLoading,error:onError});}
function onStartLoading(){}
function onError(xhr,st,er){alert(er);}
function close_shopping_bag(){$('#cestino-della-spesa').css({visibility:"hidden"});return false;}
jQuery.fn.exists=function(){return jQuery(this).length>0;}
function addSingleItem(cod)
{$.ajax({url:base_url+'prodotti-alimentari/aggiungi-singolo/'+cod,success:function(data){if(data)
{$('li#riga-carrello-'+data.cart_row+' #valore-quantita').html(data.new_total_row);$('li#riga-carrello-'+data.cart_row+' #valore-subtotale-riga').html(data.new_subtotal_row);$('li#valore-subtotale span').html(data.new_subtotal_cart);$('#riepilogo-totale-carrello').html(data.new_subtotal_value);$('#riepilogo-totale-prodotti').html(data.new_total_items);$('#avvisi').hide()
if(data.message)
{$('#avvisi-static').hide()
$('#avvisi').html('<ul>');$.each(data.message,function()
{if(this!=false)$('#avvisi').show().append('<li>'+this+'</li>');});$('#avvisi').append('</ul>');if(data.ship)
$('span.prezzo-spedizione span').css({'color':'red'}).html(data.ship);}}}});var my_options={success:function(data){$('#totale-ordine').html(data.total_cart);},dataType:'json',url:base_url+'aggiorna-totale-carrello'};$('form#dati-fatturazione').ajaxSubmit(my_options);return false;}
function remSingleItem(cod)
{$.ajax({url:base_url+'prodotti-alimentari/rimuovi-singolo/'+cod,success:function(data){if(data)
{$('li#riga-carrello-'+data.cart_row+' #valore-quantita').html(data.new_total_row);$('li#riga-carrello-'+data.cart_row+' #valore-subtotale-riga').html(data.new_subtotal_row);$('li#valore-subtotale span').html(data.new_subtotal_cart);$('#riepilogo-totale-carrello').html(data.new_subtotal_value);$('#riepilogo-totale-prodotti').html(data.new_total_items);$('#avvisi').hide()
if(data.message)
{$('#avvisi-static').hide()
$('#avvisi').html('<ul>');$.each(data.message,function()
{if(this!=false)$('#avvisi').show().append('<li>'+this+'</li>');});$('#avvisi').append('</ul>');if(!data.ship)
$('span.prezzo-spedizione span').html('');}}}});var my_options={success:function(data){$('#totale-ordine').html(data.total_cart);},dataType:'json',url:base_url+'aggiorna-totale-carrello'};$('form#dati-fatturazione').ajaxSubmit(my_options);return false;}
function deleteSingleItem(id)
{$.ajax({url:base_url+'prodotti-alimentari/cancella/'+id,success:function(data){$('#riga-carrello-'+id).fadeOut(function()
{$('li#valore-subtotale span').html(data.new_subtotal_cart);$('#riepilogo-totale-carrello').html(data.new_subtotal_value);$('#riepilogo-totale-prodotti').html(data.new_total_items);});}});var my_options={success:function(data){$('#totale-ordine').html(data.total_cart);},dataType:'json',url:base_url+'aggiorna-totale-carrello'};$('form#dati-fatturazione').ajaxSubmit(my_options);return false;}
$(document).ready(function(){$('.nascosto').css({'display':'none'});ajaxInit();$(window).scroll(function(){$('#cestino-della-spesa').css({visibility:"hidden"});});$('.compra-subito').click(function(){var h=$(window).scrollTop();var product_cod=($(this).attr('id'));$.ajax({url:base_url+'prodotti-alimentari/aggiungi/'+product_cod,success:function(data){if(data.cartSuccess)
{$('div#principale').block({message:'<img src="'+base_url+'assets/images/ajax-block-loader.gif" />',css:{border:'none',backgroundColor:null}});$('#cestino-della-spesa').show('fast').css({"top":h+"px",visibility:"visible"});$('#cestino-vuoto').remove();$("#totale-euro-carrello").html(data.subtotal);$("#riepilogo-totale-carrello").html(data.subtotal);$("#riepilogo-totale-prodotti").html(data.total_products);if(data.qta==1){var newItem='<li id="prodotto-cestino-numero-'+data.id+'">'+data.img+'<div id="qta_'+product_cod+'" class="quantita-cestino">'+data.qta+'</div></li><li class="titolo-prodotto-cestino" id="'+data.id+'">'+data.title+'</li>';$("#prodotti-cestino").append($(newItem).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100));}
else
{$('#prodotto-cestino-numero-'+data.id).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100)
$("#qta_"+product_cod).html(data.qta);}
$(".titolo-prodotto-cestino").fadeOut('slow');$('div#principale').unblock();}
else
{alert('Gentile Cliente,\nil prodotto selezionato non è disponibile.\nSe vuoi ricevere ulteriori informazioni a riguardo e/o prenotare questo prodotto, scrivici presso gestione.ordini@operamage.com\nGrazie.\nOpera Magé - I sapori della terra taggiasca s.r.l.');}}});return false;});$('ul#prodotti-cestino li img').hover(function(){var id=$(this).attr('rel');$('ul#prodotti-cestino li#'+id).show();},function(){var id=$(this).attr('rel');$('ul#prodotti-cestino li#'+id).fadeOut();});$(':checkbox').click(function(){$(this).parents('fieldset').next('fieldset').slideToggle();});if($("#flag_indirizzo_spedizione:checked").val())
{$('#indirizzo_alternativo').slideToggle();}
if($("#flag_azienda:checked").val())
{$('#dati_aziendali').slideToggle();}
$(":radio[name='tipo_spedizione']").livequery("click",function(){if($("#tipo_spedizione_2:radio:checked").val())
{$('.radio_tipo_pagamento:radio').attr('disabled','disabled');$('dd.opzioni_pagamento span').css({'color':'#eeeeee'});}
else
{$('.radio_tipo_pagamento:radio').removeAttr('disabled');$('dd.opzioni_pagamento span').css({'color':'rgb(101,100,91)'});}});var my_options={success:updateTotal,dataType:'json',url:base_url+'aggiorna-totale-carrello'};$(':radio').livequery("click",function(){var val=$(this).val();$(this.form).ajaxSubmit(my_options);});function updateTotal(data)
{$('#totale-ordine').html(data.total_cart);}
$('.annulla').click(function(){$.unblockUI();return false;});$('.modalLogin').click(function(){$.blockUI({message:$('#login-utente'),centerX:true,centerY:true,overlayCSS:{cursor:'auto'},css:{border:'none',padding:'15px','-webkit-border-radius':'10px','-moz-border-radius':'10px','border-radius':'10px',cursor:'auto',left:($(window).width()-500)/2+'px',width:'500px'}});return false;});$('#recupera-password-label').click(function(){$.blockUI({message:$('#recupera-password'),centerX:true,centerY:true,overlayCSS:{cursor:'auto'},css:{border:'none',padding:'15px','-webkit-border-radius':'10px','-moz-border-radius':'10px','border-radius':'10px',cursor:'auto',left:($(window).width()-500)/2+'px',width:'500px'}});return false;});});