$(document).ready(function(){init_ready()});function init_ready(){show_accordion();update_all_alert_divs();get_total_alerts();get_div_total_alerts("home_alerts","manage","total_wii_alerts");get_div_total_alerts("other_alerts","manage","total_other_alerts");get_div_total_alerts("custom_alerts","manage","total_custom_alerts")}function show_accordion(){$("div.manage-show > div").hide();$("div.manage-show> h3").click(function(){$(this).next().slideToggle("slow")})}function update_all_alert_divs(){$("div").filter("[id*=manage]").each(function(){pid=$(this).attr("pid");update_alert_div(pid,zd)})}function get_total_alerts(){var A=0;var B=0;$("div").filter("[id*=manage]").each(function(){pid=$(this).attr("pid");if(products_subscribed[pid]){A=A+1}if(cell_enabled==1){if(cell_subscribed[pid]){B=B+1}}});$("#total_alerts").empty();$("#total_alerts").append('<p><table height="50" border="0" align="center" valign="center"><tr><td><h1>You have <font color="purple" size="10">'+A+'</font> active alerts (<font color="purple" size="5">'+B+"</font> cell alerts)</h1></tr></td></table></p>")}function get_div_total_alerts(D,B,C){var A=0;$("div[id*="+D+"] div[id*="+B+"]").each(function(){pid=$(this).attr("pid");if(products_subscribed[pid]){A=A+1}});$("#"+C).empty();$("#"+C).append(":<font color=purple>"+A+" active alerts</font>")}function update_alert_div(B,A){$("#manage_alert_"+B).empty();if(is_email_subscribed(B)){if(B>1000){add_image_button(B,A,"remove_alert","delete alert")}else{add_image_button(B,A,"remove_alert","remove both email and cell alert")}if(cell_enabled=="1"){if(is_cell_subscribed(B)){add_image_button(B,A,"remove_cell","remove only cell alert")}else{add_image_button(B,A,"add_cell","add cell alert")}}if(B>1000){if(is_preorder_subscribed(B)){add_image_button(B,A,"remove_preorder","remove preorder alert")}else{add_image_button(B,A,"add_preorder","add preorder alert")}}}else{if(cell_enabled){title_text="add both email and cell alert"}else{title_text="add email alert"}if(B<1000){add_image_button(B,A,"add_alert",title_text)}}if(is_email_subscribed(B)){if(B<1000){add_status_image(B,"status_yes","email_status_alert")}else{add_status_image(B,"status_yes","custom_status")}}else{if(B<1000){add_status_image(B,"status_no","email_status_alert")}else{$("tr#custom_"+B).remove()}}if(cell_enabled==1){if(is_cell_subscribed(B)){if(B<1000){add_status_image(B,"status_yes","cell_status_alert")}else{add_status_image(B,"status_yes","custom_cell_status")}}else{if(B<1000){add_status_image(B,"status_no","cell_status_alert")}else{add_status_image(B,"status_no","custom_cell_status")}}}if(B>1000){if(is_preorder_subscribed(B)){add_status_image(B,"status_yes","custom_preorder_status")}else{add_status_image(B,"status_no","custom_preorder_status")}}}function is_email_subscribed(A){if(products_subscribed[A]){return true}else{return false}}function is_cell_subscribed(A){if(cell_subscribed[A]){return true}else{return false}}function is_preorder_subscribed(A){if(preorder_subscribed[A]){return true}else{return false}}function add_image_button(B,A,C,D){if(C!="remove_alert"){$("#manage_alert_"+B).append("<div id="+C+"_"+B+"><a title='"+D+"' onclick=jQuery.get('process_alert.php',{pid:'"+B+"',zd:'"+A+"',cmd:'"+C+"',email:'"+email_enabled+"',cell:'"+cell_enabled+"'},function(xml){process_alert(xml);});><img style='cursor:hand' src='images/"+C+".gif'></a></div>")}else{if(B>1000){$("#manage_alert_"+B).append("<div id="+C+"_"+B+"><a title='"+D+"' onclick='return deletechecked("+B+");'><img style='cursor:hand' src='images/"+C+".gif'></a></div>")}else{$("#manage_alert_"+B).append("<div id="+C+"_"+B+"><a title='"+D+"' onclick=jQuery.get('process_alert.php',{pid:'"+B+"',zd:'"+A+"',cmd:'"+C+"',email:'"+email_enabled+"',cell:'"+cell_enabled+"'},function(xml){process_alert(xml);});><img style='cursor:hand' src='images/"+C+".gif'></a></div>")}}}function deletechecked(A){var C=$("a[@href *='"+A+"']").text();var B=confirm("Are you sure you want to delete "+C+"?");if(B){jQuery.get("process_alert.php",{pid:A,zd:zd,cmd:"remove_alert",email:email_enabled,cell:cell_enabled},function(D){process_alert(D)})}return false}function add_status_image(B,C,A){$("#"+A+"_"+B).empty();$("#"+A+"_"+B).append("<a><img src='images/"+C+".gif'></a>")}function process_alert(B){var A=$("result",B);var C=A.attr("success");if(C==1){pid=$(A).attr("pid");cmd=$(A).attr("cmd");if(cmd=="add_alert"){products_subscribed[pid]=true;if(cell_enabled){cell_subscribed[pid]=true}}else{if(cmd=="remove_alert"){products_subscribed[pid]=false;cell_subscribed[pid]=false;if(pid>1000){preorder_subscribed[pid]=false}}else{if(cmd=="add_cell"){cell_subscribed[pid]=true}else{if(cmd=="remove_cell"){cell_subscribed[pid]=false}else{if(cmd=="add_preorder"){preorder_subscribed[pid]=true}else{if(cmd=="remove_preorder"){preorder_subscribed[pid]=false}else{alert("operation failed. Try again!")}}}}}}update_alert_div(pid,zd);get_total_alerts();get_div_total_alerts("home_alerts","manage","total_wii_alerts");get_div_total_alerts("other_alerts","manage","total_other_alerts");get_div_total_alerts("custom_alerts","manage","total_custom_alerts")}else{message=$("message",B).text();if(message==""){message="operation failed. Try again!"}alert(message);update_all_alert_divs();get_total_alerts();get_div_total_alerts("home_alerts","manage","total_wii_alerts");get_div_total_alerts("other_alerts","manage","total_other_alerts");get_div_total_alerts("custom_alerts","manage","total_custom_alerts")}};