﻿
// JScript File PageManager
var m_IE = false;
var m_showDelay; // timer delay to show widget
var m_hideDelay; // timer delay to hide widget
//////////////////////////////////////////////////////////////////////////
if(window.navigator.appName.toLowerCase().indexOf('explorer') != -1)
{
       m_IE = true;
}
//
var  m_showClientDelay;
//////////////////////////////////////////////////////////////////////////
function ClientLoad(dlay)
{
    m_showClientDelay = setTimeout( "ShowClient();" , dlay);      
}

function ShowClient()
{
    try
    {
        
        m_showClientDelay = window.clearTimeout(m_showClientDelay);
        var _screenMainPanel = document.getElementById("ScreenMainPanel");
        _screenMainPanel.style['display'] = 'block';
        var _screenLoadPanel = document.getElementById("ScreenLoadPanel");
        _screenLoadPanel.style['display'] = 'none';
    }
    catch(e)
    {
        alert("Operation is temporary unavailable.");
    }        
}
//////////////////////////////////////////////////////////////////////////
function PrintWindow()
 {   
     if(m_IE)             
     {
         var sHeaderStyle ="<head></head>";                               
         document.body.insertAdjacentHTML("beforeEnd","<div style='display:none;'><iframe name=printHiddenHelpFrame width='2480px' height='3508px'></iframe></div>");
         var doc = printHiddenHelpFrame.document;
         doc.open();
         doc.write(sHeaderStyle);
         doc.write("<body width=100% height=100%>");
         doc.write("</body>");
         doc.close();
         printHiddenHelpFrame.focus();
         printHiddenHelpFrame.print();         
         printHiddenHelpFrame.close();                  
     }
     else
     {
        window.print();
     }
 }
 function PrintReceipt(header, contentid)
 {   
         //debugger;
         var sHeaderStyle ="<head></head>";                               
         document.body.insertAdjacentHTML("beforeEnd","<iframe name=printFrame width='1px' height='1px' ></iframe>");
         var doc = printFrame.document;
         doc.open();
         doc.write(sHeaderStyle);
         doc.write("<body width=100% height=100%>");
         
         doc.write(header);
         doc.write("<div style='position:absolute;top:100px;left:0px'>");
         //doc.write("asdfasdfasdf");
         doc.write(document.getElementById(contentid).innerHTML);
         doc.write("</div>");
         doc.write("</body>");
         doc.close();
         printFrame.focus();
         setTimeout('printFrame.print();',150);
         printFrame.close();
 }
//////////////////////////////////////////////////////////////////////////
function SetMasterCheckbox(masterID)
{
    document.getElementById(masterID).checked = false;
}

function SetSlaveCheckboxes(masterID,idList)
{
    var ids = idList.split(",");
    var bMasterChecked = document.getElementById(masterID).checked;
    for( i = 0; i < ids.length; i++)
    {
        var ch = document.getElementById(ids[i]);
        ch.checked = bMasterChecked;
        ch.disabled = bMasterChecked;
    }
}

// set focus to form's element
var mt = null;
function setLoginfocus(widgetid, ctrlid)
{
	try
	{
	    //debugger;
		if(document.getElementById(widgetid) !=null)
		{
		    document.getElementById(widgetid).focus();
		    if(document.getElementById(ctrlid) != null)
			    document.getElementById(ctrlid).focus();
			if ( mt != null)
			{
				window.clearTimeout(mt);
			}
		}
	}
	catch(e)
	{
		mt = setTimeout("setLoginfocus('" + widgetid + "','" + ctrlid + "');",100);
	}
} 

function OpenResourceProvider(resourcePath, filename, description)
{
     var wndURL = "PublicDownload.aspx";
     wndURL += "?path=" + resourcePath + "&Filename=" + filename + "&descr=" + description;
     var windowName = "ResourceProvider";
     var windowId = "g_" + windowName;
     windowId = open(wndURL, windowName, 'width=500,height=250,status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no');
}

var widthKey, heightKey, leftKey, topKey;
function SaveWindowProperties() 
{
    //debugger;
    var myWidth = 0, myHeight = 0, myLeft = 0, myTop = 0;
    if( typeof( window.innerWidth ) == 'number' )
    {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
        myLeft = window.screenX;
        myTop = window.screenY;

    }
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
    {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
        myLeft = window.screenLeft;
        myTop = window.screenTop;

    }
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
    {
        //IE 4 compatible
         myWidth = document.body.clientWidth;
         myHeight = document.body.clientHeight;
         myLeft = window.screenLeft;//TODO: not sure
         myTop = window.screenTop;//TODO: not sure
    }
    
    document.cookie = widthKey + ' = ' + myWidth;
    document.cookie = heightKey + ' = ' + myHeight;
    document.cookie = topKey + ' = ' + myTop;
    document.cookie = leftKey + ' = ' + myLeft;
}

function RegisterEvents(_widthKey, _heightKey, _leftKey, _topKey)
{
    //debugger;
    widthKey = _widthKey; //'PopupImgWidth';
    heightKey = _heightKey; //'PopupImgHeight';
    leftKey = _leftKey; //'PopupImgLeft';
    topKey = _topKey; //'PopupImgTop';
    if(navigator.appName.indexOf('Netscape') > -1)
    {
        window.addEventListener('unload', SaveWindowProperties, false);
    }
    else
    {
        window.attachEvent('onunload', SaveWindowProperties, false);
    }
}

function doUnload()
{
   try { g_Registration.close(); } 
    catch(e) {}   
    
    try { g_Search_Help.close(); } 
    catch(e) {}   
    
    try { g_View_DocImage.close(); }  
    catch(e) {}   
    
    try { g_View_Certivicate.close(); } 
    catch(e) {}   
    
    try { g_View_Encumbrance.close(); } 
    catch(e) {}   
    
    try { g_DownloadWizard.close(); } 
    catch(e) {}   
    
    try { g_PrintWizard.close(); } 
    catch(e) {}   

    try { g_ResourceProvider.close(); } 
    catch(e) {}   
    
    try { g_PublicDownload.close(); } 
    catch(e) {}   
}

