function processFields(){

	var p1=document.getElementById('judet');
	var judet=p1.options[p1.selectedIndex].text;
	if(judet=="Alege..."){
		alert("Va rugam sa alegeti un judet valid");
		return false;
	}
	var localitate=document.getElementById('localitate').value;
	var strada=document.getElementById('strada').value;
	//alert(localitate+"__"+strada);
	if((strada!=null && strada.trim().length>0) && (localitate==null || localitate.trim().length==0)){
		alert("Va rugam sa specificati o localitate");
		return false;
	}
	return true;

}

function processKey(e){
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	if (keynum == 13){
	 submitForm();
	}
}


function submitForm(){
	if(!processFields()){
		return;
	}
	var p1=document.getElementById('judet');
	var judet=p1.options[p1.selectedIndex].text;
	
	var localitate=document.getElementById('localitate').value;
	var strada=document.getElementById('strada').value;

	judet=judet.replace(/-/g,"_");
	var actionStr='1-coduri-postale-'+encodeURI(judet);

	if(localitate!=null && localitate.length>0){
		localitate=localitate.replace(/-/g,"_")
		actionStr=actionStr+"-"+encodeURI(localitate);
	}
	if(strada!=null && strada.length>0){
		strada=strada.replace(/-/g,"_")
		actionStr=actionStr+"-"+strada;
	}
	//alert(actionStr);
	document.getElementById('cautare').action=actionStr;
	document.getElementById('cautare').submit();
}

function clearFields(){
	//alert(document.getElementById('localitate').value);
	var p1=document.getElementById('judet');
	var judet=p1.options[p1.selectedIndex].text;
	if(judet.toLowerCase()=='bucuresti'){
		document.getElementById('localitate').value='Bucuresti';
	}else{
		document.getElementById('localitate').value='';
	}
	document.getElementById('strada').value='';
}