﻿var resultsHTML = "";
function submitComment()
{
	var blogPostItemID = $("input[name='blogPostItemID']").val();
	var name = $("input[name='name']").val();
	var email = $("input[name='email']").val();
	var comments = $("textarea[name='comments']").val();
	var notify = false;
	if($("input[name='notify']:checked").val() == "on")
	{
		notify = true;
	}
	
	var errorMsg = "";
	if(isNullOrEmpty(name) || name == "Your name")
	{
		errorMsg = "Please enter your name\n";
	}
	if(!isValidEmail(email))
	{
		errorMsg += "Please check your email address\n";
	}
	if(isNullOrEmpty(comments) || comments == "Your comment")
	{
		errorMsg += "Please enter your comment\n";
	}
	if(errorMsg != "")
	{
		//alert(errorMsg);
	}
	else
	{
		//Submit form
		AtomicPlaypen.AjaxAPI.AtomicPlaypenAjax.SubmitBlogPostComment(blogPostItemID, name, email, comments, notify, Callback_SubmitBlogPostComment);
	}
}
function Callback_SubmitBlogPostComment(res)
{
	if (res.error)
	{
		//alert("An error occurred.\nYour request could not be processed.  " + res.error.Message)
	}
	else
	{
		resultsHTML = res.value;
		$(".commentsDiv").slideUp().html(resultsHTML).slideDown();
	}
}
function isNullOrEmpty(str)
{
	if(str == null || str == "")
	{
		return true;
	}
	else
	{
		return false;
	}
}
function blogSearch()
{
	var searchTerm = $("input[name='searchInput']").val();
	if(searchTerm != "" && blogPageLink != "")
	{
		window.location = blogPageLink + "#searchTerm=" + searchTerm;
	}
}