function validate_required(field,alerttxt,minlength)
{
	with (field)
	{
		if (value==null||value==""||value.length<minlength)
		{
			alert(alerttxt);
			return false;
		}
		else
		{
			return true;
		}
	}
}

function goodZip(incValue, valLength)
{
	if(incValue.match(/^\d{5}(-\d{4})?$/))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function goodPostal(incValue)
{
	if(incValue.length == 6)
	{
		postal = incValue.toUpperCase();
		return (postal.match(/^[A-Z][0-9][A-Z][0-9][A-Z][0-9]$/));
	}
	else
	{
		return false;
	}
}

function validate(incform)
{
	
	with(incform)
	{
		// Billing Address
		if(!validate_required(billfirstname,"Please Enter A First Name",2))
		{
			billfirstname.focus();
			return false;
		}
		if(!validate_required(billlastname,"Please Enter A Last Name",2))
		{
			billlastname.focus();
			return false;
		}
		if(!validate_required(billcompany,"Please Enter A Company Name",2))
		{
			billcompany.focus();
			return false;
		}
		if(!validate_required(billemail,"Please Enter An Email Address",2))
		{
			billemail.focus();
			return false;
		}
		if(!validate_required(billaddress1,"Please Enter A Address",5))
		{
			billaddress1.focus();
			return false;
		}
		if(!validate_required(billcity,"Please Enter A City",3))
		{
			billcity.focus();
			return false;
		}
		if(billcountry.value=='US')
		{
			if(!goodZip(billzip.value))
			{
				alert("Please Enter A Valid Zip Code (90210 or 90210-1234)");
				billzip.focus();
				return false;
			}
		}
		else
		{
			if(!goodPostal(billzip.value))
			{
				alert("Please Enter A Valid Postal Code (A1A1A1)");
				billzip.focus();
				return false;
			}
		}
	}
	return true;
}

function ValidateForm()
{
	if (document.getElementById('qty').value == "" || document.getElementById('qty').value < 1) {
		alert('Quantity must be greater than 1');
		document.getElementById('qty').focus();
		return false;
	}
	else
		return true;
}
