// JavaScript Document
// Custom JavaScript for BizBen/360 LPO

function switchPanel(panel) {
	var clickId = panel;

	switch(clickId) {
		case "bblpo_search_taba" :
			popUp_CloseAll();
			$('#bblpo_search_panel_a').css('display','block');
			$('#bblpo_search_panel_a').css('visibility','visible');
			$('#bblpo_search_taba').addClass(" selected-tab");
		
			$('#bblpo_search_panel_b').css('display','none');
			$('#bblpo_search_panel_b').css('visibility','hidden');
			$('#bblpo_search_tabb').removeClass(" selected-tab");
		
		break;
		
		case "bblpo_search_tabb" :
			popUp_CloseAll();
			if ($('#bblpo_form_busType').html() == '') {
				$.ajax({url: 'business-type-options.php', success: function(data) { 
																			$('#bblpo_form_busType').html(data); 
																			$('#bblpo_search_panel_b').css('display','block');
																			$('#bblpo_search_panel_b').css('visibility','visible');
																			$('#bblpo_search_tabb').addClass(" selected-tab");
																		
																			$('#bblpo_search_panel_a').css('display','none');
																			$('#bblpo_search_panel_a').css('visibility','hidden');
																			$('#bblpo_search_taba').removeClass(" selected-tab");
																			}});	
			} else {
				$('#bblpo_search_panel_b').css('display','block');
				$('#bblpo_search_panel_b').css('visibility','visible');
				$('#bblpo_search_tabb').addClass(" selected-tab");
			
				$('#bblpo_search_panel_a').css('display','none');
				$('#bblpo_search_panel_a').css('visibility','hidden');
				$('#bblpo_search_taba').removeClass(" selected-tab");
			}

		
		break;
		
		case "bblpo_search_tabc":
			document.location = 'http://www.bizben.com/sell-a-business.php';
/*			$('#bblpo_search_panel_c').css('display','block');
			$('#bblpo_search_panel_c').css('visibility','visible');
			$('#bblpo_search_tabc').addClass(" selected-tab");
				
			$('#bblpo_search_panel_b').css('display','none');
			$('#bblpo_search_panel_b').css('visibility','hidden');
			$('#bblpo_search_tabb').removeClass(" selected-tab");
			
			$('#bblpo_search_panel_a').css('display','none');
			$('#bblpo_search_panel_a').css('visibility','hidden');
			$('#bblpo_search_taba').removeClass(" selected-tab");		
*/		break;
	}
	return false;
		
}

function popUp_Click(el, x, y, url) {
	$('#bblpo_BusAreaPopup').hide();
	$('#bblpo_BusCategoryPopup').hide();
	
	if (el.html() == '') {
		$.ajax({url: url,
			success: function(data) {
				el.html(data);
				$("#backgroundPopup").show(); 
				//el.css('display','block');
				//el.css('visibility','visible');
				
				el.css('position', 'absolute');
				el.css('left', x);
				el.css('top', y);
				el.css('display','inline-table');
				el.css('visibility','visible');				
								
				el.fadeIn("slow");
				
			}
		});
	} else {
		$("#backgroundPopup").show(); 
		
		el.css('position', 'absolute');
		el.css('left', x);
		el.css('top', y);
		el.css('display','inline-table');
		el.css('visibility','visible');

		el.fadeIn("slow");

	}
	return false;
}
function popUp_Close(el, x, y) {
    el.css('position', 'absolute');
	el.css('left', x);
	el.css('top', y);
	
	el.css('display','block');
    el.css('visibility','hidden');
	el.fadeOut(100);
	
	el.css('display','block');
    el.css('visibility','visible');
	$("#backgroundPopup").hide();
	
	$('#bblpo-search-sel1').attr("src", "images/lpo_search_fakeselect2.png");
	$('#bblpo-search-sel2').attr("src", "images/lpo_search_fakeselect2.png");
	$('#bblpo-search-sel3').attr("src", "images/lpo_search_fakeselect2.png");
	
	return false;
}
function popUp_CloseAll() {
	$('.bblpo-BusPopup').fadeOut(100);
	$("#backgroundPopup").hide();
	
	$('#bblpo-search-sel1').attr("src", "images/lpo_search_fakeselect2.png");
	$('#bblpo-search-sel2').attr("src", "images/lpo_search_fakeselect2.png");
	$('#bblpo-search-sel3').attr("src", "images/lpo_search_fakeselect2.png");
	return false;
}
function lpo_SearchCheckAll(catName) {
	$('.'+ catName).attr('checked', 'true');
	
}


function lpo_SearchUnCheckAll(catName) {
		$('.' +catName).attr('checked', '');
}


function lpo_SearchApplyGeoArea(el) {
	var allVals = [];
	$("input.busArea:checkbox:checked").each(function() {
       allVals.push($(this).val());
     });

	$('input.bblpo-form-geoArea').each(function() {
      	$(this).val(allVals.join(','));
     });
	var cEl = $("#" + el);
	
	popUp_Close(cEl) ;
}

function lpo_SearchApplyBusType(el) {
	var allVals = [];
	$("input.busCategory:checkbox:checked").each(function() {
       allVals.push($(this).val());
     });
	$('.bblpo-form-busCat').val(allVals.join(','));
	var cEl = $("#" + el);
	popUp_Close(cEl) ;
}

/*# //Click out event!  
# $("#backgroundPopup").click(function(){  
# disablePopup();  
# });  
# //Press Escape event!  
# $(document).keypress(function(e){  
# if(e.keyCode==27 &amp;amp;amp;&amp;amp;amp; popupStatus==1){  
# disablePopup();  
# }  
# });  */

// Install various popup handlers when the document is finished loading.
jQuery(document).ready(function() {
	$('#bblpo-search-sel1').click(function(e) {
										   var clickEl = $('#bblpo-search-sel1');
										   popUp_Click($('#bblpo_BusCategoryPopup'),  clickEl.offset().left+2, clickEl.offset().top +20, 'bblpo_BusCategoryPopup.php');
										   clickEl.attr("src", "images/lpo_search_fakeselect3.png");
										   return false;
										   });

	$('#bblpo-search-sel2').click(function(e) {
										   var clickEl = $('#bblpo-search-sel2');
										   popUp_Click($('#bblpo_BusAreaPopup'), clickEl.offset().left+2, clickEl.offset().top +20, 'bblpo_BusAreaPopup.php');
										   clickEl.attr("src", "images/lpo_search_fakeselect3.png");
										   return false;
										   });
	$('#bblpo-search-sel3').click(function(e) {
										   var clickEl = $('#bblpo-search-sel3');
										   popUp_Click($('#bblpo_BusAreaPopup'), clickEl.offset().left+2, clickEl.offset().top +20, 'bblpo_BusAreaPopup.php');
										   clickEl.attr("src", "images/lpo_search_fakeselect3.png");
											return false;
										   });	
	$("#backgroundPopup").click(function(){  
								popUp_CloseAll();
								});	
	

		$(".bblpo-searchquery").click(function(e) {
										   $(".bblpo-searchquery").val('');
										   return false;
										   }
									 );	
		$(".bblpo-searchquery").blur(function(e) {
											if ($(".bblpo-searchquery").val() == '') {
										   		$(".bblpo-searchquery").val('Search all of BizBen');
											}
										   	return false;
										   }
									 );	
		
		$(".bblpo-alertemail").click(function(e) {
										   $(".bblpo-alertemail").val('');
										   return false;
										   }
									 );	
		$(".bblpo-alertemail").blur(function(e) {
											if ($(".bblpo-alertemail").val() == '') {
										   		$(".bblpo-alertemail").val('Enter Email Address');
											}
										   	return false;
										   }
									 );	
		$(".bblpo-formhider").click(function(e) {
													popUp_CloseAll();
													if ($('.bblpo-search-panel').css('height') == '30px') {
														$('.bblpo-search-panel').css('height', '285px');
														$('.bblpo-search-panel').css('margin-bottom', '4px');
														switchPanel('bblpo_search_taba');
														$('#bblpo_search_panel_a').show();
													}
													else {
														$('#bblpo_search_panel_a').hide();
														$('#bblpo_search_panel_b').hide();
														$('.bblpo-search-panel').css('height', '30px');
													}
													return false;
											   		}
									 );
		
	});


