/*************************************************************************
 *
 * cvs:			$Date: 2003/12/03 10:09:56 $Author: jonah $Revision: 1.4 $
 * file:		default.js
 * purpose:		include file with all javascript functions.
 * programmer:	jonas.ahnlund
 * develop inc:	flowinteractive
 *
 * history:		2002-09-06	created.
 *
 ************************************************************************/
var gMouseAtx = -1,
	gMouseAtY = -1;

/*********************************************************
** FUNCTION:	trim( text );
*********************************************************/
function trim( text )
{
	var reg_exp = /\s/ig;
	return text.replace( reg_exp, "" );
}

/********************************************************
** FUNCTION:	endPointTrim( text );
********************************************************/
function endPointTrim( text )
{
var reg_exp1 = /^\s/ig,
	reg_exp2 = /\s$/ig;

return text.replace( reg_exp1, "" ).replace( reg_exp2, "" );
}

/**********************************************************
** FUNCTION:	wndStat( msg );
**********************************************************/
function wndStat( msg )
{
	window.status = msg;
}

/**********************************************************
** FUNCTION:	editText( page_id, text_pos );
**********************************************************/
function editText( page_id, text_pos )
{
	window.open( "admin/text_edit/text_edit.jsp?page_id=" + page_id + "&text_pos=" + text_pos, null, "width=530,height=460,toolbar=0,status=0,scrolling=0,scrolling=no" );
}

/**********************************************************
** FUNCTION:	editImage( page_id, text_pos );
**********************************************************/
function editImage( page_id, img_pos )
{
	window.open( "admin/image_edit/image_edit.jsp?page_id=" + page_id + "&img_pos=" + img_pos, null, "width=360,height=340,toolbar=0,status=0,scrolling=0,scrolling=no" );
}

/**********************************************************
** FUNCTION:	editText( page_id, text_pos );
**********************************************************/
function editIsbn( page_id, text_pos )
{
	window.open( "admin/isbn_edit/isbn_edit.jsp?page_id=" + page_id + "&text_pos=" + text_pos, null, "width=530,height=150,toolbar=0,status=0,scrolling=0,scrolling=no" );
}

/*********************************************************************
** FUNCTION: enablePublishButton();
*********************************************************************/
function enableButtons()
{
	if( parent.admin_bottom )
	{
		 parent.admin_bottom.enableButtons();
	}
}

/*********************************************************************
** FUNCTION: enablePublishButton();
*********************************************************************/
function disableButtons()
{
	if( parent.admin_bottom )
	{
		 parent.admin_bottom.disableButtons();
	}
}

/*********************************************************************
** FUNCTION:	showLayerAt( layer_id, x, y );
*********************************************************************/
function showLayerAt( lid, x, y )
{
	/* netscape < 5 */
	if( (gBrowser == 'NN') && (gVersion < 5) )
	{
		if( eval('document.layers["' + lid + '"]') )
		{
			eval('document.layers["' + lid + '"].top =' + y );
			eval('document.layers["' + lid + '"].left =' + x );
			eval('document.layers["' + lid + '"].visibility = "show"');
		}
	}
	/* netscape > 5 */
	else if( (gBrowser == 'NN') && (gVersion >= 5) )
	{
		if( eval('document.getElementById("' + lid + '")') )
		{
			eval('document.getElementById("' + lid + '").style.top =' + y );
			eval('document.getElementById("' + lid + '").style.left =' + x );
			eval('document.getElementById("' + lid + '").style.visibility = "visible"');
		}
	}
	/* explorer */
	else if( gBrowser == 'IE' )
	{
		if( eval('document.all.' + lid) )
		{
			eval('document.all.' + lid + '.style.top =' + y );
			eval('document.all.' + lid + '.style.left =' + x );
			eval('document.all.' + lid + '.style.visibility = "visible"');
		}
	}
}

/*************************************************************************
** FUNCTION:	hideLayer( layer_id );
*************************************************************************/
function hideLayer( lid )
{
	/* netscape < 5 */
	if( (gBrowser == 'NN') && (gVersion < 5) )
	{
		if( eval('document.layers["' + lid + '"]') )
		{
			eval('document.layers["' + lid + '"].visibility = "hide"');
		}
	}
	/* netscape > 5 */
	else if( (gBrowser == 'NN') && (gVersion >= 5) )
	{
		if( eval('document.getElementById("' + lid + '")') )
		{
			eval('document.getElementById("' + lid + '").style.visibility = "hidden"');
		}
	}
	/* explorer */
	else if( gBrowser == 'IE' )
	{
		if( eval('document.all.' + lid) )
		{
			eval('document.all.' + lid + '.style.visibility = "hidden"');
		}
	}
}

/**************************************************************************
** function:    showInfo( e );
***************************************************************************/
function showInfo( e )
{
	//alert( parseInt(gMouseAtX - 250) );
	showLayerAt( 'info_layer', parseInt(gMouseAtX - 250), gMouseAtY );
}

/**************************************************************************
** function:    hideInfo();
***************************************************************************/
function hideInfo()
{
	hideLayer( 'info_layer' );
}

/**************************************************
** FUNCTION:	handleMouseMove();
**************************************************/
function handleMouseMove()
{
	if( (gBrowser == 'IE') || ((gBrowser == 'NN') && (parseInt( gVersion ) >= 5)) )
	{
		document.onmousemove = findMouse;
	}
	else if( (gBrowser == 'NN') && (parseInt( gVersion ) < 5) )
	{
		document.captureEvents( Event.MOUSEMOVE );
		document.onMouseMove = findMouse;
	}
}

/**************************************
** FUNCTION:	findMouse();
**************************************/
function findMouse( e )
{
	if( gBrowser == 'IE' )
	{
		/* explorer */
		var e = window.event;

		gMouseAtX = e.clientX;
		gMouseAtY = e.clientY;
	}
	else if( gBrowser == 'NN' )
	{
		/* netscape */
		gMouseAtX = e.pageX;
		gMouseAtY = e.pageY;
	}

	//window.status = gMouseAtX + ':' + gMouseAtY;
}

handleMouseMove();