function Highlight(target,yesno) {
	clr = "ffffff";
	if (yesno) clr="c0c0c0";
	obj=sched.rows.item('c'+target);
	obj = document.getElementById('c'+target);
	obj.style.backgroundColor = '#'+clr;
	obj.bgColor = clr;
	obj=cal.rows.item('d'+target);
	obj = document.getElementById('d'+target);
	obj.bgColor = clr;
	obj.style.backgroundColor = '#'+clr;
}

function locHighlight(target,yesno) {
	clr = "ffffff";
	if (yesno) clr="ffff80";
	obj=loc.rows.item(target);
	obj.bgColor = clr;
}

/* tool tip processing */
function ActivateTips() {
	alist = $$(".tip");
	for (var i=0; i<alist.length; i++) {
		alist[i].addClassName("tip_ready");
		alist[i].on('click', 'img', Element.addClassName('warning'));
	}
}

/* set focus on first editable field in the form */
function placeFocus(max_tab) {
	done = false;
	if (typeof(max_tab) == 'undefined') max_tab = 10000;
	for (f=0; f<document.forms.length; f++) {
		if (document.forms[f].id == 'schfrm') continue;
		for (i=0; i<document.forms[f].elements.length; i++) {
			e = document.forms[f].elements[i];
			if (document.forms[f].elements[i].name == 'sch') continue;
			if (max_tab && (e.tabIndex > max_tab)) continue;
			if (!isVisible(e)) continue;
			if (e.readOnly || e.disabled) continue;
			if ((e.type == "text") || (e.type == "textarea") || (e.type.toString().charAt(0) == "s")) {
				try {
					e.focus();
					done = true;
					break;
				} catch (er) {
				}
			}
		}
		if (done) break;
	}
	if (!done && max_tab) placeFocus(0);
}

function isVisible(e) {
	//returns true if it should be visible to user
	if (typeof(e) == "string") e = $(e);

	while (e.nodeName.toLowerCase() != 'body' && e.style.display.toLowerCase() != 'none' && e.style.visibility.toLowerCase() != 'hidden') {
		e = e.parentNode;
	}

	if (e.nodeName.toLowerCase() == 'body') return true;
	else return false;
}

function CancelPolicy() {
	win = window.open ('/training/Cancellation.html','CancellationPolicy','width=500,height=400');
}

function add_toc() {
	var hdrs = $$('#top h2');
	var i;
	var lnks = '';
	var toc = document.getElementById('toc');
	var gotop = '<div class="top"><a href="#top">Return to top</a></div>';
	var objTop;

	if (!hdrs.length) return;
	if (!toc) return;

	for (i=0; i<hdrs.length; i++) {
		ttl = hdrs[i].innerHTML;
		hdrs[i].innerHTML = '<a name="toc_' + i + '"></a>' + ttl;
		lnks = lnks + '<a href="#toc_' + i + '">' + ttl + '</a><br />';

		if (!i) continue;

		objTop = document.createElement('div');
		objTop.className = 'top';
		objTop.innerHTML = '<a href="#top">Return to top</a>';
		//newTxt = document.createTextNode('<a href="#top">Return to top</a>');
		//objTop.appendChild (newTxt);
		hdrs[i].parentNode.insertBefore (objTop, hdrs[i]);
	}

	toc.innerHTML = '<p>' + lnks + '</p>';
}

function add_toc_old() {
	var hdrs = document.getElementsByTagName('h2');
	var i;
	var lnks = '';
	var toc = document.getElementById('toc');
	var gotop = '<div class="top"><a href="#top">Return to top</a></div>';
	var objTop;

	if (!hdrs.length) return;
	if (!toc) return;

	for (i=0; i<hdrs.length; i++) {
		ttl = hdrs[i].innerHTML;
		hdrs[i].innerHTML = '<a name="toc_' + i + '"></a>' + ttl;
		lnks = lnks + '<a href="#toc_' + i + '">' + ttl + '</a><br />';

		if (!i) continue;

		objTop = document.createElement('div');
		objTop.className = 'top';
		objTop.innerHTML = '<a href="#top">Return to top</a>';
		//newTxt = document.createTextNode('<a href="#top">Return to top</a>');
		//objTop.appendChild (newTxt);
		hdrs[i].parentNode.insertBefore (objTop, hdrs[i]);
	}

	toc.innerHTML = '<p>' + lnks + '</p>';
}

my_search = false;
function search_out() {
	if (($('sch').getValue() == '') || ($('sch').getValue() == 'Search')) {
		$('sch').addClassName('empty');
		$('sch').setValue('Search');
		my_search = true;
	}
}
function search_in() {
	$('sch').removeClassName('empty');
	if (my_search) {
		my_search = false;
		$('sch').setValue('');
	}
}

//function local_init() {}

function page_init() {
	sfHover = function() {
		var sfEls = $$('.nav li');
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() { this.className+=" sfhover"; }
			sfEls[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); }
		}
	}
	if (window.attachEvent) window.attachEvent("onload", sfHover);

	search_out();
	if ($('pgloaded').getValue() != 'done') {
		placeFocus();
//		local_init();
	}
	$('pgloaded').setValue('done');
}

function Set_Cookie (name, value, expires, path, domain, secure) {
	var today = new Date();
	today.setTime( today.getTime() );

if (expires) expires = expires * 1000 * 60 * 60 * 24;

var expires_date = new Date (today.getTime() + expires);

document.cookie = name + "=" +escape( value ) +
	((expires) ? ";expires=" + expires_date.toGMTString() : "" ) +
	((path) ? ";path=" + path : "" ) +
	((domain) ? ";domain=" + domain : "" ) +
	((secure) ? ";secure" : "" );
}

function Get_Cookie (check_name) {
	var a_all_cookies = document.cookie.split (';');
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;

	for (i=0; i<a_all_cookies.length; i++) {
		a_temp_cookie = a_all_cookies[i].split( '=' );

		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		if (cookie_name == check_name) {
			b_cookie_found = true;
			if (a_temp_cookie.length > 1) cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );

			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if (!b_cookie_found) return null;
}

function Get_Cookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if (!start && (name != document.cookie.substring( 0, name.length ))) return null;
	if (start == -1) return null;
	var end = document.cookie.indexOf( ";", len );
	if (end == -1) end = document.cookie.length;
	return unescape (document.cookie.substring (len, end));
}

function Delete_Cookie( name, path, domain ) {
	if (Get_Cookie (name)) document.cookie = name + "=" +
		(path ? ";path=" + path : "") +
		(domain ? ";domain=" + domain : "") +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

