
(function( $, doc ){
	$.htmldecode = function(value){
	 return value.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>');
	};
})(jQuery, document );


(function( $, doc )
{
	$.toJSON = function(value){
	 return eval('('+value+')');
	};
})(jQuery, document );


$regx = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/;

$(function(){

$("#name,#email,#telefon,#message").focus(function() {
   
  if ($(this).val() == $(this).data("placeholder")) {
    $(this).val("");
    
  }
}).blur(function() {
 
  if ($(this).val() == "" || $(this).val() == $(this).data("placeholder")) {
  
    $(this).val($(this).data("placeholder"));
  }
}).blur();


$(".required").blur(function(){
			if($.trim($(this).val()) == "" || $.trim($(this).val()) == "Namn" || $.trim($(this).val()) == "Email"){
				$(this).addClass("blank");
				$(this).val('');
		     }
			 else{
			 
			 	if($(this).attr("id") == "email" && $regx.test($(this).val()) == false){							
				
					
					if($(this).hasClass("blank") == false)
						$(this).addClass('blank');		
					
					
				
				}
				else{
				
				
			 	if($(this).hasClass("blank") == true)
				 $(this).removeClass('blank');}
			 
			 }
		});	
		
	$("input[name=btnSend]").click(function(){
	
	
	$isvalid=true;
	$name=$("#name").val();
	$email=$("#email").val();
	$telephone=$("#telefon").val();
	$comment=$("#message").val();



		$(".required").each(function(){	
			if($.trim($(this).val()) == "" || $(this).val() == "Namn" || $(this).val() == "Email")
			{	
				$isvalid = false;
				if ($(this).hasClass("blank")== false)
					$(this).addClass("blank");
			
			}
			else
			{
				if ($(this).hasClass("blank")== true)
				$(this).removeClass("blank");
			}
		});
		
		
		
		
		if($.trim($email) != "" || $.trim($email) != "Email")
		{		
			if($regx.test($email) == false)
			{
				if($("#email").hasClass("blank")== false)
				{
				  $("#email").addClass("blank");
				  	$isvalid = false;
				}
				
			}
			else{
			
			 $isvalid == false ? false : true;
			
			}
			
	  }
	  else{
	 $isvalid =false ;	  
	}
	  
	  if($isvalid){
		
		$.loading(true);
		
		$.post($_posturl,{name : $name, email : $email,telephone : $telephone, comment : $comment  },function(response){
			
		$.loading(false);
			if (response==1)
			{
				alert("Mejlet skickat");
				
					$("#name").val($("#name").data("placeholder"));
					$("#email").val($("#email").data("placeholder"));
					$("#telefon").val($("#telefon").data("placeholder"));
					$("#message").val($("#message").data("placeholder"));
				
			}
			
			else
			{
				alert("Mail was not sent.Please try again")
			}
		});  
		  
	  }
	
});
		
		
		
	
});

	
	$(function(){
		
		$('.kontact-icon').click(function()
	{
		var target = $(this).parent('.contact-form-wrapper');
		var animator = {right: "-20"};
		var animator2 = {right: "-221"};
		
		if(target.is('.display_switch'))
		{
			if(target.is('.switcher_right')) 
			{
				animator = {left: "-221"};
				animator2 = {left: "-20"};
			}
			target.animate(animator, function()
			{
				target.removeClass('display_switch').addClass('display_switch_false');
			});
			
			
			
		}
		else
		{
			if(target.is('.switcher_right')) 
			{
				animator = {left: "-221"};
				animator2 = {left: "-20"};
			}
		
			target.animate(animator2, function()
			{
				target.removeClass('display_switch_false').addClass('display_switch');
			});
			
		}
	});
		
	
	
	
	
	
	
	
	
	
	
	
	
	
	});
	


function displayarticle(ctrl)
{
	$article = $.toJSON($(ctrl).data("news"));
	$("#article-title").html($article.title);
	$("#article-image-wrapper").find("img").attr("src",$article.image);
	$("#article-date").html($article.date);
	$("#article-description").html($.htmldecode($article.description));	
}
