$(document).ready(function(){
	$(document).pngFix();
	
	
	$('.menuitem').each(function(){
		$(this).hover(
			function(){
				var offset = $(this).offset();
				var widthd = $(this).width();
				
				$(this).find('.dropdown').show();
				
				if($.browser.msie){
					$(this).find('.dropdown').css({"margin-left": '-'+ widthd +'px'});
				}
			},
			function(){
				$(this).find('.dropdown').hide();
			}
		)
	});
	
	$('#searchform').find('input[type=text]')
		.focus(function(){
			if($(this).val() == 'zoeken') $(this).val('');
		})
		.blur(function(){
			if($(this).val() == '') $(this).val('zoeken');
		});
		
	$('#searchform').find('form').submit(function(){
		var zoeken = $('#searchform').find('input[type=text]');
		if((zoeken.val() == "") || zoeken.val() == "zoeken"){
			return false;	
		}
	});
	
/*	$("form[name=contactus]").each(function(){		
		$(this).find("input").each(function(){
			$(this)
				.val( $(this).attr('alt') )
				.click(function(){
					if($(this).val() == $(this).attr('alt')) {
						$(this).val('');
					}
				})
				.blur(function(){
					if($(this).val() == '') {
						$(this).val($(this).attr('alt'));
					}
				});
		});
		$(this).find("textarea").each(function(){
			$(this)
				.val( $(this).attr('label') )
				.click(function(){
					if($(this).val() == $(this).attr('label')) {
						$(this).val('');
					}
				})
				.blur(function(){
					if($(this).val() == '') {
						$(this).val($(this).attr('label'));
					}
				});
		});		
		$(this).submit(function(){			
			var err = false;

			$(this).find("input[title=required]").each(function(){
				if(change_border($(this))) err = true;
			});

			$(this).find("textarea[title=required]").each(function(){								
				if(change_border($(this))) err = true;
			});
			
		
			if(err) {
				return false;
			}
			else {
				return true;
			}
		});	
	});/**/
	
	
});
/* --------------------------------------------------------------------------- /**/

function checkpostvalues() {
	if ($("#qoute_form #postalcode").val() != "" && $("#qoute_form #housenumber").val() != "") {
		$.ajax({
			type: "GET",
			url: "postcode/start.php",
			data: "postcode=" + $("#qoute_form #postalcode").val() + $("#qoute_form #housenumber").val(),
			success: function(msg){
				if (msg.getElementsByTagName('straatnaam')[0].firstChild) {
					$("#straatnaam").val(msg.getElementsByTagName('straatnaam')[0].firstChild.nodeValue);
					$("#woonplaats").val(msg.getElementsByTagName('woonplaats')[0].firstChild.nodeValue);
					//document.create_account.city.value = xmldoc.getElementsByTagName('woonplaats')[0].firstChild.nodeValue;
					//document.create_account.city.value = xmldoc.getElementsByTagName('woonplaats')[0].firstChild.nodeValue;
				}			
			}
		});
	}
}

function change_border(el) {
	if(el.val() == "") {
		el.addClass('errtext');
		return true;

	} else {
		if(el.attr('name') == 'email') {
			if(validateemail(el)) {
				el.removeClass('errtext');
				return false;
			}
			else {
				el.addClass('errtext');
				return true;
			}
		}
		else if(el.attr('name') == 'password' && el.attr('alt') != '' ) {
			
			var alt = el.attr('alt');
			var confrm = $('input[name=' + alt + ']');
			
			if(el.val() != confrm.val()) {
				el.addClass('errtext');
				confrm.addClass('errtext');
				return true;
			}
			else {
				el.removeClass('errtext');
				confrm.removeClass('errtext');
				return false;
			}
		}
		else {
			el.removeClass('errtext');
			return false;
		}
	}
}

function validateemail(el) {
	var matchArray = el.val().match(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/);
	
	if (matchArray == null) {
		return false;
	} else {
		return true;
	}
}

function show_footerlink(){
	
	if($('#footer_sub').data('open') != 'true'){
		$('#footer_sub').data('open', 'true').slideDown('fast');
	}
	else {
		$('#footer_sub').data('open', 'false').slideUp('fast');
	}
	return false;
}
