
$(document).ready(function(){

$('a.schedule').click(function(){
	var thisID = $(this).attr("id").substr(5);
	$('div#box_'+thisID).toggle();
});

$('.calendar').datePicker({inline:true,selectMultiple:true,displayClose:true});

$(':button.hideScheduler').click(function(){
	//this should be a attr("class") instead of "name", but always broke for some reason
	var thisID = $(this).attr("name").substr(14);
	
	//get the Dates array and Times information
	var theDates = $('.calendar').dpGetSelected();
	var theTimes = $('.schedule_all_'+thisID).val();
	
	//keep the information that was already in there - duplication is handled later
	var prevInfo = $('#scheduler').val();
	
	//actually push the info into the hidden textbox in the aptCart form
	$('#scheduler').val(prevInfo+thisID+":"+theDates+"*"+theTimes+"|");
	
	//hide this box
	$('div#box_'+thisID).toggle();
});

$("textarea[id^='comments_']").blur(function(){
	var thisID = $(this).attr("id").substr(9);
	var prevInfo = $('#comm_specific').val();
	var thisText = $(this).val();
	
	$('#comm_specific').val(prevInfo+thisID+":"+thisText+"|");
});

//EMAIL CONTACT QUESTIONS
$('#send-email').focus(function(){
	if($('#email_questions').css('display') == 'none'){
		$('#email_questions').toggle();
	}
});

$('#send-email').blur(function(){
	if($('#send-email').val() == ''){ //empty field, so no #
		$('#email_questions').toggle();
	}
});

//PHONE CONTACT QUESTIONS
$('#send-number').focus(function(){
	if($('#phone_questions').css('display') == 'none'){
		$('#phone_questions').toggle();
	}
});

$('#send-number').blur(function(){
	if($('#send-number').val() == ''){ //empty field, so no #
		$('#phone_questions').toggle();
	}
});

//USERNAME/PASSWORD field hide/showing
$('#sign-up-user').focus(function(){
	if($('#signup_password_fields').css('display') == 'none'){
		$('#signup_password_fields').toggle();
	} else { alert('hi?'); }
});

$('#sign-up-user').blur(function(){
	if($('#sign-up-user').val() == ''){ //they didn't actually enter any text, so hide the password fields
		$('#signup_password_fields').toggle();
	}
});



//This could probably use some double-checking for possible problems
$("input[name='prefcontact']").click(function(){
	if($(this).val() == 'email'){
		if($('#email_contact').css('display') == 'none'){ $('#email_contact').toggle(); }
		if($('#phone_contact').css('display') !== 'none'){ $('#phone_contact').css('display','none'); }
	}	
	if($(this).val() == 'phone') {
		if($('#email_contact').css('display') !== 'none'){ $('#email_contact').css('display','none'); }
		if($('#phone_contact').css('display') == 'none'){ $('#phone_contact').toggle() }
	}
	if($(this).val() == 'both') {
		if($('#email_contact').css('display') == 'none'){ $('#email_contact').toggle(); }
		if($('#phone_contact').css('display') == 'none'){ $('#phone_contact').toggle(); }
	}
});

});
