﻿
// JScript File
//global variables for all Result.aspx page including user controls
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_mousePos = null; //this variable is used for Locator usercontrol and  for display grids detailes in popup windows
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)
 {   
//     if(m_IE)             
//     {
       
     //<div style='display:none;position: absolute;top: 10px; left: 10px; width: 100px; height: 100px;  background-color: Lime;z-index: 1;'>
         //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.print();   
         printFrame.close();
//         var nodeElementToRemove = document.getElementById('printFrame');
//         if(nodeElementToRemove)
//            nodeElementToRemove.removeNode(true);
         //window.print();  
//     }
//     else
//     {
//        window.print();
//     }
 }
//////////////////////////////////////////////////////////////////////////

function ShowDetailsPopup(widgetId, headerContent, dataContent) 
{
    try
    {
        //debugger;
        var mouseHorOffSet = 10;
        var mouseVertOffset = 10;
        
        var content = "<Table Class='PopupTable' border='1' bordercolor='#ccccff' cellpadding='5' cellspacing='0'><tr Class='PopupHeader'>" + headerContent + "</tr><tr>" + dataContent + "</tr></Table>";
        
        ShowPopup(widgetId, mouseHorOffSet, mouseVertOffset, content); 
    }
    catch(e)
    {
        //alert("Operation is temporary unavailable.");
    }        
}

function ShowPopup(widgetId, mouseHorOffSet, mouseVertOffset, content) 
{
    try
    {
        //debugger;
        var widget = document.getElementById(widgetId); 
        //var ww =  document.getElementsByName(widgetId);
        //var grid = document.getElementById('DocList1_GridView_Group__popupDiv');
        //var divs = document.getElementsByTagName("table");
        //for (i=0; i< divs.length ; i++)
        //{
        //    var v = divs[i].id ;
        //}
        if(m_IE)
        {      
            widget.style['left'] = m_mousePos.x + mouseHorOffSet;
            widget.style['top'] = m_mousePos.y + mouseVertOffset;
        }
        else
         {      
            widget.style['left'] = (m_mousePos.x + mouseHorOffSet) + 'px';
            widget.style['top'] = (m_mousePos.y + mouseVertOffset) + 'px';
        }
            widget.style['display'] = 'block';    
        widget.innerHTML = content;                                              
        m_showDelay = setTimeout( "HidePopup('" + widgetId + "');" , 5000);               
    }
    catch(e)
    {
        //alert("Operation is temporary unavailable.");
    }        
}
//            
function HidePopup(widgetId) 
{
 try
    {    
        m_showDelay = window.clearTimeout(m_showDelay);
        m_hideDelay = window.clearTimeout(m_hideDelay);
        
         var widget = document.getElementById(widgetId); 
         //var divs = document.getElementsByTagName("div");
 
         //var ww =  document.getElementsByName(widgetId);
         widget.style['display'] = 'none';  
  }
      catch(e)
    {
        //alert("Operation is temporary unavailable.");
    }     
}
//////////////////////////////////////////////////////////////////////////
// tab controller functionality

function OpenDetailsTab( bext, ctrlname, func )
{
        __doPostBack(ctrlname,'');
}
function OpenTab ( bext, ctrlname, func )
{
    
   // if( bext == "False")
        __doPostBack(ctrlname,'');
   // else if (func != null || func != undefined)
   //     func();
}
//////////////////////////////////////////////////////////////////////////
function ActivateDownload(linkID)
{
    try
    {        
        var link = document.getElementById(linkID);
        
        if(link != null && link != undefined)		
		    link.click();		
    }
    catch(e)
    {
        //alert("Download Dialog Cannot be Activated. Please Check Your Browser Settings or Contact to Technical Support.");
    }
}

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;
    }
}
//////////////////////////////////////////////////////////////////////////
// widget scroll functionality has benn moved to widget and registered there
//var m_scrollTimer;
//function GetScrollPos(contentPanelID, ScrollPosChangeID , ScrollPosID)
//{
//    var div = document.getElementById(contentPanelID);
//    document.getElementById(ScrollPosID).value = div.scrollTop;
//    ////
//    var com;
//    document.getElementById(ScrollPosChangeID).value = "false";
//    com = "SetScrollPos('" + contentPanelID + "','"  + ScrollPosChangeID + "','" + ScrollPosID +  "')";
//    m_scrollTimer = setTimeout( com , 100);
//    
//}

//function SetScrollPos(contentPanelID,ScrollPosChangeID,ScrollPosID)
//{
//    var sc = document.getElementById(ScrollPosChangeID);
//    var v = sc.value;
//    if( document.getElementById(ScrollPosChangeID).value == "True")
//    {
//       window.clearTimeout(m_scrollTimer);
//       var div = document.getElementById(contentPanelID);
//       div.scrollTop = document.getElementById(ScrollPosID).value;
//    }
//    else
//    {
//       com = "SetScrollPos('" + contentPanelID + "','"  + ScrollPosChangeID + "','" + ScrollPosID +  "')";
//       m_scrollTimer = setTimeout( com , 100);
//    }
//}

//////////////////////////////////////////////////////////////////////////
function postBackByHiddenFields(name) 
{
    var hiddenField = $get(name);
    if (hiddenField) 
    {
         var arg = ''; 
         hiddenField.value = '';           
         if(hiddenField.value==null || hiddenField.value =="undefined")
         {hiddenField.value = (new Date()).getTime()+'_'+rand ( (new Date()).getSeconds() * 100 );}
         else
         {
             if(hiddenField.value == '')
                 hiddenField.value = (new Date()).getTime()+'_'+rand ( (new Date()).getSeconds() * 100 );
         }
         __doPostBack(name,arg);
     }
 }   
// hide all specified tags
var arrayFormTagNames = new Array("SELECT");
function ShowHideSearchForm(bshow)
{
//    var sf = document.getElementById(g_SearchFormID);//'SearchFormEx1_WidgetContainer'
//    var im = document.getElementById(g_ScreenblockerImageID);//'ProgreesImg'
//    if (bshow && sf != null)
//    {
//        sf.style['display'] = 'block';
//        if (im != null)
//        {
//            im.style['display'] = 'block';
//        }
//    }
//    else
//    {
//        sf.style['display'] = 'none';
//        if (im != null)
//           im.style['display'] = 'none';
//    }

}
function AddClass__CssFriendlyAdapters(element, classToAdd)
{
    if (HasAnyClass__CssFriendlyAdapters(element))
    {
        if (!HasClass__CssFriendlyAdapters(element, classToAdd))
        {
            element.className = element.className + " " + classToAdd;
        }
    }
    else if (CanHaveClass__CssFriendlyAdapters(element))
    {
        element.className = classToAdd;
    }
}
function HasAnyClass__CssFriendlyAdapters(element)
{
    return (CanHaveClass__CssFriendlyAdapters(element) && (element.className.length > 0));
}

// Usage
//  __doPostBack(name,arg);
//  __doPostBack('controlIDVorPostbackAni','argumentEtePetqaEteCheDatark');
//////////////////////////////////////////////////////////////////////////
//PDF Script
var  m_ActivatePdfPrintTimer;
var m_PDFPrinterName;
function ActivatePdfPrint(PDFPrinterName)
{
    try
    {
        m_PDFPrinterName = PDFPrinterName;
        m_ActivatePdfPrintTimer = setTimeout( "StartPdfPrint();" , 5); 
    }
    catch(e)
    {
        alert("PDF File Cannot be Printed. Please Contact to Technical Support.");    
    }
}

function StartPdfPrint()
{
    try
    {
        m_ActivatePdfPrintTimer = window.clearTimeout(m_ActivatePdfPrintTimer);
        PdfPostMessage('psilent', m_PDFPrinterName); 
    }
    catch(e)
    {
        m_ActivatePdfPrintTimer = setTimeout( "StartPdfPrint();" , 5);
    }
}

//var m_pdfTimeout;
//function PdfPostMessage(objid, arg1, arg2)
//{
//    
//    var obj = document.getElementById(objid);
//    if(obj == null)
//    {
//        alert(obj);
//        //m_pdfTimeout = setTimeout( "PdfPostMessage('" + objid + "','" + arg1 + "','" + arg2 + "')", 1000);
//        return;
//    }
//    alert('ok  ' + obj);
//    if (obj != null)// && obj.type == 'application/pdf')
//    {
//        try
//        {
//            debugger;
//            obj.postMessage([arg1, arg2]);
//            if(m_pdfTimeout != null)
//                window.clearTimeout(m_pdfTimeout);
//        }
//        catch(e)
//        {
//            alert(e);
//            //debugger;
//            m_pdfTimeout = setTimeout( "PdfPostMessage('" + objid + "','" + arg1 + "','" + arg2 + "')", 1000);
//        }
//    }
//}; 

function PdfZoomIn() 
{
    try
    {
        PdfPostMessage('zoomin', 10);
    }
    catch(e)
    {
        alert("The Action is Failed. Please Try Again.");
    }    
};

function PdfZoomReal()
{
    try
    {
        PdfPostMessage('zoomreal', 0);
    }
    catch(e)
    {
        alert("The Action is Failed. Please Try Again.");
    }        
}

function PdfZoomFit()
{
    try
    {
        PdfPostMessage('zoomfit', 0);
    }
    catch(e)
    {
        alert("The Action is Failed. Please Try Again.");
    }        
}

function PdfZoomOut() 
{ 
    try
    {
        PdfPostMessage('zoomout', 10);
    }
    catch(e)
    {
        alert("The Action is Failed. Please Try Again.");
    }        
};

function PdfRotateRight()
{
    //PdfPostMessage('rotate', '90');
}

function PdfRotateLeft()
{
    //PdfPostMessage('rotate', '270');
}

function PdfFirstPage()
{
    try
    {
        PdfPostMessage('firstpage', '');
    }
    catch(e)
    {
        alert("The Page is not Loaded Yet. Please Try Again.");
    }        
}

function PdfNextPage()
{
    try
    {
        PdfPostMessage('nextpage', '');
    }
    catch(e)
    {
        alert("The Page is not Loaded Yet. Please Try Again.");
    }            
}

function PdfPreviousPage()
{
    try
    {
        PdfPostMessage('prevpage', '');
    }
    catch(e)
    {
        alert("The Page is not Loaded Yet. Please Try Again.");
    }    
}

function PdfLastPage()
{
    try
    {
        PdfPostMessage('lastpage', '');
    }
    catch(e)
    {
        alert("The Page is not Loaded Yet. Please Try Again.");
    }            
}

function PdfGotoPage(txtid)
{
    try
    {
        var txt = document.getElementById(txtid);
        var pnum = txtid.value;
        PdfPostMessage('gotopage', pnum);
    }
    catch(e)
    {
        alert("The Page is not Loaded Yet. Please Try Again.");
    }        
}

function PdfPrint()
{
    try
    {
        PdfPostMessage('print', '25'); 
    }
    catch(e)
    {
        alert("PDF File Cannot be Printed. Please Contact to Technical Support.");
    }        
}
//
function PdfSilentPrint(printerName)
{
    try
    {
        PdfPostMessage('psilent', printerName); 
    }
    catch(e)
    {
        alert("PDF File Cannot be Printed. Please Contact to Technical Support.");
    }            
};

function PdfSave()
{
    try
    {
        PdfPostMessage('saveas', ''); 
    }
    catch(e)
    {
        alert("PDF File Cannot be Saved. Please Contact to Technical Support.");
    }        
}
///////////////////////////////////////////////////////////////////////////////////////
var m_ImageViewer = null;
function OpenImageViewer()
{
    try
    {
        var url = "ImageViewerEx.aspx?image=1";
        if(m_ImageViewer != null)
        {
            m_ImageViewer.close();
            m_ImageViewer = null;
        }
        m_ImageViewer = open(url,"ImageViewer","width=800,height=600,status=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes");
        if( m_ImageViewer != null && m_ImageViewer != undefined)
            m_ImageViewer.focus();        
    }
    catch(e)
    {
        alert("Image Viewer Cannot be Activated. Please Check Your Browser Settings or Contact to Technical Support.");    
    }
}
//////////////////////////////////////////////////////////////////////////
var m_CertViewer = null;
function OpenCertificateViewer()
{
    try
    {
        var url = "ImageViewerEx.aspx?image=2";   
        if(m_CertViewer !=null)
        {
            m_CertViewer.close();  
            m_CertViewer = null;        
        }    
        m_CertViewer = open(url,"CertificateViewer","width=800,height=600,status=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes");
        if( m_CertViewer != null && m_CertViewer != undefined)
            m_CertViewer.focus();        
    }
    catch(e)
    {
        alert("Certificate Viewer Cannot be Activated. Please Check Your Browser Settings or Contact to Technical Support.");
    }    
}
//////////////////////////////////////////////////////////////////////////
var m_EncViewer = null;
function OpenEncbWindow()
{
    try
    {
        if(m_EncViewer !=null)
        {
            m_EncViewer.close();        
            m_EncViewer = null;
        }
       m_EncViewer = open('EncumbranceViewerEx.aspx',"EncumbranceViewer","width=800,height=600,status=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes");
        if( m_EncViewer != null && m_EncViewer != undefined)
           m_EncViewer.focus();
    }
    catch(e)
    {
        alert("Encumbrance Viewer Cannot be Activated. Please Check Your Browser Settings or Contact to Technical Support.");
    }    
} 

// 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)
{
     //alert("yahooooo " + resourcePath);
     var wndURL = "Public/Download.aspx";
     wndURL += "?path=" + resourcePath + "&Filename=" + filename + "&descr=" + description;
     var windowName = "ResourceProvider";
     var windowId = "g_" + windowName;
     windowId = open(wndURL, windowName, 'width=500,height=400,status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no');
}
