﻿$(function() {
	$.datepicker.setDefaults($.extend({
		buttonImage: '/Resources/Common/Images/Icons/calendar.gif',
		buttonImageOnly: true,
		buttonText: 'Select a Date',
		changeMonth: true,
		changeYear: true,
		showButtonPanel: true,
		showOn: 'button'
	}));
	$('.datepicker-pastdate').datepicker({
		minDate: '-100y',
		maxDate: '-1y',
		showButtonPanel: true,
		yearRange: '-100:0'
	});
	$('.datepicker-yearpast').datepicker({
		minDate: '-1y',
		maxDate: 0,
		yearRange: '-1:0'
	});
	$('.datepicker-yearahead').datepicker({
		minDate: 0,
		maxDate: 365
	});
	$('.datepicker-pastdate, .datepicker-yearpast, .datepicker-yearahead').mask('99/99/9999');
	$('.txt-phone').mask('(999) 999-9999? x99999');
	$('.txt-zip').mask('99999');
	$('.txt-ssn').mask('999-99-9999');

	// Stroke Assessment
	// Slideshow
	if ($('#umcprereg .stroke-assessment-slideshow').length > 1) {
		$('#umcprereg .stroke-assessment-slideshow').cycle({ fx: 'fade', speed: '500', timeout: '5000' });
	}

	// How Did You Hear About Us
	$('#umcprereg select[id$=ddlHow]').change(function() {
		$('#umcprereg #txtSource').val('');
		if ($(this).val() == 'Magazine') {
			$('#umcprereg #lblSource').html('Which magazine?');
			$('#umcprereg #txtSource').parent('div').fadeIn('medium', function() {
				$(this).removeClass('hidden');
				$(this).children('input').focus();
			});
			$('#umcprereg input[id$=txtHowDidYouHearAboutUs]').val('Magazine : Unknown');
			$('#umcprereg #txtSource').change(function() {
				var a = 'Unknown';
				if ($(this).val() != '')
					a = $(this).val();
				$('#umcprereg input[id$=txtHowDidYouHearAboutUs]').val('Magazine : ' + a);
			});
		} else if ($(this).val() == 'Newspaper') {
			$('#umcprereg #lblSource').html('Which newspaper?');
			$('#umcprereg #txtSource').parent('div').fadeIn('medium', function() {
				$(this).removeClass('hidden');
				$(this).children('input').focus();
			});
			$('#umcprereg input[id$=txtHowDidYouHearAboutUs]').val('Newspaper : Unknown');
			$('#umcprereg #txtSource').change(function() {
				var a = 'Unknown';
				if ($(this).val() != '')
					a = $(this).val();
				$('#umcprereg input[id$=txtHowDidYouHearAboutUs]').val('Newspaper : ' + a);
			});
		} else if ($(this).val() == 'Online') {
			$('#umcprereg #lblSource').html('Which website?');
			$('#umcprereg #txtSource').parent('div').fadeIn('medium', function() {
				$(this).removeClass('hidden');
				$(this).children('input').focus();
			});
			$('#umcprereg input[id$=txtHowDidYouHearAboutUs]').val('Online : Unknown');
			$('#umcprereg #txtSource').change(function() {
				var a = 'Unknown';
				if ($(this).val() != '')
					a = $(this).val();
				$('#umcprereg input[id$=txtHowDidYouHearAboutUs]').val('Online : ' + a);
			});
		} else if ($(this).val() == 'Radio') {
			$('#umcprereg #lblSource').html('What station?');
			$('#umcprereg #txtSource').parent('div').fadeIn('medium', function() {
				$(this).removeClass('hidden');
				$(this).children('input').focus();
			});
			$('#umcprereg input[id$=txtHowDidYouHearAboutUs]').val('Radio : Unknown');
			$('#umcprereg #txtSource').change(function() {
				var a = 'Unknown';
				if ($(this).val() != '')
					a = $(this).val();
				$('#umcprereg input[id$=txtHowDidYouHearAboutUs]').val('Radio : ' + a);
			});
		} else if ($(this).val() == 'Other') {
			$('#umcprereg #lblSource').html('What source?');
			$('#umcprereg #txtSource').parent('div').fadeIn('medium', function() {
				$(this).removeClass('hidden');
				$(this).children('input').focus();
			});
			$('#umcprereg input[id$=txtHowDidYouHearAboutUs]').val('Other : Unknown');
			$('#umcprereg #txtSource').change(function() {
				var a = 'Unknown';
				if ($(this).val() != '')
					a = $(this).val();
				$('#umcprereg input[id$=txtHowDidYouHearAboutUs]').val('Other : ' + a);
			});
		} else {
			$('#umcprereg input[id$=txtHowDidYouHearAboutUs]').val($(this).val());
			$('#umcprereg #txtSource').val('');
			$('#umcprereg #txtSource').parent('div').fadeOut('fast', function() {
				$(this).addClass('hidden');
			});
		}
	});

	$('#umcprereg .left-section label a[title]').qtip({
		'fontSize': '11px',
		position: {
			corner: {
				target: 'topMiddle',
				tooltip: 'bottomMiddle'
			}
		},
		style: {
			background: '#eaf6fe',
			border: {
				width: 1,
				radius: 0,
				color: '#8bbade'
			},
			color: '#666',
			fontSize: '11px',
			lineHeight: '20px',
			name: 'dark',
			padding: 10,
			tip: 'bottomMiddle'
		}
	});

	// Tidbits
	var t = { timer: null }
	var a = null;
	$('#umcprereg .left-section .field').focusin(function() {
		a = $(this).attr('class').substring($(this).attr('class').indexOf('field-') + 6);
		$('#umcprereg .right-section .tidbit-' + a).fadeIn('slow');
	}).focusout(function() {
		setTimeout(function() {
			$('#umcprereg .right-section .tidbit').not('#umcprereg .right-section .tidbit-' + a).fadeOut('medium');
		}, 100);
	});
	$('#umcprereg .left-section').focusin(function() {
		clearTimeout(t.timer);
	});
	$('#umcprereg .left-section').focusout(function() {
		t.timer = setTimeout(function() {
			a = null;
			$('#umcprereg .right-section .tidbit').fadeOut('medium');
		}, 500);
	});
});
