/// <reference path="jquery-1.7.1.min.js" />
jQuery.fn.hint = function (blurClass) {
	if (!blurClass) {
		blurClass = 'blur';
	}

	return this.each(function () {
		// get jQuery version of 'this'
		var $input = jQuery(this),

		// capture the rest of the variable to allow for reuse
	  title = $input.attr('title'),
	  $form = jQuery(this.form),
	  $win = jQuery(window);

		function remove() {
			if ($input.val() === title && $input.hasClass(blurClass)) {
				$input.val('').removeClass(blurClass);
			}
		}

		// only apply logic if the element has the attribute
		if (title) {
			// on blur, set value to title attr if text is blank
			$input.blur(function () {
				if (this.value === '') {
					$input.val(title).addClass(blurClass);
				}
			}).focus(remove).blur(); // now change all inputs to title

			// clear the pre-defined text when form is submitted
			$form.submit(remove);
			$win.unload(remove); // handles Firefox's autocomplete
		}
	});
};



jQuery.fn.customInput = function(){
	$(this).each(function(i){	
		if($(this).is('[type=checkbox],[type=radio]')){
			var input = $(this);
			
			// get the associated label using the input's id
			var label = $('label[for='+input.attr('id')+']');
			
			//get type, for classname suffix 
			var inputType = (input.is('[type=checkbox]')) ? 'checkbox' : 'radio';
			
			// wrap the input + label in a div 
			$('<span class="custom-' + inputType + '"></span>').insertBefore(input).append(input, label);
			
			// find all inputs in this set using the shared name attribute
			var allInputs = $('input[name='+input.attr('name')+']');
			
			// necessary for browsers that don't support the :hover pseudo class on labels
			label.hover(
				function(){ 
					$(this).addClass('hover'); 
					if(inputType == 'checkbox' && input.is(':checked')){ 
						$(this).addClass('checkedHover'); 
					} 
				},
				function(){ $(this).removeClass('hover checkedHover'); }
			);
			
			//bind custom event, trigger it, bind click,focus,blur events					
			input.bind('updateState', function(){	
				if (input.is(':checked')) {
					if (input.is(':radio')) {				
						allInputs.each(function(){
							$('label[for='+$(this).attr('id')+']').removeClass('checked');
						});		
					};
					label.addClass('checked');
				}
				else { label.removeClass('checked checkedHover checkedFocus'); }
										
			})
			.trigger('updateState')
			.click(function(){ 
				$(this).trigger('updateState'); 
			})
			.focus(function(){ 
				label.addClass('focus'); 
				if(inputType == 'checkbox' && input.is(':checked')){ 
					$(this).addClass('checkedFocus'); 
				} 
			})
			.blur(function(){ label.removeClass('focus checkedFocus'); });
		}
	});
};

$(window).load(function () {
    
    var cookieEnabled = (navigator.cookieEnabled) ? true : false;

    //if not IE4+ nor NS6+
    if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled) {
        document.cookie = "testcookie";
        cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
    }

    if (!cookieEnabled) {
        $('#cookieWarning').show();
    }
});




var theWindow = $(window),
        $bg = $("#bg"),
        aspectRatio = $bg.width() / $bg.height();

var is_operamini = Object.prototype.toString.call(window.operamini) === "[object OperaMini]";

$(document).ready(function () {

    var $bg = $("#bg"),
        aspectRatio = $bg.width() / $bg.height();

    function resizeBg() {

        //console.debug(aspectRatio);
        if ((theWindow.width() / theWindow.height()) < aspectRatio) {
            $bg
                    .removeClass()
                    .addClass('bgheight');
        } else {
            $bg
                    .removeClass()
                    .addClass('bgwidth');
        }

    }

    theWindow.resize(function () {
        resizeBg();

    }).trigger("resize");

    if (!is_operamini) {
        $('#banner').anythingSlider({
            easing: "swing",    // Anything other than "linear" or "swing" requires the easing plugin
            autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not
            startStopped: false,            // If autoPlay is on, this can force it to start stopped
            delay: 4500,                    // How long between slide transitions in AutoPlay mode
            animationTime: 1200,             // How long the slide transition takes
            buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
            pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
            navigationFormatter: null,       // Details at the top of the file on this use (advanced use)
            buildStartStop: false,
            buildArrows: false
        });

        $('#panoramaBanner').anythingSlider({
            easing: "swing",    // Anything other than "linear" or "swing" requires the easing plugin
            autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not
            startStopped: false,            // If autoPlay is on, this can force it to start stopped
            delay: 4500,                    // How long between slide transitions in AutoPlay mode
            animationTime: 1200,             // How long the slide transition takes
            buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
            pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
            navigationFormatter: null,       // Details at the top of the file on this use (advanced use)
            buildStartStop: false,
            buildArrows: false
        });
    }
    if (is_operamini) {
        $('#bannerWrapper ul li:not(:first)').remove();
        $('#bannerWrapper').css('height', "250px");
    }

    $('.password-obscured').hide();
    $('.password-clear').show();
    $('.password-clear').focus(function () {
        $('.password-clear').hide();
        $('.password-obscured').show();
        $('.password-obscured').focus();
    });

    $('.password-obscured').blur(function () {
        if ($('.password-obscured').val() == '') {
            $('.password-clear').val($('.password-clear').attr('title'));
            $('.password-clear').show();
            $('.password-obscured').hide();
        }
    });

    $('.showAllDealers').bind('click', function () {
        $(this).css('background-position', 'left top');
        $('.showCloseDealers').css('backgroundPosition', 'left bottom');
        fetchAllDealersForDelivery($('#InvoiceAddress_Zipcode').val());
    });
    $('.showCloseDealers').bind('click', function () {
        $(this).css('background-position', 'left top');
        $('.showAllDealers').css('backgroundPosition', 'left bottom');
        fetchDealersForDelivery($('#InvoiceAddress_Zipcode').val());
    });

    $('.noLink').bind('click', function () {
        return false;
    });


    //$('.rememberMe').customInput();

    $("a[rel^='prettyPhoto']").prettyPhoto();
    $("input").hint();
    $('area').bind('click', function () {
        fetchDealersByProvince($(this).attr('id'));
    });
    $('#ZipCodeSearchButton').bind('click', function () {
        fetchDealers();
    });
    $("#Zipcode").keyup(function (event) {
        if (event.keyCode == 13) {
            $("#ZipCodeSearchButton").click();
        }
    });

    $('.moreImages').bind('click', function () {
        var newSrc = $(this).attr('src').replace('/100/52/', '/620/320/');
        $('#mainImage').attr('src', newSrc);
    });

    $("#MapNederland area").mouseenter(function () {
        //var idx = $("#regiosmap area").index(this);
        $("#NederlandImg")[0].className = this.id;
    }).mouseleave(function () {
        if ($("#NederlandImg")[0].className == this.id) {
            $("#NederlandImg")[0].className = "";
        }
        return false;
    });

    if ($(location).attr('href').indexOf('Dealers/') > 0) {
        var url = $(location).attr('href').split('/');
        var province = url.pop();
        var check = url.pop();
        if (check == 'Dealers') {
            fetchDealersByProvince(province);
        }
    }

    $('.Amount').bind('change', function () {
        var lineId = $(this).parent().siblings().last().children().attr('href').split('/').pop();
        var newAmount = $(this).children(':selected').attr('Value');

        $(window.location).attr('href', 'UpdateShoppingCartLine/' + lineId + '/' + newAmount);
    });

    $('.DeliveryOption').live('change', function () {
        var value = $(this).attr('value');
        if (value == 'delivery') {
            $('.deliveryAddress').show();
            $('#dealerDelivery').hide();
            setDeliveryAddress();
        }
        else if (value == 'invoice') {
            $('.deliveryAddress').hide();
            $('#dealerDelivery').hide();
        }
        else if (value == 'dealer') {
            $('#dealerDelivery').show();
            $('.deliveryAddress').show();
            setDealerAddress();
        }
    });

    $('#DealerDeliveryId').live('change', function () {
        setDealerAddress();
    });


    $("#specificationSlider").scrollable({ size: 4 }); // , items: ".specificationItems"

    $('#showAccessories').bind('click', function () {
        if ($('#carrierParts').is(':visible')) {
            toggleCarrierParts();
        }
        toggleCarrierAccessory();
        return false;
    });


    $('#showParts').bind('click', function () {
        if ($('#carrierAccessories').is(':visible')) {
            toggleCarrierAccessory();
        }
        toggleCarrierParts();
        return false;
    });

    $('#hideWebsite').bind('click', function () {
        $('#siteWrapper').slideToggle(2500);
    });
});




$(window).scroll(function () {
    var windowTop = $(window).scrollTop();
    //console.debug(windowTop);
    if (windowTop > 513) {
        $('#shoppingCartPreview').css('top', windowTop - 263);
    }
    else if (windowTop < 513) {
        $('#shoppingCartPreview').css('top', 250);
    }
});

function toggleCarrierAccessory() {
    $('#showAccessories').toggleClass('accessoryShowed');
    $('#carrierAccessories').slideToggle(2500, function () {
    });
}

function toggleCarrierParts() {
    $('#showParts').toggleClass('partsShowed');
    $('#carrierParts').slideToggle(2500, function () {
    });
}

function setBackGround(window, imageSource) {
    var windowWidth = window.width();
    var imageWidth = 1024;

    if (windowWidth <= 1024) {
        imageWidth = 1024;
    }
    else if (windowWidth <= 1280) {
        imageWidth = 1280;
    }
    else if (windowWidth <= 1366) {
        imageWidth = 1366;
    }
    else if (windowWidth <= 1440) {
        imageWidth = 1440;
    }
    else if (windowWidth <= 1680) {
        imageWidth = 1680;
    }
    else if (windowWidth > 1680) {
        imageWidth = 1920;
    }


    var imgPath = '/site/images/cache/' + imageWidth + '/0/' + imageSource;
    $('img#bg').attr('src', imgPath);
}


function initNLMap() {
    $('#map_canvas').html('');
    var center = new google.maps.LatLng(52.296722, 5.298157);
    var leftTop = new google.maps.LatLng(53.3702215, 4.877930);
    var leftBottom = new google.maps.LatLng(51.261055, 3.221741);
    var rightTop = new google.maps.LatLng(53.383328, 7.316895);
    var rightBottom = new google.maps.LatLng(50.666872, 6.042480);


    var latlngbounds = new google.maps.LatLngBounds();
    latlngbounds.extend(leftTop);
    latlngbounds.extend(leftBottom);
    latlngbounds.extend(rightTop);
    latlngbounds.extend(rightBottom);
    
    
    var myOptions = {
        zoom: 7,
        center: center,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    map.fitBounds(latlngbounds);
}

function setDealerAddress() {
	/*var dealerId = $('#DealerDeliveryId').attr('value');
	var dealerUrl = "GetDealerInfo/" + dealerId;

	$.getJSON(dealerUrl, function (json) {
		if (json.Success) {
			$('#DeliveryAddress_AddressLine1').attr('value', json.Addressline);
			$('#DeliveryAddress_AddressLine1').attr('disabled', 'disabled');
			$('#DeliveryAddress_Zipcode').attr('value', json.ZipCode);
			$('#DeliveryAddress_Zipcode').attr('disabled', 'disabled');
			$('#DeliveryAddress_City').attr('value', json.City);
			$('#DeliveryAddress_City').attr('disabled', 'disabled');
			$('#DeliveryAddress_CountryId').attr('value', json.City);
			$('#DeliveryAddress_CountryId').attr('disabled', 'disabled');
		}
	});*/
}

function setDeliveryAddress() {
	var addressUrl = "GetDeliveryAddress";

	$.getJSON(addressUrl, function (json) {
		if (json.Success) {
			$('#DeliveryAddress_AddressLine1').attr('value', json.Addressline);
			$('#DeliveryAddress_AddressLine1').removeAttr('disabled');
			$('#DeliveryAddress_Zipcode').attr('value', json.ZipCode);
			$('#DeliveryAddress_Zipcode').removeAttr('disabled');
			$('#DeliveryAddress_City').attr('value', json.City);
			$('#DeliveryAddress_City').removeAttr('disabled');
			$('#DeliveryAddress_CountryId').attr('value', json.City);
			$('#DeliveryAddress_CountryId').removeAttr('disabled');
		}
	});
}

var infoWindows = null;
var markers = null;
var openInfoWindow = null;

var map = null;

var latlngArray = new Array();

function fetchDealers() {
    latlngArray = new Array();
	var zipCode = $('#Zipcode').val().replace(' ','');
	var country = $('#Country').val();
	var countryFull = $("#Country option:selected").html();
	var officials = 'false';
	if ($('input[name=officials]').attr('checked') == 'checked') {
		officials = 'true';
	}
	var address = "";
	var point1 = new google.maps.LatLng(55.397831,1.021729);
	var point2 = new google.maps.LatLng(47.002734, 14.996338);
	var bounds = new google.maps.LatLngBounds();
	bounds.extend(point1);
	bounds.extend(point2);

	var geocoder = new google.maps.Geocoder();
		$('#dealers').html('');
		$('#map_canvas').html('');
		address = zipCode;
		var latlng = new google.maps.LatLng(53.1872124, 6.1265592);
		var myOptions = {
			zoom: 11,
			center: latlng,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};


		geocoder.geocode({ 'address': address, 'bounds': bounds, 'region': country }, function (results, status) {
		    if (status == google.maps.GeocoderStatus.OK) {
		        var returnedAddress = results[0].formatted_address.toString();

		        var geoResult = results[0].address_components;
		        if (validateGeoResult(geoResult, country)) {
		            //if (returnedAddress.indexOf(countryFull) != -1) {
		            map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
		            map.setCenter(results[0].geometry.location);

		            var lat = results[0].geometry.location.lat();
		            var lon = results[0].geometry.location.lng();

		            var distance = $('#ZipCodeDistance').val();
		            var url = 'FindDealers/' + lon + '/' + lat + '/' + distance + '/false';
		            if ($(location).attr('href').indexOf('Dealers/') > 0) {
		                url = '../FindDealers/' + lon + '/' + lat + '/' + distance + '/false';
		            }
		            $.getJSON(url, function (json) {
		                if (json.Success) {
		                    var dealers = json.Results.DealerList;
		                    markers = new Array();
		                    infoWindows = new Array();

		                    for (var i in dealers) {
		                        var x = parseFloat(dealers[i].Lon);
		                        var y = parseFloat(dealers[i].Lat);
		                        var latLng = new google.maps.LatLng(y, x);
		                        latlngArray[i] = latLng;
		                        var marker = new google.maps.Marker({
		                            position: latLng,
		                            map: map,
		                            title: dealers[i].CompanyName + ' ' + dealers[i].AddressLine + ' ' + dealers[i].ZipCode + ' ' + dealers[i].City
		                        });
		                        AttachInfoWindow(marker, dealers[i], latLng);

		                        var latlngbounds = new google.maps.LatLngBounds();
		                        for (var i = 0; i < latlngArray.length; i++) {
		                            latlngbounds.extend(latlngArray[i]);
		                        }
		                        map.fitBounds(latlngbounds);
		                        
		                    }
		                    $('#dealers').html(loadDealerTable(dealers));
		                }
		            });
		        }
		        else {
		            zipCodeNotfound();
		        }
		    }
		});

	//}
}

function fetchDealersByProvince(province) {
	var address = province;
	var geocoder = new google.maps.Geocoder();
	var point1 = new google.maps.LatLng(55.397831, 1.021729);
	var point2 = new google.maps.LatLng(47.002734, 14.996338);
	var bounds = new google.maps.LatLngBounds();
	bounds.extend(point1);
	bounds.extend(point2);
	if (address != "") {
		$('#dealers').html('');
		$('#map_canvas').html('');
		var latlng = new google.maps.LatLng(53.1872124, 6.1265592);
		var myOptions = {
			zoom: 8,
			center: latlng,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

		geocoder.geocode({ 'address': address, 'region': 'NL' }, function (results, status) {
		    if (status == google.maps.GeocoderStatus.OK) {
		        map.setCenter(results[0].geometry.location);

		        var url = 'FindDealersByProvince/' + address;
		        if ($(location).attr('href').indexOf('Dealers/') > 0) {
		            url = '../FindDealersByProvince/' + address;
		        }

		        $.getJSON(url, function (json) {
		            if (json.Success) {
		                var dealers = json.Results.DealerList;
		                markers = new Array();
		                infoWindows = new Array();
		                for (var i in dealers) {
		                    if ((dealers[i].Lon != null) && (dealers[i].Lat != null)) {
		                        var x = parseFloat(dealers[i].Lon);
		                        var y = parseFloat(dealers[i].Lat);
		                        var latLng = new google.maps.LatLng(y, x);


		                        var marker = new google.maps.Marker({
		                            position: latLng,
		                            map: map,
		                            title: dealers[i].CompanyName + ' ' + dealers[i].AddressLine + ' ' + dealers[i].ZipCode + ' ' + dealers[i].City
		                        });

		                        AttachInfoWindow(marker, dealers[i], latLng);
		                    }
		                }
		                $('#dealers').html(loadDealerTable(dealers));
		            }
		        });

		    }
		});
	}
}


function fetchDealersForDelivery(zipcode) {
    var address = zipcode;
    var country = "NL";
    var point1 = new google.maps.LatLng(55.397831, 1.021729);
    var point2 = new google.maps.LatLng(47.002734, 14.996338);
    var bounds = new google.maps.LatLngBounds();
    bounds.extend(point1);
    bounds.extend(point2);

    var geocoder = new google.maps.Geocoder();
    $('#map_canvas').html('');
    var latlng = new google.maps.LatLng(53.1872124, 6.1265592);
    var myOptions = {
        zoom: 11,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };


    geocoder.geocode({ 'address': address, 'bounds': bounds, 'region': country }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {

            var geoResult = results[0].address_components;
            if (validateGeoResult(geoResult, country)) {
                map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
                map.setCenter(results[0].geometry.location);
                //console.debug(results[0].geometry.location);

                var lat = results[0].geometry.location.lat();
                var lon = results[0].geometry.location.lng();

                var url = 'FindDeliveryDealers/' + lon + '/' + lat;
                $.getJSON(url, function (json) {
                    if (json.Success) {
                        var dealers = json.Results.dealers;
                        markers = new Array();
                        infoWindows = new Array();

                        for (var i in dealers) {
                            var x = parseFloat(dealers[i].Lon.replace(',','.'));
                            var y = parseFloat(dealers[i].Lat.replace(',', '.'));
                            var latLng = new google.maps.LatLng(y, x);
                            latlngArray[i] = latLng;
                            var marker = new google.maps.Marker({
                                position: latLng,
                                map: map,
                                title: dealers[i].Name + ' ' + dealers[i].Addressline + ' ' + dealers[i].ZipCode + ' ' + dealers[i].City
                            });

                            AttachDealerInfoWindow(marker, dealers[i], latLng);
                        }

                        var latlngbounds = new google.maps.LatLngBounds();
                        for (var i = 0; i < latlngArray.length; i++) {
                            latlngbounds.extend(latlngArray[i]);
                        }
                        map.fitBounds(latlngbounds);
                    }
                });
            }
            else {
                zipCodeNotfound();
            }
        }
    });
}

function fetchAllDealersForDelivery(zipcode) {
    var address = zipcode;
    var country = "NL";
    var point1 = new google.maps.LatLng(55.397831, 1.021729);
    var point2 = new google.maps.LatLng(47.002734, 14.996338);
    var bounds = new google.maps.LatLngBounds();
    bounds.extend(point1);
    bounds.extend(point2);

    var geocoder = new google.maps.Geocoder();
    $('#map_canvas').html('');
    var latlng = new google.maps.LatLng(53.1872124, 6.1265592);
    var myOptions = {
        zoom: 11,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };


    geocoder.geocode({ 'address': address, 'bounds': bounds, 'region': country }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {

            var geoResult = results[0].address_components;
            if (validateGeoResult(geoResult, country)) {
                map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
                map.setCenter(results[0].geometry.location);
                //console.debug(results[0].geometry.location);

                var lat = results[0].geometry.location.lat();
                var lon = results[0].geometry.location.lng();

                var url = 'FindAllDeliveryDealers/' + lon + '/' + lat;
                $.getJSON(url, function (json) {
                    if (json.Success) {
                        var dealers = json.Results.dealers;
                        markers = new Array();
                        infoWindows = new Array();

                        for (var i in dealers) {
                            var x = parseFloat(dealers[i].Lon.replace(',', '.'));
                            var y = parseFloat(dealers[i].Lat.replace(',', '.'));
                            var latLng = new google.maps.LatLng(y, x);
                            latlngArray[i] = latLng;
                            var marker = new google.maps.Marker({
                                position: latLng,
                                map: map,
                                title: dealers[i].Name + ' ' + dealers[i].Addressline + ' ' + dealers[i].ZipCode + ' ' + dealers[i].City
                            });

                            AttachDealerInfoWindow(marker, dealers[i], latLng);
                        }

                        var latlngbounds = new google.maps.LatLngBounds();
                        for (var i = 0; i < latlngArray.length; i++) {
                            latlngbounds.extend(latlngArray[i]);
                        }
                        map.fitBounds(latlngbounds);
                    }
                });
            }
            else {
                zipCodeNotfound();
            }
        }
    });
}


function AttachDealerInfoWindow(marker, dealer, latLng) {
    var infowindow = new google.maps.InfoWindow({
        position: latLng,
        content: dealer.Name + '<br />' + dealer.Addressline + '<br />' + dealer.ZipCode + ' ' + dealer.City
    });
    google.maps.event.addListener(marker, 'click', function () {
        if (openInfoWindow != null) {
            openInfoWindow.close();
        }
        infowindow.open(map, marker);
        openInfoWindow = infowindow;
        $('#DealerDeliveryId').val(dealer.ObjectID);
        //console.debug(dealer.ObjectID);
        $('#DealerAddress h2').show();
        $('span#dealerDeliveryAddress').html('<table><tr><td>' + dealer.Name + '</td></tr><tr><td>' + dealer.Addressline + '</td></tr><tr><td>' + dealer.ZipCode + ' ' + dealer.City + '</td></tr></table>');
        $('#DealerAddress p').show();
    });
}

function AttachInfoWindow(marker, dealer, latLng) {

	var infowindow = new google.maps.InfoWindow({
		position: latLng,
		content: dealer.CompanyName + '<br />' + dealer.AddressLine + '<br />' + dealer.ZipCode + ' ' + dealer.City
});
	google.maps.event.addListener(marker, 'click', function () {
	    if (openInfoWindow != null) {
	        openInfoWindow.close();
	    }
	    infowindow.open(map, marker);
	    openInfoWindow = infowindow;
	});

}

function loadInfoWindow(map, index) {
	var infoWindow = infoWindows[index];
	infoWindow.open(map);
}

function loadDealerTable(dealers) {
	var counter = 0;
	var cellClass = 'dealerCell';
	var result = '<table width="100%"><tr>';
	for (var i in dealers) {
		counter++;
		result += '<td class=' + cellClass + '>';
		result += '<p class="dealerName">' + dealers[i].CompanyName + '</p>';
		result += '<p>' + dealers[i].AddressLine + '</p>';
		result += '<p>' + dealers[i].ZipCode + ' ' + dealers[i].City + '</p>';
	    result += '</td>';
		if (counter % 3 == 0) {
			if (cellClass == 'dealerCell') {
				cellClass = 'dealerCell2';
			}
			else {
				cellClass = 'dealerCell';
			}
			result += '</tr><tr>';
		}
	}
	result += '</tr></table>';

	return result;
}


function validatePostalCode(zipcode, country) {
	if (country == 'NL') {
		if (zipcode.match(/[1-9][0-9]{3} ?[a-zA-Z]{2}/)) {
			return true;
		}
		else{
			return false;
		}
	}
	if (country == 'BE' || country == 'DE') {
		if (zipcode.match(/[1-9][0-9]{3}/)) {
			return true;
		}
		else {
			return false;
		}
	}
	return false;

}

function validateGeoResult(objectArray, countryShort) {
	for (var i in objectArray) {
		if (objectArray[i].short_name == countryShort) {
			return true;
		}
	}
	return false;
}

function zipCodeNotfound() {
	var url = 'ZipCodeNotFound';
	$.getJSON(url, function (json) {
		if (json.Success) {
			var errorMessage = json.Results;
			$('#map_canvas').html(errorMessage);
		}
	});
}

