// JavaScript Document

$(document).ready(function(){
	
	$(".tab1_home").click(function(){
		window.location = "appointments/";
	});
	
	$(".tab2_home").click(function(){
		window.location = "prescriptions/";
	});
	
	$(".tab3_home").click(function(){
		window.location = "building-updates/";
	});
	
	$(".tab1").click(function(){
		window.location = "../appointments/";
	});
	
	$(".tab2").click(function(){
		window.location = "../prescriptions/";
	});
	
	$(".tab3").click(function(){
		window.location = "../building-updates/";
	});
	
	$(".NLemail").focus(function(){
		if (this.value == "Enter Email") {
			this.value = "";
		}
	});
	
	$(".NLemail").blur(function(){
		if (this.value == "") {
			this.value = "Enter Email";
		}
	});
	
	
	// PRETTY PHOTO
	$("a[rel^='prettyPhoto']").prettyPhoto({
		
		animation_speed: 'normal', /* fast/slow/normal */
		slideshow: 5000, /* false OR interval time in ms */
		autoplay_slideshow: false, /* true/false */
		opacity: 0.80, /* Value between 0 and 1 */
		show_title: true, /* true/false */
		allow_resize: true, /* Resize the photos bigger than viewport. true/false */
		default_width: 800,
		default_height: 600,
		counter_separator_label: ' of ', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'pp_default', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
		horizontal_padding: 20, /* The padding on each side of the picture */
		hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
		wmode: 'opaque', /* Set the flash wmode attribute */
		autoplay: true, /* Automatically start videos: True/False */
		modal: false, /* If set to true, only the close button will close the window */
		deeplinking: true, /* Allow prettyPhoto to update the url to enable deeplinking. */
		overlay_gallery: true, /* If set to true, a gallery will overlay the fullscreen image on mouse over */
		keyboard_shortcuts: true, /* Set to false if you open forms inside prettyPhoto */
		changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
		callback: function(){}, /* Called when prettyPhoto is closed */
		ie6_fallback: true,
		
	});
	
	
	// COTNACT FORM
	
	$("#contactForm .submit_button").click(function() {
		processContactForm();
	});
	
	
	// PRESCRIPTION REQUEST FORM
	
	$("#noticeYes").click(function(){
		$("#prescriptionFormNotice").fadeOut(function(){
			showForm();
		});
	});
	
	$("#noticeNo").click(function(){
		$("#prescriptionFormNotice").fadeOut(function(){
			$("#prescriptionContentBox").load('fail.php', function() {
				$("#prescriptionFormNoticeFail").fadeIn();
			});
		});
	});
	
	
	
	
	// APPOINTMENT REQUEST FORM
	
	$("#appointmentContentBox #noticeYes").click(function(){
		$("#appointmentFormNotice").fadeOut(function(){
			showForm_app_current();
		});
	});
	
	$("#appointmentContentBox #noticeNo").click(function(){
		$("#appointmentFormNotice").fadeOut(function(){
			showForm_app_new();
		});
	});
	
});

var hash = false; 
checkHash();

function checkHash(){ 
    if(window.location.hash != hash) { 
        hash = window.location.hash;
        if (hash == "#newPatient") {
			showForm_app_new();
		}
    } t=setTimeout("checkHash()",400); 
}

function showForm_app_current () {
	$("#appointmentFormNotice, #appointmentContentBox").fadeOut(function(){
		$(".loading").fadeIn(function(){
			$("#appointmentContentBox").load('form_current.php', function() {
				$(".loading").fadeOut(function(){
					$("#appointmentContentBox").fadeIn(function(){
						var dates = $("#app1, #app2, #app3").datepicker({ minDate: '1d' });
						$("#firstName").focus();
						$("#appointmentForm .submit_button").click(function(){
							processAppointmentRequestForm_current();
						});
					});
				})
			});
		});
	});
}

function showForm_app_new () {
	$("#appointmentFormNotice, #appointmentContentBox").fadeOut(function(){
		$(".loading").fadeIn(function(){
			$("#appointmentContentBox").load('form_new.php', function() {
				$(".loading").fadeOut(function(){
					$("#appointmentContentBox").fadeIn(function(){
						var dates = $("#app1, #app2, #app3").datepicker({ minDate: '1d' });
						$("#firstName").focus();
						$("#appointmentForm .submit_button").click(function(){
							processAppointmentRequestForm_new();
						});
						$("#insurance_0").click(function() {
							$(".noInsurance").fadeOut();
							$(".hasInsurance").fadeIn();
						});
						
						$("#insurance_1").click(function() {
							$(".noInsurance").fadeIn();
							$(".hasInsurance").fadeOut();
						});
					});
				});
			});
		});
	});
}

function showForm () {
	$("#prescriptionFormNotice, #prescriptionContentBox").fadeOut(function(){
		$(".loading").fadeIn(function(){
			$("#prescriptionContentBox").load('form.php', function() {
				$(".loading").fadeOut(function(){
					$("#prescriptionContentBox").fadeIn(function(){
						$("#firstName").focus();
						$("#prescriptionForm .submit_button").click(function(){
							processPrescriptionForm();
						});
					});
				});
			});
		});
	});
}

function processPrescriptionForm () {
	
	$("#prescriptionContentBox").fadeOut(function () {
		
		$(".loading").fadeIn(function(){
	
			var firstName 		= document.getElementById('firstName').value;
			var middleInitial 	= document.getElementById('middleInitial').value;
			var lastName 		= document.getElementById('lastName').value;
			var homePhone_1 	= document.getElementById('homePhone_1').value;
			var homePhone_2 	= document.getElementById('homePhone_2').value;
			var homePhone_3 	= document.getElementById('homePhone_3').value;
			var workPhone_1 	= document.getElementById('workPhone_1').value;
			var workPhone_2 	= document.getElementById('workPhone_2').value;
			var workPhone_3 	= document.getElementById('workPhone_3').value;
			var mobilePhone_1 	= document.getElementById('mobilePhone_1').value;
			var mobilePhone_2 	= document.getElementById('mobilePhone_2').value;
			var mobilePhone_3	= document.getElementById('mobilePhone_3').value;
			var dobMonth		= document.getElementById('dobMonth').value
			var dobDay 			= document.getElementById('dobDay').value;
			var dobYear 		= document.getElementById('dobYear').value;
			var email 			= document.getElementById('email').value;
			
			var med_1 = document.getElementById('med_1').value;
			var med_2 = document.getElementById('med_2').value;
			var med_3 = document.getElementById('med_3').value;
			var med_4 = document.getElementById('med_4').value;
			var med_5 = document.getElementById('med_5').value;
			var med_6 = document.getElementById('med_6').value;
			var med_7 = document.getElementById('med_7').value;
			
			var pharmAddress = document.getElementById('pharmAddress').value;
			var pharmPhone_1 = document.getElementById('pharmPhone_1').value;
			var pharmPhone_2 = document.getElementById('pharmPhone_2').value;
			var pharmPhone_3 = document.getElementById('pharmPhone_3').value;
			var pharmFax_1 = document.getElementById('pharmFax_1').value;
			var pharmFax_2 = document.getElementById('pharmFax_2').value;
			var pharmFax_3 = document.getElementById('pharmFax_3').value;
			
			
			$.post("form.php",{ 
				firstName:	firstName,
				middleInitial: middleInitial,
				lastName: lastName,
				homePhone_1: homePhone_1,
				homePhone_2: homePhone_2,
				homePhone_3: homePhone_3,
				workPhone_1: workPhone_1,
				workPhone_2: workPhone_2,
				workPhone_3: workPhone_3,
				mobilePhone_1: mobilePhone_1,
				mobilePhone_2: mobilePhone_2,
				mobilePhone_3: mobilePhone_3,
				dobMonth: dobMonth,
				dobDay: dobDay,
				dobYear: dobYear,
				email: email,
				
				med_1: med_1,
				med_2: med_2,
				med_3: med_3,
				med_4: med_4,
				med_5: med_5,
				med_6: med_6,
				med_7: med_7,
				
				pharmAddress: pharmAddress,
				pharmPhone_1: pharmPhone_1,
				pharmPhone_2: pharmPhone_2,
				pharmPhone_3: pharmPhone_3,
				pharmFax_1: pharmFax_1,
				pharmFax_2: pharmFax_2,
				pharmFax_3: pharmFax_3
				  
			} ,function(data) {
				$("#prescriptionContentBox").html(data);
				$(".loading").fadeOut(function() {
					$("#prescriptionContentBox").fadeIn(function(){
						$("#prescriptionForm .submit_button").click(function(){
							processPrescriptionForm();
						});
					});
				});
			});
		});
	});
		
}


function processAppointmentRequestForm_current () {
	
	$("#appointmentContentBox").fadeOut(function () {
		
		$(".loading").fadeIn(function(){
	
			var firstName 		= document.getElementById('firstName').value;
			var middleInitial 	= document.getElementById('middleInitial').value;
			var lastName 		= document.getElementById('lastName').value;
			var homePhone_1 	= document.getElementById('homePhone_1').value;
			var homePhone_2 	= document.getElementById('homePhone_2').value;
			var homePhone_3 	= document.getElementById('homePhone_3').value;
			var workPhone_1 	= document.getElementById('workPhone_1').value;
			var workPhone_2 	= document.getElementById('workPhone_2').value;
			var workPhone_3 	= document.getElementById('workPhone_3').value;
			var mobilePhone_1 	= document.getElementById('mobilePhone_1').value;
			var mobilePhone_2 	= document.getElementById('mobilePhone_2').value;
			var mobilePhone_3	= document.getElementById('mobilePhone_3').value;
			var dobMonth		= document.getElementById('dobMonth').value
			var dobDay 			= document.getElementById('dobDay').value;
			var dobYear 		= document.getElementById('dobYear').value;
			var email 			= document.getElementById('email').value;
			
			var app1 			= document.getElementById('app1').value;
			var app1_hr 		= document.getElementById('app1_hr').value;
			var app1_min 		= document.getElementById('app1_min').value;
			var app1_ampm 		= document.getElementById('app1_ampm').value;
			
			var app2 			= document.getElementById('app2').value;
			var app2_hr 		= document.getElementById('app2_hr').value;
			var app2_min 		= document.getElementById('app2_min').value;
			var app2_ampm 		= document.getElementById('app2_ampm').value;
			
			var app3 			= document.getElementById('app3').value;
			var app3_hr 		= document.getElementById('app3_hr').value;
			var app3_min 		= document.getElementById('app3_min').value;
			var app3_ampm 		= document.getElementById('app3_ampm').value;
			
			
			$.post("form_current.php",{ 
				firstName:	firstName,
				middleInitial: middleInitial,
				lastName: lastName,
				homePhone_1: homePhone_1,
				homePhone_2: homePhone_2,
				homePhone_3: homePhone_3,
				workPhone_1: workPhone_1,
				workPhone_2: workPhone_2,
				workPhone_3: workPhone_3,
				mobilePhone_1: mobilePhone_1,
				mobilePhone_2: mobilePhone_2,
				mobilePhone_3: mobilePhone_3,
				dobMonth: dobMonth,
				dobDay: dobDay,
				dobYear: dobYear,
				email: email,
				
				app1:app1,
				app1_hr:app1_hr,
				app1_min:app1_min,
				app1_ampm:app1_ampm,
				
				app2:app2,
				app2_hr:app2_hr,
				app2_min:app2_min,
				app2_ampm:app2_ampm,
				
				app3:app3,
				app3_hr:app3_hr,
				app3_min:app3_min,
				app3_ampm:app3_ampm,
				  
			} ,function(data) {
				$("#appointmentContentBox").html(data);
				$(".loading").fadeOut(function() {
					$("#appointmentContentBox").fadeIn(function(){
						$("#appointmentForm .submit_button").click(function(){
							processAppointmentRequestForm_current();
						});
					});
				});
			});
			
		});
	});
		
}

function processAppointmentRequestForm_new () {
	
	$("#appointmentContentBox").fadeOut(function () {
		
		$(".loading").fadeIn(function(){
	
			var firstName 		= document.getElementById('firstName').value;
			var middleInitial 	= document.getElementById('middleInitial').value;
			var lastName 		= document.getElementById('lastName').value;
			var homePhone_1 	= document.getElementById('homePhone_1').value;
			var homePhone_2 	= document.getElementById('homePhone_2').value;
			var homePhone_3 	= document.getElementById('homePhone_3').value;
			var workPhone_1 	= document.getElementById('workPhone_1').value;
			var workPhone_2 	= document.getElementById('workPhone_2').value;
			var workPhone_3 	= document.getElementById('workPhone_3').value;
			var mobilePhone_1 	= document.getElementById('mobilePhone_1').value;
			var mobilePhone_2 	= document.getElementById('mobilePhone_2').value;
			var mobilePhone_3	= document.getElementById('mobilePhone_3').value;
			var dobMonth		= document.getElementById('dobMonth').value
			var dobDay 			= document.getElementById('dobDay').value;
			var dobYear 		= document.getElementById('dobYear').value;
			var email 			= document.getElementById('email').value;
			
			var app1 			= document.getElementById('app1').value;
			var app1_hr 		= document.getElementById('app1_hr').value;
			var app1_min 		= document.getElementById('app1_min').value;
			var app1_ampm 		= document.getElementById('app1_ampm').value;
			
			var app2 			= document.getElementById('app2').value;
			var app2_hr 		= document.getElementById('app2_hr').value;
			var app2_min 		= document.getElementById('app2_min').value;
			var app2_ampm 		= document.getElementById('app2_ampm').value;
			
			var app3 			= document.getElementById('app3').value;
			var app3_hr 		= document.getElementById('app3_hr').value;
			var app3_min 		= document.getElementById('app3_min').value;
			var app3_ampm 		= document.getElementById('app3_ampm').value;
			
			var hasIns = 'No';
			var insCarrier = '';
			var insIDNumber = '';
			
			if (document.getElementById('insurance_0').checked) {
				hasIns = 'Yes';
				insCarrier = document.getElementById('ins_carrier').value;
				insIDNumber = document.getElementById('ins_idNumber').value;
			}
			
			
			$.post("form_new.php",{ 
				firstName:	firstName,
				middleInitial: middleInitial,
				lastName: lastName,
				homePhone_1: homePhone_1,
				homePhone_2: homePhone_2,
				homePhone_3: homePhone_3,
				workPhone_1: workPhone_1,
				workPhone_2: workPhone_2,
				workPhone_3: workPhone_3,
				mobilePhone_1: mobilePhone_1,
				mobilePhone_2: mobilePhone_2,
				mobilePhone_3: mobilePhone_3,
				dobMonth: dobMonth,
				dobDay: dobDay,
				dobYear: dobYear,
				email: email,
				
				app1:app1,
				app1_hr:app1_hr,
				app1_min:app1_min,
				app1_ampm:app1_ampm,
				
				app2:app2,
				app2_hr:app2_hr,
				app2_min:app2_min,
				app2_ampm:app2_ampm,
				
				app3:app3,
				app3_hr:app3_hr,
				app3_min:app3_min,
				app3_ampm:app3_ampm,
				
				hasIns:hasIns,
				insCarrier:insCarrier,
				insIDNumber:insIDNumber
				  
			} ,function(data) {
				$("#appointmentContentBox").html(data);
				$(".loading").fadeOut(function() {
					$("#appointmentContentBox").fadeIn(function(){
						$("#appointmentForm .submit_button").click(function(){
							processAppointmentRequestForm_new();
						});
					});
				});
			});
			
		});
	});
		
}

function processContactForm () {
	$("#contactFormBox").fadeOut(function () {
		
		$(".loading").fadeIn(function(){
	
			var name		= document.getElementById('name').value;
			var phone		= document.getElementById('phone').value;
			var email		= document.getElementById('email').value;
			var comments	= document.getElementById('comments').value;
			
			
			$.post("processForm.php",{ 
				name:name,
				phone:phone,
				email:email,
				comments:comments
				  
			} ,function(data) {
				$("#contactFormBox").html(data);
				$(".loading").fadeOut(function() {
					$("#contactFormBox").fadeIn(function(){
						$("#contactForm .submit_button").click(function() {
							processContactForm();
						});
					});
				});
			});
			
		});
	});
}

