// ------------------------------------------------------
// getCookie(Name)
//
// Read the cookie whose name is passed as a parameter
// If the cookie is NOT found, return an empty string
// If the cookie is found, return the value of the cookie
// ------------------------------------------------------
function getCookie(Name)
{
  var search = Name + "=";
  var result = "";

  if (document.cookie.length > 0) // if there are any cookies
  {
    var offset = document.cookie.indexOf(search);
    if (offset != -1) // if cookie exists
    { 
      offset += search.length;
      var end = document.cookie.indexOf(";", offset)
      if (end == -1)
        end = document.cookie.length;
      result = unescape(document.cookie.substring(offset, end));
    }
  }
  return result;	
}

// -----------------------------------------------------------
// popupWindow(p_target, p_language)
//
// Show the login popup form if the user is not logged
// If the user is logged, directly redirect to the target page
// The test to determine if the user is logged is based on
// a cookie get
// -----------------------------------------------------------
function popupWindow(p_target, p_language)
{
  var p_url = new String("");
  var p_logged = getCookie("logged");	

  if ( p_logged == "")  // the user has never logged
  {
    // The path needs to be absolute: otherwise it doesn't work on Netscape
    p_url  = "http://www.teatroallascala.org/free/lascalaweb.user_form_public.g_show?p_target=" + p_target;
    p_url += "&p_language=" + p_language + "&p_opener_name=" + self.name;

	centerWindow(p_url, 'popupLogin', 600, 250, ',resizable=no,scrollbars=no');
  }    
  else  // the user has already logged
  {
    // The path needs to be absolute: otherwise it doesn't work on Netscape
    p_url  = "http://www.teatroallascala.org/free/lascalaweb.user_manager_public.c_quick_login?p_target=" + p_target;
    p_url += "&p_language=" + p_language;
    location = p_url;
  }
}

// -----------------------------------------------------------
// popupNewWindow(p_target, p_language)
//
// Show the login popup form if the user is not logged
// If the user is logged, directly redirect to the target page
// in a new window
// The test to determine if the user is logged is based on
// a cookie get
// -----------------------------------------------------------
function popupNewWindow(p_target, p_language)
{
  var p_url = new String("");
  var p_logged = getCookie("logged");	

  if ( p_logged == "")  // the user has never logged
  {
    // The path needs to be absolute: otherwise it doesn't work on Netscape
    p_url  = "http://www.teatroallascala.org/free/lascalaweb.user_form_public.g_show?p_target=" + p_target;
    p_url += "&p_language=" + p_language + "&p_opener_name=" + self.name + "&p_new_window=TRUE";

	centerWindow(p_url, 'popupLogin', 600, 250 , ',resizable=no,scrollbars=no');
  }    
  else  // the user has already logged
  {
    // The path needs to be absolute: otherwise it doesn't work on Netscape
    p_url  = "http://www.teatroallascala.org/free/lascalaweb.user_manager_public.c_quick_login?p_target=" + p_target;
    p_url += "&p_language=" + p_language;

	centerWindow(p_url, '_blank', 790, 500, 'scrollbars=yes');
  }
}










