
function popup(arg) {
						   
// Here we will write a function when link click under class popup				   
								
						
// Here we will describe a variable popupid which gets the
// rel attribute from the clicked link							
var popupid = $('#'+arg).attr('rel');


// Now we need to popup the marked which belongs to the rel attribute
// Suppose the rel attribute of click link is popuprel then here in below code
// #popuprel will fadein
$('#'+arg).fadeIn();


// append div with id fade into the bottom of body tag
// and we allready styled it in our step 2 : CSS
//$('body').append('<div id="fade"></div>');
$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();


// Now here we need to have our popup box in center of 
// webpage when its fadein. so we add 10px to height and width 
var popuptopmargin = ($('#' + popupid).height() + 10) / 2;
var popupleftmargin = ($('#' + popupid).width() + 10) / 2;


// Then using .css function style our popup box for center allignment
$('#' + popupid).css({
'margin-top' : -popuptopmargin,
'margin-left' : -popupleftmargin
});



// Now define one more function which is used to fadeout the 
// fade layer and popup window as soon as we click on fade layer
$('#fade').click(function() {


// Add markup ids of all custom popup box here 						  
$('#fade , #popuprel, #tips').fadeOut()
return false;
});
};

function popup2(url2)
	{
		$('#popuprel').remove();
		var div = '';
		var div2 = '';
		div += '<div class="popupbox2" id="popuprel">';	
		
		$.ajax({
			url: url2,
			success: function(data) {
				div += $('#popuprel').html(data);		
			}
		});
		
		div += '</div>';
		var div2 = '<div id="fade"></div>';
		
		$("body").append(div);
		$("body").append(div2);
		
		$('#popuprel').fadeIn();
		$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
		
		
		$('#fade').click(function() {
			// Add markup ids of all custom popup box here 						  
			$('#fade,#popuprel').fadeOut()
			return false;
			});
	}
	
	function kalkuler() {
		if($('#gram').val().length > 0) {
			var gram = parseFloat($('#gram').val().replace(",","."));
			//alert(gram);
			//var gram = parseFloat($('#gram').val());
			var k = Number($('#karat').val());
			var pris = $('#pris').val();
			
			if($('#karat').val() > 0.8750 ) {
				var resultat = (gram * (pris * prosent_gull_22)) * k;
			}else{
				var resultat = (gram * (pris * prosent_gull)) * k;
			}
			$('#resultat').html("Ditt gull er verdt: " + resultat.toFixed(2) + " kr");
		}else{
			alert("Vennligst tast inn antall gram.");
			return false;
			
		}
		
	}
	
	function sporing() {
		if($('#q').val().length < 5) {
			alert("Vennligst tast inn et sporingsnummer.");
			return false;
		}
	}
	
	function validate() {
		var valid = true;
		var flereepost = false;
		var msg = "Følgende felter er feil fylt ut:" + "\n";
		$('#validate_form input').each(function(index) {
			if($(this).attr('type') != "hidden") {
				if($(this).attr('rel') == "text") {
					if($(this).val().length < 2) {
						$(this).css('background','#ff8484');
						valid = false;
						msg += "-" + $(this).attr('id') + "\n";
					}else{
						$(this).css('background','#fff');
					}
				}
				if($(this).attr('rel') == "number") {
					if(isNaN(parseInt($(this).val())) || $(this).val().length < 4) {
						$(this).css('background','#ff8484');
						valid = false;
						msg += "-" + $(this).attr('id') + "\n";
					}else{
						$(this).css('background','#fff');
					}
					
				}
				if($(this).attr('rel') == "e-post") {
					if($(this).val().indexOf('@') == -1) {
						$(this).css('background','#ff8484');
						valid = false;
						msg += "-" + $(this).attr('id') + "\n";
					}else{
						$(this).css('background','#fff');
					}
					
				}
				
				
			}
		});
		
		if($('#e-post').val() !== $('#e-post2').val()) {
			valid = false;
			msg += "De 2 e-postadressene du har tastet inn er ikke like.";
		}
		
		if(valid == false) {
			alert(msg);
			return false;
		}
	}
	
	
	function validate2() {
		var valid = true;
		var msg = "Følgende felter er feil fylt ut:" + "\n";
		$('#validate_form2 input').each(function(index) {
			if($(this).attr('type') != "hidden") {
				navn = $(this).attr('navn');
				if($(this).attr('rel') == "text") {
					if($(this).val().length < 2) {
						$(this).css('background','#ff8484');
						valid = false;
						msg += "-" + navn + "\n";
					}else{
						$(this).css('background','#fff');
					}
				}
				if($(this).attr('rel') == "number") {
					if(isNaN(parseInt($(this).val())) || $(this).val().length < 4) {
						$(this).css('background','#ff8484');
						valid = false;
						msg += "-" + navn + "\n";
					}else{
						$(this).css('background','#fff');
					}
					
				}
				if($(this).attr('rel') == "e-post") {
					if($(this).val().indexOf('@') == -1) {
						$(this).css('background','#ff8484');
						valid = false;
						msg += "-" + navn + "\n";
					}else{
						$(this).css('background','#fff');
					}
					
				}
				
				
			}
		});
				
		if(valid == false) {
			alert(msg);
			return false;
		}
	}
	
$(function() {
	$('#postnummer').keyup(function(event){
		var postnr = $('#postnummer').val();
		if (postnr.length == 4){
			$.get('/ajax_postnr.asp?p=' + postnr, function(data) {$('#poststed').val(data)});
		};
	});
});
	

	
	



