/*
	Used for submitting email addresses
*/

$(document).ready(function() {
    $('#date').datepicker();
	
	/* HIDE on page load--------------------------------*/
	$('#requestInspection').hide();
	$('#scheduledInspections').hide();
	$('#availablePermits').hide();
	$('#calculatorBuildingPermit').hide();

	/* SHOW on click	------------------------------------*/
	$("#requestAnInspection").click(function() {$("#requestAnInspection").hide();$('#requestInspection').slideDown();});
	$("#showInspections").click(function() {$('#scheduledInspections').slideDown();$('#showInspections').hide();});
	$("#showPermits").click(function() {$('#availablePermits').slideDown();$('#showPermits').hide();});
	$("#showBuildingPermitCalculator").click(function() {$('#calculatorBuildingPermit').slideDown();$('#showBuildingPermitCalculator').hide();});
	
	/* CLOSE on click	------------------------------------*/
	$("#closeInspectionRequest").click(function() {$('#requestInspection').slideUp();$("#requestAnInspection").show();});
	$("#closeCalculatorBuildingPermit").click(function() {$('#calculatorBuildingPermit').slideUp();$('#showBuildingPermitCalculator').show();});
	$("#closeInspections").click(function() {$('#scheduledInspections').slideUp();$('#showInspections').show();});
	$("#closePermits").click(function() {$('#availablePermits').slideUp();$('#showPermits').show();});
	
	
		/*  --------------------------------------------------------------------
			INSPECTION REQUEST
			Get form contents and post to database
	----------------------------------------------------------------------- */
	$("#submitRequestInspection").click(function() {
        var who=$('#who').val();
		var phone=$('#phone').val();
		var email=$('#email').val();
		var address=$('#address').val();
		var permit=$('#permit').val();
		var type=$('#type').val();
		var date=$('#date').val();
		var time=$('#time :selected').text();
		var altTime=$('#altTime :selected').text();
		var comments=$('#comments').val();
		
		var data ='who='+who+'&phone='+phone+'&email='+email+'&address='+address+'&permit='+permit+'&type='+type+'&date='+date+'&time='+time+'&altTime='+altTime+'&comments='+comments;
		
		//SEND DATA
			$.ajax({
			type: 'post',
			url: '../common/INSERT_request.php',
			data: data,
			success: function(msg)
			{
				//alert(msg);
				//Output if successful
				$('#form').fadeOut(2000);
				$('#newForm').fadeIn(2000);
				$('#newForm').html('<p>Thank you!</p>');
			}
			});
			$('#requestInspection').html('<p>Your request has been sent. You will receive an email confirming the inspection once it has been confirmed by the City. If you do not hear from the City before your inspection, please call the City Inspector at (651) 490-4691.</p>');
        return false;
    });
	
	
});

