count = 1;

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
	
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function echo(base) {
	r = new Array();
	if (!trim(document.getElementById("wp_1").value) || !trim(document.getElementById("wp_2").value)) {
		alert("Completeaza cel putin doua orase intre care doresti sa afli ruta!");
		return false;
	}
	for (i=1;i<5;i++)
		if (document.getElementById("wp_"+i)) 
			if (document.getElementById("wp_"+i).value != "") r.push(trim(document.getElementById("wp_"+i).value).replace(/ /g, '_'));
	ruta = r.join("+");
	//alert(ruta);
	window.location = base + "/traseu/"+ruta+".html#ruta";
}
function echo2(base, wp1, wp2) {

	if (!trim(wp1) || !trim(wp2)) {
		alert("Completeaza cel putin doua orase intre care doresti sa afli ruta!");
		return false;
	}
	ruta = trim(wp1) + '+' + trim(wp2);
	url = base + "/traseu/"+ruta+".html#ruta";
	window.location = url;
}

//Add more fields dynamically.
function addField(field,limit) {
	if (count <=limit) {
		document.getElementById(field + count).style.display = "block";
		count++;
	}
}

