// JavaScript Document
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
nomebrowser = BrowserDetect.browser.toLowerCase();




function IsNumeric(strString)
{
   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 email_valida(email) {

var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/; 
if (!email_reg_exp.test(email) || (email == "") || (email == "undefined"))
   	return false;
else
 	return true;
}

function resetta_input_login(idelemento) {
	valore = document.getElementById('username').value;
	pwd = document.getElementById('password').value;
	keyword = 'cerca';
	
	if( document.getElementById('cerca') ) keyword = document.getElementById('cerca').value;

	if( (pwd == "") && (idelemento != 'password') )
		document.getElementById('password').style.backgroundImage = 'url(img/bg_input_password_new.jpg)';
	else 
		document.getElementById('password').style.backgroundImage = 'url(img/bg_input_login_new.jpg)';
	if( (valore == 'user') && (idelemento == 'username') )
		document.getElementById('username').value = ''; 
	else if(valore == '')
		document.getElementById('username').value = 'user';
	if( (keyword == 'cerca') && (idelemento == 'cerca') )
		document.getElementById('cerca').value = ''; 
	else if(keyword == '')
	{
		document.getElementById('cerca').value = 'cerca';
	}

}
function carica_foto(pagina, quale, id_negozio)
{
	var stile = 'width=328,height=320 ,toolbar=no, location=no,status=yes,menubar=no,scrollbars=no,resizable=no';
	if(pagina == 'negozio')
		window.open('carica_foto.php?idnegozio='+id_negozio+'&pagina='+pagina+'&quale='+quale, '', stile);
	else if( pagina == 'offerta' )
	{
		photo = document.getElementById(quale).value;
		window.open('carica_foto.php?idnegozio='+id_negozio+'&pagina='+pagina+'&photo='+photo+'&quale='+quale, '', stile);
	}
	else if( pagina == 'post' )
	{
		photo = document.getElementById(quale).value;
		window.open('carica_foto.php?idnegozio='+id_negozio+'&pagina='+pagina+'&photo='+photo+'&quale='+quale, '', stile);	
	}
	else if( pagina == 'evento' )
	{
		photo = document.getElementById(quale).value;
		window.open('carica_foto.php?idnegozio='+id_negozio+'&pagina='+pagina+'&photo='+photo+'&quale='+quale, '', stile);	
	}	
	else if( pagina == 'prodotto' )
	{
		photo = document.getElementById(quale).value;	
		window.open('carica_foto.php?idnegozio='+id_negozio+'&pagina='+pagina+'&photo='+photo+'&quale='+quale, '', stile);			
	}
}
function get_estensione(path) {    
	posizione_punto=path.lastIndexOf(".");	
	lunghezza_stringa=path.length;	
	estensione=path.substring(posizione_punto+1,lunghezza_stringa);	
	estensione = estensione.toLowerCase();
	return estensione;
}
function controlla_estensione(path, nome_div)
{	
	if( !(get_estensione(path)=="jpg") || (get_estensione(path)=="jpeg") )
	{		
		alert('Il file deve essere in formato jpg o jpeg');
		document.getElementById('btn_foto').disabled = true;	
	}
	else
	{
		document.getElementById('btn_foto').disabled = false;
	}
}
function salva_descrizione()
{
	if( confirm('Vuoi salvare le modifiche effettuate?') )
		document.getElementById('form_descrizione').submit();
}
function cerca_multi_giorni(giorni)
{
	ritorna = false;
	for( i=0; i < giorni; i++ )
	{
		if( document.getElementById('giorni_offerta_'+i).checked )
		{
			ritorna = true;
		}
	}
	return ritorna;
}
function offerte_richieste(giorni)
{
	offerte = 0;
	for( i=0; i < giorni; i++ )
	{
		if( document.getElementById('giorni_offerta_'+i).checked )
		{
			offerte++;
		}
	}
	return offerte;
}
function annulla_select(valore)
{
	document.getElementById('giorno_offerta').selectedIndex = 0;
}
function annulla_check()
{
	giorni = 31;
	for( i=0; i < giorni; i++ )
	{	
		document.getElementById('giorni_offerta_'+i).checked = false;
	}
}
function form_offerta(offerte_disponibili)
{
	nome_prodotto = document.getElementById('nome_prodotto').value;
	descrizione_offerta = document.getElementById('descrizione_offerta').value;
	prezzo_in_offerta = document.getElementById('prezzo_in_offerta').value;
	prezzo_senza_offerta = document.getElementById('prezzo_senza_offerta').value;
	photo_uno = document.getElementById('photo_uno').value;
	photo_due = document.getElementById('photo_due').value;
	giorno_offerta = document.getElementById('giorno_offerta').value;
	//off_richieste = offerte_richieste(31);
	if( cerca_multi_giorni(31) )
	{
		document.getElementById('giorno_offerta').selectedIndex = 0;
	}
	prezzo_in_offerta = prezzo_in_offerta.replace(",",".");
	prezzo_senza_offerta = prezzo_senza_offerta.replace(",",".");

	if( (nome_prodotto.length > 50) || (nome_prodotto  == '') )
		alert('Attenzione, il nome prodotto non puo superare i 50 caratteri o essere vuoto');
	else if(!IsNumeric(prezzo_in_offerta))
		alert('Attenzione, il prezzo in offerta deve contenere solo numeri e non puo essere vuoto');
	else if(!IsNumeric(prezzo_senza_offerta))
		alert('Attenzione, il prezzo senza offerta deve contenere solo numeri e non puo essere vuoto');
	else if(  parseFloat(prezzo_in_offerta) >= parseFloat(prezzo_senza_offerta) )
		alert('Attenzione, il prezzo in offerta deve essere minore del prezzo senza offerta');
	else if(  parseFloat(prezzo_in_offerta) == 0 )
		alert('Attenzione, il prezzo in offerta non puo essere uguale a zero');		
	else if( (giorno_offerta == 0) && (!cerca_multi_giorni(31)) )
		alert('Attenzione, selezionare la data dell\'offerta');
	/*else if( off_richieste > offerte_disponibili )
		alert('Attenzione, hai solo '+offerte_disponibili+' offerte, mentre hai selezionato '+off_richieste+' giorni');*/
	else
		document.getElementById('form_crea_offerta').submit();
}
function form_modifica_offerta(offerte_disponibili)
{
	nome_prodotto = document.getElementById('nome_prodotto').value;
	descrizione_offerta = document.getElementById('descrizione_offerta').value;
	prezzo_in_offerta = document.getElementById('prezzo_in_offerta').value;
	prezzo_senza_offerta = document.getElementById('prezzo_senza_offerta').value;
	photo_uno = document.getElementById('photo_uno').value;
	photo_due = document.getElementById('photo_due').value;
	giorno_offerta = document.getElementById('giorno_offerta').value;
	prezzo_in_offerta = prezzo_in_offerta.replace(",",".");
	prezzo_senza_offerta = prezzo_senza_offerta.replace(",",".");

	if( (nome_prodotto.length > 50) || (nome_prodotto  == '') )
		alert('Attenzione, il nome prodotto non puo superare i 50 caratteri o essere vuoto');
	else if(!IsNumeric(prezzo_in_offerta))
		alert('Attenzione, il prezzo in offerta deve contenere solo numeri e non puo essere vuoto');
	else if(!IsNumeric(prezzo_senza_offerta))
		alert('Attenzione, il prezzo senza offerta deve contenere solo numeri e non puo essere vuoto');
	else if(  parseFloat(prezzo_in_offerta) > parseFloat(prezzo_senza_offerta) )
		alert('Attenzione, il prezzo in offerta non puo essere piu alto del prezzo senza offerta');
	else if(  parseFloat(prezzo_in_offerta) == 0 )
		alert('Attenzione, il prezzo in offerta non puo essere uguale a zero');		
	else
		document.getElementById('form_crea_offerta').submit();
}
var div_select = 0;
var posx = 0;
var posy = 0;
function getMouse(e){
	var ev=(!e)?window.event:e;//IE:Moz
	if (ev.pageX)
	{//Moz
		posx=ev.pageX+window.pageXOffset;
		posy=ev.pageY+window.pageYOffset;
	}
	else if(ev.clientX)
	{//IE
		posx=ev.clientX+document.body.scrollLeft;
		posy=ev.clientY+document.body.scrollTop;
	}
	else{return false}//old browsers
}
document.onmousemove=getMouse;
function DivSelect() {
	if( div_select == 0 )
	{	
		larghezza = 270;
		altezza = 150;
    	scrolltop = document.documentElement.scrollTop;
		scrollleft = document.documentElement.scrollLeft;
		leftPosition = posx + scrollleft - larghezza;
		topPosition = posy + scrolltop;
		if( leftPosition < 10 ) leftPosition = 10;		
		if( nomebrowser != 'explorer' )
		{
			leftPosition = posx - scrollleft - larghezza ;
			topPosition = posy - scrolltop;
			if( leftPosition < 10 ) leftPosition = 10;
		}
		document.getElementById('div_select').style.visibility = 'visible';
		document.getElementById('div_select').style.display = 'block';
		document.getElementById('div_select').style.top = topPosition+'px';
		document.getElementById('div_select').style.left = leftPosition+'px';
		div_select = 1;
	}
	else
	{
		document.getElementById('div_select').style.visibility = 'hidden';
		div_select = 0;
	}
}
function ajaxRicercaProvVolantini(data) {
	document.getElementById('id_citta').value = "";
	document.getElementById('txt_citta_volantini').innerHTML = "localit&aacute;";
	document.getElementById('txt_citta_volantini').style.fontWeight = 'normal';
	document.getElementById('id_provincia').value = "";
	document.getElementById('txt_provincia_volantini').innerHTML = "provincia";
	document.getElementById('txt_provincia_volantini').style.fontWeight = 'normal';
	document.getElementById('id_categoria').value = "";
	document.getElementById('txt_categoria_volantini').innerHTML = "categoria";
	document.getElementById('txt_categoria_volantini').style.fontWeight = 'normal';
	DivSelect();
	nocache = Math.floor(Math.random()*100);
	completeAHAH.ahah('ricerca_volantino_provincia.php?nocache='+nocache+'&data='+data, 'div_select', '', 'GET', '');
}
function ajaxRicercaCittaVolantini(data, id_provincia) {
	if( id_provincia == '' )
		alert("Selezionare prima una provincia");
	else
	{
		document.getElementById('id_citta').value = "";
		document.getElementById('txt_citta_volantini').innerHTML = "localit&aacute;";
		document.getElementById('txt_citta_volantini').style.fontWeight = 'normal';
		document.getElementById('id_categoria').value = "";
		document.getElementById('txt_categoria_volantini').innerHTML = "categoria";
		document.getElementById('txt_categoria_volantini').style.fontWeight = 'normal';
		DivSelect();
		nocache = Math.floor(Math.random()*100);
		completeAHAH.ahah('ricerca_volantino_citta.php?nocache='+nocache+'&data='+data+'&provincia='+id_provincia, 'div_select', '', 'GET', '')
	}
}
function ajaxRicercaCategoriaVolantini(data, id_provincia, id_citta) {
		DivSelect();
		nocache = Math.floor(Math.random()*100);
		completeAHAH.ahah('ricerca_volantino_categoria.php?nocache='+nocache+'&data='+data+'&provincia='+id_provincia+'&citta='+id_citta, 'div_select', '', 'GET', '')
}

function ajaxRicercaProv(data) {
	document.getElementById('id_citta').value = "";
	document.getElementById('txt_citta').innerHTML = "localit&aacute;";
	document.getElementById('txt_citta').style.fontWeight = 'normal';
	document.getElementById('id_provincia').value = "";
	document.getElementById('txt_provincia').innerHTML = "provincia";
	document.getElementById('txt_provincia').style.fontWeight = 'normal';
	document.getElementById('id_categoria').value = "";
	document.getElementById('txt_categoria').innerHTML = "categoria";
	document.getElementById('txt_categoria').style.fontWeight = 'normal';
	DivSelect();
	nocache = Math.floor(Math.random()*100);
	completeAHAH.ahah('ricerca_offerta_provincia.php?nocache='+nocache+'&data='+data, 'div_select', '', 'GET', '');
}
function ajaxRicercaCitta(data, id_provincia) {
	if( id_provincia == '' )
		alert("Selezionare prima una provincia");
	else
	{
		document.getElementById('id_citta').value = "";
		document.getElementById('txt_citta').innerHTML = "localit&aacute;";
		document.getElementById('txt_citta').style.fontWeight = 'normal';
		document.getElementById('id_categoria').value = "";
		document.getElementById('txt_categoria').innerHTML = "categoria";
		document.getElementById('txt_categoria').style.fontWeight = 'normal';
		DivSelect();
		nocache = Math.floor(Math.random()*100);
		completeAHAH.ahah('ricerca_offerta_citta.php?nocache='+nocache+'&data='+data+'&provincia='+id_provincia, 'div_select', '', 'GET', '')
	}
}
function ajaxRicercaCategoria(data, id_provincia, id_citta) {
		DivSelect();
		nocache = Math.floor(Math.random()*100);
		completeAHAH.ahah('ricerca_offerta_categoria.php?nocache='+nocache+'&data='+data+'&provincia='+id_provincia+'&citta='+id_citta, 'div_select', '', 'GET', '')
}
function ricercaProvincia(id_prov, provincia) {
	document.getElementById('id_provincia').value = id_prov;
	document.getElementById('txt_provincia').innerHTML = provincia.substr(0,10);
	document.getElementById('txt_provincia').style.fontWeight = 'bold';
	DivSelect();
}
function ricercaCitta(id_citta, citta) {
	document.getElementById('id_citta').value = id_citta;
	document.getElementById('txt_citta').innerHTML = citta.substr(0,10);
	document.getElementById('txt_citta').style.fontWeight = 'bold';
	DivSelect();
}
function ricercaCategoria(id_categoria, categoria) {
	document.getElementById('id_categoria').value = id_categoria;
	document.getElementById('txt_categoria').innerHTML = categoria.substr(0,10);
	document.getElementById('txt_categoria').style.fontWeight = 'bold';
	DivSelect();
}
function makeRicerca() {
	document.getElementById('form_ricerca').submit();
}
function makeRicercaEventi() {
	document.getElementById('form_ricerca_eventi').submit();
}
function makeRicercaVolantini() {
	document.getElementById('form_ricerca_volantini').submit();
}

function resettaRicerca() {
	data = document.getElementById('data').value;
	window.location = 'resetta_ricerca.php?data='+data;
}
function ajaxRicercaProvNegozio(data) {
	document.getElementById('id_citta_negozio').value = "";
	document.getElementById('txt_citta_negozio').innerHTML = "localit&aacute;";
	document.getElementById('txt_citta_negozio').style.fontWeight = 'normal';
	document.getElementById('id_provincia_negozio').value = "";
	document.getElementById('txt_provincia_negozio').innerHTML = "provincia";
	document.getElementById('txt_provincia_negozio').style.fontWeight = 'normal';
//	document.getElementById('id_categoria_negozio').value = "";
//	document.getElementById('txt_categoria_negozio').innerHTML = "categoria";
//	document.getElementById('txt_categoria_negozio').style.fontWeight = 'normal';
	DivSelect();
	nocache = Math.floor(Math.random()*100);
	completeAHAH.ahah('ricerca_negozio_provincia.php?nocache='+nocache+'&data='+data, 'div_select', '', 'GET', '');
}
function ajaxRicercaCittaNegozio(data, id_provincia) {
	if( id_provincia == '' )
		alert("Selezionare prima una provincia");
	else
	{
		document.getElementById('id_citta_negozio').value = "";
		document.getElementById('txt_citta_negozio').innerHTML = "localit&aacute;";
		document.getElementById('txt_citta_negozio').style.fontWeight = 'normal';
		document.getElementById('id_categoria_negozio').value = "";
		document.getElementById('txt_categoria_negozio').innerHTML = "categoria ";
		document.getElementById('txt_categoria_negozio').style.fontWeight = 'normal';
		DivSelect();
		nocache = Math.floor(Math.random()*100);
		completeAHAH.ahah('ricerca_negozio_citta.php?nocache='+nocache+'&data='+data+'&provincia='+id_provincia, 'div_select', '', 'GET', '')
	}
}
function ajaxRicercaCategoriaNegozio(data, id_provincia, id_citta) {
		DivSelect();
		nocache = Math.floor(Math.random()*100);
		completeAHAH.ahah('ricerca_negozio_categoria.php?nocache='+nocache+'&data='+data+'&provincia='+id_provincia+'&citta='+id_citta, 'div_select', '', 'GET', '')
}
function ricercaProvinciaNegozio(id_prov, provincia) {
	document.getElementById('id_provincia_negozio').value = id_prov;
	document.getElementById('txt_provincia_negozio').innerHTML = provincia;
	document.getElementById('txt_provincia_negozio').style.fontWeight = 'bold';
	DivSelect();
}
function ricercaCittaNegozio(id_citta, citta) {
	document.getElementById('id_citta_negozio').value = id_citta;
	document.getElementById('txt_citta_negozio').innerHTML = citta;
	document.getElementById('txt_citta_negozio').style.fontWeight = 'bold';
	DivSelect();
}
function ricercaCategoriaNegozio(id_categoria, categoria) {
	document.getElementById('id_categoria_negozio').value = id_categoria;
	document.getElementById('txt_categoria_negozio').innerHTML = categoria;
	document.getElementById('txt_categoria_negozio').style.fontWeight = 'bold';
	DivSelect();
}
function makeRicercaNegozio() {
	if( document.getElementById('id_categoria_negozio').value != '' )
		document.getElementById('form_ricerca_negozio').submit();
	else
		alert('Selezionare una categoria per ricercare un negozio');	
}

function alt_sub_in(testo) {
   	scrolltop = document.documentElement.scrollTop;
	scrollleft = document.documentElement.scrollLeft;
	leftPosition = posx + scrollleft;
	topPosition = posy + scrolltop;
	if( nomebrowser != 'explorer' )
	{
		leftPosition = posx - scrollleft;
		topPosition = posy - scrolltop;
	}
	document.getElementById('alt_txt_negozio').innerHTML = testo;
	document.getElementById('alt_txt_negozio').style.top = topPosition - 12+'px';
	document.getElementById('alt_txt_negozio').style.left = leftPosition+'px';
	document.getElementById('alt_txt_negozio').style.visibility = 'visible';
}
function alt_sub_out() {
	document.getElementById('alt_txt_negozio').style.visibility = 'hidden';
}

function alt_offerta_in() {
   	scrolltop = document.documentElement.scrollTop;
	scrollleft = document.documentElement.scrollLeft;
	leftPosition = posx + scrollleft;
	topPosition = posy + scrolltop;
	if( nomebrowser != 'explorer' )
	{
		leftPosition = posx - scrollleft;
		topPosition = posy - scrolltop;
	}
	document.getElementById('alt_txt_trovaofferta').style.top = topPosition+'px';
	document.getElementById('alt_txt_trovaofferta').style.left = leftPosition+'px';
	document.getElementById('alt_txt_trovaofferta').style.visibility = 'visible';
}
function alt_offerta_out() {
	document.getElementById('alt_txt_trovaofferta').style.visibility = 'hidden';
}
function alt_negozio_in() {
   	scrolltop = document.documentElement.scrollTop;
	scrollleft = document.documentElement.scrollLeft;
	leftPosition = posx + scrollleft;
	topPosition = posy + scrolltop;
	if( nomebrowser != 'explorer' )
	{
		leftPosition = posx - scrollleft;
		topPosition = posy - scrolltop;
	}
	document.getElementById('alt_txt_trovanegozio').style.top = topPosition+'px';
	document.getElementById('alt_txt_trovanegozio').style.left = leftPosition+'px';
	document.getElementById('alt_txt_trovanegozio').style.visibility = 'visible';
}
function alt_negozio_out() {
	document.getElementById('alt_txt_trovanegozio').style.visibility = 'hidden';
}

function alt_categoria_in() {
   	scrolltop = document.documentElement.scrollTop;
	scrollleft = document.documentElement.scrollLeft;
	leftPosition = posx + scrollleft;
	topPosition = posy + scrolltop;
	if( nomebrowser != 'explorer' )
	{
		leftPosition = posx - scrollleft;
		topPosition = posy - scrolltop;
	}
	document.getElementById('alt_txt_categoria').style.top = topPosition+'px';
	document.getElementById('alt_txt_categoria').style.left = leftPosition+'px';
	document.getElementById('alt_txt_categoria').style.visibility = 'visible';
}
function alt_categoria_out() {
	document.getElementById('alt_txt_categoria').style.visibility = 'hidden';
}

function alt_offerteoggi_in() {
   	scrolltop = document.documentElement.scrollTop;
	scrollleft = document.documentElement.scrollLeft;
	leftPosition = posx + scrollleft - 242;
	topPosition = posy + scrolltop;
	if( nomebrowser != 'explorer' )
	{
		leftPosition = posx - scrollleft - 242;
		topPosition = posy - scrolltop;
	}
	document.getElementById('alt_txt_offerteoggi').style.top = topPosition+'px';
	document.getElementById('alt_txt_offerteoggi').style.left = leftPosition+'px';
	document.getElementById('alt_txt_offerteoggi').style.visibility = 'visible';
}
function alt_offerteoggi_out() {
	document.getElementById('alt_txt_offerteoggi').style.visibility = 'hidden';
}
function alt_dataoggi_in() {
   	scrolltop = document.documentElement.scrollTop;
	scrollleft = document.documentElement.scrollLeft;
	leftPosition = posx + scrollleft - 242;
	topPosition = posy + scrolltop;
	if( nomebrowser != 'explorer' )
	{
		leftPosition = posx - scrollleft - 242;
		topPosition = posy - scrolltop;
	}
	document.getElementById('alt_txt_dataoggi').style.top = topPosition+'px';
	document.getElementById('alt_txt_dataoggi').style.left = leftPosition+'px';
	document.getElementById('alt_txt_dataoggi').style.visibility = 'visible';
}
function alt_dataoggi_out() {
	document.getElementById('alt_txt_dataoggi').style.visibility = 'hidden';
}
function recupera_password() {
	DivSelect();
	nocache = Math.floor(Math.random()*100);
	completeAHAH.ahah('recupera.php?nocache='+nocache, 'div_select', '', 'GET', '');
}
function recupera_password2(username) {
	nocache = Math.floor(Math.random()*100);
	if( username != '' )
		completeAHAH.ahah('recupera.php?nocache='+nocache+'&username='+username, 'div_select', '', 'GET', '');
}
function recupera_password3(risposta, id_utente) {
	nocache = Math.floor(Math.random()*100);
	if( risposta != '' )
		completeAHAH.ahah('recupera.php?nocache='+nocache+'&risposta='+risposta+'&id_utente='+id_utente, 'div_select', '', 'GET', '');
}
function ajax_giorno_offerta()
{
	document.getElementById('id_negozio').value = '';
	document.getElementById('no_negozio').value = '';
	document.getElementById('no_prodotto').value = '';
	DivSelect();
	nocache = Math.floor(Math.random()*100);
	completeAHAH.ahah('contatti_giorno_offerta.php?nocache='+nocache, 'div_select', '', 'GET', '');
}
function contatti_sel_giorno(data)
{
	document.getElementById('no_giorno').value = data;
	DivSelect();	
}
function ajax_nome_negozio(data)
{
	if( data == "" ) 
		alert("Attenzione, selezionare prima la data dell'offerta");
	else
	{
		document.getElementById('id_negozio').value = '';
		document.getElementById('no_prodotto').value = '';
		DivSelect();
		nocache = Math.floor(Math.random()*100);
		completeAHAH.ahah('contatti_nome_negozio.php?nocache='+nocache+'&data='+data, 'div_select', '', 'GET', '');
	}
}
function contatti_sel_negozio(id_negozio, nome_negozio)
{
	document.getElementById('id_negozio').value = id_negozio;
	document.getElementById('no_negozio').value = nome_negozio;
	DivSelect();
}
function ajax_prodotto(data, id_negozio)
{
	if( data == "" ) 
		alert("Attenzione, selezionare prima la data dell'offerta");
	else if( id_negozio == "" )
		alert("Attenzione, selezionare prima un negozio");
	else
	{
		document.getElementById('no_prodotto').value = '';
		DivSelect();
		nocache = Math.floor(Math.random()*100);
		completeAHAH.ahah('contatti_prodotto.php?nocache='+nocache+'&data='+data+'&id_negozio='+id_negozio, 'div_select', '', 'GET', '');
	}
}
function contatti_sel_prodotto(id_prodotto, prodotto)
{
	document.getElementById('id_prodotto').value = id_prodotto;
	document.getElementById('no_prodotto').value = prodotto;
	DivSelect();
}
function form_contatti()
{
	nome = document.getElementById('nome').value;
	cognome = document.getElementById('cognome').value;
	malfunzionamento = document.getElementById('malfunzionamento').value;

	if(nome == "")
	{
		alert("Attenzione, il campo nome \u00E8 obbligatorio!");
		document.getElementById('nome').focus();
	}
	else if(cognome == "")
	{
		alert("Attenzione, il campo cognome \u00E8 obbligatorio!");
		document.getElementById('cognome').focus();
	}
	else if(malfunzionamento == "")
	{
		alert("Attenzione, inserire una piccola descrizione del malfunzionamento!");
		document.getElementById('malfunzionamento').focus();
	}
	else
		document.getElementById('invio_contatti').submit();

}
function form_no_offerte()
{
	nome = document.getElementById('no_nome').value;
	cognome = document.getElementById('no_cognome').value;
	giorno = document.getElementById('no_giorno').value;
	id_negozio = document.getElementById('id_negozio').value;
	id_prodotto = document.getElementById('id_prodotto').value;
	orario = document.getElementById('no_orario').value;

	if( nome == "" )
	{
		alert("Attenzione, il campo nome \u00E8 obbligatorio");
		document.getElementById('no_nome').focus();
	}
	else if( cognome == "" )
	{
		alert("Attenzione, il campo cognome \u00E8 obbligatorio");
		document.getElementById('no_cognome').focus();
	}
	else if( giorno == "" )
	{
		alert("Attenzione, il campo giorno \u00E8 obbligatorio");
		document.getElementById('no_giorno').focus();
	}
	else if( id_negozio == "" )
	{
		alert("Attenzione, selezionare un negozio");
		document.getElementById('no_negozio').focus();
	}
	else if( id_prodotto == "" )
	{
		alert("Attenzione, selezionare un prodotto");
		document.getElementById('no_prodotto').focus();
	}
	else if( orario == "" )
	{
		alert("Attenzione, selezionare un orario");
		document.getElementById('no_orario').focus();
	}
	else
		document.getElementById('invio_offerta').submit();
}
function errore_form(iddiv)
{
	document.getElementById(iddiv).style.color = '#FF0000';
	document.getElementById(iddiv).style.fontWeight = 'bold';
}
function caricamento_in_corso()
{
	document.getElementById('div_caricamento').style.visibility = 'visible';
		document.getElementById('foto').submit();
}
function form_cerca()
{
	keyword = document.getElementById('cerca').value;
	if( (keyword != "") && (keyword != "cerca") ) window.location = 'index.php?cerca_txt='+keyword;
	else alert("Per effettuare una ricerca inserisci un testo");
}
function popup_regalo(id_offerta)
{
	url = 'popup_regalo.php?id_regalo='+id_offerta;
	newwindow=window.open(url,'name','height=710,width=320');
}
function popup_calendario()
{
	url = 'calendario_regali.html';
	newwindow=window.open(url,'name','height=710,width=320');
}
function form_scrivi_post()
{
	titolo = document.getElementById('titolo').value;
	testo_post = document.getElementById('testo_post').value;
	photo_uno = document.getElementById('photo_uno').value;
	photo_due = document.getElementById('photo_due').value;
	categoria_post = document.getElementById('categoria_post').value;
	if( (titolo.length > 150) || (titolo  == '') )
		alert('Attenzione, il titolo del post non puo superare i 150 caratteri o essere vuoto');
//	else if( (testo_post.length > 5000)  || (testo_post  == '') )
//		alert('Attenzione, il corpo del post non puo superare i 5000 caratteri o essere vuoto');
	else if( categoria_post == '' )
		alert('Attenzione, devi selezionare una categoria per il post');
	else
		document.getElementById('form_scrivi_post').submit();
}
function elimina_photo(quale)
{
	 if( confirm("Sei sicuro di voler eliminare la foto "+quale+"?") )
		 document.getElementById(quale).value = "";
}
function elimina_photo_evento(quale)
{
	 if( confirm("Sei sicuro di voler eliminare la foto "+quale+"?") )
	 {
		 quale_risposta = "risposta_"+quale;
		 quale_testo= "testo_"+quale;
		 document.getElementById(quale).value = "";
		 document.getElementById(quale_risposta).innerHTML = '';
		 document.getElementById(quale_testo).innerHTML = document.getElementById(quale_testo).innerHTML.substring(0,23);
	 }
}
function conta_caratteri()
{
	txt_commento = document.getElementById('commento').value;
	if( txt_commento.length > 2000 )
		document.getElementById('commento').value = document.getElementById('commento').value.substr(0, 2000);

	if( txt_commento != "" )
		caratteri = 2000 - txt_commento.length;
	else
		caratteri = 2000;
	document.getElementById('caratteri_rimanenti').innerHTML = caratteri;
}
function posta_commento()
{
	nominativo = document.getElementById('nominativo').value;
	email = document.getElementById('email').value;
	commento = document.getElementById('commento').value;
	if( nominativo == '' )
		alert("Attenzione, devi inserire il tuo nominativo");
	else if( email == '' ) 
		alert("Attenzione, l'email è obbligatoria");
	else if( !email_valida(email) )
		alert("Attenzione, controllare l'email inserita");
	else if( commento == '' )
		alert("Attenzione è obbligatorio inserire il commento!");
	else
		document.getElementById('form_posta_commento').submit();
}
old_pkg = "";
function acquista_pacchetto(immagine, id )
{
	if( old_pkg == "" )
	{
		document.getElementById(immagine).src = "img/btn_pacchetto_on.png";
		old_pkg = immagine;
	}
	else
	{
		document.getElementById(old_pkg).src = "img/btn_pacchetto_off.png";
		document.getElementById(immagine).src = "img/btn_pacchetto_on.png";
		old_pkg = immagine;
	
	}
	document.getElementById("id_pacchetto").value = id;
}
function invia_acquisto()
{
	if( document.getElementById("id_pacchetto").value == "" )
		alert("Selezionare un pacchetto");
	else
		document.getElementById("acquista_offerte").submit();
}
valore_check = "";
function tipo_pagamento(valore)
{
	valore_check = valore;
}
function completa_acquisto()
{
	if( valore_check == "" )
		alert("Selezionare un tipo di pagamento");
	else
		document.getElementById("completa_aquisto").submit();
}
function vai_alla_banca()
{
	document.getElementById("form_banca").submit();
}
function segnala_commento(id_commento)
{	
	url = 'popup_segnalazione.php?id='+id_commento;
	newwindow=window.open(url,'segnalazione','height=300,width=327');	
}
function check_segnalazione()
{
	nominativo = document.getElementById("nominativo").value;
	email = document.getElementById("email").value;
	motivazione = document.getElementById("motivazione").value;
	
	if( nominativo == "" )
	{
		alert("Attenzione inserire nome e cognome");
		return false;
	}
	else if( email == "" )
	{
		alert("Attenzione inserire l'email");
		return false;
	}
	else if( !email_valida(email) )
	{
		alert("Attenzione, controllare l'email inserita");	
		return false;
	} 
	else if( motivazione == "" )
	{
		alert("Attenzione inserire una motivazione");
		return false;
	}
	else
		return true;
}
function ar_posta_commento()
{
	commento = document.getElementById('commento').value;
	if( commento == '' )
		alert("Attenzione è obbligatorio inserire il commento!");
	else
		document.getElementById('form_posta_commento').submit();
}
function ajaxCategoriaPost() {
		DivSelect();
		nocache = Math.floor(Math.random()*100);
		completeAHAH.ahah('ricerca_post_categoria.php?nocache='+nocache, 'div_select', '', 'GET', '');
}
function ajaxAutorePost() {
		DivSelect();
		nocache = Math.floor(Math.random()*100);
		completeAHAH.ahah('ricerca_post_autore.php?nocache='+nocache, 'div_select', '', 'GET', '');
}

function ajaxDataPost() {
		DivSelect();
		nocache = Math.floor(Math.random()*100);
		completeAHAH.ahah('ricerca_post_data.php?nocache='+nocache, 'div_select', '', 'GET', '');
}
function controlla_data_evento()
{
	document.getElementById('giorno_evento').value = 0;
	dal = document.getElementById('giorno_dal').selectedIndex;
	al = document.getElementById('giorno_al').selectedIndex;
	if( al <= dal )
	{
		if( al > 0 )
		{
			alert('Attenzione controllare il periodo selezionato');
			document.getElementById('giorno_al').selectedIndex = dal + 1;
		}
	}
}
function controlla_data_volantino()
{
	dal = document.getElementById('giorno_dal').selectedIndex;
	al = document.getElementById('giorno_al').selectedIndex;
	if( al <= dal )
	{
		if( al > 0 )
		{
			alert('Attenzione controllare il periodo selezionato');
			document.getElementById('giorno_al').selectedIndex = dal + 1;
		}
	}
}
function controlla_date_evento()
{
	document.getElementById('giorno_dal').value = 0;
	document.getElementById('giorno_al').value = 0;	
}
function check_presso_attivita()
{
	valore = document.getElementById('presso_attivita').value;
	if( (valore == "") || (valore == 0) )
	{
		document.getElementById('presso_attivita').value = 1;
		document.getElementById('img_sel_attivita').src = "img/btn_select_eventoOn.jpg";
		document.getElementById('nome_locale').disabled = true;
		document.getElementById('indirizzo_locale').disabled = true;		
		document.getElementById('citta_locale').disabled = true;
		document.getElementById('provincia_locale').disabled = true;
		
	}
	else
	{
		document.getElementById('presso_attivita').value = 0;
		document.getElementById('img_sel_attivita').src = "img/btn_select_eventoOff.jpg";		
		document.getElementById('nome_locale').disabled = false;
		document.getElementById('indirizzo_locale').disabled = false;		
		document.getElementById('citta_locale').disabled = false;
		document.getElementById('provincia_locale').disabled = false;

	}
}
function form_inserisci_evento()
{
	titolo = document.getElementById('titolo_evento').value;
	testo_post = document.getElementById('testo_evento').value;
	photo_uno = document.getElementById('photo_uno').value;
	photo_due = document.getElementById('photo_due').value;
	categoria_evento = document.getElementById('categoria_evento').value;
	giorno_evento = document.getElementById('giorno_evento').value;
	giorno_dal = document.getElementById('giorno_dal').value;
	giorno_al = document.getElementById('giorno_al').value;	
	presso_attivita = document.getElementById('presso_attivita').value;		
	nome_locale = document.getElementById('nome_locale').value;			
	
	if( (titolo.length > 150) || (titolo  == '') )
		alert('Attenzione, il titolo dell\'evento non puo superare i 150 caratteri o essere vuoto');
//	else if( (testo_post.length > 5000)  || (testo_post  == '') )
//		alert('Attenzione, il corpo del post non puo superare i 5000 caratteri o essere vuoto');
	else if( categoria_evento == '' )
		alert('Attenzione, devi selezionare una categoria per l\'evento');
	else if( (giorno_evento == 0 ) && ((giorno_dal == 0) || (giorno_al == 0)) )
		alert('Attenzione, devi selezionare una data per l\'evento');
	else if( (presso_attivita != 1 ) && (nome_locale == "" ) )
		alert('Attenzione, devi inserire il locale dove si svolgera\' l\'evento');	
	else if ( controlla_giorni_evento(31) )
		alert('Attenzione, scegli un giorno di pubblicazione dell\'evento');	
	else
		document.getElementById('form_inserisci_evento').submit();
}
function form_modifica_evento()
{
	titolo = document.getElementById('titolo_evento').value;
	testo_post = document.getElementById('testo_evento').value;
	photo_uno = document.getElementById('photo_uno').value;
	photo_due = document.getElementById('photo_due').value;
	categoria_evento = document.getElementById('categoria_evento').value;
	giorno_evento = document.getElementById('giorno_evento').value;
	giorno_dal = document.getElementById('giorno_dal').value;
	giorno_al = document.getElementById('giorno_al').value;	
	presso_attivita = document.getElementById('presso_attivita').value;		
	nome_locale = document.getElementById('nome_locale').value;			
	
	if( (titolo.length > 150) || (titolo  == '') )
		alert('Attenzione, il titolo dell\'evento non puo superare i 150 caratteri o essere vuoto');
//	else if( (testo_post.length > 5000)  || (testo_post  == '') )
//		alert('Attenzione, il corpo del post non puo superare i 5000 caratteri o essere vuoto');
	else if( categoria_evento == '' )
		alert('Attenzione, devi selezionare una categoria per l\'evento');
	else if( (giorno_evento == 0 ) && ((giorno_dal == 0) || (giorno_al == 0)) )
		alert('Attenzione, devi selezionare una data per l\'evento');
	else if( (presso_attivita != 1 ) && (nome_locale == "" ) )
		alert('Attenzione, devi inserire il locale dove si svolgera\' l\'evento');	
	else
		document.getElementById('form_inserisci_evento').submit();
}

function ajaxRicercaEventiProv(data) {
	document.getElementById('id_citta_eventi').value = "";
	document.getElementById('txt_citta_eventi').innerHTML = "localit&aacute;";
	document.getElementById('txt_citta_eventi').style.fontWeight = 'normal';
	document.getElementById('id_provincia_eventi').value = "";
	document.getElementById('txt_provincia_eventi').innerHTML = "provincia";
	document.getElementById('txt_provincia_eventi').style.fontWeight = 'normal';
	document.getElementById('id_categoria_eventi').value = "";
	document.getElementById('txt_categoria_eventi').innerHTML = "categoria";
	document.getElementById('txt_categoria_eventi').style.fontWeight = 'normal';
	DivSelect();
	nocache = Math.floor(Math.random()*100);
	completeAHAH.ahah('ricerca_eventi_provincia.php?nocache='+nocache+'&data='+data, 'div_select', '', 'GET', '');
}
function ajaxRicercaEventiCitta(data, id_provincia) {
	if( id_provincia == '' )
		alert("Selezionare prima una provincia");
	else
	{
		document.getElementById('id_citta_eventi').value = "";
		document.getElementById('txt_citta_eventi').innerHTML = "localit&aacute;";
		document.getElementById('txt_citta_eventi').style.fontWeight = 'normal';
		document.getElementById('id_categoria_eventi').value = "";
		document.getElementById('txt_categoria_eventi').innerHTML = "categoria";
		document.getElementById('txt_categoria_eventi').style.fontWeight = 'normal';
		DivSelect();
		nocache = Math.floor(Math.random()*100);
		completeAHAH.ahah('ricerca_eventi_citta.php?nocache='+nocache+'&data='+data+'&provincia='+id_provincia, 'div_select', '', 'GET', '')
	}
}
function ajaxRicercaEventiCategoria(data, id_provincia, id_citta) {
		DivSelect();
		nocache = Math.floor(Math.random()*100);
		completeAHAH.ahah('ricerca_eventi_categoria.php?nocache='+nocache+'&data='+data+'&provincia='+id_provincia+'&citta='+id_citta, 'div_select', '', 'GET', '')
}
function ricercaProvinciaEventi(id_prov, provincia) {
	document.getElementById('id_provincia_eventi').value = id_prov;
	document.getElementById('txt_provincia_eventi').innerHTML = provincia.substr(0,10);
	document.getElementById('txt_provincia_eventi').style.fontWeight = 'bold';
	DivSelect();
}
function ricercaCittaEventi(id_citta, citta) {
	document.getElementById('id_citta_eventi').value = id_citta;
	document.getElementById('txt_citta_eventi').innerHTML = citta.substr(0,10);
	document.getElementById('txt_citta_eventi').style.fontWeight = 'bold';
	DivSelect();
}
function ricercaCategoriaEventi(id_categoria, categoria) {
	document.getElementById('id_categoria_eventi').value = id_categoria;
	document.getElementById('txt_categoria_eventi').innerHTML = categoria.substr(0,10);
	document.getElementById('txt_categoria_eventi').style.fontWeight = 'bold';
	DivSelect();
}
function ricercaProvinciaVolantini(id_prov, provincia) {
	document.getElementById('id_provincia').value = id_prov;
	document.getElementById('txt_provincia_volantini').innerHTML = provincia.substr(0,10);
	document.getElementById('txt_provincia_volantini').style.fontWeight = 'bold';
	DivSelect();
}
function ricercaCittaVolantini(id_citta, citta) {
	document.getElementById('id_citta').value = id_citta;
	document.getElementById('txt_citta_volantini').innerHTML = citta.substr(0,10);
	document.getElementById('txt_citta_volantini').style.fontWeight = 'bold';
	DivSelect();
}
function ricercaCategoriaVolantini(id_categoria, categoria) {
	document.getElementById('id_categoria').value = id_categoria;
	document.getElementById('txt_categoria_volantini').innerHTML = categoria.substr(0,10);
	document.getElementById('txt_categoria_volantini').style.fontWeight = 'bold';
	DivSelect();
}
function controlla_giorni_evento(giorni)
{
	for( i=0; i < giorni; i++ )
	{
		if( document.getElementById('giorni_evento_'+i).checked )
			return false;
	}
	return true;
}
function seleziona_tutti_giorni_evento(giorni)
{
	for( i=0; i < giorni; i++ )
	{
		document.getElementById('giorni_evento_'+i).checked = "true";
	}
}
function deseleziona_tutti_giorni_evento(giorni)
{
	for( i=0; i < giorni; i++ )
	{
		document.getElementById('giorni_evento_'+i).checked = "";
	}
}
function controlla_giorni_volantino(giorni)
{
	for( i=0; i < giorni; i++ )
	{
		if( document.getElementById('giorni_volantino_'+i).checked )
			return false;
	}
	return true;
}
function seleziona_tutti_giorni_volantino(giorni)
{
	for( i=0; i < giorni; i++ )
	{
		document.getElementById('giorni_volantino_'+i).checked = "true";
	}
}
function deseleziona_tutti_giorni_volantino(giorni)
{
	for( i=0; i < giorni; i++ )
	{
		document.getElementById('giorni_volantino_'+i).checked = "";
	}
}

function seleziona_tutti_giorni_offerta(giorni)
{
	for( i=0; i < giorni; i++ )
	{
		document.getElementById('giorni_offerta_'+i).checked = "true";
	}
	annulla_select();
}
function deseleziona_tutti_giorni_offerta(giorni)
{
	for( i=0; i < giorni; i++ )
	{
		document.getElementById('giorni_offerta_'+i).checked = "";
	}
}
function form_inserisci_volantino()
{
	titolo = document.getElementById('titolo_volantino').value;
	//testo_volantino = document.getElementById('testo_volantino').value;
	volantino_upload = document.getElementById("volantino_upload").value;
	categoria_volantino = document.getElementById('categoria_volantino').value;
	giorno_dal = document.getElementById('giorno_dal').value;
	giorno_al = document.getElementById('giorno_al').value;	
	var lastChars = volantino_upload;
		lastChars = lastChars.substring(lastChars.length-4,lastChars.length);
		lastChars = lastChars.toLowerCase();
	
	if( (titolo.length > 150) || (titolo  == '') )
		alert('Attenzione, il titolo del volantino non puo superare i 150 caratteri o essere vuoto');
	else if(volantino_upload == '') {
		alert('Attenzione, devi inserire un file per il volantino');
	} else if(volantino_upload && volantino_upload!= '' &&  lastChars!=".pdf") {
		alert("Attenzione, il formato del volantino non è corretto, ti ricordiamo che accettiamo solo file PDF");								
	}
	else if( categoria_volantino == '' )
		alert('Attenzione, devi selezionare una categoria per il volantino');
	else if( (giorno_dal == 0) || (giorno_al == 0) )
		alert('Attenzione, devi selezionare le date di validita per il volantino');
	else if ( controlla_giorni_volantino(31) )
		alert('Attenzione, scegli un giorno di pubblicazione del volantino');	
	else
		document.getElementById('form_inserisci_volantino').submit();
}

/*function delCartella(cartella,location) {
	ajax_post("/oggioffroio_test/ajax_del_cartella.php",cartella);
	document.location.href=location;
	
}*/

function form_modifica_volantino()
{
	titolo = document.getElementById('titolo_volantino').value;
	//testo_volantino = document.getElementById('testo_volantino').value;
	volantino_upload = document.getElementById("volantino_upload").value;
	categoria_volantino = document.getElementById('categoria_volantino').value;
	giorno_dal = document.getElementById('giorno_dal').value;
	giorno_al = document.getElementById('giorno_al').value;	
	var lastChars = volantino_upload;
		lastChars = lastChars.substring(lastChars.length-4,lastChars.length);
		lastChars = lastChars.toLowerCase();
	
	if( (titolo.length > 150) || (titolo  == '') )
		alert('Attenzione, il titolo del volantino non puo superare i 150 caratteri o essere vuoto');
	else if(volantino_upload == '') {
		alert('Attenzione, devi inserire un file per il volantino');
	} else if(volantino_upload && volantino_upload!= '' &&  lastChars!=".pdf") {
		alert("Attenzione, il formato del volantino non è corretto, ti ricordiamo che accettiamo solo file PDF");								
	}
	else if( categoria_volantino == '' )
		alert('Attenzione, devi selezionare una categoria per il volantino');
	else if( (giorno_dal == 0) || (giorno_al == 0) )
		alert('Attenzione, devi selezionare le date di validita per il volantino');
	else
		document.getElementById('form_inserisci_volantino').submit();
}
function zoomVolantino()
{
	document.getElementById('zoom_volantino').style.visibility = 'visible';
}
function chiudiVolantino()
{
	document.getElementById('zoom_volantino').style.visibility = 'hidden';
}
function seleziona_registrazione(selezione)
{
	registrazione_temporanea = document.getElementById('chk_reg_temporanea');
	registrazione_definitiva = document.getElementById('chk_reg_definitiva');
	if( selezione == 'temporanea' )
	{
		registrazione_definitiva.checked = '';
		if( registrazione_temporanea.checked ) 
		{
			document.getElementById('container_registrazione_temporanea').style.display = 'inline';
			document.getElementById('sottotitolo_temporanea').style.borderBottom = '0px';
			document.getElementById('container_registrazione_temporanea').style.borderBottom = '1px dotted #CCCCCC';
			document.getElementById('container_registrazione_temporanea').style.paddingBottom = '20px';
			document.getElementById('container_registrazione_utente').style.display = 'none';
		}
		else
			document.getElementById('container_registrazione_temporanea').style.display = 'none';		
	}
	else if( selezione == 'definitiva' )
	{
		registrazione_temporanea.checked = '';
		if( registrazione_definitiva.checked ) 
		{
			document.getElementById('container_registrazione_utente').style.display = 'inline';
			document.getElementById('sottotitolo_temporanea').style.borderBottom = '1px dotted #CCCCCC';
			document.getElementById('sottotitolo_definitiva').style.borderBottom = '0px';
			document.getElementById('container_registrazione_utente').style.paddingBottom = '20px';			
			document.getElementById('container_registrazione_temporanea').style.display = 'none';
		}
		else
			document.getElementById('container_registrazione_utente').style.display = 'none';
	}
}
valore_voto = "";
function voto_selezionato(valore)
{
	valore_voto = valore;
}
function vota_sondaggio_offerta(id_offerta, id_utente) {
	if( valore_voto == "" )
		alert('Selezionare un parere!');
	else
	{
		nocache = Math.floor(Math.random()*100);
		completeAHAH.ahah('vota_sondaggio_offerta.php?nocache='+nocache+'&id_offerta='+id_offerta+'&id_utente='+id_utente+'&id_voto='+valore_voto, 'sondaggio_offerta', '', 'GET', '')
	}
}
function vota_sondaggio_volantino(id_volantino, id_utente) {
	if( valore_voto == "" )
		alert('Selezionare un parere!');
	else
	{
		nocache = Math.floor(Math.random()*100);
		completeAHAH.ahah('vota_sondaggio_volantino.php?nocache='+nocache+'&id_volantino='+id_volantino+'&id_utente='+id_utente+'&id_voto='+valore_voto, 'sondaggio_offerta', '', 'GET', '')
	}
}
function vota_sondaggio_evento(id_evento, id_utente) {
	if( valore_voto == "" )
		alert('Selezionare un parere!');
	else
	{
		nocache = Math.floor(Math.random()*100);
		completeAHAH.ahah('vota_sondaggio_evento.php?nocache='+nocache+'&id_evento='+id_evento+'&id_utente='+id_utente+'&id_voto='+valore_voto, 'sondaggio_offerta', '', 'GET', '')
	}
}
function negozio_preferito(id_utente, id_negozio ) {
	if( (id_utente != "") && (id_negozio != "")	)
	{
		nocache = Math.floor(Math.random()*100);
		completeAHAH.ahah('aggiungi_negozio_preferito.php?nocache='+nocache+'&id_utente='+id_utente+'&id_negozio='+id_negozio, 'btn_box_right', '', 'GET', '')		
	}
}
function elimina_negozio_preferito(id_utente, id_negozio ) {
	if( (id_utente != "") && (id_negozio != "")	)
	{
		nocache = Math.floor(Math.random()*100);
		completeAHAH.ahah('elimina_negozio_preferito.php?nocache='+nocache+'&id_utente='+id_utente+'&id_negozio='+id_negozio, 'btn_box_right', '', 'GET', '')		
	}
}
function resetta_voto() {
	for(i=1; i<= 5; i++ )
	{
		div = "stella_"+i;
		document.getElementById(div).innerHTML = '<img src="img/img_stella_off.png" />';
	}		
}

function set_voto_negozio(id_utente, id_negozio) {
		nocache = Math.floor(Math.random()*100);
		completeAHAH.ahah('aggiungi_voto_negozio.php?nocache='+nocache+'&id_utente='+id_utente+'&id_negozio='+id_negozio+'&voto=+'+voto_negozio, 'btn_vota_negozio', '', 'GET', '')			
		completeAHAH.ahah('stelle_negozio.php?nocache='+nocache+'&id_utente='+id_utente+'&id_negozio='+id_negozio, 'txt_voto', '', 'GET', '')			
}
voto_negozio = "";
function selezione_voto_negozio(voto) {
	resetta_voto();
	for(i=1; i<= 5; i++ )
	{
		div = "stella_"+i;
		document.getElementById(div).innerHTML = '<img style="cursor: pointer;" src="img/img_stella_on.png" />';
		voto_negozio = voto;
		if( i == voto ) break;
	}
}
function cambio_itxp() {
	window.location = "vetrina_prodotti.php?itxp="+document.getElementById('itxp').value;
}
function form_prodotto()
{
	nome_prodotto = document.getElementById('nome_prodotto').value;
	descrizione_prodotto = document.getElementById('descrizione_prodotto').value;
	prezzo = document.getElementById('prezzo').value;
	photo = document.getElementById('photo').value;
	prezzo = prezzo.replace(",",".");

	if( (nome_prodotto.length > 50) || (nome_prodotto  == '') )
		alert('Attenzione, il nome prodotto non puo superare i 50 caratteri o essere vuoto');
	else if(!IsNumeric(prezzo))
		alert('Attenzione, il prezzo del prodotto deve contenere solo numeri e non puo essere vuoto');
	else if(  parseFloat(prezzo) == 0 )
		alert('Attenzione, il prezzo del prodotto non puo essere uguale a zero');		
	else
		document.getElementById('form_crea_prodotto').submit();
}
function modifica_prodotto(prodotti)
{
	conta = 0;
	selezione = "";
	for(i=1; i<= prodotti; i++)
	{
		if( document.getElementById('prodotto_selezionato_'+i).checked )
		{
			conta++;
			selezione = 'prodotto_selezionato_'+i;
		}
	}
	if( conta == 0 )
		alert('Seleziona il prodotto da modificare');
	else if( conta > 1 )
		alert('Seleziona solo un prodotto alla volta');
	else
		window.location = "modifica_prodotto.php?id="+document.getElementById(selezione).value;
}
function cancella_prodotti(prodotti)
{
	conta = 0;
	selezione = "";
	for(i=1; i<= prodotti; i++)
	{
		if( document.getElementById('prodotto_selezionato_'+i).checked )
		{
			conta++;
			id_prodotto = document.getElementById('prodotto_selezionato_'+i).value;
			selezione += id_prodotto+"-";
		}
	}
	window.location = "cancella_prodotti.php?prodotti="+selezione;
}
function elimina_photo_prodotto()
{
	if( document.getElementById('photo').value == "" )
		alert('Nessuna immagine da eliminare');
	else if( confirm('Sei sicuro di voler eliminare l\'immagine?') )
		document.getElementById('photo').value = "";
		
}
function pubblica(stato,id_prodotto,pubblicati,max_pubblicati,div_id, tot_view, itxp)
{
	if( (pubblicati < max_pubblicati) || (stato == 0) )
	{
		nocache = Math.floor(Math.random()*100);	
		array_stato[div_id] = stato;
		completeAHAH.ahah('modifica_stato_prodotto.php?nocache='+nocache+'&stato='+stato+'&id_prodotto='+id_prodotto+'&div_id='+div_id+'&itxp='+itxp, 'stato_div_'+div_id, '', 'GET', '')		
		for(i=1, i <= tot_view; i++; )
		{

			div_att = i - 1;		
			if( div_att != div_id )
			{
				id_prodotti = document.getElementById('prodotto_selezionato_'+div_att).value;
				completeAHAH.ahah('aggiorna_stato_prodotto.php?nocache='+nocache+'&id_prodotto='+id_prodotti+'&div_id='+div_att+'&itxp='+itxp, 'stato_div_'+div_att, '', 'GET', '')			
			}
		}
	}
	else
		alert('Hai pubblicato il numero massimo consentito di prodotti nella tua vetrina');
}
function mostra_vetrina(id_negozio)
{
	nocache = Math.floor(Math.random()*100);	
	completeAHAH.ahah('mostra_vetrina.php?nocache='+nocache+'&id='+id_negozio, 'container_vetrina', '', 'GET', '')			
	document.getElementById('footer_container_vetrina').innerHTML = '<a href="javascript:nascondi_vetrina(\''+id_negozio+'\');">Nascondi</a>';
}
function nascondi_vetrina(id_negozio)
{
	nocache = Math.floor(Math.random()*100);	
	completeAHAH.ahah('nascondi_vetrina.php?nocache='+nocache+'&id='+id_negozio, 'container_vetrina', '', 'GET', '')			
	document.getElementById('footer_container_vetrina').innerHTML = '<a href="javascript:mostra_vetrina(\''+id_negozio+'\');">Mostra tutto</a>';
}
function vota_prodotto_negozio(id_prodotto, id_utente, id_negozio)
{
	nocache = Math.floor(Math.random()*100);	
	completeAHAH.ahah('vota_prodotto_negozio.php?nocache='+nocache+'&id_prodotto='+id_prodotto+'&id_utente='+id_utente+'&id_negozio='+id_negozio, 'voto_prodotto_'+id_prodotto, '', 'GET', '')				
}
div_box_commento = 0;
function aggiungi_commento_negozio(id_utente, id_negozio) {
	if( div_box_commento == 0 )
	{	
		larghezza = 300;
		altezza = 200;
    	scrolltop = document.documentElement.scrollTop;
		scrollleft = document.documentElement.scrollLeft;
		leftPosition = posx + scrollleft - larghezza;
		topPosition = posy + scrolltop;
		if( leftPosition < 10 ) leftPosition = 10;		
		if( nomebrowser != 'explorer' )
		{
			leftPosition = posx - scrollleft - larghezza ;
			topPosition = posy - scrolltop - altezza;
			if( leftPosition < 10 ) leftPosition = 10;
		}
		document.getElementById('box_form_aggiungi_commento').style.visibility = 'visible';
		document.getElementById('box_form_aggiungi_commento').style.display = 'block';
		document.getElementById('box_form_aggiungi_commento').style.top = topPosition+'px';
		document.getElementById('box_form_aggiungi_commento').style.left = leftPosition+'px';
		div_box_commento = 1;
		nocache = Math.floor(Math.random()*100);	
		completeAHAH.ahah('aggiungi_commento_negozio.php?nocache='+nocache+'&id_utente='+id_utente+'&id_negozio='+id_negozio, 'box_form_aggiungi_commento', '', 'GET', '')				
	}
	else
	{
		document.getElementById('box_form_aggiungi_commento').style.visibility = 'hidden';
		div_box_commento = 0;
	}
}
function invia_commento(id_utente, id_negozio) {
	commento = document.getElementById('commento').value;
	nocache = Math.floor(Math.random()*100);	
	completeAHAH.ahah('aggiungi_commento_negozio.php?nocache='+nocache+'&id_utente='+id_utente+'&id_negozio='+id_negozio+'&commento='+commento, 'box_form_aggiungi_commento', '', 'GET', '')					
}
function chiudi_box_commento() {
	document.getElementById('box_form_aggiungi_commento').style.visibility = 'hidden';
}
function rispondi_commento_negozio(id_commento, id_utente, id_negozio) {
	if( div_box_commento == 0 )
	{	
		larghezza = 300;
		altezza = 200;
    	scrolltop = document.documentElement.scrollTop;
		scrollleft = document.documentElement.scrollLeft;
		leftPosition = posx + scrollleft - larghezza;
		topPosition = posy + scrolltop;
		if( leftPosition < 10 ) leftPosition = 10;		
		if( nomebrowser != 'explorer' )
		{
			leftPosition = posx - scrollleft - larghezza ;
			topPosition = posy - scrolltop - altezza;
			if( leftPosition < 10 ) leftPosition = 10;
		}
		document.getElementById('box_form_aggiungi_commento').style.visibility = 'visible';
		document.getElementById('box_form_aggiungi_commento').style.display = 'block';
		document.getElementById('box_form_aggiungi_commento').style.top = topPosition+'px';
		document.getElementById('box_form_aggiungi_commento').style.left = leftPosition+'px';
		div_box_commento = 1;
		nocache = Math.floor(Math.random()*100);	
		completeAHAH.ahah('risposta_commento_negozio.php?nocache='+nocache+'&id_commento='+id_commento+'&id_utente='+id_utente+'&id_negozio='+id_negozio, 'box_form_aggiungi_commento', '', 'GET', '')				
	}
	else
	{
		document.getElementById('box_form_aggiungi_commento').style.visibility = 'hidden';
		div_box_commento = 0;
	}
}
function invia_risposta(id_commento, id_utente, id_negozio) {
	risposta = document.getElementById('risposta').value;
	nocache = Math.floor(Math.random()*100);	
	completeAHAH.ahah('risposta_commento_negozio.php?nocache='+nocache+'&id_commento='+id_commento+'&id_utente='+id_utente+'&id_negozio='+id_negozio+'&risposta='+risposta, 'box_form_aggiungi_commento', '', 'GET', '')					
}
function mostra_tutti_commenti(id_negozio) {
	nocache = Math.floor(Math.random()*100);	
	document.getElementById('btn_all_commento').innerHTML = "<a href=\"javascript:mostra_commenti('"+id_negozio+"');\">Riduci</a>";	
	document.getElementById('box_lista_commenti').style.clip="rect(0px,50px,50px,0px)";
	completeAHAH.ahah('mostra_tutticommenti_negozio.php?nocache='+nocache+'&id_negozio='+id_negozio, 'box_lista_commenti', '', 'GET', '')					
}
function mostra_commenti(id_negozio) {
	nocache = Math.floor(Math.random()*100);
	document.getElementById('btn_all_commento').innerHTML = "<a href=\"javascript:mostra_tutti_commenti('"+id_negozio+"');\">Mostra Tutto</a>";
	
	completeAHAH.ahah('mostra_commenti_negozio.php?nocache='+nocache+'&id_negozio='+id_negozio, 'box_lista_commenti', '', 'GET', '')					
}
//funzione ajax utile per molte cose
//variabile per una eventuale visualizzazione della risposta
var risposta_post = "";
function ajax_post(url, param)
{		
	var arg = url;
	//url = "content.php?q=" + url;
	var http_request = false;

	if (window.XMLHttpRequest)
	{ // Mozilla, Safari,...
		http_request = new XMLHttpRequest();

		if (http_request.overrideMimeType)
		{
		http_request.overrideMimeType('text/xml');
		// See note below about this line
		}
	} 
	else if (window.ActiveXObject)
	{ // IE
		try
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e)
		{
			try
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) {}
		}
	}

	if (!http_request)
	{
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}

	http_request.onreadystatechange = function() {returnContents(http_request);};
	http_request.open('POST', url);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  	http_request.setRequestHeader("Content-length", 3000);
  	http_request.setRequestHeader("Connection", "close");
	http_request.send("param="+param);
	//http_request.send("param="+param.replace("/","\/"));	
	//http_request.send("embed="+param.replace("&amp;",""));	
}

function returnContents(http_request)
{
	if (http_request.readyState == 4)
	{
		
		if (http_request.status == 200)
		{
			//document.getElementById("risultatoajax").value=http_request.responseText;
			//alert(http_request.responseText);
			risposta_post=http_request.responseText;
			
				/*if(http_request.responseText == "KO") {
					alert(stringAlert);
					//return false;
				}*/
	
			//document.getElementById("content").innerHTML=http_request.responseText;
			//div_content.innerHTML=http_request.responseText;
		}	
		else
		{
			alert('There was a problem with the request.');
		}
	}
}
