﻿// JScript File

function navigateToApplication(link)
{
    if(link != '')
    {
        var linker;
        //alert('link: ' + link);
        //alert(window.opener);
        //alert(window.opener.closed);
        if(window.opener && !window.opener.closed)
        {
            //alert('window.opener.document');
            var browserName = navigator.appName; 
            //alert(browserName);
            if(browserName == "Microsoft Internet Explorer")
            {
                linker = window.opener.document;
            }
            else
            {
                linker = window.opener;
            }                      
            linker.focus();                        
        }
        else
        {
            //alert('window');
            //linker = window;
            //linker.location.href = link;                        
            var newWindow = window.open(link, '', 'location=1,menubar=1,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=1');
            newWindow.opener = null;
            window.opener = newWindow;
        }                    
    }
    //alert('false');
    return false;
}

function navigateAway(link)
{
    if(link == 'http://www.facorelogic.com/datacoverage/coverage.jsp')
    {
        window.open(link, '', 'location=1,menubar=1,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=1');
        return false;
    }
    return true;
}

// BEGIN Popup Handling Section
var xmlhttp=false;
//*@cc_on @*/
//*@if (@_jscript_version >= 5) 
// JScript gives us Conditional compilation, we can cope with old IE versions. 
// and security blocked creation of the objects.
try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
    try {
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
	xmlhttp = false;
    }
}

if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    xmlhttp = new XMLHttpRequest();
}

function checkLogin() {
    //popupDir = "/html/";
    xmlhttp.open("GET", "/jsp/rq.jsp?action=loginstatus", false);
    xmlhttp.send(null);
    //xmlhttp.onreadystatechange=function() {
    //if (xmlhttp.readyState==4) {
    //alert("#"+xmlhttp.responseText+"#");
    response =  xmlhttp.responseText.toLowerCase().indexOf("true");
    //secondDelim = xmlhttp.responseText.indexOf("|*-*|", firstDelim);
    //popupDir = xmlhttp.responseText.substring(firstDelim,secondDelim).replace("/\s/", "");
    //alert("#"+popupDir+"#");
    if(response > -1)
    {
        return true;
    }
    else
    {
        return false;
    }
}
// END Popup Handling Section

function displayLogin()
{
//    if(checkLogin() && window.opener && !window.opener.closed)
    if(window.name == "EkWindow")
    {
//        alert(window.name);
        PreSignin.style.display = "none";
        PostSignin.style.display = "inline";
    }
    else
    {
        PreSignin.style.display = "inline";
        PostSignin.style.display = "none";
//        if(window.name == "EkWindow")
//        {
//            alert(window.name);
//            window.name = "";
//            alert(window.name);
//        }
    }
}

function setLoginGetObj(name) {
    if (document.getElementById) {
	    return document.getElementById(name);
    }
    else if (document.all) {
	    return document.all[name];
    }
    else if (document.layers) {
   	    return document.layers[name];
    }
}

var PreSignin;
var PostSignin;

function setLogin()
{
    PreSignin = setLoginGetObj("ctl00_pnlPreSignin");
    PostSignin = setLoginGetObj("ctl00_pnlPostSignin");

    if(PreSignin != null && PostSignin != null)
    {
        displayLogin();
    }
    else{
        setTimeout("setLogin();", 5);
    }
}

setTimeout("setLogin();", 5);
