function postData(to,p){var postForm=document.createElement("form"),t,k,postInput;for(k in postForm.method="post",postForm.action=to,p){p.hasOwnProperty(k)&&((postInput=document.createElement("input")).setAttribute("type","hidden"),postInput.setAttribute("name",k),postInput.setAttribute("value",p[k]),postForm.appendChild(postInput))}document.body.appendChild(postForm),postForm.submit(),document.body.removeChild(postForm)}function needToLink(){var need_to_url=window.location.href.replace("&pt=unsubscribe","").replace("&pt=change_details",""),$pageTypeElement=$(".page-type"),$needToUnsubscribeLink=$(".need-to-unsubscribe a");$pageTypeElement.hasClass("unsubscribe")?$needToUnsubscribeLink.attr("href",need_to_url+"&pt=change_details"):$pageTypeElement.hasClass("update")&&$needToUnsubscribeLink.attr("href",need_to_url+"&pt=unsubscribe")}function updateCounter(){var $singularKey=$(".unsubscribe-counter .singular"),$pluralKey=$(".unsubscribe-counter .plural"),unsubscribeCount=0;$(".campaign-list input[type=checkbox]").each(function(){this.checked&&unsubscribeCount++}),$(".campaign-counter").text(" "+unsubscribeCount),1===unsubscribeCount?($singularKey.css("display","inline"),$pluralKey.css("display","none")):($singularKey.css("display","none"),$pluralKey.css("display","inline"))}function chooseAll(){var checkbox=document.getElementById("choose_all");$(checkbox).change(function(){var $input=$('input[name="cname[]"]');checkbox.checked?$input.attr("checked","checked"):$input.attr("checked",""),updateCounter()})}$(document).ready(function(){$("select[multiple]").each(function(){var pattern;/^custom_checkbox/.test($(this).attr("id"))&&(this.id=this.id.replace("custom_checkbox","custom"),$(this).multiSelect())}),$("#unsubscribe_change_btn").click(function(e){return e.preventDefault(),$(".unsubscribeError1").hide(),0==$('input[name="cname[]"]:checked').length?($(".unsubscribeError1").show(),!1):void $.post("me.html?"+window.location.search.replace("?",""),$("#unsubscribe_form").serialize(),function(response){if("error"==response.status){if("no_campaigns"==response.errors)return $(".unsubscribeError1").show(),!1;if("bad_id"==reponse.errors)return window.location.reload(!0),!1}else{if(response.redirect_url)return void(window.location=response.redirect_url);if(""==response.status){if(response.custom_redirect&&("get"==response.custom_redirect.method?window.location.href=response.custom_redirect.url+"?"+$.param(response.custom_redirect.data):"post"==response.custom_redirect.method?postData(response.custom_redirect.url,response.custom_redirect.data):window.location.href=response.custom_redirect.url),response.unsubscribed_campaigns)for(i in response.unsubscribed_campaigns)response.unsubscribed_campaigns.hasOwnProperty(i)&&$("
").appendTo(".campaign-list");return $(".unsubscribe").addClass("success"),!1}}alert("Something went terribly wrong :(")},"json")}),$("#unsubscribe_reason_btn").click(function(e){return e.preventDefault(),0==$('input[name="unsubscribe_reason"]:checked')?($(".reasonError1").show(),!1):void $.post("me.html?"+window.location.search.replace("?",""),$("#unsubscribe_reason").serialize(),function(response){if("error"==response.status){if("no_reason"==response.errors)return $(".reasonError1").show(),!1;if("bad_id"==reponse.errors)return location.reload(!0),!1}else{if(response.redirect_url)return void(window.location=response.redirect_url);if(""==response.status)return $(".page-reason, .page-unsubscribe").remove(),$(".unsubscribe.success").removeClass("unsubscribe success").addClass("update-success"),!1}alert("Something went terribly wrong :(")},"json")}),$("#change_details").submit(function(e){e.preventDefault(),$.post("me.html?"+window.location.search.replace("?",""),$("#change_details").serialize(),function(response){if($("span.error").remove(),$("input.error, select.error, .multiSelect.error").removeClass("error"),"error"==response.status)for(var errorTpl in response.errors){var $field,errorTpl;response.errors.hasOwnProperty(errorTpl)&&($field=$("#"+errorTpl),errorTpl=''+response.errors[errorTpl]+"",($field.hasClass("multiSelect")?$field.addClass("error").next(".multiSelectOptions"):$field.addClass("error")).after(errorTpl))}else response.redirect_url?window.location=response.redirect_url:""==response.status?($(".update").removeClass("update").addClass("update-success"),document.body.scrollTop=document.documentElement.scrollTop=0):alert("Something went terribly wrong :(")},"json")})}),$(document).ready(function(){updateCounter(),$(".campaign-list input[type=checkbox]").each(function(){$(this).bind("click",function(){updateCounter()})}),needToLink(),chooseAll()});