// JavaScript Document
//add faq to the patient
$(document).ready(function() {
var FAQerror = "";
		
function valAllowEmpty(value,title)
{
	//doesnt allow empty	
	if(value == '')
	{
		FAQerror += "<li>" + title + "</li>";
	}
}
function valEmail(value)
{
	if(value != "")
	{
		AtPos = value.indexOf("@");
		StopPos = value.lastIndexOf(".");
		
		if (AtPos == -1 || StopPos == -1) {
			FAQerror += "<li>Not a valid email address</li>";
		}
	}
}
$("input[name='submit']").click(function() {	
	FAQerror = "";
	$('.errorLabel').empty();
	$('#form *').each(function() {
		if($(this).attr('title'))
		{
			valAllowEmpty($(this).val(),$(this).attr('title'));
			if($(this).attr('id') == 'email')
			{
				valEmail($(this).val());
			}
		}
	});
	if(FAQerror != "")
	{
		$('.errorLabel').append(FAQerror);
		$('.errorLabel').show();
	}
	else
	{
		$('#loadingBar').show();
		$('.errorLabel').hide();
		
		$.post('../../../ajax/add/patientFAQ.php'
		,{
		
		  'languageID':language
		  ,'question':$('#question').val()
		  ,'email':$('#email').val()
		}
		,function(returnData)
		{
		
			if(returnData == 'ok')
			{
				$('.errorLabel').show();
				$('.errorLabel').append('FAQ Sent');
				$('#question').val('');
				$('#email').val('');
				$('#loadingBar').hide();
			}
			else
			{
				$('.errorLabel').show();
				$('.errorLabel').append(returnData);
				$('#loadingBar').hide();
				
			}
			
		}
		,'text');	
	}
	});
});