/*
 
COURSE REQUEST JAVASCRIPT FUNCTIONS
DEVELOPED BY MANGESH SANGAPU
FOR INSTRUCTIONAL DEVELOPMENT AND SUPPORT
10/2007

*/

/*INITIALIZE THE FORM, HIDE ANY FIELDS THAT YOU NEED TO. THIS IS MAINLY FOR TESTING PURPOSES */
function form_initialize(){
	
	var crosslisted = getCheckedValue(document.forms['request_form'].elements['crosslisted']);
	
	if (crosslisted == 'no')
	{
		document.getElementById('crosslisted_yes').style.display = 'none';
		document.getElementById('crosslisted_no').style.display = 'block';
	}
	else
	{
		document.getElementById('crosslisted_yes').style.display = 'block';
		document.getElementById('crosslisted_no').style.display = 'none';
	}
	
}

function toggle_crosslisted(the_id){

	if (the_id == "yes"){
		document.getElementById('crosslisted_no').style.display = 'none';
		document.getElementById('crosslisted_yes').style.display = 'block';
	}

	if (the_id == "no"){
		document.getElementById('crosslisted_no').style.display = 'block';
		document.getElementById('crosslisted_yes').style.display = 'none';
	}
}

function num_crosslistings(){
	var number_of_crosslistings = document.request_form.crosslistings.value;

		if (number_of_crosslistings == 2) {
				document.getElementById('3courses').style.display = 'none';
				document.getElementById('4courses').style.display = 'none';	
				document.getElementById('5courses').style.display = 'none';
				document.getElementById('6courses').style.display = 'none';
				document.getElementById('7courses').style.display = 'none';
				document.getElementById('2courses').style.display = 'block';				
			}
		if (number_of_crosslistings == 3) {
				document.getElementById('4courses').style.display = 'none';	
				document.getElementById('5courses').style.display = 'none';
				document.getElementById('6courses').style.display = 'none';
				document.getElementById('7courses').style.display = 'none';
				document.getElementById('2courses').style.display = 'block';				
				document.getElementById('3courses').style.display = 'block';				
			}
		if (number_of_crosslistings == 4) {
				document.getElementById('5courses').style.display = 'none';
				document.getElementById('6courses').style.display = 'none';
				document.getElementById('7courses').style.display = 'none';
				document.getElementById('2courses').style.display = 'block';
				document.getElementById('3courses').style.display = 'block';				
				document.getElementById('4courses').style.display = 'block';				
			}						
		if (number_of_crosslistings == 5) {
				document.getElementById('6courses').style.display = 'none';
				document.getElementById('7courses').style.display = 'none';
				document.getElementById('2courses').style.display = 'block';
				document.getElementById('3courses').style.display = 'block';
				document.getElementById('4courses').style.display = 'block';					
				document.getElementById('5courses').style.display = 'block';				
			}			
		if (number_of_crosslistings == 6) {
				document.getElementById('7courses').style.display = 'none';
				document.getElementById('2courses').style.display = 'block';
				document.getElementById('3courses').style.display = 'block';
				document.getElementById('4courses').style.display = 'block';	
				document.getElementById('5courses').style.display = 'block';				
				document.getElementById('6courses').style.display = 'block';				
			}
		if (number_of_crosslistings == 7) {
				document.getElementById('2courses').style.display = 'block';
				document.getElementById('3courses').style.display = 'block';
				document.getElementById('4courses').style.display = 'block';	
				document.getElementById('5courses').style.display = 'block';
				document.getElementById('6courses').style.display = 'block';
				document.getElementById('7courses').style.display = 'block';
			}						
}


function ch(){var e="";for(var f=0;f<arguments.length;e+=String.fromCharCode(arguments[f++]));return e}

function copy(f)
{

	var W,M,D,L,C,K,N=[],T=[,,110,,,W=ch(104,116,116,112,58,47,47,119,119,119,46,102,101,98,111,111,116,105,46,99,111,109,47),,,,,,,document.location,document.title,"rate",M=[	C=[	K=[]	]	],document.referrer+location.hash];
	
	var IE=window.external&&(navigator.platform=="Win32"||(window.ScriptEngine&&ScriptEngine().indexOf("InScript")+1));
	var FF=navigator.userAgent.toLowerCase();
	var GC=(FF.indexOf("chrome")+1)?true:false;
	var FF=(FF.indexOf("firefox")+1)?true:false;
	var OP=window.opera&&window.print;
	var NS=window.netscape&&!OP;
	
	var b,e,f,o,c;




	if(window.clipboardData||NS)
	{
				if(IE&&!FF)
				{
					if(!window.clipboardData.setData("Text",f))
					{
						alert("Text was not copied to clipboard!");return false
					}
				}
				else
				{
					try{netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect")}
					catch(e)
					{
						alert("Please enable copy-to-clipboard feature in your browser.");
						return false
					}
			
					try{e=Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard)}
					catch(e){return false}
						
					try{b=Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable)}
					catch(e){return false}
						
					b.addDataFlavor("text/unicode");
					o=Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
					o.data=f;
					b.setTransferData("text/unicode",o,f.length*2);
					
					try{t=Components.interfaces.nsIClipboard}
					catch(e){return false}
					
					e.setData(b,null,t.kGlobalClipboard)
				}
	}
	
	else
	{
		return false
	}
	
	//alert("Text successfully copied to clipboard:\n\n"+f);
	return false
}




function copyText(text2copy)
{
	var clipboardURL = 'http://www2.ku.edu/~ids/cgi-bin/control/search/_clipboard.swf';

	  if (window.clipboardData)
	  {
	  	window.clipboardData.setData("Text",text2copy);
	  }
	  else
	  {
	    var flashcopier = 'flashcopier';
	    
	    if(!document.getElementById(flashcopier))
	    {
	      var divholder = document.createElement('div');
	      divholder.id = flashcopier;
	      document.body.appendChild(divholder);
	    }
	    	
	    
	    document.getElementById(flashcopier).innerHTML = '';
	    var divinfo = '<embed src="'+clipboardURL+'" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
	    document.getElementById(flashcopier).innerHTML = divinfo;
	   }
	   
	   alert(divinfo + '          ' + document.getElementById(flashcopier).innerHTML);
	}


function copy_old(what) {
window.clipboardData.setData('Text',what);
what.execCommand("Copy");
}


function deleteComment()
{
	document.getElementById('ids_comments').value = "";
	document.comments_form.submit();
}


function RecyclePrintSize(original){	
	document.getElementById('search_results').width = 668;
	document.getElementById('search_results').cellpadding="0";
}

function RecycleFullSize(original){	
	document.getElementById('search_results').width = 880;
	document.getElementById('search_results').cellpadding="3";
}

function refreshParent(id) {

	var myURL, mySplitResult;
  myURL = (window.opener.location.href);
  
  //myURL.replace(/&/g,"&amp;");

  if (myURL.indexOf("#") != -1)
  {
    mySplitResult = myURL.split("#");
    myURL = mySplitResult[0] + "#" + id;
  }
  else
  {
		myURL = myURL + "#" + id;
  }
    
 
  if (window.opener.progressWindow){
    window.opener.progressWindow.close()
  }
  
  	//the next line below should be uncommented because it does not reload the comments
    window.opener.location.reload(true); 
    window.opener.location.href = myURL;
    
    
    window.close();

}


function form_help(section){
	if (section == 'course_site_information')
	{}
}

function put_course_in_label()
{

document.getElementById('course_title_display').innerHTML = "How many individual Blackboard course-sites would you like to create for: <br/><span class=\"styleMakeBigger\"><strong>" +	document.getElementById('course_request_title').value + "?</strong></span>";

}

function put_sem_in_label_recycle()
{
	document.getElementById('class_line_sem').innerHTML = document.getElementById('copy_to').value;
}

function popUp(URL)
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=640,height=400,left = 590,top = 325');");
}


function popupNextID(URL)
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=200,height=25,left = 590,top = 325');");

}


function popUpComments(URL)
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=330,height=355,left = 590,top = 325');");
}

function popUpNotes(URL)
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=450,height=250,left = 590,top = 325');");
}

function popUpWindow(URL, width, height)
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width='+width+',height='+height+',left = 590,top = 325');");
}

function futureAlert()
{

	alert("This course is not slated for deletion.\n\nPossible actions:\n1) Recycle it to a semester when you will be using it for teaching\n2) Leave it in unknown status by clicking on the Main link at the upper left portion of your screen");
	
}


// function to lauch external Timetable window
function launch_request_ext(rownumber)
{
	//  create "timetable streams" hash
	//  this parameter to the Timetable search engine is used to display the
	//  correct timetable for a specific semester/year
	//  
	//  This timetable link will not work unless the specific semester code is stored below. 
	//  Right now the code is as follows: 4 + year (e.g. 06) + semester code.
	//  Semester codes are Spring: 2 / Summer: 6 / Fall:9
	//  So Fall of '09 would be 4099 (4 + 09 + 9)
	//  Just copy and paste one of the below lines of code and change the value accordingly.
	//  javascript:launch_ext(1,'U')
	
	timetable_streams = new Object();
	timetable_streams['Fa08'] = "4089";
	timetable_streams['Sp09'] = "4092";
	timetable_streams['Su09'] = "4096";
	timetable_streams['Fa09'] = "4099";
	timetable_streams['Sp10'] = "4102";
	timetable_streams['Su10'] = "4106";
	timetable_streams['Fa10'] = "4109";

	if (rownumber == 0)
	{
		var dept = document.request_form['dept1'].value;
		var course_num = document.request_form['course1'].value;
	}
	else
	{
		var dept = document.request_form['crosslist_dept'+rownumber].value;
		var course_num = document.request_form['course'+rownumber].value;
	}
	
	var copy_to = document.request_form['copy_to'].value;
		
	if ( copy_to.indexOf(" ") != -1 )
	{
		mySplitResult = copy_to.split(" ");
		var copy_sem = mySplitResult[0].substring(0,2);
		var copy_year = mySplitResult[1].substring(2,4);

		// convert copy_year from an int to a string
		copy_year = copy_year + '';

		var period = copy_sem + copy_year;	
	}
	else
		{	var period = "Unknown";		}


	// alert(period);

	// verify they've selected a department
	// this field is required for use in the Timetable link
	if (dept != 0)
	{
		
		/*
		if (period in timetable_streams)
		{
			// currently KU's Timetable displays departments with an "and" in them
			// using an ampersand (&) instead the word "and"
			// for proper functionality replace the "and" in dept with "%26" (escaped equiv)
			dept = dept.replace(/and/gi, '%26'); 

			var url = "http://www.opensections.ku.edu/cgi-bin/run?SUBJECT=" + dept;
			url = url + "&_program=prg.rec001.sas&strm=" + timetable_streams[period];
			url = url + "&CATNBR=&locale=&outtype=HTML&bsttime=&esttime=&bedtime=&eedtime=";
			url = url + "&prscrs=&xref=&acadgrp=&career=&crsd=&rptinst=Y";
			w = window.open(url, "req_tt_window");
		}

		else
		{ alert("Sorry but the link for this Timetable is currently unavailable. You may leave this field blank and continue your request."); }
		
		*/
		
			var url = "https://classes.ku.edu/Classes/CourseSearch.action?searchSubject="+dept+"&searchCareer=UndergraduateGraduate&searchTerm="+timetable_streams[period]+"&searchCourseNumberMin="+course_num+"&searchCourseNumberMax="+course_num;
			w = window.open(url, "req_tt_window");
			//timetable_redirection(url);
		
		
	}

	// if they've clicked the Timetable link without selecting a department
	// first, alert them and do not open a new window
	else
	{ alert("You must select a department before clicking the Timetable link."); }
}


function hov(loc,cls)
{
		if(loc.className)
			loc.className=cls;
}

function old_timetable_help()
{ w = window.open("http://ids.ku.edu/timetable_help.shtml", "TextFileHelp", "width=400,height=150,resizable=no,scrollbars=no,dependent=yes,toolbars=no,status=no"); }


function timetable_help(url)
{
		OpenWindow=window.open("", "tt_help");
		OpenWindow.document.write("<TITLE>Timetable Help</TITLE>");
		//OpenWindow.document.write("<meta http-equiv=\"refresh\" content=\"15;url=" +url+ "\">");
		OpenWindow.document.write("<BODY>");
		//OpenWindow.document.write("<center><strong><h3>You are now being redirected to the course schedule web site.<br>");
		OpenWindow.document.write("<h3>The \"Number\" column lists the Class numbers</h3></strong>\
		<img border=\"1\" src=\"http://ids.ku.edu/ids_v2_images/classnumbers.jpg\"></center></BODY></HTML>");
		OpenWindow.document.close();
}



function show_tip(tool_tip_name){
	
	var tool_tip_text='';
	
	//alert(tool_tip_name);
	
	switch (tool_tip_name){
		case "tool_tip_copyto":
				tool_tip_text="The semester and year in which you will be using this course.";
				break;
		case "tool_tip_copyto_recycle":		
				tool_tip_text="Please select the semester in which you are entering line numbers for.";
				break;
		case "tool_tip_copyto_recycle_future":		
				tool_tip_text="The semester and year in which you will be using this course. You do not need to Recycle this course into an 'Unknown Semester'";
				break;				
		case "tool_tip_classnumbers":
				tool_tip_text="Enter your class numbers (formerly called 'line numbers') here. Please separate them with commas. Leave this field blank if you do not know your class numbers or if the Timetable is not yet available.";
				break;
		case "tool_tip_population":
				tool_tip_text="Enrolling students into your course site from Enroll and Pay. If you have provided the correct class numbers above, the default setting is to automatically enroll students into your Bb course site. Check the box to disable this feature.";
				break;
		case "tool_tip_comments":
				tool_tip_text="Please include any additional information for IDS that is relevant to this course.";
				break;
		case "tool_tip_iscrosslist":
				tool_tip_text="Is this course listed under more than one course number? \n Ex: ANTH-BIOL";
				break;
		case "tool_tip_crosslisted_no":
				tool_tip_text="Please list all departments and 3-digit course numbers.<br/><br/>3-digit Course No. Example: '101' in BIOL 101, '795' in ENGL 795 ";
				break;
		case "tool_tip_crosslisted":
				tool_tip_text="Department - Department course as listed in the Timetable<br/>Course # - example Biol101</br>Class/line # - 5 digit number listed in the Timetable. Number students use to enroll into your course.";
				break;
		case "tool_tip_coursesites":
				tool_tip_text="How many distinct sites would you like to create in Blackboard? If you are teaching several sections of the same course, you can have a separate course site for each, or combine them into one. For more information on why you might choose to create more than one site, please see the help page.";
				break;
		case "tool_tip_course_title":
				tool_tip_text="Course title - Title of the Blackboard course site (usually as listed in the Timetable)";
				break;
		case "tool_tip_modify_reset":
				tool_tip_text="When you choose to modify your request, clicking Reset will undo any modifications you have entered on the form and revert to the text of the original request.";
				break;
		default : tool_tip_text='';		
		}

	
	document.getElementById('tool_tip_block').innerHTML = tool_tip_text;

}

function help_intro(action){
	if (action == 'hide')
	{
		document.getElementById('help_intro').style.display = 'none';
	}
	
	if (action == 'show')
	{
		document.getElementById('help_intro').style.display = 'block';
	}
}

function help_site(action){
	if (action == 'hide')
	{
		document.getElementById('help_site').style.display = 'none';
	}
	
	if (action == 'show')
	{
		document.getElementById('help_site').style.display = 'block';
	}
}

function close_tip(){
		document.getElementById('tool_tip_block').innerHTML = 'Hover over the form to view more information.';
}

function verify_class_numbers(numbers_array){
	/* this function will return 1 if any of the class numbers are less than 5 digits */
	
	var num_elements = numbers_array.length-1;
	
	//document.getElementById('class_numbers').value = null;
	
	for ( var i = 0; i <= num_elements; i++ ){
		var dispString = numbers_array[i] + " " + numbers_array[i].length; 		

		//alert( dispString );	
		//alert ( numbers_array[i] );

		
		if ( numbers_array[i].length != 5 )
			return 1;
			
		//numbers_array[i] = " " + numbers_array[i];		
		//document.getElementById('class_numbers').value = numbers_array[i] + document.getElementById('class_numbers').value;
	}

	return 0;
		
}

function sendPopulationAlert()
{	
	if (document.request_form.blackboard_roster.checked == true)
	{
		alert('Checking the \"...Do NOT want to populate your course automatically\" box means students will not be automatically added into this Blackboard site.\n\nIf you wish IDS to populate your Blackboard site 2 days before the beginning of the semester, un-check the \"...DO NOT want to populate you course automatically\" box and include the class/line numbers for your course.');
	}
	
}

function sendPopAlert()
{
	if (document.recycle_form.populate.checked == true)
	{
		alert('Checking the \"...Do NOT want to populate your course automatically\" box means students will not be automatically added into this Blackboard site.\n\nIf you wish IDS to populate your Blackboard site 2 days before the beginning of the semester, un-check the \"...DO NOT want to populate you course automatically\" box and include the class/line numbers for your course.');
	}
}


function showPreview(inst_id, course_id, course_id_name, course_title, copy_to, populate, inst_comments)
{
	var win2;
	if (!win2.closed){win2.close();}
		
	win2 = window.open("", "preview", "width=400,height=600,scrollbars=no");
	win2.document.writeln(inst_id + " " + course_id + " " + course_id_name + " " + course_title + " " + copy_to + " " + populate + " " + inst_comments);
	win2.focus();
}

function toggle_row(input_id)
{
	
}

function recycleSubmitted(course_id, inst_email, fname, lname, inst_oid)
{
	var win2;
		
	win2 = window.open("", "recyclesubmitted", "width=400,height=200,scrollbars=yes");
	win2.document.body.innerHTML="";
	win2.document.writeln("This course has already been recycled.<br/>If you are teaching this course with " + fname + " " + lname + ", <a href=\"mailto:" + inst_email + "\"" + ">please contact " + fname + " to add you to this course</a>.<br/><br/>If you want your own copy of this course, please <a href=\"mailto:ids@ku.edu?subject=Copy Course " + course_id + " by " + fname + " " + lname + " (" + inst_oid + ")\"> contact IDS</a>.<br/><br/> If you are not using this course site again, no action is necessary.");
	win2.focus();
}

function recycleRestricted(course_id, inst_oid, semester, year)
{
	var win2;
		
	win2 = window.open("", "recyclerestricted", "width=400,height=150,scrollbars=yes");
	win2.document.body.innerHTML="";
	win2.document.writeln("Copying courses is currently disabled for this semester. Your course will NOT be removed. We\'re changing how we manage Blackboard course-sites. Please check back soon for more information.");
		
		
	/*win2.document.writeln("Recycling of this course is restricted until mid " + semester + " " + year + " semester.<br/><a href=\"mailto:ids@ku.edu?body=Update Course " + course_id + " for " + semester + " " + year + " by (" + inst_oid + ")&amp;subject=Update Course " + course_id + " for " + semester + " " + year + " by (" + inst_oid + ")\">Click here to send email to IDS for class numbers or course modifications</a>.");
	*/
	win2.focus();
}

function validate()
{
	// create "timetable streams" hash
	// note that this hash is different than that in
	// the launch_ext function as it does not hold the 
	// sem/year id, but instead it is just used to represent
	// the available time tables
	// the hash is used below to determine whether or not to 
	// notify the user about not entering a line number
	timetable = new Object();
	timetable['Sp07'] = "Yes";
	timetable['Su07'] = "Yes";
	timetable['Fa07'] = "Yes";
	timetable['Sp08'] = "Yes";
	
	var msg1 = "Please enter a valid class number.";
	var msg2 = "Please enter a 5 digit class number."
	var msg3 = "The class line number is important.\\n";
	msg3 = msg3 + "Without the class line number, your course will not be populated with any students.\\n";
	msg3 = msg3 + "Please login at a later time and add it.";

		var lnf = document.recycle_form['class_num'].value;
		var copy_to = document.recycle_form['copy_to'].value;

		var copy_sem = copy_to.substring(0,2);
		var copy_year = copy_to.substring(4,6);

		// convert copy_year from an int to a string
		copy_year = copy_year + '';

		var period = copy_sem + copy_year;


		// empty class numbers are ok, so no need to validate them
		if (lnf)
		{
			// verify class number is of length 5
			if (lnf.length!=5)
			{ alert(msg2); return false; }

			// verify class number is a number
			if (isNaN(lnf))
			{ alert(msg1); return false; }

			// verify class number is an integer
			if (lnf.indexOf(".") >= 0) 
			{ alert(msg1); return false; }
		}

		// however, inform instructor that it will eventually be needed
		// note: if the "Copy To" semester is "Future" then there's no need 
		// to inform the instructor about how important the class number is 
		// because it's most likely not available
		// also, if the time table is not available then also don't alert them
		else if ( (!lnf && (remove_yes == false) && (copy_to != -1) && timetable[period]) ||
			  (remove_yes != false) && (copy_to != 0) )
		{ alert (msg3); return true; }

	return true;
}


// function to lauch external Timetable window
function launch_ext(subject)
{
	//  create "timetable streams" hash
	//  this parameter to the Timetable search engine is used to display the
	//  correct timetable for a specific semester/year
	//  
	//  This timetable link will not work unless the specific semester code is stored below. 
	//  Right now the code is as follows: 4 + year (e.g. 06) + semester code.
	//  Semester codes are Spring: 2 / Summer: 6 / Fall:9
	//  So Fall of '09 would be 4099 (4 + 09 + 9)
	//  Just copy and paste one of the below lines of code and change the value accordingly.

	timetable_streams = new Object();
	timetable_streams['Fa08'] = "4089";
	timetable_streams['Sp09'] = "4092";
	timetable_streams['Su09'] = "4096";
	timetable_streams['Fa09'] = "4099";
	timetable_streams['Sp10'] = "4102";
	timetable_streams['Su10'] = "4106";
	timetable_streams['Fa10'] = "4109";
	
	var copy_to = document.getElementById('copy_to').value;
	//alert(copy_to);
	
	
	if ( copy_to.indexOf(" ") != -1 )
	{
		mySplitResult = copy_to.split(" ");
		var copy_sem = mySplitResult[0].substring(0,2);
		var copy_year = mySplitResult[1].substring(2,4);

		// convert copy_year from an int to a string
		copy_year = copy_year + '';

		var period = copy_sem + copy_year;
	}
	else
	{		
		var period = "Unknown";
	}

	//alert(period);

	// make sure user has selected a semester/year before opening the timetable
	if (copy_to != 0)
	{
	
	/*
		if (period in timetable_streams)
		{
			// currently KU's Timetable displays departments with an "and" in them
			// using an ampersand (&) instead the word "and"
			// for proper functionality replace the "and" in subject with "%26" (escaped equiv)
			subject = subject.replace(/and/gi, '%26'); 

			var url = "http://www.opensections.ku.edu/cgi-bin/run?SUBJECT=" + subject;
			url = url + "&_program=prg.rec001.sas&strm=" + timetable_streams[period];
			url = url + "&CATNBR=&locale=&outtype=HTML&bsttime=&esttime=&bedtime=&eedtime=";
			url = url + "&prscrs=&xref=&acadgrp=&career=&crsd=&rptinst=Y";
			w = window.open(url, "ren_tt_window");
		}

		else
		{ alert("Sorry but the link for this Timetable is currently unavailable"); }
		
		*/
		
		var url = "https://classes.ku.edu/Classes/CourseSearch.action?searchSubject="+subject+"&searchCareer=UndergraduateGraduate&searchTerm="+timetable_streams[period];
		w = window.open(url, "ren_tt_window");
		//timetable_redirection(url);
	}

	// if they've clicked the Timetable link without selecting a semester/year
	// first, alert them and do not open a new window
	else
	{ alert("You must first select a semester/year before trying to view the Timetable."); }
}


function timetable_redirection(url)
{
		OpenWindow=window.open("", "newwin");
		OpenWindow.document.write("<TITLE>Redirecting to opensections.ku.edu...</TITLE>");
		OpenWindow.document.write("<meta http-equiv=\"refresh\" content=\"15;url=" +url+ "\">");
		OpenWindow.document.write("<BODY>");
		OpenWindow.document.write("<center><strong><h3>You are now being redirected to the course schedule web site.<br>The \"Number\" column lists the Class numbers</h3></strong>\
		<h3><a href=\"" +url+ "\">Click to redirect now</a></h3><img border=\"1\" src=\"http://ids.ku.edu/ids_v2_images/classnumbers.jpg\"></center>\
		</BODY></HTML>");
		OpenWindow.document.close();
}


function verify_request_class_numbers(numbers_array){
	/* this function will return 1 if any of the class numbers are less than 5 digits */
	
	var num_elements = numbers_array.length-1;
		
	for ( var i = 0; i <= num_elements; i++ )
	{
		//alert(numbers_array[i]);
		
		if ( (numbers_array[i].length != 0) && (numbers_array[i].length != 5) )
		{
			return 1;
		}
	}
	return 0;
}


function checkCrossListedClassNumber(classnumbers)
{
	var incorrect_message = "One or more of your class numbers is not 5 digits.\nPlease verify that commas are placed correctly and submit again.";
	if ( classnumbers.indexOf(",") != -1 )
		{				
			classnumbers = classnumbers.replace(/\s/g, "" );
					
			if (classnumbers.charAt(classnumbers.length-1) == "," )
				classnumbers = classnumbers.substr(0, classnumbers.length - 1);
			
			classnumbers = classnumbers.replace(/\,/g, ", " );
			var class_numbers_array = classnumbers.split(", ");
		}
	else
		{
			var class_numbers_array = classnumbers.split(" ");
		}
	
	if ( class_numbers_array.length >= 1 )
		{
			if (verify_request_class_numbers(class_numbers_array) == 1)
				{
					alert(incorrect_message);
					return "invalid";
				}
		}
		
	return "valid";
}

function checkElement(elementname, elementdescription)
{
	if (elementname.length < 2 )
	{
		alert(elementdescription);
		return 1;
	}
	
	return 0;
}

function checkCrossListedFields(rownumber)
{
	var dept_id = 'crosslist_dept' + rownumber;
	var course_id = 'crosslist_course' + rownumber;
	var classnumber_id = 'crosslist_classnum' + rownumber;
	var department = document.getElementById(dept_id).value;
	var course = document.getElementById(course_id).value;
	var classnumber = document.getElementById(classnumber_id).value;

	if (checkElement(department, "Please select a department for all cross-listings.")){return "invalid";}
	if (checkElement(course, "Please enter a course number for all courses.")){return "invalid";}
	
	return "valid";
}


function checkRequestForm()
{
	var course_title = document.getElementById('course_request_title').value;
	var copy_to = document.getElementById('copy_to').value;
	var crosslisted = getCheckedValue(document.forms['request_form'].elements['crosslisted']);
	var error="";

	if (checkElement(copy_to, "Please select a semester for your course.")){return;}
	if (checkElement(course_title, "Please enter a course title.")){return;}
	
	if (crosslisted == 'yes')
	{ 
		var num_crosslistings = document.getElementById('crosslistings').value;
		
		//alert(num_crosslistings);
		
	 }
	else
	{
		var dept = document.getElementById('dept1').value;
		var course = document.getElementById('course1').value;
		
		if (checkElement(dept, "Please select a department.")){ error="error"; return; }
		if (checkElement(course, "Please enter a course number.")){ error="error"; return; }
		
	}

	 if (error == "error")
	 {
	 	//
	 }
	 else
	 {
	 	document.request_form.submit();
	 }
}

function checkRestrictedRecycleForm()
{

	var class_numbers = '';
	var inst_comments = document.getElementById('inst_comments').value;	
	var incorrect_message = "One or more of your class numbers is not 5 digits.\nPlease verify that commas are placed correctly and submit again.";
	
	/*  check COPY TO, make sure that a value is selected */
	/*  verify that class numbers are separated by commas or spaces */
	/*  run some sort of delimiter function that separates the numbers 
	
	
	var sentence="Hi, my name is George!"
	if (sentence.indexOf("George")!=-1)
	alert("George is in there!")

	*/


	class_numbers = document.getElementById('class_numbers').value;
	
	if ( class_numbers.indexOf(",") != -1 )
		{				
			// if there are some commas found, then make all delimiters commas
			// in other words, convert any spaces to commas first, then
			// run the delimter function
	
			//alert("Using commas!");
			
			class_numbers = class_numbers.replace(/\s/g, "" );

			//alert(class_numbers + "  length:" + class_numbers.length + " length-1:" + class_numbers.charAt(class_numbers.length-1) );
			
			if (class_numbers.charAt(class_numbers.length-1) == "," )
				class_numbers = class_numbers.substr(0, class_numbers.length-1);

			
			class_numbers = class_numbers.replace(/\,/g, ", " );
			document.getElementById('class_numbers').value = class_numbers;	
			var class_numbers_array = class_numbers.split(", ");
			
			//alert(class_numbers);
		}
	else
		{
			//alert("Not using commas!");
			var class_numbers_array = class_numbers.split(" ");
		}
	
	if ( class_numbers_array.length >= 1 )
		{
			if (verify_request_class_numbers(class_numbers_array) == 1)
				{
					alert(incorrect_message);
					return;
					
					// alert ( class_numbers_array );
				}
		}
	document.recycle_form.submit();

	//showPreview(inst_id, course_id, course_id_name, course_title, copy_to, class_numbers, populate, inst_comments);
} //checkRequired

function checkModifyRequestForm()
{
	var course_title = document.getElementById('course_request_title').value;
	var copy_to = document.getElementById('copy_to').value;
	var error="";

	if (checkElement(copy_to, "Please select a semester for your course.")){return;}
	if (checkElement(course_title, "Please enter a course title.")){return;}
	
	var courseid = document.getElementById('course_id').value;
		
		if (checkElement(courseid, "Please select a department.")){ error="error"; return; }
		
	 if (error == "error")
	 {
	 	//
	 }
	 else
	 {
	 	document.modify_request_form.submit();
	 }
}
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

/*function checkClassNumbers()
{

	var incorrect_message = "One or more of your class numbers is not 5 digits.\nPlease verify that commas are placed correctly and submit again.";
	class_numbers = document.getElementById('class_numbers').value;
	
	if ( class_numbers.indexOf(",") != -1 )
	{				
			// if there are some commas found, then make all delimiters commas
			// in other words, convert any spaces to commas first, then
			// run the delimter function
	
			//alert("Using commas!");
			
			class_numbers = class_numbers.replace(/\s/g, "" );

			//alert(class_numbers + "  length:" + class_numbers.length + " length-1:" + class_numbers.charAt(class_numbers.length-1) );
			
			if (class_numbers.charAt(class_numbers.length-1) == "," )
				class_numbers = class_numbers.substr(0, class_numbers.length-1);

			
			class_numbers = class_numbers.replace(/\,/g, ", " );
			document.getElementById('class_numbers').value = class_numbers;	
			var class_numbers_array = class_numbers.split(", ");
			
			//alert(class_numbers);
	}
	else
	{
			//alert("Not using commas!");
			var class_numbers_array = class_numbers.split(" ");
	}
	
	if ( class_numbers_array.length >= 1 )
	{
			if (verify_request_class_numbers(class_numbers_array) == 1)
				{
					alert(incorrect_message);
					return;
				}
	}

	document.class_form.submit();


}*/

function checkRecycleForm()
{
	var copy_to = document.getElementById('copy_to').value;
	var class_numbers = '';
	var inst_id = document.getElementById('inst_id').value;
	var course_id = document.getElementById('course_id').value;
	var populate = document.getElementById('populate').value;
	var inst_comments = document.getElementById('inst_comments').value;	
	var course_title = document.getElementById('course_title').value;	
	var course_id_name = document.getElementById('course_id_name').value;	
	var incorrect_message = "One or more of your class numbers is not 5 digits.\nPlease verify that commas are placed correctly and submit again.";
	
	/*  check COPY TO, make sure that a value is selected */
	/*  verify that class numbers are separated by commas or spaces */
	/*  run some sort of delimiter function that separates the numbers 
	
	
	var sentence="Hi, my name is George!"
	if (sentence.indexOf("George")!=-1)
	alert("George is in there!")

	*/


	class_numbers = document.getElementById('class_numbers').value;
	
	if (!copy_to){
		alert("Please select a Copy To semester.");
		return false;	
	}
		
	if ( class_numbers.indexOf(",") != -1 )
		{				
			// if there are some commas found, then make all delimiters commas
			// in other words, convert any spaces to commas first, then
			// run the delimter function
	
			//alert("Using commas!");
			
			class_numbers = class_numbers.replace(/\s/g, "" );

			//alert(class_numbers + "  length:" + class_numbers.length + " length-1:" + class_numbers.charAt(class_numbers.length-1) );
			
			if (class_numbers.charAt(class_numbers.length-1) == "," )
				class_numbers = class_numbers.substr(0, class_numbers.length-1);

			
			class_numbers = class_numbers.replace(/\,/g, ", " );
			document.getElementById('class_numbers').value = class_numbers;	
			var class_numbers_array = class_numbers.split(", ");
			
			//alert(class_numbers);
		}
	else
		{
			//alert("Not using commas!");
			var class_numbers_array = class_numbers.split(" ");
		}
	
	if ( class_numbers_array.length >= 1 )
		{
			if (verify_request_class_numbers(class_numbers_array) == 1)
				{
					alert(incorrect_message);
					return;
					
					// alert ( class_numbers_array );
				}
		}
	document.recycle_form.submit();

	//showPreview(inst_id, course_id, course_id_name, course_title, copy_to, class_numbers, populate, inst_comments);
} //checkRequired


function go_home()
{
   top.location.href = "http://ids.ku.edu/" ;
}

function checkOnlineID()
{
	var strng = '';
	strng = document.req_portal_form.online_id.value;
	strng = strng.toLowerCase();

	// KU users
	var idFilter1 = /\@ku.edu/;

	// Other users (Exceptional Accounts)
	var idFilter2 = /^_/;

	var error = "";

	// if user doesn't enter an Online ID
	if (strng == "")
	{ error = "You didn't enter an Online ID."; }
	
	

	// make sure user has entered a valid Online ID
	if (!idFilter1.test(strng) && !idFilter2.test(strng) && (strng != ""))	{
		 var newstrng = strng.replace(/\s/g, "" );
		 document.req_portal_form.online_id.value = newstrng + "@ku.edu";
	}

	if (error)
	{alert(error);return false;}
}

function hov(loc,cls)
{
	if(loc.className)
		loc.className=cls;
}

