function checkdupes(course_id, thisbox) {

crsarray = document.getElementsByName('crs_selected[]');

for (i = 0; i < crsarray.length; i++){ 
	//alert(crsarray[i].id);
	//alert(thisbox);
	if (crsarray[i].id == course_id) {
	//alert("matched");
		if(thisbox.checked == true) { crsarray[i].checked = true; }
		else if(thisbox.checked == false) { crsarray[i].checked = false; }
	}
}
}



function openpopup(popurl, w, h){
var string = ("width="+w+",height="+h+",scrollbars,resizable");
//alert(string);
var winpops=window.open(popurl,"",string)
}




function checkcomments(thisform) {
 
 if ((thisform.comment.value != '')&&(thisform.comment_type.value == ''))  {
  alert("Please select a comment type for your comments.");
  return false;
 } else if ((thisform.comment.value == '')&&(thisform.comment_type.value != ''))  {
  alert("Please type in a comment for the comment category you selected.");
  return false;
 } else {
  return true;
 }
 
}






function checkreqs(thisform) {

 var checker = false;
 
 if (thisform.clgreqful_id.checked) {
  checker = true;
 }
 
 for (counter = 0; counter < thisform.clgreqful_id.length; counter++) {
  if (thisform.clgreqful_id[counter].checked) {
   checker = true;
  }
 }
 
 if (checker == false) {
  alert("You must answer all questions and complete any assessment section before continuing.");
  return false;
 } else {
  return true;
 }
 
}
 
function checkrc(thisform) {

 var checker = 0;

 for (n = 0; n < thisform.elements.length; n++) {
  if (thisform.elements[n].checked) {
   checker = (checker + 1);
  }
 }
 
 if (checker < 2) {
  alert("Please select an option for both halves of the requirement.");
  return false;
 } else {
  return true;
 }

}

function checkmajlist(thisform) {

 var checker = 0;

 for (counter = 0; counter < thisform.length; counter++) {
  if (thisform.elements[counter].checked) {
   checker = checker + 1
  }
 }

 if (checker < 3) {
  alert("Please select three majors from the list");
  return false;
 } else {
  return true;
 }
}

/*
function ACchecker(answer) {
  
  var correct = "False";
  
  var explain = "All students at UC Berkeley are required to take American Cultures course.";
  
  RightorWrong(answer, correct, explain);
}
*/

function ACchecker(answer) {
  
  var correct = "The American Cultures requirement can be satisfied with courses that provide an integrative and comparative analysis of race, culture and ethnicity in the United States as determined by the American Cultures office";
  
  var explain = "For more information, see the AC website at http://americancultures.berkeley.edu/.";
  
  RightorWrong(answer, correct, explain);
}

function RCchecker(thisform) {

 if (thisform.RC[0].checked) {
  alert("Incorrect.  You may satisfy one or both halves of the R&C requirement before coming to Berkeley.");
 }
 if (thisform.RC[1].checked) {
  alert("Correct!  You may satisfy one or both halves of the R&C requirement before coming to Berkeley.");
 }
}

function QRchecker(answer) {
  
  var correct = "False";
  
  var explain = "The QR requirement may be met by test scores or course work which includes computer science, statistics and mathematics.\n\nReview the 'How do I satisfy' section again for details.  Advisers usually recommend Statistics 2 for students who are not interested in taking more than one quantitative course and don't need to take any math, statistics, or computer science courses for their major.  Students may also take an equivalent course at a community college over the summer (check with www.assist.org).";
  
  if (answer == correct) {
    alert("You answered: "+answer+".\n\nCorrect!  The QR requirement may be met by test scores or course work which includes computer science, statistics and mathematics.");
  } else {
    alert("You answered: "+answer+".\n\nIncorrect.  "+explain);
  }
}


function sumchecker1(answer) {
  
  var correct = "120 units";
  
  var explain = "You must complete at least 120 semester units to graduate.\n\nYou may take more than 120 units as long as you graduate in no more than eight semesters (counting all the institutions you have attended), or enroll through the semester in which your units exceed 130 units (not counting AP units or college credit earned while still a high school student).";
  
  RightorWrong(answer, correct, explain);
}

function sumchecker2(answer) {
  
  var correct = "False";

  var explain = "Most students take 13-15 units per semester.\n\nWe encourage students to take a lighter load during their first semester because it is a huge transition from high school to college level work.  After the first semester, students have a better sense of the competition, pace and intensity of courses at Berkeley and are able to adjust future course loads according to their needs. The key to success is having a balanced course load.";
  
  RightorWrong(answer, correct, explain);
}

function Majchecker(answer) {
    
  var correct = "False";
  
  var explain = "All incoming students enter the College as undeclared.  They declare a major by completing prerequisite courses and applying to and being accepted by the major of their choice.";
  
  RightorWrong(answer, correct, explain);
}

function Writchecker(answer) {

  var correct = "F. Any of the options from A - E";
 
  var explain = "Any of the options from A-E may be used to satisfy the Entry Level Writing Requirement.";
 
  RightorWrong(answer, correct, explain);
}

function sturespchecker1(answer) {
  
  var correct = "5th week of the semester";
  
  var explain = "Early Drop Deadline (EDD) courses must be dropped by the end of the 2nd week of classes, but you can drop most classes until the Friday of the 5th week.  Remember, you will be charged a fee for any drops after the 2nd week.";
  
  RightorWrong(answer, correct, explain);
}


function sturespchecker2(answer) {
  
  var correct = "True";
  
  var explain = "You order DARS reports through Bear Facts by clicking the DARS link. After providing the requested information, you receive a report via e-mail within 24 hours at your on-file e-mail address (so make sure it's up-to-date!).";
  
  RightorWrong(answer, correct, explain);
}

function tipchecker1(answer) {
  
  var correct = "Both a & b";
  
  var explain = "Course priorities for your first semester should include both completing either your Entry Level Writing Requirement or the Reading & Composition requirement and beginning to explore lower division prereqs for your major(s).";
  
  RightorWrong(answer, correct, explain); 
}

function tipchecker2(answer) {
  
  var correct = "False";
  
  var explain = "Balancing your course load is a key element  that helps many students do well at Cal.  For first year students, we recommend no more than two of any kind of course, to avoid overload.";
  
  RightorWrong(answer, correct, explain);
}

function tipchecker3(answer) {
  
  var correct = "False";
  
  var explain = "Exam group dates will not change. Be SURE not to schedule two courses with the same exam group, or you may be forced to miss a final, which can make you flunk a course.";
  
  RightorWrong(answer, correct, explain);
}

function tipchecker4(answer) {
  
  var correct = "False";
  
  var explain = "Even if you got all A's in high school, academic expectations at Berkeley are going to be different than what they were at your high school or community college.  If you have never taken a full load of Cal courses, you may be surprised by the workload. 13 units is a great place to start - you can always take more later!";
  
  RightorWrong(answer, correct, explain);
}

function majprereqchecker(answer) {
  
  var correct = "All of the above";
  
  var explain = "You should make use of all options A-D to complete your major(s) prerequisites.";
  
  RightorWrong(answer, correct, explain);
}

function majchecker1(answer) {
switch(answer) { 
	case 'Do nothing. I already declared my major on my application to Cal':
	alert("Incorrect.  To declare your major, you should visit the major department as soon as possible to talk with the major adviser, and prioritize completing the lower division prerequisite courses required for your major.");
	break;
	case 'Visit the major department as soon as possible':
	alert("You are partially correct.  In addition to visiting the major department to speak with the major adviser, you should also prioritize completing the lower division prerequisite courses required for your major.");
	break;
	case 'Complete the lower division prerequisite courses specified by your intended major':
	alert("You are partially correct.  In addition to completing the lower division prerequisites required for the major, you should also visit the major department as soon as possible to speak with the major adviser.");
	break;
	case 'Finish upper division requirements for the department':
	alert("Incorrect. To declare your major, you should visit the major department as soon as possible, and prioritize completing the lower division prerequisite courses required for your major. ");
	break;
	default:
	alert("Correct!");
	}
}

function capchecker(answer) {
switch(answer) { 
	case 'Majors that study millinery fashion':
	alert("Incorrect.  Although it would be interesting, UC Berkeley does not offer a major in hat making.  A 'capped' major is one that restricts admission to the major, even if you meet the basic qualifications, and requires you to declare in their first semester at Cal.");
	break;
	case 'Majors that restrict admission to qualified applicants':
	alert("You are partially correct.  A 'capped' major also requires that you apply when, including work in progress, you have reached less than or equal to 80 total units.");
	break;
	case 'Majors that require you to apply in your first semester at Cal':
	alert("You are partially correct. A 'capped' major also restricts admission due to very high student interest and demand.");
	break;
	default:
	alert("Correct!");
	}
}

/*
function RightorWrong(answer, correct, explain) {

  if (answer == correct) {
    alert("You answered: "+answer+".\n\nCorrect!  "+explain);
  } else {
    alert("You answered: "+answer+".\n\nIncorrect!  "+explain);
  }
}
*/

function RightorWrong(answer, correct, explain) {

  if (answer == correct) {
    alert("Correct!  "+explain);
  } else {
    alert("Incorrect.  "+explain);
  }
}

function openCatalog(dept) {
	
	if (dept == "") { alert("Please select a department"); }
	else {
	/* to be revised later using
	- http://www.admuncher.com/forum/viewtopic.php?t=537&sid=f622c44911746d1313b3ab47f52cb4e5
	- http://www.codetoad.com/javascript/isnumeric.asp  */
	
	//alert(dept);
	//alert(dept.indexOf(' '));
	//alert("space character '" + dept.charAt(3) + "'");
	//dept.replace("\s", "%20");
	if (dept == "L & S") { dept = "LNS";}
	/*else  if (dept == "BIO ENG") {dept = "BIO%20ENG";}
	else if (dept == "CHM ENG") {dept = "CHM%20ENG";}
	else if (dept == "CIV ENG") {dept = "CIV%20ENG";}
	else if (dept == "COG SCI") {dept = "COG%20SCI";}
	else if (dept == "COM LIT") {dept = "COM%20LIT";}
	else if (dept == "DEV STD") {dept = "DEV%20STD";}
	else if (dept == "EA LANG") {dept = "EA%20LANG";}
	else if (dept == "EL ENG") {dept = "EL%20ENG";}
	else if (dept == "ENV DES") {dept = "ENV%20DES";}
	else if (dept == "ENV SCI") {dept = "ENV%20SCI";}
	else if (dept == "ETH STD") {dept = "ETH%20STD";}
	else if (dept == "EURA ST") {dept = "EURA%20ST";}
	else if (dept == "IND ENG") {dept = "IND%20ENG";}*/
	//alert(dept);
	var urrl = "http://sis.berkeley.edu/catalog/gcc_search_sends_request?p_dept_cd=" + dept;
	window.open(urrl,'catwindow',"menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
	}
}