/** Used to show/collapse the divs and arrow images */

function show_or_hide_filter(arrow_img, collapsable) {
		
	var arrow = document.getElementById(arrow_img)
	var el = document.getElementById(collapsable);
	if ( el.style.display != 'none' ) {
		// switch to right-pointing arrow
		arrow.src='images/collapse_arrow_right.gif';
	}
	else {
		// switch to down-pointing arrow
		arrow.src='images/collapse_arrow_down.gif';
	}
	
	show_hide_by_id(collapsable);
	
}

	
/** Shows or hides a div with a certain id. */
function show_hide_by_id(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
	el.style.display = 'none';
	}
	else {
	el.style.display = '';
	}
}

/** Shows or hides a div with a certain id. */
function show_hide_by_id_arr(arr) {
	for (var i = 0; i < arr.length; i++) {
		var el = document.getElementById(arr[i]);
		if ( el.style.display != 'none' ) {
			el.style.display = 'none';
		}
		else {
			el.style.display = '';
		}
	}
}

/** Shows or hides a div with a certain class. 
Used in omdomen.html */
function show_hide_by_class(class_name, container_type) {
	var box = document.getElementById(class_name+'_showhide_box');
	
	var selector = "." + class_name;
	
	if (container_type != "") {
		selector = container_type + selector;
	}
		
	if (box.checked) {
		$(selector).show();
	} else {
		$(selector).hide();
	}
	
}

/* shows the "annat" fields if necessary */
function showhideAnnatfields() {
	var el = document.getElementById('annatFields');
	//var val = document.forms['omdome_form'].system_id.value;
	var val = document.forms['omdome_form'].elements['system_id'].value;
	if (val == 0 || val == null) {
		el.style.display = 'block';
	}
	else {
		el.style.display = 'none';
	}
}

/* shows the element if fieldName has value = 0 */
function showIfNeeded(element_ID, field_name, form_name, dispStyle) {
	var el = document.getElementById(element_ID);
	var val = document.forms[form_name].elements[field_name].value;
	dispStyle = dispStyle || 'block'; //if null, set to 'block'
	if (val == 0 || val == null) {
		try{
			el.style.display = dispStyle; //IE throws error when setting unsupported styles like 'table'	
		}
		catch(theError){
			el.style.display = 'block';
		}
	}
	else {
		el.style.display = 'none';
	}
}

/* Changes the appearance of the selected tab in the navigation tabrow */
function setSelectedTab(tabName) {

	// Restore the CSS classes of all tabs to unselected state
	/*
	var allTabs = [];
	allTabs[0] = "listning";
	allTabs[1] = "omdomen"
	
	for(var i = 0; i < allTabs.length; i++) {
		$("#tab_" + allTabs[i]).removeClass('tab_selected');
	}
	*/
	
	//remove the 'tab_selected' class from all tabs
	$("table.table_tab td.tab_center a").removeClass('tab_selected');
	
	//delete the tabName + '_fade' class
	$("#cellbelowtabs").attr('class', 'cell_fade none_fade');
	
	if(tabName != '') {
		$("#tab_" + tabName).addClass('tab_selected');
	
		// Change the gradient bar below the tab to use the same color as the tab.
		// This is done by adding the CSS class "[tabName]_fade" to the fade area.
		
		$("#cellbelowtabs").attr('class', 'cell_fade ' + tabName + '_fade');
	}
	
}


/** Changes the "visar x av y" number based on how many rows are hidden in the <tbody> section of a <table id="table_count_id">. */
/*
function updateNumOfSystems(div_to_update, table_to_count_id) {
	var div_to_update = document.getElementById(div_to_update);
	var table_to_count = document.getElementById(table_to_count_id);
	var count = 0;
	for (var i = 0; i < table_to_count.tBodies[0].rows.length; i++) {
		if (table_to_count.tBodies[0].rows[i].style.display != 'none') {
			count++;
		}
	}
	div_to_update.innerHTML = count;
	
}
*/

/* http://www.dynamicdrive.com/forums/showthread.php?t=11883&page=3 */
function getQueryValue(name) {
    var match = (new RegExp('[?&;]' + name + '=([^&;#]*)')).exec(document.URL);

    return match ? unescape(match[1]) : null;
}



/* -------------------------------------------------------------- */
/* From http://domscripting.com/presentations/atmedia2006/slides/
Make striped columns
*/


function addClass(element,name) {
  if (!element.className) {
    element.className = name;
  } 
	/*
	else {
    element.className+= " ";
    element.className+= name; 
  }
	*/
}

/*
function stripeTables() {
  var tables = document.getElementsByTagName("table");
  for (var i=0; i<tables.length; i++) {
    if (tables[i].className.match("striped")) {
    	var rows = tables[i].getElementsByTagName("tr");
    	for (var j=1; j<rows.length; j=j+2) {
      	addClass(rows[j],"even_row");
    	}
  	}
	}
}
*/

function stripeTable(id, start_row) {
  var table = document.getElementById(id);   
	//var rows = table.getElementsByTagName("tr");
	for (var j=start_row; j<table.rows.length; j=j+2) {
		addClass(table.rows[j],"even_row");
	}
}

function stripeTableAndColumns(id, start_row, start_col) {
  stripeTable(id, start_row);
	// Color each other column; give the table cells a class.
	var table = document.getElementById(id);
	/*
	for (var j=start_row+1; j<table.rows.length; j=j+2) {
		for (var col = start_col; col < table.rows[j].cells.length; col=col+2) {
			//if (table.rows[j].className= = "even_row") {
			addClass(table.rows[j].cells[col],"even_col");
			//}
		}
	}
	for (var j=start_row; j<table.rows.length; j=j+2) {
		for (var col = start_col; col < table.rows[j].cells.length; col=col+2) {
			//if (table.rows[j].className == "even_row") {
			addClass(table.rows[j].cells[col],"even_col_2");
			//}
		}
	}
	*/
	for (var j=start_row; j<table.rows.length; j++) {
		for (var col = start_col; col < table.rows[j].cells.length; col=col+2) {
			if (table.rows[j].className == "even_row") {
			addClass(table.rows[j].cells[col],"even_col_2");
			} else if (!table.rows[j].className) {
				addClass(table.rows[j].cells[col],"even_col");
			}
		}
	}
	
}


