
function checkForm(){
	var check = true;
	jQuery(".required").each(function(index, element) {
		var $this = jQuery(this);
		if (jQuery.trim($this.val() + " ") == ""){
			$this.addClass('richiesto');
			$this.focus();
            var messaggio = "Devi inserire i campi richiesti";
            messaggio = messaggio.replace(/%campo%/gi,$this.attr("id"));
			alertDialog(messaggio);
			check = false;
			return false;
		}
		$this.removeClass('richiesto');
	});
	return check;
}
var funzioneR;
function errorGeoLocation() {

    //jQuery(document).trigger('LocationFailed');
	jQuery('#alertErrorLocation').remove();
	var html;
    html = "<div id='alertErrorLocation'><table style='width:100%; height:auto;'>";
    html += "<tr><td style='width:100%; padding-bottom:15px;' colspan='2'><input autocomplete=\"off\" placeholder='Citt&agrave; o CAP' name='citta' type='text' style='width:99%;' /></td></tr><tr><td style='width:200px; vertical-align:bottom;'>Inserisci la Citt&agrave;</td>";
    html += "<td align='right'><input name='bottone_conferma' type='button' value='OK'  style='width:100px;' /></td></tr></table></div>";
    var dHtml = jQuery(html);
    //jQuery('a').live('click',function(e){return false;});
    var zindex = 999;
    jQuery('.disableBody').remove();
	jQuery('<div class="disableBody"></div>').appendTo('body'); jQuery('.disableBody').css({'z-index':zindex,width:jQuery(window).width(),height:jQuery(window).height()});
    dHtml.dialog({title:'Trova le offerte nella tua citt&agrave;',width:450,zIndex:zindex+1,resizable: false,close:function(){errorGeoLocation()}});
    jQuery("input[name='citta']").live('keypress',function (e) {
		if (e.which == 13) {
			jQuery('input[name="bottone_conferma"]').click();
            e.preventDefault();
		} 
	});
    jQuery('input[name="bottone_conferma"]').live('click',function(e){
        var citta = jQuery('#alertErrorLocation input[name="citta"]').val();
        if (jQuery.trim(citta + " ").length > 0){
        	jQuery('.disableBody').remove();
        	changeLocation(citta);
            jQuery(this).die();
            jQuery(this).unbind('click');
   			dHtml.dialog('destroy');
        	
        }
        e.preventDefault();
    }); 
}


function lampeggio_iniziale(){
    var barra = jQuery('input[name="q"]');
    var i = 0;

do{
    barra.queue('barraQueue', function(){
        jQuery(this).blur();
        jQuery(this).dequeue('barraQueue');
    }).delay('500','barraQueue');
    
    barra.queue('barraQueue', function(){
        jQuery(this).focus();
        jQuery(this).dequeue('barraQueue');
    }).delay('500','barraQueue');
    
    i = i+1;
}
while (i<3)

    barra.dequeue('barraQueue');
}

function documentInitialize() {
    margine = 11;
	var objbl = jQuery('.cont_whole_page');
    divleft =(jQuery(window).width()-1024)/2;
    jQuery('.parametri').css({'margin-left':objbl.offset().left});

    //jQuery("input[name='citta']").live('keyup.autocomplete',function(){jQuery(this).autocomplete({minLength:3,autoFocus:true,source: getCityName});});    
	jQuery.ajaxSetup({ scriptCharset: "utf-8" , contentType: "application/json; charset=utf-8"});
    jQuery('.result_negozio a').click(function(e){e.preventDefault();setCookie('categoria','');setCookie('gruppo',jQuery(this).attr('title'));window.location = jQuery(this).attr('href');});
    jQuery("[placeholder]").focus(function(){var input=$(this); if(input.val()==input.attr("placeholder")){input.val("''");input.removeClass("placeholder")}}).blur(function(){var input=$(this);if(input.val()=="''"||input.val()==input.attr("placeholder")){input.addClass("placeholder");input.val(input.attr("placeholder"))}}).blur();
    jQuery('.cambia').click(cambiaDialog);
	writeLocations(jQuery.cookie('citta'),jQuery.cookie('raggio'));
	width = objbl.width();
	height = objbl.height();
	m_pos = objbl.position();
	right = m_pos.left+width + margine;
	t = m_pos.top; bottom = m_pos.top + height + margine;
	left = 0;	
    var tempob =  (new Date().getTime());
	jQuery('#ricerca select').live('change',function(){
		jQuery.cookie(jQuery(this).attr('name'),jQuery(this).val());
	});
	jQuery('.submit').click(function(e){
		window.location='result.asp?q='+jQuery('input[name="q"]').val();
		e.preventDefault()
	});
	jQuery('input[name="q"]').keypress(function(e){
		if(e.which==13){
			window.location='result.asp?q='+jQuery(this).val()
		}
	}).focus(function(){
		jQuery(this).select()
	}).focus();


	if (getCookie('lat') != 0) {        
    	lampeggio_iniziale();
	}

	checkIndicatorLista();
	jQuery(document).bind("changeLista", checkIndicatorLista);
	initPulsanteListaSpesa();
	bannerTop();
    jQuery(document).bind("changeLocation",function(){lampeggio_iniziale();});
	jQuery('.bannerTop a').click(function(e){sSend({funzione:"sBanner",h:jQuery(this).attr("href"),t:9});});
	jQuery('.sceltaLingua a').live("click",function(e){e.preventDefault;setCookie('lingua',jQuery(this).attr("lingua"));setCookie('gruppo',' ');setCookie('categoria','');setCookie('defaultCustomList','');setCookie('customProdotti','');window.location.reload();});    
}


function sSend(dati){
	jQuery.get('heart.asp',dati);
}
/*
function drawBarraMenu(){
	var barra_menu = [{html:'Home',href:'default.asp',descrizione:'Home'},
    {html:'come funziona?',href:'come-funziona.asp',descrizione:'come funziona?'},
    {html:'lista della spesa',href:'lista-spesa.asp',descrizione:'lista della spesa'},
    { html: 'news', href: 'news.asp', descrizione: 'news' },
		{html:'Il TUO Parere',href:'suggerimenti.asp',descrizione:''}
	];drawMenu(jQuery('#menu .pulsanti ul'),barra_menu);
}
*/
/*
function drawLateraleMenu(){
	var laterale_menu =[{html:'volantini',href:'volantini.asp',descrizione:'volantini'},
		{html:'tamtam consiglia',href:'tamtam-consiglia.asp',descrizione:'tamtam consiglia'},
		{html:'le pi&ugrave; cliccate',href:'piu-cliccate.asp',descrizione:'le pi&ugrave; cliccate'},
		{html:'sei un negozio?',href:'sei-negozio.asp',descrizione:'sei un negozio?'},
		{html:'registrati',href:'registrati.asp',descrizione:'registrati'}
        
	];
	
	//drawMenu(jQuery('#menu_laterale .pulsanti ul'),laterale_menu);
}*/


function requestProdotti(dati, classe, titolo) {
	jQuery('.' + classe).css({ background: "url(/imgs/load.gif) 50% 50% no-repeat" });
    jQuery("." + classe + " ul").remove();
    var fr = jQuery("." + classe).attr("fr");
    jQuery.get('heart.asp', dati, function (data) { 
    	var json ="";var ul, vuoto;
        if (typeof(data) !== "object"){
            json = jQuery.parseJSON(data);
        } 
        else 
        	json = data;
         
		if (json.prodotti.length > 0) {
			vuoto = false;
			ul = createListProdotti(json.prodotti,fr);
		}
		else {
			vuoto = true;
			 ul = jQuery("<ul class='vuoto'><li><span>Non ci sono Offerte cambia il raggio di ricerca</span></li></ul>");
		}
		jQuery('.' + classe).css('background', "").append(ul);
		if (vuoto) jQuery('.' + classe).trigger("getProdottiVuoti");
		else jQuery('.' + classe).trigger("getProdottiComplete");
	}).error(function (jqXHR, textStatus, errorThrown) {
		//alert("error " + textStatus);
        
    });
}

function refreshMenu(){
	var lat = jQuery.cookie('lat');
	if (lat == 0 || lat == '0' || lat == null) return false;
    
	jQuery.getJSON('heart.asp',{funzione:'categorie'},function(data){
	    var obj = jQuery('select[name="categoria"]'); 
		jQuery('option', obj).remove(); 
		obj.append('<option value="Tutte le categorie">Tutte le categorie</option>');
		data = data.categorie; 
        for (var key in data) {
			var d = data[key];
			obj.append('<option value="' + d.categoria + '">' + d.categoria + ' <span>(' + d.numeroProdotti + ')</span></option>');
		}
		jQuery('option[value="'+jQuery.cookie('categoria').replace(/\+/g,' ')+'"]').attr('selected','selected');
	});
	jQuery.getJSON('heart.asp',{funzione:'marchi'},function(data){
		var obj = jQuery('select[name=gruppo]');
		jQuery('option',obj).remove();
		obj.append('<option value="Punti Vendita">Punti Vendita</option>');
		data=data.marchi;
		for (var key in data){
			var d = data[key];
			obj.append('<option value="'+d.nome_marchio+'">'+d.nome_marchio+' <span>('+d.numeroProdotti+')</span></option>');
		}
		jQuery('option[value="'+jQuery.cookie('gruppo').replace(/\+/g,' ')+'"]').attr('selected','selected');
	});
}
function cambiaDialogClick(){
	if (jQuery('.cambia_dialog').html() == null )return;
    var citta = jQuery('.cambia_dialog input[name="citta"]').val();
    var raggio = jQuery('.cambia_dialog input[name="raggio"]').val();
    if (raggio == 'undefined' || citta == 'undefined')return;
    if (raggio > 50) raggio = 50;
    if (raggio <= 0) raggio = 1;
    jQuery.cookie('raggio', raggio); 
    changeLocation(citta); 
    jQuery('.cambia_dialog').remove();
    jQuery('.cambia_dialog').dialog('destroy'); 
}
var fixCambiaDialog = false;
function cambiaDialog(e) {
	jQuery('.cambia_dialog').remove(); 
	jQuery('<div class="cambia_dialog"><table style="width:100%; padding-bottom:5px;"><tr><td style="font-size:0.9em; width:40px;">Citt&agrave;:</td><td style="width:260px;"><input autocomplete="off" placeholder="Citt&agrave; o CAP" name="citta" type="text" value="' + jQuery.cookie('citta').replace(/\+/g," ") + '" style="font-size:1.1em; width:99%;"/></td></tr></table><table style="width:100%;"><tr><td class="ie_table_fix" style="font-size:0.9em; width:90px;">Raggio (in km):</td><td style="width:80px;"><input name="raggio" type="text" value="' + jQuery.cookie('raggio') + '" style="font-size:1.1em; width:40px; float:left;"/></td><td style="width:100px;"><input name="cambia" type="button" value="Ok" style="width:100px; float:right;" /></td></tr></table></div>').dialog({ title: 'Cambia la tua posizione', resizable:false, width:350, dialogClass: 'shadow' });
    jQuery('.ui-dialog-content').css({'padding':'1em 1em 0'});
    jQuery(".cambia_dialog input[name='cambia']").live('click',cambiaDialogClick); 
    jQuery(".cambia_dialog input[name='citta']").live('keypress',function (e) {
		if (e.which == 13) {
			cambiaDialogClick();
            e.preventDefault();
		} 
	});
    jQuery(".cambia_dialog input[name='raggio']").live('keypress', function (e) {
    	if (e.which == 13){
			cambiaDialogClick();
            e.preventDefault();
       	}
        else if (e.which == 8 || e.which == 13 || e.whitch == 144 || (e.which >= 48 && e.which <=57))
        	return true;
        else e.preventDefault();
	}); 
	e.preventDefault();
}



function CreateBookmarkLink() {
 title = "TamTam Offerte"; 
  // Blogger - Replace with <$BlogItemTitle$> 
  // MovableType - Replace with <$MTEntryTitle$>

 url = "http://www.tamtamofferte.com";
  // Blogger - Replace with <$BlogItemPermalinkURL$> 
  // MovableType - Replace with <$MTEntryPermalink$>
  // WordPress - <?php bloginfo('url'); ?>

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
    if(jQuery.browser.safari){alert('Siamo spiacenti ma con il suo browser occorre utilizzare Ctrl-D (Windows) o Cmd-D (MacOS) per aggiungere TamTam tra i preferiti');}
    var isChrome;  
    if (navigator.userAgent.indexOf("Chrome/") > -1){alert('Siamo spiacenti ma con il suo browser occorre utilizzare Ctrl-D per aggiungere TamTam tra i preferiti')};
}

function setHomepage()
{
 if (document.all)
    {
        document.body.style.behavior='url(#default#homepage)';
  document.body.setHomePage('http://www.tamtamofferte.com');
 
    }
    else if (window.sidebar)
    {
    if(window.netscape)
    {
         try
   {  
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
         }  
         catch(e)  
         {  
    alert('Siamo spiacenti ma con i suoi settaggi del browser occorre impostare manualmente TamTam come pagina iniziale utilizzando il menu delle preferenze di Mozilla FireFox');  
         }
    } 
    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
    prefs.setCharPref('browser.startup.homepage','http://www.tamtamofferte.com');
 }
 if(jQuery.browser.safari){alert('Siamo spiacenti ma con il suo browser occorre impostare manualmente TamTam come pagina iniziale utilizzando il menu delle preferenze di Safari');}
 var isChrome;  
 if (navigator.userAgent.indexOf("Chrome/") > -1){alert('Siamo spiacenti ma con il suo browser occorre impostare manualmente TamTam come pagina iniziale utilizzando il menu delle preferenze di Chrome')};
}
