var lsBrowser = navigator.appName;
var navInfo = navigator.userAgent;
var intervallo=100;
var cont=0;
var tempo=0;
var flashRun=0;
var myShow;
var myHide;
var myWidthOLD;
var myHeightOLD;

function popupwindow(LarghezzaWindow,AltezzaWindow,Pagina) {

	var iMyWidth;
	var iMyHeight;
	var LarghezzaPagina;
	var AltezzaPagina;
	
	LarghezzaWindow=LarghezzaWindow.toUpperCase()
	AltezzaWindow=AltezzaWindow.toUpperCase()	

	LarghezzaPagina = window.screen.width;
	AltezzaPagina = window.screen.height;

	if (LarghezzaWindow == "FULL") {
			LarghezzaWindow = window.screen.width;
		}
	if (AltezzaWindow == "FULL") {
			AltezzaWindow = window.screen.height;
		}
	iMyWidth = (LarghezzaPagina/2) - (LarghezzaWindow/2); 
	iMyHeight = (AltezzaPagina/2) - (AltezzaWindow/2);
	var win = window.open(Pagina,"","height=" + (AltezzaWindow - 10) + ",width=" + (LarghezzaWindow-10) + ",menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",scrollbars=0");
//	var win = window.open(Pagina,"","height=" + (AltezzaWindow - 10) + ",width=" + (LarghezzaWindow-10) + ",menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,scrollbars=0");
	win.focus();
}
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 flashIsRunning(){
	flashRun=true;
//	alertSize();
}

function flash_is_load(){
	cont++;
	if(cont>50 || flashRun!=0){
		clearInterval(tempo);
		if(flashRun){
			SetCookie("flashPulgin", "true", null, "/", null, false);
		}else{
			SetCookie("flashPulgin", "false", null, "/", null, false);
			showHide('acc','flash');
		}
	}
}
function showHide(show,hide){
	if(show=="flash" && GetCookie("flashPulgin")=="false"){
		str_msg_confirm="Per visualizzare lo spot in home page del sito di Uliveto hai bisogno del plug-in Macromedia FlashPlayer 8. \nOK PER SCARICARE FLASH PLAYER 8 ";
		res=window.confirm(str_msg_confirm);
		if(res){
			RemoveCookie("show");
			RemoveCookie("hide");
			RemoveCookie("flashPulgin");
			window.location.href="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
		}
	} else {
		cambialocation=false;
		var expdate = new Date();
		expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
		SetCookie("show", show, expdate, "/", null, false);
		SetCookie("hide", hide, expdate, "/", null, false);
		if(show=="acc" && hide=="flash" && flashRun==true){
			cp=document.getElementById("flashobj").GetVariable("_root.currentURL");
			pos=window.location.href.indexOf(cp);
			if(window.location.href.substr(pos)!=cp){
				//alert(window.location.href+"\n"+cp);
				cambialocation=true;
			}
		}
		if(!cambialocation){
			document.getElementById(show).style.display="block";
			//alert(document.getElementById(show).style.display);
			document.getElementById(hide).style.display="none";
			//alert(document.getElementById(hide).style.display);
		}else{
			window.location.href=cp;			
		}
	}
}

function showHideAndSwap(show,hide,pagina) {
	showHide(show,hide);
	window.location.href=pagina;
} 

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 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 getCookieVal(offset){
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}

function RemoveCookie(name){
	document.cookie = name+"=; path=/";	
}

window.onload = function(){
	MM_preloadImages('/_images/logo_flyer_f2.gif','/_images/logoUliveto_f2.jpg');
	/*myShow=GetCookie("show");
	myHide=GetCookie("hide");
	if(myShow!=null && myShow!=''){
		showHide(myShow,myHide);
	}else{
		showHide('flash','acc');
		tempo = setInterval('flash_is_load()', intervallo);		
	}	*/
//	alertSize();
}
