﻿var _system = '';
function showHelp(helpFile)
{
    var s = parent.document.getElementById('hDivOpen').value.split(';');
    var Index = s.length;
    var path = 'Help%20Files/GLOBALERFX/Output/carolineb/MyWebHelp/Default.htm#StartTopic='
    if (helpFile.indexOf('Admin - ') >= 0) path = '../' + path;
    showPopup(Index, path + helpFile,'',550,750);
}
function showAdminHelp(helpFile)
{
    var s = parent.document.getElementById('hDivOpen').value.split(';');
    var Index = s.length;
    var path = 'Help%20Files/GLOBAL-UK-ADMIN/Output/carolineb/MyWebHelp/Default.htm#StartTopic='
    if (helpFile.indexOf('Admin - ') >= 0) path = '../' + path;    
    showPopup(Index, path + helpFile,'',550,750);
}
var gTabIndexes = new Array();
var gTabbableTags = new Array("A","BUTTON","TEXTAREA","INPUT","IFRAME");	

//Events
window.onresize = reposPopUp;
window.onafterresize = reposPopUp;

//Set Default value
function setDefault(Val, Default)
{
    if(Val == undefined || Val == '') return Default;    
	else return Val;
}

//Open div tag with transition
function doTransition(div, Visibility, Transition, Duration) 
{

	//div.filters[0].Apply();
	//div.filters[0].transition = Transition;
	//div.filters[0].duration = Duration;
	div.style.visibility = Visibility;
	//div.filters[0].Play();
	
}

function reposPopUp() 
{

    var s = parent.document.getElementById('hDivOpen').value.split(';');
    
    if (s.length > 0)
    {
    
        for (Index=0;Index<=s.length-1;Index++)
        {
        
            //var Index = i;//s.length-1;
            var div = eval('parent.document.getElementById("' + 'divPopup' + Index + '")');            
            var divMask = eval('parent.document.getElementById("' + 'divPopupMask' + Index + '")');            
            var ifm = eval('parent.document.getElementById("' + 'ifmPopup' + Index + '")');  
            var ifmMask = eval('parent.document.getElementById("' + 'ifm' + Index + '")');  

            if (div != undefined && div != '' && div != null) 
            {
            
                if (div.style.visibility == 'visible')
                {
                    var Height = parent.document.getElementById('hH' + Index).value; 
                    var Width = parent.document.getElementById('hW' + Index).value;
                    var Top = setDefault(parent.document.getElementById('hT' + Index).value, Top); 
                    var Left = setDefault(parent.document.getElementById('hL' + Index).value, Left);

                    var FormHeight = document.body.offsetHeight-4;
                    var FormWidth = document.body.offsetWidth-4;
                    if (document.documentElement && document.documentElement.clientWidth)
                    {
	                    FormHeight = document.documentElement.clientHeight;
 	                    FormWidth = document.documentElement.clientWidth;
                    }
                    if (Top == undefined || Top == 'undefined' || Top == '') 
                    {
                        Top = (FormHeight-div.offsetHeight)/2;
                        if (Top <= 10) Top = 10;
                        if(document.body.scrollTop > document.body.offsetTop) Top += document.body.scrollTop;
                    }

                    if (Left == undefined || Left == 'undefined' || Left == '')
                    {
                        Left = (FormWidth-div.offsetWidth)/2;
                        if (Left < 1) Left = 1;
                    }
                    if(document.body.scrollLeft > document.body.offsetLeft) Left += document.body.scrollLeft;
                                    
                    div.style.top = Top + "px";
                    div.style.left = Left + "px";
                    ifmMask.style.top = Top + "px";
                    ifmMask.style.left = Left + "px";
                    if (document.documentElement && document.documentElement.clientWidth)
                    {
                        if (document.documentElement.scrollHeight > document.documentElement.offsetHeight) FormHeight += ((document.documentElement.scrollHeight - document.documentElement.offsetHeight)+4);
                        if (document.documentElement.scrollWidth > document.documentElement.offsetWidth) FormWidth += ((document.documentElement.scrollWidth - document.documentElement.offsetWidth)+4);
                    }
                    else
                    {
                        if (document.body.scrollHeight > document.body.offsetHeight) FormHeight += ((document.body.scrollHeight - document.body.offsetHeight)+4);
                        if (document.body.scrollWidth > document.body.offsetWidth) FormWidth += ((document.body.scrollWidth - document.body.offsetWidth)+4);
                    }
                    divMask.style.height = FormHeight;
                    divMask.style.width = FormWidth;
                
                    var t=0;
                    var l=0;
                    var cNode = div;
                    while(cNode.tagName!='BODY')
                    { 
	                    l+=cNode.offsetLeft; 
	                    t+=cNode.offsetTop; 
	                    cNode=cNode.offsetParent; 
	                    if (cNode != null) break;
                    }
                    ifmMask.style.top = t;
                    ifmMask.style.left = l;
                    ifmMask.style.width = div.offsetWidth;
                    ifmMask.style.height = div.offsetHeight;
                    parent.document.getElementById('ifm' + Index).className = 'clsdisplayinline';
                    //ifmMask.className='clsdisplayinline';//.style.display = 'inline';
                    parent.document.getElementById('divPopupMask' + Index).className = 'clsdisplayBlockdivPopupMask';
                    //divMask.className='clsdisplayBlock';//.style.display = 'block';
                    var head = eval('parent.document.getElementById("' + 'tblPopupTitle' + Index + '")');
                    head.style.position = 'absolute';
                    head.style.top = 1;
                    
                }
            }
        }
    }
}

function hideDiv(div)
{
    div.className='clsdisplaynone';//.style.display = 'none';
}

function getObject(sControl)
{
    if (document.getElementById('GlobalMasterPage_' + sControl) != null) sControl = 'GlobalMasterPage_' + sControl;
    return sControl;
}

function showPopup(Index, Form, Title, Height, Width, Top, Left, CloseButton, TransitionOpen, TransitionClose, TransitionSpeed)
{



    //var Index = setDefault(Index, parent.document.getElementById('hDivOpen').value); 
    if (Index == undefined || Index == 'undefined' || Index == '') Index = 1;


    var Form = setDefault(Form, 'about:blank');
    if (Form == 'about:blank')
    {
        var s = parent.document.getElementById('hDivOpen').value;
        if (s.length > 0)
        {            
            s = parent.document.getElementById('hDivOpen').value.split(';');
            parent.document.getElementById('hDivOpen').value = '';
            for (i=1;i<=s.length-2;i++) parent.document.getElementById('hDivOpen').value += s[i] + ';';
            Index = i;
	    }
    }

    var sDivPopup = 'divPopup';
    var sDivPopupMask = 'divPopupMask';
    var sIfm = 'ifm';
    var sIfmPopup = 'ifmPopup';

    var div = eval(document.getElementById(sDivPopup + Index));


    
    var Title = setDefault(Title, '');
    
    var Height = setDefault(Height, 300); 
    var Width = setDefault(Width, 300);

	parent.document.getElementById('hH' + Index).value = Height;
	parent.document.getElementById('hW' + Index).value = Width;
	parent.document.getElementById('hT' + Index).value = Top;
	parent.document.getElementById('hL' + Index).value = Left;

    var CloseButton = setDefault(CloseButton, '1'); 
    
    var divMask = eval('parent.document.getElementById("' + sDivPopupMask + Index + '")');    
     
	parent.document.getElementById('hOpen').value = setDefault(parent.document.getElementById('hOpen').value, 1); 
	parent.document.getElementById('hClose').value = setDefault(parent.document.getElementById('hClose').value, 0); 
	parent.document.getElementById('hSpeed').value = setDefault(parent.document.getElementById('hSpeed').value, 0.5);
	
	var TransitionOpen = setDefault(TransitionOpen, parent.document.getElementById('hOpen').value); 
	var TransitionClose = setDefault(TransitionClose, parent.document.getElementById('hClose').value); 
	var TransitionSpeed = setDefault(TransitionSpeed, parent.document.getElementById('hSpeed').value);

	parent.document.getElementById('hOpen').value = TransitionOpen;
	parent.document.getElementById('hClose').value = TransitionClose;
	parent.document.getElementById('hSpeed').value = TransitionSpeed;

    if (div.style.visibility == 'visible')
    {
    
       
        if (Index < 2) hideDisplayObjects("visible");
        setTabIndexes("visible");
        parent.document.getElementById('divPopupMask' + Index).className='clsdisplaynone';
//        divMask.className='clsdisplaynone';//.style.display = 'none';
    
        var ifmMask = eval('parent.document.getElementById("' + 'ifm' + Index + '")');    
        parent.document.getElementById('ifm' + Index).className='clsdisplaynone';
        //ifmMask.className='clsdisplaynone';//.style.display = 'none';



        var ifm = eval('parent.document.getElementById("' + 'ifmPopup' + Index + '")');    
	    ifm.src = 'about:blank';
	    //if (Index == 1) 
	    disEnableControls(false, document);	    
        doTransition(div, "hidden", TransitionClose, TransitionSpeed);
        //parent.document.getElementById('hDivOpen').value = '';
	    //setTimeout('hideDiv(' + div.id + ')', 1000);
	    reposPopUp(); 
    }
    else
    {
       
        var s = parent.document.getElementById('hDivOpen').value.split(';');
        if (Index < s.length) Index = s.length;    

        disEnableControls(true, document);

        hideDisplayObjects("hidden");
        setTabIndexes("hidden");
 
parent.document.getElementById('btnClosePopup' + Index).className='clsdisplaynone';   
parent.document.getElementById('btnClosePopupTitle' + Index).className='clsdisplaynone';   
parent.document.getElementById('lblTitle' + Index).innerHTML = '&nbsp;';
parent.document.getElementById('tblPopup' + Index).className = 'clsdisplaynone';
parent.document.getElementById('tblPopupTitle' + Index).className='clsdisplaynone';
        if (Title == '') 
        {
        
            if (CloseButton != 0) 
//            {
//                parent.document.getElementById('btnClosePopup' + Index).className='clsdisplaynone';//.style.display = 'none';
//            }
//            else 
            {
                parent.document.getElementById('btnClosePopup' + Index).className='clsdisplayinline';//.style.display = 'inline';
            }
            parent.document.getElementById('tblPopup' + Index).className='clsdisplayinlinetblPopup';//.style.display = 'inline';
//            parent.document.getElementById('tblPopupTitle' + Index).className='clsPopupHeader';//.style.display = 'none';

        }
        else 
        {
            if (CloseButton != 0) 
//            {
//                parent.document.getElementById('btnClosePopupTitle' + Index).className='clsdisplaynone';//.style.display = 'none';
//            }
//            else 
            {
                parent.document.getElementById('btnClosePopup' + Index).className = 'clsdisplayinline';//.style.display = 'inline';
            }
            parent.document.getElementById('lblTitle' + Index).innerHTML = '&nbsp;' + Title;
//            parent.document.getElementById('tblPopup' + Index).className = 'clsPopupTitleClear';//.style.display = 'none';
            parent.document.getElementById('tblPopupTitle' + Index).className = 'clsdisplayinlinetblPopupTitle';//.style.display = 'inline';
        }
    
        var ifm = eval('parent.document.getElementById("' + 'ifmPopup' + Index + '")');    


	    ifm.src = Form;	  

        ifm.style.height = Height + "px";
        ifm.style.width = Width  + "px";
        
        div.style.height = Height  + "px";
        div.style.width = Width  + "px";   
       
        parent.document.getElementById('divPopup' + Index).className = 'clsdisplayBlockdivPopup';
        
        //div.className='clsdisplayBlock';//.style.display = 'block';
                
        parent.document.getElementById('hDivOpen').value +=  div.id + ';';

        doTransition(div, "visible", TransitionOpen, TransitionSpeed);    

        reposPopUp();

        if((div.offsetWidth - Width) < 30)
        {
            //ifm.style.width = Width + 10  + "px";
            Width = Width + (30 + (div.offsetWidth - Width));
            div.style.width = Width  + "px"; 
        }
        
        if((div.offsetHeight - Height) < 30)
        {
            ifm.style.height = Height + 20 + "px";
            Height = Height + (30 + (div.offsetHeight - Height));
            div.style.height = Height  + "px";
            
        }
        
	            
        var ifmMask = eval('parent.document.getElementById("' + 'ifm' + Index + '")');            
        var t=0;
        var l=0;
        var cNode = div;
        while(cNode.tagName!='BODY')
        { 
	        l+=cNode.offsetLeft; 
	        t+=cNode.offsetTop; 
	        cNode=cNode.offsetParent; 
	        if (cNode != null) break;
        }
        ifmMask.style.top = t;
        ifmMask.style.left = l;
        ifmMask.style.width = div.offsetWidth;
        ifmMask.style.height = div.offsetHeight;
        parent.document.getElementById('ifm' + Index).className = 'clsdisplayinline';
//        ifmMask.className='clsdisplayinline';//.style.display = 'inline';

        var browserName=navigator.appName; 
        if (browserName=="Microsoft Internet Explorer")
        {
            ifmMask.style.zIndex = ifmMask.style.zIndex + Index;
            div.style.zIndex = div.style.zIndex + Index;
            divMask.style.zIndex = divMask.style.zIndex + Index;
        }
        else
        {
         /*
            alert('ifmMask.style.zIndex Before' + ifmMask.style.zIndex);
            alert('divMask.style.zIndex Before' + divMask.style.zIndex);
            alert('div.style.zIndex Before' + div.style.zIndex);
         */
            ifmMask.style.zIndex = parseInt(ifmMask.style.zIndex) + parseInt(Index) + 10;
            div.style.zIndex = parseInt(div.style.zIndex) + Index + 10;
            divMask.style.zIndex = parseInt(divMask.style.zIndex) + Index + 10;
         /*
            alert('ifmMask.style.zIndex After' + ifmMask.style.zIndex);
            alert('divMask.style.zIndex After' + divMask.style.zIndex);
            alert('div.style.zIndex After' + div.style.zIndex);
         */
        }

        if (document.getElementById('slogan') != null)
            document.getElementById('slogan').tabIndex="-1";
     
        window.focus();

    }
}


//Disable/Enable controls
function disEnableControls(Status, obj)
{


    switch (obj.nodeName)
    {
        case '#document':
        {
            
	        for(var i = 0; i < obj.forms.length; i++) disEnableControls(Status, obj.forms[i])
            disEnableControls(Status,window.parent);
            var browserName=navigator.appName;
            if (browserName=="Microsoft Internet Explorer")
            {
                for(var i = 0; i < obj.frames.length; i++) disEnableControls(Status, obj.frames[i].document)
            }
            else
            {
                //for(var i = 0; i < obj.frames.length; i++) disEnableControls(Status, obj.frames[i].document)
            }
	        
        }
        break;
        case 'FORM':
        {
	        for(var i = 0; i < obj.elements.length; i++) 
	        {
	            if(obj.elements[i] != undefined)
	            {
	                if(obj.elements[i].type != 'hidden')
	                {
	                    disEnableControls(Status, obj.elements[i])
	                    if (obj.elements[i].tagName == 'SELECT') Status, obj.elements[i].disabled = Status;
	                }
	            }
	        }
        }
        break;
        case 'FRAME':
        {
	        for(var i = 0; i < obj.frames.length; i++) disEnableControls(Status, obj.frames[i].name)
        }
        break;
    }        
}

//Set Tab Indexes
function setTabIndexes(sStatus) 
{
	if (document.all) 
	{
		var i = 0;
		for (var j = 0; j < gTabbableTags.length; j++) 
		{
			var tagElements = document.getElementsByTagName(gTabbableTags[j]);
			for (var k = 0 ; k < tagElements.length; k++) 
			{
			    if (sStatus == "visible")
			    {
				    tagElements[k].tabIndex = gTabIndexes[i];
			        tagElements[k].tabEnabled = true;
				}
				else
				{
				    gTabIndexes[i] = tagElements[k].tabIndex;
				    tagElements[k].tabIndex="-1";
				}
				i++;
			}			
		}
	}
}

//Hide/display Objects
function hideDisplayObjects(sStatus) 
{
	for(var i = 0; i < document.forms.length; i++) 
		for(var e = 0; e < document.forms[i].length; e++)
			if(document.forms[i].elements[e].tagName == "OBJECT") document.forms[i].elements[e].style.visibility = sStatus;
}