// cms_script.js
// Javascript functions for the Baylor CMS
// Initial: Colin W., 8/3/03
// Modified: Colin W., 10/21/03, to add focus()
// Modified: Colin W., 05/07/04, to add width and height handling
// Modified: Jerry K., Fall 2005, to add toggleVisible function
// Modified: Colin W., 05/05/06, to add quicklinks_jumpto function
// Modified: Colin W., 01/08/09, to add include_js function - now we can include other JS files from within JS, and it puts them in the head in the DOM

function popup_window(url,width,height)
	{
	var x = width;
	var y = height;
	if (!x) x = 525;
	if (!y) y = 500;
	var w = window.open(url,'','personalbar=no,scrollbars=yes,resizable=yes,toolbar=no,height='+y+',width='+x+'');
	w.focus();
	}

// This function is used by the resource form calendar control
function toggleVisible(elemVis, elemHide) {
  var e1 = document.getElementById(elemVis);
  var e2 = document.getElementById(elemHide);
  if( e1 ) {
    e1.style.display = 'block';
  }
  if( e2 ) {
    e2.style.display = 'none';
  }
}

// This is for the quicklinks navigation style, for cases where we do not want a "GO" button
function quicklinks_jumpto(form, name) {
	var myindex= eval('form.'+ name + '.selectedIndex');
    var myval=eval('form.' + name + '.options[myindex].value');
    eval('form.'+ name + '.selectedIndex = 0');
	if (myval != "") {
        if (myval.indexOf("http://") != -1) {
	        location.href=myval;
        } else {
	        location.href=myval;
        }
    }
}

function include_js(script_filename) {
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);
    return false;
}
