$(document).ready(function() {
	
	//var wlbl = $(".searchTabsInputText").width();
	//$("#displaySearchInfoText").width(wlbl);
	$("#srcHow").height("26px");
	$("#topSearchKeywordsBox").css("background-color","#fff");
	$("#topSearchKeywordsBox").css("color","#92B139");
	
	
	var $tabs = $("#tabs").tabs({
		selected:3
	});
	var selected = "";
	//document.getElementById("srcForm").getAttribute("action") = 'http://www.greekjustice.gr/Αναζήτηση/';
	$("#srcForm").attr('action','http://www.greekjustice.gr/Αναζήτηση/');
	
    $("#tabs").bind('tabsshow',function(event, ui) {
    	$(".searchTabsInputText").val($(ui.tab).text());
    	selected = $tabs.tabs('option','selected');
    	if (selected==1) {
    		if ($("#srcHow").val()==1) {
    			$("#myKeywords").attr('name','keywords[exact_phrase]');
    			document.getElementById("srcForm").action = '/search_results_jobs/?action=search';
    			//$("#srcForm").attr('action','/demo/search_results_jobs/');
    		} else {
    			$("#myKeywords").attr('name','keywords[like]');
    			//$("#srcForm").attr('action','/demo/search_results_jobs/');
    			document.getElementById("srcForm").action = '/search_results_jobs/?action=search';
    		}
    	} else {
    		//$("#srcForm").attr('action','http://greekjustice.ath.cx/Αναζήτηση/');
    		document.getElementById("srcForm").action = 'http://www.greekjustice.gr/Αναζήτηση/';
    	}
    	
    	
    	return false;
    });
	
    $("#topSearchKeywordsBox").autocomplete({
    	minLength:3,
    	source: function(req, add){
	    	$.getJSON("http://www.greekjustice.gr/templates/default/js/greekjustice_js.php?task=getkeywordsList&callback=?", req, function(data) {
		    	var suggestions = [];
		    	$.each(data, function(i, val){
		    		suggestions.push(val.key);
		    	});
		    	add(suggestions);
		   	});
	    }
    });
    
    $("#topSearchKeywordsBox").live('click',function() {
    	$(this).css("background-color","#fff");
    	$(this).css("color","#92B139");
    	$(this).val("");
    });
	
	$(".searchTabsInputButton4").live("click",function() {
		selected = $tabs.tabs('option','selected');
		$("#myKeywords").attr("value",$(".searchTabsInputText").val());
		$("#srcForm").submit();
		return false;
	});	
});
