function ClassHTTP () {
 CreaOggettoHTTP();
 this.objHttp= "";
 this.sitoweb= '';
 this.InviaRichiesta = InviaRichiesta;
 this.Operazione = Operazione;
 this.nomeogg = "";
 function CreaOggettoHTTP() {
	 if (navigator.appName == "Microsoft Internet Explorer") {
		 this.objHttp = new ActiveXObject("Microsoft.XMLHTTP");
	 	ie = true;
	 } else {
		 this.objHttp = new XMLHttpRequest();
	 }
 }
 
 function InviaRichiesta(type,url,nome) {
	 nomeogg = nome;
	 objHttp.open(type,url,true);
	 objHttp.onreadystatechange = this.Operazione;
	 objHttp.send(null);
 }
 function Operazione() {
	 if (objHttp.readyState == 4) {
		 document.getElementById(nomeogg).innerHTML = objHttp.responseText;
	 }
 }
}
function ControllaAnnuncio() {
	var form = document.aggiungi;
		if (form.sottocategoria.value > 0) {
				if (form.nome.value != "") {
						if (form.prezzo.value > 0) {
							form.submit();
						} else alert("Inserisci un prezzo!");
				} else alert("Inserisci il nome!");
		} else alert("Selezina la sottocategoria!");
}
function ControllaAnnuncioModifica() {
	var form = document.modifica;
				if (form.nome.value != "") {
						if (form.prezzo.value > 0) {
							form.submit();
						} else alert("Inserisci un prezzo!");
				} else alert("Inserisci il nome!");
}
function CancellaImmagine(id) {
	var ogg = new ClassHTTP();
	ogg.InviaRichiesta("get","http://www.compraevendi.ch/moduli/vendi.php?cancellaimmagine&id="+id,'foto'+id);
}

function sic(indirizzo,testo){
    if(confirm(testo)){
        window.location.href=indirizzo;
    }
}
function popup_img(id) {
	javascript:window.open('http://www.compraevendi.ch/moduli/vendi.php?foto&num='+id,'Foto','width=400,height=400 ,toolbar=no, location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes');
}
function Sottocategorie(dest,id) {
	var ogg = new ClassHTTP();
	ogg.Operazione =  function Operazione() {
	    if (objHttp.readyState == 4) {
		       if (objHttp.responseXML != null) {

		           var xmlDoc =  objHttp.responseXML;
		           var TagDati = xmlDoc.getElementsByTagName('Dati')[0];
		           var TagMessaggi = TagDati.getElementsByTagName('Sottocategorie')[0];
		           var TagMessaggiItems = TagMessaggi.getElementsByTagName("sottocategoria");
		           if (TagMessaggi.length != 0) {
		               for (i = dest.options.length;i >= 0;i--)  {
		                   dest.options[i] = null;
	                 	}
	                for (i = 0;i < TagMessaggiItems.length;i++)  {
	                    dest.options[dest.options.length] = new Option(TagMessaggiItems[i].firstChild.nodeValue,TagMessaggiItems[i].getAttribute("valore"));
	                }
	             }
		       }
		  }
	  } 
	ogg.InviaRichiesta("get","moduli/vendi.php?sottocategoria&id="+id,dest);
}
function isEmail(indirizzo) {
  if (window.RegExp) {
    var nonvalido = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var valido = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
    var regnv = new RegExp(nonvalido);
    var regv = new RegExp(valido);
    if (!regnv.test(indirizzo) && regv.test(indirizzo))
      return true;
    return false;
    }
  else {
    if(indirizzo.indexOf("@") >= 0)
      return true;
    return false;
     }
}
function ConfermaInvio() {
	var form = document.contatta;
	if (form.nome.value != "") {
		if (isEmail(form.mail.value)) {
			if (form.testo.value != "") {
				form.submit();
			} else alert("Inserire un testo!");
		} else alert("Inserire un mail valido!");
	} else alert("Inserire il tuo nome!");
}
