var domain = "www.contextdiscovery.com"
var path = "http://"+ domain +"/logout.aspx";
var loginpath ="https://"+ domain +"/managemyaccount.aspx";
var downloadpath = "https://"+ domain +"/backProcessDownload.aspx";
var logoutpath = "http://"+ domain +"/logout.aspx";

function login()
{         
    //alert(path + " : " +loginpath)
    if(LoginMessage())
    {    
        alert("You are now logged on");
    }       
    if(ProcessLogin())
    {
        document.getElementById("imgaccount").setAttribute("src","images/logout.gif");
        document.getElementById("lnkaccount").setAttribute("href",path);
        document.getElementById("lnkProfile").style.display='';
    }
    else
    {
        document.getElementById("imgaccount").setAttribute("src","images/my-account.gif");
        document.getElementById("lnkaccount").setAttribute("href",loginpath);
        document.getElementById("lnkProfile").style.display='none';
    }   
}

function openwind()
{
    if(!ProcessLogin())
        alert("Please login in a system before download demo product.");
    else
        win = window.open("backProcessDownload.aspx","DownloadDemoProduct","width=100,height=100")            
}



function ProcessLogin()
{
    var req = null;
    if (navigator.userAgent.indexOf("Mozilla")>=0)
	{
        if(window.XMLHttpRequest)
        {
            req=new XMLHttpRequest();
        } 
    }
    //IF  IE browsers
    if (navigator.userAgent.indexOf("MSIE")>=0)
	{ 
        if(window.ActiveXObject)
        {
            req=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    var randomnumber=Math.floor(Math.random()*100000);
    req.open('GET', 'backProcessLogin.aspx?login=1&email=&pwd=&nocache='+randomnumber, false);
    req.send(null);
    if(req.status == 200)
    {
        if(req.responseText == "true")
            return true;
        else
            return false;
    }
}

function LoginMessage()
{
    var req = null;
    if(window.XMLHttpRequest)
    {
        req=new XMLHttpRequest();
    } else
    //IF  IE browsers
    if(window.ActiveXObject)
    {
        req=new ActiveXObject("Microsoft.XMLHTTP");
    }
    var randomnumber=Math.floor(Math.random()*100000);    
    req.open('GET', 'backProcessLogin.aspx?login=2&email=&pwd=&nocache='+randomnumber, false);
    req.send(null);          
    if(req.status == 200)
    {
        if(req.responseText != "true")
            return true;
        else
            return false;
    }
}

function SaveData()
{
    var req = null;
    if(window.XMLHttpRequest)
    {
        req = new XMLHttpRequest();        
    }else
        if(window.ActiveXObject)
        {
            req = new ActiveXObject("Microsoft.XMLHTTP");
        }
   
   var randomnumber = Math.floor(Math.random() * 100000);
   req.open('GET','backProcessLogin.aspx?login=11&email=&pwd=&nocache='+randomnumber, false);
   req.send(null);
   
   if(req.status == 200)
   {
        if(req.responseText == "true")
            return true;
        else
            return false;
   }
}

function DemoDownload(status)
{
//alert("The Free Download is temporarily not available. Please try in a few days.");    
//alert(loginpath + " : "+ downloadpath);
    var req = null;
    if(window.XMLHttpRequest)
    {
        req=new XMLHttpRequest();
    } else
    //IF  IE browsers
    if(window.ActiveXObject)
    {
        req=new ActiveXObject("Microsoft.XMLHTTP");
    }
    var randomnumber=Math.floor(Math.random()*100000);
    req.open('GET', 'backProcessLogin.aspx?login=8&nocache='+randomnumber, false);
    req.send(null);
    //alert(status);
    //alert(req.responseText);
    if(req.status == 200)
    {
        if(req.responseText == "false")
        {
            //alert("Demo product download available once you login.");
            if(status =="3")
            {    //location.href="managemyaccount.aspx";
                location.href=loginpath;
            }
        }
        else
        {
            //location.href="backProcessDownload.aspx";
            location.href=downloadpath;
            
            //win = window.open("backProcessDownload.aspx?login=&nocache='+randomnumber","DownloadDemoProduct","width=5,height=5,toolbar=0,menubar=0,titlebar=0");
            //win.Close();
            //win.sizeToContent();
        }
    }
}

function confirmdownload(status)
{
    var req = null;
    if(window.XMLHttpRequest)
    {
        req=new XMLHttpRequest();
    } else
    //IF  IE browsers
    if(window.ActiveXObject)
    {
        req=new ActiveXObject("Microsoft.XMLHTTP");
    }
    var randomnumber=Math.floor(Math.random()*100000);
    req.open('GET', 'backProcessLogin.aspx?login=10&nocache='+randomnumber, false);
    req.send(null);
    if(req.status == 200)
    {
        if(req.responseText == "true")
        {
            
                DemoDownload(status);
        }
    }

}

function logout()
{
    location.href= logoutpath;
}