function isValidURL(field)
{
	var httpregex = /^(http+:\/\/)/;
	var urlregex = /^[\w-]+.[.\w-]*\w$/;
	
	var match = field.match(httpregex); 
	
	if (match)
	{
		match = field.substr(match[1].length,field.length)
		match = match.match(urlregex);
	}
		
	if (!match)
		return false;
	else 
		return true;
}

function isValidEmail(email)
{
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(email) && r2.test(email));
}

function feb(year){
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function no(n)
{
	for (var i = 1; i <= n; i++)
    {
		this[i]=31;
		if (i==4 || i==6 || i==9 || i==11)
        {
            this[i] = 30;
        }
		if (i==2)
        {
            this[i] = 29;
        }
   }
   return this
}

function isValidDate(day, month, year)
{
	array = no(12);
	if ((month == 2 && day > feb(year)) || day > array[month])
    {
		return false;
	}
    return true;
}

function trim(str)
{
	str = ''+str;
	return str.replace(/^\s*|\s*$/g,"");
}

function isNumeric(passedVal)
{
	var ValidChars = "0123456789 /-.";
	var IsNumber=true;
	var Char;
	if(trim(passedVal) == "")
	{
		return false;
	}
	passedVal = trim(passedVal);

	for (i = 0; i < passedVal.length && IsNumber == true; i++)
	{
		Char = passedVal.charAt(i);
		if (ValidChars.indexOf(Char) == -1)
		{
			IsNumber = false;
		}
	}
	return IsNumber;
}

function dimenticato(form)
{
	if (trim(form.user.value)=="")
	{
		alert('Il campo User ID e obbligatorio!');
		form.user.focus();
		return false;
	}
	
	if (trim(form.email.value)=="")
	{
		alert('Il campo E-mail e obbligatorio!');
		form.email.focus();
		return false;
	}
	
	if (trim(form.email.value) != "" && !isValidEmail(trim(form.email.value)))
	{
		alert('Il campo E-mail e errato!');
		form.email.focus();
		return false;
	}
	return true;
}

function unsubscribe(form)
{
	if (trim(form.email.value)=="")
	{
		alert('Il campo E-mail e obbligatorio!');
		form.email.focus();
		return false;
	}
	
	if (trim(form.email.value) != "" && !isValidEmail(trim(form.email.value)))
	{
		alert('Il campo E-mail e errato!');
		form.email.focus();
		return false;
	}
	return true;
}

function elimina(link,type)
{
	if (confirm('Sei sicuro che vuoi eliminare '+type+'?'))
	{
		window.location.href=link;
	}
}

var selezione_val = '~';
var selezione_val_tutti = '~';

function sel_tutti(sel)
{
	if (selezione_val != sel)
	{
		selezione_val = sel;
		v = sel.split("~");
		for (i=1;i<=v.length-2;i++)
		{
			label = 'sel' + v[i];
			document.getElementById(label).checked = true;
		}
	}
	else
	{
		selezione_val = '~';
		v = sel.split("~");
		for (i=1;i<=v.length-2;i++)
		{
			label = 'sel' + v[i];
			document.getElementById(label).checked = false;
		}
	}
}

function sel_tutti2()
{
	if (selezione_val != selezione_val_tutti)
	{
		selezione_val = selezione_val_tutti;
		v = selezione_val_tutti.split("~");
		for (i=1;i<=v.length-2;i++)
		{
			label = 'sel' + v[i];
			document.getElementById(label).checked = true;
		}
	}
	else
	{
		selezione_val = '~';
		v = selezione_val_tutti.split("~");
		for (i=1;i<=v.length-2;i++)
		{
			label = 'sel' + v[i];
			document.getElementById(label).checked = false;
		}
	}
}

function selezione(id,element)
{
	if (element.checked)
	{
		selezione_val += id + '~';
	}
	else
	{
		selezione_val = selezione_val.replace(id + '~','');
	}
}

function elimina_selezione(link,type,type2)
{
	if (selezione_val == '~')
	{
		alert(type2);
		return false;
	}
	else
	{
		if (confirm('Sei sicuro che vuoi eliminare '+type+'?'))
		{
			window.location.href=link+selezione_val;
		}
	}
}

function agenzie(form)
{
	if (trim(form.ragione_sociale.value) == "")
	{
		alert('Il campo Rag. sociale e obbligatorio!');
		form.ragione_sociale.focus();
		return false;
	}
	if (trim(form.via.value) == "")
	{
		alert('Il campo Indirizzo e obbligatorio!');
		form.via.focus();
		return false;
	}
	if (trim(form.CAP.value) != "" && !isNumeric(form.CAP.value))
	{
		alert('Il campo CAP e errato!');
		form.CAP.focus();
		return false;
	}
	if (trim(form.comune.value) == "")
	{
		alert('Il campo Comune e obbligatorio!');
		form.comune.focus();
		return false;
	}
	if (trim(form.telefono.value) != "" && !isNumeric(form.telefono.value))
	{
		alert('Il campo Telefono e errato!');
		form.telefono.focus();
		return false;
	}
	if (trim(form.fax.value) != "" && !isNumeric(form.fax.value))
	{
		alert('Il campo FAX e errato!');
		form.fax.focus();
		return false;
	}

	if (trim(form.url.value) != "" && form.url.value.substring(0,7) != "http://")
		form.url.value = "http://" + form.url.value;
		
	if (trim(form.url.value) != "" && !isValidURL(trim(form.url.value)))
	{
		alert('Il campo Sito web e errato!');
		form.url.focus();
		return false;
	}
	if (trim(form.email.value) == "")
	{
		alert('Il campo E-mail e obbligatorio!');
		form.email.focus();
		return false;
	}
	if (trim(form.email.value) != "" && !isValidEmail(trim(form.email.value)))
	{
		alert('Il campo E-mail e errato!');
		form.email.focus();
		return false;
	}
	if (trim(form.user.value) == "")
	{
		alert('Il campo User ID e obbligatorio!');
		form.user.focus();
		return false;
	}
	if (trim(form.password.value) == "")
	{
		alert('Il campo Password e obbligatorio!');
		form.password.focus();
		return false;
	}
	if (trim(form.password2.value) == "")
	{
		alert('Occorre digitare la password nel campo Conferma password!');
		form.password2.focus();
		return false;
	}
	if (form.password.value != form.password2.value)
	{
		alert('La password e la conferma non coincidono!');
		form.password2.value="";
		form.password2.focus();
		return false;
	}
	if (trim(form.logo.value) != "")
	{
		l = trim(form.logo.value);
		v = l.split(".");
		if (v.length > 1 && v[v.length - 1])
		{
			if (v[v.length - 1].toLowerCase() != "gif" && v[v.length - 1].toLowerCase() != "jpg" && v[v.length - 1].toLowerCase() != "jpeg")
			{
				alert('Il logo dovra avere formato .gif o .jpg!');
				form.logo.focus();
				return false;
			}
		}
		else
		{
			alert('Il logo dovra avere formato .gif o .jpg!');
			form.logo.focus();
			return false;
		}
	}
	return true;
}

function agenti(form)
{
	if (trim(form.cognome.value) == "")
	{
		alert('Il campo Cognome e obbligatorio!');
		form.cognome.focus();
		return false;
	}
	if (trim(form.nome.value) == "")
	{
		alert('Il campo Nome e obbligatorio!');
		form.nome.focus();
		return false;
	}
	if (trim(form.cell.value) == "" || !isNumeric(form.cell.value))
	{
		alert('Il campo Cellulare e obbligatorio!');
		form.cell.focus();
		return false;
	}	
	if (trim(form.telefono.value) != "" && !isNumeric(form.telefono.value))
	{
		alert('Il campo Telefono e errato!');
		form.telefono.focus();
		return false;
	}
	if (trim(form.fax.value) != "" && !isNumeric(form.fax.value))
	{
		alert('Il campo FAX e errato!');
		form.fax.focus();
		return false;
	}	
	if (trim(form.email.value) != "" && !isValidEmail(trim(form.email.value)))
	{
		alert('Il campo E-mail e errato!');
		form.email.focus();
		return false;
	}
	
	if (trim(form.foto.value) != "")
	{
		foto = form.foto.value;
		v = foto.split(".");
		if (v.length > 1 && v[v.length - 1])
		{
			if (v[v.length - 1].toLowerCase() != "jpg")
			{
				alert('Ogni foto dovra avere formato .jpg!');
				form.foto.focus();
				return false;
			}
		}
		else
		{
			alert('Ogni foto dovra avere formato .jpg!');
			form.foto.focus();
			return false;
		}
	}
	
	
	return true;
}

var count = 1;
var total = 15;
function aggiungi_foto()
{
	var element = document.getElementById("dfoto"+count);
	var element2 = document.getElementById("dfoto"+(count+1));
	var ok = true;
	for (i=0;i<count;i++)
	{
		if (document.getElementById("foto"+i).value == '')
			ok = false;
		else
		{
			foto = document.getElementById("foto"+i).value;
			v = foto.split(".");
			if (v.length > 1 && v[v.length - 1])
			{
				if (v[v.length - 1].toLowerCase() != "jpg")
				{
					ok = false;
				}
			}
			else
			{
				ok = false;
			}
		}
	}
	if (ok)
	{
		element.style.display="";
		count++;
		if (count == total) document.getElementById("buton").style.display="none";
	}
	else
	{
		alert('Ogni foto dovra avere formato .jpg!');
	}
}

function no_foto(no)
{
	total = total - no;
	if (total)
		document.getElementById("dfoto0").style.display='';
	else
		document.getElementById("buton").style.display="none";
}

function annunci(form)
{
	if (trim(form.riferimento.value) == "")
	{
		alert('Il campo Riferimento e obbligatorio!');
		form.riferimento.focus();
		return false;
	}
	/*if (form.agente.value == "0")
	{
		alert('Il campo Agente e obbligatorio!');
		form.agente.focus();
		return false;
	}*/
	if (trim(form.comune.value) == "")
	{
		alert('Il campo Comune e obbligatorio!');
		form.comune.focus();
		return false;
	}
	if (form.categoria.value == "0")
	{
		alert('Il campo Categoria e obbligatorio!');
		form.categoria.focus();
		return false;
	}
	if (trim(form.prezzo.value) != "" && (isNaN(trim(form.prezzo.value)) || parseFloat(trim(form.prezzo.value))<=0))
	{
		alert('Il campo Prezzo e obbligatorio!');
		form.prezzo.focus();
		return false;
	}
	
	if (trim(form.mq.value)!="" && (isNaN(trim(form.mq.value)) || parseFloat(trim(form.mq.value))<=0))
	{
		alert('Il campo Mq e errato!');
		form.mq.focus();
		return false;
	}
	
	if (trim(form.spese_condominiali.value)!="" && (isNaN(trim(form.spese_condominiali.value)) || parseFloat(trim(form.spese_condominiali.value))<0))
	{
		alert('Il campo Spese condominiali e errato!');
		form.spese_condominiali.focus();
		return false;
	}
	
	if (form.subito.checked == false)
	{
		if (!isValidDate(form.day.value, form.month.value, form.year.value))
		{
			alert('Il campo Disponibile e obbligatorio!');
			form.day.focus();
			return false;
		}
	}
	
	if (trim(form.descrizione.value) == "")
	{
		alert('Il campo Descrizione e obbligatorio!');
		form.descrizione.focus();
		return false;
	}
	
	var ok = true;
	for (i=0;i<count;i++)
	{
		if (document.getElementById("foto"+i).value == '')
			ok = false;
		else
		{
			foto = document.getElementById("foto"+i).value;
			v = foto.split(".");
			if (v.length > 1 && v[v.length - 1])
			{
				if (v[v.length - 1].toLowerCase() != "jpg")
				{
					ok = false;
				}
			}
			else
			{
				ok = false;
			}
		}
	}
	
	//no foto
	if (document.getElementById("foto"+(count-1)).value == '')
		ok = true;
	
	if (!ok)
	{
		alert('Ogni foto dovra avere formato .jpg!');
		return false;
	}
	
	return true;
}

function pubblica_selezione(link)
{
	if (selezione_val == '~')
	{
		alert('Nessun annuncio selezionato!');
		return false;
	}
	else
	{
		window.location.href=link+selezione_val;
	}
}

function sospendi_selezione(link)
{
	if (selezione_val == '~')
	{
		alert('Nessun annuncio selezionato!');
		return false;
	}
	else
	{
		window.location.href=link+selezione_val;
	}
}


function export_selezione(link)
{
	if (selezione_val == '~')
	{
		alert('Nessun annuncio selezionato!');
		return false;
	}
	else
	{
		window.location.href=link+selezione_val;
	}
}


function non_export_selezione(link)
{
	if (selezione_val == '~')
	{
		alert('Nessun annuncio selezionato!');
		return false;
	}
	else
	{
		window.location.href=link+selezione_val;
	}
}

// number formatting function
// copyright Stephen Chapman 24th March 2006
// permission to use this function is granted provided
// that this copyright notice is retained intact

function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) {var x = Math.round(num * Math.pow(10,dec));if (x >= 0) n1=n2='';var y = (''+Math.abs(x)).split('');var z = y.length - dec;y.splice(z, 0, pnt);while (z > 3) {z-=3; y.splice(z,0,thou);}var r = curr1+n1+y.join('')+n2+curr2;return r;}

function trim2(value)
{
	return trim(value.replace(/\./g,''));
}

function format_no(obj)
{
	val = obj.value.replace(/\./g,'');
	//val = val.replace(/,/g,'');
	val = trim(val);
	if (!isNaN(val))
	{
		if (val != '')
			obj.value = formatNumber(val,0,'.','','','','-','');
	}
	else
	{
		obj.value = formatNumber(0,0,'.','','','','-','');
	}
}

function cerca()
{
	var form = document.getElementById("cerca");
	
	if (form.categoria.value == 0)
	{
		alert('Il campo Categoria e errato!');
		form.categoria.focus();
		return false;
	}
	
	if (trim2(form.prezzo.value)!="" && (isNaN(trim2(form.prezzo.value)) || parseFloat(trim2(form.prezzo.value))<0))
	{
		alert('Il campo Prezzo e errato!');
		form.prezzo.focus();
		return false;
	}
	
	if (trim2(form.prezzo2.value)!="" && (isNaN(trim2(form.prezzo2.value)) || parseFloat(trim2(form.prezzo2.value))<0))
	{
		alert('Il campo Prezzo e errato!');
		form.prezzo2.focus();
		return false;
	}
	
	if (form.mq && trim(form.mq.value)!="" && (isNaN(trim(form.mq.value)) || parseFloat(trim(form.mq.value))<=0))
	{
		alert('Il campo Mq e errato!');
		form.mq.focus();
		return false;
	}
	
	if (form.mq2 && trim(form.mq2.value)!="" && (isNaN(trim(form.mq2.value)) || parseFloat(trim(form.mq2.value))<=0))
	{
		alert('Il campo Mq e errato!');
		form.mq2.focus();
		return false;
	}
	
	form.pagina.value = 1;
	
	return true;
}

function tipo_cerca(avansata, skip)
{
	
	if (!skip)
	{
		if (document.getElementById("cerca").avansata.value == avansata)
			return;
	}

	document.getElementById("cerca").avansata.value = avansata;

	if (avansata)
	{
		document.getElementById("1").style.display="";
		document.getElementById("2").style.display="";
		document.getElementById("3").style.display="";
		document.getElementById("4").style.display="";
		document.getElementById("5").style.display="";
		document.getElementById("6").style.display="";
		document.getElementById("7").style.display="";
		document.getElementById("m1").src = 'images/tab_semplice_off.gif';
		document.getElementById("m2").src = 'images/tab_avanzata_on.gif';
	}
	else
	{
		document.getElementById("1").style.display="none";
		document.getElementById("2").style.display="none";
		document.getElementById("3").style.display="none";
		document.getElementById("4").style.display="none";
		document.getElementById("5").style.display="none";
		document.getElementById("6").style.display="none";
		document.getElementById("7").style.display="none";
		document.getElementById("m1").src = 'images/tab_semplice_on.gif';
		document.getElementById("m2").src = 'images/tab_avanzata_off.gif';
		
		document.getElementById("cerca").mq.value = "";
		document.getElementById("cerca").mq2.value = "";
		document.getElementById("cerca").cucina.value = 0;
		document.getElementById("cerca").bagni.value = 0;
		document.getElementById("cerca").box.checked = false;
		document.getElementById("cerca").posto_auto.checked = false;
		document.getElementById("cerca").cantina.checked = false;
		document.getElementById("cerca").lavanderia.checked = false;
		document.getElementById("cerca").giardino.checked = false;
		document.getElementById("cerca").piscina.checked = false;
		document.getElementById("cerca").terrazzo_balcone.checked = false;
		
		document.getElementById("cerca").impianto_allarme.checked = false;
		document.getElementById("cerca").videocitofono.checked = false;
		document.getElementById("cerca").fibra_ottica_ADSL.checked = false;
		document.getElementById("cerca").TV_satellitare.checked = false;
		document.getElementById("cerca").domotica.checked = false;
		document.getElementById("cerca").pannelli_solari.checked = false;
		document.getElementById("cerca").aria_condizionata.checked = false;
		
		document.getElementById("cerca").subito.checked = false;
		
		document.getElementById("cerca").agenzia.value = 0;
		document.getElementById("cerca").riferimento.value = "";
	}
}

function pagina_cerca(pagina)
{
	document.getElementById("cerca").pagina.value = pagina;
	document.getElementById("cerca").submit();
}

function pagina(page,pages,ordina,ordina2,agenzia)
{
	if (trim(page)=="" || isNaN(trim(page)) || parseInt(trim(page))<=0 || parseInt(trim(page))>pages)
	{
		alert('Il campo Pagina e errato!');
	}
	else
	{
		window.location.href="annunci_admin.php?id_agenzia="+agenzia+"&ordina="+ordina+"&ordina2="+ordina2+"&pagina="+page;
	}
	return false;
}

function torna_ricerca()
{
	document.getElementById("cerca").method='post';
	document.getElementById("cerca").action='session.php';
	document.getElementById("cerca").submit();
}

function pagina_cerca2(cpagina,maxpagina,pagina)
{
	if (trim(pagina)=="" || isNaN(trim(pagina)) || parseInt(trim(pagina))<=0 || parseInt(trim(pagina))>maxpagina)
	{
		alert('Il campo Pagina e errato!');
	}
	else
	{
		document.getElementById("cerca").pagina.value = pagina;
		document.getElementById("cerca").submit();
	}
}

function ordina_cerca(ordina_,ordina,ordina2)
{
	if (ordina == ordina_)
	{
		if (ordina2 == 'ASC')
			ordina2 = 'DESC';
		else
			ordina2 = 'ASC';
	}
	else
	{
		ordina2 = 'ASC';
	}
	document.getElementById("cerca").ordina.value = ordina_;
	document.getElementById("cerca").ordina2.value = ordina2;
	document.getElementById("cerca").submit();
}

function invia(form)
{
	if (trim(form.nome.value)=="")
	{
		alert('Il campo Cognome e Nome e obbligatorio!');
		form.nome.focus();
		return false;
	}
	
	if (trim(form.email.value)=="")
	{
		alert('Il campo E-mail e obbligatorio!');
		form.email.focus();
		return false;
	}
	
	if (trim(form.email.value) != "" && !isValidEmail(trim(form.email.value)))
	{
		alert('Il campo E-mail e errato!');
		form.email.focus();
		return false;
	}
	
	if (trim(form.telefono.value)=="")
	{
		alert('Il campo Telefono e obbligatorio!');
		form.telefono.focus();
		return false;
	}
	
	if (trim(form.telefono.value) != "" && !isNumeric(form.telefono.value))
	{
		alert('Il campo Telefono e errato!');
		form.telefono.focus();
		return false;
	}
	
	if (trim(form.prezzo.value)!="" && (isNaN(trim(form.prezzo.value)) || parseFloat(trim(form.prezzo.value))<=0))
	{
		alert('Il campo Prezzo e errato!');
		form.prezzo.focus();
		return false;
	}
	
	if (trim(form.prezzo2.value)!="" && (isNaN(trim(form.prezzo2.value)) || parseFloat(trim(form.prezzo2.value))<=0))
	{
		alert('Il campo Prezzo e errato!');
		form.prezzo2.focus();
		return false;
	}
	
	if (trim(form.prezzo.value)!="" && trim(form.prezzo2.value)!="" && parseFloat(trim(form.prezzo.value)) > parseFloat(trim(form.prezzo2.value)))
	{
		alert('Il campo Prezzo e errato!');
		form.prezzo2.focus();
		return false;
	}
	
	if (trim(form.mq.value)!="" && (isNaN(trim(form.mq.value)) || parseFloat(trim(form.mq.value))<=0))
	{
		alert('Il campo Mq e errato!');
		form.mq.focus();
		return false;
	}
	
	if (trim(form.mq2.value)!="" && (isNaN(trim(form.mq2.value)) || parseFloat(trim(form.mq2.value))<=0))
	{
		alert('Il campo Mq e errato!');
		form.mq2.focus();
		return false;
	}
	
	if (trim(form.mq.value)!="" && trim(form.mq2.value)!="" && parseFloat(trim(form.mq.value)) > parseFloat(trim(form.mq2.value)))
	{
		alert('Il campo Mq e errato!');
		form.mq2.focus();
		return false;
	}
	
	/*if (trim(form.comune.value)=="")
	{
		alert('Il campo Comune e obbligatorio!');
		form.comune.focus();
		return false;
	}*/
	
	if (trim(form.note.value)=="")
	{
		alert('Il campo Note e obbligatorio!');
		form.note.focus();
		return false;
	}
	
	if (form.ack1[0].checked == false)
	{
		alert('Devi accetare il trattamento dei tuoi dati!');
		return false;
	}
	
	if (form.ack2[0].checked == false)
	{
		alert('Devi accetare il trattamento dei tuoi dati!');
		return false;
	}
	
	/*if (
		form.c1.checked == false &&
		form.c2.checked == false &&
		form.c3.checked == false &&
		form.c4.checked == false &&
		form.c5.checked == false &&
		form.c6.checked == false &&
		form.c7.checked == false &&
		form.c8.checked == false &&
		form.c9.checked == false &&
		form.c10.checked == false &&
		form.c11.checked == false
	)
	{
		alert('Il campo Categoria e obbligatorio!');
		return false;
	}*/
	
	return true;
}

function registrati(form)
{
	if (trim(form.nome.value)=="")
	{
		alert('Il campo Nome e obbligatorio!');
		form.nome.focus();
		return false;
	}
	
	if (trim(form.email.value)=="")
	{
		alert('Il campo E-mail e obbligatorio!');
		form.email.focus();
		return false;
	}
	
	if (trim(form.email.value) != "" && !isValidEmail(trim(form.email.value)))
	{
		alert('Il campo E-mail e errato!');
		form.email.focus();
		return false;
	}
	
	if (form.autorizzo.checked == false)
	{
		alert('Devi accetare il trattamento dei tuoi dati!');
		return false;
	}
	
	
	
	return true;
}

function proposta(check,ordina,ordina2,agenzia,pagina)
{
	window.location.href="action.php?ordina="+ordina+"&ordina2="+ordina2+"&action=proposta&id="+check.value+"&agenzia="+agenzia+"&pagina="+pagina;
}

function sospendi(id,status,ordina,ordina2,agenzia,pagina)
{
	if (status == 1)
	{
		window.location.href="action.php?ordina="+ordina+"&ordina2="+ordina2+"&action=sospendi&id="+id+"&agenzia="+agenzia+"&pagina="+pagina;
	}
	else
	{
		window.location.href="action.php?ordina="+ordina+"&ordina2="+ordina2+"&action=attiva&id="+id+"&agenzia="+agenzia+"&pagina="+pagina;
	}
	return false;
}

function attiva_richiesta(id,status,ordina,ordina2)
{
	if (status == 1)
	{
		window.location.href="action.php?ordina="+ordina+"&ordina2="+ordina2+"&action=sospendi_richiesta&id="+id;
	}
	else
	{
		window.location.href="action.php?ordina="+ordina+"&ordina2="+ordina2+"&action=attiva_richiesta&id="+id;
	}
	return false;
}

function sospendi_agenzia(id,status)
{
	if (status == 1)
	{
		window.location.href="action.php?action=sospendi_agenzia&id="+id;
	}
	else
	{
		window.location.href="action.php?action=attiva_agenzia&id="+id;
	}
	return false;
}

function notificare_agenzia(id,status)
{
	if (status == 1)
	{
		window.location.href="action.php?action=notificare&status=0&id="+id;
	}
	else
	{
		window.location.href="action.php?action=notificare&status=1&id="+id;
	}
	return false;
}

function export_agenzia(id,status)
{
	if (status == 1)
	{
		window.location.href="action.php?action=export&status=0&id="+id;
	}
	else
	{
		window.location.href="action.php?action=export&status=1&id="+id;
	}
	return false;
}


function disponibile(checked)
{
	if (checked)
	{
		document.getElementById("disponibile_da").style.display="none";
	}
	else
	{
		document.getElementById("disponibile_da").style.display="";
	}
}

function invia2(form)
{
	if (trim(form.nome.value)=="")
	{
		alert('Il campo Il tuo nome e obbligatorio!');
		form.nome.focus();
		return false;
	}
		
	if (trim(form.email.value)=="")
	{
		alert('Il campo La tua e-mail e obbligatorio!');
		form.email.focus();
		return false;
	}
	
	if (trim(form.email.value) != "" && !isValidEmail(trim(form.email.value)))
	{
		alert('Il campo La tua e-mail e errato!');
		form.email.focus();
		return false;
	}
	
	if (trim(form.nome2.value)=="")
	{
		alert('Il campo Il nome del destinatario e obbligatorio!');
		form.nome2.focus();
		return false;
	}
		
	if (trim(form.email2.value)=="")
	{
		alert('Il campo E-mail del tuo amico e obbligatorio!');
		form.email2.focus();
		return false;
	}
	
	if (trim(form.email2.value) != "" && !isValidEmail(trim(form.email2.value)))
	{
		alert('Il campo E-mail del tuo amico e errato!');
		form.email2.focus();
		return false;
	}
	
	if (trim(form.msg.value)=="")
	{
		alert('Il campo Messaggio e obbligatorio!');
		form.msg.focus();
		return false;
	}
}

function pubblica(form)
{
	if (trim(form.nome.value)=="")
	{
		alert('Il campo Nome e obbligatorio!');
		form.nome.focus();
		return false;
	}
	
	if (trim(form.cognome.value)=="")
	{
		alert('Il campo Cogome e obbligatorio!');
		form.cognome.focus();
		return false;
	}
	
	if (trim(form.email.value)=="")
	{
		alert('Il campo E-mail e obbligatorio!');
		form.email.focus();
		return false;
	}
	
	if (trim(form.email.value) != "" && !isValidEmail(trim(form.email.value)))
	{
		alert('Il campo E-mail e errato!');
		form.email.focus();
		return false;
	}
	
	if (trim(form.telefono.value)=="")
	{
		alert('Il campo Telefono e obbligatorio!');
		form.telefono.focus();
		return false;
	}
	
	if (trim(form.telefono.value) != "" && !isNumeric(form.telefono.value))
	{
		alert('Il campo Telefono e errato!');
		form.telefono.focus();
		return false;
	}
	
	if (trim(form.comune.value) == "")
	{
		alert('Il campo Comune e obbligatorio!');
		form.comune.focus();
		return false;
	}
	
	if (form.ack1[0].checked == false)
	{
		alert('Devi accetare il trattamento dei tuoi dati!');
		return false;
	}
	
	if (form.ack2[0].checked == false)
	{
		alert('Devi accetare il trattamento dei tuoi dati!');
		return false;
	}
	
	return true;
}

function invia_amico(link)
{
	if (selezione_val == '~')
	{
		alert('Nessun annuncio selezionato!');
		return false;
	}
	else
	{
		window.open('invia_amico.php?id='+selezione_val,null,'height=380,width=450,status=no,toolbar=no,menubar=no,location=no');
	}
}

function ordina_admin(ordina_,ordina,ordina2)
{
	if (ordina == ordina_)
	{
		if (ordina2 == 'ASC')
			ordina2 = 'DESC';
		else
			ordina2 = 'ASC';
	}
	else
	{
		ordina2 = 'ASC';
	}
	window.location = 'annunci.php?ordina='+ordina_+'&ordina2='+ordina2;
}

function ordina_admin2(ordina_,ordina,ordina2,id_agenzia)
{
	if (ordina == ordina_)
	{
		if (ordina2 == 'ASC')
			ordina2 = 'DESC';
		else
			ordina2 = 'ASC';
	}
	else
	{
		ordina2 = 'ASC';
	}
	window.location = 'annunci_admin.php?id_agenzia='+id_agenzia+'&ordina='+ordina_+'&ordina2='+ordina2+"&pagina=1";
}

function ordina_admin3(ordina_,ordina,ordina2)
{
	if (ordina == ordina_)
	{
		if (ordina2 == 'ASC')
			ordina2 = 'DESC';
		else
			ordina2 = 'ASC';
	}
	else
	{
		ordina2 = 'ASC';
	}
	window.location = 'registrati.php?ordina='+ordina_+'&ordina2='+ordina2;
}

function ordina_admin4(ordina_,ordina,ordina2)
{
	if (ordina == ordina_)
	{
		if (ordina2 == 'ASC')
			ordina2 = 'DESC';
		else
			ordina2 = 'ASC';
	}
	else
	{
		ordina2 = 'ASC';
	}
	window.location = 'richieste.php?ordina='+ordina_+'&ordina2='+ordina2;
}

function ordina_admin5(id,ordina,ordina2,ordina_,ordina1,ordina12)
{
	if (ordina1 == ordina_)
	{
		if (ordina12 == 'ASC')
			ordina12 = 'DESC';
		else
			ordina12 = 'ASC';
	}
	else
	{
		ordina12 = 'ASC';
	}
	window.location = 'sim_richieste.php?id='+id+'&ordina='+ordina+'&ordina2='+ordina2+'&ordina1='+ordina_+'&ordina12='+ordina12;
}

function popup_email(id)
{
	email = document.getElementById(id).innerHTML;
	wnd = window.open();
	wnd.document.write(email);
	wnd.document.close();
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}