var isIE=document.all?true:false;
var isDOM=document.getElementById?true:false;
var isNS4=document.layers?true:false;

/* _w : which ID (1) or (2) */
/* _h : (h)ide or (s)how */
function toggleT(_w,_h) {
  if (isDOM) {
    if (_h=='s') document.getElementById(_w).style.visibility='visible';
    if (_h=='h') document.getElementById(_w).style.visibility='hidden';
  }
  else if (isIE) {
    if (_h=='s') eval("document.all."+_w+".style.visibility='visible';");
    if (_h=='h') eval("document.all."+_w+".style.visibility='hidden';");
  }
  else if(isNS4) {
    if (_h=='s') eval("document.layers['"+_w+"'].visibility='show';");
    if (_h=='h') eval("document.layers['"+_w+"'].visibility='hide';");
  }
}

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility

function moveObject(objectId, newXCoordinate, newYCoordinate) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.left = newXCoordinate;
	styleObject.top = newYCoordinate;
	return true;
    } else {
	// we couldn't find the object, so we can't very well move it
	return false;
    }
} // moveObject

function switchIfCorrect(the_form, this_div, showAns_div, next_div , value) {
  //test if any field has not been properly filled in
  if(value == "correct") {
    switchDiv(this_div, showAns_div, next_div);//goes to part 1
  }  
}

function popError(error_message) {
  //test if any field has not been properly filled in
  document.question1.Q1.checked = false;
  alert(error_message);
  
}

function switchDiv(this_div, showAns_div, next_div) {
  if (getStyleObject(this_div) && getStyleObject(next_div)) {
    toggleT(this_div,'h');
    toggleT(showAns_div,'s');
    toggleT(next_div,'s');
    //changeObjectVisibility(this_div, "hidden");
    //changeObjectVisibility(next_div, "visible");
  }
}

function twoSemTest() {
    var flag = new Boolean();
    if((document.Semester2.term2.value == document.Semester_new.term_new.value) || (document.Semester2.term2.value == "Fall")) {
      var addOneToYear = document.Semester2.year2.value * 1 + 1;
      var newYear = document.Semester_new.year_new.value;
    
      if(newYear > addOneToYear) {
        document.testing.test2.value = "yes";
        flag = true;
      }
      else {
        flag = false;
      }
      //next two lines for test only
      //document.testing.test1.value = addOneToYear;
      //toggleT('test','s');
    }
    else {
      if(document.Semester2.year2.value == document.Semester_new.year_new.value) {
        flag = false;    
      }
      else {
        flag = true;
      }
    }
   
   return flag;
}

function ResetAndStartOver() {
      document.degree.degreeOption.value = "   ";
      document.Semester_new.term_new.value = "   ";
      document.Semester_new.year_new.value = "   ";      
      document.Semester.term.value = "   ";
      document.Semester.year.value = "   ";
      document.OutOfSchool_info.outofschool.value = "   ";
      document.OutOfSchool_info_b.outofschool_b.value = "   ";
      document.OutOfSchool_info_c.outofschool_c.value = "   ";      
      document.Semester2.term2.value = "";
      document.Semester2.year2.value = "";
      toggleT('divstartover','h');
      toggleT('seeAdviser','h');      
      toggleT('divt1','h');
      toggleT('start','s');
      toggleT('part1','h');
      toggleT('part2','h');
      toggleT('part2b','h');
      toggleT('part2c','h');
      toggleT('part3','h');
      toggleT('theEnd','h');
}

//
function showCoreSheet() {
  //toggleT('theEnd','s');
  var submission_string="";
  
  var yearMinusOne = document.Semester2.year2.value * 1 - 1;
  var yearPlusOne = document.Semester2.year2.value * 1 + 1;  
  
  if(((document.Semester2.year2.value == 2002) && (document.Semester2.term2.value == "Spring")) || (document.Semester2.year2.value <= 2001)) {
     toggleT('seeAdviser','s');
     toggleT('theEnd','h');
     submission_string = document.Semester2.term2.value + " " + document.Semester2.year2.value;
     document.c.programSheet.value = submission_string;
  }
  else if(document.Semester2.term2.value == "Fall") {
    submission_string += document.Semester2.degree2.value + ":  "; 
    submission_string += document.Semester2.year2.value + " - " + yearPlusOne.toString().substring(2,4);
    document.details.programSheet.value = submission_string;
  }
  else {
    submission_string += document.Semester2.degree2.value + ":  "; 
    submission_string += yearMinusOne + "-" + document.Semester2.year2.value.substring(2,4);
    document.details.programSheet.value = submission_string;
  }
  
  //submission_string += document.Semester2.term2.value + " ";
  //submission_string += document.Semester2.year2.value + " ";  

//  **** used only for testing  
//  for (var form_loop=0; form_loop<document.forms.length; form_loop++) {
//    for (var elems=0; elems<document.forms[form_loop].length;elems++) {
//      if (document.forms[form_loop].elements[elems].name != "") {
//        submission_string += document.forms[form_loop].name + "_" +
//          document.forms[form_loop].elements[elems].name + "=" +
//          document.forms[form_loop].elements[elems].value + "\n";
//      }
//    }
//  }
  
  // the next two lines are written for debugging - 
  // to put the script into action
  // comment out the changeObjectVisibility() line
  // and uncomment the document.hidden.form.submit() line
  //
  //document.hiddenform.submit(); 
  //changeObjectVisibility("theEnd","visible");
}
