var chkBrowCookieName = "www_documenta_com_lastvisit";
var cookieAlertMsg = "";
var expDays = 1;
var exp = new Date(); 
//exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
exp.setTime(exp.getTime() + (1*60*1000));

function cookieAlert() { // scrive il testo di avvertimento se i cookies sono disabilitati
	document.write(cookieAlertMsg);
}

function initDoc() { //
if (document.all) {// IE
		document.styleSheets[0].href="css/documentaE.css"; 
	}
	chkBrowser(js_version);
}
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 winopen(newinLocation){
	var winname = "";
	var winwidth = 630;
	var wintop = 50;
	var heightmargin =100;
	var winheight = screen.height-wintop-heightmargin;
	var winleft = (screen.width-(winwidth))/2;
	if (document.all) {// IE
		topleft = ",top="+wintop+",left="+winleft;
	} else {// NN
		topleft = ",screenY="+wintop+",sceenX="+winleft;
	}
	if (newinLocation.indexOf("esempio.htm") > -1){
		winname = "ExampleWin";
		winprop = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no";
	} else if (newinLocation.indexOf(".pdf") > -1){
		winname = "ExamplePdf";
		winprop = "toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=yes,copyhistory=no";
	} else {
		winname = "ExternalWin";
		winprop = "toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes";
	}
	win = window.open(newinLocation, winname, (winprop+",width="+winwidth+",height="+winheight+topleft));
	if (!(document.all)) {// NN
		win.moveTo(winleft,wintop);
	}
	win.focus();
}

function chkBrowser(js_version) {
	if (chkBrowserNeeded()){
		if (GetCookie(chkBrowCookieName)== null){
				cookieAlertMsg = "<b><img src='img/alert.gif' width='31' height='31'>"
				cookieAlertMsg = cookieAlertMsg + "<font color='#FFFF00'> <font color='#910000' size='2'>"
				cookieAlertMsg = cookieAlertMsg + "Il browser non supporta i cookies o il supporto è disabilitato."
				cookieAlertMsg = cookieAlertMsg + "</font></font><font size='2'><br>"
				cookieAlertMsg = cookieAlertMsg + "Per accedere a tutte le funzioni di questo sito &egrave; necessario<br>"
			    cookieAlertMsg = cookieAlertMsg + "aggiornare il browser o abilitare il supporto per i cookies.</font></b>"
				cookieAlertMsg = cookieAlertMsg + "<p><img src='img/linea_arancio.gif' width='1000' height='2'></p>";
		}
		chkBrowser_core(js_version);
	}
}
function chkBrowser_core(js_version) {
    var agt=navigator.userAgent.toLowerCase();
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);
    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    var is_nav2 = (is_nav && (is_major == 2));
    var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && (is_major >= 4));
    var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    var is_nav6 = (is_nav && (is_major == 5));
    var is_nav6up = (is_nav && (is_major >= 5));
    var is_gecko = (agt.indexOf('gecko') != -1);
    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie4up  = (is_ie && (is_major >= 4));
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
	if((is_ie4up) || (is_nav4up)){// browser supportato
	}else{// browser sconosciuto
		alert("Attenzione: per accedere al sito documenta.com sono richiesti Internet Explorer o Netscape Navigator v. 4 o successive.");
	}
	if(js_version !== "1.2"){
		alert("Per accedere al sito documenta.com è richiesto JavaScript 1.2: si consiglia di aggiornare il browser utilizzato.");
	}
}
function chkBrowserNeeded(){
	var WWHTime = GetCookie(chkBrowCookieName);
	if (WWHTime==null){
		var rightNow = new Date();
		SetCookie (chkBrowCookieName, rightNow.getTime(), exp);
		return true;
	}
	return false;
}
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 = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}
