$(document).ready(function(){

	$("#co").autocomplete("/wspolne/services/", {
		delay: 100,
        width: 220,
        minChars: 2,
        max: 10,
        multiple: false,
        mustMatch: false,
        selectFirst: false,
        scroll: true,
        scrollHeight: 300,
	});
	
	$("#gdzie").autocomplete("/wspolne/cities/", {
		delay: 100,
        width: 220,
        minChars: 2,
        max: 8,
        multiple: false,
        mustMatch: false,
        selectFirst: false,
        scroll: true,
        scrollHeight: 300,
	});
		 
    /*$("#co").focus(function(){
		if($(this).val() == 'Szukaj')
			$(this).attr("value", "");
		else if($(this).val() == '')
			$(this).attr("value", "Szukaj");    			
	});*/
		 
		 
	$("#gdzie").keyup(function(){
		if($("#ucname").val()) {			
			if($("#ucname").attr("value") == $(this).attr("value").toLowerCase()) {
				$("#ucspan").css({display:"none"});				
			} else {
				$("#ucspan").css({display:"inline"});				
			}
		}
		
		if(!$("#uc").attr('checked')) {
		if($(this).val() == '') {
			$("#ulica").attr("disabled", "disabled");
			$("#ulica").css({'background-color':"#CCC"});
			$("#promien").attr("disabled", "disabled");
			$("#promien").css({'background-color':"#CCC"});
		} else {
			$("#ulica").attr("disabled", "");
			$("#ulica").css({'background-color':"#FFF"});
			$("#promien").attr("disabled", "");
			$("#promien").css({'background-color':"#FFF"});
		}}
	});
	
	$("#uc").change(function() {
		//$(".jqcity")
		//$("#cc").attr('checked','');
		if($(this).attr('checked')) {
			$("#gdzie").attr("disabled", "disabled");
			//$("#gdzie").attr("readonly", "readonly");
			$("#gdzie").css({'background-color':"#CCC"});
			/*$("#otherlabel").css({display:"inline"});*/
			
			$("#ulica").attr("disabled", "");
			$("#ulica").css({'background-color':"#FFF"});
			$("#promien").attr("disabled", "");
			$("#promien").css({'background-color':"#FFF"});
		} else {
			$("#gdzie").attr("disabled", "");
			//$("#gdzie").attr("readonly", "");
			$("#gdzie").css({'background-color':"#FFF"});
			/*$("#gdzie").css({display:"inline"});
			$("#otherlabel").css({display:"none"});*/
			if($("#gdzie").val() == '') {
				$("#ulica").attr("disabled", "disabled");
				$("#ulica").css({'background-color':"#CCC"});
				$("#promien").attr("disabled", "disabled");
				$("#promien").css({'background-color':"#CCC"});
			}
			
		}
		
		//id = $(this).attr("id").split("_");		
	});
	/*$("#cc").change(function() {		
		$("#uc").attr('checked','');
		if($(this).attr('checked')) {
			$("#gdzie").attr("readonly", "readonly");
			$("#gdzie").css({'background-color':"#CCC"});		
		} else {
			$("#gdzie").attr("readonly", "");
			$("#gdzie").css({'background-color':"#FFF"});		
		}			
	});*/
	
	$(".jqcity_old").change(function() {
		//$(".jqcity")
		if($(this).attr("value") == 2) {
			$("#gdzie").attr("readonly", "readonly");
			$("#gdzie").css({'background-color':"#CCC"}); 
			/*$("#otherlabel").css({display:"inline"});*/
		} else if($(this).attr("value") == 1) {
			$("#gdzie").attr("readonly", "");
			$("#gdzie").css({'background-color':"#FFF"});
			/*$("#gdzie").css({display:"inline"});
			$("#otherlabel").css({display:"none"});*/
		}
		
		//id = $(this).attr("id").split("_");		
	});
	
	/*$("#sp_categories").change(function() {
   		$("#sp_categories,input[type='submit']").attr("disabled", true);   		
     	$.get("/ajax/load-categories?cat_id="+$('#sp_categories').attr('value'),
        function(responseText) 
        { 
            $.taconite(responseText);
        } );
    }
	);*/ 
	
	$("input.marker").click(function() {
		
		var id = $(this).attr("id").split("_");
		var tempmarker
		if(id && id[1])
		{
			id = id[1];
		
			if(markers && markers[id])
			{
				tempmarker = markers[id];		
				if($(this).attr("value") == 1){
					$(this).attr("value", 0);
					tempmarker.hide();
				} else
				{	
					$(this).attr("value", 1);
					tempmarker.show();
				}
			}
		}
	});
	
	$("#locButton_notused").click(function() {		
		return;  
		if($("#typeshop").attr("value") || $("#typeworkshop").attr("value") || $("#typeschool").attr("value") || $("#typeinsurance").attr("value") || $("#typeother").attr("value"))  
		{   
			if($("#city").attr("value"))		
			{				
				var point;
				if($("#street").attr("value"))
					localizeGMapZoom($("#city").attr("value"), $("#street").attr("value"), false, true);
				else
					localizeGMapZoom($("#city").attr("value"), '', true, true);
								
		    } else {
		     	 $("#geoerr").attr("value",1);
		     	 $("#locform").submit();	    
		    }		    
	    }
	});
	
	$(".lastCommentsEntry").mouseover(function() {
		$(this).addClass("lastCommentEntryHover");
	});
	
	$(".lastCommentsEntry").mouseout(function() {
		$(this).removeClass("lastCommentEntryHover");
	});
	
});

function submitGoogleSearch()
{	
	
	
	if($("#co").attr("value") && $("#cco").attr("value"))
		$("#cco").attr("value", '');
	
	if($("#gdzie").attr("value") && $("#cgdzie").attr("value"))
		$("#cgdzie").attr("value", '');
	$("#locform").submit();	
	/*if($("#co").attr("value") || $("#cco").attr("value"))  
	{   
		$("#locform").submit();			    	    
	} else
	{
		$("#locPanelMessage").html("Wypełnij to pole!");
	
	}*/
}

function submitGoogleSearch_notused()
{
	return;
	if($("#co").attr("value"))  
	{   
			if($("#gdzie").attr("value"))		
			{			
				localizeGMapZoom($("#gdzie").attr("value"), 'locform');						
		    }				    	    
	} else
		$("#geoerr").attr("value",1);
	
	$("#locform").submit();
}

