
	// --------------------------------------------------------------------------
	// FIELD VALIDATION ROUTINES
	// --------------------------------------------------------------------------

	var Undetermined=0;

	//must select	
	function validateClearingLoc()
	{
			var Sel = document.TaxCalc.ClearingAt.selectedIndex;
									
			if(Sel == Undetermined)
			{
				alert("You must select the clearing location.");
				return false;
			}
			
			return true;	
	}	

	//must select
	function validateDestinationLoc()
	{
			var Sel = document.TaxCalc.DestinedTo.selectedIndex;
										
			if(Sel == Undetermined)
			{
				alert("You must select the destination location.");
				return false;
			}
			
			return true;	
	}	

	//must select
	function validateCategory()
	{
		if( document.TaxCalc.fCategory.value == "Choose a category" )
		{
			alert("You must select a category to which the product belongs.");
			return false;
		}
		
		return true;
	}

	//must select
	function validateCurrency()
	{
			var Sel = document.TaxCalc.fcountry.selectedIndex;
									
			if(Sel == Undetermined)
			{
				alert("You must select a currency to convert from.");
				return false;
			}
			
			return true;	
	}	

	//must select
	function validateOrigin()
	{
		if (( document.TaxCalc.Origin[0].checked == 0 ) && ( document.TaxCalc.Origin[1].checked == 0 ))
		{
			//none have been selected
			alert("You must select an origin for the product.");
			return false;
		}
		
		return true;
	}

	//validate that it doesn't contain invalid characters
	function ValidateShipValue()
	{
		var strValue = document.TaxCalc.ShipValue.value;
		
		for (var i=0;i<strValue.length;i++) 
		{
			var letter=strValue.substring(i,i+1);
			if ((letter<"0" || "9"<letter) && letter!='.') 
			{
				alert("You have entered an invalid shipping value.");
				return false;
			}
		}
		
		return true;
	}	

	//must select checks
	function validateFields()
	{
		if(!validateClearingLoc())
			return false;
			
		if(!validateDestinationLoc())
			return false;

		if(!validateCategory())
			return false;			
	
		if(!validateCurrency())
			return false;

		if(!validateOrigin())
			return false;

		if(!ValidateShipValue())
			return false;			
	}

	// --------------------------------------------------------------------------
	// CATEGORY SUB PAGE
	// --------------------------------------------------------------------------

	function choosecategory()
	{
		window.open("tariffguide.htm","tariffguide","height=400,width=640,scrollbars,resizable");
	}

	//cannot change manually
	function checkcategoryfield()
	{
		alert("You cannot directly change this value. Please select a category using the Choose Category button."); 
		document.TaxCalc.fCategory.value="Choose a category";	
	}
	
	// --------------------------------------------------------------------------
	// VFD Description
	// --------------------------------------------------------------------------

	function vfd()
	{
		window.open("vfd.htm","vfdwin","height=200,width=350,scrollbars,resizable");
	}	

	// --------------------------------------------------------------------------
	// PAGE INITIALIZATION
	// --------------------------------------------------------------------------

	//put today's date in date field
	function todaydate()
	{
		var date = new Date();
		var day = date.getDate();
		var month = date.getMonth() + 1;
		var year = date.getYear();
		
        if (navigator.appName == "Netscape")
        {
			if (year<100)
			{
				year+=1900;
			}
        }  
        else
        {
			year+=1900;
        }              
		
		document.TaxCalc.ShipDate.value= month + "-" + day + "-" + year;
	}

	//reset all form controls
	function initializeform()
	{
		document.TaxCalc.ClearingAt.selectedIndex=0;
		document.TaxCalc.DestinedTo.selectedIndex=0;	
		document.TaxCalc.fCategory.value="Choose a category";
		todaydate();
		document.TaxCalc.ShipValue.value="";
		document.TaxCalc.fcountry.selectedIndex=0;

		//deselect the origins
		document.TaxCalc.Origin[0].checked=0;
		document.TaxCalc.Origin[1].checked=0;
		if (document.TaxCalc.ShipValueCAN.value > 0){
			document.TaxCalc.ShipValueCAN.value="$0.00";
			}
		document.TaxCalc.DutyAmt.value="$0.00";
		document.TaxCalc.GST.value="$0.00";
		document.TaxCalc.PST.value="$0.00";
		document.TaxCalc.QPST.value="$0.00";
		document.TaxCalc.HST.value="$0.00";
		document.TaxCalc.GrandTotal.value="$0.00";			
	}

