$(function(){
	//The submit button is clicked
	$('#formAskMaggie').click(function(){

	//Setup any needed variables.
	var inputFname = $('#askFname').val(),
		inputLname = $('#askLname').val(),
		inputEmail = $('#askEmail').val(),
		inputQuestion = $('#askQuestion').val(),
		response_text = $('#askResponse');
		//Hide any previous response text
		response_text.hide();

		//Change response text to 'loading...'
		response_text.html('<img alt="" src="images/sn_loading.gif" /> Loading...').show();

		//Make AJAX request
		$.post('php/questionSend.php', {askFname: inputFname, askLname: inputLname, askEmail: inputEmail, askQuestion: inputQuestion}, function(data){
			response_text.html(data);
		});
		
		//Cancel default action
		return false;
	});

	//The submit button is clicked
	$('#formComments').click(function(){

	//Setup any needed variables.
	var inputName = $('#commName').val(),
		inputEmail = $('#commEmail').val(),
		inputComment = $('#comment').val(),
		response_text = $('#commResponse');
		//Hide any previous response text
		response_text.hide();

		//Change response text to 'loading...'
		response_text.html('<img alt="" src="images/sn_loading.gif" /> Loading...').show();

		//Make AJAX request
		$.post('php/commentSend.php', {commName: inputName, commEmail: inputEmail, comment: inputComment}, function(data){
			response_text.html(data);
		});

		//Cancel default action
		return false;
	});

	//The submit button is clicked
	$('#formStores').click(function(){

	//Setup any needed variables.
	var inputState = $('#state').val(),
		inputCity = $('#city').val(),
		outputStores = $('#stores');
		//Hide any previous response text
		outputStores.hide();

		//Change response text to 'loading...'
		outputStores.html('<img alt="" src="images/sn_loading.gif" /> Loading...').show();

		//Make AJAX request
		$.post('php/findStores.php', {state: inputState, city: inputCity}, function(data){
			outputStores.html(data);
		});

		//Cancel default action
		return false;
	});

	//The submit button is clicked
	$('#changeComments').click(function(){
	//Setup any needed variables.
	var inputID = $('#commID').val(),
		inputEmail = $('#commEmail').val(),
		inputName = $('#commName').val(),
		inputComment = $('#commComment').val(),
		inputDate = $('#commDate').val(),
		inputValidate = $('#validate:checked').val(),
		outputResponse = $('#commResponse');
		
		//Hide any previous response text
		outputResponse.hide();
		//Change response text to 'loading...'
		outputResponse.html('<img alt="" src="images/sn_loading.gif" /> Loading...').show();
		
		//Make AJAX request
		$.post('php/updateComment.php', {commID: inputID, commEmail: inputEmail, commName: inputName, commComment: inputComment, commDate: inputDate, validate: inputValidate}, function(data){
			outputResponse.html(data);
		});

		//Cancel default action
		return false;
	});

	$('.confirmDelete').click(function(){
		$(this).children('.confirm').slideDown();
	});
	$('.confirmNo').click(function(){
		$(this).parent('.confirm').slideUp();
		return false;
	});
	$('.confirmYes').click(function(){
		var inputID = $(this).attr("id");
		$.post('php/deleteComment.php', {commID: inputID}, function(data){
		});
	});
	$('.qYes').click(function(){
		var inputID = $(this).attr("id");
		$.post('php/deleteQuestion.php', {qID: inputID}, function(data){
		});
	});
	$('.sYes').click(function(){
		var inputID = $(this).attr("id");
		$.post('php/deleteStore.php', {sID: inputID}, function(data){
			if(data == "success") {
				return true;
			} else {
				return false;
			}
		});
	});
	
	$('#changeQuestion').click(function(){
	//Setup any needed variables.
	var inputID = $('#qID').val(),
		inputEmail = $('#qEmail').val(),
		inputFirstName = $('#qFirstName').val(),
		inputLastName = $('#qLastName').val(),
		inputQuestion = $('#question').val(),
		inputAnswer = $('#answer').val(),
		inputDate = $('#qDate').val(),
		inputValidate = $('#validate:checked').val(),
		outputResponse = $('#qResponse');
		
		//Hide any previous response text
		outputResponse.hide();
		//Change response text to 'loading...'
		outputResponse.html('<img alt="" src="images/sn_loading.gif" /> Loading...').show();
		
		//Make AJAX request
		$.post('php/updateQuestion.php', {qID: inputID, qEmail: inputEmail, qFirstName: inputFirstName, qLastName: inputLastName, question: inputQuestion, answer: inputAnswer, qDate: inputDate, validate: inputValidate}, function(data){
			outputResponse.html(data);
		});
		//Cancel default action
		return false;
	});
	
	$('#changeStore').click(function(){
	var inputID = $('#sID').val(),
		inputName = $('#sName').val(),
		inputStreet = $('#street').val(),
		inputCity = $('#city').val(),
		inputState = $('#state').val(),
		outputResponse = $('#sResponse');
		
		outputResponse.hide();
		outputResponse.html('<img alt="" src="images/sn_loading.gif" /> Loading...').show();
		
		$.post('php/updateStore.php', {sID: inputID, sName: inputName, street: inputStreet, city: inputCity, state: inputState}, function(data){
			outputResponse.html(data);
		});
		//Cancel default action
		return false;
	});
	$('#addStore').click(function(){
	var inputName= $('#sName').val(),
		inputStreet = $('#street').val(),
		inputCity = $('#city').val(),
		inputState = $('#state').val(),
		response_text = $('#sResponse');

		response_text.hide();
		response_text.html('<img alt="" src="images/sn_loading.gif" /> Loading...').show();

		//Make AJAX request
		$.post('php/addStore.php', {sName: inputName, street: inputStreet, city: inputCity, state: inputState}, function(data){
			response_text.html(data);
		});
		
		//Cancel default action
		return false;
	});
});
