function HxTabPane(varname,saveCurrentTab,cookieName) {
	//Variables
	this.varname            = varname;
	this.tabs               = new HxObjectList();
	this.obj                = undefined;
	this.obj2               = undefined;
	this.activeTab          = 0;
	this.tab_handles        = "";
	this.tab_content        = "";
	this.saveCurrentTab     = saveCurrentTab;
    this.cookieName         = cookieName;
	
	//Functions
	this.draw = HxTabPane_draw;
	this.addTab = HxTabPane_addTab;
	this.setActiveTab = HxTabPane_setActiveTab;
}
function HxTabPane_draw(obj_to_handles,obj_to_content) {
	
	this.obj = document.getElementById(obj_to_handles);
	this.obj2 = document.getElementById(obj_to_content);
	this.tab_handles = obj_to_handles;
	this.tab_content = obj_to_content;
	/*alert("Removing" + this.obj2.childNodes.length);*/
	
	if (this.obj != undefined) {
		while (this.obj.childNodes.length) {
			this.obj.removeChild(this.obj.childNodes[0]);
		}
		tbl = document.createElement("table");
		tbl.className = "HxTab_table";
		tbody = document.createElement("tbody");
		tr  = document.createElement("tr");
				
		this.tabs.first();
		i = 0;
		while (tab = this.tabs.getObject()) {
			if (i == 0) {
				
				if (i == this.activeTab) {
					tdstarter = document.createElement("td");
					tdstarter.className = "HxTab_start_marked";
				} else {
					tdstarter = document.createElement("td");
					tdstarter.className = "HxTab_start";
				}
				tr.appendChild(tdstarter);
			}
			
			txt = document.createTextNode(this.tabs.cur.getTitle());
			td = document.createElement("td");
			if (i == this.activeTab) {
				td.className = "HxTab_title_marked";
			}else{
				td.className = "HxTab_title";
			}
			td.appendChild(txt);
		
			a = document.createElement("a");
			a.setAttribute("href","#");
			a.className = "HxTab_link";
			//a.onclick = new Function("i="+i+";"+this.varname+".tabs.first();c = 0;while (c < i) {"+this.varname+".tabs.forward();c++;}txt = document.createTextNode("+this.varname+".tabs.getObject().getContent());"+this.varname+".obj.removeChild("+this.varname+".obj.childNodes[1]);"+this.varname+".obj.appendChild(txt);"+this.varname+".setActiveTab("+i+");");
			//alert(this.varname+".setActiveTab("+i+");"+this.varname+".draw('"+this.tab_handles+"','"+this.tab_content+"');");
			a.onclick = new Function(this.varname+".setActiveTab("+i+",\""+this.cookieName+"\");"+this.varname+".draw('"+this.tab_handles+"','"+this.tab_content+"');");
			a.appendChild(txt);

			td.appendChild(a);
			tr.appendChild(td);
			if (i < this.tabs.count()-1) {
				/*
				count == 4;
				{**}[..][..][..]
				[..]{**}[..][..]
				[..][..]{**}[..]
				[..][..][..]{**}
				*/

				tdspacer = document.createElement("td");
				if ((i+1) == this.activeTab) {
					tdspacer.className = "HxTab_spacer_right_marked";
				}else if ((i) == this.activeTab) {
					tdspacer.className = "HxTab_spacer_left_marked";
				}else {
					tdspacer.className = "HxTab_spacer";
				}
				tr.appendChild(tdspacer);
			}
			
			if ((i+1) == this.tabs.count()) {
				if (i == this.activeTab) {
					tdend = document.createElement("td");
					tdend.className = "HxTab_end_marked";
				} else {
					tdend = document.createElement("td");
					tdend.className = "HxTab_end";
				}
				tr.appendChild(tdend);
			}
			
			this.tabs.forward();
			
			i++;
		}
		tbody.appendChild(tr);
		tbl.appendChild(tbody);
		this.obj.appendChild(tbl);

        
	}else{
		out("Duer ikke! Elementet '"+this.tab_handles+"' findes ikke!");	
	}	
		/** So much for the tab names **/
		this.tabs.first();
		c = 0;
		while (c < this.activeTab) {
			c++;
			this.tabs.forward();
		}
		this.tabs.getObject().activate(this.tab_content);

}
function HxTabPane_setActiveTab(i,cookieKey) {
	this.activeTab=i;
    if (this.tabs.getObject() != undefined) {
	    this.tabs.getObject().moveBack();
        if (this.saveCurrentTab != undefined) {
            c = new HxCookie();
            if (cookieKey == undefined)
                return;
            else
                c.setCookie(cookieKey,this.activeTab,2 * 24 * 60);
        }
    }
}

function HxTabPane_addTab(tab) {
	this.tabs.addObject(tab);
}
	

function HxTab(k,i,t) {
	//Variables
	this.tab_title = k;
	this.tab_input = i;
	this.tab_type = t;
	this.tab_dest	= undefined;
	
	//Functions
	this.getTitle = HxTab_getTitle;
	this.activate = HxTab_activate;
	this.moveBack = HxTab_moveBack;
	this.move	  = HxTab_move;
}
function HxTab_getTitle() {
	return this.tab_title;	
}
function HxTab_activate(where) {
	this.tab_dest = where;
	to = document.getElementById(where);
	if (this.tab_type == "id") {
		from = document.getElementById(this.tab_input);
		//alert(this.tab_input+ ":" + from.childNodes.length + " | "+this.tab_dest+": " + to.childNodes.length);
		//alert("Moving from "+this.tab_input+" ("+from.childNodes.length+" children) to "+where+" ("+to.childNodes.length+" children)");
		this.move(from,to);
	}else if (this.tab_type == "html") {
		txt = document.createTextNode(this.tab_input);
		to.appendChild(txt);
	}
	
}
function HxTab_move(from,to) {
	if (from != undefined && to != undefined) {
		//for (i = 0; i < len; i++) {
		//alert(from.childNodes.length);
		while (from.childNodes.length) {
			//alert(from.childNodes.length);
			//obj = from.childNodes[i].cloneNode(true);
			obj = from.childNodes[0];
			
			to.appendChild(obj);	
			//if (from.childNodes[i].length)
				//HxTab_move(from.childNodes[i],to);
			//from.removeChild(obj);
			//alert(from.childNodes.length);
			
		}	
	}	
}
function HxTab_moveBack() {
	from = document.getElementById(this.tab_dest);
	to = document.getElementById(this.tab_input);
	if (from != undefined && to != undefined) {
	//alert("Moving BACK from "+this.tab_dest+" ("+from.childNodes.length+" children) to "+this.tab_input+" ("+to.childNodes.length+" children)");
		this.move(from,to);
		
	}	
}
	
/**
* HxInputSwitcher kan bruges til at skifte udskifte SELECT options. 
* @param string id Id of select box
*/
function HxOptionSwitcher(id) {
	this.optionlist	= new Array(new Array());
	this.selectbox 	= id;
	//Functions
	this.addOption = HxOptionSwitcher_add
	this.swap = HxOptionSwitcher_swap;
}
function HxOptionSwitcher_swap(group) {
	obj = document.getElementById(this.selectbox);
	if (this.optionlist[group] != undefined) {
		
		while (obj.childNodes.length) {
			obj.removeChild(obj.childNodes[0]);
		}
		for (i = 0; i < this.optionlist[group].length; i++) {
			opt = document.createElement("option");
			opt.value = this.optionlist[group][i].getValue();
			if (this.optionlist[group][i].getAttrib() == "selected")
				opt.selected = true;	
			opt.appendChild(document.createTextNode(this.optionlist[group][i].getKey()));
			obj.appendChild(opt);
		}
		//alert(this.optionlist[group][0].getKey())
	}
}
function HxOptionSwitcher_add(group,opt) {

	if (this.optionlist[group] == undefined) 
		this.optionlist[group] = new Array();
	len = this.optionlist[group].length
	if (len == 0)
		len = 0;
	arr = new Array(len);
	
	for (i=0; i<len; i++) {		
		arr[i] = this.optionlist[group][i];
	}
	arr[len] = opt;
	this.optionlist[group] = arr;
}
function HxSelectOption(key,val,attrib) {
	this.key = key;
	this.val = val;
	this.attrib = attrib;
	
	//methods
	this.getValue = HxSelectOption_getvalue;
	this.getKey = HxSelectOption_getkey;
	this.getAttrib = HxSelectOption_getattrib;
}
function HxSelectOption_getvalue() {
	return this.val;
}
function HxSelectOption_getkey() {
	return this.key;
}
function HxSelectOption_getattrib() {
	return this.attrib;
}

function textToAlphaNum(txt) {
	allowed_chars = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","_","1","2","3","4","5","6","7","8","9","0");
	look_for_chars = new Array("æ","å","ø","-"," ");
	replace_chars = new Array("ae","aa","oe","_","_");
	str = new String(txt);
	str = str.toLowerCase();
	fixedStr = "";
	for (var i = 0; i < str.length; i++){
		done = false;
		for (var j = 0; j < allowed_chars.length; j++) {
			if (str.charAt(i) == allowed_chars[j]) {
				fixedStr += str.charAt(i)
				done = true;
			}
		}
		if (done == false) {
			for (var j = 0; j < look_for_chars.length; j++) {
				if (str.charAt(i) == look_for_chars[j]) {
					fixedStr += replace_chars[j];
				}
			}
		}
	}
	return fixedStr;
}
function textToAlphaNumCI(txt) {
	allowed_chars = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","_","1","2","3","4","5","6","7","8","9","0");
	look_for_chars = new Array("æ","å","ø","-"," ");
	replace_chars = new Array("ae","aa","oe","_","_");
	str = new String(txt);
	fixedStr = "";
	for (var i = 0; i < str.length; i++){
		done = false;
		for (var j = 0; j < allowed_chars.length; j++) {
			if (str.charAt(i) == allowed_chars[j] || str.charAt(i) == allowed_chars[j].toUpperCase()) {
				fixedStr += str.charAt(i)
				done = true;
			}
		}
		if (done == false) {
			for (var j = 0; j < look_for_chars.length; j++) {
				if (str.charAt(i) == look_for_chars[j] || str.charAt(i) == look_for_chars[j].toUpperCase()) {
					fixedStr += replace_chars[j];
				}
			}
		}
	}
	return fixedStr;
}
function fieldToAlphaNum(id) {
	obj = document.getElementById(id);
	allowed_chars = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","_","1","2","3","4","5","6","7","8","9","0");
	look_for_chars = new Array("æ","å","ø","-"," ");
	replace_chars = new Array("ae","aa","oe","_","_");
	str = new String(obj.value);
	str = str.toLowerCase();
	fixedStr = "";
	for (var i = 0; i < str.length; i++){
		done = false;
		for (var j = 0; j < allowed_chars.length; j++) {
			if (str.charAt(i) == allowed_chars[j]) {
				fixedStr += str.charAt(i)
				done = true;
			}
		}
		if (done == false) {
			for (var j = 0; j < look_for_chars.length; j++) {
				if (str.charAt(i) == look_for_chars[j]) {
					fixedStr += replace_chars[j];
				}
			}
		}
	}
	obj.value = fixedStr;
}

/**
* The HxFormFieldTrigger adds specific task to specific events. 
* It can replace options in a select list upon a specific event
* of any other form field.
*/
function HxFormFieldTrigger() {
    this.options = new Array();
    this.triggers = new Array();
    
    this.register = HxFormFieldTrigger_register;
    this.addTrigger = HxFormFieldTrigger_addTrigger();
}
function HxFormFieldTrigger_addOption(object,name,value) {
    if (document.getElementById("object") != undefined) {
        if (this.options[object] == undefined)
            this.options[object] = new Array();
        opt = new Array();
        opt["name"] = name;
        opt["value"] = value;
        this.options[object][this.options[object].length] = opt;
    }
}
/**
* @param string object  ID of the object on which to apply the trigger.
* @param event          Trigger event match traditionel html evens: onChange, onMouseDown etc.
* @param val            Match this value against
* @param act            What to do when it's triggered, possible values: replaceOptions
*/
function HxFormFieldTrigger_addTrigger(object, event, val, act) {
    if (this.trigger[object] == undefined) {
        this.trigger[object] = new Array();
    }
    trigger = new Array();
    trigger["event"] = event;
    trigger["value"] = val;
    trigger["action"] = act;
    
    this.trigger[object][this.trigger[object].length] = trigger;
    
    
    /** Commencing trigger to object **/
    obj(object).trigger["event"] = new Function(object,values,FormFieldTrigger_replaceSelectOptions);
}
/**
* @param string object  ID of the object
* @param array values   associative array of values
*/
function HxFormFieldTrigger_replaceSelectOptions(object,values) {
    clear(object);
    selector = new LmntSelect();
    selector.lmnt = obj(object);
    for (i = 0; i < values.length; i++) {
        selector.addOption(values[i]["name"],values[i]["value"])
    }
}
function HxFormFieldTrigger_register() {

}