// JavaScript Document
$(document).ready(function(){

	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});


	$(".state_id").change(function(){
		var state_id 	= document.getElementById('state_id').value;
		var state_id	= $(this).val();

		$("#installation").html('<option value=""> loading... </option>');

		if(state_id == ''){
			return false();
		}else{
			var dataString = 'doCase=loadInstallations&state_id='+ state_id;
			$.ajax({
				type: "POST",
				url: "http://www.militaryforsaleforrent.com/ajax.php",
				data: dataString,
				cache: false,
				success: function(html){
					$("#installation").html(html);
				}
			});
		}
	});	
	
	jQuery.validator.messages.required = "";

	$("#frmSearch").validate({	
								  
		invalidHandler: function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1
					? 'You missed 1 field. It has been highlighted below'
					: 'You missed ' + errors + ' fields.  They have been highlighted below.';
				//$("div.error span").html(message);
				//$("div.error").show();
				//alert(message);
			} else {
				$("div.error").hide();
			}
		},
        errorElement: 'span',
		onkeyup: false,
		submitHandler: function() {

//			var state_id 	= document.getElementById('state_id').value;
//			var installation = document.getElementById('installation').value;
			
//			alert(state_id + ' => ' + installation);
			
			document.getElementById('frmSearch').submit();
//			var g_id = document.getElementById('g_id').value;
//			alert(g_id);
//
//			var dataString = $("#frmSearch").serialize();
//			
//			$.ajax({
//				type: "POST",
//				url: "http://www.militaryforsaleforrent.com/ajax.php",
//				data: dataString,
//				cache: false,
//				success: function(retVal){
//					if(retVal == g_id){
//						window.location.href = 'members.php?page=member_listing_photos&g_id='+retVal;
//					}else{
//						alert('You have not updated any information.\r\n\r\nIf you made any changes and getting this message - please contact support!');
//						return false;
//					}
//				}
//			});		
		}
	});	
	

});

