//=======================================================================================================
//-------------------------------------------------------------------------------------------------------
//	Blog Javascript functions
//-------------------------------------------------------------------------------------------------------
//=======================================================================================================
//-------------------------------------------------------------------------------------------------------
//	openEmailPopup
//-------------------------------------------------------------------------------------------------------
function openEmailPopup( id )
{
	sizeX = 460;
	sizeY = 500;
	
	//	Center the window
	leftpos	= (screen.width)  ? (screen.width-sizeX)/2 : 100;
	toppos	= (screen.height) ? (screen.height-sizeY)/2 : 100;

	//	Define the window size
	widthVar  = 'width=' + sizeX + ',';
	heightVar = 'height=' + sizeY + ',';

	//	Open the window
	url						= "/blog/email.php/id/" + id;
	target					= "email" + id;
	winobject				= window.open(url,target,"menubar=0,statusbar=0,scrollbars=1,toolbar=0,location=0," + widthVar + heightVar + "left=" + leftpos + ",top=" + toppos + ",resizable=1" );
	winobject.focus();
}

//---------------------------------------------------------------------------------------------------------
//	Validate email address
//---------------------------------------------------------------------------------------------------------
function IsEmail( fieldvalue )
{
	return fieldvalue.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
}

//-------------------------------------------------------------------------------------------------------
//	validateCommentForm
//-------------------------------------------------------------------------------------------------------
function validateCommentForm()
{
	form = document.commentform;

	control = form["verification"];
	if ( !str_trim(control.value) )
	{
		alert("Word verification is required.");
		control.focus();
		return false;
	}

	if (document.getElementById( 'submitbutton' ).value == 'Processing')
	{
		return;
	}
	
	document.getElementById( 'submitbutton' ).value = 'Processing';

	url = '/blog/verify_captcha.php/verification/' + control.value + '/u/' + new Date();
	
	req = initHTTPObject();
	req.open("GET", url, true );
	req.onreadystatechange = function() 
	{ 
		if (req.readyState == 4) 
		{ 
			responseText = req.responseText; 
			
			if (responseText)
			{
				alert(responseText);
				document.getElementById( 'submitbutton' ).value = 'Submit';
			}
			else
			{		
				form.submit();
			}
		}
	}
	
	req.send(null);
}

//-------------------------------------------------------------------------------------------------------
//	toggleWidget
//-------------------------------------------------------------------------------------------------------
function toggleWidget( id )
{
	if (document.getElementById( id ).style.display == 'none' )
	{
		document.getElementById( id ).style.display = 'block';

		if( id == 'subscribe' )
		{
			document.getElementById("st").setAttribute("src","/blog/images/subscribe1.gif");
		}
	}

	else
	{
		document.getElementById( id ).style.display = 'none';

		if( id == 'subscribe' )
		{
			document.getElementById("st").setAttribute("src","/blog/images/subscribe0.gif");
		}
	}
}

//-------------------------------------------------------------------------------------------------------
//	toggleCommentForm
//-------------------------------------------------------------------------------------------------------
var commentFormOn = false;

function toggleCommentForm()
{
	if (commentFormOn == false)
	{
		showCommentForm();
		commentFormOn = true;
	}

	else
	{
		hideCommentForm();
		commentFormOn = false;
	}
}

function OpenCommentForm()
{
	document.getElementById("collapsable").style.display	= "block";
}

//-------------------------------------------------------------------------------------------------------
//	showCommentForm
//-------------------------------------------------------------------------------------------------------
function showCommentForm()
{
//	fadeDivAction( 'collapsable', 'document.getElementById( "collapsable" ).style.display = "block";' );
	document.getElementById( "collapsable" ).style.display = "block";
}

//-------------------------------------------------------------------------------------------------------
//	hideCommentForm
//-------------------------------------------------------------------------------------------------------
function hideCommentForm()
{
//	fadeDivAction( 'collapsable', 'document.getElementById( "collapsable" ).style.display = "none"' );
	document.getElementById( "collapsable" ).style.display = "none";
}

//---------------------------------------------------------------------------------------------------------
//	Load the comment formatter
//---------------------------------------------------------------------------------------------------------
function loadCommentFormatter()
{
//---------------------------------------------------------------------------------------------------------
//	Start the formatter
//---------------------------------------------------------------------------------------------------------
	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		relative_urls : false,
		theme_advanced_toolbar_location : "top",
		theme_advanced_buttons1 : "bold,italic,underline,indent",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : ""
	});
}

//-------------------------------------------------------------------------------------------------------
//	ToggleShareList
//-------------------------------------------------------------------------------------------------------
function ToggleShareList( source_button )
{
	sharelist	= document.getElementById( 'share'+source_button );

	sharelist.style.left = getOffsetLeft( source_button ) +  'px';
	sharelist.style.top  = ( getOffsetTop( source_button ) + getOffsetHeight( source_button )) + 'px';

	if( sharelist.style.display == "block" )
	{
		sharelist.style.display = "none";
	}
	else
	{
		sharelist.style.display = "block";
	}
}

