(function(b){var a={init:function(c){var d=this;b(this.selector).bind("reset_form",function(){a.reset_form(d.selector)});this.each(function(){var e=b(this);e.find(".con_con_con a.user_pic_xsmall_noshadow").live("click",function(g){g.stopPropagation();g.preventDefault();var f=e.find(".selected_user_list");a.select_user(b(this),f);e.find(".checked_count").html(e.find(".haveBorder").length);return false});e.find("input[name=invite_title]").keypress(function(){e.find(".title_error").text("").hide()});e.find(".datepicker").datepicker({showOn:"both",buttonImage:"/static/images/calendar.gif",buttonImageOnly:true,onSelect:function(g,f){a.update_date(f.selectedYear,f.selectedMonth,f.selectedDay,e.find(".selected_date"));e.find(".date_error").text("").hide()}});e.find(".time_picker").autoConvertUI({max_height:210,css_class:"ui_select s",type:"select",hook_event_1:function(f){}});e.find(".select").autoConvertUI({css_class:"ui_select s",type:"select",hook_event_1:function(f){}});e.find(".checkbox").autoConvertUI({type:"checkbox",hook_event_1:function(f){}});e.find(".post_btn").click(function(f){f.preventDefault();a.submit(e)});e.find(".cancel_btn").click(function(f){e.find("input[name=invite_date], input[name=invite_title], textarea[name=invite_note]").val("");e.find(".selected_user_list").html("");e.find(".error_msg").text("").hide()});e.find(".add_manually").click(function(h){var g=b(this);var f=g.siblings(".add_contact");f.removeClass("v_hide");g.hide();f.find("input").focus();return false});e.find(".input_invite_location").guluAutoComplete({max:10,width:206,stop_submit:true,cacheLength:20,footer:function(g,f){if(g.length){return false}footer_data={html:'<div class="add_new">Add Place : '+f+"</div>",data:[f],value:false,result:""};return footer_data}},{list_contain:e.find(".location_list"),url:"/search/ajax/auto_complete_place/",remove_item:function(){var f=e.find(".location_list .input_wrapper input");e.find(".target .pic_frame").html(gettext("<span>Please select place first</span>"));f.css("width","auto")},result:function(i,g,f){var h=e.find(".location_list");var j=h.find(".input_wrapper input");if(f){a.add_select_place(g,h,j,e)}else{autoShowDialogAjax({url:"/place/ajax/popup_add_place/",callback:function(){b("#id_form_add_place").data("restore",j);b("#id_form_add_place").find("#id_name").val(g[0]).attr("readonly","readonly")},callback_close:function(){return_data=j.data("place");if(return_data){a.add_select_place(return_data,h,j,e)}}})}}});e.find("input.contact_input").focusout(function(){var f=b(this).parent();var g=f.siblings(".add_manually");f.addClass("v_hide");g.show()}).guluAutoComplete({max:5,width:200,content_width:200,loadingClass:"",stop_submit:true,liClass:"people",cacheLength:0,footer:function(g,f){if(g.length){return false}valid=Gulu.validateEmail(f);footer_data={html:'<div class="add_new"> Email: '+f+"</div>",data:[f,valid],value:false,result:""};return footer_data}},{list_contain:e.find(".hidden_user_list"),url:"/search/ajax/auto_complete_people/",remove_item:function(){},input_auto_size:false,result:function(f,h,g){if(g){a.add_select_user(h,e)}else{if(h[1]){Invite.AddNewContact(h[0],function(i){a.add_select_user(i.data,e);e.find(".checked_count").html(e.find(".haveBorder").length)})}else{console.log("invalid email.")}}e.find(".checked_count").html(e.find(".haveBorder").length)},only_one:false,no_duplicate:true,preprocessing:function(){var f=e.find(".hidden_user_list");e.find(".user_list a.user_pic_xsmall_noshadow").each(function(){f.append(b('<input type="hidden" id="'+b(this).attr("cid")+'" />'))})}})});return this},reset_form:function(c){b(c).find("form")[0].reset();b(c).find(".selected_user_list").empty();b(c).find(".checked_count").html("0")},add_select_user:function(e,c){var f=b('<a href="#" title="'+e[1]+'" target="blank" cid="'+e[0]+'" class="user_pic_xsmall_noshadow fL"><img src="'+e[5]+'" width="26" height="26" alt="'+e[1]+'" /></a>');f.insertBefore(c.find(".user_list .add_contact"));var d=c.find(".selected_user_list");a.select_user(f,d);var g=c.find(".hidden_user_list");g.append(b('<input type="hidden" id="'+e[0]+'" />'));c.find(".contact_input").val("").trigger("reset_inputs_params")},select_user:function(d,c){var e=d.attr("cid");if(d.hasClass("haveBorder")){d.removeClass("haveBorder");c.find("input.id_"+e).remove()}else{d.addClass("haveBorder");c.append(b('<input type="hidden" id="'+e+'" class="id_'+e+'" name="contact_list[]" value="'+e+'">'));c.parents(".con_con_con").find(".contact_error").text("").hide()}},add_select_place:function(e,f,g,c){f.append(b('<input type="hidden" class="place_select_results" name="place" id="'+e[0]+'" value="'+e[0]+'"/>'));f.find("ul").append(b('<li style="max-width:85px;" class="'+e[0]+'"><span class="name">'+e[1]+'</span><span class="cancel">x</span></li>'));g.val("");g.attr("size","1");g.css("width","2px");var d=b('<img src="'+e[6]+'" width="105" height="105" alt="'+e[0]+'">');c.find(".target .pic_frame").html(d)},submit:function(d){var e=d.find(".title_error");var q=d.find(".contact_error");var g=d.find(".selected_date");var o=d.find(".date_error");var p=d.find("form");var j=p.serializeObject();var n=true;if(!j.invite_title){e.text(gettext("This is required.")).show();n=false}else{e.text("").hide()}if(!j["contact_list[]"]||(j["contact_list[]"]&&j["contact_list[]"].length==0)){q.text(gettext("This is required.")).show();n=false}else{q.text("").hide()}var l=g.attr("year");var k=g.attr("month");var m=g.attr("day");if(!l||!k||!m){o.text(gettext("Please choose a date.")).show();n=false}else{o.text("").hide()}if(n!=true){b("#id_lets_go_submit_mask").remove();return false}var f=j.invite_time;var h=Math.floor(f/60);var i=f%60;var c=Date.UTC(l,k,m,h,i)*0.001;g.val(c);p.submit()},update_date:function(f,e,c,d){d.attr("year",f);d.attr("month",e);d.attr("day",c)},add_mask:function(c,d){b("#"+d).remove();c.css("position","relative");c.append(b('<div id="'+d+'" class="ui_dialog_bg brown" style="position:absolute; z-index:99; top:0px; left:0px; width:'+c.width()+"px; height:"+c.height()+'px; "><img style="display:block; margin:80px auto 0; width:32px; height:32px; " src="/static/images/icon_loading.gif"></div>'))},destroy:function(){return this.each(function(){})}};b.fn.LetsGo=function(c){if(a[c]){return a[c].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof c==="object"||!c){return a.init.apply(this,arguments)}else{b.error("Method "+c+" does not exist on jQuery.LetsGo")}}return this}})(jQuery);
