/*=============================================================*/
// Funzione generica di apertura pagina:
// apriPagina('/home/testpage','_top');
//
function apriPagina(url,targetName) {
  var targetWin = targetName ? targetName : '_top';
  window.open(url,targetWin);
}
/*=============================================================*/

/*=============================================================*/
// Funzione generica di apertura popup:
// apriPopup('/home/testpage',800,600,true,true,targetName);
//
function apriPopup(url,x,y,scroll,resize,targetName) {
  var scrollVar = scroll ? 'yes' : 'no';
  var resizeVar = resize ? 'yes' : 'no';
  var targetWin = targetName ? targetName : '_blank';
  window.open(url,targetWin,'width='+x+',height='+y+',scrollbars='+scrollVar+',toolbar=no,status=no,location=no,directories=no,resizable='+resizeVar+',screenX=20,screenY=25');
}
/*=============================================================*/



function shortcutWinPopup(url,media,mode) {
  //alert(url+"\n"+media+"\n"+mode);
  var scrollbarsMode = '';
  var resizableMode = '';
  if (mode == '1') {
    scrollbarsMode = 'yes';
    resizableMode = 'yes';
  } else {
    scrollbarsMode = 'no';
    resizableMode = 'no';
  }
//  var widthSize = 610;
//  var heightSize = 537;
  var widthSize = 640;
  var heightSize = 495;
  if (media == 'Image') {
    widthSize = 610;
    heightSize = 537;
  } else if (media == 'Audio') {
    widthSize = 610;
    heightSize = 350;
  } else if (media == 'Video') {
    widthSize = 610;
    heightSize = 537;
  } else if (media == 'AudioNoRubrica') {
    widthSize = 350;
    heightSize = 380;
  } else if (media == 'VideoNoRubrica') {
    widthSize = 360;
    heightSize = 500;
  } else if (media == 'ImageNoRubrica') {
    widthSize = 240;
    heightSize = 199;
  }
  window.open(url,'_blank','width='+widthSize+',height='+heightSize+',scrollbars='+scrollbarsMode+',toolbar=no,status=no,location=no,directories=no,resizable='+resizableMode+',screenX=20,screenY=25');
}


function zoom(url,size) {
  window.open(url,'_blank','width='+size+',height='+size+',scrollbars=no,toolbar=no,status=no,location=no,directories=no,resizable=no,screenX=20,screenY=25');
}

//function zoomOn(url,sizeX,sizeY) {
function zoomOn(url,size) {
  var el = document.getElementById('zoom');

  el.innerHTML = "<a href='javascript:zoomOff();'><img border=0 src='" + url + "'></a>";

  el.style.width = size;
  el.style.height = size;
  el.style.display = 'block';
}
function zoomOff() {
  var el = document.getElementById('zoom');
  el.innerHTML = '';
  el.style.display = 'none';
}




function stayOnTouch_MainToPopup() {
  try {
    ircOpened.focus();
  } catch(err) {
    alert(err.message);
    ircWin(ircStart);
  }
}

function stayOnTouch_PopupToMain() {
  try {
    parent.opener;
  } catch(err) {
    alert(err.message);
    parent.close();
  }
}



var myTimer = null;









var ircOpened = null;
function ircWin(ircUrl) {
    ircOpened = window.open(ircUrl,'WebGuiIrcChatPopUp','width=600,height=400,scrollbars=yes,toolbar=no,status=no,location=no,directories=no,resizable=yes,screenX=20,screenY=25');
}


try {
  if ((ircStart.length > 1) && !Get_Cookie('WebGuiIrcChatPopUp')) {
    Set_Cookie('WebGuiIrcChatPopUp','Y','60','/','','');
    ircWin(ircStart);
  }
} catch(err) {}




function chatReload() {
  if (ircOpened != null && !ircOpened.closed) {
    ircOpened.close();
  }
  //Delete_Cookie('WebGuiIrcChatPopUp','/','');
  try {
    if (ircStart.length > 1) {
      ircWin(ircStart);
    }
  } catch(err) {}
}



function confermaSblocco(question1,action1,question2,action2) {
  if (confirm(question1)) {
    apriPopup(action1,10,10,false,false); //invia richiesta di modifica
  } else if (confirm(question2)) {
    apriPagina(action2); //forzatura sblocco
  }
  return false;
}





























function chatOff() { //kiamata dall'opener
  if (ircOpened != null && !ircOpened.closed) {
    ircOpened.close();
  }
}
function chatOffPopup() { //kiamata dal pop-up
  self.close();
}






function stayOnTouch() {
  try {
    ircOpened.focus();
  } catch(err) {
    Delete_Cookie('WebGuiIrcChatPopUp','/','');
    clearTimeout(myTimer);
  }
}






/*
for (var a in window) {
alert(a + ' ==> ' + window[a]);
}
*/
/*
var test = window.document;
for (var a in test) {
  //alert(a + ' ==> ' + test[a]);
  alert(test.name);
}
*/

























/*
if (ircOpened == null) {
  ircWin(ircStart);
  alert('opro');
} else {

  try {
    alert(ircOpened);
    ircOpened.focus();
  } catch(err) {
    alert(err.message);

    for (var a in err) {
      alert(a + '==> ' + err[a]);
    }


    ircWin(ircStart);
  }
}
*/


/*
if ((ircStart.length > 1) && !Get_Cookie('WebGuiIrcChatPopUp')) {
  Set_Cookie('WebGuiIrcChatPopUp','Y','60','/','','');
  ircWin(ircStart);
} else if (ircStart.length > 1) {
  var ircOpenedJsonText = Get_Cookie('WebGuiIrcChatPopUp');
  ircOpened = ircOpenedJsonText.parseJSON();
  try {
    //alert(ircOpened);
    ircOpened.focus();
  } catch(err) {
    alert(err.message);

    for (var a in err) {
      alert(a + '==> ' + err[a]);
    }


    ircWin(ircStart);
  }
}
*/

//Delete_Cookie('WebGuiIrcChatPopUp','/','');





function Set_Cookie( name, value, expires, path, domain, secure ) {
  // set time, it's in milliseconds
  var today = new Date();
  today.setTime( today.getTime() );

  /*
  if the expires variable is set, make the correct
  expires time, the current script below will set
  it for x number of days, to make it for hours,
  delete * 24, for minutes, delete * 60 * 24
  */
  if ( expires ) {
    //expires = expires * 1000 * 60 * 60 * 24;
    expires = expires * 1000 * 60;
  }
  var expires_date = new Date( today.getTime() + (expires) );

  document.cookie = name + "=" +escape( value ) +
  ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
  ( ( path ) ? ";path=" + path : "" ) +
  ( ( domain ) ? ";domain=" + domain : "" ) +
  ( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
function Get_Cookie(name) {
  var start = document.cookie.indexOf( name + "=" );
  var len = start + name.length + 1;
  if ( ( !start ) &&
  ( name != document.cookie.substring( 0, name.length ) ) )
  {
    return null;
  }
  if ( start == -1 ) return null;
  var end = document.cookie.indexOf( ";", len );
  if ( end == -1 ) end = document.cookie.length;
  return unescape( document.cookie.substring( len, end ) );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
  if ( Get_Cookie( name ) ) {
    document.cookie = name + "=" +
    ( ( path ) ? ";path=" + path : "") +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
  }
}



