
var varCheck1 = "";
var varCheck2 = "";
var varCheck3 = "";
var varCheck4 = "";

varAttach = 0;
var varSig = "";

function valid_patent()
	
{
	if (document.patent.reportstatus.value=="") {
	alert("Must accept your report status before submitting. Please click the 'Check Report Status' button and follow the instructions.")
	return false;
	}

	if (validatecontract(document.patent.GrantNumber.value)) 
	{
		return false;
	}	


	if (document.patent.Recipient.value=="") {
	alert("Please enter the Recipient's name to continue.")
	document.patent.Recipient.focus()
	return false
	}

	if (document.patent.SponsoringInstituion.value=="") {
	alert("Please enter a sponsoring institution to continue.")
	document.patent.SponsoringInstituion.focus()
	return false
	}

	if (document.patent.Name.value=="") {
	alert("Please enter a Certifying Official's name.")
	document.patent.Name.focus()
	return false
	}

	if (document.patent.Certifying_Institution.value=="") {
	alert("Please enter the Certifying Official's institution.")
	document.patent.Certifying_Institution.focus()
	return false
	}
	if (document.patent.Address1.value=="") {
	alert("Please enter the Certifying Official's address.")
	document.patent.Address1.focus()
	return false
	}

	if (document.patent.State.value==" Select a State or Province") {
	alert("Please enter the Certifying Official's state.")
	document.patent.State.focus()
	return false
	}

	if (document.patent.Zip.value=="") {
	alert("Please enter the Certifying Official's zip code.")
	document.patent.Zip.focus()
	return false
	}

	if(!checknum(document.patent.Zip)){
	alert("The Certifying Official's zip code should be numbers only")
	document.patent.Zip.focus()
	return false}
	
	if (document.patent.Country.value==" Select your Country") {
	alert("Please enter the Certifying Official's country.")
	document.patent.Country.focus()
	return false
	}


	if (document.patent.Phone.value=="") {
	alert("Please enter the Certifying Official's phone number.")
	document.patent.Phone.focus()
	return false
	}
	if(!checknum(document.patent.Phone)){
	alert("The Certifying Official's phone number should be numbers only")
	document.patent.Phone.focus()
	return false}

	if (document.patent.Email.value=="") {
	alert("Please enter the Certifying Official's email address.")
	document.patent.Email.focus()
	return false
	}

	if(!checkemail(document.patent.Email)){
	alert("The Certifying Official's email address seems invalid. I don't see a @.")
	return false
	}
	if(!checkdot1(document.patent.Email)){
    alert("The Certifying Official's email address seems invalid. Please re-enter");
	return false
	}
		
	if (varCheck1 =="1"){
		varAttach = 1
	}
	if (varCheck2 =="1"){
		varAttach = 1
	}
	if (varCheck3 =="1"){
		varAttach = 1
	}
	if (varCheck4 =="1"){
		varAttach = 1
	}
	
	if (varAttach!=0){
		if (document.patent.PatentInfo.value=="") {
		    alert("The system is expecting to get an upload with this form according to your survey response. Please select a file by clicking Browse.");
			return false;
		}
	}

	if (document.patent.Signature.checked==false)
	{
		alert("Please check the box that verifies you understand the information being sent")
		return false;
	}

return true
   }

function checknum(field) {
var valid = "0123456789-"
var ok = "yes";
var temp;
for (var i=0; i<field.value.length; i++)
	 {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
		}
if (ok == "no") 
	{
	field.focus();
	field.select();
	field.value = "0"
	return false;
   }
return true
}

function checkemail(field)
{
  if (field.value.indexOf("@") == -1 ||
        field.value == "") 
   {
 	field.focus();
    return false;
    }
    return true
}

function checkdot1(field)
{
  if (field.value.indexOf(".") == -1 ||
        field.value == "") 
   {
       field.focus()
       return false;
    }
    return true
}

function validatecontract(field) 
{
	var valid = "rR0123456789-";
	var hyphencount = 0;

	if (field.length!=7 && field.length!=8) 
	{
		alert("Please check the grant number it seems to be formatted wrong.");
		return true;
	}
	if (field.length==7 && ""+field.charAt(0)=="R") 
	{
		alert("Please check the grant number it seems to be formatted wrong.");
		return true;
	}
	if (field.length==7 && ""+field.charAt(0)=="r") 
	{
		alert("Please check the grant number it seems to be formatted wrong.");
		return true;
	}
	for (var i=0; i < field.length; i++) 
	{
		temp = "" + field.substring(i, i+1);
		if (temp == "-") hyphencount++;
			if (valid.indexOf(temp) == "-1") 
			{
				alert("Invalid characters in your grant number.  Please try again.");
				return true;
			}
		if ((hyphencount > 1) || ((field.length==8) && ""+field.charAt(5)!="-")) 
		{
			alert("Please validate the grant number.");
			return true;
		}
		if ((hyphencount > 1) || ((field.length==7) && ""+field.charAt(4)!="-")) 
		{
			alert("Please validate the grant number.");
			return true;
		}

}
	}
