// JavaScript Document
<!--
/*-------------------------------------*/
// THE ULTIMATE FOOTBANNER ADVERTISING 	/
//                                    	/
//  Creato da Saibal nel Gennaio 2008	  /
//                                    	/
// Dedicato al ciapet di Manuela Arcuri	/
//                                    	/
// Last revision: 22/01/08              /
/*-------------------------------------*/
/* ARGOMENTI:
1) tempo di chiusura automatica in millisecondi
2) durata del cookie  (in minuti). se impostata a "0" vale per una sessione
3) nome iframe (la dir www.html.it/ads_pages/)
4) lunghezza dell'iframe in pixel (default se vuoto vale 100%)
5) altezza dell'iframe in pixel (default se vuoto vale 90px)
*/

/* parte da aggiungere alla pagina nel HEAD:
<!-- FOOTERBANNER START -->
<script type="text/javascript" src="footerbanner.js"></script>
<script type="text/javascript">
addLoadEvent(function() { show_footbanner('50000','1','iframe.htm','',''); })
</script>
<!-- FOOTERBANNER START -->
*/

///////////////////////////
/* INIZIO CONFIGURAZIONE */
///////////////////////////
//path principale dei CSS
var url_css 		= 'http://supermercatipre.cosacerchi.org/';
var url_iframe  = 'http://supermercatipre.cosacerchi.org/';
var subdom_inc	= (subdom_inc) 	? subdom_inc 	: 'n';
//array dei siti con sottodominio per cui deve valere il cookie
site_cookname  	= new Array();
site_cookname[0]= 'cosacerchi.org';

function show_footbanner (autoclose,cook_time,myframename,myframe_w,myframe_h) {

  cook_name   		= window.location.hostname + '_footbanner';
	cook_domain 		= '';
	var b_explorer 	= navigator.appVersion.indexOf("MSIE");
	var objBody 		= document.getElementsByTagName("body").item(0);
	var objHead 		= document.getElementsByTagName("head").item(0);
	//dimensioni di default
	var myframe_w   = (myframe_w != '') ? myframe_w	: '99.9%';
	var myframe_h   = (myframe_h != '') ? myframe_h : '70px';

	//escludo gli explorer con la finestra più corta di 1000 pixel
	if (document.documentElement.clientWidth <= 900 && b_explorer != "-1") {
		return false;
	}

html_code =  '<div id="iframe_container" style="width:' +myframe_w+ ';">';
html_code += '<div id="close_left">';
html_code += '<a href="javascript:void(0);" onclick="close_footbanner(); return(false)">Chiudi</a></div>';
html_code += '<iframe id="myiframe" style="height:' +myframe_h+ ';" ';
html_code += 'src="' +url_iframe+myframename+ '" ';
html_code += 'frameborder="0" scrolling="no"></iframe>';
html_code += '</div>';

	// vedo che parametri dare al cookie (in caso dovesse passare anche subdomain)
	if (subdom_inc == 'y') {
  	for (i=0; i<site_cookname.length; i++) {
			if (window.location.hostname.indexOf(site_cookname[i]) != -1) {
			  cook_name 	= site_cookname[i] + '_footbanner';
				cook_domain	= site_cookname[i];
			}
		}
	}
 	
  //vedo se esistono gli elementi base della pagina
	if (objBody != "null" && objHead != "null") 
	{

		//se non c'è il cookie impostato
		if (document.getElementById && ScanCookie_footbanner(cook_name)==0) 
		{

			//stampo i css aggiuntivi
			if (document.getElementById('css_footbanner') != "null") {

				var cssNode 	= document.createElement('link');
				cssNode.id    = 'css_footbanner';
				cssNode.type 	= 'text/css';
				cssNode.rel 	= 'stylesheet';
				cssNode.href 	= url_css + 'footerbanner.css';
				cssNode.media = 'screen';
				objHead.appendChild(cssNode);
				document.getElementById('css_footbanner').disabled = false;
				
				// stampo i css solo per explorer 6.0 o inferiore
				if (parseInt(navigator.appVersion.substr(b_explorer+5)) <= 6) {

					var cssNode_ie 	= document.createElement('link');
					cssNode_ie.id    = 'css_footbanner_ie';
					cssNode_ie.type 	= 'text/css';
					cssNode_ie.rel 	= 'stylesheet';
					cssNode_ie.href 	= url_css + 'footerbanner_ie.css';
					cssNode_ie.media = 'screen';
					objHead.appendChild(cssNode_ie);
					document.getElementById('css_footbanner_ie').disabled = false;
					
				}
				
				if (document.getElementById('css_footbanner').disabled == false) {

					//creo il div contenitore della pagina
					firstdiv 		= objBody.getElementsByTagName('div')[0];
					if (firstdiv.id != "") {
		          	firstid 	= firstdiv.id;
          } else {
            alert('Attenzione! Il primo elemento della pagina non ha un ID');
            return false;
          }
            
			if (document.getElementById(firstid).parentNode != objBody) {
						alert('Attenzione! L\'elemento "' +firstid+ '" non è il primo div della pagina');
						return false;
					}
					
					ref_div 	= document.getElementById(firstid);
				 	pre_div 	= document.createElement('div');
				 	pre_div.setAttribute('id','pre_container');
				 	objBody.insertBefore(pre_div,ref_div);
				 	pre_div.appendChild(ref_div);

				 	//div spaziatore a fine pagina per MOZILLA e IE7
					space_elem = document.createElement('div');
				 	space_elem.setAttribute('id','footspacer');
		  		space_elem.style.height	= myframe_h;
				 	pre_div.insertBefore(space_elem, null);

					// div contenitore del footer banner
				 	foot_elem = document.createElement('div');
				 	foot_elem.setAttribute('id','footbanner');
				 	objBody.insertBefore(foot_elem, null);
				 	foot_elem.innerHTML   	= html_code;

	  		}
			}

		}
		else
		{	
			alert("Non Visualizzo");			
			begin();
		}

	}

	//chiudo la cagata di footbanner e setto il cookie
  setTimeout("close_footbanner()",autoclose);
  CreationCookie_footbanner(cook_name,false,cook_time,cook_domain);
  
} //fine funzione


/////////////////////
/* FUNZIONE CHIUDI */
/////////////////////
function close_footbanner() {

  if (document.getElementById('css_footbanner')) {
  	document.getElementById('css_footbanner').disabled = true;
  }
  
	if (document.getElementById('footspacer')) {
		document.getElementById('footspacer').style.display  = 'none';
	}
	
	if (document.getElementById('footbanner')) {
		document.getElementById('footbanner').style.display  = 'none';
	}
	
	/*if (document.getElementById('css_footbanner_ie')) {
  	document.getElementById('css_footbanner_ie').disabled = true;
  }*/

  /*if (document.getElementById('pre_container')) {
		document.getElementById('pre_container').style.height	='100%';
	}*/
	begin();
} //fine funzione


////////////////////////////////////
/* FUNZIONE SCANNA E SETTA COOKIE */
////////////////////////////////////
function ScanCookie_footbanner(variable) {

 cook    		= document.cookie;
 variable	 += "=";
 place   		= cook.indexOf(variable,0);

 if (place <= -1)
  return(0);
 else {
  end = cook.indexOf(";",place)
  if (end <= -1)
   return(unescape(cook.substring(place+variable.length,cook.length)));
  else
   return(unescape(cook.substring(place+variable.length,end)));
 }
}

function CreationCookie_footbanner(nome,valore,durata,dominio) {

	if (dominio != '') {
  	miodominio = "domain= " +dominio+ "; ";
  } else {
  	miodominio = '';
  }

	if (durata != 0) {
   	var calc_durata = parseInt(durata) * 60000;
   	var now 				= new Date();
  	var ex 					= new Date();
  	var valore      = escape(valore);
  	ex.setTime(now.getTime() + calc_durata);

		document.cookie = nome+ "=" +valore+ " ; path=/; " +miodominio+ "expires=" +ex.toGMTString();
	} else {
		document.cookie = nome+ "=" +valore+ "; path=/; " +miodominio+ "expires=";
	}

}// fine funzioni


///////////////////////////
/* FUNZIONE ADDLOADEVENT */
///////////////////////////
function addLoadEvent(func) 
{

	var oldonload = window.onload;
  if (typeof window.onload != 'function') 
  {
    window.onload = func;
  } 
  else 
  {
    window.onload = function() 
	{
      if (oldonload) 
	  {
        oldonload();
      }
      func();
    }
  }
}
//-->