// JavaScript Document
/* Story Page validation */

function validateCountry()
{		
	// JS Authtication Helper
	security_matrix();

	if($("#txtCountry").val() == 0 || $("#txtCountry").val() == "")
	{
		$('html,body').animate({scrollTop: $("#txtCountry").offset().top},'slow');
		$("#countryNotification").removeClass('valid_sub-story');
		$("#countryNotification").addClass('red_text_sub-story');
		$("#countryNotification").text('Country name required');

		return false;
	}
	else
	{
		$("#countryNotification").text('');
		$("#countryNotification").removeClass('red_text_sub-story');
		$("#countryNotification").addClass('valid_sub-story');
		return true;
	}	
}
function validateState()
{	
	// JS Authtication Helper
	security_matrix();

	if($("#txtState").val() == "")
	{
		$('html,body').animate({scrollTop: $("#txtState").offset().top},'slow');
		$("#stateNotification").removeClass('valid_sub-story');
		$("#stateNotification").addClass('red_text_sub-story');
		$("#stateNotification").text('State name required');
	return false;
	}
	else
	{
		$("#stateNotification").text('');
		$("#stateNotification").removeClass('red_text_sub-story');
		$("#stateNotification").addClass('valid_sub-story');
		return true;
	}
}
function validateCity()
{	
	// JS Authtication Helper
	security_matrix();

	if($("#txtCity").val() == 0 || $("#txtCity").val() == "")
	{
		$('html,body').animate({scrollTop: $("#txtCity").offset().top},'slow');
		$("#cityNotification").removeClass('valid_sub-story');
		$("#cityNotification").addClass('red_text_sub-story');
		$("#cityNotification").text('City name required');
	return false;
	}
	else
	{
		$("#cityNotification").text('');
		$("#cityNotification").removeClass('red_text_sub-story');
		$("#cityNotification").addClass('valid_sub-story');
		return true;
	}
}

function validateCategory()
{
	// JS Authtication Helper
	security_matrix();

	if($("#txtCategory").val() <= 0)
	{
		$('html,body').animate({scrollTop: $("#txtCategory").offset().top},'slow');
		$("#catNotification").removeClass('valid_sub-story');
		$("#catNotification").addClass('red_text_sub-story');
		$("#catNotification").text('Category required');
	return false;
	}
	else
	{
		$("#catNotification").text('');
		$("#catNotification").removeClass('red_text_sub-story');
		$("#catNotification").addClass('valid_sub-story');
		return true;
	}
}

function validateTitle()
{
	// JS Authtication Helper
	security_matrix();

	if($("#txtTitle").val().length <= 0)
	{
		$('html,body').animate({scrollTop: $("#txtTitle").offset().top},'slow');
		$("#tNameNotification").removeClass('valid_sub-story');
		$("#tNameNotification").addClass('red_text_sub-story');
		$("#tNameNotification").text('Title required');
	return false;
	}
	else
	{
		$("#tNameNotification").text('');
		$("#tNameNotification").removeClass('red_text_sub-story');
		$("#tNameNotification").addClass('valid_sub-story');
		return true;
	}
}


function validateTags()
{
	// JS Authtication Helper
	security_matrix();

	if($("#content_keywords").val().length <= 0)
	{
		$('html,body').animate({scrollTop: $("#content_keywords").offset().top},'slow');
		$("#tagsNotification").removeClass('valid');
		$("#tagsNotification").addClass('red_text');
		$("#tagsNotification").text('Tags required');
	return false;
	}
	else
	{
		$("#tagsNotification").text('');
		$("#tagsNotification").removeClass('red_text');
		$("#tagsNotification").addClass('valid');
		return true;
	}
}


function validateContent(test)
{
	// JS Authtication Helper
	security_matrix();

	if(test.length <= 0)
	{
		$("#storyNotification").removeClass('valid');
		$("#storyNotification").addClass('red_text');
		$("#storyNotification").text('Story required');
		return false;
	}
	else
	{
		$("#storyNotification").text('');
		$("#storyNotification").removeClass('red_text');
		$("#storyNotification").addClass('valid');
		return true;
	}
}


function validateTemplate()
{
/*	if(test.length <= 0)
	{
		$("#storyNotification").removeClass('valid');
		$("#storyNotification").addClass('red_text');
		$("#storyNotification").text('Story required');
		return false;
	}
	else
	{
		$("#storyNotification").text('');
		$("#storyNotification").removeClass('red_text');
		$("#storyNotification").addClass('valid');
		return true;
	}	*/
	
	return true;
}

function validateStoryAgreement(id)
{
	if($("#"+id).is(':checked'))
	{
		$('html,body').animate({scrollTop: $("#"+id).offset().top},'slow');
        $("#storytermsNotification").text('');
		$("#storytermsNotification").removeClass('red_text');	

	return true;
	}
	else
	{
	  $("#storytermsNotification").text('Must be agree to the terms and conditions to proceed.');
	  $("#storytermsNotification").addClass('red_text');
	return false;
	}
}

/* End of story page validation */


function validatePFirstName()
{
	// JS Authtication Helper
	security_matrix();

	if($("#pr_first_namae").val().length <= 0)
	{
		$("#pfNameNotification").removeClass('valid_sub-story');
		$("#pfNameNotification").addClass('red_text_sub-story');
		$("#pfNameNotification").text('First Name required');
	return false;
	}
	else
	{
		$("#pfNameNotification").text('');
		$("#pfNameNotification").removeClass('red_text_sub-story');
		$("#pfNameNotification").addClass('valid_sub-story');
		return true;
	}
}


function validatePLastNmae()
{
	// JS Authtication Helper
	security_matrix();

	if($("#pr_last_namae").val().length <= 0)
	{
		$("#plNameNotification").removeClass('valid_sub-story');
		$("#plNameNotification").addClass('red_text_sub-story');
		$("#plNameNotification").text('Last Name required');
	return false;
	}
	else
	{
		$("#plNameNotification").text('');
		$("#plNameNotification").removeClass('red_text_sub-story');
		$("#plNameNotification").addClass('valid_sub-story');
		return true;
	}
}


function validatePWeburl()
{
	// JS Authtication Helper
	security_matrix();

	if($("#pr_web_url").val().length <= 0)
	{
		$("#pwebNameNotification").removeClass('valid_sub-story');
		$("#pwebNameNotification").addClass('red_text_sub-story');
		$("#pwebNameNotification").text('Website Url required');
	return false;
	}
	else
	{
		$("#pwebNameNotification").text('');
		$("#pwebNameNotification").removeClass('red_text_sub-story');
		$("#pwebNameNotification").addClass('valid_sub-story');
		return true;
	}
}



function validatePAddress()
{
	// JS Authtication Helper
	security_matrix();

	if($("#pr_address").val().length <= 0)
	{
		$("#addressNotification").removeClass('valid_sub-story');
		$("#addressNotification").addClass('red_text_sub-story');
		$("#addressNotification").text('Address required');
	return false;
	}
	else
	{
		$("#addressNotification").text('');
		$("#addressNotification").removeClass('red_text_sub-story');
		$("#addressNotification").addClass('valid_sub-story');
		return true;
	}
}



function validatePostalCode()
{
	// JS Authtication Helper
	security_matrix();

	if($("#pr_postal_code").val().length <= 0)
	{
		$("#postalCodeNotification").removeClass('valid_sub-story');
		$("#postalCodeNotification").addClass('red_text_sub-story');
		$("#postalCodeNotification").text('Postal code required');
	return false;
	}
	else
	{
		$("#postalCodeNotification").text('');
		$("#postalCodeNotification").removeClass('red_text_sub-story');
		$("#postalCodeNotification").addClass('valid_sub-story');
		return true;
	}
}



function validatePhoneNo()
{
	// JS Authtication Helper
	security_matrix();

	if($("#pr_phone_no").val().length <= 0)
	{
		$("#phoneNoNotification").removeClass('valid_sub-story');
		$("#phoneNoNotification").addClass('red_text_sub-story');
		$("#phoneNoNotification").text('Phone No required');
	return false;
	}
	else
	{
		$("#phoneNoNotification").text('');
		$("#phoneNoNotification").removeClass('red_text_sub-story');
		$("#phoneNoNotification").addClass('valid_sub-story');
		return true;
	}
}



function validatePEmail()
{

	if($("#pr_email_address").val().length<=0)
	{

		$("#pemailAddNotification").removeClass('valid_sub-story');
		$("#pemailAddNotification").addClass('red_text_sub-story');
		$("#pemailAddNotification").text('Email required');
	return false;
	}
	else
	{
		if(validatePressEmailFormate())
		{
	  	$("#pemailAddNotification").text('');
		$("#pemailAddNotification").removeClass('red_text_sub-story');
		$("#pemailAddNotification").addClass('valid_sub-story');
			return true;
		}
        else
        {
              return false;
        }
	}
}
function validatePressEmailFormate(){
		//testing regular expression
		var a = $("#pr_email_address").val();
		var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
		//if it's valid email
		if(filter.test(a)){
			$("#pemailAddNotification").text('');
			$("#pemailAddNotification").removeClass('red_text_sub-story');
			$("#pemailAddNotification").addClass('valid_sub-story');			
			return true;
		}
		//if it's NOT valid
		else{
			$("#pemailAddNotification").removeClass('valid_sub-story');
			$("#pemailAddNotification").addClass('red_text_sub-story');
			$("#pemailAddNotification").text('Email is not in correct format');
			return false;
		}
	}

















