/************************************************************************************************/
/* XMLHTTPRequest Interface                                                                     */
/************************************************************************************************/
function XHConn()
{
  var xmlhttp, bComplete = false;
  var sRes;


  try { xmlhttp = new ActiveXObject ("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject ( "Microsoft.XMLHTTP" ); }
  catch (e) { try { xmlhttp = new XMLHttpRequest (); }
  catch (e) { xmlhttp = false; }}}

  if ( !xmlhttp ) return null;

  this.connect = function( sURL, sMethod, sVars )
  {
    sRes = "error";
    if (!xmlhttp ) return sRes;

    bComplete = false;
    sMethod = sMethod.toUpperCase ();

    try 
    {
      if (sMethod == "GET")
      {
        xmlhttp.open (sMethod, sURL + "?" + sVars, false );
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, false);
        xmlhttp.setRequestHeader( "Method", "GET "+sURL+" HTTP/1.1" );
        xmlhttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
      }

      xmlhttp.onreadystatechange = function()
      {
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          sRes = xmlhttp.responseText;
        }

      };


      xmlhttp.send(sVars);
      if ( sRes == "error" ) sRes = xmlhttp.responseText;
    }

    catch(z) 
    {
      return sRes; 
    }

    return sRes;
  };

  return this;
}

function GetHtmlPage ( sURL, sVars )
{
  var myConn = new XHConn();
  if (!myConn) return "error";

  var sResp = myConn.connect( sURL, "POST", sVars );
  
  return sResp;
}

function GetScript ( type )
{
	return GetHtmlPage ( "/examples/" + type + ".cpp" );
}

function PrintExternalFile ( url )
{
	document.write ( GetHtmlPage ( url ) );
}

function LoadScript ( type )
{
	try
	{
		parent.load_script ( type );
	}
	catch (e)
	{
		alert ( "This feature is only available in embedded help" );
	}
}

function InsertIntoScript ( what, selstart, selend, include_file )
{
	try
	{
		parent.insert_into_script ( what, selstart, selend, include_file );
	}
	catch (e)
	{
		alert ( "This feature is only available in embedded help" );
	}
}
