// Funzioni varie per il sito


// Help popup. Per l'help contestuale. Accetta 2 parametri: Sezione del sito o gioco e Argomento
function openHelp(SiteSection,Topic) {
	popupWin = window.open('cp_PopUpHelp.asp?sid=' + SiteSection + '&cmd=' + Topic,'EIN','width=375,height=415,left=50,top=50,scrollbars=yes,resizable=yes');
	popupWin.focus();
}

// eccezione al popup. Apre una finestra di Chat
function ApriFinestraChat(mylink, windowname)
{
if (! window.focus)return true;
var href;
var winl = (screen.width - 400) / 2;
var wint = (screen.height - 500) / 2;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
var ref=window.open(href, windowname, 'width=500,height=400,top='+wint+',left='+winl+',scrollbars=no,resizable=no');
ref.focus();
return false;
}

// Apre una finestra popup
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
var LarghezzaFinestra = (screen.width - 300);
if (LarghezzaFinestra > 1024)
   LarghezzaFinestra=1024;
if (LarghezzaFinestra < 500)
   LarghezzaFinestra=500;
var AltezzaFinestra = (screen.height - 100);
if (AltezzaFinestra > 768)
   AltezzaFinestra=768;
if (AltezzaFinestra < 400)
   AltezzaFinestra=400;
var winl = (screen.width - LarghezzaFinestra) / 2;
var wint = (screen.height - AltezzaFinestra) / 2;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
var ref=window.open(href, windowname, 'width='+LarghezzaFinestra+',height='+AltezzaFinestra+',top='+wint+',left='+winl+',scrollbars=yes,resizable=yes');
ref.focus();
return false;
}


// Chiude la finestra e ripassa al chiamante
function targetopener(mylink, closeme, closeonly)
{
if (! (window.focus && window.opener))return true;
window.opener.focus();
if (! closeonly)window.opener.location.href=mylink.href;
if (closeme)window.close();
return false;
}

// Scrive un Coockie
function setCookie(name, value, days) {
  var expireDate = new Date ();
  expireDate.setTime( expireDate.getTime() + (days * 24 * 3600 * 1000) );
  document.cookie = name + "=" + escape(value) + "; expires=" + expireDate.toGMTString();
}

// Legge un Coockie
function getCookie(name) {
 if (document.cookie.length > 0) {
  var start;
  var end;
  start = document.cookie.indexOf(name + "=");
  if ( start == -1 ) return null;
  end = document.cookie.indexOf(";", start);
  if (end == -1) end = document.cookie.length;
   return unescape( document.cookie.substring(start + name.length + 1, end) );
  }
  return null;
 }

// Cancella un Coockie
function deleteCookie( name ) {
 if ( getCookie(name) ) {
  document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
 }

// BROWSER SNIFFER
function Is() {
  agent  = navigator.userAgent.toLowerCase();
  this.major = parseInt(navigator.appVersion);
  this.minor = parseFloat(navigator.appVersion);
  this.ns    = ((agent.indexOf('mozilla')   !=   -1) &&
               ((agent.indexOf('spoofer')   ==   -1) &&
               (agent.indexOf('compatible') ==   -1)));
  this.ns2   = (this.ns && (this.major      ==    3));
  this.ns3   = (this.ns && (this.major      ==    3));
  this.ns4b  = (this.ns && (this.major      ==    4) &&
               (this.minor                  <= 4.03));
  this.ns4   = (this.ns && (this.major      ==    4));
  this.ns6   = (this.ns && (this.major      >=    5));
  this.ie    = (agent.indexOf("msie")       !=   -1);
  this.ie3   = (this.ie && (this.major      <     4));
  this.ie4   = (this.ie && (this.major      ==    4) &&
               (agent.indexOf("msie 5.0")   ==   -1));
  this.ie5   = (this.ie && (this.major      ==    4) &&
               (agent.indexOf("msie 5.0")   !=   -1));
  this.ie55  = (this.ie && (this.major      ==    4) &&
               (agent.indexOf("msie 5.5")   !=   -1));
  this.ie6   = (this.ie && (this.major      ==    4) &&
               (agent.indexOf("msie 6")     !=   -1));
  this.nsdom = (this.ns4 || this.ns4b);
  this.iedom = (this.ie4 || this.ie5 || this.ie55);
  this.nedom = (this.ie4 || this.ie5 || this.ie55 || this.ns4);
  this.w3dom = (this.ie6 || this.ns6);
}

var is = new Is();

// Settaggio variabili da usare per indirizzare documento, stile e contenuto html
//(usate per la compatibilità cross browser)
var is = new Is()

if(is.nsdom) {
  doc = "document[";
  sty = "]";
  htm = "].document"
} else if(is.iedom) {
  doc = "document.all[";
  sty = "].style";
  htm = "].document";
} else if(is.w3dom) {
  doc = "document.getElementById(";
  sty = ").style";
  htm = ")";
}

// Come cambiare lo stato di visibilità:
function CambiaStatoVisibilitaDaID(ID, bVisibile){
   var MioLayer = eval(doc + '"' +ID+ '"' + sty);
   if (bVisible==0)
      { MioLayer.visibility = "hidden"; }
   else
      { MioLayer.visibility = "visible"; }
}

// Come cambiare il contenuto dell'HTML
function CambiaContenutoHTML(ID, NewHTML){
   var MioLayer = eval(doc + '"' +ID+ '"' + htm);
   var msg = NewHTML;
    if(is.nsdom) {
      MioLayer.write(msg);
      MioLayer.close();
    } else if(is.iedom || is.w3dom) {
      MioLayer.innerHTML = msg;
    }
}

// Come spostare un layer
function SpostaOggetto(ID,Left,Top){
   var MioObj = eval(doc + '"' +ID+ '"' + sty);
   MioObj.left = Left;
   MioObj.top = Top;
}

// Per conoscere lo spazio disponibile a video, nel tag <BODY> inserire ciò che segue:
// <body onload="available_width  = (is.iedom) ? document.body.clientWidth  : innerWidth;
//        available_height = (is.iedom) ? document.body.clientHeight : innerHeight;"
//        onresize=" available_width  = (is.iedom) ? document.body.clientWidth  : innerWidth;
//        available_height = (is.iedom) ? document.body.clientHeight : innerHeight;">


