if( typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement ) {
	HTMLElement.prototype.insertAdjacentElement = function (where,parsedNode) { 
		switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this)
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling) this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else this.parentNode.appendChild(parsedNode);
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function (where,htmlStr) {
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}


	HTMLElement.prototype.insertAdjacentText = function (where,txtStr) {
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}
}

var cancella_cache = true;
var oggetti_caricati = "";
var rootdomain = "http://"+window.location.hostname;
var step_cache = "";

function carica_contenutoHP(url, containerid, HPswf) {
	
	var page_request = false;
  
  
	if (window.XMLHttpRequest) page_request = new XMLHttpRequest();
	else if (window.ActiveXObject) {
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e){
			try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){}
		}
	} else return false; //non abilitato
  
 if ((HPswf=='swf') && document.getElementById('menusx')) 
		document.getElementById('menusx').style.display = "none"; 

	
  

  
	page_request.onreadystatechange=function(){
		loadpage(page_request, containerid, HPswf);	
	}
	
	if (cancella_cache) step_cache = (url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime();
	page_request.open('GET', url+step_cache, true);
	page_request.send(null);
	
}

function loadpage(page_request, containerid, HPswf) {
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
	// && web_trends == false

		var elementoDiv =  document.getElementById(containerid);

		elementoDiv.innerHTML = page_request.responseText;
    if (HPswf!='swf')	{
    	 if (getCookieHPClassica('nomeHP')=='classica') {
      
      var elem_input=elementoDiv.getElementsByTagName('input');
      for (var j=0; j<elem_input.length; j++ ) {
       if (elem_input[j].id =='checkHP') elem_input[j].checked=true;
        
       }
    	}
    }
   
// if (HPswf=='swf'){
//    var elem_div=elementoDiv.getElementsByTagName("div");
//  	for ( var j=0; j<elem_div.length; j++ ) {
//  	 if ((elem_div[j].id =="visualHP") || (elem_div[j].id =="footerHP") || (elem_div[j].id =="navigazioneHP")) 

//  	 	elem_div[j].style.display = "none";
  	 	
 // 	}
  		
 //   var elem_ul=elementoDiv.getElementsByTagName("ul");
 //   for ( var j=0; j<elem_ul.length; j++ ) {
 //   	if (elem_ul[j].id =="menusx") 
 // 	 	elem_ul[j].style.display = "none";
  	 	
  	 	
 //   }
//  }

  if (HPswf!='swf'){
   var elem_div=elementoDiv.getElementsByTagName("div");
 	for ( var j=0; j<elem_div.length; j++ ) {
 	 if ((elem_div[j].id =="nav") || (elem_div[j].id =="visual_interno") || (elem_div[j].id =="footerHP")) 
 	 	elem_div[j].style.display = "none";
  	 	
 	}
	}
	 var elem_script = elementoDiv.getElementsByTagName("script");
		
		for ( var k=0; k<elem_script.length; k++ ) {
			
		var testohtml = elem_script[k].innerHTML;
	//	alert(k+' testohtml: '+ testohtml);	
		var ing = "<!"+"--";
		var usc = "--"+">";
		
		if (testohtml.indexOf(ing)!=-1 ) testohtml = testohtml.replace( ing,"");
	 
	  if  (testohtml.indexOf(usc)!=-1) testohtml = testohtml.replace( usc,"");
		
		eval(testohtml);	

		}
	}
}

function loadobjs(){
	if (!document.getElementById) return;

	for (i=0; i<arguments.length; i++) {
		var file = arguments[i];
		var fileref = "";
		
		if (oggetti_caricati.indexOf(file)==-1) {
			if (file.indexOf(".js")!=-1) {
				fileref=document.createElement('script');
				fileref.setAttribute("type","text/javascript");
				fileref.setAttribute("src", file);
			} else if (file.indexOf(".css")!=-1) {
				fileref=document.createElement("link");
				fileref.setAttribute("rel", "stylesheet");
				fileref.setAttribute("type", "text/css");
				fileref.setAttribute("href", file);
			}
		}
		if (fileref!=""){
			document.getElementsByTagName("head").item(0).appendChild(fileref);
			oggetti_caricati+=file+" ";
		}
	}
}



function setCookieHPClassica(checked,NameOfCookie,which){
	var expire = new Date();
	expire.setTime(expire.getTime() + (60*60*24*31*1000));
	if(checked == true){
		document.cookie = NameOfCookie + '='+which+'' + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))+";path=/";
	}else{eraseCooKieHPClassica(NameOfCookie,which,expire);}
}

function getCookieHPClassica(NameOfCookie)
{

// Prima controlliamo se c'è un cookie memorizzato.
// Altrimenti la lunghezza del document.cookie sarebbe zero.

if (document.cookie.length > 0)
{

// Poi controlliamo se il nome del cookie è conservato nell'oggetto
// "document.cookie"della pagina

// Siccome è possibile inserire più di un cookie su una
// singola pagina, è possibile che il nostro cookie
// non sia presente, anche se l'oggetto "document.cookie"
// non è solo un testo vuoto.
// Se il nome del nostro cookie non è presente, verrà memorizzato il valore -1
// nella variabile chiamata "begin".

begin = document.cookie.indexOf(NameOfCookie+"=");
if (begin != -1) // Nota: != significa "non è uguale a"
{

// Il nostro cookie era presente.
// Il valore memorizzato nel cookie viene rimandato dalla funzione.

begin += NameOfCookie.length+1;
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end)); }
}
return null;

// Il nostro cookie non era presente.
// Il valore "null" viene rimandato dalla funzione.

}

function set_page(NameOfCookie,HP1,HP2,pathHP)
{ 
	
	var can_play = false;
        var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	var mimetype = 'application/x-shockwave-flash';

	if (navigator.mimeTypes) 
	   if (navigator.mimeTypes[mimetype] != null) 
	      if (navigator.mimeTypes[mimetype].enabledPlugin != null) 
	         can_play = true;
	       
	if  (isIE && !can_play)  can_play= (ControlVersion()!=-1) ? true : false;
	 

 	if (getCookieHPClassica(NameOfCookie)=='classica' || !can_play) 
    		carica_contenutoHP(pathHP+'.html', 'home', 'classic');
 	else   carica_contenutoHP(pathHP+'_swf.html', 'home', 'swf');
 
}





function  eraseCooKieHPClassica(NameOfCookie,which,oldEx){
	var expire = new Date();
	expire.setTime(expire.getTime() - (1000*60*60*24));
	document.cookie= NameOfCookie + '='+which+'' + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))+";path=/";
}

function checkHPclassica(){
	var path=window.location.href;

	if(path.indexOf("html")>-1)
	 if (getCookieHPClassica('nomeHP')=='classica') 
             if (document.getElementById("checkHP"))
		 document.getElementById("checkHP").checked=true;


}

function rewrite() {
var url = location.href;
var urlnuovo = url;


if(url.indexOf('_swf.page') > -1){
	
var	urlultimo = urlnuovo.replace ('_swf.page', '.shtml');
    location.replace(urlultimo);
	}
	
	
	
}


function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}
