function ViewSchedaSMS(CodAnnu, Durata) {
	var mypagesize = RicavaHW();
	var mywidth = (document.all) ? mypagesize[1] : mypagesize[1] -16;
	if ($("scheda_sms")) {
		removeElement($("scheda_sms"));
	}
	var dwidth = 400;
	if (Durata!=undefined) {
		Durata = ", per la durata di " + Durata;
		var dheight = 406;
	} else {
		Durata = "";
		var dheight = 391;
	}

	oggettoDivB = OmbraBackGround("HeadBLayer", dwidth, dheight);

	oggettoDiv = document.createElement("div");
	oggettoDiv.setAttribute("id", "scheda_sms");
	oggettoDiv.className = "scheda_sms";
	oggettoDiv.style.left = (mywidth - dwidth) / 2 + "px";
	oggettoDiv.style.top = (mypagesize[0] - dheight) / 2 + "px";
	oggettoDiv.style.height = dheight + "px";
	oggettoDiv.style.zIndex = "190";
	var InsHtml  = "<img style='border-bottom: 1px solid #000;' src='http://immagini.ilmercatone.com/scehda_sms.jpg' alt='Pubblicità Servizio SMS' width='400' height='275'>";
	if (CodAnnu!=null) {
		InsHtml += "<div style='vertical-align: baseline; text-align: center; font-family: Arial; font-size: 14pt; font-weight: bold; position: absolute; background-color: #fff; color: #E55725; width: 250px; height: 23px; top: 118px; left: 75px;'>MERCATONE " + CodAnnu + "</div>";
	} else {
		InsHtml += "<div style='vertical-align: baseline; text-align: center; font-family: Arial; font-size: 14pt; font-weight: bold; position: absolute; background-color: #fff; color: #039; width: 385px; height: 65px; top: 85px; left: 5px;'>Apri il tuo annuncio e clicca su \"Aumenta la visibilit&agrave; con un SMS\" e saprai come fare!</div>";
	}
	InsHtml += "<br>";
	InsHtml += "<font size='2' face='Arial'><b>IlMercatone.com costa 2 euro iva inclusa" + Durata + ". Non è un servizio in abbonamento. Riservato a maggiorenni.</b><br/>";
	InsHtml += "E' gestito da JM SpA, per clienti Tim, Vodafone, Wind e 3. Costo i.i. SMS inviato: Tim gratuito; Vodafone e 3 secondo piano tariffario; Wind: 12,4 centesimi dall'Italia e 50 centesimi dall'estero.<br/>";
	InsHtml += "<b>Customer care: 02896340007 (9:00-21:00)</b>.";
	InsHtml += "</font>";
	oggettoDiv.innerHTML = InsHtml;
	oggettoDiv.onclick = function() {
		close_layer("scheda_sms"); 
		close_layer("HeadBLayer");
		return false;
	};


	setTimeout("oggettoDivB.style.display = oggettoDiv.style.display = 'block';", 350);

	objBody = document.getElementsByTagName("body").item(0);
	objBody.insertBefore(oggettoDiv, objBody.firstChild);
	objBody.insertBefore(oggettoDivB, objBody.firstChild);

	opacityBackGround();
}

function HeadLayer() {
	var Err = 0;
	var layerhtml = new String(arguments[0]);
	var mypagesize = RicavaHW();
	var mywidth = (document.all) ? mypagesize[1] : mypagesize[1] -16;

	if ($("HeadFLayer") != null) {
		removeElement($("HeadFLayer"));
	}

	var layerhtml = eval("(" + layerhtml + ")");

	oggettoDivB = OmbraBackGround("HeadBLayer", layerhtml.width, layerhtml.height);
	$("loading_ajax").style.display = "none";

	oggettoDivF = document.createElement("div");
	oggettoDivF.setAttribute("id", "HeadFLayer");
	oggettoDivF.style.width = layerhtml.width + "px";
	oggettoDivF.style.height = layerhtml.height + "px";
	oggettoDivF.style.left = (mywidth - layerhtml.width) / 2 + "px";
	oggettoDivF.style.top = (mypagesize[0] - layerhtml.height) / 2 + "px";
	oggettoDivF.style.zIndex = "190";
	oggettoDivF.innerHTML = layerhtml.html;
	oggettoDivF.onclick = function() {
		removeElement($("HeadBLayer"));
		removeElement($("HeadFLayer"));
		removeElement($("div_opacity"));
	};

	setTimeout("oggettoDivB.style.display = oggettoDivF.style.display = 'block';", 350);

	objBody = document.getElementsByTagName("body").item(0);
	objBody.insertBefore(oggettoDivF, objBody.firstChild);
	objBody.insertBefore(oggettoDivB, objBody.firstChild);

	if (Err == 1) {
		alert("Si è verificato un problema nell'esecuzionde della Query.");
	}
	return true;
}

function ViewLayer(VLayer) {
	var objOverlay = opacityBackGround();
	var objLoadingImageLink = document.createElement("a");
	var arrayPageSize = RicavaHW();

	objLoadingImageLink.setAttribute("href","#");
	objLoadingImageLink.onclick = function () {
		$("div_opacity").style.display = "none";
		return false;
	}
	objOverlay.appendChild(objLoadingImageLink);

	var objLoadingImage = document.createElement("img");
	objLoadingImage.src = loadingImage;
	objLoadingImage.setAttribute("id","loading_ajax");
	objLoadingImage.style.position = "absolute";
	objLoadingImage.style.zIndex = "150";
	objLoadingImage.style.border = "0px";
	objLoadingImage.style.top = (((arrayPageSize[0] - 35 - objLoadingImage.height) / 2) + "px");
	objLoadingImage.style.left = (((arrayPageSize[3] - 20 - objLoadingImage.width) / 2) + "px");
	objLoadingImageLink.appendChild(objLoadingImage);

	ajaxSend(HeadLayer, "ViewLayer", "Layer", VLayer);
	return true;
}

function ViewSendMail(idAnnu, URI_Ann, urlimg) {
	var mypagesize = RicavaHW();
	var mywidth = (document.all) ? mypagesize[1] : mypagesize[1] -16;
	opacityBackGround();

	if ($("SendMailAnn") != null) {
		removeElement($("SendMailAnn"));
	}

	oggettoDivB = OmbraBackGround("HeadBLayer", 460, 350, 10, 22);

	oggettoDivF = document.createElement("div");
	oggettoDivF.setAttribute("id", "SendMailAnn");
	oggettoDivF.style.left = (((mywidth - 444) / 2) + 10) + "px";
	oggettoDivF.style.top  = (((mypagesize[0] - 339) / 2) + 10) + "px";
	oggettoDivF.style.zIndex = "190";
	oggettoDivF.style.backgroundImage = "url('http://immagini.ilmercatone.com/stripe3.gif')";
	oggettoDivF.style.backgroundColor = "#FFFFFF";
	oggettoDivF.style.backgroundRepeat = "repeat";
	oggettoDivF.style.backgroundAttachment = "scroll";
	oggettoDivF.style.backgroundPosition = "left top";

	var InsHtml  = "<form action='/sendEmail.html' method='post' id='FSendMailAnn'>";
	InsHtml += "<input type='hidden' name='IDAnnu' value='" + idAnnu + "'>";
	InsHtml += "<input type='hidden' name='RefUrl' value='" + URI_Ann + "'>";
	InsHtml += "<fieldset style='border:medium none; margin-left:2px; margin-right:2px;'>";
	InsHtml += "<legend style='font-size:12px; font-weight:bold; margin:3px 0 3px -6px; padding:0;'>Invia Email all'utente</legend>";
	InsHtml += "<a href='javascript:void(0);' onclick='close_layer(\"HeadBLayer\");close_layer(\"SendMailAnn\");' style='position: absolute; right: 7px; top: 7px;' title='chiudi'><img src='" + urlimg + "transparent.gif' class='iconssprite close_div' alt='Chiudi'></a>";
	InsHtml += "<ol style='list-style-image:none; list-style-position:outside; list-style-type:none;'>";
	InsHtml += "<li>";
	InsHtml += "<label for='txtemail'>Tuo indirizzo email:</label>";
	InsHtml += "<input type='text' size='54' class='form_fields' name='txtemail' id='txtemail' style='border-color:#CACACA; border-style:solid; border-width:1px 1px 1px 1px;'>";
	InsHtml += "</li>";
	InsHtml += "<li>";
	InsHtml += "<label for='txttext'>Messaggio:</label>";
	InsHtml += "<textarea cols='40' rows='5' name='txttext' id='txttext' style='border-color:#CACACA; border-style:solid; border-width:1px 1px 1px 1px;'></textarea>";
	InsHtml += "</li>";
	InsHtml += "<li style='margin-bottom:4px;'>";
	InsHtml += "<span>Inserisci il codice</span>";
	InsHtml += "<input type='text' align='bottom' id='txtVerificaSMA' name='codice_verifica' maxlength='6' size='10' style='border-color:#CACACA; border-style:solid;  border-width:1px 1px 1px 1px;'>";
	InsHtml += "<img align='bottom' src='/img/captcha.php?reg=pub' name='captcha_key_pubbl' alt='immagine captcha'>";
	InsHtml += "<img align='bottom' src='" + urlimg + "transparent.gif' onclick='document.images[\"captcha_key_pubbl\"].src = \"/img/captcha.php?\"+new Date();' class='iconssprite reload' alt='Rigenera'>";
	InsHtml += "</li>";
	InsHtml += "<li style='margin-bottom:4px;'>";
	InsHtml += "<input type='button' onclick='return checkSendMailAnn($(\"FSendMailAnn\"));' style='border: 1px solid #c9c9c9; background-color: #fff; margin: 10px 5px 0pt 0pt;' value='Invia' name='Invia'/>";
	InsHtml += "<p style='display: inline; height:50px; margin-top:10px; float: left; width:340px;'>Cliccando su Invia, accetti le <a target='_blank' href='/regole.html#n8'>condizioni d'uso</a> e l'informativa sulla <a target='_blank' href='/regole.html#n5'>privacy</a>. Il tuo messaggio sarà inviato solo all'autore dell'annuncio e non sarà reso pubblico.</p>";
	InsHtml += "</li>";
	InsHtml += "</ol>";
	InsHtml += "</fieldset>";
	InsHtml += "</form>";

	oggettoDivF.innerHTML = InsHtml;
	setTimeout("oggettoDivB.style.display = oggettoDivF.style.display = 'block';", 350);

	objBody = document.getElementsByTagName("body").item(0);
	objBody.insertBefore(oggettoDivF, objBody.firstChild);
	objBody.insertBefore(oggettoDivB, objBody.firstChild);
	return true;
}

var loadingImage = "/img/loading.gif";
var closeButton = "/img/close.gif";

function NewOpenFotoAnn(PFoto, IDAnnu){
	if (!document.getElementsByTagName){ return; }
	var objBody = document.getElementsByTagName("body").item(0);
	var arrayPageSize = RicavaHW();
	var frazId = parseInt(IDAnnu /10000);
	var urlIMG = "http://static-foto.ilmercatone.com/" + frazId + "/" + IDAnnu + "/foto" + PFoto + ".0.jpg";
	var imgPreloader = new Image();

	if ($("loadingImage")) {
		$("loadingImage").style.top = (((arrayPageSize[0] - 35 - $("loadingImage").height) / 2) + "px");
		$("loadingImage").style.left = (((arrayPageSize[3] - 20 - $("loadingImage").width) / 2) + "px");
		$("loadingImage").style.display = "block";
	}

	$("div_opacity_img").style.height = (arrayPageSize[2] + "px");
	$("div_opacity_img").style.display = "block";

	// preload image
	imgPreload = new Image();
	imgPreload.onload=function(){
		$("lightboxImage").src = urlIMG;

		var lightboxTop = ((arrayPageSize[0] - 35 - imgPreload.height) / 2);
		var lightboxLeft = ((arrayPageSize[3] - 20 - imgPreload.width) / 2);
	
		$("lightbox").style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
		$("lightbox").style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";

		if ($("loadingImage")) {
			$("loadingImage").style.display = "none";
		}
		
		$("lightbox").style.display = "block";

		var MinO = 0.1;
		$("lightbox").style.opacity = MinO;
		$("lightbox").style.filter= "alpha(opacity=" + (MinO*100) + ")";
		var SeTime = setInterval(function() {
			var opa = $("lightbox").style;
			if (parseFloat(opa.opacity) <= 1) {
				var val = parseFloat(opa.opacity) + MinO;
				opa.opacity = val;
				opa.filter= "alpha(opacity=" + (val*100) + ")";
			} else {
				clearInterval(SeTime);
				var oggettoDivB = OmbraBackGround("HeadBLayer", $("lightbox").offsetWidth, $("lightbox").offsetHeight);
				objBody.insertBefore(oggettoDivB, $("div_opacity_img").nextSibling);
				oggettoDivB.style.display = "block";
			}
		}, 1);

		$("div_opacity_img").style.height = (arrayPageSize[2] + "px");

		return false;
	}

	imgPreload.src = urlIMG;

}

function initLightbox() {
	if (!document.getElementsByTagName){ return; }
	var objBody = document.getElementsByTagName("body").item(0);
	var mypagesize = RicavaHW();

	var objOverlay = document.createElement("div");
	objOverlay.setAttribute("id", "div_opacity_img");
	objOverlay.style.position = "absolute";
	objBody.appendChild(objOverlay);

	objOverlay.style.opacity = "0.80";
	objOverlay.style.filter= "alpha(opacity=80)";

	objOverlay.style.top = "0";
	objOverlay.style.left = "0";
	objOverlay.style.zIndex = "50";
	objOverlay.style.width = "100%";
	objOverlay.style.height = mypagesize[2] +"px";

	objOverlay.style.display = "none";
	objOverlay.style.backgroundColor = "#fff";


	var arrayPageSize = RicavaHW();

	var imgPreloader = new Image();
	imgPreloader.onload=function(){
		var objLoadingImageLink = document.createElement("a");
		objLoadingImageLink.setAttribute("href","#");
		objLoadingImageLink.onclick = function () {
			$("lightbox").style.display = "none";
			removeElement($("HeadBLayer"));
			$("div_opacity_img").style.display = "none";
			return false;
		}
		objOverlay.appendChild(objLoadingImageLink);

		var objLoadingImage = document.createElement("img");
		objLoadingImage.src = loadingImage;
		objLoadingImage.setAttribute("id","loadingImage");
		objLoadingImage.style.position = "absolute";
		objLoadingImage.style.zIndex = "150";
		objLoadingImage.style.border = "0px";
		objLoadingImage.style.top = (((arrayPageSize[0] - 35 - objLoadingImage.height) / 2) + "px");
		objLoadingImage.style.left = (((arrayPageSize[3] - 20 - objLoadingImage.width) / 2) + "px");
		objLoadingImageLink.appendChild(objLoadingImage);

		imgPreloader.onload=function(){};

		return false;
	}
	imgPreloader.src = loadingImage;

	// Crea lightbox div, same note about styles as above
	var objLightbox = document.createElement("div");
	objLightbox.setAttribute("id","lightbox");
	objLightbox.style.display = "none";
	objLightbox.style.position = "absolute";
	objLightbox.style.zIndex = "100";
	objBody.insertBefore(objLightbox, objOverlay.nextSibling);

	// Crea un link
	var objLink = document.createElement("a");
	objLink.setAttribute("href", "#");
	objLink.setAttribute("title", "Clicca per chiudere");
	objLink.onclick = function () {
		$("lightbox").style.display = "none";
		removeElement($("HeadBLayer"));
		$("div_opacity_img").style.display = "none";
		return false;
	}
	objLightbox.appendChild(objLink);

	// preload e crea l'immagine del pulsante "Chiudi"
	var imgPreloadCloseButton = new Image();
	imgPreloadCloseButton.onload=function(){
		var objCloseButton = document.createElement("img");
		objCloseButton.src = closeButton;
		objCloseButton.setAttribute("id","closeButton");
		objCloseButton.style.position = "absolute";
		objCloseButton.style.zIndex = "200";
		objCloseButton.style.border = "0px";
		objLink.appendChild(objCloseButton);

		return false;
	}

	imgPreloadCloseButton.src = closeButton;

	// Crea immagine
	var objImage = document.createElement("img");
	objImage.setAttribute("id","lightboxImage");
	objImage.style.border = "0px";
	objLink.appendChild(objImage);
}