﻿//<![CDATA[
/******************************************************************************
	Page Functions
******************************************************************************/
function init()
{
	var fName = 'File:  page.js\nFunction:  init()';

	try
	{
	    showTime();
		setPage();

		_pg.SetButtonStyles();

		if(_obj.OK('ctl00_hALERT')) getSaveData();

		setInterval('showTime();', 900);
	}
	catch(e)
	{
		if(_app.Debug) alert(fName + '\n\n' + e.toString());
	}
}

function setPage()
{
	var fName = 'File:  page.js\nFunction:  setPage()';

	try
	{
	    _util.SetHW();
	    
		if(_obj.OK('dDisabled'))
		{
			if(_obj.GetStyle('dDisabled', 'visibility') == 'visible') { _obj.Move('dDisabled', 0, 0, _doc.Height, _doc.Width); }
		}
		if(_obj.OK('ifAppMSG'))
		{
			_obj.Move('ifAppMSG', (_app.Height / 2) - (_obj.PoSi('ifAppMSG').Height / 2), (_app.Width / 2) - (_obj.PoSi('ifAppMSG').Width / 2));
		}
		if(_obj.OK('dMessage'))
		{
			_obj.Move('dMessage', (_app.Height - 80), (_app.Width - 250));
		}
		if(_obj.OK('dSave'))
		{
			_obj.Move('dSave', 70, 0);
			_obj.SetStyle('dSave', 'width', _app.Width);
		}
		if(_obj.OK('dLogo'))
		{
			_obj.SetStyle('dLogo', 'width', _app.Width);
		}
		if(_obj.OK('dNav'))
		{
			_obj.SetStyle('dNav', 'width', _app.Width);
		}
		if(_obj.OK('dMSG'))
		{
			_obj.SetStyle('dMSG', 'width', _app.Width);
		}
		if(_obj.OK('dContent'))
		{
			_obj.SetStyle('dContent', 'width', _app.Width);
		}
		if(_obj.OK('dn'))
		{
		    _obj.Move('dn', (_app.Height - 65), (_app.Width - 65));
			_obj.Move('center', ((_app.Height / 2) - 180), ((_app.Width / 2) - 165));
			_obj.Move('dn1', ((_app.Height / 2) - 180 + 162), ((_app.Width / 2) - 165 + 54));
			_obj.Move('dn2', ((_app.Height / 2) - 180 + 126), ((_app.Width / 2) - 165 + 163));
			_obj.Move('dn3', ((_app.Height / 2) - 180 + 18), ((_app.Width / 2) - 165 + 126));
			_obj.Move('dn4', ((_app.Height / 2) - 180 + 55), ((_app.Width / 2) - 165 + 19));
			_obj.Move('dn5', ((_app.Height / 2) - 180 + 90), ((_app.Width / 2) - 165 + 90));
		}
	}
	catch(e)
	{
		if(_app.Debug) alert(fName + '\n\n' + e.toString());
	}
}

function focusPage()
{
	var fName = 'File:  page.js\nFunction:  focusPage()';

	try
	{
		_pg.FocusWindows();
	}
	catch(e)
	{
		if(_app.Debug) alert(fName + '\n\n' + e.toString());
	}
}

function leavePage()
{
	var fName = 'File:  page.js\nFunction:  leavePage()';

	try
	{
		if(_obj.GetData('ctl00_hSaveOK') == 'False')
		{
	        showMessage(true);
    	    
		    return '***** You have made changes to the data. *****';
		}
	}
	catch(e)
	{
		if(_app.Debug) alert(fName + '\n\n' + e.toString());
	}
}

function reloadPage()
{
	var fName = 'File:  page.js\nFunction:  reloadPage()';

	try
	{
		_pg.nav2(_app.CPage);
	}
	catch(e)
	{
		if(_app.Debug) alert(fName + '\n\n' + e.toString());
	}
}


/******************************************************************************
	Save Functions
******************************************************************************/
function saveOK()
{
	var fName = 'File:  page.js\nFunction:  saveOK()';

	try
	{
		_obj.SetData('ctl00_hSaveOK', 'True');
	}
	catch(e)
	{
		if(_app.Debug) alert(fName + '\n\n' + e.toString());
	}
}

function setSaveAlert(OBJ, bCHANGE)
{
	var fName = 'File:  page.js\nFunction:  setSaveAlert(OBJ, bCHANGE)';

	try
	{
	    _obj.SetData('ctl00_hSaveOK', 'False');
	    
		if(typeof bCHANGE == 'undefined') bCHANGE = true;

		if(_obj.OK(OBJ) && bCHANGE)
		{
			setSaveData(OBJ);
			
		    _obj.SetStyle(OBJ, 'background', '#ffff66');

			if(_obj.OK('dSave'))
			{
				_obj.SetStyle('dSave', 'visibility', 'visible');
			}
		}
	}
	catch(e)
	{
		if(_app.Debug) alert(fName + '\n\n' + e.toString());
	}
}

function setSaveAlertX(OBJ)
{
	var fName = 'File:  page.js\nFunction:  setSaveAlertX(OBJ)';

	try
	{
		if(_obj.OK(OBJ))
		{
			setSaveData(OBJ);
			
		    _obj.SetStyle(OBJ, 'background', '#ffff66');

			if(_obj.OK('dSave'))
			{
				_obj.SetStyle('dSave', 'visibility', 'visible');
			}
		}
	}
	catch(e)
	{
		if(_app.Debug) alert(fName + '\n\n' + e.toString());
	}
}

function setSaveData(OBJ)
{
	var fName = 'File:  page.js\nFunction:  setSaveData(OBJ)';

	try
	{
		if(_obj.OK(OBJ))
		{
			if(_obj.OK('ctl00_hDATA'))
			{
				var data = _obj.GetData('ctl00_hDATA');
				var reg = new RegExp(OBJ, 'g');
				
				if(data.match(reg) == null)
				{
					data += OBJ + '|';
				}

				if(data.length > 0)
				{
					if(data.charAt(0) == '|') data = data.substring(1, data.length);
				}

				_obj.SetData('ctl00_hDATA', data);
			}
		}
	}
	catch(e)
	{
		if(_app.Debug) alert(fName + '\n\n' + e.toString());
	}
}

function getSaveData()
{
	var fName = 'File:  page.js\nFunction:  getSaveData()';

	try
	{
		if(_obj.OK('ctl00_hDATA'))
		{
			if(_obj.GetData('ctl00_hDATA') != '')
			{
				var data = _obj.GetData('ctl00_hDATA');
				var arrData = data.split('|');
				
				for(var x = 0; x < arrData.length; x++)
				{
					if(_obj.OK(arrData[x]))
					{
						if(_obj.GetStyle(arrData[x], 'background') != '#ffff00')
						{
							setSaveAlert(arrData[x]);
						}
					}
				}
			}
		}
	}
	catch(e)
	{
		if(_app.Debug) alert(fName + '\n\n' + e.toString());
	}
}


/******************************************************************************
	Delete Functions
******************************************************************************/
function deleteData()
{
	var fName = 'File:  page.js\nFunction:  deleteData()';

	try
	{
	    var rtn = null;
    	
	    rtn = window.confirm("Delete data.\nAre you sure?");
    	
	    if(rtn)
	    {
		    showMessage();

		    _obj.SetData('ctl00_hSaveOK', 'True');
		    _obj.SetData('ctl00_hCode', '_del');
		    _obj.xForm('aspnetForm');
	    }
	}
	catch(e)
	{
		if(_app.Debug) alert(fName + '\n\n' + e.toString());
	}
}


/******************************************************************************
	Functions
******************************************************************************/
function showTime()
{
	var fName = 'File:  page.js\nFunction:  showTime()';

	try
	{
		var tdy = new Date();
		var hrs = tdy.getHours();
		var gText = 'Good ';
		var ampm = '';
		
		if(hrs >= 0 && hrs < 12)
		{
			gText += 'Morning';
			ampm = ' AM';
		}
		if(hrs >= 12 && hrs < 18)
		{
			gText += 'Afternoon';
			ampm = ' PM';
		}
		if(hrs >= 18)
		{
			gText += 'Evening';
			ampm = ' PM';
		}
		
		hrs = (hrs > 12) ? hrs - 12 : hrs;
		hrs = (hrs == 0) ? 12 : hrs;
		
		var dText = _app.DaysARR[tdy.getDay()] + ', ' + _app.MonthsARR[tdy.getMonth()] + ' ' + tdy.getDate() + ', ' + tdy.getFullYear();
		var tText = hrs + ':' + ((tdy.getMinutes() < 10) ? '0' + tdy.getMinutes() : tdy.getMinutes()) + ':' + ((tdy.getSeconds() < 10) ? '0' + tdy.getSeconds() : tdy.getSeconds()) + ampm;

		if(_obj.OK('dDate')) _obj.SetData('dDate', dText);
		if(_obj.OK('dTime')) _obj.SetData('dTime', tText);
		if(_obj.OK('ctl00_dGreeting')) _obj.SetData('ctl00_dGreeting', gText);
	}
	catch(e)
	{
		if(_app.Debug) alert(fName + '\n\n' + e.toString());
	}
}

function showMessage(bHIDE)
{
	var fName = 'File:  page.js\nFunction:  showMessage(bHIDE)';

	try
	{
		if(typeof bHIDE == 'undefined') bHIDE = false;

		if(_obj.OK('dProcess'))
		{
		    if(bHIDE)
		    {
			    _obj.SetStyle('dProcess', 'visibility', 'hidden');
		    }
		    else
		    {
			    _obj.SetStyle('dProcess', 'visibility', 'visible');
		    }
		}
	}
	catch(e)
	{
		if(_app.Debug) alert(fName + '\n\n' + e.toString());
	}
}

function setListButton(OBJ)
{
	var fName = 'File:  page.js\nFunction:  setListButton(OBJ)';

	try
	{
        var ndx = -1;
        
        ndx = _obj.GetIndex('ctl00_cphMain_lstData')

        if(ndx > -1)
        {
            _obj.SetData(OBJ, 'Get Data');
            _obj.FlashButton(OBJ);
        }
	}
	catch(e)
	{
		if(_app.Debug) alert(fName + '\n\n' + e.toString());
	}
}

function getReportParams(ID)
{
	_cookie.Set('_cr', _app.SID());

	_pg.Lock();
	_obj.SetEnabled('ifAppMSG');
	_obj.Move('ifAppMSG', (_app.Height / 2) - 250, (_app.Width / 2) - 250, 500, 500);
	_obj.SetData('ifAppMSG', _app.SitePath() + '_crReports/pureport.aspx?id=' + ID + '&_sid=' + _app.SID());
	_obj.SetStyle('ifAppMSG', 'visibility', 'visible');

	_cookie.Del('_cr');
}

function PDFReport(Report, Title)
{
	var fName = 'File:  nvtracker.js\nFunction:  PDFReport(Report, Title)';

	try
	{
		_cookie.Set('_reportvu', _app.SID());
		
		_pg.nav2r('_crReports/reportvu.aspx?rptname=' + Title + '&rpt=' + Report + '.rpt&loi=' + Report + '&DomainID=' + _obj.GetData('ctl00_hDefDomainID') + '&StartDate=' + _app.dt() + '&EndDate=' + _app.dt());
	}
	catch(e)
	{
		if(_app.Debug) alert(fName + '\n\n' + e.toString());
	}
}
//]]>

