function ChangeCodeFontSize( dir )
{
	var min = 8;
	var max = 18;
	
	var code = document.getElementById( 'code' );
	
	if( code.style.fontSize )
	{
	
		var s = parseInt( code.style.fontSize.replace( "px", "" ) );
		
	}
	else
	{
	
		var s = 13;
		
	}
	
	if ( dir == "up" )
	{
	
		s += 1;
		
	}
	else if ( dir == "down" )
	{
	
		s -= 1;
	
	}
	
	if( s < min )
	{
	
		s = min;
		
	}
	else if ( s > max )
	{
	
		s = max;
		
	}
	
	code.style.fontSize = s + "px";
	//code.style.lineHeight = "1.5em";
	
	var plain = document.getElementById( 'plainview' );
	
	plain.style.fontSize = s + "px";
	//plain.style.lineHeight = "1.5em";
	
}

function ToggleCodeView( show )
{

	var code = document.getElementById( 'code' );
	var plain = document.getElementById( 'plainview' );
	
	if ( show == "code" )
	{
	
		code.style.display = "block";
		plain.style.display = "none";
		
	}
	else if ( show == "plain" )
	{
	
		code.style.display = "block";
		plain.style.height = code.scrollHeight + "px";
		//plain.scrollHeight = code.scrollHeight;
		
		code.style.display = "none";
		plain.style.display = "block";
	
	}

}

function SubmitGotoSnip( )
{

	var form = document.getElementById( 'gotoform' );
	var snip = document.getElementById( 'gotosnip' );
	form.action = "/" + snip.value;
	form.submit();

}

function SubmitPreview( )
{

	var form = document.getElementById( 'newpost' );
	form.action = "/preview";
	form.submit();

}

function getXCoord( el )
{

	x = 0;
	
	while( el )
	{
	
		x += el.offsetLeft;
		el = el.offsetParent;
		
	}
	
	return x;
}

function getYCoord( el )
{

	y = 0;
	
	while( el )
	{
	
		y += el.offsetTop;
		el = el.offsetParent;
		
	}
	
	return y;
}


function CodeToolsUpdate( )
{

	var codetools = document.getElementById( 'codetools' );
	if ( codetools )
	{
	
		if ( codetools.stayposy - window.pageYOffset < 0 )
		{
		
			codetools.style.position = "fixed";
			//codetools.style.top = ( pageYOffset - codetools.staypos ) + "px";
			codetools.style.top = "0px";
			codetools.style.left = codetools.stayposx + "px";
			codetools.style.border = "1px solid #356AA0";
			codetools.style.width = codetools.staywidth;
			
		}
		else
		{
		
			codetools.style.position = "relative";
			codetools.style.top = document.body.clientTop + "px";
			codetools.style.left = "0px";
			codetools.style.border = "0px";
		
		}
	
	}

}


function CodeToolsInit( )
{

	var codetools = document.getElementById( 'codetools' );
	if ( codetools )
	{
	
		var y = getYCoord( codetools );
		var x = getXCoord( codetools );
		codetools.stayposy = y;
		codetools.stayposx = x;
		codetools.staywidth = codetools.offsetWidth;
		window.onscroll = CodeToolsUpdate;
		CodeToolsUpdate();
		
		setInterval( "CodeToolsUpdate()", 1000 );
		
	}
	
}



