﻿// JScript File
function window_onload() 
{
    var dlgBox = ISGetObject("dlgBoxSecurity");
    dlgBox.ShowDialog();

    setTimeout(
    function()
    {   
        try
        { 
            var txtUser = ISGetObject("txtUserID");            
            if (txtUser.Value == "") 
                txtUser.SetFocus();
            else 
            {
                var txtPwd = ISGetObject("txtPassword");
                txtPwd.SetFocus();
            }
        }
        catch(e)
        {
        }
    }, 500);
}

function dlgBox_Closed(id, result)
{
    if (result == "OK")
    {
        
    }
    else
    {
        if (confirm("Are you sure want to cancel the login process?"))
            window.close();
        else
            return false;
    }
}

function dlgBox_BeforeCreated(id)
{
    var dlgBox = ISGetObject(id);
    dlgBox.EnableDropShadow = true;
}

function DoOK()
{
    var btnOK = ISGetObject("btnOK");
    var btnCancel = ISGetObject("btnCancel");
    var txtUser = ISGetObject("txtUserID")
    var user = txtUser.GetValueData();
    var txtPwd = ISGetObject("txtPassword")
    var pwd = txtPwd.GetValueData();
    var dlgBox = ISGetObject("dlgBoxSecurity");
    var lblProgress = document.getElementById("lblProgress");
    var pass = true;
    
    if (user == "" || user == null || pwd == "" || pwd == null)
        pass = false;
    
    event.returnValue = false;
    event.cancelBubble = true;
    
    if (pass)
    {
        if(!IS.moz)
        {
            btnOK.Hide();
            btnCancel.Hide();
            
            lblProgress.style.display = "";
        }
        else
        {
            btnOK.Disable();
            btnCancel.Disable();
        }
        
        return true;
    }
    else
    {
        var co = ISGetObject("coInfo");

        co.GetElement().style.zIndex = 300;
        
        if (user == "" || user == null)
        {
            co.SetText("Please fill in your User ID.");
            co.ShowAutoDetect(txtUser.HtmlObj, false);
            txtUser.SetFocus();
        }
        else
        {
            co.SetText("Please fill in your password.");
            co.ShowAutoDetect(txtPwd.HtmlObj, false);
            txtPwd.SetFocus();
        }
        
        return false;
    }
}

function DoCancel()
{
    var dlgBox = ISGetObject("dlgBoxSecurity");
    dlgBox.DialogResult = "Cancel";
    dlgBox.CloseDialog();
}

function IncorrectPassword()
{
    var btnOK = ISGetObject("btnOK");
    var btnCancel = ISGetObject("btnCancel");
    var txtUser = ISGetObject("txtUserID");
    var txtPwd = ISGetObject("txtPassword");
    var dlgBox = ISGetObject("dlgBoxSecurity");
    var lblProgress = document.getElementById("lblProgress");
    
    var co = ISGetObject("coInfo");
    co.GetElement().style.zIndex = 300;
    co.SetText("You have entered wrong password.");
    co.ShowAutoDetect(txtPwd.HtmlObj, false);
    txtPwd.SetFocus();
    
    btnOK.Show();
    btnCancel.Show();
    txtPwd.SetFocus();
    lblProgress.style.display = "none";
}

function LoginConfirmed()
{
    var chkFullScreen = document.getElementById("dlgBoxSecurity_ViewContentTemplate_chkFullScreen");
    var isIE7 = IsIE7x();
    var authenticatedUrl = "Authenticated/Default.aspx";
    var slVersion = IS.GetSilverlightVersion();
    
    if (slVersion != "" && IS.ie)
        authenticatedUrl = "Authenticated/Default_Silverlight.aspx";
    
    if (chkFullScreen.checked)
    {
        if (window.name != "TDN2_MAIN")
        {
            var windowAttributes = "fullscreen=yes, scroll=no, status=no";
            var wndName = "TDN2_MAIN";
            var fullWnd = null;
            
            if (IS.moz || isIE7) 
            {
                windowAttributes = "width=" + (window.screen.availWidth - (isIE7 ? 6 : 0)) + ",height=" + (window.screen.availHeight - (isIE7 ? 60 : 0));
                if (IsIE7x())
                    windowAttributes += ",left=0, top=0";
                else
                    wndName = "";
            }

            fullWnd = open(authenticatedUrl + "?fullscreen=yes", wndName, windowAttributes);
            
            if (!fullWnd)
            {
                alert("Please allow popup for this domain for full screen mode.");
                return;
            }
            
            var thisWnd = window.self;
            thisWnd.opener = window.self;
            if (!isIE7)
                thisWnd.close();
        }
        else
            location = authenticatedUrl; // if already in the full screen window, simply redirect the window's location.
    }
    else
    {
        location = authenticatedUrl;
    }
}

function txtPassword_OnKeyDown(controlId)
{
    if(event.keyCode == 13)
    {		        
        var btnOK = ISGetObject("btnOK");		                   
        var input = ISGetObject(controlId);
        
        input.HtmlObj.blur();
        setTimeout(function() {btnOK.SetFocus(); btnOK.Click();}, 10);
    }
	return true;
}

function Button_Init(id)
{
    var button = ISGetObject(id);
    
    Page.SetupButton(button);
}

function ShowAbout()
{
    var co = ISGetObject("coAbout");
    
    co.GetElement().style.zIndex = 300;
    co.ShowAutoDetect(document.getElementById("linkAbout"), false);
}

var Page =
{
    SetupButton: function(button)
    {
        var imageSet = new Object();
            
        imageSet.ButtonLeftInactive = imageSet.ButtonLeftOver = "mac/button_left_inactive.gif";
        imageSet.ButtonCenterInactive = imageSet.ButtonCenterOver = "mac/button_center_inactive.gif";
        imageSet.ButtonRightInactive = imageSet.ButtonRightOver = "mac/button_right_inactive.gif";
        imageSet.ButtonLeftActive = "mac/button_left_active.gif";
        imageSet.ButtonCenterActive = "mac/button_center_active.gif";
        imageSet.ButtonRightActive = "mac/button_right_active.gif";
        
        button.BorderType = "ComplexImages";
        button.WebResourceIdentifier = "D";
        button.ImagesSettings = imageSet;
        button.DesktopManager = new ISControl("Dummy");
        button.DesktopManager.WebResourceIdentifier = "D";
        button.DesktopManager.UseWebResourcesForClient = true;
        button.DesktopManager.ResolveImagePath = Page.ResolveImagePath;
        button.RenderComplexImages();
    },    
    
    ResolveImagePath: function(image)
    {
        return this._ResolveImagePath("/CommonLibrary/Images/WebDesktop/", image);
    }
};