function checkForInt(evt) 
{
	evt = ( evt ) ? evt : window.event;
	var charCode = ( evt.which ) ? evt.which : evt.keyCode
	return (charCode <= 31 || (charCode >= 48 && charCode <= 57))
}

function buOv(id)
{
	document.getElementById("a" + id).className = 'a1Ov';
	document.getElementById("ico" + id).style.backgroundImage = 'url(/gfx/menu/bu' + id + 'Ov.gif)';
}

function buOut(id)
{
	document.getElementById("a" + id).className = 'a1';
	document.getElementById("ico" + id).style.backgroundImage = 'url(/gfx/menu/bu' + id + '.gif)';
}

function bu2Ov(id)
{
	if(id == "Home")
	{
		document.getElementById("img" + id).src = '/gfx/buHomeOv.gif';
	}
	else
	{
		document.getElementById("a" + id).className = 'a2Ov';
	document.getElementById("div" + id).className = 'menu3BuOv';
	}
}

function bu2Out(id)
{
	if(id == "Home")
	{
		document.getElementById("img" + id).src = '/gfx/buHome.gif';
	}
	else
	{
		document.getElementById("a" + id).className = 'a2';
	document.getElementById("div" + id).className = 'menu3Bu';
	}
}

function clearDefault(id)
{
	if(id.defaultValue == id.value)
	{
		$(id).addClass('inputCustomValue');
		$(id).removeClass('inputDefaultValue');
		id.value = "";
	}
}

function setDefault(id)
{
	if(id.value == "")
	{
		$(id).removeClass('inputCustomValue');
		$(id).addClass('inputDefaultValue');
		id.value = id.defaultValue;
	}
}

function goKleur(imgUrl)
{
	document.getElementById('prodImg').style.backgroundImage = 'url(' + imgUrl +')';
}


function wijzigAantal(form, val)
{
	if(val > 0)
	{
		document.getElementById("form" + form).submit();
	}
	else
	{
		document.getElementById('aantalBox' + form).style.display='block';
		/* document.getElementById('newNum' + form).focus(); */
	}
}

function addVal(form, val) 
{
    var select = document.getElementById("aantal" + form);
	select.options[select.options.length] = new Option(val, val);
}

function anderAdres()
{
	if(document.getElementById('canderadres0').checked == true)
	{
		document.getElementById('caa_name').value = "";
		document.getElementById('caa_street').value = "";
		document.getElementById('caa_houseNumber').value = "";
		document.getElementById('caa_houseNumberAdd').value = "";
		document.getElementById('caa_postalCode').value = "";
		document.getElementById('caa_city').value = "";
		$('#anderadresDiv').slideUp("slide");
	}
	else
	{
		$('#anderadresDiv').slideDown("slide");
	}
}

function vatNumber1()
{
	if($('#ccountryId').val() == "17" || $('#ccountryId').val() == "66")
	{
		$('#rechtsVorm').slideDown("slide");
		$('#ophalenknop').slideUp("slide");
		if(document.getElementById('crechtsvorm').value == "bedrijf")
		{
			$('.display2').slideDown("slide");
			$('.display3').slideDown("slide");
			//document.getElementById('crechtsvorm').value = "";
		}
		else if(document.getElementById('crechtsvorm').value == "vzw")
		{
			$('.display2').slideUp("slide");
			$('.display3').slideDown("slide");
		}
		else
		{
			$('.display2').slideUp("slide");
			$('.display3').slideUp("slide");
		}
		
		if($('#ccountryId').val() == "66")
		{
			$('#cc').html("DE");
		}
		else
		{
			$('#cc').html("BE");
		}
		
	}
	else
	{
		document.getElementById('cvatNumber').value = "";
		document.getElementById('crechtsvorm').value = "";
		$('.display2').slideUp("slide");
		$('.display3').slideDown("slide");
		$('#rechtsVorm').slideUp("slide");
		
		$('#ophalenknop').slideDown("slide");
		$('#cc').html("NL");
	}
	
	
}



$(document).ready(function(){
	$("#formMailinglist").validate({
		highlight: function(element, errorClass) {
		     $(element).addClass('f1Error');
		},
		unhighlight: function(element, errorClass) {
		     $(element).removeClass('f1Error');
		}
	});
	
	$("#selToepassing").change(function(){
		if($(this).val() != "")
		{
			var options = '<option value=""></option>';
			$("#selFormaat").html(options);
			$.getJSON("/include/jsondata.php",{toepassing: $(this).val(), action: 'getMaten'}, function(j){
		      for (var i = 0; i < j.length; i++) {
		        options += '<option value="' + j[i].id + '">' + j[i].id + '</option>';
		      }
		      $("#selFormaat").html(options);
		      if(j.length > 0)
		      {
		      	$('#selFormaat').removeAttr('disabled');
		      }
		    });
		    
	      	$('#buToonresultaten').removeAttr('disabled');
	      	$('#buToonresultaten').removeClass('disabled');
	    	$('#selFormaat').change();
		}
	});
	
	$("#selFormaat").change(function(){
		if($(this).val() != "")
		{
			$.getJSON("/include/jsondata.php",{toepassing: $("#selToepassing").val(), formaat: $(this).val(), action: 'getSoorten'}, function(j){
		      var options = '<option value=""></option>';
		      $("#selSoort").html(options);
		      for (var i = 0; i < j.length; i++) {
		        options += '<option value="' + j[i].id + '">' + j[i].id + '</option>';
		      }
		      $("#selSoort").html(options);
		      if(j.length > 0)
		      {
		      	$('#selSoort').removeAttr('disabled');
		      }
		    });
		}
	});

	$('#selToepassing').change();
	
	
	$(".getAddress").click(function(){
		postcode = $("input[name=postalCode]").val();
		houseNumber = $("input[name=houseNumber]").val();
		houseNumberAdd = $("input[name=houseNumberAdd]").val();
		$.ajax({
			url:"/include/jsondata.php",
			method:"post",
			data: ({	action: "getAddress",
						postalCode: postcode,
						houseNumber: houseNumber,
						houseNumberAdd: houseNumberAdd,
						companySearch: "1"
			}),
			dataType: "json",
			success: function(data){
					$("input[name=street]").val(data.street);
					$("input[name=city]").val(data.city);
					$("input[name=company]").val(data.company);
			}
		});
	});
	
	$(".getAddressAA").click(function(){
		postcode = $("input[name=aa_postalCode]").val();
		houseNumber = $("input[name=aa_houseNumber]").val();
		houseNumberAdd = $("input[name=aa_houseNumberAdd]").val();
		$.ajax({
			url:"/include/jsondata.php",
			method:"post",
			data: ({	action: "getAddress",
						postalCode: postcode,
						houseNumber: houseNumber
			}),
			dataType: "json",
			success: function(data){
				$("input[name=aa_street]").val(data.street);
				$("input[name=aa_city]").val(data.city);
			}
		});
	});
	
	
	
});


function checkVariation(val)
{
	alert(val);
}


