if( typeof nl == "undefined" ) var nl = new Object();
if( typeof nl.gitp == "undefined" ) nl.gitp = new Object();
if( typeof nl.gitp.portal == "undefined" ) nl.gitp.portal = new Object();

nl.gitp.portal.lokatienet = {
	Lokatie : function()
	{
		// -- instance variables
		this.streetStop = "";
		this.cityStop = "";
		this.postcodeStart = "";
		this.countryStop = "";
		this.postcodeStop = "";
		
		// -- setters
		this.setStreetStop = function( streetStop )			{ this.streetStop = this.escapeSpaces( streetStop ); }
		this.setCityStop = function( cityStop )				{ this.cityStop = this.escapeSpaces( cityStop ); }
		this.setPostcodeStart = function( postcodeStart )	{ this.postcodeStart = this.removeSpaces( postcodeStart ); }
		this.setPostcodeStop = function( postcodeStop )		{ this.postcodeStop = this.removeSpaces( postcodeStop ); }		
		this.setCountryStop = function( countryStop ) {
			if( countryStop.toLowerCase() == "nederland" )
			{
				this.countryStop = "NL";
			} else if( countryStop.toLowerCase().indexOf( "belgi" ) >-1 ) {
				this.countryStop = "BE";
			} else {
				this.countryStop = "NL";
			}
		}
		
		// -- string functions
		this.escapeSpaces = function( value )				{ return value.replace( / /g, "+" ); }
		this.removeSpaces = function( value )				{ return value.replace( / /g, "" ); }
		
		// -- check the postcode and calculate the route
		this.calculateRoute = function( postcodeStart )
		{
			var url = "";
			
			if( postcodeStart == "" )
			{
				alert( "U moet een postcode invullen." );
				return false;
			}
			
			this.setPostcodeStart( postcodeStart );
			url = this.composeURL();
			
			window.open( url ,"Route","width=800,height=600, menubar=no,status=no,directory=no,location=no,resizable=yes,scrollbars=yes,toolbar=no");
			//window.open( url ,"_blank","width=800,height=600, menubar=no,status=no,directory=no,location=no,resizable=yes,scrollbars=yes,toolbar=no");
			
			return true;
		}
		
		// -- put together the lokatienet url
		this.composeURL = function()
		{
			var url =	"http://tools.locatienet.com/location/getroute.asp" + 
						"?config_id=8576" +
						"&street_stop=" + this.streetStop + 
						"&country_stop=" + this.countryStop + 
						"&city_stop=" + this.cityStop + 
						"&postcode_stop=" + this.postcodeStop + 
						"&speedprofile=1&optfactor=90&detailmap=on&language=dutch&country_start=NL"+
						"&postcode_start=" + this.postcodeStart;
			return url;
		}
	}
};
