// JavaScript Document

var destination = false;
var fresh;
var geocoder;
var lat;
var local_height = 380;
var long;
var map;
var origin = false;
var postcode;
var radius;

var country_value;

function get_country_response(country,origin_0,destination_0) {
			
		if(navigator.appName == "Microsoft Internet Explorer"){
			http = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			http = new XMLHttpRequest();
		}
		params = "country="+country+"&origin="+origin_0+"&destination="+destination_0;
		
		var url = window.locale.baseUrl+'/ajax/search_country.php';
		http.open('POST', url);
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", params.length);
		http.setRequestHeader("Connection", "close");
		http.onreadystatechange = function(){ get_country_result(http); };
		http.send(params);
		
	
}
function get_country(fr)
{
	country_value=document.getElementById('search_country').value;
	
	var country=country_value;	
	var destination=document.getElementById('destination_in_country').checked;
	var origin=document.getElementById('origin_in_country').checked;
	if(destination== false && origin==false)
		alert(window.locale.trs.MUST_SELECT_MIN_ONE_BOX);
	else
	{
		if(destination==true && origin==true)
			get_country_response(country,1,1);
		else
		{
			if(destination==true && origin==false)
				get_country_response(country,0,1);
			else
				get_country_response(country,1,0);
		}
	}
}

function wait_on_calc()
{

		var search_results = document.getElementById('search_results');
		search_results.innerHTML = "";
		var p = document.createElement('p');
		p.setAttribute('class', 'calc');
		p.setAttribute('classname', 'calc');
		var text = document.createTextNode(window.locale.trs.CALCULATING+'...');
		p.appendChild(text);
		var img = document.createElement('img');
		img.setAttribute('src', '/images/working.gif');
		img.setAttribute('class', 'working');
		search_results.appendChild(p);
		search_results.appendChild(img);
	
}


// scriu rezultatele frumos in tabela 
function get_country_result(http){
	
	var _tr = window.locale.trs;
	
	if(http.readyState==3)
	{
		wait_on_calc();		
	}
	
	if(http.readyState == 4 && http.status == 200){
		var response = http.responseText;
		if(response){			
			if(window.ActiveXObject){
				//IE
				var doc = new ActiveXObject("Microsoft.XMLDOM");
				doc.async = "false";
				doc.loadXML(response);
			} else {
				//Mozilla, Firefox, Opera, etc.
				var parser = new DOMParser();
				var doc = parser.parseFromString(response, "text/xml");
			}
						
			// documentElement always represents the root node
			var x = doc.documentElement;
			if(x.childNodes[0].childNodes[0].nodeName != 'errorno'){
				var search_results = document.getElementById('search_results');
				search_results.innerHTML = "";
				var div = document.createElement('div');
				div.setAttribute('id', 'results_pager');
				var p = document.createElement('p');
				var text = document.createTextNode(_tr.RESULTS+': 1 - '+(x.childNodes[1].childNodes.length)+' of '+x.childNodes[0].childNodes[0].childNodes[0].firstChild.nodeValue+', '+_tr.PAGE+': 1 ');
				p.appendChild(text);
				if(parseInt(x.childNodes[0].childNodes[0].childNodes[1].firstChild.nodeValue) > 1){
					var total_pages = parseInt(x.childNodes[0].childNodes[0].childNodes[1].firstChild.nodeValue);
					var results_per_page = x.childNodes[1].childNodes.length;
					if(total_pages>3)
						total_pages=3;
					for(var i = 2; i <= total_pages; i++){
						var a = document.createElement('a');
						var start = (i-1)*results_per_page;
						a.setAttribute('href', window.locale.baseUrl+'/search.php?s='+start);
						var a_text = document.createTextNode(i);
						a.appendChild(a_text);
						p.appendChild(a);
						var text = document.createTextNode(' ');
						p.appendChild(text);
					}
					var next = results_per_page;
					var last = results_per_page*(total_pages-1);
					var a = document.createElement('a');
					a.setAttribute('href', window.locale.baseUrl+'/search.php?s='+next);
					var a_text = document.createTextNode(_tr.NEXT+' >');
					a.appendChild(a_text);
					p.appendChild(a);
					var text = document.createTextNode(' ');
					p.appendChild(text);
					var a = document.createElement('a');
					a.setAttribute('href', window.locale.baseUrl+'/search.php?s='+last);
					var a_text = document.createTextNode('>>');
					a.appendChild(a_text);
					p.appendChild(a);
				}
				div.appendChild(p);
				search_results.appendChild(div);
				var div = document.createElement('div');
				div.setAttribute('id', 'results_save_search');
				if (parseInt(x.childNodes[0].childNodes[0].childNodes[2].firstChild.nodeValue) == 1) {
					var form = document.createElement('form');
					form.setAttribute('action', window.locale.baseUrl+'/search.php');
					form.setAttribute('method', 'post');
					var input = document.createElement('input');
					input.setAttribute('type', 'submit');
					input.setAttribute('name', 'alert');
					input.setAttribute('value', window.locale.trs.SAVE_SEARCH_EMAIL);
					form.appendChild(input);
					div.appendChild(form);
				} else {
					var br = document.createElement('br');
					div.appendChild(br);
				}
				search_results.appendChild(div);
				var div = document.createElement('div');
				div.setAttribute('class', 'clear');
				div.setAttribute('className', 'clear');
				search_results.appendChild(div);
				var table = document.createElement('table');
				//console.debug("Created table element");
				table.setAttribute('cellspacing', '0');
				var tbody = document.createElement('tbody');
				var tr = document.createElement('tr');
				tr.setAttribute('class', 'header');
				tr.setAttribute('className', 'header');
				var td = document.createElement('td');
				td.setAttribute('class', 'shipment cell');
				td.setAttribute('className', 'shipment cell');
				text = document.createTextNode(_tr.SHIPMENT);
				td.appendChild(text);
				tr.appendChild(td);
				//console.debug("Created shipment cell");
				td = document.createElement('td');
				td.setAttribute('class', 'bids cell');
				td.setAttribute('className', 'bids cell');
				text = document.createTextNode(_tr.BIDS);
				td.appendChild(text);
				tr.appendChild(td);
				//console.debug("Created bids cell");
				td = document.createElement('td');
				td.setAttribute('class', 'price cell');
				td.setAttribute('className', 'price cell');
				var a = document.createElement('a');
				a.setAttribute('href', window.locale.baseUrl+'/search.php?s=0&sort_by=price%20DESC');
				text = document.createTextNode(_tr.PRICE);
				a.appendChild(text);
				td.appendChild(a);
				tr.appendChild(td);
				//console.debug("Created price cell");
				td = document.createElement('td');
				td.setAttribute('class', 'origin cell');
				td.setAttribute('className', 'origin cell');
				text = document.createTextNode(_tr.ORIGIN);
				td.appendChild(text);
				tr.appendChild(td);
				//console.debug("Created origin cell");
				td = document.createElement('td');
				td.setAttribute('class', 'destination cell');
				td.setAttribute('className', 'destination cell');
				text = document.createTextNode(_tr.DESTINATION);
				td.appendChild(text);
				tr.appendChild(td);
				//console.debug("Created destination cell");
				td = document.createElement('td');
				td.setAttribute('class', 'miles cell');
				td.setAttribute('className', 'miles cell');
				a = document.createElement('a');
				a.setAttribute('href', window.locale.baseUrl+'/search.php?s=0&sort_by=distance%20DESC');
				text = document.createTextNode(_tr.MILES);
				a.appendChild(text);
				td.appendChild(a);
				tr.appendChild(td);
				//console.debug("Created miles cell");
				td = document.createElement('td');
				td.setAttribute('class', 'date cell');
				td.setAttribute('className', 'date cell');
				a = document.createElement('a');
				a.setAttribute('href', window.locale.baseUrl+'/search.php?s=0&sort_by=date%20DESC');
				text = document.createTextNode(_tr.DATE);
				a.appendChild(text);
				td.appendChild(a);
				tr.appendChild(td);
				//console.debug("Created date cell");
				tbody.appendChild(tr);
				if (x.childNodes[2]) {
  				var j = true;
				
				
				/*   Featured listings  */
				
				
				
          for(var i = 0; i < x.childNodes[2].childNodes.length; i++){
        	  //console.debug("Feartured Listing "+i+" start");
				    tr = document.createElement('tr');
  					if(j){
  								tr.setAttribute('class', 'featured_listing');
  								tr.setAttribute('className', 'featured_listing');
  								tr.setAttribute('bgcolor', '#ffc15f');
  								j = false;
  							} else {
  							  tr.setAttribute('class', 'featured_listing');
  								tr.setAttribute('className', 'featured_listing');
  								tr.setAttribute('bgcolor', '#ffd38f');
  								j = true;
  							}
  					td = document.createElement('td');
  					td.setAttribute('class', 'shipment cell');
  					td.setAttribute('className', 'shipment cell');
					//featured listing picture
  					if(x.childNodes[2].childNodes[i].childNodes[13].firstChild){
  						var a = document.createElement('a');
  						a.setAttribute('href', window.locale.baseUrl+'/transport/'+x.childNodes[2].childNodes[i].childNodes[26].firstChild.nodeValue+'/'+x.childNodes[2].childNodes[i].childNodes[0].firstChild.nodeValue+'/');
  						var img = document.createElement('img');
  						if (x.childNodes[2].childNodes[i].childNodes[13].firstChild.nodeValue > 13827) {
                img.setAttribute('src', 'http://images.shiply.com/uploads/'+x.childNodes[2].childNodes[i].childNodes[13].firstChild.nodeValue+'_thumb');
              } else {
                img.setAttribute('src', '/uploads/'+x.childNodes[2].childNodes[i].childNodes[13].firstChild.nodeValue+'_thumb');
              }            
  						a.appendChild(img);
  						td.appendChild(a);
  					}
					//featured listing title
  					var a = document.createElement('a');
  					a.setAttribute('href', window.locale.baseUrl+'/transport/'+x.childNodes[2].childNodes[i].childNodes[26].firstChild.nodeValue+'/'+x.childNodes[2].childNodes[i].childNodes[0].firstChild.nodeValue+'/');
  					var text = document.createTextNode(x.childNodes[2].childNodes[i].childNodes[25].firstChild.nodeValue);
  					a.appendChild(text);
  					td.appendChild(a);
  					if(x.childNodes[2].childNodes[i].childNodes[14].firstChild){
  						if(parseInt(x.childNodes[2].childNodes[i].childNodes[15].firstChild.nodeValue) == 1){
  							var img = document.createElement('img');
  							img.setAttribute('class', 'ebay');
  							img.setAttribute('className', 'ebay');
  							img.setAttribute('src', '/images/auction_won.gif');
							img.setAttribute('onMouseover', 'showhint(\'eBay auction item won\', this, event, \'150px\')');
  							td.appendChild(img);
  						} else if(parseInt(x.childNodes[2].childNodes[i].childNodes[15].firstChild.nodeValue) == 2){
  							var img = document.createElement('img');
  							img.setAttribute('class', 'ebay');
  							img.setAttribute('className', 'ebay');
  							img.setAttribute('src', '/images/auction.gif');
							img.setAttribute('onMouseover', 'showhint(\'User currently bidding on eBay auction - item not yet won\', this, event, \'200px\')');
  							td.appendChild(img);
  						}
  					}
  					var p = document.createElement('span');
  					p.setAttribute('class', 'category');
  					p.setAttribute('className', 'category');
  					if(x.childNodes[2].childNodes[i].childNodes[25].firstChild && x.childNodes[2].childNodes[i].childNodes[9].firstChild.nodeValue != "Other"){
  						text = document.createTextNode(x.childNodes[2].childNodes[i].childNodes[9].firstChild.nodeValue+' > '+x.childNodes[2].childNodes[i].childNodes[27].firstChild.nodeValue);
  					} else {
  						text = document.createTextNode(x.childNodes[2].childNodes[i].childNodes[9].firstChild.nodeValue);
  					}
  					p.appendChild(text);
  					td.appendChild(p);
  					tr.appendChild(td);
  					td = document.createElement('td');
  					td.setAttribute('class', 'bids cell');
  					td.setAttribute('className', 'bids cell');
  					a = document.createElement('a');					
  				        a.setAttribute('href', window.locale.baseUrl+'/transport/'+x.childNodes[2].childNodes[i].childNodes[26].firstChild.nodeValue+'/'+x.childNodes[1].childNodes[i].childNodes[0].firstChild.nodeValue+'/#bids');		
  					text = document.createTextNode(x.childNodes[2].childNodes[i].childNodes[28].firstChild.nodeValue);
  					a.appendChild(text);
  					td.appendChild(a);
  					tr.appendChild(td);
  					td = document.createElement('td');
  					td.setAttribute('class', 'price cell');
  					td.setAttribute('className', 'price cell');
  					if(x.childNodes[2].childNodes[i].childNodes[3].firstChild){
  						p = document.createElement('p');
  						text = document.createTextNode(window.locale.currencySymbol+x.childNodes[2].childNodes[i].childNodes[3].firstChild.nodeValue);
  						var img = document.createElement('img');
  						img.setAttribute('src', '/images/int/'+window.locale.language+'/max.gif');
  						p.appendChild(text);
  						td.appendChild(p);
  						td.appendChild(img);
  					} else {
  						var img = document.createElement('img');
  						img.setAttribute('src', '/images/int/'+window.locale.language+'/flexible.gif');
  						td.appendChild(img);
  					}
  					tr.appendChild(td);
  					td = document.createElement('td');
  					td.setAttribute('class', 'origin cell');
  					td.setAttribute('className', 'origin cell');
  					var postcode = x.childNodes[2].childNodes[i].childNodes[8].firstChild.nodeValue;
  					p = document.createElement('p');
  					text = document.createTextNode(postcode);
  					p.appendChild(text);
  					td.appendChild(p);
  					if(x.childNodes[2].childNodes[i].childNodes[17].firstChild.nodeValue == "choose"){
  						var img = document.createElement('img');
  						img.setAttribute('src', '/images/search_cal.gif');
  						td.appendChild(img);
  						p = document.createElement('p');
  						text = document.createTextNode(x.childNodes[2].childNodes[i].childNodes[18].firstChild.nodeValue+' - '+x.childNodes[2].childNodes[i].childNodes[19].firstChild.nodeValue);
  						p.appendChild(text);
  						td.appendChild(p);
  					}
  					tr.appendChild(td);
  					td = document.createElement('td');
  					td.setAttribute('class', 'destination cell');
  					td.setAttribute('className', 'destination cell');
  					var postcode = x.childNodes[2].childNodes[i].childNodes[12].firstChild.nodeValue;
  					p = document.createElement('p');
  					text = document.createTextNode(postcode);
  					p.appendChild(text);
  					td.appendChild(p);
  					if(x.childNodes[2].childNodes[i].childNodes[20].firstChild.nodeValue == "choose"){
  						var img = document.createElement('img');
  						img.setAttribute('src', '/images/search_cal.gif');
  						td.appendChild(img);
  						p = document.createElement('p');
  						text = document.createTextNode(x.childNodes[2].childNodes[i].childNodes[21].firstChild.nodeValue+' - '+x.childNodes[2].childNodes[i].childNodes[22].firstChild.nodeValue);
  						p.appendChild(text);
  						td.appendChild(p);
  					}
  					tr.appendChild(td);
  					td = document.createElement('td');
  					td.setAttribute('class', 'miles cell');
  					td.setAttribute('className', 'miles cell');
  					text = document.createTextNode(x.childNodes[2].childNodes[i].childNodes[10].firstChild.nodeValue);
  					td.appendChild(text);
  					tr.appendChild(td);
  					td = document.createElement('td');
  					td.setAttribute('class', 'date cell');
  					td.setAttribute('className', 'date cell');
  					text = document.createTextNode(x.childNodes[2].childNodes[i].childNodes[6].firstChild.nodeValue);
  					td.appendChild(text);
  					tr.appendChild(td);
  					td = document.createElement('td');
  					td.setAttribute('class', 'clear');
  					td.setAttribute('className', 'clear');
  					tr.appendChild(td);
  					tbody.appendChild(tr);
  				}
  				tr = document.createElement('tr');
          tr.setAttribute('class', 'featured_bottom');
          tr.setAttribute('className', 'featured_bottom');
          td = document.createElement('td');
          td.setAttribute('colspan', 7);
          text = document.createTextNode('Featured Shipments! ');
          td.appendChild(text);
          a = document.createElement('a');
          a.setAttribute('href', '/myshiply.php?featured=1')
          text = document.createTextNode('Promote your shipment listings');
          a.appendChild(text);
          td.appendChild(a);
          tr.appendChild(td);
          tbody.appendChild(tr);
          //console.debug("Feartured Listing "+i+" end");
  			}
			
			
			
			/* Normal Listings */
			
			
			
				var j = true;
				for(var i = 0; i < x.childNodes[1].childNodes.length; i++){
					//console.debug("Listing "+i+" start");
					tr = document.createElement('tr');
					if(j){
						tr.setAttribute('class', 'highlight');
						tr.setAttribute('className', 'highlight');
						j = false;
					} else {
						j = true;
					}
					td = document.createElement('td');
					td.setAttribute('class', 'shipment cell');
					td.setAttribute('className', 'shipment cell');
					
					if(x.childNodes[1].childNodes[i].childNodes[13].firstChild){
						var a = document.createElement('a');
						//alert(x.childNodes[1].childNodes[i].childNodes[26].firstChild.nodeValue);
						a.setAttribute('href', window.locale.baseUrl+'/transport/'+x.childNodes[1].childNodes[i].childNodes[26].firstChild.nodeValue+'/'+x.childNodes[1].childNodes[i].childNodes[0].firstChild.nodeValue+'/');
						var img = document.createElement('img');
						if (x.childNodes[1].childNodes[i].childNodes[13].firstChild.nodeValue > 13827) {
              img.setAttribute('src', 'http://images.shiply.com/uploads/'+x.childNodes[1].childNodes[i].childNodes[13].firstChild.nodeValue+'_thumb');
            } else {
              img.setAttribute('src', '/uploads/'+x.childNodes[1].childNodes[i].childNodes[13].firstChild.nodeValue+'_thumb');
            }            
						a.appendChild(img);
						td.appendChild(a);
						//console.debug("Created image");
					}
					var a = document.createElement('a');
					a.setAttribute('href', window.locale.baseUrl+'/transport/'+x.childNodes[1].childNodes[i].childNodes[26].firstChild.nodeValue+'/'+x.childNodes[1].childNodes[i].childNodes[0].firstChild.nodeValue+'/');
					var text = document.createTextNode(x.childNodes[1].childNodes[i].childNodes[25].firstChild.nodeValue);
					a.appendChild(text);
					td.appendChild(a);
					//console.debug("Created title");
					if(x.childNodes[1].childNodes[i].childNodes[14].firstChild){
						if(parseInt(x.childNodes[1].childNodes[i].childNodes[15].firstChild.nodeValue) == 1){
							var img = document.createElement('img');
							img.setAttribute('class', 'ebay');
							img.setAttribute('className', 'ebay');
							img.setAttribute('src', '/images/auction_won.gif');
							img.setAttribute('onMouseover', 'showhint(\'eBay auction item won\', this, event, \'150px\')');
							td.appendChild(img);
							//console.debug("Created auction won");
						} else if(parseInt(x.childNodes[1].childNodes[i].childNodes[15].firstChild.nodeValue) == 2){
							var img = document.createElement('img');
							img.setAttribute('class', 'ebay');
							img.setAttribute('className', 'ebay');
							img.setAttribute('src', '/images/auction.gif');
							img.setAttribute('onMouseover', 'showhint(\'User currently bidding on eBay auction - item not yet won\', this, event, \'200px\')');
							td.appendChild(img);
							//console.debug("Created auction");
						}
					}
					var p = document.createElement('span');
					p.setAttribute('class', 'category');
					p.setAttribute('className', 'category');
					
					
					//category
					if(x.childNodes[1].childNodes[i].childNodes[27].firstChild && x.childNodes[1].childNodes[i].childNodes[9].firstChild.nodeValue != "Other"){
						text = document.createTextNode(x.childNodes[1].childNodes[i].childNodes[9].firstChild.nodeValue+' > '+x.childNodes[1].childNodes[i].childNodes[27].firstChild.nodeValue);
					} else {
						text = document.createTextNode(x.childNodes[1].childNodes[i].childNodes[9].firstChild.nodeValue);
					}
					p.appendChild(text);
					td.appendChild(p);
					tr.appendChild(td);
					//console.debug("Created category");
					td = document.createElement('td');
					td.setAttribute('class', 'bids cell');
					td.setAttribute('className', 'bids cell');
					// bids
					a = document.createElement('a');					
				        a.setAttribute('href', window.locale.baseUrl+'/transport/'+x.childNodes[1].childNodes[i].childNodes[26].firstChild.nodeValue+'/'+x.childNodes[1].childNodes[i].childNodes[0].firstChild.nodeValue+'/#bids');		
					text = document.createTextNode(x.childNodes[1].childNodes[i].childNodes[28].firstChild.nodeValue);
					a.appendChild(text);
					td.appendChild(a);
					tr.appendChild(td);
					//console.debug("Created bids");
					td = document.createElement('td');
					td.setAttribute('class', 'price cell');
					td.setAttribute('className', 'price cell');
					if(x.childNodes[1].childNodes[i].childNodes[3].firstChild) {
						p = document.createElement('p');
						text = document.createTextNode(window.locale.currencySymbol+x.childNodes[1].childNodes[i].childNodes[3].firstChild.nodeValue);
						var img = document.createElement('img');
						img.setAttribute('src', '/images/int/'+window.locale.language+'/max.gif');
						p.appendChild(text);
						td.appendChild(p);
						td.appendChild(img);
						//console.debug("Created max price");
					} else {
						var img = document.createElement('img');
						img.setAttribute('src', '/images/int/'+window.locale.language+'/flexible.gif');
						td.appendChild(img);
						//console.debug("Created flexible");
					}
					tr.appendChild(td);
					td = document.createElement('td');
					td.setAttribute('class', 'origin cell');
					td.setAttribute('className', 'origin cell');
					//from countrt 24
					if (x.childNodes[1].childNodes[i].childNodes[8].firstChild) {
						var postcode = x.childNodes[1].childNodes[i].childNodes[8].firstChild.nodeValue;
					}
					else {
						var postcode = "-";
					}
					p = document.createElement('p');
					text = document.createTextNode(postcode);
					p.appendChild(text);
					td.appendChild(p);
					//console.debug("Created from address");
					if(x.childNodes[1].childNodes[i].childNodes[17].firstChild.nodeValue == "choose"){
						var img = document.createElement('img');
						img.setAttribute('src', '/images/search_cal.gif');
						td.appendChild(img);
						p = document.createElement('p');
						text = document.createTextNode(x.childNodes[1].childNodes[i].childNodes[18].firstChild.nodeValue+' - '+x.childNodes[1].childNodes[i].childNodes[19].firstChild.nodeValue);
						p.appendChild(text);
						td.appendChild(p);
						//console.debug("Created pickup");
					}
					tr.appendChild(td);
					td = document.createElement('td');
					td.setAttribute('class', 'destination cell');
					td.setAttribute('className', 'destination cell');
					//to country
					if (x.childNodes[1].childNodes[i].childNodes[12].firstChild) {
						var postcode = x.childNodes[1].childNodes[i].childNodes[12].firstChild.nodeValue;
					}
					else {
						var postcode = "-";						
					}
					p = document.createElement('p');
					text = document.createTextNode(postcode);
					p.appendChild(text);
					td.appendChild(p);
					//console.debug("Created to address");
					if(x.childNodes[1].childNodes[i].childNodes[20].firstChild.nodeValue == "choose"){
						var img = document.createElement('img');
						img.setAttribute('src', '/images/search_cal.gif');
						td.appendChild(img);
						p = document.createElement('p');
						text = document.createTextNode(x.childNodes[1].childNodes[i].childNodes[21].firstChild.nodeValue+' - '+x.childNodes[1].childNodes[i].childNodes[22].firstChild.nodeValue);
						p.appendChild(text);
						td.appendChild(p);
						//console.debug("Created delivery");
					}
					tr.appendChild(td);
					td = document.createElement('td');
					td.setAttribute('class', 'miles cell');
					td.setAttribute('className', 'miles cell');
					text = document.createTextNode(x.childNodes[1].childNodes[i].childNodes[10].firstChild.nodeValue);
					td.appendChild(text);
					tr.appendChild(td);
					//console.debug("Created miles");
					td = document.createElement('td');
					td.setAttribute('class', 'date cell');
					td.setAttribute('className', 'date cell');
					text = document.createTextNode(x.childNodes[1].childNodes[i].childNodes[6].firstChild.nodeValue);
					td.appendChild(text);
					tr.appendChild(td);
					//console.debug("Created date");
					td = document.createElement('td');
					td.setAttribute('class', 'clear');
					td.setAttribute('className', 'clear');
					tr.appendChild(td);
					tbody.appendChild(tr);
					//console.debug("Listing "+i+" end");
				}
				table.appendChild(tbody);
				search_results.appendChild(table);
				var p = document.createElement('p');
				var text = document.createTextNode(_tr.RESULTS+': 1 - '+(x.childNodes[1].childNodes.length)+' of '+x.childNodes[0].childNodes[0].childNodes[0].firstChild.nodeValue+', '+_tr.PAGE+': 1 ');
				p.appendChild(text);
				if(parseInt(x.childNodes[0].childNodes[0].childNodes[1].firstChild.nodeValue) > 1){
					var total_pages = parseInt(x.childNodes[0].childNodes[0].childNodes[1].firstChild.nodeValue);
					
					var results_per_page = x.childNodes[1].childNodes.length;
					if(total_pages>3)
						total_pages=3;
					for(var i = 2; i <= total_pages; i++) {
						var a = document.createElement('a');
						var start = (i-1)*results_per_page;
						a.setAttribute('href', window.locale.baseUrl+'/search.php?s='+start);
						var a_text = document.createTextNode(i);
						a.appendChild(a_text);
						p.appendChild(a);
						var text = document.createTextNode(' ');
						p.appendChild(text);
					}
					var next = results_per_page;
					var last = results_per_page*(total_pages-1);
					var a = document.createElement('a');
					a.setAttribute('href', window.locale.baseUrl+'/search.php?s='+next);
					var a_text = document.createTextNode(_tr.NEXT+' >');
					a.appendChild(a_text);
					p.appendChild(a);
					var text = document.createTextNode(' ');
					p.appendChild(text);
					var a = document.createElement('a');
					a.setAttribute('href', window.locale.baseUrl+'/search.php?s='+last);
					var a_text = document.createTextNode('>>');
					a.appendChild(a_text);
					p.appendChild(a);
				}
				search_results.appendChild(p);
			} else {
				var search_results = document.getElementById('search_results');
				search_results.innerHTML = "";
				var div = document.createElement('div');
				div.setAttribute('id', 'results_pager');
				var p = document.createElement('p');
				var text = document.createTextNode(_tr.RESULTS+': 0');
				p.appendChild(text);
				div.appendChild(p);
				search_results.appendChild(div);
				var div = document.createElement('div');
				div.setAttribute('id', 'results_save_search');
				if (parseInt(x.childNodes[1].firstChild.nodeValue) == 1) {
					var form = document.createElement('form');
					form.setAttribute('action', window.locale.baseUrl+'/search.php');
					form.setAttribute('method', 'post');
					var input = document.createElement('input');
					input.setAttribute('type', 'submit');
					input.setAttribute('name', 'alert');
					input.setAttribute('value', window.locale.trs.SAVE_SEARCH_EMAIL);
					form.appendChild(input);
					div.appendChild(form);
				} else {
					var br = document.createElement('br');
					div.appendChild(br);
				}
				search_results.appendChild(div);
				var div = document.createElement('div');
				div.setAttribute('class', 'clear');
				div.setAttribute('className', 'clear');
				search_results.appendChild(div);
				var table = document.createElement('table');
				table.setAttribute('cellspacing', '0');
				var tbody = document.createElement('tbody');
				var tr = document.createElement('tr');
				tr.setAttribute('class', 'header');
				tr.setAttribute('className', 'header');
				var td = document.createElement('td');
				td.setAttribute('class', 'shipment cell');
				td.setAttribute('className', 'shipment cell');
				text = document.createTextNode(_tr.SHIPMENT);
				td.appendChild(text);
				tr.appendChild(td);
				td = document.createElement('td');
				td.setAttribute('class', 'bids cell');
				td.setAttribute('className', 'bids cell');
				text = document.createTextNode(_tr.BIDS);
				td.appendChild(text);
				tr.appendChild(td);
				td = document.createElement('td');
				td.setAttribute('class', 'price cell');
				td.setAttribute('className', 'price cell');
				var a = document.createElement('a');
				a.setAttribute('href', window.locale.baseUrl+'/search.php?s=0&sort_by=price%20DESC');
				text = document.createTextNode(_tr.PRICE);
				a.appendChild(text);
				td.appendChild(a);
				tr.appendChild(td);
				td = document.createElement('td');
				td.setAttribute('class', 'origin cell');
				td.setAttribute('className', 'origin cell');
				text = document.createTextNode(_tr.ORIGIN);
				td.appendChild(text);
				tr.appendChild(td);
				td = document.createElement('td');
				td.setAttribute('class', 'destination cell');
				td.setAttribute('className', 'destination cell');
				text = document.createTextNode(_tr.DESTINATION);
				td.appendChild(text);
				tr.appendChild(td);
				td = document.createElement('td');
				td.setAttribute('class', 'miles cell');
				td.setAttribute('className', 'miles cell');
				a = document.createElement('a');
				a.setAttribute('href', window.locale.baseUrl+'/search.php?s=0&sort_by=distance%20DESC');
				text = document.createTextNode(_tr.MILES);
				a.appendChild(text);
				td.appendChild(a);
				tr.appendChild(td);
				td = document.createElement('td');
				td.setAttribute('class', 'miles_added cell');
				td.setAttribute('className', 'miles_added cell');
				text = document.createTextNode(_tr.MILES_ADDED);
				td.appendChild(text);
				tr.appendChild(td);
				td = document.createElement('td');
				td.setAttribute('class', 'date cell');
				td.setAttribute('className', 'date cell');
				a = document.createElement('a');
				a.setAttribute('href', window.locale.baseUrl+'/search.php?s=0&sort_by=date%20DESC');
				text = document.createTextNode(_tr.DATE);
				a.appendChild(text);
				td.appendChild(a);
				tr.appendChild(td);
				tbody.appendChild(tr);
				tr = document.createElement('tr');
				td = document.createElement('td');
				td.setAttribute('colspan', '8');
				td.colSpan = 8;
				var center = document.createElement('center');
				var text = document.createTextNode('- '+_tr.NO_RESULTS+' -');
				center.appendChild(text);
				td.appendChild(center);
				tr.appendChild(td);
				tbody.appendChild(tr);
				table.appendChild(tbody);
				search_results.appendChild(table);
			}
		}
	}
}





function remove_local_suggestions() {
	postcode = false;
	if(document.getElementById('local_suggest')){
		document.getElementById('local_suggest').parentNode.removeChild(document.getElementById('local_suggest'));
	}
	var local = document.getElementById('local');
	local.style.height = local_height+'px';
}

function set_postcode(p) {
	postcode = p;
	document.getElementById('local_suggest').parentNode.removeChild(document.getElementById('local_suggest'));
	var local = document.getElementById('local');
	local.style.height = local_height+'px';
	document.getElementById('local_post_code').value = postcode;
	set_radius();
}