
//------------------------------------------------------------------------------------------------------------------------------------
//-- Get parent
//------------------------------------------------------------------------------------------------------------------------------------

function JS_Utils_GetParent ( objElement )
{
	 if ( objElement.parentElement ) { return objElement.parentElement };
	 if ( objElement.parentNode ) { return objElement.parentNode };
	 if ( objElement.parent ) { return objElement.parent };
	 return;
}

//------------------------------------------------------------------------------------------------------------------------------------
//-- Show hide element
//------------------------------------------------------------------------------------------------------------------------------------

function JS_Utils_ShowHide ( objElement, bShow )
{
	if ( bShow == null )
	{
		if ( objElement.style.display == "none" ) objElement.style.display = "block";
		else objElement.style.display = "none";
	}
	else
	{
		if ( bShow ) 	objElement.style.display = "block";
		else objElement.style.display = "none";
	}
}

//------------------------------------------------------------------------------------------------------------------------------------
//-- Trim
//------------------------------------------------------------------------------------------------------------------------------------

function JS_Utils_Trim (s)
{
	return s.replace(/^\s+|\s+$/g,"");
}

function JS_Utils_LeftTrim (s)
{
	return s.replace(/^\s+/,"");
}

function JS_Utils_RightTrim (s)
{
	return s.replace(/\s+$/,"");
}

//------------------------------------------------------------------------------------------------------------------------------------
//-- Open Window (unused at present)
//------------------------------------------------------------------------------------------------------------------------------------

function JS_Utils_OpenWindow ( mypage, myname, w, h, scroll )
{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',noresize'
	win = window.open(mypage, myname, winprops);
}

//------------------------------------------------------------------------------------------------------------------------------------
//-- Truncate
//------------------------------------------------------------------------------------------------------------------------------------

function JS_Utils_Truncate ( strSource, strSymbol, nMaxChars )
{
	if(strSource.length > nMaxChars)
	{
		/** Cut off target length - truncation indication length (... = 3 more chars) **/
			strSource = strSource.replace(/(^ | $)/gi, '').substr(0, nMaxChars-(strSymbol.length))+strSymbol;
		}
	return strSource;
}

//---------------------------------------------------------------------------------------------------------------------------------
//-- Popup Modal (for form submission and ajax)
//---------------------------------------------------------------------------------------------------------------------------------

var objModal;

function JS_Utils_ShowModal ()
{
	// hide selects if IE6
	bIsIE6 = /msie|MSIE 6/.test(navigator.userAgent);
	if ( bIsIE6 )
	{
		var arSelects = document.getElementsByTagName("select");
		for ( var n=0; n<arSelects.length; n++ ) arSelects[n].style.display = "none";
		
		window.scrollTo(0,0); // send to top of page, ie6 only
	}
	
	// require modal item to be on the page
	objModal = document.getElementById("divModal");
	
	if ( objModal ) objModal.style.display = "block";
	
	return true;
}

function JS_Utils_HideModal ()
{
	if ( objModal ) objModal.style.display = "none";
}

//------------------------------------------------------------------------------------------------------------------------------------
//-- dltypeof
//------------------------------------------------------------------------------------------------------------------------------------

function JS_Utils_dltypeof ( vExpression )
{
	/* dltypeof.js
	*  by Peter Belesis. v1.0 040823
	*  Copyright (c) 2004 Peter Belesis. All Rights Reserved.
	*  Originally published and documented at http://www.dhtmlab.com/
	*/
	var sTypeOf = typeof vExpression;
	if( sTypeOf == "function" )
	{
		var sFunction = vExpression.toString();
		if( ( /^\/.*\/$/ ).test( sFunction ) )
		{
			return "regexp";
		}
		else if( ( /^\[object.*\]$/i ).test( sFunction ) )
		{
			sTypeOf = "object"
		}
	}
	if( sTypeOf != "object" )
	{
		return sTypeOf;
	}

	switch( vExpression )
	{
		case null:
			return "null";
		case window:
			return "window";
		case window.event:
			return "event";
	}

	if( window.event && ( event.type == vExpression.type ) )
	{
		return "event";
	}

	var fConstructor = vExpression.constructor;
	if( fConstructor != null )
	{
		switch( fConstructor )
		{
			case Array:
				sTypeOf = "array";
				break;
			case Date:
				return "date";
			case RegExp:
				return "regexp";
			case Object:
				sTypeOf = "jsobject";
				break;
			case ReferenceError:
				return "error";
			default:
				var sConstructor = fConstructor.toString();
				var aMatch = sConstructor.match( /\s*function (.*)\(/ );
				if( aMatch != null )
				{
					return aMatch[ 1 ];
				}

		}
	}

	var nNodeType = vExpression.nodeType;
	if( nNodeType != null )
	{
		switch( nNodeType )
		{
			case 1:
				if( vExpression.item == null )
				{
					return "domelement";
				}
				break;
			case 3:
				return "textnode";
		}
	}

	if( vExpression.toString != null )
	{
		var sExpression = vExpression.toString();
		var aMatch = sExpression.match( /^\[object (.*)\]$/i );
		if( aMatch != null )
		{
			var sMatch = aMatch[ 1 ];
			switch( sMatch.toLowerCase() )
			{
				case "event":
					return "event";
				case "math":
					return "math";
				case "error":
					return "error";
				case "mimetypearray":
					return "mimetypecollection";
				case "pluginarray":
					return "plugincollection";
				case "windowcollection":
					return "window";
				case "nodelist":
				case "htmlcollection":
				case "elementarray":
					return "domcollection";
			}
		}
	}

	if( vExpression.moveToBookmark && vExpression.moveToElementText )
	{
		return "textrange";
	}
	else if( vExpression.callee != null )
	{
		return "arguments";
	}
	else if( vExpression.item != null )
	{
		return "domcollection";
	}

	return sTypeOf;
}

function JS_Utils_FindParentElement(eElement, strTargetElement)
	{
		/** Is caller the target? **/
		if(eElement.tagName != strTargetElement)
		{
			var eParent = JS_Utils_GetParent(eElement);
			var n = 0;
			
		//	alert(eParent.tagName+" "+strTargetElement);
			while( eParent.tagName != strTargetElement)
			{
				/** Kill infiniloop **/
				if(n > 255){alert("No form found");return false;}
				/** Move up a level **/
				eParent = JS_Utils_GetParent(eParent);
				n++;
			}
			return eParent;
		}
		else
		return eElement;
	}
//------------------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------------------
	




