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 checkValidExistingFormFields() {
  
   if(!checkValidExistingOwnerInfo() || !checkDatesAndTimes() || !checkAllExistingPetNames() || !checkAllExistingDogWeights() || !checkAllExistingPlaytimes()) {
      return false;
   }
   else {
      return true;
   } 
}

function markErrorsInForm() {
   
   markUpDates();
   
   if(document.orderform.fullName.value=='') { markErrorInForm('fullNametext'); } 
   else { clearErrorInForm('fullNametext'); }   
   if(document.orderform.emailAddress.value=='' || !checkEmailAddress(document.orderform.emailAddress.value)) { markErrorInForm('emailAddresstext'); } 
   else { clearErrorInForm('emailAddresstext'); } 
    
   if(getBoardedBefore() && document.orderform.boardedPets1 != null) {
      if(document.orderform.boardedPets1.value=='') { markErrorInForm('boardedPetstext1'); } 
      else { clearErrorInForm('boardedPetstext1'); }  
   }
   
   if(getBoardedBefore() && document.orderform.boardedPets2 != null) {   
      if(document.orderform.boardedPets2.value=='') { markErrorInForm('boardedPetstext2'); } 
      else { clearErrorInForm('boardedPetstext2'); }
   }
   
   if(getBoardedBefore() && document.orderform.boardedPets3 != null) {
      if(document.orderform.boardedPets3.value=='') { markErrorInForm('boardedPetstext3'); } 
      else { clearErrorInForm('boardedPetstext3'); }
   }
   
   if(getBoardedBefore() && document.orderform.boardedPets4 != null) {
      if(document.orderform.boardedPets4.value=='') { markErrorInForm('boardedPetstext4'); } 
      else { clearErrorInForm('boardedPetstext4'); }
   }
   
   if(getBoardedBefore() && document.orderform.boardedPets5 != null) {
      if(document.orderform.boardedPets5.value=='') { markErrorInForm('boardedPetstext5'); } 
      else { clearErrorInForm('boardedPetstext5'); }                
   }
   
   var numberofpets = document.getElementById('existingpets').value;
    
   if(getExistingDogWeight(1)=='' && getIsDog(1) && numberofpets >= 1) { markErrorInForm('existing_dogweighttext1'); } 
   else { clearErrorInForm('existing_dogweighttext1'); }
   if(getExistingDogWeight(2)=='' && getIsDog(2) && numberofpets >= 2) { markErrorInForm('existing_dogweighttext2'); } 
   else { clearErrorInForm('existing_dogweighttext2'); }  
   if(getExistingDogWeight(3)=='' && getIsDog(3) && numberofpets >= 3) { markErrorInForm('existing_dogweighttext3'); } 
   else { clearErrorInForm('existing_dogweighttext3'); } 
   if(getExistingDogWeight(4)=='' && getIsDog(4) && numberofpets >= 4) { markErrorInForm('existing_dogweighttext4'); } 
   else { clearErrorInForm('existing_dogweighttext4'); }           
   if(getExistingDogWeight(5)=='' && getIsDog(5) && numberofpets >= 5) { markErrorInForm('existing_dogweighttext5'); } 
   else { clearErrorInForm('existing_dogweighttext5'); }
   
   var oform = document.orderform;
   if(oform.existing_playtimes1 != null && oform.existing_playtimes1.value != '' && !isNumeric(oform.existing_playtimes1.value) ) { markErrorInForm('existing_playtimestext1'); }
   else { clearErrorInForm('existing_playtimestext1'); }
   if(oform.existing_playtimes2 != null && oform.existing_playtimes2.value != '' && !isNumeric(oform.existing_playtimes2.value) ) { markErrorInForm('existing_playtimestext2'); }
   else { clearErrorInForm('existing_playtimestext2'); }
   if(oform.existing_playtimes3 != null && oform.existing_playtimes3.value != '' && !isNumeric(oform.existing_playtimes3.value) ) { markErrorInForm('existing_playtimestext3'); }
   else { clearErrorInForm('existing_playtimestext3'); }
   if(oform.existing_playtimes4 != null && oform.existing_playtimes4.value != '' && !isNumeric(oform.existing_playtimes4.value) ) { markErrorInForm('existing_playtimestext4'); }
   else { clearErrorInForm('existing_playtimestext4'); }
   if(oform.existing_playtimes5 != null && oform.existing_playtimes5.value != '' && !isNumeric(oform.existing_playtimes5.value) ) { markErrorInForm('existing_playtimestext5'); }
   else { clearErrorInForm('existing_playtimestext5'); }
}

function isValidForm() {  
  
   if(!checkValidExistingFormFields()) {
      alert('The fields marked in red type require your attention.');
      return false;
   }
   
   return true;
   
}

