function clearInput() {
	$('.fade').focus(function() {
	   $(this).select();
	   $(this).prev().fadeTo(150, 0);
	   $(this).keydown(function() {
		  // $(this).css('background-repeat', 'repeat');                  
	   });
	});
	$('.fade').blur(function() {
	   if($(this).val() == '' ) {
		   //$(this).css('background-repeat', 'no-repeat');
		   $(this).prev().fadeTo(150, 1);
	   }
	});
	$('.fade').each(function(){
	   if($(this).val() != '') {
		   //$(this).css('background-repeat', 'repeat');
	   };
	});
}

function initialize() {
	
	var locations = [
		['Regio Maastricht', 50.851368,5.690973],
		['Regio Heerlen', 50.888174,5.979499],
		['Regio Sittard', 50.998405,5.869119],
		['Regio Helmond', 51.479255,5.65701],
		['Regio Eindhoven', 51.441642,5.469723],
		['Regio Tilburg', 51.57, 5.07],
		['Regio Breda', 51.574807,4.774816],
		['Regio Den Bosch', 51.697928,5.317006],
		['Regio Dordrecht',	51.797387,4.673479],
		['Regio Etten-leur', 51.578155,4.649388],
		['Regio Oosterhout', 51.63904,4.861737],
		['Regio Roosendaal', 51.532135,4.461994],
		['Regio Bergen op zoom', 51.494576,4.287162],
		['Regio Goes', 51.504646,3.89113],
		['Regio Middelburg', 51.5,3.616667],
		['Regio Middelharnis', 51.75,4.17],
		['Regio Rotterdam', 51.924216,4.481776],
		['Regio Den haag', 52.069858,4.291111],
		['Regio Oud-beijerland', 51.82,4.42],
		['Regio Waalwijk', 51.689491,5.05824],
		['Regio Gorichem', 51.834326,4.969423],
		['Regio Oirschot', 51.50705,5.309181],
		['Regio Brielle', 51.903555,4.163984],
		['Regio Hellevoetsluis', 51.833133,4.143303],
		['Regio Oostvoorne', 51.911356,4.094649],
		['Regio Weert', 51.252171,5.70457],
		['Regio Valkenswaard', 51.350278,5.458889],
		['Regio Tholen', 51.532717,4.215673],
		['Regio Helmond', 51.479255,5.65701],
		['Regio Zierikzee', 51.650069,3.918367],
		['Regio Spijkenisse', 51.8413,4.331841],
		['Regio Oss', 51.764377,5.51462],
		['Baarle Nassau', 51.445137,4.929523],
		['Regio Zundert', 51.469144,4.656664],
		['Regio Steenbergen', 51.582223,4.319248],
		['Regio Zevenbergen',	51.645278,4.599722],
		['Regio Fijnaart', 51.63648,4.473156],
		['Regio Capelle a/d Ijssel', 51.93,4.58],
		['Regio Uden', 51.666667,5.616667],
		['Regio Nistelrode', 51.701908,5.562056],
		['Regio Oisterwijk', 51.577385,5.195134],
		['Regio Goeree overflakkee', 51.690977, 4.212683]
	];

	var myOptions = {
		zoom: 8,
		center: new google.maps.LatLng(51.574807,4.774816),
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};

	var map = new google.maps.Map(document.getElementById("google-maps"),
	myOptions);
	
	setMarkers(map, locations);
}

function setMarkers(map, locations) {
	 
	var image = new google.maps.MarkerImage('images/template/icon-google-maps.png',
	new google.maps.Size(50, 33),
	new google.maps.Point(0,0),
	new google.maps.Point(0, 25));
	
	var infowindow = new google.maps.InfoWindow();
 
	for (var i = 0; i < locations.length; i++) {
		var location = locations[i];
		var myLatLng = new google.maps.LatLng(location[1], location[2]);
		var marker = new google.maps.Marker({
			position: myLatLng,
			map: map,
			icon: image,
			title: location[0]
		});
	
		google.maps.event.addListener(marker, 'click', (function(marker, i) {
			return function() {
				infowindow.setContent('<strong style="font-size: 14px; color: #004178;">'+locations[i][0]+'</strong><br /><br /> Bel <span style="color: #004178; font-weight: bold;">0187 843337</span> voor een <strong style="color: #FAA635;">GRATIS</strong> proefles!');
				infowindow.open(map, marker);
			}
		})(marker, i));
	
	}

}

function validateStaticForm(p_sForm) {
	
	switch(p_sForm) {
		
		case 'contactform':
		case 'inschrijfform':
		
			var rules = {};
			rules['sName'] = {
				required: true,
				notags: true,
				minlength: 2
			};
			rules['sTelephone'] = {
				required: true,
				notags: true,
				minlength: 6
			};
			rules['sEmail'] = {
				required: true,
				email: true,
				notags: true
			};
			rules['sQuestion'] = {
				required: true,
				notags: true
			};
			
			var messages = {};
			messages['sName'] = {
				required: 'Vul uw naam in',
				notags: 'U mag geen tags invullen',
				minlength: 'Vul minimaal 2 tekens in'
			};
			messages['sTelephone'] = {
				required: 'Vul uw telefoonnummer in',
				notags: 'U mag geen tags invullen',
				minlength: 'Vul minimaal 6 tekens in'
			};
			messages['sEmail'] = {
				required: 'Vul uw e-mailadres in',
				email: 'Vul een geldig e-mailadres in',
				notags: 'U mag geen tags invullen'
			};
			messages['sQuestion'] = {
				required: 'Vul uw bericht in',
				notags: 'U mag geen tags invullen'
			};
			
			$('#'+p_sForm).validate({
				rules: rules,
				messages: messages,
				errorPlacement: function(error, element) {
					error.insertAfter(element.parents('.input, .textarea'));
				},
				success: function(label) {
					label.remove();
				},
				submitHandler: function(form) {
					form.submit();
				}
			});	
			
		break;
		case 'guestbookform':
			
			var rules = {};
			rules['sName'] = {
				required: true,
				notags: true,
				minlength: 2
			};
			rules['sEmail'] = {
				required: true,
				email: true,
				notags: true
			};
			rules['sMessage'] = {
				required: true,
				notags: true
			};
			
			var messages = {};
			messages['sName'] = {
				required: 'Vul uw naam in',
				notags: 'U mag geen tags invullen',
				minlength: 'Vul minimaal 2 tekens in'
			};
			messages['sEmail'] = {
				required: 'Vul uw e-mailadres in',
				email: 'Vul een geldig e-mailadres in',
				notags: 'U mag geen tags invullen'
			};
			messages['sMessage'] = {
				required: 'Vul uw bericht in',
				minlength: 4,
				notags: 'U mag geen tags invullen'
			};
			
			$('#'+p_sForm).validate({
				rules: rules,
				messages: messages,
				errorLabelContainer: '.response',
				errorElement: 'span',
				success: function() {
					
				},
				submitHandler: function(form) {
					
					var options = {
						url: 'guestbook/processform',
						type: "POST",
						success: function(p_sResponse) {
							var oJson = jQuery.parseJSON(p_sResponse);
							if(oJson.success == 'true') {
								$('#guestbookform').fadeOut(250, function() {
									$('#uploadform').fadeIn(250);
									$('#uploadform #nId').val(oJson.nID);
								});
							}
							$('.response').html(oJson.response);
							$('.response').fadeIn(250);
						},
						error: function(message){
							alert('error'+message);
						}
					}
						
					$(form).ajaxSubmit(options);
					
				}
			});	
			
		break;
		
	}	
	
}

function customSelect(){
	$("select").each(function(){
		$(this).wrap("<div class='selector'></div>");
		
		var spanText = $(this).attr('title');
		var span = "<span class='select'>" + spanText + "</span>";
		
		$(this).before(span)
		.fadeTo(1, 0)
		.focus(function(){
			$(this).parents(".selector").addClass("focus");
		})
		.change(function(){
			$(this).siblings("span").text($(this).children(":selected").text());
		}).click ( function (){
			$(this).siblings("span").text($(this).children(":selected").text());		
		}) 
		.blur(function(){
			$(this).parents(".selector").removeClass("focus");
		});	
	});
	$('select').trigger("change");
}

function clearInput() {
	$('.fade').focus(function() {
		$(this).select();
		$(this).prev().fadeTo(150, 0);
		$(this).keydown(function() {
			$(this).css('background-repeat', 'repeat');			 
		});
	});
	$('.fade').blur(function() {
		if ( $(this).val() == '' ) {
			$(this).css('background-repeat', 'no-repeat');
			$(this).prev().fadeTo(150, 1);
		}
	});
	$('.fade').each(function(){
		if ( $(this).val() != '') {
			$(this).css('background-repeat', 'repeat');
		};
	});
}

function uploadImage() {
    $('#file_upload').uploadify({
        'script'    		: 'guestbook/processform',
        'cancelImg'   		: 'images/cancel.png',
        //'folder'      		: 'http://www.webkey6.nl/klant/nxxt/images/guestbook',
        'auto'        		: false,
        'method'      		: 'post',
        'scriptAccess' 		: 'always',
        'removeCompleted' 	: false,
        'scriptData'		: {'uploadifyUpload': true },
        'sizeLimit'   		: 102400,
        'width'				: 120,
        'height'			: 30,
        'fileExt'     		: '*.jpg;*.gif;*.png',
		'fileDesc'    		: 'Image Files',
		'onError': function (event, queueID ,fileObj, errorObj) {
			var msg;
            if (errorObj.status == 404) {
               //alert('Could not find upload script. Use a path relative to:');
               msg = 'Could not find upload script.';
            } else if (errorObj.type === "HTTP")
               msg = errorObj.type+": "+errorObj.status;
            else if (errorObj.type ==="File Size")
               msg = fileObj.name+'<br>'+errorObj.type;
            else
               msg = errorObj.type+": "+errorObj.text;
            	//alert(msg);

		},
		'onComplete': function(event, ID, fileObj, p_sResponse, data) {
			var oJson = jQuery.parseJSON(p_sResponse);
			if(oJson.success == 'true') {
				$('#uploadform').fadeOut(250);
				$('.response').html(oJson.response);
			}
	    }

      });
    $('#uploadform .submit input').click(function() {    	
    	$('#file_upload').uploadifySettings("scriptData", {'uploadifyUpload': true, 'sessionID' : $('#nId').val()}, true);
    	$('#file_upload').uploadifyUpload();
    });
}
