function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function blurLink() {

}

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}
function no_map() {
	var e = document.getElementById('map_showing');
	if (e!=undefined) e.className = 'invisible';
	var f = document.getElementById('map_hidden');
	if (f!=undefined) f.className = 'visible';
	var g = document.getElementById('show_map');
	if (g!=undefined) g.className = 'visible show_map';
	var h = document.getElementById('map');
	if (h!=undefined) h.setAttribute("width","7");
	if (h!=undefined) h.setAttribute("background","/fileadmin/template/vudat/images/no_map_right_edge.gif");
	return false;
}
function map() {
	var e = document.getElementById('map_hidden');
	if (e!=undefined) e.className = 'invisible';
	var f = document.getElementById('map_showing');
	if (f!=undefined) f.className = 'visible';
	var g = document.getElementById('show_map');
	if (g!=undefined) g.className = 'invisible show_map';
	var h = document.getElementById('map');
	if (h!=undefined) h.setAttribute("width","218");
	if (h!=undefined) h.setAttribute("background","/fileadmin/template/vudat/images/map_bg.gif");
	return false;
}
function cloud() {
	var e = document.getElementById('the_cloud');
	if (e!=undefined) e.className = 'cloud';
	var f = document.getElementById('the_cloud_option');
	if (f!=undefined) f.className = 'un_link';
	var g = document.getElementById('the_list_option');
	if (g!=undefined) g.className = '';
}
function list() {
	var e = document.getElementById('the_cloud');
	if (e!=undefined) e.className = 'list';
	var f = document.getElementById('the_cloud_option');
	if (f!=undefined) f.className = '';
	var g = document.getElementById('the_list_option');
	if (g!=undefined) g.className = 'un_link';
}
function loadMap() {
	if (readCookie('vuDAT_map')=='hide') {
		no_map();
		//alert('no_map');
		eraseCookie('vuDAT_map');
		createCookie('vuDAT_map','hide','30');
	} else {
		map();
		//alert('map');
		eraseCookie('vuDAT_map');
		createCookie('vuDAT_map','show','30');
	}
}

function loadCloud() {
	if (readCookie('vuDAT_cloud')=='cloud') {
		cloud();
		//alert('no_map');
		eraseCookie('vuDAT_cloud');
		createCookie('vuDAT_cloud','cloud','30');
	} else {
		list();
		//alert('map');
		eraseCookie('vuDAT_cloud');
		createCookie('vuDAT_cloud','list','30');
	}
}

/* Function so IE doesn't display active X control approval dialog */
function embed_map(location) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ');
	document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="207" height="335" title="Developing An Online Course">');
	document.write('<param name="movie" value="fileadmin/template/vudat/media/teachonline_map.swf?id='+location+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="#E5F3B8" />');
	document.write('<embed src="fileadmin/template/vudat/media/teachonline_map.swf?id='+location+'" ');
	document.write('quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" ');
	document.write('type="application/x-shockwave-flash" width="207" height="335" bgcolor="#E5F3B8"></embed></object>');
}

function toggle(i) {
	var e = document.getElementById(i);
	if (e!=undefined) {
		var t = e.className;
		if (t.match('invisible')) { t = t.replace(/invisible/gi, 'visible'); }
		else { t = t.replace(/visible/gi, 'invisible'); }
		e.className = t;
	}
}

/* Toggles state of all matching elements */
function t_name(baseName,howMany) {
	var e
	var t
	for (var n = 1; n < howMany+1; n++)  {
		e = document.getElementById(baseName + n);
		if (e!=undefined) {
			t = e.className;
			if (t.match('invisible')) { 
				t = t.replace(/invisible/gi, 'visible'); 
			} else { 
				t = t.replace(/visible/gi, 'invisible'); 
			}
			e.className = t;
		}
	}
}

function t_off(i) {
	var e = document.getElementById(i);
	if (e!=undefined) {
		var t = e.className;
		if (t=='visible') { 
			t = 'invisible'; 
		}
		e.className = t;
	}
}

/*
function t_on(i) {
	var e = document.getElementById(i);
	if (e!=undefined) {
		var t = e.className;
		if (t.match('invisible')) { 
			t = t.replace(/invisible/gi, 'visible'); 
		}
		e.className = t;
	}
}
*/

function t_on(i) {
	var e = document.getElementById(i);
	if (e!=undefined) {
		var t = e.className;
		if (t=='invisible') { 
			t = 'visible'; 
		}
		e.className = t;
	}
}

/* Hides all matching elements */
function t_all_off(baseName,howMany) {
	for (var n = 0; n < howMany+1; n++)  {
		t_off(baseName + n);
		t_off(baseName + n + 'plus');
		t_on(baseName + n + 'minus');
		classify_it(baseName + 'rh_' + n,'rh_p');
	}
}

/* Shows all matching elements */
function t_all_on(baseName,howMany) {
	for (var n = 0; n < howMany+1; n++)  {
		t_on(baseName + n);
		t_on(baseName + n + 'plus');
		t_off(baseName + n + 'minus');
		classify_it(baseName + 'rh_' + n,'rh_m');
	} 
}

/* Sets element to passed class name */
function classify_it(elementID,className) {
	var e = document.getElementById(elementID);
	if (e!=undefined) {
		e.className = className;
	}
}

/* toggle between the two class names passed */
function t(elementID,classOne,classTwo) {
	var e = document.getElementById(elementID);
	if (e!=undefined) {
		var t = e.className;
		if(t==classOne) {
			e.className = classTwo;
		} else {
			e.className = classOne;
		}
	}
}

function alternate(id){
	if(document.getElementsByTagName){  
		var table = document.getElementById(id);
		if(table){
			var rows = table.getElementsByTagName("tr");  
			for(i = 0; i < rows.length; i++){          
				//manipulate rows
				if(i % 2 == 0){
					rows[i].className = "even";
				} else {
					rows[i].className = "odd";
				}      
			}
		}
	}
}
