function searchService() {
	
	var _results = $('.results-block').css('opacity', 0);
	var _emptyresult = 'There are no records...'
	var _country = new Array(1,2);
	var _tid;

	function showError(msg)
	{
		var _results = $('.results-block').css('opacity', 0);
		_results.css('opacity', 0);
		$('span.postal-code').css({color: '#af0206'}).html(msg);
		$('.results-block h4').css('opacity', 0);
		_results.animate({opacity: 1}, 350);
		_tid = setTimeout( function() { _results.animate({opacity: 0}, 350); }, 3000 );
		return false;
	}

	$('form.postal-form').each(function(){
		var _form = $(this);
		var _submit = $('input.submit', _form);
		_form.submit(function(){
			clearTimeout(_tid);
			$('span.postal-code').css('color', '#000000');
			$('.results-block h4').css('opacity', 1); 
			$('#map').css({left: -9999, position: 'absolute'});
			var _type = _form.attr('class').indexOf('search-form1')!=-1 ? 'address' : 'postal';
			if ($(this).hasClass('dataservices-form')) _type = 'distance';
			/* check on default values */
			var _inputs = document.getElementsByTagName('input');
			if (_inputs) {
				for(var i=0; i<_inputs.length; i++) {
					if (_inputs[i].value == _value[_inputs[i].index])
					{
						_inputs[i].value = '';
					}
				}
			}
            /* check not empty city and postalcode */
			switch(_type)
			{
				case 'address':
					if (_country.join().search($('#country').val()) != -1)
					{
						if ($('.address').val() == '')
						{
							showError('Please enter an address.');
							$('input').blur();
							$('.address').focus();
							return false;
						}
					}
					if ($('.city').val() == '')
					{
						showError('Please enter a city.');
						$('input').blur();
						$('.city').focus();
						return false;
					}
				break;
				case 'postal':
					if ($('.postal').val() == '')
					{
						showError('Please enter a postal code.');
						$('input').blur();
						$('.postal').focus();
						return false;
					}
				break;
				case 'distance':
					if ($($('.postals')[0]).val() == '')
					{
						showError('Please enter a postal code.');
						$('input').blur();
						$($('.postals')[0]).focus();
						return false;
					}
					if ($($('.postals')[1]).val() == '')
					{
						showError('Please enter a postal code.');
						$('input').blur();
						$($('.postals')[1]).focus();
						return false;
					}
				break;
			}
            /* ajax request */
			var _data = _form.serialize();
			var _url = _form.attr('action');
			$.ajax({
				url: _url,
				type: 'POST',
				data: _data,
				success: function(msg){
					var _postal_code = '';
					var _adress	 = '';
					switch (_type)
					{
						case 'postal':
							_adress = $('.postal').val() + ', ' + $('#mySelectText2').text();
							eval('var json = '+msg+';');
							if(json.length > 0)
							{
								_postal_code  = (json[0].street != null && json[0].street != '') ? json[0].street + ' st, ' : '';
								_postal_code += (json[0].city != null && json[0].city != '') ? json[0].city + ', ' : '';
								_postal_code += (json[0].region4 != null && json[0].region4 != '') ? json[0].region4 + ', ' : '';
								_postal_code += (json[0].region3 != null && json[0].region3 != '') ? json[0].region3 + ', ' : '';
								_postal_code += (json[0].region2 != null && json[0].region2 != '') ? json[0].region2 + ', ' : '';
								_postal_code += (json[0].region1 != null && json[0].region1 != '') ? json[0].region1 + ', ' : '';
								_postal_code += (json[0].country != null && json[0].country != '') ? json[0].country : '';
								ShowMap(json);
							}
							else
							{
								_postal_code = _emptyresult;
							}
						break;
						case 'address':
							_adress  = ($('.address').val() != '') ? $('.address').val() + ' st, ' : '';
							_adress += ($('.city').val() != '') ? $('.city').val() + ', ' : '';
							_adress += ($('#state').val() != '') ? $('#mySelectText0').text() + ', ' : '';
							_adress += ($('#mySelectText1').text() != '') ? $('#mySelectText1').text() : '';
							eval('var json = '+msg+';');
							if (json.length > 0)
							{
								_postal_code = json[0].postcode;
								ShowMap(json);
							}
							else
							{
								_postal_code = _emptyresult;
							}
						break;
						case 'distance':
							_adress  = $($('.postals')[0]).val() +' '+ $('#mySelectText0').text() + ', ';
							_adress += $($('.postals')[1]).val() +' '+ $('#mySelectText1').text();
							if (msg == '')
							{
								_postal_code = _emptyresult;
							}
							else
							{
								eval('var json = '+msg+';');
//								_postal_code = json.km.toFixed(2)+' km';
								_postal_code = json.ml.toFixed(2)+' ml';
							}
						break;
					}
					_results.css('opacity', 0);//.html(_res);
					$('span.adress').html(_adress);
					$('span.postal-code').html(_postal_code);
					_results.animate({opacity: 1}, 350, function(){
						$(this).css('opacity', 'auto');
					});
					$('input').blur();
				},
				error: function(){
					alert('Ajax Error! Can\'t find path to file may be.')
				}
			})
			return false;
		})
	});
}

function GMapInit()
{
	if (GBrowserIsCompatible()) {
		gmap = new GMap2(document.getElementById("map"));
		gmap.setUIToDefault();
		gmap.removeMapType(G_HYBRID_MAP);
		gmap.removeMapType(G_SATELLITE_MAP);
		gmap.removeMapType(G_PHYSICAL_MAP);
		mapinit = true;
	}
}

function ShowMap(id)
{
	if (mapinit) {
		gmap.clearOverlays();
//		for (var i=0; i<id.length; i++)
//		{
			var point = new GLatLng(id[0].lat, id[0].lng);
			gmap.setCenter(point, 12);
			var marker = new GMarker(point);
			gmap.addOverlay(marker);
//		}
		$('#map').css({left: 0, position: 'relative'});
	}
}

