﻿// Function to apply rollover image and rollout image
var doc=document;
function RollOverImages(ImgID,RollOverImgSource)
{
    try
    {
        var Img=ImgID;
        doc.getElementById(Img).src=RollOverImgSource;
    }
    catch(err){return '';}
}

//old code.
function OpenColorPicker(TargetControl)
{
    try
    {
	    var color_picker_window
	    var ColorValue
	    if (window.ActiveXObject)
	    {
	    // for IE browser
	        ColorValue = showModalDialog('ColorPicker.aspx','ColorPicker','dialogHeight:410px;dialogWidth:420px; center:Yes; help:Yes; scroll:No')
	    }
	    else if(window.XMLHttpRequest)
	    {
	       // for Other Browser
	        ColorValue = showModalDialog('MozillaColorPicker.aspx','ColorPicker','dialogHeight:280px;dialogWidth:425px; center:Yes; help:Yes; scroll:No')
	    }
	    if(ColorValue)
	        {
		        if(ColorValue=="LOGOUT") window.opener.location.href="Default.aspx"
		        else
		        {
			        document.getElementById(TargetControl).style.backgroundColor = '#' + ColorValue
			        document.getElementById(TargetControl).style.color = '#' + ColorValue
			        document.getElementById(TargetControl).value = '#' + ColorValue
			        return ColorValue
		        }
	        }
    }
    catch(err){return '';}
}

function setHeight()
{
    try
    {
        var imgHeight = 400;
        var docHeight = document.documentElement.clientHeight;
        var calcHeight = (docHeight - imgHeight)/2;
        if ( calcHeight < 0 ){calcHeight = calcHeight * (-1);}
        document.getElementById("topBar").style.height = Math.floor(calcHeight) + "px";
        if(document.getElementById("classicView"))
        {
            if(document.getElementById("classicView").style.display=="")
            {
                document.getElementById("homeView").style.display = "none";
            }
            else
            {
                document.getElementById("homeView").style.display = "";
            }
        }
    }
    catch(err){return '';}
}

function ApplyMaskingDiv(callee)
{   
//    if (callee == "BtmPnl")
//    {
//        try
//        {
//            // Masking the whole screen
//            var top = (parent.frames[1].document.documentElement.clientHeight)/2;
//            top = Math.floor((top * 10)/100);
//            for(var i=0;i<4;i++)
//            {
//                parent.frames[i].document.getElementById('MaskedDiv').style.display='';
//                parent.frames[i].document.getElementById('MaskedDiv').style.visibility='visible';
//                parent.frames[i].document.getElementById('MaskedDiv').style.top='0px';
//                parent.frames[i].document.getElementById('MaskedDiv').style.left='0px';
//                parent.frames[i].document.getElementById('MaskedDiv').style.width =  4000 + 'px';
//                parent.frames[i].document.getElementById('MaskedDiv').style.height = 2000 + 'px';
//            }
//            parent.frames[1].document.getElementById('divAbout').style.display = "";
//            parent.frames[1].document.getElementById('divAbout').style.top = top + "px";
//            
//        }
//        catch(ex)
//        {
//            window.parent.document.getElementById('MaskedDiv').style.display='';
//            window.parent.document.getElementById('MaskedDiv').style.visibility='visible';
//            window.parent.document.getElementById('MaskedDiv').style.top='0px';
//            window.parent.document.getElementById('MaskedDiv').style.left='0px';
//            window.parent.document.getElementById('MaskedDiv').style.width =  4000 + 'px';
//            window.parent.document.getElementById('MaskedDiv').style.height = 2000 + 'px';
//            window.parent.document.getElementById('divAbout').style.display = "";
//        }
//    }
//    else if (callee == "DiWizardHome")
//    {
//        document.getElementById ('MaskedDiv').style.display='';
//        document.getElementById ('MaskedDiv').style.visibility='visible';
//        document.getElementById ('MaskedDiv').style.top='0px';
//        document.getElementById ('MaskedDiv').style.left='0px';
//        document.getElementById ('MaskedDiv').style.width =  4000 + 'px';
//        document.getElementById ('MaskedDiv').style.height = 2000 + 'px';
//        document.getElementById ('divAbout').style.display='';
//    }
//    HideLoader();
}

function RemoveMaskingDiv(callee)
{
//    if (callee == "BtmPnl")
//    {
//        // Remove the masking from the screen
//        for(var i=0;i<4;i++)
//        {
//            parent.frames[i].document.getElementById ('MaskedDiv').style.display='none';
//            parent.frames[i].document.getElementById ('MaskedDiv').innerHTML = "";
//        }
//        parent.frames[1].document.getElementById('divAbout').style.display = "none";
//    }
//    else if(callee == "DiWizardHome")
//    {
//        document.getElementById ('MaskedDiv').style.display='none';
//        document.getElementById('divAbout').style.display = "none";
//        try
//        {
//            document.getElementById("Iframe1").document.getElementById("MaskedDiv").style.visibility = 'hidden';
//            document.getElementById("Iframe1").src = document.getElementById("Iframe1").src;
//        }
//        catch(ex)
//        {}
//        try
//        {
//            document.getElementById ('MaskedDiv').style.visibility='hidden';
//        }
//        catch(ex)
//        {
//        }
//    }
}

function OpenDiAbout(callee)
{ 
    var divAbout = null;
    
    //Try to find the div anyway
    try{
        divAbout = parent.frames[1].document.getElementById('divAbout');
    }
    catch(ex)
    {
        try{
            divAbout = window.parent.document.getElementById('divAbout');
        }
        catch(ex){
            divAbout = document.getElementById ('divAbout');
        }
    }
   
    // Show once found and then only apply mask
    if(divAbout)
    {             
        ApplyMask();                   
        divAbout.style.display = "";
        
        if (callee == "BtmPnl")
        {
            var top = (parent.frames[1].document.documentElement.clientHeight)/2;
            top = Math.floor((top * 10)/100);            
            //divAbout.style.top = top;
        }   
    }
}

function CloseDiAbout(callee)
{       
    var divAbout = null;
    
    //Try to find the div anyway
    try{
        divAbout = parent.frames[1].document.getElementById('divAbout');
    }
    catch(ex)
    {
        try{
            divAbout = window.parent.document.getElementById('divAbout');
        }
        catch(ex){
            divAbout = document.getElementById ('divAbout');
        }
    }
   
    // Hide once found
    if(divAbout){
        divAbout.style.display = "none";
    }
    // Remove mask in every case
    RemoveMask();        
}

function ShowLoader()
{
    var divLoader = parent.frames[1].document.getElementById("divLoader");    
    if(divLoader){
        MakeLoaderCentered(divLoader, 32, 32);
        divLoader.style.display = "block";
    }
}

function HideLoader()
{
    var divLoader = parent.frames[1].document.getElementById("divLoader");
    if(divLoader){
        divLoader.style.display = "none";
    }
}

function MakeLoaderCentered(ctlPopup, popupWidth, popupHeight)
{    
    var availHeight = 0;
    var availWidth = 0;
    var doc = window.parent.document;
    var win = window.parent.window;
    
    if(typeof(win.innerWidth) == 'number'){
        availHeight = win.innerHeight;
        availWidth = win.innerWidth;
    }else if(doc.documentElement && (doc.documentElement.clientWidth || doc.documentElement.clientHeight)){
        availHeight = doc.documentElement.clientHeight;
        availWidth = doc.documentElement.clientWidth;
    }else if(doc.body && (doc.body.clientWidth || doc.body.clientHeight)){
        availHeight = doc.body.clientHeight;
        availWidth = doc.body.clientWidth;
    }

    var WinTop = (availHeight - popupHeight)/2;
    var WinLeft = (availWidth - popupWidth)/2;   
    
    if(WinTop < 0) WinTop = 0;
    if(WinLeft < 0) WinLeft = 0;    
        
    ctlPopup.style.top = (WinTop - 140) + "px";
    ctlPopup.style.left = WinLeft + "px";
}

function ApplyMask()
{   
    try
    {
        var MaskedDiv = null;
        
        if(window.parent && window.parent.frames.length > 0) // If the page contains iframe
        {
            for(var i=0; i<parent.frames.length; i++)
            {
                // Search everywhere for the MaskedDiv
                try{
                    MaskedDiv = parent.frames[i].document.getElementById('MaskedDiv');
                }
                catch(ex){
                    MaskedDiv = document.getElementById('MaskedDiv');
                }
                
                // Try to apply only if found
                if(MaskedDiv){            
                   SetMaskDivAttributes(MaskedDiv, true);
                }
            }
        }
        else // If the page contains no-iframe
        {
            MaskedDiv = document.getElementById('MaskedDiv');
            if(MaskedDiv){            
               SetMaskDivAttributes(MaskedDiv, true);
            }
        }
    }
    catch(ex){
        // do nothing
    }             
}

function RemoveMask()
{   
    try
    {
        var MaskedDiv = null;
        
        if(window.parent && window.parent.frames.length > 0) // If the page contains iframe
        {            
            for(var i=0; i<parent.frames.length; i++)
            {
                // Search everywhere for the MaskedDiv
                try{
                    MaskedDiv = parent.frames[i].document.getElementById('MaskedDiv');
                }
                catch(ex){
                    MaskedDiv = document.getElementById('MaskedDiv');
                }
                
                // Try to remove only if found
                if(MaskedDiv){                        
                    SetMaskDivAttributes(MaskedDiv, false);                             
                }
            }
        }
        else // If the page contains no-iframe
        {                
            MaskedDiv = document.getElementById('MaskedDiv');
            if(MaskedDiv){            
                SetMaskDivAttributes(MaskedDiv, false);
            } 
        }
    }
    catch(ex){
        // do nothing
    }             
}

function SetMaskDivAttributes(MaskedDiv, forApplying)
{
    // If current call is for applying mask
    if(forApplying)
    {
        MaskedDiv.style.display = '';
        MaskedDiv.style.visibility = 'visible';
        MaskedDiv.style.top = '0px';
        MaskedDiv.style.left = '0px';
        MaskedDiv.style.width = 4000 + 'px';
        MaskedDiv.style.height = 2000 + 'px';
    }
    else // If it is for removing mask
    {
        MaskedDiv.innerHTML = '';
        MaskedDiv.style.visibility = 'hidden';                
        MaskedDiv.style.display = 'none';
    }
}