$(document).ready(function() {
  	      
		// write the value of hidden dealer field to text output
		$('#dealerOutput').text( $('#txtDealerWrapper input').val() );
		
		// init fg menu
		$('.fg-button').hover
		(
			function() { $(this).removeClass('ui-state-default').addClass('ui-state-focus'); },
			function() { $(this).removeClass('ui-state-focus').addClass('ui-state-default'); }
		);

		$('#flyout').menu({
			content: $('#menuContent').html(),
			flyOut: true,
			showSpeed: 100,
			crossSpeed: 100,
			maxHeight: 180,
			width: 250
		});


		// is "IsCustomer" checkbox checked?
		var customerChecked = $('#txtIsCustomer:checked').val() ? true : false ;
		// show or hide dealer selector based on #is-customer-container
        if (customerChecked) {
			
            $('#is-customer-container').show();
			
			} else {
				
            $('#is-customer-container').hide();
			
			}
    
		function toggleDealerMenu() {
			var customerChecked = $('#txtIsCustomer:checked').val() ? true : false ;
			if (customerChecked) {		
				$('#is-customer-container').fadeIn(350);				
				} else {			
					$('#is-customer-container').fadeOut(350); 
					$('#dealerOutput').text('');
					$('#txtDealerWrapper input').val('');
					}
		}; 
		
		$('#txtIsCustomer').click(toggleDealerMenu);
	
}); // dom ready 


// form validation
		
		// validate email address
		function emailValidate(email){
			var emailRegEx = /^([a-zA-Z0-9_\.\-\'\+])+\@(([a-zA-Z0-9\-])+\.)+[a-zA-Z0-9]{2,4}$/;
			if(email.match(emailRegEx)){
				return true;
				} else {
				return false;
				}
			}
			
		function formValidate() {	
		
			var form = $('#sub-form');
		
			var msgPreamble = '<p>Please correct the following errors:</p>';
			var msg = '<ul>';
			
			var name 		= $('#name').val();
			var email 		= $('#jdjdf-jdjdf').val();
			
			var valScore	= 0;	
			
			
			if (name == '') {
				msg += '<li>Please provide your full name</li>';
				
				} else {
					
				valScore ++;
				
					}
							
			if (email == '' || emailValidate(email) == false) {
				msg += '<li>Please provide a valid email address</li>';
				
				} else {
					
				valScore ++;
				
					}
			
			msg += '</ul>';
	
			// did form validate?
			if (valScore > 1) {
				return true;
			
			} else {
			
				$("#dialog").html(msgPreamble + msg);
				
				$("#dialog").dialog({
                    buttons: { "Ok": function() { $(this).dialog("close"); } },
                    draggable: false,
                    modal: true,
                    title: "The form has not been completed",
                    resizable: false,
					show: "clip",
                    hide: "clip",
                    width: 380
                });
				
                $("#dialog").dialog('open');
				
				return false
				
			}
	}