
//----------------------------------------------------------------------
// Useful Page Functions
//----------------------------------------------------------------------

function JS_Utils_GetParent ( objElement )
{
	 if ( objElement.parentElement ) { return objElement.parentElement };
	 if ( objElement.parentNode ) { return objElement.parentNode };
	 if ( objElement.parent ) { return objElement.parent };
	 return;
}

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

//----------------------------------------------------------------------
//----------------------------------------------------------------------

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+$/,"");
}

//----------------------------------------------------------------------
//----------------------------------------------------------------------

function JS_Utils_InArray ( strNeedle, arHaystack )
{
	var nFoundIndex = -1;
	
	for ( var i = 0; i < arHaystack.length; i++ )
	{
		if ( JS_Utils_Trim(strNeedle) == JS_Utils_Trim(arHaystack[i]) )
		{
			nFoundIndex = i;
			break;
		}
	}
	
	return nFoundIndex;
}

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

//----------------------------------------------------------------------
// Modal
//----------------------------------------------------------------------

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";
	}
	
	// require modal item to be on the page
	var Modal = document.getElementById("divModal");
	Modal.style.display = "block";
	
	return true;
}

//----------------------------------------------------------------------
//----------------------------------------------------------------------