//* JavaScript for History of Family Search
//* Author:  M M Hofmeister
//* Date:    03/10/01
//* Copyright:  Hofsearch.com, 2001


//  *********************************************************************
function checkBasic() {
   if (editName()) {
       if (editCounty()) {
         if (editCity()) {
           if (editYear()) {
             return true;
           }
         }
       }
   }
   return false;
}

//  *********************************************************************
function checkCensus() {
   var foundone = false
   for (i=0; i < document.one.searchType.length; i++) {
        if (document.one.searchType[i].checked) {   
            typeCensus = document.one.searchType[i].value;
            if (typeCensus == "1910..Federal") {
              document.one.orderCost.value = "35.00";
            }
            else {
              document.one.orderCost.value = "25.00";
            }   
            foundone = true;
        }
   }
   if (!foundone) {
     alert('Please select the type of Census search you would like.');
     return false;
   }
   
   if (editSurname()) {
       if (editGivenName()) {
         if (editAge()) {
           if (editCensusYears()) {
             return true;
           }
         }
       }
   }
   return false;
}

//  *********************************************************************
function checkCustom() {
   var foundone = false
   for (i=0; i < document.one.searchType.length; i++) {
        if (document.one.searchType[i].checked) {   
            type = document.one.searchType[i].value;
            if (type == "Silver") {
              document.one.orderCost.value = "280.00";
            }
            else {
              if(type == "Gold") {
               document.one.orderCost.value = "420.00";
              }
              else {
                if (type == "Platinum") {
                  document.one.orderCost.value = "600.00";
                }
                else {
                  document.one.orderCost.value = "150.00";
                }
              }
            }   
            foundone = true;
        }
   }
   if (!foundone) {
     alert('Please select the type of Custom search you would like.');
     return false;
   }
   
   if (editSurname()) {
       if (editGivenName()) {
             return true;   
       }
   }
   return false;
}

//  *********************************************************************
function checkCustInfo() {
   var fname = document.one.firstName.value;
   if (isEmpty(fname)) {
     alert('Please enter your First Name, before continuing.');
     document.one.firstName.focus();
     return false;
   }
   var lname = document.one.lastName.value;
   if (isEmpty(lname)) {
     alert('Please enter your Last Name, before continuing.');
     document.one.lastName.focus(); 
     return false; 
   }
   
   if (editEmailAddress()) {
     if(editMailingAddress()) {
       return true;
     }
   }
   return false;   
}

//  *********************************************************************
function checkDirectory() {
   if (editName()) {
       if (editFirstName()) {
         if (editCity()) {
           if (editYear()) {
             return true;
           }
         }
       }
   }
   return false;
}

//  *********************************************************************
function checkDraft() {
   if (editSurname()) {
       if (editGivenName()) {
         if (editBirthYear()) {
           if (editCounty()) {
             if (editAddrLine1()) {
               return true;
             }
           }
         }
       }
   }
   return false;
}


//  *********************************************************************
function checkIrish() {
   if (editName()) {
       if (editCounty()) {
         if (editParish()) {
           if (editYear()) {
             return true;
           }
         }
       }
   }
   return false;
}

//  *********************************************************************
function checkNatural() {
   if (editSurname()) {
       if (editFirstName()) {
         if (editCountry()) {
           if (editAge()) {
             if(editDate()) {
               return true;
             }
           }
         }
       }
   }
   return false;
}

//  *********************************************************************
function checkPayment() {
   var method=getSelected("paymentMethod");

   if (method == "Check") {
     alert('Please understand that we will not begin our research\nuntil payment has been received.\n\nPlease make your check out to: Cynthia Hofmeister and mail to:\n\tCynthia Hofmeister\n\tHistory of Family Search\n\tP.O. Box 1885\n\tOrem, Utah 84059-1885');
     return true;
   }
   var bname = document.one.billingName.value;
   if (isEmpty(bname)) {
     alert('Please enter the Billing Name exactly as it appears on the credit card.');
     document.one.billingName.focus();
     return false;
   }
   var cardNo = document.one.cardNumber.value;
   if (isEmpty(cardNo)) {
     alert('Please enter the Credit Card Number, before continuing.');
     document.one.cardNumber.focus(); 
     return false; 
   }
   
   currentDate = new Date();
   with (currentDate) {
        currMonth = getMonth() +1;
        currYear  = getFullYear();
   }               
   currMonth = currMonth +"";
   if (currMonth.length < 2) {
       currMonth = "0" +currMonth;
   }               
   currYear = currYear +"";
   today = currYear+currMonth;
   var month = getSelected("month");
   var year  = getSelected("year");
   if (month.length < 2) {
        month = "0"+month;
   }
   expire = year+month;
   if (expire < today) {
     alert('Please double check your expiration date, the expiration date of the credit card is not valid.');
     return false;
   }
   return true;   
}

//  *********************************************************************
function checkProbate() {
   if (editName()) {
         if (editCounty()) {
           if (editCity()) {
             if(editYear()) {
               return true;
             }
           }
         }
   }
   return false;
}

//  *********************************************************************
function checkTravel() {
   if (editSurname()) {
       if (editGivenName()) {
         if (editAge()) {
           if (editBirthPlace()) {
             return true;
           }
         }
       }
   }
   return false;
}


//  *********************************************************************
function editAddrLine1() {
   var bp = document.one.addrLine1.value;
   if (isEmpty(bp)) {
     alert('Please enter the Street Address.'); 
     document.one.addrLine1.focus(); 
     return false;
   }
   return true;
}

//  *********************************************************************
function editAge() {
   var age = document.one.age.value;
   if (isEmpty(age)) {
     alert('Please enter the appoximate Age of the person you want searched.');
     document.one.age.focus();
     return false;
   }
   for (i=0; i<age.length; i++) {
        var ch = age.substring(i, i +1);
        if (ch < "0" || "9" < ch)  {
            alert("\nAge must be numeric.\nPlease re-enter the approximate Age of the person.");
            document.one.age.focus();
            return false;
        }
   }
   return true;
}
//  *********************************************************************
function editBirthPlace() {
   var bp = document.one.birthPlace.value;
   if (isEmpty(bp)) {
     alert('Please enter the Birth Place of the inidividual you are searching for.'); 
     document.one.birthPlace.focus(); 
     return false;
   }
   return true;
}

//  *********************************************************************
function editBirthYear() {
   var years = document.one.birthYear.value;
   if (isEmpty(years)) {
     alert('Please enter the approximate Year of Birth.');
     document.one.birthYear.focus();
     return false;
   }
   return true;
}

//  *********************************************************************
function editCensusYears() {
   var years = document.one.censusYear.value;
   if (isEmpty(years)) {
     alert('Please enter the Census year(s) that you would like searched.');
     document.one.censusYear.focus();
     return false;
   }
   return true;
}

//  *********************************************************************
function editCity() {
   var gname = document.one.city.value;
   if (isEmpty(gname)) {
     alert('Please enter the City.');
     document.one.city.focus(); 
     return false; 
   }
   return true;
}

//  *********************************************************************
function editCounty() {
   var gname = document.one.county.value;
   if (isEmpty(gname)) {
     alert('Please enter the County.');
     document.one.county.focus(); 
     return false; 
   }
   return true;
}

//  *********************************************************************
function editCountry() {
   var gname = document.one.country.value;
   if (isEmpty(gname)) {
     alert('Please enter the Country of Birth.');
     document.one.country.focus(); 
     return false; 
   }
   return true;
}

//  *********************************************************************
function editDate() {
   var date = document.one.date.value;
   if (isEmpty(date)) {
     alert('Please enter the Date of Naturalization (approximate).');
     document.one.date.focus(); 
     return false; 
   }
   return true;
}

//  *********************************************************************
function editEmailAddress() {
    email = document.one.emailAddress.value;      
    if(isEmpty(email)) {
      alert("A valid email address is required.\n\nPlease enter your email address.");
      document.one.emailAddress.focus();
      return false;
    }
    var emailf    = document.one.emailAddress;
    var atsignPos = email.indexOf("@", 0)       // CHECK FOR AN @ SIGN
       
    if (email.indexOf(" ", 0) != -1) {
        alert("No spaces are permitted in an email address, please retry.");
        emailf.focus();
        return false;
    }
    else if (atsignPos == -1) {
        alert("A valid email address requires an @ symbol, please retry.");
        emailf.focus();
        return false;
    }
    else if (email.indexOf(".", atsignPos) == -1) {
        alert("A valid email domain is required after the @ symbol, please retry.");
        emailf.focus();
        return false;
    }
    else {
        return true;
    }
    return false;
}

//  *********************************************************************
function editFirstName() {
   var gname = document.one.firstName.value;
   if (isEmpty(gname)) {
     alert('Please enter the First Name of the person you want searched.'); 
     document.one.firstName.focus(); 
     return false; 
   }
   return true;
}

//  *********************************************************************
function editGivenName() {
   var gname = document.one.givenName.value;
   if (isEmpty(gname)) {
     alert('Please enter the Given Name of the person you want searched.');
     document.one.givenName.focus(); 
     return false; 
   }
   return true;
}

function editMailingAddress() {
//  *********************************************************************
    var addr1 = document.one.addrLine1.value;
    var addr2 = document.one.addrLine2.value;
    var city  = document.one.city.value;
    var zip   = document.one.zipCode.value;
    var zip2  = document.one.zip4.value;
            
    if ((isEmpty(addr1))  ||
       (isEmpty(city))        ||
       (isEmpty(zip)))   {
         alert("Mailing address must contain at least one address line, city, state, and zip code, please try again.");
         document.one.addrLine1.focus(); 
         return false;
    }
    
    for (i=0; i<zip.length; i++) {
        var ch = zip.substring(i, i +1);
        if (ch < "0" || "9" < ch)  {
            alert("\nZip code must be numeric.\nPlease re-enter your Zip Code.");
            document.one.zipCode.focus();
            return false;
        }
    }
    
    if (zip.length != 5) {
        alert("\nZip Code must be five digits.\nPlease re-enter your Zip Code.")
        document.one.zipCode.focus();
        return false;
    }
       
    if (! isEmpty(zip2)) {
        for (i=0; i<zip2.length; i++)  {
            ch = zip2.substring(i, i +1);
            if (ch < "0" || "9" < ch)  {
                alert("\Zip code suffix must be numeric.\nPlease re-enter your Zip Code suffix.");
                document.one.zip4.focus();
                return false;

            }
        }
        if (zip2.length != 4) {
            alert("\nZip Code suffix must be four digits.\nPlease re-enter your Zip Code suffix.")
            document.one.zip4.focus();
            return false;
        }
    }
    return true;   
}

//  *********************************************************************
function editName() {
   var gname = document.one.name.value;
   if (isEmpty(gname)) {
     alert('Please enter the Name you are searching for.');
     document.one.name.focus(); 
     return false; 
   }
   return true;
}

//  *********************************************************************
function editParish() {
   var gname = document.one.parish.value;
   if (isEmpty(gname)) {
     alert('Please enter the Civil Parish.');
     document.one.parish.focus(); 
     return false; 
   }
   return true;
}

//  *********************************************************************
function editSurname() {
   var surname = document.one.surname.value;
   if (isEmpty(surname)) {
     alert('Please enter the Surname of the person you want searched.');
     document.one.surname.focus();
     return false;
   }
   return true;
} 
 
//  *********************************************************************
function editYear() {
   var years = document.one.year.value;
   if (isEmpty(years)) {
     alert('Please enter the year.');
     document.one.year.focus();
     return false;
   }
   return true;
}

//  *********************************************************************
function feedbacks() {
  var gname = document.one.name.value;
  if (isEmpty(gname)) {
     alert('Please enter your Name before sending us feedback.');
     document.one.name.focus(); 
     return false; 
  }
  if(editEmailAddress()) {
      document.one.submit();
      return false;
  }
  return false;
}

//  *********************************************************************
function getSelected(objName) {   
    for (i=0;i< document.one[objName].options.length; i++) {
        if (document.one[objName].options[i].selected == true) {
            return document.one[objName].options[i].value;
            break;
        }
    }
}   

//  *********************************************************************
function isEmpty(el) {
    if (el == null) {
        return true;
    }
    if (el.length == 0) {
        return true;
    }
    for (i=0; i<el.length; i++) {
        var ch = el.substring(i, i +1);
        if (ch > " ") {
            return false;
        } 
    }
    return true;
}  

//  *********************************************************************
function jump(url) {
   location.href=url;
   return false;
}

//  *********************************************************************
function orderForms() {
   var orderForm=getSelected("orderForm");
   var url="";
   switch(orderForm) {
        case "Census":
            url="https://www.hofsearch.com/order.census.html";
            break;
        case "Directory":
            url="https://www.hofsearch.com/order.directory.html";
            break;
        case "County":
            url="https://www.hofsearch.com/order.county.html";
            break;
        case "Custom":
            url="https://www.hofsearch.com/order.custom.html";
            break;
        case "Draft":
            url="https://www.hofsearch.com/order.draft.html";
            break;
        case "Irish":
            url="https://www.hofsearch.com/order.irish.html";
            break;
        case "Land":
            url="https://www.hofsearch.com/order.land.html";
            break;
        case "Probate":
            url="https://www.hofsearch.com/order.probate.html";
            break;
        case "Travel":
            url="https://www.hofsearch.com/order.passport.html";
            break;
        case "Vital":
            url="https://www.hofsearch.com/order.vital.html";
            break;
        case "Natural":
            url="https://www.hofsearch.com/order.natural.html";
            break;
   }
   jump(url);
   return false;
} 

//  *********************************************************************
function openWin(url, title, options) {
   window.open(url, title, options);
}

//  *********************************************************************
function setOrderDate() {
   currentDate = new Date();
   with (currentDate) {
        currDay   = getDate();
        currMonth = getMonth() +1;
        currYear  = getFullYear();
   }
   cDay = currDay +"";
   if (cDay.length < 2) {
       cDay = "0" +cDay;
   }               
   cMonth = currMonth +"";
   if (cMonth.length < 2) {
       cMonth = "0" +cMonth;
   } 
                 
   cYear = currYear +"";
   document.one.orderDate.value=cMonth+"/"+cDay+"/"+cYear;
}

//  *********************************************************************
function setOrderNo(type) {
   currentDate = new Date();
   with (currentDate) {
        currDay   = getDate();
        currMonth = getMonth() +1;
        currYear  = getFullYear();
        currHours = getHours();
        currMins  = getMinutes();
        currSecs  = getSeconds();
   }
   cDay = currDay +"";
   if (cDay.length < 2) {
       cDay = "0" +cDay;
   }               
   cMonth = currMonth +"";
   if (cMonth.length < 2) {
       cMonth = "0" +cMonth;
   }
   
   cHours = currHours +"";
   if (cHours.length < 2) {
       cHours = "0" +cHours;
   }               
   cMins = currMins +"";
   if (cMins.length < 2) {
       cMins = "0" +cMins;
   }
   cSecs = currSecs +"";
   if (cSecs.length < 2) {
       cSecs = "0" +cSecs;
   }              
   cYear = currYear +"";
   totalDate = cYear+cMonth+cDay+cHours+cMins+cSecs;
   document.one.orderNo.value = totalDate;
   document.one.filename.value = totalDate+"."+type+".txt";
   return false;
}

//  *********************************************************************
function submits(pageId) {
  switch(pageId) {
        case "Census":
            if (checkCensus()) {
              setOrderNo(pageId);
              document.one.submit();
            }
            break;
        case "County":
            if (checkBasic()) {
              setOrderNo(pageId);
              document.one.submit();
            }
            break;
        case "CustInfo":
            if (checkCustInfo()) {
              document.one.submit();
            }
            break;
        case "Custom":
            if (checkCustom()) {
              setOrderNo(pageId);
              document.one.submit();
              }
            break;
        case "Directory":
            if (checkDirectory()) {
              setOrderNo(pageId);
              document.one.submit();
            }
            break;
        case "Draft":
            if (checkDraft()) {
              setOrderNo(pageId);
              document.one.submit();
            }
            break;
        case "Irish":
            if (checkIrish()) {
              setOrderNo(pageId);
              document.one.submit();
            }
            break;
        case "Land":
            if (checkDirectory()) {
              setOrderNo(pageId);
              document.one.submit();
            }
            break;
        case "Natural":
            if (checkNatural()) {
              setOrderNo(pageId);
              document.one.submit();
            }
            break;
        case "Payment":
            if (checkPayment()) {
              setOrderDate();
              document.one.submit();
            }
            break;
        case "Passport":
            if (checkTravel()) {
              setOrderNo(pageId);
              document.one.submit();
            }
            break;
        case "Probate":
            if (checkProbate()) {
              setOrderNo(pageId);
              document.one.submit();
            }
            break;
        case "Vital":
            if (checkBasic()) {
              setOrderNo(pageId);
              document.one.submit();
            }
            break;
  }
  return false;
}



