$('document').ready(function() {

	$('#contactForm').submit( function() {

		var name = $("input[@name='name']").val();
		var address = $("input[@name='address']").val();
		var city = $("input[@name='city']").val();
		var phone = $("input[@name='phone']").val();
		var email = $("input[@name='email']").val();

		var str = '';

		if(name.length < 3) str += " - Namn saknas\n";
		if(address.length < 3) str += " - Gatuadress saknas\n";
		if(city.length < 3) str += " - Postadress saknas\n";
		if(phone.length < 3) str += " - Telefon saknas\n";
		if(email.length < 3) str += " - E-mail saknas\n";
		

		if(str.length > 0){
			alert("Följande fel hittades:\n"+str);
			return false;
		}

		return true;

	});

	$('#articleID').change( function() {
		var ID = $(this).val();

		$.get('xmlhttp/getArticle.php', { ID: ID }, function(data){
			$('#article').html(data);
		});

	});
});

function popup (url, width, height, status, menu, resizable) {
	var time = new Date();
	var name = Math.floor((Math.random() * Math.round(time.getTime())));

	var prop = 'toolbar=no,location=no,directories=no,scrollbars=yes,copyhistory=no,';
	prop += 'status='+ (status ? 'yes' : 'no') +',';
	prop += 'resizable='+ (resizable ? resizable : 'yes') + ',';
	prop += 'menu='+ (menu ? 'yes' : 'no') +',';
	prop += 'width='+ (width ? width : 500) +',';
	prop += 'height='+ (height ? height : 400);

	var win = window.open(typeof(url) == 'string' ? url : url.href, name, prop);
	win.focus();
	
	return false;
}

function nemo (namn,foretag){
	location.href= 'mailto:'+namn+'@'+foretag;
	return false;
}