$('document').ready( function () {
	/* INIT */



	$('#newsletteradd').submit( function() {
		
		var data = $('#newsletteradd').formSerialize();

		$.post('handlers/newsletter.handler.php', data, function(data) {
			var list = data.split('||');

			alert(data);

			if(list[0] == 1){
				$('.newsletter .msg').html(list[1]);
				$('#newsletteradd').hide();
			}else{
				$('.newsletter .msg').html(list[1]);
			}
		});

		return false;
	});


	$('#my_settings input, #register input').change( function() {

		var name = $(this).attr('name');
		var value = $(this).val();

		var obj = $(this);

		$(this).removeClass('error');
		$(this).removeClass('ok');

		var value2 = '';

		if(name == 'repeat_password'){
			var value2 = $("input[name$='password']").val();
		}


		$.post('xmlhttp/checkField.php', { field: name, value: value, value2: value2 }, function(data){

			var list = data.split('||');

			if(list[0] != 1){
				obj.addClass('error');
				$('#'+name).attr('value', 0);
			}else{
				obj.addClass('ok');
				$('#'+name).attr('value', 1);
			}

			$('.'+name+'_msg').html(list[1]);

			$('#my_settings input, #register input').each(function(){
				var cl = $(this).attr('class');

				if(!isNan(cl)){
					alert(cl);
				}
			});
		});
	});


	//Hover-function for webshop-standard och imagelist
	$('#webshop-imagelist tr, #webshop-standard tr').hover( function() {
		$(this).addClass('active');
	}, function() {
		$(this).removeClass('active');
	});
}); 

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

function changeProductMainPicture(img, imageID, productID, orgImg){
	$('.thumb').removeClass('active');

	$('#t_'+imageID).addClass('active');

	if(img.length > 5){
		$('#productImageLargeTD').html('<img src="'+img+'">');
	}
}
