(function($) {
  function onChange(event) {

 	   	switch(this.id)
 	   	{
 	   	
 	   		case 'activity':
 	   			$("#type option").remove();
 	   			$("#location option").remove();
 	   			$("#typeSelectContainer").removeClass("LC-step2").addClass("LC-step2-disabled");
 	   			$("#locationSelectContainer").removeClass("LC-step3").addClass("LC-step3-disabled");
 	   			var actId = $("#activity").val();
 	   			if(cmDataType[actId] && cmDataType[actId])
 	   			{
 	   				$("#typeSelectContainer").removeClass("LC-step2-disabled").addClass("LC-step2");
 	   				jQuery('#type').append('<option selecte="s"></option>');
 	   				$.each(cmDataType[actId], function(key, value) {
 	   				 jQuery('#type').append(jQuery('<option></option>').val(key).html(value));
 	   				}); 
 	   			}
 	   		break;
 	   		case 'type':
 	   			$("#location option").remove();
 	   			$("#locationSelectContainer").removeClass("LC-step3").addClass("LC-step3-disabled");
 	   			var actId = $("#activity").val();
 	   			var typeId = $("#type").val();
 	   			
 	   			if(cmDataLocation && cmDataLocation[actId] && cmDataLocation[actId][typeId])
 	   			{
 	   				
 	   				$("#locationSelectContainer").removeClass("LC-step3-disabled").addClass("LC-step3");
 	   				jQuery('#location').append('<option selecte="s"></option>');
 	   				
 	   				$.each(cmDataLocation[actId][typeId], function(key, value) {
 	   				
 	   				 jQuery('#location').append(jQuery('<option></option>').val(key).html(value));
 	   				}); 
 	   			}
 	   		break;
 	   	}
 	
 		if(sselect) 
 			$('#type, #location').resetSS();
   }
   
   $.contactMap = {
         init: function() {
         	$("#activity").change(onChange);
         	$("#type").change(onChange);
         	$("#location").change(onChange);
        },
        submit:function()
		{
			var url = '/'+baseLocation;
			if($("#activity").val() && $("#type").val() && $('#location').val())
			{
				var reg=new RegExp("[^0-9]",'g');
				var activityVal = $("#activity").val();
				activityVal=activityVal.replace(reg,'');
				url += '/'+$("#activity option:selected").text()+'-a'+activityVal+'/'+$("#type option:selected").text()+'-t'+$("#type").val()+'/'+$("#location option:selected").text()+'-l'+$("#location").val()+'/';
				window.location.replace(url);
			}
		}
       
        
    }
})(jQuery);

$(document).ready(function(){
     
     jQuery.contactMap.init();
   	    
});
