var browser = "";

//detecting older netscapes
if (!document.all){browser = "Old Netscape"}

//detecting Opera if (navigator.userAgent.indexOf("Opera") > 0){browser = "Opera"}

//detecting IE
if (navigator.appName =="Microsoft Internet Explorer" && navigator.userAgent.indexOf("Opera") < 0){browser = "IE"}

function loadPopup(popupString) {
  var array = popupString.split('|');
  var url = array[0];
  var params = array[1];
  window.open(url, 'popup', params);
}

function linkTo(item) {

	var action 	= item.options[item.selectedIndex].value;
	document.location = action;
}

function populateYearOfBirth(selectid, selectedvalue)
{
	var formfield = document.getElementById(selectid);
	// Populate select list with years from 100 to 18 years before current year
	var now = new Date();
	var thisYear = now.getYear()
	var index = 1 ;
	for ( y = (thisYear-18) ; y >= (thisYear-100) ; y-- )
	{
		formfield[index] = new Option(y, y);
		if (selectedvalue && selectedvalue == y) { formfield.selectedIndex = index ; }
		index++ ;
	}
}


// function to submit the parent form of an element
function parentFormSubmit(elem) {
  while (elem.nodeName != 'FORM' && elem.parentNode) { elem = elem.parentNode; }
  if (elem.nodeName == 'FORM') { 
  	elem.submit(); 
  } else { 
  	return false; 
  }
}

/**
 * originally from the 'balancedColumns.js' script,
 * by Paul@YellowPencil.com and Scott@YellowPencil.com
 *
 * June 2007 - adapted for special use by Framfab
 */
function balanceCols(colArr, noPreviousHeight) {
  if (!colArr || !document.getElementById) { return; }
  
  // get elems with IDs from colArr in new array
  var divs = [];
  var thisElem = null;
  for (var i = 0; i < colArr.length; ++i) {
    if (thisElem = document.getElementById(colArr[i])) {
      divs.push(thisElem);
    }
  }
  
  // if desired, remove all explicit height declarations from cols before balancing
  if (noPreviousHeight) {
    for (var i = 0; i < divs.length; ++i) {
      divs[i].style.height = '';
    }
  }
  
  // Let's determine the maximum height out of all columns specified
  var maxHeight = 0;
  for (var i = 0; i < divs.length; i++) {
    if (divs[i].offsetHeight > maxHeight) maxHeight = divs[i].offsetHeight;
  }
	
  // Let's set all columns to that maximum height
  for (var i = 0; i < divs.length; i++) {
    divs[i].style.height = maxHeight + 'px';

    // Now, if the browser's in standards-compliant mode, the height property
    // sets the height excluding padding, so we figure the padding out by subtracting the
    // old maxHeight from the new offsetHeight, and compensate!  So it works in Safari AND in IE 5.x
    if (divs[i].offsetHeight > maxHeight) {
      divs[i].style.height = (maxHeight - (divs[i].offsetHeight - maxHeight)) + 'px';
    }
  }
}


// read and render username for welcome-message in header
function getUserName(url) {
	url = url + "&sid=" + Math.random()
	
	var xmlUserNameReq = xmlLoader(url);
	if(xmlUserNameReq.getElementsByTagName("username")[0] && xmlUserNameReq.getElementsByTagName("username")[0].length !=0) {
		var userName = xmlUserNameReq.getElementsByTagName("username")[0].childNodes[0].nodeValue;
		return userName;
	}
	return "";
}

function renderUserName(loadedMessage, userName) {
	loadedMessage = loadedMessage.replace(/\$_username/, userName);
	var hdrWelcome = document.getElementById('hdrWelcome');
	hdrWelcome.innerHTML = loadedMessage;
}
