/* tally.js */

/* This javascript was written by Dennis M. Fashimpaur for cyberdimmensions.com.  This
   script shall not be altered, modified or copied in whole or in part without the
   express written permission of Dennis M. Fashimpaur and cyberdimmensions.com.  Any
   violation of this copyright will be prosecuted to the fullest extent of the law.

   Contact information:

   Dennis M. Fashimpaur                    Cyberdimmensions.com
   164 S. Dubois Ave                       http://www.cyberdimmensions.com
   Elgin, IL 60123                         maryweis@cyberdimmensions.com
   fashimpaur@hotmail.com

*/

function getResults (formname){

  nameform = formname;
  checkForm(formname);

}

function writePopUp ( textOut, nof ){

  if (nof == "ee"){
    popResults = window.open("","poppedWin","height=275,width=350");
  }
  if (nof == "open"){
    popResults = window.open("","poppedWin","height=500,width=550,scrollbars=yes,resizable=yes");
  }
  popResults.document.write (textOut);
  popResults.document.close();
 
}

function checkForm(thisForm){

  var form1 = "EvanEss";
  var form2 = "Opengifts";
  var form3 = "Telling";
  var form4 = "Reaching";
  var form5 = "Hospitality";
  if (thisForm == form1){
    evEssResults();
  }
  if (thisForm == form2){
    openGiftsResults();
  }
  if (thisForm == form3){
    tellingCong();
  }
  if (thisForm == form4){
    youngGen();
  }
  if (thisForm == form5){
    hospitality();
  }
}

function evEssResults (){

  var score = 0;
  var resultText = "";
  var formlen = document.EvanEss.elements.length;
  var x = 0;
  for (x=0; x<formlen; ++x){
    var elementtype = document.EvanEss.elements[x].type;
    var ischecked = document.EvanEss.elements[x].checked;
    var elementval = document.EvanEss.elements[x].value;
    if ((elementtype == "radio")&&(ischecked == true)&&(elementval == 3)){
      ++score;
    }
  }

  if (score <= 20){
    resultText = "Thank you for using this self-assessment indicator to\n" + 
                 " look at your congregation's evangelism efforts. To be \n" + 
                 "successful in reaching out with Christ's message during \n" + 
                 "the next decade your congregation must be willing to make \n" + 
                 "some major changes. We hope you will turn to the resources \n" + 
                 "section of this web site for tips and tools that will help \n" + 
                 "you with those changes.\n";
  }
  if ((score <= 40) && (score > 20)){
    resultText = "Thank you for using this self-assessment indicator to look \n" + 
                 "at your congregation's evangelism efforts. Your congregation \n" + 
                 "has already put in place a number of the things you'll need in \n" + 
                 "order to be successful in reaching out with Christ's message \n" + 
                 "during the coming decade. There are, however, a number of other \n" + 
                 "things you need to do to be effective evangelists. Please visit \n" + 
                 "our resources section of this web site for tips and tools to \n" + 
                 "help you with those changes.\n";
  }
  if (score > 40){
    resultText = "Congratulations! You've already taken major steps to being \n" + 
                 "effective in reaching out with Christ's message during the \n" + 
                 "coming decade. We urge you to continue in your efforts and \n" + 
                 "suggest you visit the resources section of this web site for \n" + 
                 "tips and tools to help you with those changes.\n";
  }
  var doctitle = "Evangilism Essentials Assessment Results";
  var message = topHTML (doctitle);
  var closing = htmlClose();
  message = message + "<TR><TD><P>\n" + resultText + "</P></TD></TR>\n" + closing;
  writePopUp (message, "ee");
}

function topHTML (title){

  var topData = "<HTML><HEAD>\n<TITLE>" + title + "</TITLE></HEAD>\n" + 
                "<BODY BGCOLOR='#FFFFFF' TEXT='#000000'>\n" + 
                "<CENTER><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=340><TR>\n" + 
                "<TD ALIGN=MIDDLE><FONT SIZE=3 FACE='Times New Roman'><B>Your Assessment Results:</B></FONT>\n" + 
                "</TD></TR>\n";
  return topData;
}

function htmlClose ( ) {

  var closeData = "<TR><TD ALIGN=MIDDLE><FORM NAME='xit'><P><INPUT TYPE='SUBMIT' VALUE='OK' onClick='self.close()'>\n" + 
                  "&nbsp;&nbsp;<INPUT TYPE='SUBMIT' VALUE='PRINT' onClick='window.print()'>\n" +
                  "</P></FORM></TD></TR>\n"; +
                  "</TABLE></CENTER></BODY></HTML>"; 
                   
  return closeData;
}


function openGiftsResults (){

  var giftsarray = new Array ("Administration", "Artistry", "Discernment", "Evangelism",
                              "Exhortation", "Faith", "Giving", "Hospitality", "Intercession",
                              "Knowledge", "Leadership", "Mercy", "Music-Vocal", "Music-Instrumental",
                              "Pastoral", "Service", "Skilled Craft", "Teaching", "Wisdom",
                              "Writing");
  var ansa;
  var ansb;
  var ansc;
  var indxa;
  var indxb;
  var indxc;
  var total;
  var valsarray = new Array();
  var marker = 0;
  var calcresult;
  var i;
  var arrayout = new Array();
  var formlen = document.Opengifts.elements.length;
  for (i=0; i<formlen; ++i){
    var inputtype = document.Opengifts.elements[i].type;
    if ((inputtype == "select-one")&&(document.Opengifts.elements[i].name != "goto")){
      var selectindx = document.Opengifts.elements[i].selectedIndex;
      var inputval = parseInt(document.Opengifts.elements[i].options[selectindx].value);
      valsarray[marker] = inputval;
      ++marker;
    }
  }
  for (i=0; i<20; ++i){
    total = valsarray[i] + valsarray[i+20] + valsarray[i+40];
    calcresult = (Math.round((total/12)*100)*4);

    arrayout[i] = calcresult;
  }

  var tableText = "<CENTER><TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n";
  tableText = tableText + "<TR><TD>&nbsp;</TD><TD><IMG SRC='grscale.jpg' width=400></TD></TR>";
  
  for (i=0; i<20; ++i){
    if (arrayout[i] >0){
      tableText = tableText + "<TR><TD ALIGN=MIDDLE><FONT FACE='Arial' SIZE=-4>" + 
                  giftsarray[i] + "</FONT></TD>\n<TD><IMG SRC='redhr.jpg'" +
                  " width=" + arrayout[i] + " height=10 BORDER=0></TD></TR>\n";
    }
    else {
      tableText = tableText + "<TR><TD ALIGN=MIDDLE><FONT FACE='Arial' SIZE=-4>" + 
                  giftsarray[i] + "</FONT></TD>\n<TD COLSPAN=10></TD></TR>\n";
    }
  }
  tableText = tableText + "</TABLE></CENTER><BR><BR>\n";
  var doctitle = "Opening Spiritual Gifts Results";
  var message = topHTML (doctitle);
  var closing = htmlClose();
  message = message + "<TR><TD><P>\n" + tableText + "</P></TD></TR>\n" + closing;
  writePopUp (message, "open");
}


function tellingCong(){

  var tellscore = 0;
  var replyend = "Please take a close look at the responses you\'ve \n" +
                 "marked \"We could do this\" or \"We could do this better\" \n" +
                 "and discuss what you could do to ";
  var resourcesend = "For tools and tips, take a look at the resources, \"Communication\" \n" +
                     "and \"Outreach\" to improve your congregation\'s Communication Ministry.";
  var reply = "";
  var formlen = document.Telling.elements.length;
  for (x=0; x<formlen; ++x){
    var ischecked = document.Telling.elements[x].checked;
    var inputtype = document.Telling.elements[x].type;
    var checkedval = document.Telling.elements[x].value;
    if ((inputtype == "radio")&&(ischecked == true)&&(checkedval == 3)){
      ++tellscore;
    }
  }
  if (tellscore<=20){
    reply = "Thanks for your participation in this assessment.  As you can see, there \n" +
            "are a number of opportunities for your congregation as you develop \n" +
            "communication evangelism. " + replyend + "become effective communicator-\n" +
            "evangelists. " + resourcesend;
  }
  if ((tellscore>20)&&(tellscore<=40)){
    reply = "Congratulations, you are well on the way to effective communication \n" +
            "evangelism. " + replyend + "more effectively communicate through the use \n" +
            "of these items. " + resourcesend;
  }
  if (tellscore>40){
    reply = "Congratulations! You are doing a great job of Communication Evangelism! \n" +
            replyend + "make these specific items more communication friendly. ";
  }
  var doctitle = "The Telling Congregation Assessment Results";
  var message = topHTML (doctitle);
  var closing = htmlClose();
  message = message + "<TR><TD><P>\n" + reply + "</P></TD></TR>\n" + closing;
  writePopUp (message, "ee");
}

function youngGen(){

  var ygscore = 0;
  var x;
  var formlen = document.Reaching.elements.length;
  for (x=0; x<formlen; ++x){
    var inputtype = document.Reaching.elements[x].type;
    if ((inputtype == "select-one")&&(document.Reaching.elements[x].name != "goto")){
      var selectIndx = document.Reaching.elements[x].selectedIndex;
      var optionval = parseInt(document.Reaching.elements[x].options[selectIndx].value);
      ygscore = ygscore + optionval;
    }
  }
  ygscore = Math.round(ygscore/44);

  if (ygscore == 5){
    reply = "You top the charts in discipling younger generations. Boomer and \n" +
            "busters clearly feel welcome and included in the life, ministry, \n" +
            "and leadership of your congregation.  Your congregations' future is bright.";
  }
  if (ygscore == 4){
    reply = "You are a generationally-friendly congregation.  Singles, parents, \n" +
            "young adults, youth and children know that the congregation is committed \n" +
            "to passing on the faith to younger generations.  Continue to grow in your \n" +
            "strengths and address your weaknesses.";
  }
  if (ygscore == 3){
    reply = "You are doing a fair job of discipling younger generations. \n" +
            "Spend time building on your strengths in generational ministry. \n" +
            "Focus deliberate efforts and energy on the elements of generational \n" +
            "ministry that are missing.";
  }
  if (ygscore == 2){
    reply = "Stop and reflect on your congregation's mission and ministry.  Determine \n" +
            "three key strategies your congregation can address to be more attractive \n" +
            "to younger generations.";
  }
  if (ygscore == 1){
    reply = "Your present ministry focus is primarily on World War II generations. \n" +
            "To ensure the future health and vitality of your congregation devote \n" +
            "some major attention to these issues.";
  }
  var doctitle = "Reaching Younger Generations Assessment Results";
  var message = topHTML (doctitle);
  var closing = htmlClose();
  message = message + "<TR><TD><P>\n" + reply + "</P></TD></TR>\n" + closing;
  writePopUp (message, "ee");
}

function hospitality(){

  var hscore = 0;
  var x;
  var elementcount = 0;
  var reply = "";
  var formlen = document.Hospitality.elements.length;
  for (x=0; x<formlen; ++x){
    var inputtype = document.Hospitality.elements[x].type;
    if ((inputtype == "select-one")&&(document.Hospitality.elements[x].name != "goto")){
      var selectIndx = document.Hospitality.elements[x].selectedIndex;
      var optionval = parseInt(document.Hospitality.elements[x].options[selectIndx].value);
      hscore = hscore + optionval;
      ++elementcount;
    }
  }
  hscore = Math.round(hscore/elementcount);

  if (hscore == 5){
    reply = "You top the list in hospitality! Visitors feel welcomed. You likely \n" +
            "experience a 90% return rate on your first time worship visitors.";
  }
  if (hscore == 4){
    reply = "You are a warm, hospitable congregation.  Visitors sense a genuine welcome \n" +
            "and know their presence has been appreciated.  Most of your first worship \n" +
            "visitors will return and will likely find a caring home in your congregation.";
  }
  if (hscore == 3){
    reply = "You are doing a fine job of welcoming guests to your congregation. Spend \n" +
            "more time building on your strengths.  Note areas of weakness and \n" +
            "initiate steps to strengthen your hospitality ministry. Please choose \n" +
            "resources, 'Hospitality' and 'Outreach' for tips and tools on how to \n" +
            "improve your Hospitality Ministry.";
  }
  if (hscore == 2){
    reply = "Visitors probably perceive your church to be cold and closed.  Your members \n" +
            "likely spend most of their time meeting with their freinds.  Visitors probably \n" +
            "do not feel appreciated and welcomed.  Your worship visitors return rate is \n" +
            "probably less than 20%. Please choose resources, 'Hospitality' and \n" +
            "'Outreach' for tips and tools on how to improve your Hospitality Minsitry.";
  }
  if (hscore == 1){
    reply = "Visitors are not returning to your congregation.  Emergency surgery is \n" +
            "needed on your hospitality ministry.  Your congregation, unless it changes \n" +
            "is slipping into a coma. Pleas choose resources, 'Hospitality' and \n" +
            "'Outreach' for tips and tools on how to improve your Hospitality Ministry.";
  }
  var doctitle = "Hospitality Assessment Results";
  var message = topHTML (doctitle);
  var closing = htmlClose();
  message = message + "<TR><TD><P>\n" + reply + "</P></TD></TR>\n" + closing;
  writePopUp (message, "ee");
}
