function suggestion_write(suggestedmail, parent) {
   var  mkt_lang = "cs";
	
   $(parent + ' .mkt_email').val(suggestedmail);
   $(parent + ' #mkt_suggestion').attr('style','display:none');
}

(function() {
	
	$(document).on('newsletter:mailkit', function() {
       
       if($("#subscription-form").length) {
       	
       	     mailkitCore("#subscription-form");
       	
       } else if ($(".subscription-form").length) {
       	
       		 mailkitCore(".subscription-form");
       }
        
	});
	
	
	//ms darky od srdce
	
	$(document).on('newsletter:darkyOdSrdce', function(){
       
       if($("#ms-darkyOdSrdce-newsletter").length) {
       	
       	     mailkitCore("#ms-darkyOdSrdce-newsletter");
       	
       } 
	});
	
		
	
	//ms vseobecne
	
	$(document).on('newsletter:msNwsRegister', function(){
       
       if($("#ms-nws-register").length) {
       	
       	     mailkitCore("#ms-nws-register");
       	
       } 
	});
	

	$(document).on('newsletter:mailkitTajenka', function(){
     	
     	mktSuggest("#tajenka-form");
     	
   
     	function tajenkaValidate() {
     	
	     	$('#tajenka-form').validate({
			   onchange: false,
			   rules: {
				   "Quiz-email": {
					   onfocusout: false,
				   	   required: true,
					   email: true
				   }
			    },
			   messages: { 
				   "Quiz-email": {
				       required: "* zadejte svůj e-mail 2", 
				   	   email: "* špatný formát e-mailu 2"
				   }
				}
			});
		
     	}
     	
	});
	
	$(document).on('newsletter:mailkitRecipes', function(){

        mailkitCore("#subscription-form-recipes");
        
	});

	$(document).on('newsletter:mailkitSeasonRecipes', function(){

        mailkitCore("#subscription-form-season-recipes");
        
	});
	

	function mailkitCore(mailkitForm) {

		mtkValidate(mailkitForm);
		mktSuggest(mailkitForm);
	}
	
	function mtkValidate(mailkitForm) {
		
		$(mailkitForm).validate({
		   onchange: false,
		   rules: {
			email: {
			   onfocusout: false,
		   	   required: true,
			   email: true,
		    },
		    agreement:{
		    	required: true
		    }
		   },
		   messages: { 
		   	agreement :{
		   		required: "Je třeba potvrdit souhlas s podmínkami.<br/>"
		   	},
			email: { 
		       required: "* zadejte svůj e-mail", 
		   	   email: "* špatný formát e-mailu", 
			}
		   }
		});
    }

	function mktSuggest(mailkitForm) {

	  if(mkt_form_opts.suggest == 'true') {
		   $(mailkitForm + ' .mkt_email').on('blur', function() {
			$(this).mailcheck({
			   domains: domains,                      // optional
			   secondLevelDomains: secondLevelDomains, // optional
			   topLevelDomains: topLevelDomains, 		// optional
		
			   suggested: function(element, suggestion) {
				// callback code
				//console.log("suggestion ", suggestion.full);
				// show the suggestion box
				$(mailkitForm + ' #mkt_suggestion').removeAttr('style');
				// show the message as offered by the helper
				$(mailkitForm + ' #mkt_suggestion').html("nemysleli jste" + " <a class=\"suggestion\" href=\"javascript:suggestion_write('" + suggestion.full + "', '" + mailkitForm + "' );\">" + suggestion.full + "</a>?");
			   },
			   empty: function(element) {
				// callback code
				// neni co navrhnout
				$(mailkitForm + ' #mkt_suggestion').html('No Suggestions :(');
				$(mailkitForm + ' #mkt_suggestion').attr('style','display:none');
			   }
			});
		   });
		}
	   
   
	  if(mkt_form_opts.suggest == 'autocomplete' ||  mkt_form_opts.suggest == 'true') {
		   $(mailkitForm + " .mkt_email").emailautocomplete({
			suggClass: "mkt_email2",
			domains: ["aol.com", "att.net", "comcast.net", "facebook.com", "gmail.com", "gmx.com", "googlemail.com",
		      "google.com", "hotmail.com", "hotmail.co.uk", "mac.com", "me.com", "mail.com", "msn.com",
		      "live.com", "sbcglobal.net", "verizon.net", "yahoo.com", "yahoo.co.uk",
		      "email.com", "games.com" /* AOL */, "gmx.net", "hush.com", "hushmail.com", "icloud.com", "inbox.com",
		      "lavabit.com", "love.com" /* AOL */, "outlook.com", "pobox.com", "rocketmail.com" /* Yahoo */,
		      "safe-mail.net", "wow.com" /* AOL */, "ygm.com" /* AOL */, "ymail.com" /* Yahoo */, "zoho.com", "fastmail.fm",
		      "yandex.com", "bellsouth.net", "charter.net", "comcast.net", "cox.net", "earthlink.net", "juno.com",
		      "btinternet.com", "virginmedia.com", "blueyonder.co.uk", "freeserve.co.uk", "live.co.uk",
		      "ntlworld.com", "o2.co.uk", "orange.net", "sky.com", "talktalk.co.uk", "tiscali.co.uk",
		      "virgin.net", "wanadoo.co.uk", "bt.com", "sina.com", "qq.com", "naver.com", "hanmail.net", "daum.net",
		      "nate.com", "yahoo.co.jp", "yahoo.co.kr", "yahoo.co.id", "yahoo.co.in", "yahoo.com.sg", "yahoo.com.ph",
		      "hotmail.fr", "live.fr", "laposte.net", "yahoo.fr", "wanadoo.fr", "orange.fr", "gmx.fr", "sfr.fr", "neuf.fr",
		      "free.fr", "gmx.de", "hotmail.de", "live.de", "online.de", "t-online.de" /* T-Mobile */, "web.de", "yahoo.de",
		      "mail.ru", "rambler.ru", "yandex.ru", "ya.ru", "list.ru", "hotmail.be", "live.be", "skynet.be", "voo.be",
		      "tvcablenet.be", "telenet.be", "hotmail.com.ar", "live.com.ar", "yahoo.com.ar", "fibertel.com.ar",
		      "speedy.com.ar", "arnet.com.ar", "hotmail.com", "gmail.com", "yahoo.com.mx", "live.com.mx", "yahoo.com",
		      "hotmail.es", "live.com", "hotmail.com.mx", "prodigy.net.mx", "msn.com", "yahoo.com.br", "hotmail.com.br",
		      "outlook.com.br", "uol.com.br", "bol.com.br", "terra.com.br", "ig.com.br", "itelefonica.com.br", "r7.com",
		      "zipmail.com.br", "globo.com", "globomail.com", "oi.com.br", "seznam.cz","centrum.cz","email.cz","post.cz",
		      "volny.cz","tiscali.cz","centrum.sk","post.sk","azet.sk","zoznam.sk","poczta.onet.pl","onet.pl","interia.pl",
		      "wp.pl","o2.pl","op.pl","stonline.sk","citromail.hu","atlas.sk","atlas.cz","buziaczek.pl","yandex.ua","szm.sk",
		      "outlook.cz","outlook.sk","freemail.hu","interia.eu","vp.pl","poczta.fm","yahoo.es","yahoo.ro","gazeta.pl",
		      "stream.cz","firmy.cz","spoluzaci.cz","tiscali.it","pobox.sk","quick.cz","mail.bg","aon.at","gmx.at","tlen.pl",
		      "ukr.net","sapo.pt","autograf.pl","iol.cz","kabelmail.de","orangemail.sk","vipmail.hu","chello.at","abv.bg",
		      "inbox.lv","hot.ee","mail.ee","inbox.lt"
			]
		   });
		}
	}
	

 })();
 