//-- File Name     : global.js
//-- Date          : Mar 26th 2006
//-- Author        : Robert Scott-Buccleuch
//-------------------------------------------------------------------------------------------------


//-- Function Name : addLoadEvents
//-- Parameters    : funct
//-- Author        : Simon Willson
//-- website       : http://simon.incutio.com
//-------------------------------------------------------------------------------------------------
function addLoadEvents(funct){
 //-- store whatever is in the onload
 var oldOnLoad = window.onload;
 //-- if there is no fuction attached to it then attach funct
 if(typeof window.onload != 'function'){
	window.onload = funct;
 }else{
	//-- otherwise add the existing function then funct
	window.onload = function(){
	 oldOnLoad();
	 funct();
	}//--end anonoymous function 

 }//-- end if 
}//-- end function addLoadEvents

//-- Function Name : addEvent
//-- Parameters    : elm        - element
//--							 : evType     - event type
//--               : fn         - function name
//--               : useCapture - 
//-- Author        : Scott Andrew
//-- website       : N/A
//-- Summary       : cross browser add event fucntion
//-------------------------------------------------------------------------------------------------
function addEvent(elm, evType, fn, useCapture){

 if(elm.AddEventListener){
	//-- DOM Standard event listener
	elm.AddEventListener(evType, fn, useCapture);
	return true;
 }else if(elm.attachEvent){
	//-- IE event listener
	var r = elm.attachEvent('on' + evType, fn);
	return r;
 }else{
	//-- Older browsers failsafe event attachement method
	elm['on' + evType] = fn;
 }//-- end
}//-- end function addEvent


function getStyle(el,styleProp){
	var x = document.getElementById(el);
	if (window.getComputedStyle)
		var y = window.getComputedStyle(x,null).getPropertyValue(styleProp);
	else if (x.currentStyle){
		var tmpStr = styleProp.indexOf("-");
		if (tmpStr > 0){
		 tmpVar = styleProp.split("-");
		 capital = tmpVar[1].substring(0,1); 
		 capital = capital.toUpperCase();
		 restOfword = tmpVar[1].substring(1,tmpVar[1].length);
		 styleProp = tmpVar[0] + capital + restOfword;
		}
		var y = eval('x.currentStyle.' + styleProp);
	}//end if
	return y;

}//END FUCTION


function makePopup(url, width, height, overflow){
  if (width > 640) { width = 640; }
  if (height > 480) { height = 480; }

  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;
}


/*************************************************************************************
* DOM scripting by brothercake -- http://www.brothercake.com/
* GNU Lesser General Public License -- http://www.gnu.org/licenses/lgpl.html
* allows other DOM scripting to run before window.onload;
**************************************************************************************/
function domFunction(f, a)	{
	var n = 0;
	var t = setInterval(function() {
		var c = true;
		n++;
		if(typeof document.getElementsByTagName != 'undefined' && (document.getElementsByTagName('body')[0] != null || document.body != null)) {
			c = false;
			if(typeof a == 'object') {
				for(var i in a) {
					if((a[i] == 'id' && document.getElementById(i) == null) || (a[i] == 'tag' && document.getElementsByTagName(i).length < 1))	{ 
						c = true; 
						break; 
					}
				}
			}
			if(!c) { f(); clearInterval(t); }
		}
		if(n >= 60) { clearInterval(t);}
	}, 250);
};


/*************************************************************************************
* Make rel="external" anchors pop up to new window. 
**************************************************************************************/
function makeExternalLinks() {
	if (!document.getElementsByTagName) return;
	var aExtAnchors = document.getElementsByTagName('a');
	for (var i=0; i<aExtAnchors.length; i++) {
		var anchor = aExtAnchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
		}
	}
}
new domFunction(makeExternalLinks);