//----------------------------------------------
// Copyright TaylorMade Systems June 2002
// All Rights Reserved
//----------------------------------------------
var submitButton = "";

function MAIN_onLoad()
{
	var theForm = document.RACE_ENTRY;
	if(theForm.BOAT_TYPE[0].checked)
		PHRF_BOAT_onClick();
	else
		PORTSMOUTH_BOAT_onClick();		
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return(curtop);
}

function PORTSMOUTH_BOATMAKE_onChange()
{
    var theForm = document.RACE_ENTRY;
    var ndx = theForm.PORTSMOUTH_BOATMAKE.selectedIndex
    var work = theForm.PORTSMOUTH_BOATMAKE.options[ndx].value
    theForm.DPN.value = work
    if(ndx == 0)
    {
		theForm.OTHER.value = "";
		theForm.OTHER.focus();
    }	
}

function MOD1_CODE_onChange()
{
    var theForm = document.RACE_ENTRY;
    var ndx = theForm.MOD1_CODE.selectedIndex
    var value = theForm.MOD1_CODE.options[ndx].value
    var text  = theForm.MOD1_CODE.options[ndx].text
    var i = value.indexOf("/")
    var dpn = value.substring(0,i)
    value = value.substring(i+1)
    
    if(ndx == 0)
    {
		theForm.MOD1_DESC.value = "";
		theForm.MOD1_DPN.value = "1.0000";
		theForm.MOD1_DESC.focus();
    }
    else
    {
		theForm.MOD1_DESC.value = value;
		theForm.MOD1_DPN.value = dpn;
		theForm.MOD1_DESC.focus();
    }
    return;	
}

function MOD2_CODE_onChange()
{
    var theForm = document.RACE_ENTRY;
    var ndx = theForm.MOD2_CODE.selectedIndex
    var value = theForm.MOD2_CODE.options[ndx].value
    var text  = theForm.MOD2_CODE.options[ndx].text
    var i = value.indexOf("/")
    var dpn = value.substring(0,i)
    value = value.substring(i+1)
    
    if(ndx == 0)
    {
		theForm.MOD2_DESC.value = "";
		theForm.MOD2_DPN.value = "1.0000";
		theForm.MOD2_DESC.focus();
    }
    else
    {
		theForm.MOD2_DESC.value = value;
		theForm.MOD2_DPN.value = dpn;
		theForm.MOD2_DESC.focus();
    }
    return;	
}

function PHRF_BOAT_onClick()
{
	document.getElementById('PHRF').style.visibility = "visible";
    document.getElementById('PORTSMOUTH').style.visibility = "hidden";
    document.getElementById('PORTSMOUTH_BOATMAKE').style.display = "none";
    document.getElementById('MOD1_CODE').style.display = "none";
    document.getElementById('MOD2_CODE').style.display = "none";
}

function PORTSMOUTH_BOAT_onClick()
{
    document.getElementById('PHRF').style.visibility = "hidden";
    document.getElementById('PORTSMOUTH').style.visibility = "visible";
    document.getElementById('PORTSMOUTH_BOATMAKE').style.display = "inline";
    document.getElementById('MOD1_CODE').style.display = "inline";
    document.getElementById('MOD2_CODE').style.display = "inline";    
}

function RACE_ENTRY_onsubmit()
{
    var theForm = document.RACE_ENTRY;
    var ndx    
    var work

    if(isEmpty(theForm.RACE.value))
    {
        window.alert("Please enter a value for the 'NAME OF RACE' field.");
        theForm.RACE.focus();
        return(false);
    }

    if(isEmpty(theForm.DATE_OF_RACE_dateTextBox.value))
    {
        window.alert("Please enter a value for the 'DATE OF RACE' field.");
        theForm.DATE_OF_RACE_dateTextBox.focus();
        return(false);
    }
    
	if(!isDate(theForm.DATE_OF_RACE_dateTextBox.value))
	{
        window.alert("Please enter a valid value for the 'DATE OF RACE' field. Should be in MM/DD/YYYY format");
        theForm.DATE_OF_RACE_dateTextBox.focus();
        return(false);	
	}
	
    if(isEmpty(theForm.BOATNAME.value))
    {
        window.alert("Please enter a value for the 'BOAT NAME' field.");
        theForm.BOATNAME.focus();
        return(false);
    }
    	
    if(isEmpty(theForm.SAIL_NO.value))
    {
        window.alert("Please enter a value for the 'SAIL NO' field.");
        theForm.SAIL_NO.focus();
        return(false);
    }    	
    	
    if(isEmpty(theForm.SKIPPER.value))
    {
        window.alert("Please enter a value for the 'SKIPPER' field.");
        theForm.SKIPPER.focus();
        return(false);
    }
    
    if(isEmpty(theForm.ONBOARD.value))
    {
        window.alert("Please enter a value for the 'SOULS ON BOARD' field.");
        theForm.ONBOARD.focus();
        return(false);
    }
            
    if(!isPosInteger(theForm.ONBOARD.value))
    {
        window.alert("Please enter a valid value for the 'SOULS ON BOARD' field.");
        theForm.ONBOARD.focus();
        return(false);
    }
          
    if(isEmpty(theForm.EMAIL.value))
    {
        window.alert("Please enter a value for the 'EMAIL' field.");
        theForm.EMAIL.focus();
        return(false);
    }
    
    if(!theForm.BOAT_TYPE[0].checked &&
       !theForm.BOAT_TYPE[1].checked)
    {
		window.alert("Please select either 'PHRF' or 'PORTSMOUTH' type of boat");
		theForm.BOAT_TYPE[0].focus();
		return(false);
    }
    
    if(theForm.BOAT_TYPE[0].checked)	// PHRF_BOAT
    {
		if(isEmpty(theForm.BOATMAKE.value))
		{
			window.alert("Please enter a value for the 'BOAT MAKE' field.");
			theForm.BOATMAKE.focus();
			return(false);
		}
		if(isEmpty(theForm.RATING.value))
		{
			window.alert("Please enter a value for the 'PHRF' field.");
			theForm.RATING.focus();
			return(false);
		}				
		if(!isInteger(theForm.RATING.value))
		{
			window.alert("Please enter a valid value for the 'PHRF' field.");
			theForm.RATING.focus();
			return(false);
		}
		if(isEmpty(theForm.CERTNO.value))
		{
			window.alert("Please enter a value for the 'RATING CERTIFICATE #' field.");
			theForm.CERTNO.focus();
			return(false);
		}		
		if(isEmpty(theForm.USMEMBNO.value))
		{
			window.alert("Please enter a value for the 'USSA MEMBER #' field.");
			theForm.USMEMBNO.focus();
			return(false);
		}			
    }
    else	// PORTSMOUTH EDITS
    {   
		ndx = theForm.PORTSMOUTH_BOATMAKE.selectedIndex;
		if(ndx == 0)
		{
			if(isEmpty(theForm.OTHER.value))
			{
				window.alert("You have selected '--Other--' as your boat type. Please enter a boat description.");
				theForm.OTHER.focus();
				return(false);
			}
		}
		
		if(!isNumber(theForm.DPN.value))
		{
			window.alert("Enter a numeric value in the 'DPN' field.");
			theForm.DPN.focus();
			return(false);
		}
		
		ndx = theForm.MOD1_CODE.selectedIndex
		if(ndx == 0)	// no modifier
		{
			theForm.MOD1_DPN.value = "1.0000"
			theForm.MOD1_DESC.value = ""
		}
		else
		{		
			if(isEmpty(theForm.MOD1_DESC.value))
			{
				window.alert("Enter a description for the MODIFIER #1 field.");
				theForm.MOD1_DESC.focus();
				return(false);
			}
			if(!isNumber(theForm.MOD1_DPN.value))
			{
				window.alert("Enter a numeric value in the MODIFIER #1 'DPN' field.");
				theForm.MOD1_DPN.focus();
				return(false);
			}
		}
		
		ndx = theForm.MOD2_CODE.selectedIndex
		if(ndx == 0)	// no modifier
		{
			theForm.MOD2_DPN.value = "1.0000"
			theForm.MOD2_DESC.value = ""
		}
		else
		{
			if(isEmpty(theForm.MOD2_DESC.value))
			{
				window.alert("Enter a description for the MODIFIER #2 field.");
				theForm.MOD2_DESC.focus();
				return(false);
			}
			if(!isNumber(theForm.MOD2_DPN.value))
			{
				window.alert("Enter a numeric valud in the MODIFIER #2 'DPN' field.");
				theForm.MOD2_DPN.focus();
				return(false);
			}
		}		
    }   
    
	if(isEmpty(theForm.SIGNATURE.value))
	{
		window.alert("Please enter a value for the 'SIGNATURE' field. It means you have read and accepted the disclaimer.");
		theForm.SIGNATURE.focus();
		return(false);
	}    
             
    return(true);
}
