// JavaScript Document

var defaultEmptyOK = false
// FORM FIELD PROCESSING FUNCTIONS
function isEmail (s)
{   
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function isEmpty(s)
{   
  return ((s == null) || (s.length == 0))
}

function isDigit(c)
{   
  return ((c >= "0") && (c <= "9"))
}

function isInteger(s)
{   var i;

    //If string is empty and it should not be, then not an integer
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return true;
       else return (isInteger.arguments[1] == true);
    
    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isDate2 (year, month, day)
{
	// Original post: Dan Osborne <dano@specialist.co.uk>
	//                4/26/1999
	//                JavaScript <javascript@LaTech.edu>
	// Modified by:   Walter Torres <walter@torres.ws>
	//                4/29/2001

	// This is an interesting way to do validation of dates!

	// First, decrement the given month;
	// since humans think in base ONE and
	// JavaScript dates for months think in base ZERO.
	//      Human month range : 1 - 12
	// JavaScript month range : 0 - 11
	month--;  

	// Then, create a new JS Date Object based upon given values.
	// NOTICE: This will convert 2/32/2000 to 3/3/2000
	//         JavaScript 'helps' you like this.
	var objTempDate = new Date(year,month,day);

	// Now, tear that new Data Object apart and see if the
	// values it gives back matches what we gave it.
	return	( ( objTempDate.getFullYear() == year  ) &&
			  ( objTempDate.getMonth()    == month ) &&
			  ( objTempDate.getDate()     == day)  )  ? true : false

	// Very nice method Dan!
}

function openwin(url) {
	var newwindow=window.open(url,'xx','location=0,menubar=0,toolbar=0,resizable=1,scrollbars=1,status=0,width=620');
	if (window.focus) {newwindow.focus()}
}

function checkApp(obj)   {
  var bFcheck = true; 
  var errmsg = "ERRORS WERE FOUND with the following fields.  Please correct before proceeding.\n\n";
  var bErrors = false;
  document.forms[0].action = "submitapp.php";
  sign = document.getElementById("Sign"); 
  
  btn = obj.value;
  //alert ('clicked ' + btn + ' button\n\n' + document.forms[0].SubmissionType.value + '\n\nagreement: ' + sign.style.display);

   
  //if SUBMIT ONLINE button clicked first time
  if ((obj.name == "btnOnline") && (sign.style.display == "none")) {
      bFcheck = false;
      sign.style.display="";
      alert ("Please review the AGREEMENT section before proceeding.");
  } else {
    bFcheck = true;
  }

  //check remaining form data    
    if (bFcheck == true) {
      with (document.forms[0]) {
        //alert('checking signature...');
        if ((Signature.checked == false) && (SubmissionType.value == 'ONLINE')) {
          errmsg += "* For online submission, signature must be indicated by checking the box in the AGREEMENT section.\n\n";
          bErrors = true;
        }
      //PERSONAL INFO section
      //alert('checking personal info')
        if (isEmpty(FName.value)) {
          errmsg += "* First Name (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(LName.value)) {
          errmsg += "* Last Name (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(Address.value)) {
          errmsg += "* Address (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(City.value)) {
          errmsg += "* City (required)\n\n";
          bErrors = true;
        }  
        if (isEmpty(State.value)) {
          errmsg += "* State (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(Zip.value)) {
          errmsg += "* Zip (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(Phone.value)) {
          errmsg += "* Phone # (required)\n\n";
          bErrors = true;
        } 
        if (!isEmpty(Email.value)) {
          if (!isEmail(Email.value)) {
            errmsg += "* Email (invalid email)\n\n";
            bErrors = true;
          }
        }
        if ((isEmpty(BirthMonth.value)) || (isEmpty(BirthDay.value)) || (isEmpty(BirthYear.value))) {
          errmsg += "* Birthdate (required)\n\n";
          bErrors = true;
        }
        if (!((isEmpty(BirthMonth.value)) && (isEmpty(BirthDay.value)) && (isEmpty(BirthYear.value)))) {
          //if (!isDate(BirthYear.value, BirthMonth.value, BirthDay.value)) {
          retval = isDate2(BirthYear.value, BirthMonth.value, BirthDay.value);
          if (retval == false) {
            errmsg += "* Birth date (invalid date)\n\n";
            bErrors = true;
          }
        }
        if ((isEmpty(BaptismMonth.value)) || (isEmpty(BaptismDay.value)) || (isEmpty(BaptismYear.value))) {
          errmsg += "* Baptism date (required)\n\n";
          bErrors = true;
        }
        if (!((isEmpty(BaptismMonth.value)) && (isEmpty(BaptismDay.value)) && (isEmpty(BaptismYear.value)))) {
          if (!isDate2(BaptismYear.value, BaptismMonth.value, BaptismDay.value)) {
            errmsg += "* Baptism date (invalid date)\n\n";
            bErrors = true;
          }
        }
        if ((Gender[0].checked == false) && (Gender[1].checked == false)) {
          errmsg += "* Gender (required)\n\n";
          bErrors = true;
        }
        //PARENT/GUARDIAN section
        //alert('checking PG section')
        if (isEmpty(PGName.value)) {
          errmsg += "* Parent/Guardian (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(PGAddress.value)) {
          errmsg += "* Parent/Guardian Address (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(PGCity.value)) {
          errmsg += "* Parent/Guardian City (required)\n\n";
          bErrors = true;
        }  
        if (isEmpty(PGState.value)) {
          errmsg += "* Parent/Guardian State (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(PGZip.value)) {
          errmsg += "* Parent/Guardian Zip (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(PGPhone.value)) {
          errmsg += "* Parent/Guardian Phone # (required)\n\n";
          bErrors = true;
        } 
        if (!isEmpty(PGEmail.value)) {
          if (!isEmail(PGEmail.value)) {
            errmsg += "* Parent/Guardian Email (invalid email)\n\n";
            bErrors = true;
          }
        }
        //PERSONAL & SPIRITUAL BACKGROUND section
        //alert('checking P&S section')
        if ((ps1[0].checked == false) && (ps1[1].checked == false)) {
          errmsg += "* Personal & Spiritual Background Question 1 (required)\n\n";
          bErrors = true;
        }
        if ((ps2[0].checked == false) && (ps2[1].checked == false)) {
          errmsg += "* Personal & Spiritual Background Question 2 (required)\n\n";
          bErrors = true;
        }
        if (ps2[1].checked == true) {
          if (isEmpty(ps2a.value)) {
            errmsg += "* Personal & Spiritual Background Question 2 - church (required)\n\n";
            bErrors = true;
          }
        }
        for (i=3;i<12;i++) {
          elname = "ps" + i;
          el = document.getElementById(elname);
          if (isEmpty(el.value)) {
            errmsg += "* Personal & Spiritual Background Question " + i + " (required)\n\n";
            bErrors = true;
          }
        } 
        //EDUCATION & EMPLOYMENT BACKGROUND section
        //alert('checking E&E section')
        if (ee1.selectedIndex == 0) {
          errmsg += "* Educational & Employment Background Question 1 (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(ee4.value)) {
          errmsg += "* Educational & Employment Background Question 4 (required)\n\n";
          bErrors = true;
        }
        //FAMILY BACKGROUND section
        //alert('checking family section')
        if (isEmpty(f1.value)) {
          errmsg += "* Family Background Question 1 (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(f2.value)) {
          errmsg += "* Family Background Question 2 (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(f3.value)) {
          errmsg += "* Family Background Question 3 (required)\n\n";
          bErrors = true;
        }
        if ((f3.value == "0") && (isEmpty(f3a.value))) {
          errmsg += "* Family Background Question 3 - financial independence (required)\n\n";
          bErrors = true;
        }
        if ((f4[0].checked == false) && (f4[1].checked == false)) {
          errmsg += "* Family Background Question 4 (required)\n\n";
          bErrors = true;
        }
        psupport = false;
        for (i=0;i<9;i++) {
          if (f5[i].checked == true) {
            psupport = true;
            break;
          }
        }
        if (psupport == false) {
          errmsg += "* Family Background Question 5 (required)\n\n";
          bErrors = true;
        }
        //HEALTH section
        //alert('checking health section')
        bh1 = false;
        bh7 = false;
        bh8 = false;
        for (i=0;i<9;i++) {
          if (h1[i].checked == true) {
            bh1 = true;
            break;
          }
        }
        if (bh1 == false) {
          errmsg += "* Health Question 1 (required)\n\n";
          bErrors = true;
        }
        if ((h2[0].checked == false) && (h2[1].checked == false)) {
          errmsg += "* Health Question 2 (required)\n\n";
          bErrors = true;
        }
        if ((h2[0].checked == true) && (isEmpty(h2a.value))) {
          errmsg += "* Health Question 2 - allergies (required)\n\n";
          bErrors = true;
        }
        if ((h3[0].checked == false) && (h3[1].checked == false)) {
          errmsg += "* Health Question 3 (required)\n\n";
          bErrors = true;
        }
        if ((h3[0].checked == true) && (isEmpty(h3a.value))) {
          errmsg += "* Health Question 3 - physical limitations/disabilities (required)\n\n";
          bErrors = true;
        }
        if ((h4[0].checked == false) && (h4[1].checked == false)) {
          errmsg += "* Health Question 4 (required)\n\n";
          bErrors = true;
        }
        if ((h4[0].checked == true) && (isEmpty(h4a.value))) {
          errmsg += "* Health Question 4 - explain (required)\n\n";
          bErrors = true;
        }
        if ((h5[0].checked == false) && (h5[1].checked == false)) {
          errmsg += "* Health Question 5 (required)\n\n";
          bErrors = true;
        }
        for (i=0;i<9;i++) {
          if (h7[i].checked == true) {
            bh7 = true;
            break;
          }
        }
        if (bh7 == false) {
          errmsg += "* Health Question 7 (required)\n\n";
          bErrors = true;
        }
        for (i=0;i<9;i++) {
          if (h8[i].checked == true) {
            bh8 = true;
            break;
          }
        }
        if (bh8 == false) {
          errmsg += "* Health Question 8 (required)\n\n";
          bErrors = true;
        }
        //AUTOBIOGRAPHICAL SKETCH section
        //alert('checking bio section')
        if (isEmpty(bio.value)) {
          errmsg += "* Autobiographical Sketch (required)\n\n";
          bErrors = true;
        }
        //REFERENCES section
        //alert('checking references section')
        if (isEmpty(plclRefName.value)) {
          errmsg += "* Pastor/Local Church Leader Reference - name (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(plclRefRel.value)) {
          errmsg += "* Pastor/Local Church Leader Reference - relationship  (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(plclRefPhn.value)) {
          errmsg += "* Pastor/Local Church Leader Reference - phone #  (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(plclRefAddr.value)) {
          errmsg += "* Pastor/Local Church Leader Reference - address  (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(ocmRefName.value)) {
          errmsg += "* Other (non-family) Church Member Reference - name (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(ocmRefRel.value)) {
          errmsg += "* Other (non-family) Church Member Reference - relationship (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(ocmlRefPhn.value)) {
          errmsg += "* Other (non-family) Church Member Reference - phone # (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(ocmRefAddr.value)) {
          errmsg += "* Other (non-family) Church Member Reference - address (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(ncmRefName.value)) {
          errmsg += "* Non-Church Member Reference - name (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(ncmRefRel.value)) {
          errmsg += "* Non-Church Member Reference - relationship (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(ncmRefPhn.value)) {
          errmsg += "* Non-Church Member Reference - phone # (required)\n\n";
          bErrors = true;
        }
        if (isEmpty(ncmRefAddr.value)) {
          errmsg += "* Non-Church Member Reference - address (required)\n\n";
          bErrors = true;
        }
      }
      if (bErrors == true) {
        alert (errmsg);
      } else {
        //alert ('going to submit');
        document.forms[0].submit();
      }
  }
}



function fillTestData() {
alert("Filling test data");
with (document.forms[0]) {
  FName.value = "Test" ;
  LName.value = "Applicant";
  MName.value = "LITES";
  Address.value ="123 Some St.";
  City.value = "Anycity";
  State.value = "MO";
  Zip.value = "64489";
  Country.value = "USA"  ;
  Phone.value =  "8885551212";
  AltPhone.value =  "8885551213";
  Email.value =  "cgriffie@yahoo.com";
  BirthMonth.value =  "1";
  BirthDay.value = "2";
  BirthYear.value = "1980";
  BaptismMonth.value =  "11";
  BaptismDay.value = "17";
  BaptismYear.value = "2001";
  Gender[0].checked = true;
  PGName.value =  "Parent Guardian";
  PGAddress.value =  "1234 Some St.";
  PGCity.value =  "Anycity";
  PGState.value =  "KS";
  PGZip.value =  "66612";
  PGCountry.value = "USA" ;
  PGPhone.value =  "8771234567";
  PGAltPhone.value =  "8779876543";
  PGEmail.value =  "pg@email.com";
  Pastor.value =  "My Pastor";
  PastorPhone.value =  "8887773333";
  YouthWorker.value =  "Youth Worker";
  YWPhone.value = "8776548899" ;
  ps1[0].checked = true;
  ps2[0].checked =  true;
  ps2a.value = "Some Church"; 
  ps3.value = "PS3 - A highlight of this week was one of our morning corporate worship sessions where we listened to a tape by Josef Tson, a Romanian pastor who has suffered much for the cause of Christ.  Mr. Tson shared with us the importance of overcoming fear in order to be truly effective for the Kingdom of God.  This was a very timely message for many of us!  Please pray for us that we would be completely surrendered to God and truly live for an audience of One.";
  ps4.value = "PS4 - A highlight of this week was one of our morning corporate worship sessions where we listened to a tape by Josef Tson, a Romanian pastor who has suffered much for the cause of Christ.  Mr. Tson shared with us the importance of overcoming fear in order to be truly effective for the Kingdom of God.  This was a very timely message for many of us!  Please pray for us that we would be completely surrendered to God and truly live for an audience of One."; 
  ps5.value = "PS5 - A highlight of this week was one of our morning corporate worship sessions where we listened to a tape by Josef Tson, a Romanian pastor who has suffered much for the cause of Christ.  Mr. Tson shared with us the importance of overcoming fear in order to be truly effective for the Kingdom of God.  This was a very timely message for many of us!  Please pray for us that we would be completely surrendered to God and truly live for an audience of One."; 
  ps6.value = "PS6 - A highlight of this week was one of our morning corporate worship sessions where we listened to a tape by Josef Tson, a Romanian pastor who has suffered much for the cause of Christ.  Mr. Tson shared with us the importance of overcoming fear in order to be truly effective for the Kingdom of God.  This was a very timely message for many of us!  Please pray for us that we would be completely surrendered to God and truly live for an audience of One."; 
  ps7.value = "PS7 - A highlight of this week was one of our morning corporate worship sessions where we listened to a tape by Josef Tson, a Romanian pastor who has suffered much for the cause of Christ.  Mr. Tson shared with us the importance of overcoming fear in order to be truly effective for the Kingdom of God.  This was a very timely message for many of us!  Please pray for us that we would be completely surrendered to God and truly live for an audience of One."; 
  ps8.value = "PS8 - A highlight of this week was one of our morning corporate worship sessions where we listened to a tape by Josef Tson, a Romanian pastor who has suffered much for the cause of Christ.  Mr. Tson shared with us the importance of overcoming fear in order to be truly effective for the Kingdom of God.  This was a very timely message for many of us!  Please pray for us that we would be completely surrendered to God and truly live for an audience of One."; 
  ps9.value = "PS9 - A highlight of this week was one of our morning corporate worship sessions where we listened to a tape by Josef Tson, a Romanian pastor who has suffered much for the cause of Christ.  Mr. Tson shared with us the importance of overcoming fear in order to be truly effective for the Kingdom of God.  This was a very timely message for many of us!  Please pray for us that we would be completely surrendered to God and truly live for an audience of One."; 
  ps10.value = "PS10 - A highlight of this week was one of our morning corporate worship sessions where we listened to a tape by Josef Tson, a Romanian pastor who has suffered much for the cause of Christ.  Mr. Tson shared with us the importance of overcoming fear in order to be truly effective for the Kingdom of God.  This was a very timely message for many of us!  Please pray for us that we would be completely surrendered to God and truly live for an audience of One."; 
  ps11.value = "PS11 - A highlight of this week was one of our morning corporate worship sessions where we listened to a tape by Josef Tson, a Romanian pastor who has suffered much for the cause of Christ.  Mr. Tson shared with us the importance of overcoming fear in order to be truly effective for the Kingdom of God.  This was a very timely message for many of us!  Please pray for us that we would be completely surrendered to God and truly live for an audience of One."; 
  ee1.selectedIndex =  3;
  ee2.value = "N/A";
  ee3.value = "lots o jobs, lksdjflsjdfksdjfls, lksdjfslidfjslkdf, lsjdflksjdlkfj"; 
  ee4.value = "serve God, lksdjflsjdfksdjfls, lksdjfslidfjslkdf, lsjdflksjdlkfj";  
  f1.value =  "F1 - the quick brown fox jumbed over the lazy dog";
  f2.value =  "F2 - the quick brown fox jumbed over the lazy dog";
  f3.value =  "50";
  f3a.value =  "N/A";
  f4[1].checked = true;
  f5[3].checked = true;
  h1[3].checked = true;
  h2[0].checked = true;
  h2a.value =  "fish, pollen, etc.";
  h3[1].checked = true;
  h3a.value =  "N/A";
  h4[1].checked = true;
  h4a.value =  "N/A";
  h5[1].checked = true;
  h6.value =  "none";
  h7[4].checked = true;
  h8[3].checked = true;
  bio.value = "I was brought up in the church and had a desire to serve God at an early age.  However, as I entered my teenage and college-age years, other things began to take priority in my life.   It became very important to me to 'fit-in' and I started drinking with some of my friends.   I lost my virginity at the age of 17 and became involved in other aspects of sexual immorality.  When I got to college, I gave up drinking and sex, though I would still have inappropriate physical relationships with guys.   Unfortunately, I continued to have a gutter-mouth and bad taste in music - hard-core, explicit rap.   I was also in the gospel choir.   What a contradiction!   There was a part of me that was so attracted to the world and yet another part of me was attracted to God.   Through the choir, I began to experience the presence of God, as I never had before.   By the end of my freshman year, I was attending campus bible studies, but I was also still holding on to the world.   During my sophomore year, I continued in the choir and also started attending a Missionary Baptist church.  One evening, I returned from classes and was sitting on my bed, getting ready to pop in some of my favorite rap music that I filled my mind with daily.  I sensed a strong instruction to get rid of all my secular music and begin to listen to Christian radio and music.   I obeyed this instruction.   This signaled a turning point in my life.  In looking back, this is the point at which I would say that God intervened and saved me.   During that year and over the next several years, God did a miraculous work of transformation in my life.  During the summer before my senior year, God began to convict me (again) of the Sabbath (up to that time I had been attending the Missionary Baptist church mentioned previously).  Though it was a hard decision to make, I knew that I had to seek out a Sabbath-keeping church when I returned to school.  Because of this decision, I had to miss Saturday choir practices and endure the 'looks' of my fellow choir-members who thought that I was becoming legalistic.   There was no Church of God 7th Day in the city that I was in (Atlanta), but God led me to a Seventh Day Adventist church and surrounded me with fellow Sabbath-keepers in an awesome way.   I have absolutely no doubt that God was leading.   Since my college days, God has continued to lead me and take me on journeys and adventures that strengthen my knowledge of and relationship with Him, though some of those journeys are often difficult and I want to give up.  Praise God for His patience and faithfulness!  When I stray, He draws me back.  When I draw nigh, He draws nigh to me.  One thing I can say with assurance, developing a personal relationship with God through Jesus Christ is NEVER a boring journey!   It continues to be a new challenge everyday!" ;
  plclRefName.value =  "Pastor Reference";
  plclRefRel.value =  "Pastor of my Church";
  plclRefPhn.value =  "8889997686";
  plclRefAddr.value =  "123 Some Rd., KC, MO 76778";
  ocmRefName.value =  "Other Church Member";
  ocmRefRel.value =  "Elder in my church";
  ocmlRefPhn.value =  "8776545566";
  ocmRefAddr.value =  "123 Some Rd., KC, KS 76778";
  ncmRefName.value =  "Non-Church Member";
  ncmRefRel.value =  "Boss";
  ncmRefPhn.value =  "8778877664";
  ncmRefAddr.value =  "123 Corporate Rd., KC, MO 76778";
  }
  alert("Done");
}

function cancelReg() {
  var c = confirm('Are you sure you want to cancel your registration?\nIf yes, click OK.');
    if (c) {
      document.forms[0].reset();
      window.location.href = "http://www.cog7.org/convention";
    }
}
 

function checkIfNum(evt) {
    evt = (evt) ? evt : ((event) ? event : null);
    if (evt) {
        var charCode = (evt.charCode || evt.charCode == 0) ? evt.charCode : 
                       ((evt.keyCode) ? evt.keyCode : evt.which);
        if (charCode > 13 && (charCode < 48 || charCode > 57)) {
            if (evt.returnValue) {
                evt.returnValue = false;
            } else if (evt.preventDefault) {
                evt.preventDefault();
            } else {
                return false;
            }
        }
    }
}
