
function DateAdd(startDate, numDays, numMonths, numYears)
{
	var returnDate = new Date(startDate.getTime());
	var yearsToAdd = numYears;
	var month = returnDate.getMonth()	+ numMonths;
	if (month > 11)
	{
		yearsToAdd = Math.floor((month+1)/12);
		month -= 12*yearsToAdd;
		yearsToAdd += numYears;
	}
	returnDate.setMonth(month);
	returnDate.setFullYear(returnDate.getFullYear()	+ yearsToAdd);
	returnDate.setTime(returnDate.getTime()+60000*60*24*numDays);
	return returnDate;
}
function YearAdd(startDate, numYears)
{
		return DateAdd(startDate,0,0,numYears);
}
function MonthAdd(startDate, numMonths)
{
		return DateAdd(startDate,0,numMonths,0);
}	


function CkDates(input){
var now = new Date();
if (document.calform.InstallationDate1.value != '') {
	var then1 = new Date(document.calform.InstallationDate1.value);
	var gap1 = then1.getTime() - now.getTime();
	gap1 = Math.floor(gap1 / (1000 * 60 * 60 * 24));
	for (var i=0; i < document.calform.reminder1.length; i++)
   {
   if (document.calform.reminder1[i].checked)
      {
      var rem1_val = document.calform.reminder1[i].value;
      }
   }
  	var tmonth = MonthAdd(then1, parseInt(rem1_val));
	var gap1a = tmonth.getTime() - now.getTime();
	gap1a = Math.floor(gap1a / (1000 * 60 * 60 * 24));  
	if (gap1a < -1) {
	alert ('Please check your installation date 1. It should be the most recent date your unit was put back into service. If it is correct, your unit is overdue for maintenance. Please register your unit after service has been performed and the unit is reinstalled.'); 
	return false;
	}
	if (gap1 > -1) {
	alert ('Please choose a date prior to todays date for Installation Date 1!'); 
	return false;
	}
}

if (document.calform.InstallationDate2.value != '') {
	var then2 = new Date(document.calform.InstallationDate2.value);
	var gap2 = then2.getTime() - now.getTime();
	gap2 = Math.floor(gap2 / (1000 * 60 * 60 * 24));
	for (var i=0; i < document.calform.reminder2.length; i++)
   {
   if (document.calform.reminder2[i].checked)
      {
      var rem1_val2 = document.calform.reminder2[i].value;
      }
   }
  	var tmonth2 = MonthAdd(then2, parseInt(rem1_val2));
	var gap2a = tmonth2.getTime() - now.getTime();
	gap2a = Math.floor(gap2a / (1000 * 60 * 60 * 24));  
	if (gap2a < -1) {
	alert ('Please check your installation date 2. It should be the most recent date your unit was put back into service. If it is correct, your unit is overdue for maintenance. Please register your unit after service has been performed and the unit is reinstalled.'); 
	return false;
	}
	if (gap2 > -1) {
	alert ('Please choose a date prior to todays date for Installation Date 2!'); 
	return false;
	}
}

if (document.calform.InstallationDate3.value != '') {
	var then3 = new Date(document.calform.InstallationDate3.value);
	var gap3 = then3.getTime() - now.getTime();
	gap3 = Math.floor(gap3 / (1000 * 60 * 60 * 24));
	for (var i=0; i < document.calform.reminder3.length; i++)
   {
   if (document.calform.reminder3[i].checked)
      {
      var rem1_val3 = document.calform.reminder3[i].value;
      }
   }
  	var tmonth3 = MonthAdd(then3, parseInt(rem1_val3));
	var gap3a = tmonth3.getTime() - now.getTime();
	gap3a = Math.floor(gap3a / (1000 * 60 * 60 * 24));  
	if (gap3a < -1) {
	alert ('Please check your installation date 3. It should be the most recent date your unit was put back into service. If it is correct, your unit is overdue for maintenance. Please register your unit after service has been performed and the unit is reinstalled.'); 
	return false;
	}
	if (gap3 > -1) {
	alert ('Please choose a date prior to todays date for Installation Date 3!'); 
	return false;
	}
}


if (document.calform.InstallationDate4.value != '') {
	var then4 = new Date(document.calform.InstallationDate4.value);
	var gap4 = then4.getTime() - now.getTime();
	gap4 = Math.floor(gap4 / (1000 * 60 * 60 * 24));
	for (var i=0; i < document.calform.reminder4.length; i++)
   {
   if (document.calform.reminder4[i].checked)
      {
      var rem1_val4 = document.calform.reminder4[i].value;
      }
   }
  	var tmonth4 = MonthAdd(then4, parseInt(rem1_val4));
	var gap4a = tmonth4.getTime() - now.getTime();
	gap4a = Math.floor(gap4a / (1000 * 60 * 60 * 24));  
	if (gap4a < -1) {
	alert ('Please check your installation date 4. It should be the most recent date your unit was put back into service. If it is correct, your unit is overdue for maintenance. Please register your unit after service has been performed and the unit is reinstalled.'); 
	return false;
	}
	if (gap4 > -1) {
	alert ('Please choose a date prior to todays date for Installation Date 4!'); 
	return false;
	}
}


if (document.calform.InstallationDate5.value != '') {
	var then5 = new Date(document.calform.InstallationDate5.value);
	var gap5 = then5.getTime() - now.getTime();
	gap5 = Math.floor(gap5 / (1000 * 60 * 60 * 24));
	for (var i=0; i < document.calform.reminder5.length; i++)
   {
   if (document.calform.reminder5[i].checked)
      {
      var rem1_val5 = document.calform.reminder5[i].value;
      }
   }
  	var tmonth5 = MonthAdd(then5, parseInt(rem1_val5));
	var gap5a = tmonth5.getTime() - now.getTime();
	gap5a = Math.floor(gap5a / (1000 * 60 * 60 * 24));  
	if (gap5a < -1) {
	alert ('Please check your installation date 5. It should be the most recent date your unit was put back into service. If it is correct, your unit is overdue for maintenance. Please register your unit after service has been performed and the unit is reinstalled.'); 
	return false;
	}
	if (gap5 > -1) {
	alert ('Please choose a date prior to todays date for Installation Date 5!'); 
	return false;
	}
}


{
    var requiredFields = new Array("CustomerContactName",
								   "CustomerPhone",
								   "CustomerEmail",
								   "CustomerAddress",
								   "CustomerCity",
								   "CustomerState",
								   "CustomerZip",
								   "Username",
								   "Password");

    var fieldNames = new Array("Contact Name",
								   "Phone",	
								   "Email",
								   "Address",
								   "City",
								   "State",
								   "Zip",
								   "Username",
								   "Password");


    var fieldCheck   = true;
    var fieldsNeeded = "\nA value must be entered in the following field(s):\n\n\t";

    for(var fieldNum=0; fieldNum < requiredFields.length; fieldNum++) {
        if ((input.elements[requiredFields[fieldNum]].value == "") ||
            (input.elements[requiredFields[fieldNum]].value == " ")) {

            fieldsNeeded += fieldNames[fieldNum] + "\n\t";
            fieldCheck = false;
        }
    }

    if (fieldCheck == true)
    {
        return true;
    }

    else
    {
        alert(fieldsNeeded);
        return false;
    }
}

}











function CkDates2(input){
var now = new Date();
if (document.calform.InstallationDate1.value != '') {
	var then1 = new Date(document.calform.InstallationDate1.value);
	var gap1 = then1.getTime() - now.getTime();
	gap1 = Math.floor(gap1 / (1000 * 60 * 60 * 24));
	for (var i=0; i < document.calform.reminder1.length; i++)
   {
   if (document.calform.reminder1[i].checked)
      {
      var rem1_val = document.calform.reminder1[i].value;
      }
   }
  	var tmonth = MonthAdd(then1, parseInt(rem1_val));
	var gap1a = tmonth.getTime() - now.getTime();
	gap1a = Math.floor(gap1a / (1000 * 60 * 60 * 24));  
	if (gap1a < -1) {
	alert ('Please check your installation date 1. It should be the most recent date your unit was put back into service. If it is correct, your unit is overdue for maintenance. Please register your unit after service has been performed and the unit is reinstalled.'); 
	return false;
	}
	if (gap1 > -1) {
	alert ('Please choose a date prior to todays date for Installation Date 1!'); 
	return false;
	}
}

if (document.calform.InstallationDate2.value != '') {
	var then2 = new Date(document.calform.InstallationDate2.value);
	var gap2 = then2.getTime() - now.getTime();
	gap2 = Math.floor(gap2 / (1000 * 60 * 60 * 24));
	for (var i=0; i < document.calform.reminder2.length; i++)
   {
   if (document.calform.reminder2[i].checked)
      {
      var rem1_val2 = document.calform.reminder2[i].value;
      }
   }
  	var tmonth2 = MonthAdd(then2, parseInt(rem1_val2));
	var gap2a = tmonth2.getTime() - now.getTime();
	gap2a = Math.floor(gap2a / (1000 * 60 * 60 * 24));  
	if (gap2a < -1) {
	alert ('Please check your installation date 2. It should be the most recent date your unit was put back into service. If it is correct, your unit is overdue for maintenance. Please register your unit after service has been performed and the unit is reinstalled.'); 
	return false;
	}
	if (gap2 > -1) {
	alert ('Please choose a date prior to todays date for Installation Date 2!'); 
	return false;
	}
}

if (document.calform.InstallationDate3.value != '') {
	var then3 = new Date(document.calform.InstallationDate3.value);
	var gap3 = then3.getTime() - now.getTime();
	gap3 = Math.floor(gap3 / (1000 * 60 * 60 * 24));
	for (var i=0; i < document.calform.reminder3.length; i++)
   {
   if (document.calform.reminder3[i].checked)
      {
      var rem1_val3 = document.calform.reminder3[i].value;
      }
   }
  	var tmonth3 = MonthAdd(then3, parseInt(rem1_val3));
	var gap3a = tmonth3.getTime() - now.getTime();
	gap3a = Math.floor(gap3a / (1000 * 60 * 60 * 24));  
	if (gap3a < -1) {
	alert ('Please check your installation date 3. It should be the most recent date your unit was put back into service. If it is correct, your unit is overdue for maintenance. Please register your unit after service has been performed and the unit is reinstalled.'); 
	return false;
	}
	if (gap3 > -1) {
	alert ('Please choose a date prior to todays date for Installation Date 3!'); 
	return false;
	}
}


if (document.calform.InstallationDate4.value != '') {
	var then4 = new Date(document.calform.InstallationDate4.value);
	var gap4 = then4.getTime() - now.getTime();
	gap4 = Math.floor(gap4 / (1000 * 60 * 60 * 24));
	for (var i=0; i < document.calform.reminder4.length; i++)
   {
   if (document.calform.reminder4[i].checked)
      {
      var rem1_val4 = document.calform.reminder4[i].value;
      }
   }
  	var tmonth4 = MonthAdd(then4, parseInt(rem1_val4));
	var gap4a = tmonth4.getTime() - now.getTime();
	gap4a = Math.floor(gap4a / (1000 * 60 * 60 * 24));  
	if (gap4a < -1) {
	alert ('Please check your installation date 4. It should be the most recent date your unit was put back into service. If it is correct, your unit is overdue for maintenance. Please register your unit after service has been performed and the unit is reinstalled.'); 
	return false;
	}
	if (gap4 > -1) {
	alert ('Please choose a date prior to todays date for Installation Date 4!'); 
	return false;
	}
}


if (document.calform.InstallationDate5.value != '') {
	var then5 = new Date(document.calform.InstallationDate5.value);
	var gap5 = then5.getTime() - now.getTime();
	gap5 = Math.floor(gap5 / (1000 * 60 * 60 * 24));
	for (var i=0; i < document.calform.reminder5.length; i++)
   {
   if (document.calform.reminder5[i].checked)
      {
      var rem1_val5 = document.calform.reminder5[i].value;
      }
   }
  	var tmonth5 = MonthAdd(then5, parseInt(rem1_val5));
	var gap5a = tmonth5.getTime() - now.getTime();
	gap5a = Math.floor(gap5a / (1000 * 60 * 60 * 24));  
	if (gap5a < -1) {
	alert ('Please check your installation date 5. It should be the most recent date your unit was put back into service. If it is correct, your unit is overdue for maintenance. Please register your unit after service has been performed and the unit is reinstalled.'); 
	return false;
	}
	if (gap5 > -1) {
	alert ('Please choose a date prior to todays date for Installation Date 5!'); 
	return false;
	}
}


{
    var requiredFields = new Array("DistributorName",
                                   "ContactName",
								   "Address",
								   "City",
								   "State",
								   "Zip",
								   "Phone",
								   "Email",
								  "Username",
								   "Password");

    var fieldNames = new Array("Distributor Name",
                                   "Contact Name",
								   "Address",
								   "City",
								   "State",
								   "Zip",
								   "Phone",
								   "Email",
								  "Username",
								   "Password");


    var fieldCheck   = true;
    var fieldsNeeded = "\nA value must be entered in the following field(s):\n\n\t";

    for(var fieldNum=0; fieldNum < requiredFields.length; fieldNum++) {
        if ((input.elements[requiredFields[fieldNum]].value == "") ||
            (input.elements[requiredFields[fieldNum]].value == " ")) {

            fieldsNeeded += fieldNames[fieldNum] + "\n\t";
            fieldCheck = false;
        }
    }

    if (fieldCheck == true)
    {
        return true;
    }

    else
    {
        alert(fieldsNeeded);
        return false;
    }
}



}


