/**
 * @author eli geske
 */

 
 
/* POPUP BOX */
$(document).ready(function(){	
	// DEFINE DIALOG BOX
	$("#dialogPop").dialog({
		autoOpen: false,
		bgiframe: true,
		height: 400,
		width: 350,
		modal: true
	});
	
	$('.agency_container a').click(function(){
		$link = $(this).attr('href');	
		$('#dialogPop').dialog('open');
		$('#popFrame').attr('src', $link );
		return false;
	});		
});


/* HIDE/SHOW SEARCH FROM */
$(document).ready(function(){

	if($('.agencyList').length > 0){
		$('.post').slideUp();
		$('#become_anAgent_form').slideUp();
		$('#newSearch').fadeIn();
	}
	
	$('#newSearch').click(function(){
		$('#newSearch').fadeOut();
		$('#become_anAgent_form').slideDown();
		$('.agencyList').hide();
	});

});
 
/* SEARCH FORM - enables/disables form buttons/inputs */
$(document).ready(function(){
	checkZipDisableButton();
	//changeCity();
	
	// GET COUNTIES
	//getCounty();
	
//	$("#county").click(function(){
//
//		if($('#county').val() == ""){
//			getCounty();
//		}
//		$('#zipcode').val('');
//		changeCity();
//		
//	});

	$("#zipcode").click(function(){
//		$('#county').html('<option value="">Select One</option>');
//		$('#city').attr("disabled", "disabled");
//		$('#city').html("<option value=''>Select One</option>");
		checkZipDisableButton();
	});	
	$('#zipcode').keyup(function(){
		checkZipDisableButton();					
	});
	
//	$("#county").change(function(){
//		$county = $('#county').val();
//		
//		var randomnumber=Math.floor(Math.random()*11);
//		$url = "/wp-content/themes/macneill2/ajax/countyToCity.php?type=city&val=" + $county + "&rand=" + randomnumber;
//		
//		if($county.length > 1){	
//			$.get($url,{city: "city"}, function(data){
//
//				$('#city').removeAttr("disabled");
//				$('#city').html(data);
//				changeCity();
//			});					
//		}else{
//			$('#city').attr("disabled", "disabled");
//			$('#city').html("<option value=''>Select One</option>");
//			changeCity();
//		}
//		
//	});
	
//	$("#city").change(function(){
//		$city = $('#city').val();
//		changeCity($city);
//	});
	
	$('#agencyList a').click(function(){
		$url=$(this).attr('href');
		$('#popFrame').attr('src', $url);
		
		$('#dialog').dialog('open');
		return false;
	});

//	function getCounty(){
//		$state = "FL";
//		var randomnumber=Math.floor(Math.random()*11);
//		$url = "/wp-content/themes/macneill2/ajax/countyToCity.php?type=county&val=" + $state + "&rand=" + randomnumber;
//		$.get($url, function(data){
//			$('#county').html(data);
//		});
//	}
	
	$('#btn_findAgent_yellow').click(function(){	
		if($('#btn_findAgent_yellow').hasClass('find_agent_disabled'))	
			$('#become_anAgent_form').submit();
	});
	
	function checkZipDisableButton(){
		$zipcodeValue = $('#zipcode').val();
			
			if($zipcodeValue.length == 5 && isNaN($zipcodeValue) == false){
				//$('#btn_findAgent_yellow').removeAttr("disabled");
				$('#btn_findAgent_yellow').attr("src", "/wp-content/themes/macneill2/images/btn_findAgent_yellow.gif");
				$('#btn_findAgent_yellow').addClass('find_agent_disabled');
//				$('#btn_findAgent_yellow').css({
//										'background':'url(/wp-content/themes/macneill2/images/btn_findAgent_yellow.gif)',
//										'cursor':'pointer',
//										'height':'35px',
//										'width':'138px'});
			}else{
				//$('#btn_findAgent_yellow').attr("disabled", "disabled");
				$('#btn_findAgent_yellow').attr("src", "/wp-content/themes/macneill2/images/btn_findAgent_yellow_disabled.gif");
				$('#btn_findAgent_yellow').removeClass('find_agent_disabled');
//				$('#btn_findAgent_yellow').css({
//										'background':'url(/wp-content/themes/macneill2/images/btn_findAgent_yellow_disabled.gif)',
//										'cursor':'default'});
			}
	}
	

//	 function changeCity(){
//		$val = $('#city').val();
//		if ($val.length > 1) {
//			$('#btn_findAgent_yellow').removeAttr("disabled");
//			$('#btn_findAgent_yellow').css({
//										'background':'url(/wp-content/themes/macneill2/images/btn_findAgent_yellow.gif)',
//										'cursor':'pointer'});
//			
//			
//		}else{
//			$('#btn_findAgent_yellow').attr("disabled", "disabled");
//			$('#btn_findAgent_yellow').css({
//										'background':'url(/wp-content/themes/macneill2/images/btn_findAgent_yellow_disabled.gif)',
//										'cursor':'default'});
//		}
//
// 	}	
	
 });
 
