// Vars for comments rotator functions
var rotations = 0;
var total_comments = 6;

$(document).ready(function(){
	// Drop down menu functionality
	$("ul.topnav li a").hover(function() { 
		$(this).parent().find("ul.subnav").slideDown('fast').show();
		$(this).parent().find("ul.subnav").css({opacity:0.9});
  
		$(this).parent().hover(function() {  
		}, function(){ 
			$(this).parent().find("ul.subnav").slideUp('fast');
			$(this).parent().find("ul.subnav").css({opacity:1});
		});
	});
	// Start comments rotator
	rotator();
});


// Initiate comments rotator
function rotator() {
	setInterval('rotate()',6000);
}
// Comments rotate function
function rotate(){
	if(rotations < total_comments-1){
		rotations++;
	} else {
		rotations = 0;
	}
	rotation_amount = rotations * -100;
	$('#rotator_block').css({opacity: 1.0}).animate({opacity: 0}, 1000, function(){
		$('#rotator_block img').css({top:rotation_amount});
		$('#rotator_block').css({opacity: 0}).animate({opacity: 1.1}, 1000);
	});	
}

function faq(){
	$('.faq_answer').hide();
	$('#faq li').click(function(e) {
    	$('#faq li').removeClass('faq_active');
		$('.faq_answer').slideUp('fast');
		 $('.faq_answer').promise().done(function() {
			 $(e.target).addClass('faq_active');
			$(e.target).children(':first').slideDown('medium');
		 });
	});
}

function patient_messages(){
	$(document).ready(function(){
		$('#send_message').hide();
		$('#send_file').hide();
	});	
	
	$('#message_but').click(function(e){
		$('#send_file').hide('fast');
		$('#send_message').show('fast');
	});
	$('#file_but').click(function(e){
		$('#send_message').hide('fast');
		$('#send_file').show('fast');
	});
	$('#UserPatientFileUploadForm').submit(function(e) {
		$( "#file_processing" ).dialog({height: 200, width: 400, modal: true, show: 'fade', title:'<span class="ui-icon ui-icon-folder-open"></span>Processing Request'});
	});
}

function patient_application(){
	var nextshow = null;
	$(document).ready(function(){
		$('.details').hide();
		$('#details_name').show();
	});
	$('#continue_but').click(function(e){
		if(validates($(this).attr('rel'))){
			nextshow = '#'+$(this).attr('rel');
			$('.details').hide('fast');
			$(nextshow).show('med');
			$('#continue_but').attr('rel', $(nextshow).attr('rel'));
		}
		
	});
}

function validates(idcheck){
	var alert_msg = null;
	switch(idcheck){
		case 'details_age':
			if($('#UserFirstName').val()){
				if($('#UserLastName').val()){
					alert_msg = null;
				} else {
					alert_msg = 'Please enter patients last name!';
				}
			} else {
				alert_msg = 'Please enter patients first name!';
			}
			
		break;
		
		case 'details_address':
			if($('#UserSex').val()){
				alert_msg = null;
			} else {
				alert_msg = 'Please select Male or Female!';	
			}
			
		break;
		
		case 'details_email':
			if($('#UserStreetAddress1').val()){
				if($('#UserState').val()){
					if($('#UserCity').val()){
						if($('#UserCountry').val()){
							alert_msg = null;
						}else{
							alert_msg = 'Please enter your country!';
						}
					}else{
						alert_msg = 'Please enter your city!';
					}
				}else{
					alert_msg = 'Please enter your state or region!';
				}
			
			} else {
				alert_msg = 'Please enter street address!';
			}
			
		break;
		
		case 'details_phone':
			if($('#UserEmailAddress').val()){
				alert_msg = null;
			} else {
				alert_msg ='Please enter your contact email address!';
			}
			
		break;
		
		case 'details_condition':
			if($('#UserPhoneNumber').val() || $('#UserMobileNumber').val()){
				alert_msg = null;
			} else {
				alert_msg = 'Please enter your phone or mobile number!';	
			}
			
		break;
		
		case 'details_history':
			if($('#UserDetailPatientCondition').val()){
				alert_msg = null;
			} else {
				alert_msg = 'Please provide information about your condition!';
			}
			
		break;
		
		case 'details_questions':
		
			if($('#UserDetailLastTreatment').val() != 'Not Provided'){
				
				if($('#UserDetailAppetite').val() != 'Not Provided'){
				
					if($('#UserDetailSleep').val() != 'Not Provided'){
				
						if($('#UserDetailExercise').val() != 'Not Provided'){
				
							if($('#UserDetailBowel').val() != 'Not Provided'){
				
								if($('#UserDetailWeight').val() != 'Not Provided'){
				
									if($('#UserDetailStress').val() != 'Not Provided'){
											
										alert_msg = null;
					
									} else {
										alert_msg = 'Please select an option for personal stress/worry question.';	
									}
					
								} else {
									alert_msg = 'Please select an option for weight question.';;	
								}
					
							} else {
								alert_msg = 'Please select an option for regular bowel regularity question.';	
							}
				
						} else {
							alert_msg = 'Please select an option for exercise question.';
						}
				
					} else {
						alert_msg = 'Please select an option for sleep question.';	
					}
				
				} else {
					alert_msg = 'Please select an option for appetite question.';	
				}
				
			} else {
				alert_msg = 'Please select an option for last treatment question.';
			}
		
		break;
		
		case 'send_doc':
			if($('#UserAgreeTerms').val()){
				$('#UserViewAccountForm').submit();
			} else {
				alert_msg = 'Please enter your name to accept Terms and Conditions!';	
			}
			
		break;
		
		
		default:
			alert_msg = null;
	}
	
	if(alert_msg){
		alert_msg = '<br /><div style="text-align:center; display:block;">' + alert_msg + '</div>';
		$('#alert_message').html(alert_msg);
		$( "#form_alerts" ).dialog({height: 120, width: 350, modal: true, show: 'fade', title:'<span class="ui-icon ui-icon-notice"></span>Form Error Detected!'});
	} else {
		return true;	
	}
}

function showNext(){
	$('.details').hide('med');	
}
