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

	$('#prev_new, #next_new, #next_used, #prev_used').click( function() {

		var ident = $(this).attr('id').substr(5);

		var p = $('#page_'+ident).val();
		var pages = $('#pages_'+ident).val();
		var active = $('#active').val();
		var brand = $('#brand').val();

		if($(this).attr('id') == 'prev_'+ident){
			p = parseInt(p) - 1;
		}else if($(this).attr('id') == 'next_'+ident){
			p = parseInt(p) + 1;
		}

		var categoryID = 70;
		var newcar = 0;

		if(ident == 'new'){
			var categoryID = 18;
			var newcar = 1;
		}

		if(p <= pages && p >= 1){
			$.get("xmlhttp/getPage.php", { p: p, active: active, newcar: newcar, categoryID: categoryID, brand: brand }, function(data){
				$('#list_'+ident).html(data);
			});

			if(p > 1){
				$('#prev_'+ident).removeClass('inactive');
			}else{
				$('#prev_'+ident).addClass('inactive');
			}

			if(p == pages){
				$('#next_'+ident).addClass('inactive');
			}else{
				$('#next_'+ident).removeClass('inactive');
			}

			$('#page_'+ident).attr('value', p);
		}

	});

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

		var form = true;
		var error = 0;
		$('#casio_katalog .check').each( function() {
				
			if($(this).val().length < 2){
				error = 1;
			}
		});

		if(error == 1){
			alert('Uppgifter saknas');
			form = false;
		}

		return form;
	});
});

function selectCar ( id ) {

	$.get('xmlhttp/getCar.php', { carID: id }, function(data){
		$('#product').html(data);
		$('#product').show();
	});

	window.scroll(0,0); 
}

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;
}