/* Javascript functions for all of public acalog site. */

/* GENERAL pup up window function */
function popup(URL, NAME, WIDTH, HEIGHT, SCROLL) {
	//	Get width and height for IE.
	if (screen.height) {
		LEFT = (screen.width - WIDTH) / 2;
		TOP = (screen.height - HEIGHT) / 2;
	} else {
		LEFT = (screen.availWidth - WIDTH) / 2;
		TOP = (screen.availHeight - HEIGHT) / 2;
	}
	popupWindow = window.open(URL,NAME,'height='+HEIGHT+',width='+WIDTH+',resizable=yes,scrollbars='+SCROLL+',menubar=no,toolbar=no,personalbar=no,statusbar=no,locationbar=no,screenX='+LEFT+',screenY='+TOP+',left='+LEFT+',top='+TOP);
	popupWindow.focus();
}

/* PRINT LINK capability testing and window pop function for popup print links. */
function print_link_popup(URL, NAME, WIDTH, HEIGHT, SCROLL) {
	if (!window.print) {
		URL ="help.php#print_link";
	}
	popup(URL,NAME,WIDTH,HEIGHT,SCROLL);
}

/* PRINT LINK capability testing and window pop function for non-popup print links. */
function print_link_nopop() {
	if (window.print) {
		window.print();
	} else {
		popup('help.php#print_link','help',600,470,'yes');
	}
}

/* Close popup and change location of popup opener. */
function redirect_opener(LOCATION) {
	window.close();
	window.opener.location = LOCATION;
}

/* Fix links within description data. */
function fix_link(URL) {
	document.location.href=URL;
}
function fix_link_popup(URL) {
	popup(URL, 'temp', 600, 470, 'yes');
}

/*	The following functions are used to show/hide information in complex filter links.	*/

//	Display the formatted Display/Hide link.
//	@param	id_name		- The ID name of the DIV to display/hide must always start with "data".
//	@param	link_copy	- The information to be displayed/hidden such as "Programs" or "Courses".
//	@return	nothing
function showlink(id_name, link_copy) {
	if (document.getElementById) {
		document.write("<a href=\"javascript:hideshow('"+id_name+"')\"><span id=\"link"+id_name.substring(4)+"\">Display</span> "+link_copy+"</a>");
	}
}

//	Displays or hides the selected DIV and changes the Display/Hide link to say "Display" or "Hide" as appropriate.
//	@param	div_id	- The DIV id to display/hide.
//	@return	nothing
function hideshow(div_id) {
	if (document.getElementById) {
		dataobj = document.getElementById(div_id);
		linkobj = document.getElementById("link"+div_id.substring(4));
		if (dataobj.style.display=="none") {
			dataobj.style.display="";
			linkobj.innerHTML = "Hide";
		} else {
			dataobj.style.display="none";
			linkobj.innerHTML = "Display";
		}
	}
}

/*	in_portfolio is actually the current catalog oid and, if present, denotes that the course is being displayed in the portfolio
	is_archive denotes if the catalog is an archived catalog when showing courses in the portfolio.
	if show_program_display_field is 1, then display the program display text after a course (usually credits) */
function hideCourse(catalog, course, activator, display_options)
{
	params = "catoid=" +catalog+ "&coid=" +course+ "&display_options=" +display_options+ "&hide";
	window.ajax = new Ajax.Request('http://www.catalogs.ohio.edu/ajax/preview_course.php', { method: 'get', parameters: params, onComplete: showData} );
	node = activator.parentNode;
	activator.parentNode.innerHTML = activator.parentNode.innerHTML + '<p style="text-align: center;"><img src="http://www.catalogs.ohio.edu/loading.gif" alt="" style="width: 16px; height: 16px;" /></p>';
	window.ajax.activator = node;
}

/*	in_portfolio is actually the current catalog oid and, if present, denotes that the course is being displayed in the portfolio
	is_archive denotes if the catalog is an archived catalog when showing courses in the portfolio.
	if show_program_display_field is 1, then display the program display text after a course (usually credits) */
function showCourse(catalog, course, activator, display_options)
{
	try {
		params = "catoid=" +catalog+ "&coid=" +course+ "&display_options=" +display_options+ "&show";
		window.ajax = new Ajax.Updater(activator.parentNode, 'http://www.catalogs.ohio.edu/ajax/preview_course.php', { method: 'get', parameters: params} );
		node = activator.parentNode;
		activator.parentNode.innerHTML = activator.parentNode.innerHTML + '<p style="text-align: center;"><img src="http://www.catalogs.ohio.edu/loading.gif" alt="" style="width: 16px; height: 16px;" /></p>';
		window.ajax.activator = node;
	} catch (e) {
		popup('preview_course.php?catoid=' +catalog+ '&coid=' +course,'preview_course',600,325,'yes');
	}
}

function showData(request)
{
	node = window.ajax.activator.innerHTML = request.responseText;
}