﻿
// 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)
{
    var jsPanel = document.getElementById("JsInfoPanel");
    jsPanel.style['display'] = 'none';
		
    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);
	}
} 
var searchFocus = null;
function setSearchFormFocus(containerid)
{
    try
    {
        //debugger;
        var searchFormContainer = document.getElementById(containerid);
        var txtArray = searchFormContainer.getElementsByTagName('input');
        for(var i=0; i< txtArray.length; i++)
        {
            if(txtArray[i].className.toLowerCase().indexOf('def') > -1)
            {
                txtArray[i].focus();
                if (searchFocus != null)
			    {
				    //debugger;
				    window.clearTimeout(searchFocus);
			    }
                break;
            }
        }
     }
     catch(e)
     {
        searchFocus = setTimeout("setSearchFormFocus('" + containerid + "');",100);
	 }
}

function ShowPopupTest() {
    try {
        var testWin = window.open('popuptest.html', 'PopupTest', 'width=1,height=1,left=' + 300 + ',top=' + 300 + ',scrollbars=no,toolbar=no,menubars=no,location=no,status=no,titlebar=no');
        if (!CheckPopupBlocked(testWin)) {
            if (testWin)
                testWin.close();
            alert("Popup blockers are disabled.");
        }
        if (testWin && !testWin.closed)
            testWin.close();
    } catch (exception) {
        CheckPopupBlocked(null);
    }
}

function CheckPopupBlocked(windowId) {
    var retVal = false;
    if (!windowId || windowId.closed || typeof windowId.closed == 'undefined' || windowId.test) {
        retVal = true;
        alert("Popup blockers must be disabled to use this application.");
    }
    return retVal;
}

var g_PopupDisable;
function OpenPopupWindow() {    
    var wndURL = "PupupBlockerHelp.aspx";
    var windowName = "PopupDisable";
    g_PopupDisable = open(wndURL, windowName, 'height=600,width=700,left=200,top=200,resizable=yes,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no');
    CheckPopupBlocked(g_PopupDisable);
}


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');
    CheckPopupBlocked(windowId);
}

var g_PrintTesting;
function OpenPrintWizard(resourcePath)
{
    var wndURL = "PrintWizard.aspx";
    wndURL += "?TestMode=1&path=" + resourcePath;
    var windowName = "PrintTesting";
    g_PrintTesting = open(wndURL, windowName, 'width=600,height=500,status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no');
    CheckPopupBlocked(g_PrintTesting);
}

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) { }

    try { g_PopupDisable.close(); }
    catch (e) { }

    try { g_PrintTesting.close(); }
    catch (e) { }
    
    
}


