$(document).ready(function(){
				   
	if(LoadPopUp)
	{
		
		if( parseInt($('.popUpVal').text()) == 1)
		{

				    createPopup();	 					
					$('#popup_form #popup_bt_send').bind('click',checkAndSubmit);
					
					
					
	$('#email1').focus(function(){ if (this.value == "Skriv din email her") { this.value=""; this.style.color="black"; } });
	$('#email1').blur(function(){ if (this.value == "") {this.value="Skriv din email her"; this.style.color="#828282"; } });
	$('#popupname').focus(function(){ if (this.value == "Navn") { this.value=""; this.style.color="black"; } });
	$('#popupname').blur(function(){ if (this.value == "") {this.value="Navn"; this.style.color="#828282"; } });
	$('.MainPopup_container .close').bind('click',function(){ $('.MainPopup_container').fadeOut(400);  });
					
					
					
					resizing();  
					$(window).resize(resizing);	 

	} 
		}
						   });




function resizing()
{
	var W  = $(window).width();
	var H  = $(window).height();
	tgtLeft = (W - $('.MainDiv_container').width())/2;
	tgttop = (H - $('.MainDiv_container').height())/2;
	var obj = {left:tgtLeft,top:tgttop};
	$('.MainDiv_container').stop().animate(obj,850);
	$('#shadow').css('opacity',0.6);
	$('#shadow').css('width',W);
	$('#shadow').css('height',H);
}


function createPopup()
{
    var htmlc = '<form id="popup_form" method="post" name="frm_check" action=""><div class="MainPopup_container"> ';
	 	htmlc = htmlc + '<div id="shadow" ></div>';
htmlc = htmlc + '<div class="MainDiv_container" > ';
		htmlc = htmlc + '<div class="close" >';
		htmlc = htmlc + '<img src="images/Close.png" //></div>'; 
		htmlc = htmlc + '<div class="Heading">';
		htmlc = htmlc + ' <span>Tilmeld nyhedsbrev</span>';
		htmlc = htmlc + '<img class="popupimg" src="images/banner.jpg" />';
htmlc = htmlc + ' <span style="font-size:13px;color:#2d56c0;"><br//>Nyhedsbrevene er gratis og kan til enhver tid frameldes.<br//>Disse udsendes ca. hver m&aring;ned</span></div>';
		htmlc = htmlc + ' <input id="popupname" type="text" name="name" class="input_textfeild InputText" value="Navn"   />';
		htmlc = htmlc + ' <input id="email1" type="text" name="email" class="input_textfeild InputText" value="Skriv din email her"   />';
		htmlc = htmlc + '<input type="hidden" value="Tilmeld" class="button popup_button" name="send"/>';
		//htmlc = htmlc + '<input type="submit" value="Tilmeld" class="button popup_button" name="send" id="popup_bt_send"/>';
		htmlc = htmlc + '<div id="popup_bt_send" value="Tilmeld" class="popup_button">Tilmeld</div>';
				
		htmlc = htmlc + '</div></div></form>';
		 
		 
	
	$('body').append(htmlc);

						   



}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		  // alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		  // alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   // alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   // alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   // alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   // alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
 



function checkAndSubmit(e)
{
  if($('#popup_form').find('#popupname').attr('value').length > 0 && $('#popup_form').find('#popupname').attr('value') != "Navn")
  {
	   if(echeck($('#popup_form').find('#email1').val()) )
	   {
		
		  $('#popup_form').submit(); 
	   }
	   else
	   {
		alert("Voer een geldige e-mailadres."); 
	   }
  }
  else
  {
	  alert("Voer een geldige Navn."); 
  }
 
}
