function submit_form_statie()
{
	var statie = document.getElementById('statie').value;
	
	if (statie.replace(/^\s+|\s+$/g, '') == '')
		statie = 'statie';
	
	statie = statie.replace(/^\s+|\s+$/g, '');
	statie = URLEncode(statie.replace(/\s+/g, '_'));
	
	document.getElementById('commit-form').value = 'commit';
	document.getElementById('mersul_trenurilor_form').action = LINK_HOST+'/Statie'+'/'+statie; 
	
	document.forms.mersul_trenurilor_form.submit();
}

YAHOO.example.ACFlatData = function() {
    var oACDS;
    var oAutoComp1;

    return {
        init: function() {
    	var search_type = document.getElementById('search-type').value;
    	if (search_type == 'tren' || search_type == 'statie')
    	{
    		
    		oACDS = new YAHOO.widget.DS_XHR(LINK_HOST+"/lib/autocomplete_statie.php", ["\n", "\t"]);
    		oACDS.responseType = YAHOO.widget.DS_XHR.TYPE_FLAT;
    		oACDS.maxCacheEntries = 1;
    		oACDS.queryMatchSubset = true;
    		
    		oAutoComp1 = new YAHOO.widget.AutoComplete('statie','ysearchcontainer3', oACDS);
            oAutoComp1.minQueryLength = 2;
            oAutoComp1.animVert = false; 
            oAutoComp1.animHoriz = false; 
            oAutoComp1.maxResultsDisplayed = 15;
			oAutoComp1.useIFrame = true;
             	
            oAutoComp1.formatResult = function(oResultItem, sQuery) {
                var sKey = oResultItem[0];
                var name  = formName(sKey, sQuery, sQuery.length);
                var aMarkup = ["<div class='ysearchresult'><div class='ysearchquery'>",
                  	name,
                    "</div></div>"];
                return (aMarkup.join(""));
            };
            
    	}
            },
            
        validateForm: function() {
            // Validate form inputs here
            return false;
        }
    };
} ();

function formName(name, strSearch, howLong)
{  
	var i = 0;               	
	var result = "";
	do
	{
		name2 = name.toLowerCase();
		strSearch2 = strSearch.toLowerCase();
		position = name2.search(strSearch2);
		if (position != -1)
		{
			if (position != 0)
			{
				result += "<span>";
				result += name.substr(0, position);
				result += "<span style='font-weight:bold;'>";
				result += name.substr(position, howLong);
				result += "</span>";
				name = name.substr(position+howLong, name.length-position-howLong);
				result += "</span>";
			}
			else
			{
				result += "<span>";
				result += "<span style='font-weight:bold;'>";
				result += name.substr(0, howLong);
				result += "</span>";
				name = name.substr(howLong, name.length-howLong);
				result += "</span>";
			}
		}
		else
		{
			result += name;
			name = "";
		}
	}while (name != "")
	
	return result;
	
}
function show_sosiri() 
{
	document.getElementById('span_plecari').style.display = "none";
	document.getElementById('span_plecari').style.visiblity = "hidden";
	document.getElementById('span_sosiri').style.display = "block";
	document.getElementById('span_sosiri').style.visiblity = "visible";
	
}

function show_plecari() 
{
	document.getElementById('span_sosiri').style.display = "none";
	document.getElementById('span_sosiri').style.visiblity = "hidden";
	document.getElementById('span_plecari').style.display = "block";
	document.getElementById('span_plecari').style.visiblity = "visible";
}

function show_ambele() 
{
	document.getElementById('span_sosiri').style.display = "block";
	document.getElementById('span_sosiri').style.visiblity = "visible";
	document.getElementById('span_plecari').style.display = "block";
	document.getElementById('span_plecari').style.visiblity = "visible";
}
YAHOO.example.ACFlatData.init();
