function ucfirst(word){
	fstLetter = word.substr(0,1);
	rest = word.substr(1, word.length);
	fstLetter = fstLetter.toUpperCase();
	return fstLetter + rest;
}

document.getElementsByIdMatch = function(regex, tagname){
	var elems = document.getElementsByTagName(tagname)
	var matches = new Array();
	for(i=0; i<elems.length; i++){
		if(elems[i].id.search(regex) != -1) matches.push(elems[i]);
	}
	return matches;
}

function hide_all(){
	var divs = document.getElementsByTagName('div');
	var matches = document.getElementsByIdMatch(/^Course/, 'div');
	for(i=0; i<matches.length; i++)
		matches[i].style.display = "none";
}

function show_elem(id){
	document.getElementById(id).style.display = "block";
}

function hide_elem(id){
	document.getElementById(id).style.display = "none";
}



/* Course Class */
function Course(id){
	this.id = id;
	this.namespace = "Course" + this.id;	//Course name is product ID.
	this.descId = this.namespace + "Desc";
	this.syllId = this.namespace + "Syllabus";
	this.costId = this.namespace + "Cost";
	
	this.hideTabs = function(){
		// Get all elements whose IDs extend the this.namespace namespace.
		regex = new RegExp("^" + this.namespace + "[^$]+");
		matches = document.getElementsByIdMatch(regex, 'div');
		for(i in matches) matches[i].style.display = "none";		
		regex = new RegExp("^" + this.namespace + "[a-zA-Z]+"+"Tab$");
		matches = document.getElementsByIdMatch(regex, 'li');
		for(i in matches) matches[i].className = "inactive";		
	}
	
	this.showTab = function(tabname) {
		show_elem(this.namespace + ucfirst(tabname));
	}

	this.raiseTab = function(tabname){
		this.hideTabs();
		document.getElementById(this.namespace + tabname + "Tab").className = "active";
		show_elem(this.namespace + "Banner");
		this.showTab(tabname);
	}
}

var course;

function course_init(){
  //hide_all();
  hide_elem('CourseInit');
  course = new Course(productid);
  course.hideTabs();
  course.raiseTab('Desc');
  show_elem('Course' + productid);
}

function show_course(id){
	course = new Course(id);
	hide_all();
	show_elem(course.namespace);
	show_elem(course.namespace + "Desc");
	//Swap flash holder for course banner
	//document.getElementById('flashHolder').style.display = "none";
	document.getElementById(course.namespace + "Banner").style.display = "block";
	document.getElementById(course.namespace + "DescTab").style.height = "5px";
	event.srcElement.className = "subActive";
}
