 function getObject(objName)
 {
    var obj;

    if (document.all)
    {
        obj = document.all(objName);
    } else
    {
        obj = objName;
    }

    return obj;

 }

 function calcTotal(question)
 {
    var count;
    var total = 0;
    var numValue;
    var tmp;
    var fieldName;
    var oldTotal;

    fieldName = "qcount" + question;
    count = getObject(fieldName).value;

    fieldName = "qtotal" + question;
    oldTotal = getObject(fieldName).value;


    for (i=1; i <= count; i++)
    {
        fieldName = "answer" + question + "_" + i;
        tmp = getObject(fieldName).value;

        // make sure its a number
        if (isNaN(tmp) || tmp == '' || tmp == ' ' || tmp == '  ' || tmp == '   ')
        {
             getObject(fieldName).value = 0;
        } else
        {
            total += parseInt(tmp);
        }


    }

    // validate (just warn for now)
    if (total>100 && oldTotal < 101) {
        alert("Warning: The total is over 100%");
    }

    fieldName = "qtotal" + question;
    getObject(fieldName).value = total;

 }


 function calcMTotal(question, col) {

     var fieldName;
     var qCount;
     var total = 0;
     var tmp;
     var qCount;

     fieldName = "numquestions" + question;
     qCount = getObject(fieldName).value;

     for (i=1; i <= qCount; i++)
     {
         fieldName = "answer" + question + "_" + i + "_" + col;
         tmp = getObject(fieldName).value;

         // make sure its a number
         if (isNaN(tmp) || tmp == '' || tmp == ' ' || tmp == '  ' || tmp == '   ')
         {
              getObject(fieldName).value = 0;
         } else
         {
             total += parseInt(tmp);
         }


     }

     fieldName = "qtotal" + question + "_" + col;
     getObject(fieldName).value = total;

}


function doSurvey(URN, studentCode, tocSurveyIndex, courseCode) {
   var newLocation;

   newLocation = "websurvey.asp?URN=" + URN;
   newLocation = newLocation + "&MKSC=" + studentCode;
   newLocation = newLocation + "&TOCSI=" + tocSurveyIndex;
   newLocation = newLocation + "&MKCC=" + courseCode;

   window.location.href = newLocation;

}

function checkForPageChange(newPage) {

    if (paging) {

        var newLayer;

        newLayer = "page" + newPage;

        if (newLayer != currentLayer) {
            hideLayer(currentLayer);
            document.getElementById(newLayer).style.display = 'block';
            currentLayer = newLayer;
        }
    }

}

function jumpQuestionCombo(count) {

  var linkID;
  var answerID;
  var choice;
  var targetQuestion;
  var optionIndex;
  var tmp;
  var pgTmp;

  linkID = "link" + count;
  answerID = "answer" + count;

  lastChoice = document.frmSurvey[linkID].value;
  choice = document.frmSurvey[answerID].value;

  tmp = "link_option" + count + "_" + choice;
  optionIndex = document.frmSurvey[tmp].value;


  tmp = "link_target" + count + "_" + choice;

  targetQuestion = document.frmSurvey[tmp].value;

  pgTmp = "pg" + targetQuestion;

  document.frmSurvey[linkID].value = choice;

  if (optionIndex == choice && optionIndex != lastChoice) {
  
    // see if popup survey, targetQuestion will be < -1
    if (targetQuestion < -1) {
      var surveyIndex = (targetQuestion * -1) -1;
      var surveyURL = "popup.asp?from=" + document.frmSurvey.URN.value +"&to=" + surveyIndex;
      window.open(surveyURL);
    } else {
      checkForPageChange(document.frmSurvey[pgTmp].value);
      window.location.href = "#" + targetQuestion;
    }
    
  }

}

function jumpQuestion(triggerOption, targetQuestion, count) {

  var choice;
  var linkID;
  var answerID;
  var lastChoice;
  var pgTmp;

  linkID = "link" + count;
  answerID = "answer" + count;
  lastChoice = document.frmSurvey[linkID].value;
  choice = document.frmSurvey[answerID].value;
  pgTmp = "pg" + targetQuestion;

  document.frmSurvey[linkID].value = choice;

  if (triggerOption == choice && triggerOption != lastChoice) {
      
    // see if popup survey, targetQuestion will be < -1
    if (targetQuestion < -1) {
      var surveyIndex = (targetQuestion * -1) -1;
      var surveyURL = "popup.asp?from=" + document.frmSurvey.URN.value +"&to=" + surveyIndex;
      window.open(surveyURL);
    } else {
      // standard jump
			checkForPageChange(document.frmSurvey[pgTmp].value);
			window.location.href = "#" + targetQuestion;
    }
    
  }

}

function jumpQuestionRadio(triggerOption, targetQuestion, count, radioOption) {

  var choice;
  var linkID;
  var answerID;
  var lastChoice;
  var pgTmp;

  linkID = "link" + count;
  answerID = "answer" + count;
  lastChoice = document.frmSurvey[linkID].value;
  choice = document.frmSurvey[answerID][radioOption].value;
  pgTmp = "pg" + targetQuestion;

  document.frmSurvey[linkID].value = choice;

  if (triggerOption == choice && triggerOption != lastChoice) {
  
    // see if popup survey, targetQuestion will be < -1
    if (targetQuestion < -1) {
      var surveyIndex = (targetQuestion * -1) -1;
      var surveyURL = "popup.asp?from=" + document.frmSurvey.URN.value +"&to=" + surveyIndex;
      window.open(surveyURL);
    } else {
      // standard jump
			checkForPageChange(document.frmSurvey[pgTmp].value);
			window.location.href = "#" + targetQuestion;
		}
		
  }

}

var labelOff = 0;
var tblOff = 0;
var helper = true;
var currentLabel = 0;

function showLabel(tblID, lblID)
{
  if (currentLabel == lblID)
  {
    if (helper == true) {
      if (tbl.length > 1) {
        tbl[tblID-1].rows[lblID].style.visibility = 'visible';
        tbl[tblID-1].rows[lblID].style.height = '8 pt';
      } else {
        tbl.rows[lblID].style.visibility = 'visible';
        tbl.rows[lblID].style.height = '8 pt';
      }
    }
    if ((labelOff != 0) && (labelOff != lblID)) {
      if (tbl.length > 1) {
        tbl[tblOff-1].rows[labelOff].style.visibility = 'hidden';
        tbl[tblOff-1].rows[labelOff].style.height = '0 pt';
      } else {
        tbl.rows[labelOff].style.visibility = 'hidden';
        tbl.rows[labelOff].style.height = '0 pt';
      }
      labelOff = lblID;
            tblOff = tblID;
    } else {
      labelOff = lblID;
            tblOff = tblID;
    }
  }
}

