function startup() {
			document.getElementById("test-form").reset();
            var dates = new Date();
            var formObj = document.getElementById("test-form");
			d = 0;
			x = 0;
			f = '';
          
        }

var startDate;

function dateformat(datetoformat){
	var formatteddate;
	var curr_date = datetoformat.getDate();
	var curr_month = datetoformat.getMonth();
	curr_month++;
	var curr_year = datetoformat.getFullYear();
	return formatteddate = (curr_month + "/" + curr_date + "/" + curr_year);
	
}

function makeStartDate(formObj) {
    return new Date(formObj["convictiondate"].value);
}

function start2string(formObj) {
    return formObj["datemonth"].value + '/' + formObj["dateday"].value + '/' + formObj["dateyear"].value;
}


function monthadd(obj){

    var startDate = makeStartDate(obj.form);
    var d = 0;
	var x = 0;
	var f;
	var newdate;
	var fullname
	f = obj.form["finepaymentdate"].value;
	if (f != ''){
	f = new Date(obj.form["finepaymentdate"].value);
	}else{
		f = '';
	}
	if (obj.form["convictiontype"][0].checked == true) {
		x = 36;
	}else {
		if (obj.form["convictiontype"][1].checked == true)
			x = 60;
	}
	
	if (x =="") {
		alert("please select conviction type");
		return false;
	}
	
   if (document.testform.fullname.value == ""){
   alert("Please enter your Full Name");
   document.testform.fullname.select()
   document.testform.fullname.focus()
   return false;
   } 
   
//Phone Number Fileds-----------------------------------------
  if (document.testform.phonenumber.value.length <= 9){
   alert ("Please enter a valid \"Phone Number\"");
   document.testform.phonenumber.select()
   document.testform.phonenumber.focus()
   return false;
  } 
	
//Email Filed
 if (document.testform.emailadd.value ==""){
   alert("You must provide your \"Email Address\"");
   document.testform.emailadd.select()
   document.testform.emailadd.focus()
   return false;
   
  }
  invalidCharsList = " /:,;~#";
  if (document.testform.emailadd.value.indexOf('@',0)==-1 ||
      document.testform.emailadd.value.indexOf('@',0)== 0 ||
      document.testform.emailadd.value.indexOf('.',0)==-1) {
      alert("The email address you entered appears to be invalid! \n\nPlease re-enter your email address and try again.")
      document.testform.emailadd.select()
      document.testform.emailadd.focus()
      return false;
  }  
  for(i=0; i<invalidCharsList.length; i++){
   errorChar = invalidCharsList.charAt(i);
   if(document.testform.emailadd.value.indexOf(errorChar,0) != -1) {
    alert("The email address you entered appears to be invalid! \n\nPlease re-enter your email address and try again.")
    document.testform.emailadd.select()
    document.testform.emailadd.focus()
    return false;
      }
 
     }
	 
	
	
	if (obj.form["sentencingmonths"].value != "") {
		d += parseInt(obj.form["sentencingmonths"].value);
	}
	if (obj.form["probationmonths"].value != "") {
		d += parseInt(obj.form["probationmonths"].value);
	}

        startDate.addMonths(d);
		
		if (startDate.valueOf() > f.valueOf()){
					startDate.addMonths(x);
					newdate = dateformat(startDate);
					obj.form["eligibilitydate"].value = newdate;
					startDate.subtractMonths(12);
					newdate = dateformat(startDate);
					obj.form["applicationdate"].value = newdate;
					document.forms[0].submit()
				
				}

			if (startDate.valueOf() < f.valueOf() || startDate.valueOf() == f.valueOf() ){
					f.addMonths(x);
					newdate = dateformat(f);
					obj.form["eligibilitydate"].value = newdate;
					f.subtractMonths(12);
					newdate = dateformat(f);
					obj.form["applicationdate"].value = newdate;
					document.forms[0].submit()
				
				}
}

function IsNumeric(sText)

{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }


function ValidateForm(obj){
	
	if (!IsNumeric(document.testform.sentencingmonths.value)) 
   { 
      alert('Please enter only the months in numbers.') 
      document.testform.sentencingmonths.focus(); 
      return false; 
      } 
	  if (!IsNumeric(document.testform.probationmonths.value)) 
   { 
      alert('Please enter only the months in numbers.') 
      document.testform.probationmonths.focus(); 
      return false; 
      } 

monthadd(obj);
 }

window.onload = startup;