function updateStatus(a,b){$("#"+a+"Form input").attr("disabled",true);$("#"+a+"Form #status").html('<img src="http://www.hymnal.net/images/transparent-loading.gif"/> '+b)}function hs(){document.location="http://www.hymnal.net/search.php/all/all/"+$.trim($("#hymnsearch #search-input").val())}function closePanel(){$("div#panel").slideUp("slow")}function p(b){var a=$("#searchFavForm #favk").val();if(!a){a=""}$.ajax({type:"POST",url:"http://www.hymnal.net/components/favorites-panel.php",data:{p:b,favk:a},updateStatus:function(){$("#panel .content #body ul#favs").html("")},success:function(c){$("#panel .content #body").html(c)},error:function(e,d,c){alert("ERROR: response="+e.responseText+", desc="+d);return false}})}function delsel(){var a="";$("input[type='checkbox']").each(function(){if($(this).is(":checked")){if(a!=""){a+=","}a+=$(this).attr("id")}});if(a==""){$("#emailForm #status").html("You have not selected any song.");return false}$.ajax({type:"POST",url:"http://www.hymnal.net/components/favorites-panel.php",data:{values:a,type:"delsel"},dataType:"json",beforeSend:updateStatus("email","Deleting..."),success:function(b){if(b.status=="success"){openFavorites()}else{$("#emailForm #status").text(b.msg);$("#emailForm input").removeAttr("disabled")}},error:function(d,c,b){alert("ERROR: response="+d.responseText+", desc="+c);return false}});return false}function openFavorites(){$("#panelfeature").html("Favorites");var a=$("#searchFavForm #favk").val();if(!a){a=""}$("#panel .content").load("http://www.hymnal.net/components/favorites-panel.php",{favk:a})}function emailFavs(){$.ajax({type:"POST",url:"http://www.hymnal.net/components/favorites-panel.php",data:{type:"emailfavs",toemail:$("#emailForm #email").val()},dataType:"json",beforeSend:updateStatus("email","Sending the email..."),success:function(a){$("#emailForm #status").text(a.msg);$("#emailForm input").removeAttr("disabled")},error:function(c,b,a){alert("ERROR: response="+c.responseText+", desc="+b);return false}})}function openProfile(){$("#panelfeature").html("Profile");$("#panel .content").load("http://www.hymnal.net/components/profile-panel.php",{},function(a){$("#profileForm input").focus(function(){$("#profileForm #status").text("")});$("#profileForm").submit(function(){$.ajax({type:"POST",url:"http://www.hymnal.net/components/header.php",data:{firstname:$("#profileForm #firstname").val(),lastname:$("#profileForm #lastname").val(),email:$("#profileForm #email").val(),original:$("#profileForm #original").val(),type:"edit"},dataType:"json",beforeSend:updateStatus("profile","Saving changes..."),success:function(b){$("#profileForm #status").text(b.msg);if(b.status=="success"){location.reload(true)}else{$("#profileForm input").removeAttr("disabled")}},error:function(d,c,b){alert("ERROR: response="+d.responseText+", desc="+c);return false}})});$("#profileForm a.lost-pwd").click(function(){$.ajax({type:"POST",url:"http://www.hymnal.net/components/header.php",data:{email:$("#profileForm #email").val(),type:"lost-pwd"},dataType:"json",beforeSend:updateStatus("profile","Sending email..."),success:function(b){$("#profileForm #status").text(b.msg);if(b.status=="success"){}else{$("#profileForm input").removeAttr("disabled")}},error:function(d,c,b){alert("ERROR: response="+d.responseText+", desc="+c);return false}})})})}function r(b,a){$.ajax({type:"POST",url:"http://www.hymnal.net/components/header.php",data:{songtype:b,songnum:a,type:"rate-song"},dataType:"json",success:function(c){if(c.status=="success"){$("#content .article h2 span.star").html('<a href="#" onclick="ur(\''+b+"','"+a+'\')"><img src="http://www.hymnal.net/images/rated-star.png" /></a>');$("#col ul#category li.inline span.star").html('<a href="#" onclick="ur(\''+b+"','"+a+'\')"><img src="http://www.hymnal.net/images/rated-star.png" /></a> Remove from My List');if($("#panelfeature").html()=="Favorites"){openFavorites()}}},error:function(e,d,c){alert("ERROR: response="+e.responseText+", desc="+d)}})}function ur(b,a){$.ajax({type:"POST",url:"http://www.hymnal.net/components/header.php",data:{songtype:b,songnum:a,type:"unrate-song"},dataType:"json",success:function(c){if(c.status=="success"){$("#content .article h2 span.star").html('<a href="#" onclick="r(\''+b+"','"+a+'\')"><img src="http://www.hymnal.net/images/unrated-star.png" /></a>');$("#col ul#category li.inline span.star").html('<a href="#" onclick="r(\''+b+"','"+a+'\')"><img src="http://www.hymnal.net/images/unrated-star.png" /></a> Add to My List');if($("#panelfeature").html()=="Favorites"){openFavorites()}}},error:function(e,d,c){alert("ERROR: response="+e.responseText+", desc="+d)}})}$(document).ready(function(){$("#open").click(function(){$("div#panel").slideDown("slow");if(login){switch($("#panelfeature").html()){case"Favorites":openFavorites();break;case"Profile":openProfile();break;default:openFavorites();break}}else{$("#panel .content").load("http://www.hymnal.net/components/login-register-panel.php",{},function(a){$("#loginForm input").focus(function(){$("#loginForm #status").text("")});$("#loginForm").submit(function(){$.ajax({type:"POST",url:"http://www.hymnal.net/components/header.php",data:{email:$("#loginForm #email").val(),pwd:$("#loginForm #pwd").val(),type:"login"},dataType:"json",beforeSend:updateStatus("login","Logging in..."),success:function(b){$("#loginForm input").removeAttr("disabled");$("#loginForm #status").text(b.msg);switch(b.status){case"success":location.reload(true);break;case"too-many-logins":$("#loginForm input").attr("disabled",true);break}},error:function(d,c,b){alert("ERROR: response="+d.responseText+", desc="+c);return false}})});$("#loginForm a.lost-pwd").click(function(){$.ajax({type:"POST",url:"http://www.hymnal.net/components/header.php",data:{email:$("#loginForm #email").val(),type:"lost-pwd"},dataType:"json",beforeSend:updateStatus("login","Sending email..."),success:function(b){$("#loginForm #status").text(b.msg);if(b.status=="success"){}else{$("#loginForm input").removeAttr("disabled")}},error:function(d,c,b){alert("ERROR: response="+d.responseText+", desc="+c);return false}})});$("#registerForm input").focus(function(){$("#registerForm #status").text("")});$("#registerForm").submit(function(){$.ajax({type:"POST",url:"http://www.hymnal.net/components/header.php",data:{email:$("#registerForm #email").val(),type:"register"},dataType:"json",beforeSend:updateStatus("register","Sending email..."),success:function(b){$("#registerForm #status").text(b.msg);if(b.status=="success"){}else{$("#registerForm input").removeAttr("disabled")}},error:function(d,c,b){alert("ERROR: response="+d.responseText+", desc="+c);return false}})})})}});$("#close").click(function(){closePanel()});$("#toggle a").click(function(){$("#toggle a").toggle()})});