$(document).ready(function(){	
	
	// when creating a newsletter message:
	$("select[name='ml_template']").val('msgtemplate_klas_nyhetsbrev');

	// newsletter
	label2value();
	// debug: $("#newsletter-checkboxes").css("visibility", "visible");
	$("input[name='md4e46lists[]'][value='1']").click(); // select: alla
	$('#lan').change(function(e){
		// uncheck all
		for (var j=2; j<23; j++){
			$("input[name='md4e46lists[]'][value='"+j+"']").attr('checked', false);
		}
		// check
		$("input[name='md4e46lists[]'][value='"+$(this).val()+"']").click();
	});

	// css menu
	$("#navmenu-h li,#navmenu-v li").hover( function() { $(this).addClass("iehover"); }, function() { $(this).removeClass("iehover"); } ); 

	// fancybox
	$("#smakprov").fancybox({
		'width': '85%',
		'height': '95%',
		'autoScale': false,
		'transitionIn': 'elastic',
		'transitionOut': 'fade',
		'type': 'iframe'
	});

	// copy details checkbox
	$('a#copyOrderAdress').click(function(event) {

		$('input#m5bd08shipping_0_company').val( $('input#m5bd08billing_company').val() );
		
		$('input#m5bd08shipping_0_firstname').val( $('input#m5bd08billing_firstname').val() );
		
		$('input#m5bd08shipping_0_lastname').val( $('input#m5bd08billing_lastname').val() );
		
		$('input#m5bd08shipping_0_address1').val( $('input#m5bd08billing_address1').val() );
		
		
		
		$('input#m5bd08shipping_0_postal').val( $('input#m5bd08billing_postal').val() );

		$('input#m5bd08shipping_0_city').val( $('input#m5bd08billing_city').val() );

		$('input#m5bd08shipping_0_email').val( $('input#m5bd08billing_email').val() );

		  event.preventDefault();
	});
	
});

/*
 * label2value
 * jquery based script for using form labels as text field values
 * more info on http://cssglobe.com/post/1500/using-labels- 
 *
 * Copyright (c) 2008 Alen Grakalic (cssglobe.com)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 */

this.label2value = function(){	

	// CSS class names
	// put any class name you want
	// define this in external css (example provided)
	var inactive = "inactive";
	var active = "active";
	var focused = "focused";
	
	// function
	$("label").each(function(){		
		obj = document.getElementById($(this).attr("for"));
		if(obj!=null){ // added by Elia
			if(($(obj).attr("type") == "text") || (obj.tagName.toLowerCase() == "textarea")){			
				$(obj).addClass(inactive);			
				var text = $(this).text();
				$(this).css("display","none");			
				$(obj).val(text);
				$(obj).focus(function(){	
					$(this).addClass(focused);
					$(this).removeClass(inactive);
					$(this).removeClass(active);								  
					if($(this).val() == text) $(this).val("");
				});	
				$(obj).blur(function(){	
					$(this).removeClass(focused);													 
					if($(this).val() == "") {
						$(this).val(text);
						$(this).addClass(inactive);
					} else {
						$(this).addClass(active);		
					};				
				});				
			};	
		};
	});		
};
