var warningTimeout = 1080000;
var finalTimeout = 1200000;
//var warningTimeout = 3000;
//var finalTimeout = 5000;
var warningTimeoutID;
var finalTimeoutID;
var minrestore=0
var initialwidth,initialheight
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all
var ileft = 50;
var itop = 100;
var valid = true;

function startTimeout() {
	window.clearTimeout(warningTimeoutID);
	window.clearTimeout(finalTimeoutID);
	warningTimeoutID = window.setTimeout('displayWarning()', warningTimeout);
	finalTimeoutID = window.setTimeout('displayTimeoutAlert()', finalTimeout);
}

function displayWarning() {
	loadwindow("warning",500,120);
}

function displayTimeoutAlert() {
	closeit("warning");
    loadwindow("timeout",500,120);
    valid = false;
}

function iecompattest(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function loadwindow(wname,width,height){
    var elementStyle = document.getElementById(wname).style;
    elementStyle.display=''
    elementStyle.width=initialwidth=width+"px"
    elementStyle.height=initialheight=height+"px"
    elementStyle.left=ileft + "px"
    elementStyle.top=ns6? window.pageYOffset*1+itop+"px" : iecompattest().scrollTop*1+itop+"px"
}

function closeit(wname){
	document.getElementById(wname).style.display="none"
}

function submitform(formName, request) {
	var formObj = eval(document.forms[formName]);
	formObj.action = request;
	formObj.submit();
}

// Conditional Fields Methods

function initConditionalFields( targetElements, condition )
{
    if( !condition )
    {
        return;
    }

    if( targetElements )
    {
        for( var index = 0; index < targetElements.length; index++ )
        {
            var targetElement = targetElements[ index ];
            if( targetElement )
            {
                if( targetElement.checked == true )
                {
                    toggleConditionalFields( targetElement.name, targetElement.value, condition );
                }
                else
                {
                    toggleConditionalFields( targetElement.name, '', condition );
                }
            }
        }
    }
}

function toggleConditionalFields( key, flag, condition )
{
    if( !condition )
    {
        return;
    }

    var keyIndex = -1;
    if( entryKeys )
    {
        for( var index = 0; index < entryKeys.length; index++ )
        {
            var entryKey = entryKeys[ index ];
            if( key == entryKey )
            {
                keyIndex = index;
                break;
            }
        }
    }

    if( entryValues )
    {
        if( keyIndex > -1 && keyIndex < entryValues.length )
        {
            var entryValue = entryValues[ keyIndex ];
            if( entryValue )
            {
                if( flag == condition )
                {
                    for( var index = 0; index < entryValue.length; index++ )
                    {
                        disableInput( entryValue[ index ] );
                    }
                }
                else
                {
                    for( var index = 0; index < entryValue.length; index++ )
                    {
                        enableInput( entryValue[ index ] );
                    }
                }
            }
        }
    }
}

function disableInput( elementID )
{
    if( elementID )
    {
        var element = document.getElementById( elementID );
        if( element )
        {
            element.readOnly = true;
            element.style.backgroundColor = '#ebebe4';
            element.value = '';
        }
    }
}

function enableInput( elementID )
{
    if( elementID )
    {
        var element = document.getElementById( elementID );
        if( element )
        {
            element.readOnly = false;
            element.style.backgroundColor = '#ffffff';
        }
    }
}

function makeTopFrame()
{
    if( window.top != window.self )
    {
        window.top.location = windowSelfLocation;
    }
}
