// SUBMIT FORM
	
	/*http://dotnetslackers.com/JavaScript/re-137768_JavaScript_gt_gt_Get_Any_CSS_Property_Value_of_an_Object_using_style.aspx*/
	function $style(ElementId, CssProperty)
	{
	    function $(stringId) {
	        return document.getElementById(stringId);
		}   

		if($(ElementId) != null){
			if($(ElementId).currentStyle) {
		        var convertToCamelCase = CssProperty.replace(/\-(.)/g, function(m, l){return l.toUpperCase()});
		        return $(ElementId).currentStyle[convertToCamelCase];
		    }
			else if (window.getComputedStyle)
			{
		        var elementStyle = window.getComputedStyle($(ElementId), "");
		        return elementStyle.getPropertyValue(CssProperty);
		    }
	    }
	}
	
	
	/*
	* jQuery emptyonclick plugin
	*
	* Created by Andreas Creten (andreas@madewithlove.be) on 2008-06-06.
	* Copyright (c) 2008 madewithlove. All rights reserved.
	*
	* Version: 1.2
	*/
	
	jQuery.fn.extend({
	    emptyonclick: function(options) {
	        return this.each(function() {
	            new jQuery.EmptyOnClick(this, options);
	        });
	    }
	});
	
	jQuery.EmptyOnClick = function(element, options) {
	    var defaultValue = $(element).val();
	    var defaultBgColor = $style($(element), "background-color");
	    var defaultColor = $style($(element), "color");

	    // Bind event handlers to the element
	    if($(element).attr('type') != "submit"){
			$(element)
			// On Focus: Store the default value if it's not set, empty the field
			.bind("focus", function(e) {
				if(defaultValue == $(this).val()){
					$(this).val('');
					$(this).attr('style', 'background-color:#999; color:#FFF;');
				}
			})

			// On Blur: if the field is empty, reset the default value
			.bind("blur", function(e) {
				if(!$(this).val()) {
					$(this).val(defaultValue);
					$(this).attr('style', 'background-color:'+defaultBgColor+'; color:'+defaultColor+';');
				}
			});

			// Search for the form which has the element
			/*$("form:has(#"+element.id+")")
			// If the form gets resetted, set the default value back
			.bind('reset', function(e) {
				//$(element).val(defaultValue);
				//$(element).removeClass(options.changeClass);
			}) 
			// If the form gets submitted empty, remove the default values
			.bind('submit', function(e) {
				//if($(element).val() == defaultValue) $(element).val('');
			});*/
	    }
	};
	
	$(function() {
		
		// TIP EN VENINDE ---------------------------------
		
		$("#tip-friend").hide();
		
		$("#tip-friend-btn").click(function(){
			$("#tip-friend").fadeIn();
	    });
	    $("#close-form").click(function(){
			$('#tip-friend').fadeOut();
	    });
		
		// CONTACT ---------------------------
		$('.contact-form').ajaxForm({ 
			target: '#contact-result',
			success: function() { 
				$('.contact-form').resetForm();
				$('#contact-result').fadeIn();
				//alert($('contact-form').val());
				/*setTimeout(function(){
					$('.contact-form')[ 0 ].reset();
				},4000);*/
				
			}
		});
		
		// TIP FRIEND ---------------------------
		$('.tipfriend-form').ajaxForm({ 
			target: '#tipfriend-result',
			success: function() { 
				$('#tipfriend-result').fadeIn(); 
			}
		});
	    
	    // NEWSLETTER ---------------------------
		/*$('.newsletter-form').ajaxForm({ 
			target: '#newsletter-result', 
			success: function() { 
				$('#newsletter-result').fadeIn();
			}
		});*/
		
		// ASK MARIE ---------------------------
		$('.askmarie-form').ajaxForm({ 
			target: '#askmarie-result', 
			success: function() { 
				$('#askmarie-result').fadeIn();
			}
		});
		
		$('input, textarea').emptyonclick();
	})
	
	function clearForm(theform, fade_out, duration){
		$(theform)[ 0 ].reset();
		//clear form after a few seconds
		setTimeout(function(){
			
			$('#success').remove();
			var config = { formControls: 'input[type="text"], textarea[value]' };
			config = $.extend(config);
			
			$(config.formControls,theform).each(function() {
				if($(this).val() == "Navn") $(this).attr('style', 'background-color:#9bc6e8; color:#777;');
				if($(this).val() == "Venindes email") $(this).attr('style', 'background-color:#eaecad; color:#777;');
				if($(this).val() == "E-mail") $(this).attr('style', 'background-color:#e5b3d0; color:#777;');
				if($(this).val() == "Besked") $(this).attr('style', 'background-color:#afaea9; color:#777;');
				if($(this).val() == "Spørgsmål") $(this).attr('style', 'background-color:#afaea9; color:#777;');
				if($(this).val() == "Skriv din e-mail...") $(this).attr('style', 'background-color:#e5b3d0; color:#777;');
			});
		},duration);
	
		if(fade_out){
			$('#tip-friend').animate({opacity: 1.0}, 3000);
			$('#tip-friend').fadeOut();
		}
	}

	
	
	/**** Submit buttons focus style (mousedown) *************************************/
	sfFocus = function() {
		var sfEls = document.getElementsByTagName("INPUT");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onfocus=function() {
				this.className+=" sffocus";
			}
			sfEls[i].onblur=function() {
				this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
			}
		}
	}
	if (window.attachEvent) window.attachEvent("onload", sfFocus);

