﻿function getCookieVal(offset) 
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	var val = document.cookie.substring(offset, endstr);
	
	if (window.decodeURIComponent)	// No encode/decode functions on Mac IE 5.xx
	{
		val = window.decodeURIComponent(val);
	}
	
	return (val);
}

function setCookie(name, value, expires, path, domain, secure) 
{
	var curCookie = name + "=" + encodeURI(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");

	document.cookie = curCookie;
}

function getCookie(name) 
{
	var val = null;
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) 
	{
		var j = i + alen;
		
		if (document.cookie.substring(i, j) == arg)
		{
			val = getCookieVal(j);
			break;
		}
		
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}

	return (val);
}

function initDocument()
{
	var		txtUID = document.getElementById('txtUserID');
	var		txtPWD = document.getElementById('txtPassword');
	var		userID = getCookie('EAP.USERID');
	
	
	if (userID && txtPWD && txtUID && (userID != 'fbopr') && (userID != 'fboreg'))
	{
		txtUID.value = userID;
		txtPWD.focus();
	}
	else
	{
		txtUID.focus();
    }

    var tz = document.getElementById('eap_user_tz');

    if (tz) 
    {
        var dt = new Date();
        tz.value = dt.getTimezoneOffset();
    }
	
}

function Validate()
{
	var	userID = document.getElementById('txtUserID');
	var ok = (userID.value != '');
	
	if (!ok)
	{
		alert('You must provide a User ID!');
		userID.focus();
	}
	
	return (ok);
}
