/**
************************************
* JC Gadget st00f
************************************
*
* Simple functions for MS Gadgets
*
* @copyright	Copyright (C) 2006, Jack Chapple
* @author	Jack Chapple <jack@jcxp.net>
*/

function jcObj()
{
	this.wshObj = new ActiveXObject( 'WScript.Shell' );

	this.error = function( errMsg )
	{
		this.wshObj.popup( 'Whoops!\n\n' + errMsg, 0, 'Oh Noes!', 16 );
	}

	this.getStyle = function( layerObj, styleProp )
	{
		var didShow = false;
	
		if ( typeof(layerObj) == "string" )
		{
			var layerObj = document.getElementById( layerObj );
		}
	
		if ( layerObj.style.display == "none" )
		{
			layerObj.style.display = '';
			didShow = true;
		}
		
		if ( document.defaultView )
		{
			try
			{
				var y = document.defaultView.getComputedStyle(layerObj,null).getPropertyValue(styleProp);
			}
			catch(e){}
		}
		if ( layerObj.currentStyle && y == null )
		{
			try
			{
				var y = layerObj.currentStyle[styleProp];
			}
			catch(e){}
		}
		
		if ( didShow ) layerObj.style.display = 'none';
		
		return y;
	}

	this.truncate = function( txt, max )
	{
		if ( txt.length > max )
		{
			txt = txt.substring( 0, max );
		
			var i = txt.lastIndexOf( " " );
			
			if ( i < 0 )
			{
				i = max;
			}
			
			txt = txt.substring( 0, i );
			txt += "... ";
		}
		
		return txt;
	}

	this.fixXmlHttpUrl = function( url )
	{
		url += ( ( url.indexOf('?') + 1 ) ? '&' : '?' ) + ( new Date() ).getTime();

		return url;
	}

	this.stripHtml = function( txt )
	{
		txt = txt.replace( /<.+?>/g, '' );
		return txt;
	}
}

var jc = new jcObj();
