SITEPATH = "http://www.lista3.com/";

function makeSublist(parent,child,isSubselectOptional,childVal) {
	$("body").append("<select style='display:none' id='"+parent+child+"'></select>");
	$('#'+parent+child).html($("#"+child+" option"));
	
	var parentValue = $('#'+parent).attr('value');
	$('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());
	
	childVal = (typeof childVal == "undefined")? "" : childVal ;
	$("#"+child+' option[@value="'+ childVal +'"]').attr('selected','selected');
	
	$('#'+parent).change( 
		function() {
			var parentValue = $('#'+parent).attr('value');
			$('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());
			if(isSubselectOptional) $('#'+child).prepend("<option value='none'> -- Select -- </option>");
			$('#'+child).trigger("change");
      $('#'+child).focus();
		}
	);
}


$(document).ready(function() {
	makeSublist('categories','subcategories', false, '');
	makeSublist('countries','states', false, '');	
	makeSublist('states','cities', false, '');	
});

function selectUsersIndex(){

	var country = $("#country").val();
	var state = $("#state").val();
	var city = $("#city").val();
	var search = $("#search").val();
	
	console.log(SITEPATH + "users/index/country:" + country + "/state:" + state + "/city:" + city + "/search:" + search);
	
	document.location = SITEPATH + "users/index/country:" + country + "/state:" + state + "/city:" + city + "/search:" + search;

}

function selectServicesIndex() {

	var category = $("#categories").val();
	var subcategory = $("#subcategories").val();
	var search = $("#search").val();
 
 document.location = SITEPATH + "services/index/search:" + search + "/category:" + category + "/subcategory:" + subcategory;
 
};

function selectSiteIndex(url) {

	var country = $("#countries").val();
	var state = $("#states").val();
	var city = $("#cities").val();
 
	document.location = url + "/country:" + country + "/state:" + state + "/city:" + city;
 
};

function leftSearch(url) {

	var search = $("#ServiceSearch").val();
 
	document.location = url + "/search:" + search;
 
};