/* from dustin diaz */
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

function insertAfter(parent, node, referenceNode) {
	parent.insertBefore(node, referenceNode.nextSibling);
}

Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};

function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}


function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

/* from hedger wang */
function getNaturalSize(dImg)
{
var naturalSize  = {width:-1, height:-1};
if(dImg.naturalWidth != null)
{
	naturalSize.width = dImg.naturalWidth;
	naturalSize.height = dImg.naturalHeight;
}
else if(dImg.runtimeStyle)
{
	dImg.runtimeStyle.width= 'auto';
	dImg.runtimeStyle.height= 'auto';
	dImg.runtimeStyle.borderWidth= '0';
	dImg.runtimeStyle.padding= '0';
	naturalSize.width =  dImg.offsetWidth;
	naturalSize.height =  dImg.offsetHeight;
	dImg.runtimeStyle.width= '';
	dImg.runtimeStyle.height= '';
	dImg.runtimeStyle.borderWidth= '';
	dImg.runtimeStyle.padding= '';
}else 
{
	var dImgBk = dImg.cloneNode(true);
	dImg.className = '';
	dImg.style.width = 'auto !important';
	dImg.style.height = 'auto !important';
	dImg.style.borderWidth= '0 !important';
	dImg.style.padding= '0 !important';
	dImg.removeAttribute('width');
	dImg.removeAttribute('height');
	
	naturalSize.width =  dImg.width;
	naturalSize.height =  dImg.height;

	dImg.setAttribute('width' , dImgBk.getAttribute('width') );
	dImg.setAttribute('height', dImgBk.getAttribute('height') );


	dImg.style.width = dImgBk.style.width ; 
	dImg.style.height = dImgBk.style.height ; 
	dImg.style.padding = dImgBk.style.padding ; 
	dImg.style.borderWidth=  dImgBk.style.borderWidth ; 
	dImg.style.className = dImgBk.style.className ; 
	
};

return(naturalSize);
}
