<!-- $Id: javascript.js,v 1.11 2005/04/29 20:16:32 tony Exp $ -->

function Start(page) {
 
OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,height=200,width=300,resizable=no");
 
}


function toggleT(targetId,visibility) {
  if (document.getElementById) {
    target = document.getElementById(targetId);
    if (visibility == 'h') {
      target.style.display = "none";
      target.style.visiblity = "hidden";
    }
    else {
      target.style.display = "";
      target.style.visibility = "visible";
    }
  } 
}

function processforms(formbase, selectedform, formNumber) {
  if (checkrequired(formbase) == false) {
	return false;
  }

  if (checkrequired(selectedform) == false) {
	return false;
  }  

  if (formNumber == 2) {
    if (checknew(selectedform) == false) {
  	return false;
    }
  }


  return mergeforms(formNumber);
}

function checknew(which) {
  if (document.images) {
    var found = false;

    for (i=0;i<which.length;i++) {
      var tempobj=which.elements[i];

      if (tempobj.name.substring(0,3)=="new") {
	if (!((tempobj.type=="text"||tempobj.type=="textarea")&&
	     tempobj.value =='')||(tempobj.type.toString().charAt(0)=="s" &&
				  tempobj.selectedIndex==0)) {
          
           found = true;
	}
      }
    }
    if (found == false) {
      alert("Please make sure you have entered course change information into at least one field.");
      return false;	
    }
  }
  return true;
}

function checkrequired(which) {
  if (document.images) {
    for (i=0;i<which.length;i++) {
      var tempobj=which.elements[i];

      if (tempobj.name.substring(0,8)=="required") {
	if (((tempobj.type=="text"||tempobj.type=="textarea")&&
	     tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s" &&
				  tempobj.selectedIndex==0)) {
          shortFieldName=tempobj.name.substring(8,30).toUpperCase();
          alert("Please make sure the " + shortFieldName +
                " field was properly completed.");
          return false;	
	}
      }
    }
  }
  return true;
}

function mergeforms(formNumber) {
  document.errorform.name.value = document.formbase.requiredname.value;
  document.errorform.institution.value = document.formbase.requiredinstitution.value;
  document.errorform.phone.value = document.formbase.requiredphone.value;
  document.errorform.email.value = document.formbase.requiredemail.value;

  /* course addition */
  if (formNumber == 1) {
    document.errorform.type.value = "Course Addition";
    document.errorform.beginterm.value = document.formaddition.requiredbeginterm.value;
    document.errorform.course_prefix.value = document.formaddition.requiredcourse_prefix.value
    document.errorform.course_number.value = document.formaddition.requiredcourse_number.value
    document.errorform.course_title.value = document.formaddition.requiredcourse_title.value
    document.errorform.course_units.value = document.formaddition.requiredcourse_units.value
    document.errorform.course_bacc_level.value = document.formaddition.requiredcourse_bacc_level.value
    document.errorform.course_same_as_1.value = document.formaddition.course_same_as_1.value
    document.errorform.course_same_as_2.value = document.formaddition.course_same_as_2.value
    document.errorform.course_same_as_3.value = document.formaddition.course_same_as_3.value
    document.errorform.course_same_as_4.value = document.formaddition.course_same_as_4.value
    document.errorform.comments.value = document.formaddition.comments.value
    document.errorform.done.value = document.formaddition.done.value;
    document.errorform.pagename.value = document.formaddition.pagename.value
  }
  /* course change */
  else if (formNumber == 2) {
    document.errorform.type.value = "Course Change";
    document.errorform.beginterm.value = document.formcorrection.requiredbeginterm.value;
    document.errorform.current_prefix.value = document.formcorrection.requiredcurrent_prefix.value;
    document.errorform.current_number.value = document.formcorrection.requiredcurrent_number.value;
    document.errorform.current_title.value = document.formcorrection.requiredcurrent_title.value;
    document.errorform.current_units.value = document.formcorrection.requiredcurrent_units.value;
    document.errorform.current_bacc_level.value = document.formcorrection.requiredcurrent_bacc_level.value
    document.errorform.current_same_as_1.value = document.formcorrection.current_same_as_1.value;
    document.errorform.current_same_as_2.value = document.formcorrection.current_same_as_2.value;
    document.errorform.current_same_as_3.value = document.formcorrection.current_same_as_3.value;
    document.errorform.current_same_as_4.value = document.formcorrection.current_same_as_4.value;
    document.errorform.new_prefix.value = document.formcorrection.new_prefix.value;
    document.errorform.new_number.value = document.formcorrection.new_number.value;
    document.errorform.new_title.value = document.formcorrection.new_title.value;
    document.errorform.new_units.value = document.formcorrection.new_units.value;
    document.errorform.new_bacc_level.value = document.formcorrection.new_bacc_level.value;
    document.errorform.new_same_as_1.value = document.formcorrection.new_same_as_1.value;
    document.errorform.new_same_as_2.value = document.formcorrection.new_same_as_2.value;
    document.errorform.new_same_as_3.value = document.formcorrection.new_same_as_3.value;
    document.errorform.new_same_as_4.value = document.formcorrection.new_same_as_4.value;
    document.errorform.comments.value = document.formcorrection.comments.value;
  }
  /* course termination */
  else if (formNumber == 3) {
    document.errorform.type.value = "Course Termination";
    document.errorform.terminationterm.value = document.formtermination.requiredterminationterm.value;
    document.errorform.course_prefix.value = document.formtermination.requiredcourse_prefix.value;
    document.errorform.course_number.value = document.formtermination.requiredcourse_number.value;
    document.errorform.course_title.value = document.formtermination.requiredcourse_title.value;
    document.errorform.course_units.value = document.formtermination.requiredcourse_units.value;
    document.errorform.term_same_as.value = document.formtermination.term_same_as.checked == true ? "Yes" : "No";
    document.errorform.comments.value = document.formtermination.comments.value;
  }
  else {
    alert("unknown form number");
    return false;
  }
  document.errorform.submit();
  return false;

}
