var show_alert_download_norme = 0;
var download_rimanenti = 0;
var ibox_item_id, ibox_url, ibox_title, ibox_params;	
function alertDownloadNorme() {

	
	document.write ('<div id="inner_content" style="display:none;">');
	document.write ('<div id="inner_alert_div" style="height:200px; line-height:18px;">');
	document.write ('<h2>Informazioni per il download</h2>');
	document.write ('<p>Registrandoti hai ricevuto un "<strong>bonus iscrizione</strong>" che ti consente di scaricare gratuitamente il testo di 3 norme.<br /></p>');
	/*
	if (download_rimanenti > 0) {
		document.write ('Puoi scaricare ancora ' + download_rimanenti + ' '+ stringa_norma +'; <a href="" id="link_download">clicca qui</a> per confermare il download.<br /><br /><br />');
	}
	else {
		document.write ('Avendo già scaricato 3 norme, hai esaurito il "bonus iscrizione".<br /><br /><br />');
	}
	*/
	document.write ('<p style="margin-top:15px"><span id="messaggio_alert_download"></span></p>');
	document.write ('<p style="margin-top:15px">Se desideri <strong>consultare l\'archivio completo delle nostre norme</strong>, <a href="/utente/acquisti/servizi.html" title="Abbonati a PrevenzioneIncendi.it"><strong>sottoscrivi un abbonamento</strong></a> della durata di <strong>365 giorni</strong> al prezzo di <strong>50 &euro; + iva</strong> per scaricare tutte le norme che desideri.</p>');
	document.write ('</div>');
	document.write ('</div>');
	
}

function changeId(item_id, url, title, params) {

	ibox_item_id	= item_id;
	ibox_url		= url;
	ibox_title		= title;
	ibox_params 	= params;
	
	var array_proprieta_ajax = new Array();
	array_proprieta_ajax["url"]='/api/get_xml_alert_download.php?idn=' + item_id;
	array_proprieta_ajax["method"]='GET';
	array_proprieta_ajax["onSuccess"]=handleHttpResponse_alertDownload;
	
	ServerRequest.sendRequest(array_proprieta_ajax);


}

function downloadNorma( id_norma ) {
	window.location.href = '/download.php?file='+ id_norma;
	hideIbox();
	
}

function handleHttpResponse_alertDownload( httpResponse ) {
	
	var xmlDocument = httpResponse.responseXML;
	show_alert_download_norme = xmlDocument.getElementsByTagName('show_alert_download_norme').item(0).firstChild.data;
	download_rimanenti = xmlDocument.getElementsByTagName('download_rimanenti').item(0).firstChild.data;
	
	//alert("show_alert_download_norme = " + show_alert_download_norme);
	//alert("download_rimanenti = " + download_rimanenti);

	//alertDownloadNorme();
	
	if ( show_alert_download_norme == '0' ) {
		window.location.href = '/download.php?file='+ ibox_item_id;
		return false;
	}
	
	msgAlertDownload = getObj('messaggio_alert_download');

	if (download_rimanenti > 0) {

		if (download_rimanenti == 1) {
			stringa_norma = 'norma';
		} else {
			stringa_norma = 'norme';
		}

		msgAlertDownload.innerHTML = 'Puoi scaricare ancora ' + download_rimanenti + ' '+ stringa_norma +'; <a href="javascript:void(0)" id="link_download" onClick="downloadNorma('+ibox_item_id+'); return false"><strong>clicca qui</strong></a> per confermare il download.<br />';
		//document.write ('Puoi scaricare ancora ' + download_rimanenti + ' '+ stringa_norma +'; <a href="" id="link_download">clicca qui</a> per confermare il download.<br /><br /><br />');
	} else {
		msgAlertDownload.innerHTML = 'Avendo già scaricato 3 norme, hai esaurito il "bonus iscrizione".<br />';
		//document.write ('Avendo già scaricato 3 norme, hai esaurito il "bonus iscrizione".<br /><br /><br />');
	}

	/*
	try {
		downloadObj = getObj('link_download');
		downloadObj.href = '/download.php?file='+ ibox_item_id;
	} catch (e) {
	}
	*/
	//alert("handleHttpResponse_alertDownload");
	
	if(showIbox(ibox_url, ibox_title, ibox_params)) {
		showBG();
		window.onscroll = maintPos;
		window.onresize = maintPos;
	}

}
