function handleEnterKey(event) {
   if (event.keyCode == 13 || event.keyCode == 3) {
        if (event.target.name == "COUNTRY") {
            return true;
        } else {
            event.returnValue = false; // Stop propagating
            return false;
        }
   }
}

function handleEnterKeyIE() {
   if (event.keyCode == 13 || event.keyCode == 3) {
        var isIE4, isIE5;
        isIE4 = false;
        isIE5 = false;
        if (navigator.appVersion.indexOf("MSIE") != -1) {
            if (navigator.appVersion.charAt(0) == "4") {
                isIE4 = true;
            }
            if (navigator.appVersion.indexOf("MSIE 5") != -1) {
                isIE5 = true;
            }
        }
        if (isIE5 == true && event.target.name == "COUNTRY") {
            return true;
        } else {
            event.returnValue = false; // Stop propagating
            return false;
        }
   }
}

function changeDateOptions() {
    var form = document.CAPTUREFORM;

    if( !form && document.forms.length ) {
        form = document.forms[0];
    }

    if ( form && form.MONTH ) {
        var monthVal = parseInt(form.MONTH.value);
        if (!isNaN(monthVal))
        {

            var month = eval(form.MONTH.value) + 1;

            if ( month == 2) {
                    form.DAY.options[31] = null;
                    form.DAY.options[30] = null;
            } else if ( (month == 4) || (month == 6) || (month == 9) || (month == 11) ) {
                    if (form.DAY.options.length == 32) {
                            form.DAY.options[31] = null;
                    } else {
                            form.DAY.options[30] = new Option("30", "29", false, false);
                    }
            } else {
                    if (form.DAY.options.length < 32) {
                            form.DAY.options[30] = new Option("30", "29", false, false);
                            form.DAY.options[31] = new Option("31", "30", false, false);
                    }
            }
        }
    }
}

if (navigator.appVersion.indexOf("MSIE") != -1) {
    document.onkeypress = handleEnterKeyIE;
}
else
{
   document.onkeypress = handleEnterKey;
}

function focusFirstName() {
	var inputElements = document.getElementsByTagName('input');
	var found = false;
	var index = 0;

	while( !found && index < inputElements.length )
	{
		var element = inputElements[index++];

		if( element.type == 'text' )
		{
			element.focus();
			found = true;
		}
	}

    changeDateOptions();
}

function selectCurrentLogin(form) {
    if( form.OFFEREDNAMES ) {
        var index = form.OFFEREDNAMES.selectedIndex;
        form.ALTNAME.value = form.OFFEREDNAMES.options[index].text;
    }
}

function addPlatformBrowserNames(){
	var bodyElement = document.body;
	if (bodyElement) 
	{
		BrowserDetectLite();
		var browser = getBrowserName();
		var OS = getOSName();
		document.body.className = OS+browser;
	}
}

function getOSName(){
	var OSName = 'mac';
	if (this.isUnix) OSName='unix';
	else if (this.isWin) OSName='windows';
	return OSName;
}
	function getBrowserName(){
	var browserName = 'mozilla';
	if (this.isSafari) browserName='safari';
	else if (this.isFirefox) browserName='firefox';
	else if (this.isIE) browserName='ie';
	else if (this.isNS) browserName='ns';
	return browserName;
}

function BrowserDetectLite() {
	var ua = navigator.userAgent.toLowerCase();
	this.ua = ua;
	// browser name
	this.isGecko = (ua.indexOf("gecko") != -1);
	this.isMozilla = (this.isGecko && ua.indexOf("gecko/") + 14 == ua.length);
	this.isFirefox = (this.isGecko && ua.indexOf("firefox") != -1); 
	this.isSafari = (this.isGecko && ua.indexOf("safari") != -1);
	this.isIE = ( (ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1) );
	// spoofing and compatible browsers
	this.isIECompatible = ( (ua.indexOf("msie") != -1) && !this.isIE);
	this.isNSCompatible = ( (ua.indexOf("mozilla") != -1) && !this.isNS && !this.isMozilla);
	// browser version
	this.versionMinor = parseFloat(navigator.appVersion);
	// correct version number for Firefox
	if (this.isFirefox) {
		this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
	}
	// correct version number for Safari
	else if (this.isSafari) {
		this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
	}
	// correct version number for IE4+
	else if (this.isIE && this.versionMinor >= 4) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
	}
	this.versionMajor = parseInt(this.versionMinor,10);
	// platform
	this.isWin = (ua.indexOf('win') != -1);
	this.isWin32 = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1) );
	this.isMac = (ua.indexOf('mac') != -1);
	this.isUnix = (ua.indexOf('unix') != -1 || ua.indexOf('linux') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1);
}