function hideAllDropDowns()
{
	var dropdowns = document.getElementsByTagName('select');
	for (var i = 0; i < dropdowns.length; i++) { dropdowns[i].style.visibility = 'hidden'; }
}

//Show all dropdowns that were hidden because of IE bug
function showAllDropDowns()
{
	var dropdowns = document.getElementsByTagName('select');
	for (var i = 0; i < dropdowns.length; i++) { dropdowns[i].style.visibility = 'visible'; }
}

// Detect browser (see http://www.quirksmode.org/js/detect.html)
function checkIt(string)
{
	var detect = navigator.userAgent.toLowerCase();
	return detect.indexOf(string) + 1;
}

// Cross-browser code to get element position
function getElementY(e)
{
  if (!(e=xGetElementById(e))) return 0;
  var y = 0;
  while (e) {
    if (xDef(e.offsetTop)) y += e.offsetTop;
    e = xDef(e.offsetParent) ? e.offsetParent : null;
  }
  return y;
}
function getElementX(e)
{
  if (!(e=xGetElementById(e))) return 0;
  var x = 0;
  while (e) {
    if (xDef(e.offsetLeft)) x += e.offsetLeft;
    e = xDef(e.offsetParent) ? e.offsetParent : null;
  }
  return x;
}
function xDef()
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}
function xGetElementById(e)
{
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else e=null;
  return e;
}

// Show custom popup
function showMessagePopup(obj, type, message)
{
	document.getElementById('popuptitle').innerHTML = type;
	document.getElementById('popuptitle').style.backgroundImage = 'url(styles/default/icon_' + type + '.gif)';
	document.getElementById('popuptitle').style.width = '355px';
	document.getElementById('popup').style.display = 'block';
	document.getElementById('popup').style.width = '400px';
	var top = getElementY(obj);
	if (!checkIt('mac') || !checkIt('safari')) top += 30;
	document.getElementById('popup').style.top = top.toString() + 'px';
	document.getElementById('popupcontentwindow').style.backgroundColor = '#EEEEEE';
	document.getElementById('popupcontent').innerHTML = message;
}

// Show custom remote popup
function showRemotePopup(obj, type, title, url)
{
	if (checkIt('msie') && checkIt('mac'))
	{
		var height = 200;
		if (url.toLowerCase().indexOf('sentmessage') > -1) height = 400;
		openWindow(url, 350, height, 'yes');
	}
	else
	{
		document.getElementById('popuptitle').innerHTML = '<img src=\"../images/icons/' + type + '.png\" border=\"0\" align=\"absmiddle\" width=\"16\" /> ';
		document.getElementById('popuptitle').innerHTML += title;
		document.getElementById('popuptitle').style.width = '500px';
		document.getElementById('popup').style.display = 'block';
		document.getElementById('popup').style.width = '570px';
		//document.getElementById('popup').style.top = (getElementY(obj)).toString()+ 'px';
		//document.getElementById('popup').style.left = (getElementX(obj)).toString()+10 + 'px';
		document.getElementById('popup').style.margin.bottom = (getElementY(obj)).toString() + 'px';
		document.getElementById('popupcontentwindow').style.backgroundColor = '#F8F5EA';
		loadRemoteContent(url, 'popupcontent');
	}
}

// Hide custom popup
function hidePopup()
{
	document.getElementById('popuptitle').innerHTML = '';
	document.getElementById('popupcontent').innerHTML = '<div align="center">loading...</div>';
	document.getElementById('popup').style.display = 'none';
}

//Use ajax to load content into this window
function loadRemoteContent(url, id) 
{
  var requestURL = escape(url);
  if (document.getElementById) var x = (window.ActiveXObject) ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
  
	if (x) 
  {
    x.onreadystatechange = function() 
    {
      if (x.readyState == 4 && x.status == 200) 
      {
        el = document.getElementById(id);
        el.innerHTML = x.responseText;
				
      }
    }
    x.open('GET', url, true);
    x.send(null);
  }
}

//Extend javascript string to support trim method
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

//Mac IE has no built-in Array.push() method
if(typeof Array.prototype.push == 'undefined')
{
	Array.prototype.push=function()
	{
		var i=0;
		b=this.length,a=arguments;
		for(i;i<a.length;i++)this[b+i]=a[i];
		return this.length;
	};
}
