function checkTop( )
{
	if ( top.location != self.location ) {
		top.location = self.location;
	}
}

function checkBrowser( )
{
	this.ver = navigator.appVersion;
	this.agent = navigator.userAgent;
	this.dom = document.getElementById ? 1 : 0;
	this.opera5 = this.agent.indexOf( "Opera 5" ) > - 1;
	this.ie5 = ( this.ver.indexOf( "MSIE 5" ) > - 1 && this.dom && ! this.opera5 ) ? 1 : 0; 
	this.ie6 = ( this.ver.indexOf( "MSIE 6" ) > - 1 && this.dom && ! this.opera5 ) ? 1 : 0;
	this.ie4 = ( document.all && ! this.dom && ! this.opera5 ) ? 1 : 0;
	this.ie = this.ie4 || this.ie5 || this.ie6;
	this.mac = this.agent.indexOf( "Mac" ) > - 1;
	this.ns6 = ( this.dom && parseInt( this.ver ) >= 5 ) ? 1 : 0; 
	this.ns4 = ( document.layers && ! this.dom) ? 1 : 0;
	this.bw = ( this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5 );
	return this;
}

function setHomepage( h, url )
{
	bw = new check_browser( );
	if ( ! bw.ie ) {
		return;
	}
	h.style.behavior='url(#default#homepage)';
	h.setHomePage( url );
}

function addToBookmark( url, descr )
{
	bw = new check_browser( );
	if ( ! bw.ie ) {
		return;
	}
	window.external.addFavorite( url, descr );
}

function showWindow( url, winName, params ) {
	return window.open( url, winName, params );
}

function openBlank( name, params ) {
	if ( params.length == 0 ) {
		params = 'directories=no,height=250,left=50,location=no,menubar=no,resize=yes,scrollbars=yes,status=no,toolbar=no,top=50,width=350';
	}
	return window.open( 'about:blank', name, params );
}

// getImageXYcoord ( imgname ) -> object{x,y}
function getImageXYcoord( img )
{
	var elm = document.images[ img ];
	if ( document.layers ) return elm;

	// NS4 images contain x and y values
	var rd = { x:0 ,y:0 };
	do {
		rd.x += parseInt( elm.offsetLeft );
		rd.y += parseInt( elm.offsetTop );
		elm = elm.offsetParent;
	} while ( elm );
	return rd;
}

function padWithZeros( rounded_value, decimal_places ) {
    var value_string = rounded_value.toString( );
    var decimal_location = value_string.indexOf( "." );
    if ( decimal_location == -1 ) {
        decimal_part_length = 0;
        value_string += decimal_places > 0 ? "." : "";
    }
    else {
        decimal_part_length = value_string.length - decimal_location - 1;
    }
    var pad_total = decimal_places - decimal_part_length;
    if ( pad_total > 0 ) {
        for ( var counter = 1; counter <= pad_total; counter++ ) {
            value_string += "0";
		}
	}
    return value_string;
}

function roundDecimals( original_number, decimals ) {
    var result1 = original_number * Math.pow( 10, decimals );
    var result2 = Math.round( result1 );
    var result3 = result2 / Math.pow( 10, decimals );
    return padWithZeros( result3, decimals );
}

function isNumber( value ) {
	if ( isNaN( value ) || value.length == 0 ) {
		return false;
	}
	str = new String( value );
	if ( str.indexOf( ".", 0 ) >= 0 ) {
		return false;
	}
	n = new Number( value );
	return ( n >= 0 );
}

function insertCode( form, input, opencode, closecode, askuser ) {
	if ( eval( "document.forms." + form + ".editmode[0].checked" ) ) {
		txt = "";
		if ( askuser ) {
			txt = prompt( "", "" );
		}
		str = txt ? new String( txt ) : new String( "" );
		if ( ! askuser || askuser && str.length > 0 ) {
			eval( "document.forms." + form + ".elements." + input + ".value += '" + opencode + txt + closecode+ "'" );
		}
	}
	else {
		eval( "document.forms." + form + ".elements." + input + ".value += '" + opencode + closecode + "'" );
	}
	eval( "document.forms." + form + ".elements." + input + ".focus( )" );
}
