// This file is for the general purpose javascript functions

/************************************************
*
*	In-Page Tabs
*
************************************************/
function js_tabs(group,section) {
	if(document.getElementById(group)) {
		var all_divs = document.getElementById(group).getElementsByTagName("div");
		var tabs_count = all_divs.length;
		var i = 0;
		while(i<tabs_count) {
			if(all_divs[i].id.indexOf('js_tab') >= 0) {
				var pieces = all_divs[i].id.split('js_tab_');
				document.getElementById("js_tab_title_"+pieces[1]).style.backgroundColor = "#eeeeee";
				document.getElementById("js_tab_title_"+pieces[1]).style.borderBottom = "1px solid grey";
				document.getElementById("js_tab_"+pieces[1]).style.display = "none";
			}
			i++;
		}
		document.getElementById("js_tab_title_"+section).style.backgroundColor = "#ffffff";
		document.getElementById("js_tab_title_"+section).style.borderBottom = "none";
		document.getElementById("js_tab_"+section).style.display = "";
	}
}

/************************************************
*
*	Dynamic Loading Multiple Drop Down Boxes
*
************************************************/
function dynamic_dropdown(options,val,second_dropdown) {
	var len = options.length;
	if(options.length == 0) { return; }
/*	if(!document.getElementById(second_dropdown)) { return; }*/
	var drop_down = document.getElementById(second_dropdown);
	drop_down.style.display = "block";
	drop_down.options.length = 0;
	drop_down.options[drop_down.options.length] = new Option("-Select Option-","");
	var i = 0;
	while(i < len) {
		/*if(options[i][0] == val) {*/
			drop_down.options[drop_down.options.length] = new Option(options[i][1],options[i][2]);
		/*}*/
		i++;
	}
}


/************************************************
*
*	Slug Maker
*
************************************************/
function create_alias(val) {
	alias = val.toLowerCase();
	alias = alias.replace(/\s+/g, "-");
	alias = alias.replace(/-[-]+/g, "-");
	alias = alias.replace(/\&amp\;/g, "and");
	alias = alias.replace(/\&/gi, "and");
	alias = alias.replace(/[^a-zA-Z0-9 -]/g, "");
	alias = alias.replace(/^[\-]/, "");
	alias = alias.replace(/[\-]$/, "");
	return alias;
}

function create_new_alias(location,value) {
	if(document.getElementById(location) && document.getElementById(location).value == "") {
		document.getElementById(location).value = create_alias(value);
	}
}


/************************************************
*
*	5 Star Ranking
*
************************************************/
function five_star_ranking(val) {
	if(val == 0) { return; }
	var i = 1;
	var rating_text = new Array('','Poor','Fair','Average','Good','Excellent');
	//var rating_text = new Array('','Fair','Decent','Good','Excellent','Amazing');
	while(i <= 5) {
		if(document.getElementById('ranking_star_'+ i)) {
			document.getElementById('ranking_star_'+ i).src = (i <= val ? '/images/star_full.gif' : '/images/star_empty.gif');
		}
		i++;
	}
	document.getElementById('ranking_stars').value = val;
	document.getElementById('ranking_text').innerHTML = rating_text[val];
}