var g_oWindow = null;
var g_sCleanUp = "no";
function fnGetPath(sUrl)
{
    if( -1 != sUrl.indexOf( "?" ) )
    {
        sUrl = sUrl.substring( 0 , sUrl.indexOf("?") );
    }
    var path = sUrl.substring( 0 , sUrl.lastIndexOf( "/" ) + 1);
    if (path.indexOf("/corporate/") >= 0)
    {
      path = path.substring( 0 , path.lastIndexOf( "/corporate/" ) + 1);
    }
    return path;
}
function launch() {
var sURL = "";
var sWindowName = "";
var sHostname = "";
var sPathname = "";
var sFeatures = "";
var sProtocol = "";
var sHostNameTitle = "";
var sErrMsg = "";
      try
      {
            if (g_oWindow == null)
            {     
                  // Features
                  sFeatures += "left=0,";
                  sFeatures += "top=0,";
                  sFeatures += "location=No,";
                  sFeatures += "menubar=No,"; 
                  sFeatures += "resizable=Yes,";
                  sFeatures += "scrollbars=No,";
                  sFeatures += "status=Yes,";
                  sFeatures += "titlebar=Yes,";
                  sFeatures += "toolbar=No";
                  // Set Window Name
                  sWindowName = "_blank";
                  // Set Window Features
                  sFeatures = "status=yes,toolbar=no,menubar=no,location=no,resizable=yes";
                  // Host
                  sHostname = window.location.hostname;
                  // Protocol
                  switch (sHostname.toLowerCase()) {
                        case "www.telapoint.com":
                        case "louweb14.telapoint.com":
                        case "louweb15.telapoint.com":
                        case "louweb10.telapoint.com":
                        case "beta.telapoint.com":
                              sProtocol = "https:";
                              break;            
                        default:
                              sProtocol = "http:";
                              break;            
                  }
                  // Path
                  sPathname = fnGetPath(top.location.pathname)
                  // Login To TelaFuel
                  g_oWindow = window.open(sProtocol + "//" + sHostname + "/telafuel/login.asp?option=0&hostname=" + sHostname + "&cleanup=" + g_sCleanUp, sWindowName, sFeatures);
                  // Set Focus
                  g_oWindow.focus();            
            }
            else
            {
                  // Set Focus
                  g_oWindow.focus();                        
            }
      }
      catch(e)
      {
            switch (e.number) {
                  case -2147418094:
                        g_oWindow = null;
                        fnCleanUp(sProtocol + "//" + sHostname + "/telafuel/xmllogout.asp?");
                        launch();
                        break;
                  default:
                        fnGetErrorMessage("default.asp", "launch()", e)
                        break;
            }
      }           
}
function fnCleanUp(sURL) {
var httpObj = null;
var oXMLDocument = null;
var oXMLResult = null;
var sURL;
var sErrMsg = "";
      try
      {
            // Create
            httpObj = new ActiveXObject("Microsoft.XMLHTTP");  
            httpObj.open("GET", sURL, false);
            httpObj.setRequestHeader("Content-type", "text/xml");
            httpObj.send();
            oXMLDocument = httpObj.responseXML;
            // Check Result
            oXMLResult = oXMLDocument.selectSingleNode("//Result"); 
            if (parseInt(oXMLResult.getAttribute("ReturnCode"), 10) == 1)
            {
                  return true;
            }
            else
            {
                  oError = new Error(10429, "Call to xmlLogout.asp failed.");
                  throw oError;
            }
      }
      catch(e)
      {
            fnGetErrorMessage("default.asp", "fnCleanUp()", e)
      }
}
function fnOnLoad() {
      try
      {
            if(window.hotnews.clientHeight > window.topstories.height) window.topstories.height = window.hotnews.clientHeight;
            if(window.topstories.clientHeight > window.hotnews.height) window.hotnews.height = window.topstories.clientHeight      
      }
      catch(e)
      {
      
      }
}
function on_contextmenu() { 
      event.returnValue = false; 
      return false;
} 
function fnGetErrorMessage(sScriptName, sFunctionName, oError) {
var sError = "";
            sError += "Script Error: " + sScriptName + 
                          "\nFunction: " + sFunctionName +
                      "\nNumber: " + (oError.number & 0xFFFF) + 
                      "\nDescription: " + oError.description;
            return sError; 
}


