function addMeta(name, content) {
  var meta;
  if (document.createElement && (meta = document.createElement('meta'))) {
    // set properties
    meta.name = name;
    meta.content = content;

    // now add the meta element to the head
    document.getElementsByTagName('head').item(0).appendChild(meta);
  }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
} 
function addCss(cssCode) {
  var styleElement = document.createElement('style');
    styleElement.type = 'text/css';
    if (styleElement.styleSheet) {
      styleElement.styleSheet.cssText = cssCode;
    } else {
      styleElement.appendChild(document.createTextNode(cssCode));
    }
    document.getElementsByTagName('head')[0].appendChild(styleElement);
}
  
  
function getKeyCode(e)
{
	if (window.event)
		return window.event.keyCode;
	else if (e)
		return e.which;
	else
		return null;
}
  
function keyRestrict(e, validchars) {
	var key='', keychar='';
	key = getKeyCode(e);
	if (key == null) return true;
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	validchars = validchars.toLowerCase();
	if (validchars.indexOf(keychar) != -1)
		return true;
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		return true;
	return false;
}

function showElement(id) {
  var element = document.getElementById(id);
  element.style.display = '';
}

function hideElement(id) {
  var element = document.getElementById(id);
  element.style.display = 'none';
}

function toggleElement(id) {
  var element = document.getElementById(id);
  
  if (element.style.display == '') 
    hideElement(id);
  else
    showElement(id);
}

function insertOption(list, text, value) {
  var y=document.createElement('option');
  y.text=text;
  y.value=value;

  try {
    list.add(y,null); // standards compliant
  }
  catch(ex) {
    list.add(y); // IE only
  }
}
  
function clearList(list) {
  var index = list.length-1;
  while (index >= 0) {
    list.remove(index--);
  }
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function isValueInRange(value, minValue, maxValue) {
  if ((value < minValue) || (value > maxValue)) {
    return false;
  } else {
    return true;
  }
}