function addLoadListener(fn)
{
  if (typeof window.addEventListener != 'undefined')
  {
    window.addEventListener('load', fn, false);
  }
  else if (typeof document.addEventListener != 'undefined')
  {
    document.addEventListener('load', fn, false);
  }
  else if (typeof window.attachEvent != 'undefined')
  {
    window.attachEvent('onload', fn);
  }
  else
  {
    var oldfn = window.onload;
    if (typeof window.onload != 'function')
    {
      window.onload = fn;
    }
    else
    {
      window.onload = function()
      {
        oldfn();
        fn();
      };
    }
  }
}
//
function addClass(target, classValue)
{
	var pattern = new RegExp("(^| )" + classValue + "( |$)");
	if(!pattern.test(target.className))
	{
		if(target.className == abort)
		{
			target.className = classValue;
		}
		else
		{
			target.className += " " + classValue;
		}
	}
	return true;
}
//
function getElementsByAttribute(attribute, attributeValue)
{
	var elementArray = new Array();
	var matchedArray = new Array();
	if(document.all)
	{
		elementArray = document.all;
	}
	else
	{
		elementArray = document.getElementsByTagName("*");
	}
	for(var i = 0; i < elementArray.length; i++)
	{
		if(attribute == "class")
		{
			var pattern = new RegExp("(^| )" + attributeValue + "( |$)");
			if(pattern.test(elementArray[i].className))
			{
				matchedArray[matchedArray.length] = elementArray[i];
			}
		}
		else if(attribute == "for")
		{
			if(elementArray[i].getAttribute("htmlFor") || elementArray[i].getAttribute("for"))
			{
				if(elementArray[i].htmlFor == attributeValue)
				{
					matchedArray[matchedArray.length] = elementArray[i];
				}				
			}
		}
		else if(elementArray[i].getAttribute(attribute) == attributeValue)
		{
			matchedArray[matchedArray.length] = elementArray[i];
		}
	}
	return matchedArray;
}
//
function getViewportSize()
{
	var size = [0,0];
	if(typeof window.innerWidth != 'undefined')
	{
		size = [window.innerWidth,
				window.innerHeight];
	}
	else if(typeof document.documentElement != 'undefined' 
		&& typeof document.documentElement.clientWidth != 
		'undefined' && typeof document.documentElement.clientWidth != 0)
	{
		size = [document.documentElement.clientWidth,
				document.documentElement.clientHeight];
	}
	else
	{
		size = [document.getElementsByTagName('body')[0].clientWidth,
				document.getElementsByTagName('body')[0].clientHeight];
	}
}
//
function getCookie(searchName)
{
	var cookies = document.cookie.split(";");
	for(var i = 0; i < cookies.length; i++)
	{
		var cookieCrumbs = cookies[i].split("=");
		var cookieName = cookieCrumbs[0];
		var cookieValue = cookieCrumbs[1];
		if(cookieName == searchName)
		{
			return cookieValue;
		}
	}
	return false;
}
//
function getSubCookie(cookieName, subCookieName)
{
	var cookies = document.cookie.split(";");
	for(var i = 0; i < cookies.length; i++)
	{
		var cookieCrumbs = cookies[i].split("=");
		cookieCrumbs[0] = cookieCrumbs[0].replace(/^\s+/, "");
		if(cookieCrumbs[0] == cookieName)
		{
			var cookieValue = cookieCrumbs[1];
			cookieValue = unescape(cookieValue);
			var subCookies = cookieValue.split("/");
			for(var j = 0; j < subCookies.length; j++)
			{
				var subCookieCrumbs = subCookies[j].split(":");
				if(subCookieCrumbs[0] == subCookieName)
				{
					return subCookieCrumbs[1];
				}		
			}
		}
	}
	return false;
}
//
function makePopup(url, width, height, overflow){
	if (width > 640) {
		width = 640;
	}
	if (height > 1000){
		height = 1000;
	}
	if (overflow == '' || !/^(scroll|resize|both)$/.test(overflow)){
		overflow = 'both';
	}

	var win = window.open(url, '',
      'width=' + width + ',height=' + height
      + ',scrollbars=' + (/^(scroll|both)$/.test(overflow) ? 'yes' : 'no')
      + ',resizable=' + (/^(resize|both)$/.test(overflow) ? 'yes' : 'no')
      + ',status=yes,toolbar=no,menubar=no,location=no'
  	);

	return win;
}