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;
	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 (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;
				
				}

			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;
				
				}
}

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;