/*
	Program: javascript.js
	version: 6.0 
	date: 2006/07/14 

	myFC.dk, Internet solutions
 	http://www.myfc.dk

 	Copyright (c) 2005-2009 myFC.dk
*/


document.getElementsByClassName = function(cl) {
  var retnode = [];
  var myclass = new RegExp('\\b'+cl+'\\b');
  var elem = this.getElementsByTagName('*');
  for (var i = 0; i < elem.length; i++) {
    var classes = elem[i].className;
    if (myclass.test(classes)) retnode.push(elem[i]);
  }
  return retnode;
}; 


function toggleBox(szDivID,group) {
  if (document.layers) { // NN4+
    if (document.layers[szDivID].visibility == 'visible') {
      document.layers[szDivID].visibility = "hide";
      document.layers[szDivID].display = "none";
    } else {
      document.layers[szDivID].visibility = "show";
      document.layers[szDivID].display = "block";
    }
  } else if (document.getElementById) { // gecko(NN6) + IE 5+
    var obj = document.getElementById(szDivID);
    var objSD = document.getElementById(szDivID+"SD");

    if (obj.style.visibility == 'visible') {
      obj.style.visibility = "hidden";
      obj.style.display = "none";
    } else {
			// Fist hide all elements in the same group
      if (group !== '') {
        var ll = group.length;
        var arrElements = document.getElementsByTagName("div");
        for (var i=0; i < arrElements.length; i++) {
          var wdiv = arrElements[i].id;
          if (wdiv.substr(0,ll) == group) {
            var ww = wdiv.substr(wdiv.length-2,2);
            if (ww !== 'SD') {
              arrElements[i].style.visibility = "hidden";
              arrElements[i].style.display = "none";
            }
          }
        }
      }
      obj.style.visibility = "visible";
      obj.style.display = "block";
    }
  } else if (document.all) { // IE 4
    if (document.all[szDivID].style.visibility == 'visible') {
      document.all[szDivID].style.visibility = "hidden";
      document.all[szDivID].style.display = "none";
    } else {
      document.all[szDivID].style.visibility = "visible";
      document.all[szDivID].style.display = "block";
    }
  }
}


function loadPage(kald,ksh) {
  location.href=kald+'&load_page=yes&ksh='+ksh.value;	
}

function newElement(kald,rc) {
  if (rc.value == undefined) {
    location.href=kald;
  } else {
    location.href=kald + rc.value;
  }
}

function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

// -------------------------
// Validate Send formular
// -------------------------
function Send(frm) {
  var obj = document.getElementById(frm);

  if(obj.navn.value === "") {
    alert("Dit navn mangler.");
    obj.navn.focus();
    return false;
  }

  if(obj.header.value === "") {
    alert("Overskrift mangler.");
    obj.header.focus();
    return false;
  }

  if(obj.header.value.length < 3) {
    alert("Overskrift skal mindst være 3 tegn!");
    obj.header.focus();
    return false;
  }

  if(obj.tekst.value === "") {
    alert("Din besked mangler.");
    obj.tekst.focus();
    return false;
  }
  return true;
}

// -------------------------
// Check, unCheck items
// -------------------------
function CheckunCheckEm(id,id2) {
  var fl = id2.length;
  var checker = (document.getElementById(id2).checked);
  var count = document.getElementById(id).elements.length;
  for (var i=0; i < count; i++) {
    var el = document.getElementById(id).elements[i].id;
    if (el.substring(0,fl) == id2) {
      document.getElementById(id).elements[i].checked = checker;
    }
  }
}

// -------------------------
// Function to validate email
// -------------------------
function validate_email(email) {
  var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
  return regex.test(email);
}

// Function to print help text
function print_help(ident) {
  var url = "pages/help_print.php?ident=" + ident;
  window.open(url,"myfc_help","top=0,left=0,width=600,height=600,scrollbars=yes");
}

function getElementsByAttribute(attr,val,container,check)
{
  var checker = check.checked;
  container = container||document;
  var all = container.all||container.getElementsByTagName('*');
  for(var k=0;k<all.length;k++) {
    var el = all[k];
    if(el.getAttribute(attr) == val) {
      el.checked = checker;
    }
  }
  return arr;
}

// -------------------------
// Funktion benyttes til browse_images.php
// -------------------------
function popup(theURL,winName,features) {
  var theWidth = screen.availWidth || screen.width;
  var theHeight = screen.availHeight || screen.height;

  var width = Math.round(eval(theWidth * 0.7));
  var height = Math.round(eval(theHeight * 0.7));
  var top = Math.round(eval((theHeight-height) / 2 - 40));
  var left = Math.round(eval((theWidth-width) / 2));
  var param = 'left='+left+',top='+top+',dependent=yes,toolbar=no,resizable=yes,scrollbars=yes,status=no,height='+height+',width='+width;
  window.open(theURL,winName,param);
}

// -------------------------
// Remove img_id from form
// and clear img tag
// -------------------------
function removeImg(form,img,wrapper,container,html) {
  var frm = document.getElementById(form);
  var img_id = document.getElementById(img);
  img_id.value = "";

  var Node = document.getElementById(container);
  Node.parentNode.removeChild(Node);

  var wrap = document.getElementById(wrapper);
  wrap.innerHTML = html;
}

// ------------------------------
// Return img_id from img_browse
// ------------------------------
function returnImage(id,name,formName,imgId,imgContainer,imgWidth) {
  var el = document.getElementById(formName);
  var img = document.getElementById(imgId);
  img.value = id;
  el2 = document.getElementById(imgContainer);
  if (el2 !== null) {
    imgtag = '<img src="../user/images/img_2006/'+name+'" width="'+imgWidth+'" alt="" />'
    el2.innerHTML = imgtag;
   	dialogClose();
  }
}

function getScreenWH() {
  var width = screen.availWidth;
  var height = screen.availHeight;
  var res = width + '/' + height;
  setCookie("screenRes",res,14);
}

function setCookie(c_name,value,expiredays) {
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie=c_name+ "=" +escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name) {
  if (document.cookie.length > 0) {
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1) {
      c_start=c_start + c_name.length+1;
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length;
      return unescape(document.cookie.substring(c_start,c_end));
    }
  }
  return "";
}


// SMS functions
function select_all(thename) {
	var selectlist = document.getElementById(thename).options;
	for(i = 0; i < selectlist.length; i++) {
		selectlist[i].selected = true;
	}
	return true;
}

function move_selected(to, from) {
	var tolist = document.getElementById(to).options;
	var fromlist = document.getElementById(from).options;
	
	var iterations = 0;
	
	for(i = 0; i < fromlist.length; i++) {
		if(fromlist[i].selected) {
			tolist[tolist.length] = new Option(fromlist[i].text, fromlist[i].value);
			fromlist[i] = null;
			i--;
		}
	}
}

function move_all(to, from) {
	var tolist = document.getElementById(to).options;
	var fromlist = document.getElementById(from).options;
	
	var iterations = 0;
	
	while(fromlist.length > 0) {
		tolist[tolist.length] = new Option(fromlist[0].text, fromlist[0].value);
		fromlist[0] = null;
	}
}


/*

CUSTOM FORM ELEMENTS

Created by Ryan Fait
www.ryanfait.com

The only things you may need to change in this file are the following
variables: checkboxHeight, radioHeight and selectWidth (lines 24, 25, 26)

The numbers you set for checkboxHeight and radioHeight should be one quarter
of the total height of the image you use for checkboxes and radio
buttons. Both images should contain the four stages of both inputs stacked
on top of each other in this order: unchecked, unchecked-clicked, checked,
checked-clicked.

You may need to adjust your images a bit if there is a slight vertical
movement during the different stages of the button activation.

The value of selectWidth should be the width of your select list image.

Visit http://ryanfait.com/ for more information.

*/

var checkboxHeight = "30";
var radioHeight = "30";
var selectWidth = "190";


/* No need to change anything after this */


document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } .disabled { opacity: 0.5; filter: alpha(opacity=50); }</style>');

var Custom = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		for(a = 0; a < inputs.length; a++) {
			if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") {
				span[a] = document.createElement("span");
				span[a].className = inputs[a].type;

				if(inputs[a].checked == true) {
					if(inputs[a].type == "checkbox") {
						position = "0 -" + (checkboxHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					} else {
						position = "0 -" + (radioHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					}
				}
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.clear;
				if(!inputs[a].getAttribute("disabled")) {
					span[a].onmousedown = Custom.pushed;
					span[a].onmouseup = Custom.check;
				} else {
					span[a].className = span[a].className += " disabled";
				}
			}
		}
		inputs = document.getElementsByTagName("select");
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].className == "styled") {
				option = inputs[a].getElementsByTagName("option");
				active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++) {
					if(option[b].selected == true) {
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = "select";
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				if(!inputs[a].getAttribute("disabled")) {
					inputs[a].onchange = Custom.choose;
				} else {
					inputs[a].previousSibling.className = inputs[a].previousSibling.className += " disabled";
				}
			}
		}
		document.onmouseup = Custom.clear;
	},
	pushed: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
		} else if(element.checked == true && element.type == "radio") {
			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
		} else if(element.checked != true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
		} else {
			this.style.backgroundPosition = "0 -" + radioHeight + "px";
		}
	},
	check: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 0";
			element.checked = false;
		} else {
			if(element.type == "checkbox") {
				this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else {
				this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
				group = this.nextSibling.name;
				inputs = document.getElementsByTagName("input");
				for(a = 0; a < inputs.length; a++) {
					if(inputs[a].name == group && inputs[a] != this.nextSibling) {
						inputs[a].previousSibling.style.backgroundPosition = "0 0";
					}
				}
			}
			element.checked = true;
		}
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
			} else if(inputs[b].type == "radio" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			}
		}
	},
	choose: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
			}
		}
	}
}
window.onload = Custom.init;

