var path = 'http://www.coopilpellicano.org/pellicanoweb/';
var req;

// ************************************************
// Returns URL content, using GET method
//
// addr : URL to ask for
//
// Must be called with an addr specified to begin to read URL content,
// then without any parameter to control if URL contenet is completely read or not
// It returns url content if already read, empty string otherwise
// ************************************************
function GetUrlContent(addr)
{
  // there could be errors in using ActiveX interface
  try
  {
    // there's a specified url, ask for content
    if (addr != null && addr != "")
    {
      if (window.ActiveXObject)
      {
        // create ActiveX object to read URL
        req = new ActiveXObject("Msxml2.XMLHTTP");
      }
      if (window.XMLHttpRequest)
      {
        req = new XMLHttpRequest();
      }
      //
      if (req) 
      {
        req.open("GET", addr, true);
        req.send(null);
      }
    }
    //
    // check request's status, if equal to 4 the job is done
    if (req.readyState == 4) 
    {
      // return response text
      return req.responseText;
    }
    else // not ready yet
    {
      return "";
    }
  } 
  catch (ex) // in error case
  { 
    alert(ex.message);
    // consider as not ready yet
    return ""; 
  }
}

function GetPage(div, addr)
{
  var HTML = ""; // used to concatenate HTML to be shown to user
  //
  // there could be errore in using ActiveX interface or retrieving HTMl objects
  try
  {
    // used to read HTML code representing requests of assistance
    var HTML = "";
    //
    // with a specified addr parameter retrieve its url content, asking to IN.DE web service
    // list of requests of assistance
    if (addr != null && addr != "")
    {
      // get response from specified addr
      // use getUrlContent with parameter
      HTML =  GetUrlContent(addr);
    }
    else // no addres specified, check if response is ready now
    {
      // use getUrlContent without parameter
      HTML = GetUrlContent();
    }
    //
    if (HTML == null || HTML == "")
    {
      setTimeout('GetPage(\''+div+'\', \'' + '\');', 100);
      return;
    }
    //
    document.getElementById(div).innerHTML = HTML;
  }
  catch (ex) {}
}

// **************************************************
// Read a parameter value passed via url
// **************************************************
function GetURLParam(strParamName)
{
  var strReturn = "";    // initially empty string
  //
  // look for parameters, "?" must be present
  var strHref = window.location.href;
  var commaPos = strHref.indexOf("?");
  if (commaPos > -1 )
  {
    // get all url after "?", in lower case
    var strQueryString = strHref.substr(commaPos).toLowerCase();
    //
    // look for specified parameter
    var ParamPos = strQueryString.indexOf(strParamName.toLowerCase() + "=");
    if (ParamPos > -1 )
    {
      // get right part of query string, first param now is the desired one
      var ParamString = strQueryString.substr(ParamPos);
      //
      // split token using "=" as delimiter
      var aParam = ParamString.split("=");
      //
      // 2nd token is value to return
      strReturn = aParam[1];
      //
      // remove possible next params
      if (strReturn.indexOf('&') > 0)
      {
        strReturn = strReturn.substr(0, strReturn.indexOf('&'));
      }
    }
  }
  //
  // return unescaped found value
  return unescape(strReturn);
} 

function SetPage(pagina)
{
	document.getElementById('WebFrame').src = pagina;
}