// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

function clearText(field){
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
}

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

function convert2Link(str) {
	str=str.toLowerCase();
	str=str_replace("- ","-",str);
	str=str_replace("'","",str);
	str=str_replace('"',"",str);
	str=str_replace("(","",str);
	str=str_replace(")","",str);
	str=str_replace("-","",str);
	str=str_replace(".","",str);
	str=str_replace(",","",str);
	str=str_replace("#","",str);
	str=str_replace(" ","-",str);
	str=str_replace("/","",str);
	str=str_replace("&","&amp;",str);
	return str;
}


// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

function gotoBranche() {
	var brancheName=convert2Link(element('branchSearch').value);
	window.location=domainroot+'/'+brancheName+'.html';
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------

function gotoCompany(ref) {
	window.location.href=ref;
}

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

function showCompanySearchResults() {
	var searchResultsObj=element('companySearchResults');

	var search=element('companySearch').value;
	if (search.length<2) {
		hideCompanySearchResults();
		return false;
	}

	var url=domainroot+'/index.php?ajaxsubmit=getcompanylist&letters='+search;

	var ajaxConnector=new sack();

	ajaxConnector.requestFile=url;
	ajaxConnector.onCompletion=function () {
		var response=ajaxConnector.response;

		if (response!='') {
			var HTML="";
			var elements=response.split("#");

			var maxItems=(elements.length)-1;
			var height=200;
			var width=440;

			if (maxItems>0)
				for (idx=0;idx<(elements.length-1);idx++) {
					items=elements[idx].split("=");

					HTML+=
						"<div class=resultListItem onclick='gotoCompany(\""+items[0]+"\");'>"+
							items[1]+
						"</div>";
				}

			searchResultsObj.innerHTML=
				"<div class=resultlist style='z-index: 1000; width: "+width+"px; height: "+height+"px;'>"+
					"<div class=innerresultList style='height: "+(height-40)+"px; width: "+(width-2)+"px;'>"+
						HTML+
					"</div>"+
				"</div>";

			searchResultsObj.style.display='block';
			searchResultsObj.style.visibility='visible';
		}
		else {
			searchResultsObj.innerHTML="";
			hideDIV(searchResultsObj);
		}
	};

	ajaxConnector.runAJAX();
}

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

function hideCompanySearchResults() {
	var searchResultsObj=element('companySearchResults');
	hideDIV(searchResultsObj);
}

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

