/**
 *	SPIRIT 3.91/4 Transitional :: Core Library of Functions
 *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *	BETA BETA BETA BETA BETA BETA BETA BETA BETA BETA 
 *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *	Copyright : Isotope Communications Ltd 2006 *
 *			  : *unless otherwise credited..
 *	Author	  : Jim Morrison
 *	Version	  : 0.1 ( alpha )
 *	Purpose	  : All the little toys we keep using and re-writing
 *			  : in one place.. 
 */

var jsRND = '1.0.1';
 

/**
 * REALLY USEFUL BITS THAT SHOULD GO ELSEHWERE
 */

function showObject(o){
	x = '';
	y = 0;
	for ( i in o ){
		x += i + ' = ' + o[i] + '\n';
		if ( y > 10 ) {
			alert(x);
			y = 0; x = '';
		}
		y++;
	}
	alert(x);
}

function cycleBack(e,tag){
	x = 0;
	while ((e.tagName.toUpperCase() != tag.toUpperCase()) && x < 10){
		e = e.parentElement;
		x++;
	}
	return e;
}

function cycleForward(e,tag){
	for (z=0;z<e.childNodes.length;z++){
		if (e.childNodes[z] && e.childNodes[z].tagName){
			if (e.childNodes[z].tagName.toUpperCase() == tag.toUpperCase()){
				return (e.childNodes[z]);
			}
		}
	}
}
 
function evDOMpath(p){
	if ( p ) {
		pExp = p.split('.');
		path = '';
		for ( var x = 0; x < pExp.length; x++ ){
			path ? path += '.' : null;
			path += pExp[x];
			if ( !eval(path) ){
				return false;
			}
		}
		return eval(p);
	}
}

/**
 * CodeCredit: by Scott Andrew LePera, http://www.scottandrew.com/weblog/articles/cbs-events
 */

function addEvent(obj, evType, fn, useCapture){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, useCapture);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		alert("Handler could not be attached");
	}
}

function rtf(){
	return false;
}





/*Popup function.. behaves with *some* blockers.. eg. Gtoolbar */
function isoJsPopup(url,name,props) {
	
	var WindowRef = null;
	
	if ( props == '' ) {
		props = "resizable=yes,scrollbars=yes,status=yes, width=640, height=480";
	}
	
	 if(WindowRef == null || WindowRef.closed)
	 /* if the pointer to the window object in memory does not exist
	    or if such pointer exists but the window was closed */
	
	 {
	   WindowRef = window.open(url, name, props);
	   /* then create it. The new window will be created and
	      will be brought on top of any other window. */
	 }
	 else
	 {
	   WindowRef.focus();
	   /* else the window reference must exist and the window
	      is not closed; therefore, we can bring it back on top of any other
	      window with the focus() method. There would be no need to re-create
	      the window or to reload the referenced resource. */
	 };
}






/*	PNG TRANSPARENCY IN IE .. */
/*	
	INCLUDE THIS IN TEMPLATE:
	
	<!--[if lt IE 7]>
		window.attachEvent("onload", isoIEPNG);	
	<![endif]-->
	
*/

function isoJsIEPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}
