//=======================================================================================================
//-------------------------------------------------------------------------------------------------------
//	Blog Javascript functions
//-------------------------------------------------------------------------------------------------------
//=======================================================================================================
//-------------------------------------------------------------------------------------------------------
//	openEmailPopup
//-------------------------------------------------------------------------------------------------------
function openEmailPopup( id )
{
	sizeX = 500;
	sizeY = 400;
	
	//	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
	content					= '/blog/email.php/id/' + id;
	target					= 'email' + id;
	winobject				= window.open(content,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';
	}

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

//-------------------------------------------------------------------------------------------------------
//	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
//---------------------------------------------------------------------------------------------------------
	if( commentFormOn )
	{
		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 : ""
		});
	}
}
