/****************************
	VTCHAMBER Global js
****************************/


function jumpMenu(selObj,restore){ //v3.0
  var targ = "self";
  
 eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function gup(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
	return results[1];
	
}

function makeSublist(parent,child,childVal)
{
	$("body").append("<select style='display:none' id='"+parent+child+"'></select>");
	$('#'+parent+child).html($("#"+child+" option"));
	
	var parentValue = $('#'+parent).attr('value');
	
	if (parentValue == "all") {
		$('#'+child).html($("#"+parent+child+" option").clone());
	} else {
		$('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());
		$('#'+child).prepend("<option value='all'> -- All Towns -- </option>");	
	}
		
	childVal = (typeof childVal == "undefined")? "" : childVal ;
	$("#"+child+' option[@value="'+ childVal +'"]').attr('selected','selected');
	
	$("#"+child).val( gup("city").replace(/\+/g, " ") );
	
	$('#'+parent).change(function(){
			var parentValue = $('#'+parent).attr('value');
			
			if (parentValue == "" || parentValue == "all") {
				$('#'+child).html($("#"+parent+child+" option").clone());
			} else {
				$('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());
				$('#'+child).prepend("<option value='all'> -- All Towns -- </option>");					
			}
			
			//set child list to all option
			$("#"+child).attr('value','all');
			
			$('#'+child).trigger("change");
			$('#'+child).focus();
	});
	
	//get class name and split on underscore. set region2 to val for full list
	$('#'+child).change(function(){
		var tempVal = $('#'+child+ " option:selected").attr("class");
		tempVal = tempVal.split("_");
		$('input#region2').val(tempVal[1]);
	});
}

$(document).ready(function(){

	//dependent region >> city selector
	makeSublist('region_select','city_select', ' ');

	//http://code.google.com/p/jquery-checkbox/
	$('#search-members-form input:checkbox').checkbox();

	//$('#search-members-form ul li.list-header ul.sub-list').addClass('hidden');
	
	//toggle children lists
	$('#search-members-form ul li.list-header').children('label').click(function(){
		
		var thisChecked = $(this).children('span.jquery-checkbox').hasClass('jquery-checkbox-checked');
		
		if (thisChecked == false) {
			
			//show child list
			$(this).parent('li.list-header').children('ul.sub-list').show();
			//toggle ON children check states
			//$(this).parent('li.list-header').children('ul.sub-list').checkCheckboxes();
			
		} else if (thisChecked == true) {
			
			//hide child lists
			$(this).parent('li.list-header').children('ul.sub-list').hide();
			//toggle OFF child children check states
			$(this).parent('li.list-header').children('ul.sub-list').unCheckCheckboxes();
		}
	});
	
	//select ALL checkboxes
	$('a.select-all').click(function(){
		$('fieldset.type > div.col-a, fieldset.type > div.col-b').checkCheckboxes();
		$('fieldset.type ul.sub-list').show();
		return false;
	});	

	//select NO checkboxes
	$('a.select-none').click(function(){
		$('fieldset.type').unCheckCheckboxes();
		$('fieldset.type ul.sub-list').hide();
		return false;
	});	
	
	//refine search link - toogle search form
	$('a.refine-search').toggle(function(){
		$('#search-members-form').fadeIn(100).slideDown(500);
		$(this).text("Hide Search").addClass('hide-search');
		return false;
	}, function(){
		$('#search-members-form').fadeOut(100).slideUp(500);
		$(this).text("Refine Search").removeClass('hide-search');
		return false;
	});
	
	
	
});