var http_request = false;
   var ml=false;
 function XRequest() 
 	{
	    http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
         }
      } 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('No XMLHTTP instance!');
         return false;
      }
	  return http_request;
   }
   

   
function putprovincia()
{
if (ml.readyState == 4) { 	if (ml.status == 200)  		{
//Action
document.getElementById("iprovincia").innerHTML = ml.responseText;

	} 	 }
}

function sel_provincia(ireg) 
{
if (!ireg) { return false; }

var myurl = '/get_provincia.php';
var mydata = '?idr=' + ireg;
ml = XRequest(myurl,mydata);
ml.onreadystatechange = putprovincia;
ml.open('GET', myurl + mydata, true);
ml.send(null);

}

function putloc()
{
if (pl.readyState == 4) { 	if (pl.status == 200)  		{
document.getElementById("ilocalita").innerHTML = pl.responseText;
	} 	 }
}

function sel_localita(iprov)
{
if (!iprov) { return false; }

var myurl = '/get_localita.php';
var mydata = '?idp=' + iprov;
pl = XRequest(myurl,mydata);
pl.onreadystatechange = putloc;
pl.open('GET', myurl + mydata, true);
pl.send(null);
}

function get_page(page)
{
var	my_spec = document.getElementById("cat").value;
var page_out = page + my_spec;
document.location.href=page_out;	
}

function invia_inserzione()
{
var email = document.getElementById("email").value;
var messaggio = document.getElementById("messaggio").value;
if (!email) { alert('Manca la email!'); return false; }
if (!messaggio) { alert('Manca il messaggio!'); return false; }
document.getElementById("inserzione").submit();
// TODO
}

function uploaderror(my_msg)
{ 
alert(my_msg); 
}

function vedi_foto(my_foto)
{
var stringa = "/vedi_foto.php?imgfile=" + my_foto;
window.open(stringa,'propostissime',"width=500,height=400,toolbar=false,menubar=false,resizable=1");
}
function upload_ok(my_th, my_foto)
{
var str = '<img src=\"' + my_foto + '\" border=\"1\">';
document.getElementById("my_th").value=my_th;
document.getElementById("my_file").value=my_foto;

document.getElementById("my_img").innerHTML = str;	
upload_off();
}

function msg_reply(idmsg,my_pagina,my_cat)
{
var str = 'http://www.propostissime.com/reply.php?id=' + idmsg + '&pagina=' + my_pagina + '&cat=' + my_cat;
document.location.href=str;
}


function bookmark () { window.external.AddFavorite(location.href,document.title) }


function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function upload_on()
{
var ftab = document.getElementById("tabfile");
var x = findPosX(ftab);
var y = findPosY(ftab);
document.getElementById("win_upload").style.top = y + "px";
document.getElementById("win_upload").style.left = x + "px";
document.getElementById("win_upload").style.visibility = 'inherit';
}

function upload_off()
{
	document.getElementById("win_upload").style.visibility = 'hidden';
}

function invia_immagine()
{
var filez = document.getElementById("userfile").value;
if (!filez) { return false; }
upload_on();
}

function invia_attivita()
{
	var email = document.getElementById("email").value;
var messaggio = document.getElementById("messaggio").value;
if (!email) { alert('Manca la email!'); return false; }
if (!messaggio) { alert('Manca il messaggio!'); return false; }
document.getElementById("inserzione").submit();
}


