function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function maximizeWindow() {
	if (GetCookie("ofmecc_full")=='0') {
		top.window.moveTo(0,0);
		if (document.all) {
			top.window.resizeTo(screen.availWidth,screen.availHeight);
		} else if (document.layers||document.getElementById) {
			if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
				top.window.outerHeight = screen.availHeight;
				top.window.outerWidth = screen.availWidth;
			}
		}
	}
}


function fullwin(page){
	window.open(page);
}

function getVar(name) {
	
	get_string = document.location.search;         
	return_value = '';
	
	do { //This loop is made to catch all instances of any get variable.
	name_index = get_string.indexOf(name + '=');
	
	if(name_index != -1) {
	  get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);
	  
	  end_of_value = get_string.indexOf('&');
	  if(end_of_value != -1)                
	    value = get_string.substr(0, end_of_value);                
	  else                
	    value = get_string;                
	    
	  if(return_value == '' || value == '')
	     return_value += value;
	  else
	     return_value += ', ' + value;
	  }
	} while(name_index != -1)
	
	//Restores all the blank spaces.
	space = return_value.indexOf('+');
	while(space != -1) { 
	  return_value = return_value.substr(0, space) + ' ' + return_value.substr(space + 1, return_value.length);
	  space = return_value.indexOf('+');
	}
	//alert(return_value);
	return(return_value);
}
function createMaximizeIcon(page) {
	//SetCookie ("ofmecc_full", '1');
	var sub=getVar('sub');
	document.write("<a href=\"javascript:void(0);\" onMouseOver=\"MM_swapImage('Image5','','img/full2.gif',1)\" onMouseOut=\"MM_swapImgRestore()\" onClick=\"icon_fullscreen('"+page+"');\"><img src=\"img/full1.gif\" alt=\"FULL SCREEN\" name=\"Image5\" width=\"12\" height=\"13\" border=\"0\"></a>");
}
function createMinimizeIcon(page) {
	//SetCookie ("ofmecc_full", '0');
	var sub=getVar('sub');
	document.write("<a href=\"javascript:void(0);\" target=\"_blank\" onMouseOver=\"MM_swapImage('Image_fin','','img/finestra2.gif',1)\" onMouseOut=\"MM_swapImgRestore()\" onClick=\"return icon_newwin('"+page+"');\"><img src=\"img/finestra1.gif\" alt=\"STANDARD MODE\" name=\"Image_fin\" width=\"12\" height=\"13\" border=\"0\"></a>");
}
function createIframe(page) {
	alert(page);
	document.write("<iframe name='CORNICE' frameborder=0 src='"+page+"' width='100%' height='100%'></iframe>");
}
function createIcons(page) {
	var c;
	//alert("got cookie:"+GetCookie("ofmecc_full"));
	if (c=GetCookie("ofmecc_full")=='0') {
		//alert("got cookie:"+c+" (min)");
		createMaximizeIcon(page);
	} else if (c=GetCookie("ofmecc_full")=='1') {
		//alert("got cookie:"+c+" (max)");
		createMinimizeIcon(page);
	} else {
		SetCookie ("ofmecc_full", '1');
		//alert("no cookie, so create it");
	}	
}

function getCookieVal (offset) {

	var endstr = document.cookie.indexOf (";", offset);
	
	if (endstr == -1)
		endstr = document.cookie.length;
	
	return unescape(document.cookie.substring(offset, endstr));

}

function GetCookie (name) {

	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) 
			break; 
	}
	
	return null;

}

function SetCookie (name, value)  {

	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (2 < argc) ? argv[2] : null;
	var path = (3 < argc) ? argv[3] : null;
	var domain = (4 < argc) ? argv[4] : null;
	var secure = (5 < argc) ? argv[5] : false;
	
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");

}

function DisplayInfo() {

	var expdate = new Date();
	var visit;
	
	expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365)); 
	
	if(!(visit = GetCookie("visit"))) 
		visit = 0;
	
	visit++;
	
	SetCookie("visit", visit, expdate, "/", null, false);
	
	var message;
	
	if(visit == 1) message=" Benvenuto nella pagina di HTML.it";
	if(visit == 2) message=" Esempio di Massimiliano Valente";
	if(visit == 3) message=" Visita il sito Web di HTML.it";
	if(visit == 4) message=" Visita www.html.it"; 
	if(visit == 5) message=" Qui puoi inserire un messaggio a piacere";
	if(visit == 6) message=" Qui puoi inserire un altro messaggio";
	
	alert("\n"+"Hai visitato questa pagina\n"+""+visit+" "+"volte."+"\n"+"\n"+message);

}

function ResetCounts() {

	var expdate = new Date();
	
	expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365)); 
	visit = 0;
	
	SetCookie("visit", visit, expdate , "/", null, false);
	leapto();

}

function xbDetectBrowser()
{
  var oldOnError = window.onerror;
  var element = null;

  window.onerror = null;
  
  // work around bug in xpcdom Mozilla 0.9.1
  window.saveNavigator = window.navigator;

  navigator.OS    = '';
  navigator.version  = parseFloat(navigator.appVersion);
  navigator.org    = '';
  navigator.family  = '';

  var platform;
  if (typeof(window.navigator.platform) != 'undefined')
  {
    platform = window.navigator.platform.toLowerCase();
    if (platform.indexOf('win') != -1)
      navigator.OS = 'win';
    else if (platform.indexOf('mac') != -1)
      navigator.OS = 'mac';
    else if (platform.indexOf('unix') != -1 || platform.indexOf('linux') != -1 || platform.indexOf('sun') != -1)
      navigator.OS = 'nix';
  }

  var i = 0;
  var ua = window.navigator.userAgent.toLowerCase();
  
  if (ua.indexOf('safari') != -1)
  {
    i = ua.indexOf('safari');
    navigator.family = 'safari';
    navigator.org = 'safari';
    navigator.version = parseFloat('0' + ua.substr(i+7), 10);
  }
  else if (ua.indexOf('opera') != -1)
  {
    i = ua.indexOf('opera');
    navigator.family  = 'opera';
    navigator.org    = 'opera';
    navigator.version  = parseFloat('0' + ua.substr(i+6), 10);
  }
  else if ((i = ua.indexOf('msie')) != -1)
  {
    navigator.org    = 'microsoft';
    navigator.version  = parseFloat('0' + ua.substr(i+5), 10);
    
    if (navigator.version < 4)
      navigator.family = 'ie3';
    else
      navigator.family = 'ie4'
  }
  else if (ua.indexOf('gecko') != -1)
  {
    navigator.family = 'gecko';
    var rvStart = ua.indexOf('rv:');
    var rvEnd   = ua.indexOf(')', rvStart);
    var rv      = ua.substring(rvStart+3, rvEnd);
    var rvParts = rv.split('.');
    var rvValue = 0;
    var exp     = 1;

    for (var i = 0; i < rvParts.length; i++)
    {
      var val = parseInt(rvParts[i]);
      rvValue += val / exp;
      exp *= 100;
    }
    navigator.version = rvValue;

    if (ua.indexOf('netscape') != -1)
      navigator.org = 'netscape';
    else if (ua.indexOf('compuserve') != -1)
      navigator.org = 'compuserve';
    else
      navigator.org = 'mozilla';
  }
  else if ((ua.indexOf('mozilla') !=-1) && (ua.indexOf('spoofer')==-1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera')==-1)&& (ua.indexOf('webtv')==-1) && (ua.indexOf('hotjava')==-1))
  {
    var is_major = parseFloat(navigator.appVersion);
    
    if (is_major < 4)
      navigator.version = is_major;
    else
    {
      i = ua.lastIndexOf('/')
      navigator.version = parseFloat('0' + ua.substr(i+1), 10);
    }
    navigator.org = 'netscape';
    navigator.family = 'nn' + parseInt(navigator.appVersion);
  }
  else if ((i = ua.indexOf('aol')) != -1 )
  {
    // aol
    navigator.family  = 'aol';
    navigator.org    = 'aol';
    navigator.version  = parseFloat('0' + ua.substr(i+4), 10);
  }
  else if ((i = ua.indexOf('hotjava')) != -1 )
  {
    // hotjava
    navigator.family  = 'hotjava';
    navigator.org    = 'sun';
    navigator.version  = parseFloat(navigator.appVersion);
  }

  window.onerror = oldOnError;
}

xbDetectBrowser();



function fullscreen(url) {
	//var larg_schermo = screen.availWidth - 10;
	//var altez_schermo = screen.availHeight - 30;
	SetCookie ("ofmecc_full", '1');
	newwindow=window.open(url, "full", "fullscreen=1,scrollbars=no");
}

function icon_fullscreen(url) {
	//var larg_schermo = screen.availWidth - 10;
	//var altez_schermo = screen.availHeight - 30;
	SetCookie ("ofmecc_full", '1');
	newwindow=window.open(url, "full", "fullscreen=1,scrollbars=no");
	
	window.close();
	return false;
}
function icon_newwin(url) {
	//var larg_schermo = screen.availWidth - 10;
	//var altez_schermo = screen.availHeight - 30;
	var w=760;
	var h=420;
	if (document.all) {
		w=screen.availWidth;
		h=screen.availHeight;
	} else if (document.layers||document.getElementById) {
		if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
			h = screen.availHeight;
			w = screen.availWidth;
		} else {
			h=top.window.outerHeight;
			w=top.window.outerWidth;
		}
	}
	
	SetCookie ("ofmecc_full", '0');
	newwindow=window.open(url, "normal", "top=0,left=0,screenX=0,screenY=0,height="+h+",width="+w+",scrollbars=auto,toolbar=yes,status=yes,menubar=yes,location=yes,resizable=yes");
	
	window.close();
	return false;
	
}
function popitup(url) {
	newwindow=window.open(url,'name','height=420,width=760');
	if (window.focus) {
		newwindow.focus()
	}
	return false;
}
