﻿//tilføjet af tangora 25/03-08
function SelectToCheck(selectId)
{
	this.Select = document.getElementById(selectId);
	this.CheckBoxArea = null;
	this.Debug = false;

	this.BuildCheckBoxes = function()
	{
		var area = document.createElement('div');
		this.Select.parentNode.insertBefore(area, this.Select);
		this.Select.style.display = 'none';
		this.CheckBoxArea = area;

		for (var i=0; i<this.Select.options.length; i++)
		{
			var opt = this.Select.options[i];
			area.insertBefore(this.BuildCheckBox(i, opt.innerHTML, opt.checked), null);
		}
		
	}
	
	this.BuildCheckBox = function(i, text, checked)
	{
		var div = document.createElement('div');
		div.style.cssText = 'clear:both';
		div.className = 'input_exception';
		var chk = document.createElement('input');
		chk.type = 'checkbox';
		chk.checked = checked;
		chk.style.cssText = 'float:left; margin-right:5px;';
		chk.id = 'auto_chk' + i;
		div.insertBefore(chk, null);
		div.innerHTML += '<label class="section" style="clear:right" for="' + chk.id + '">' + text + '</label>';
		return div;
	}
	
	this.GetValues = function()
	{
		var coll = this.CheckBoxArea.getElementsByTagName('input');
		for (var i=0; i<coll.length; i++)
		{
			this.Select.options[i].selected = coll[i].checked;
		}
		if (this.Debug) this.Select.style.display = '';
	}
}





//
// EG Courses
// 
// This function is used for:
//   - alternating background colors in table
//
var rowno;
function UpdateTableRow(recordid) {
  if (!rowno) { rowno=0; }
  rowno++;
  
  if (rowno % 2 == 0) {
    // set background color for every second row
    var obj=document.getElementById('row'+recordid);
    if (obj && obj.style) {
	obj.className="tableroweven";
    }
  }
}

// reset row count (used when starting a new group)
function ResetRowCount() {
  rowno=0;
  locations=new Array();
}

// 
// This function is used for:
//   - preparing list of location names
//
// Notice: sortorder must be unique for each location
//
var locations=new Array();
function AddLocation(sortorder, location, locationgif) {
  if (!locations[sortorder]) {
    locations[sortorder]='<span><img src="/media/-300008/pictures/'+locationgif+'" width=5 height=5 hspace=2 alt="'+location+'">'+location+'</span>';
  }
}

function WriteLocations() {
  if (locations && locations.length) {
    var html="", sp="&nb"+"sp;";
    for (var i=0; i<locations.length; i++) {
	if (locations[i]) {
	  html+=sp+sp+sp+locations[i];
	}
    }
    if (html) {
	document.write("<div class=locations><span class=section>"+html+"</span></div>");
    }
  }
}

