function trim(value) {
  value = value.replace(/^\s+/,'');
  value = value.replace(/\s+$/,'');
  return value;
}

$(document).ready(function(){

	$('#directions_submit').bind('click', function(e) {
    
    e.preventDefault(); 
    
    allok = 1;
    
    street_val = $('#street').val();
    city_val   = $('#city').val();
    
    if ((trim(street_val)) == '')
    {
      alert('Vul aub uw adres in.');
      allok = 0;
    }

    if ((trim(city_val)) == '')
    {
      alert('Vul aub uw woonplaats in.');      
      allok = 0;
    }
            
		if (allok == 1)
		{
			var streetURI = encodeURIComponent(street_val);
			var townURI = encodeURIComponent(city_val);			
			dothapopup('route.php?street=' + streetURI + '&town=' + townURI, 'Routebeschrijving');
		}
	
  });
	
});

function dothapopup(thaurl, thaname)
{
  var height = 550; 
  var width  = 630; 

  var windowURL  = thaurl;
  var windowName = thaname;	
	var windowFeatures = 'height=' + height + ', width=' + width + ', scrollbars=yes';
				
	if ($.browser.msie) {//hacked together for IE browsers
		centeredY = (window.screenTop - 120) + ((((document.documentElement.clientHeight + 120)/2) - (height/2)));
		centeredX = window.screenLeft + ((((document.body.offsetWidth + 20)/2) - (width/2)));
	}else{
		centeredY = window.screenY + (((window.outerHeight/2) - (height/2)));
		centeredX = window.screenX + (((window.outerWidth/2) - (width/2)));
  }
	window.open(windowURL, windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();
}

