/*
This js file is intended to be a repository for general java script functions
*/

//dialog vars
var PromptText;
var PromptTimeoutEnabled = false;

function showProcessing(mainform, processingform)
{
    ShowProgressBar();
}

function RedirectInNewWindow(url)
{
    var wd = 0.75*screen.width;
    var ht = screen.height;
    var myWindow=window.open(url,'_blank','width=' + wd.toString() + ',top=0,left=0,height=' + ht.toString() + ',resizable=yes,titlebar=yes,toolbar=yes,scrollbars=yes,menubar=yes,location=yes');
    if (myWindow == null)
    {
        myWindow=window.open(url);		
    }
		
    window.history.back();    
    
    if ( myWindow != null )
		myWindow.focus();    
}

function RedirectInNewWindowFromOnload(frm)
{
    document.getElementById(frm).submit(); 
    window.history.back();
}

function StartTimer (min)
{
	var ms;

	if ( min < 1 )	// provide default
		min = 15
	ms = min * 60 * 1000; //min * sec * ms

	window.setTimeout ('OpenPopup(' + min + ')', ms);
}

function OpenPopup (min)
{
	var LeftPosition = (screen.width) ? (screen.width-300)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-120)/2 : 0;
	var msg = "Your session is about to expire. Click 'ok' to extend your online session.";
	var settings = 'dialogHeight:150px;dialogWidth:300px;dialogLeft:' + LeftPosition + 'px;dialogTop:' + TopPosition + 'px;scrollbars:no;status:no;resizable:no;help:no;';
    var url = window.location.href;
    
    if (url.indexOf('Internal/Login.aspx') > -1)
    {
        url = url.replace("Internal/Login.aspx", "popupdialog.aspx");
    }
    else
    {
        url = "popupdialog.aspx"
    }
    
            
	if(window.showModalDialog)
	{
		var args = new Array(msg,true);
		var newWindow = window.showModalDialog(url,args,settings);
		if(newWindow == 'timeout')
			document.forms[0].submit();
		StartTimer (min);
	}
	else
	{
		PromptText = msg;
		PromptTimeoutEnabled = true;
        DisplayModalWindow(url,150,300,TopPosition,LeftPosition)
	}
}


function DisplayModalWindow(page,h,w,t,l)
{
	window.top.captureEvents (Event.CLICK|Event.FOCUS);
	winModalWindow = window.open (page,"ModalChild",	"dependent=yes,width="+w+",height="+h+",top="+t+",left="+l+"location=no,menubar=no,resizable=no,status=no,titlebar=no,toolbar=no");
	winModalWindow.focus();
}

function HideControls(htmltag)
{
    var tags = document.getElementsByTagName(htmltag);
    var ti = 0;
    if (tags)
    {
        while (tags[ti])
        {
            tags[ti].style.visibility = "hidden";
            ti++;
        }
    }
}

function ShowControls(htmltag)
{
    var tags = document.getElementsByTagName(htmltag);
    var ti = 0;
    if (tags)
    {
        while (tags[ti])
        {
            if (tags[ti].style.visibility == "hidden")
                tags[ti].style.visibility == "";
            ti++;
        }
    }
}

function ShowControls(htmltag)
{
    var tags = document.getElementsByTagName(htmltag);
    var ti = 0;
    if (tags)
    {   
        while (tags[ti])
        {
            tags[ti].style.visibility = "visible";
            ti++;
        }
    }
}

function GetClientIDOfServerControl(containerTag, ServerID, htmltag)
{
    var container = document.getElementById(containerTag);
    
    if (container)
    {
        var tags = container.getElementsByTagName(htmltag);
        var ti = -1;
        
        if (tags)
        {   
            while (tags[++ti])
            {
                if (tags[ti].id.indexOf(ServerID) > -1)
                    return tags[ti];
            }
        }
        else
        {
            return null;
        }
    }
    else
    {
        return null;
    }
}

	
