var ajaxBusiness;var ajaxUser;function user(urlUser,login){var pagetitle=$("title").html();$("#posttoolAreaLinkBox-input").defaultvalue("defdrop",defdrop);$("body").livequery("click",function(event){$("#profile_picture_flyout").hide()});$("div.img-hover").livequery(function(event){$(this).hover(function(){$("div.change").show()},function(){$("div.change").hide()})});$("div.change").livequery("click",function(event){$('#img-thumb').find('#thumbnail').imgAreaSelect({hide:true});$("#profile_picture_flyout").show();event.stopPropagation()});$("#profile_picture_upload, #business_picture_upload").livequery("click",function(event){var id=$(this).attr("id");var status=(id=="profile_picture_upload")?'chgPicProf':'chgPicBiz';newUploadPic(status);return false});$(".jqmClose").livequery("click",function(event){});$("#profile_picture_thumb").livequery("click",function(event){ajaxUser=$.ajax({global:false,beforeSend:function(){$("div.ajax-load-page").show();$("#content-menu, #content").fadeTo("fast",0.25)},type:"POST",timeout:50000,url:urlx+"/other",data:{status:"chgPicProf"},success:function(msg){if(msg){$("body").css({"overflow-y":"hidden"});$("div.ajax-load-page").hide();$("div.overlay").show();$("div.modalPostFeed").html(msg);$("div.modalPostFeed").show();$("div.overlay").animate({scrollTop:0},'slow');saveThumb();$('#uploadImg').html('Continue');$('#uploadImg').attr("id","save_thumb");$('#modal-content').hide();$('#modal-content').next().hide();$("#img-thumb").show();$('#img-thumb').find('#thumbnail').imgAreaSelect({aspectRatio:'1:1',onSelectChange:preview,parent:'#imgHandler',minWidth:200,minHeight:200,handles:true});$('#thumbnail').click();$("a.btnConfirm").livequery("click",function(event){var id=$(this).attr("id");if(id!=undefined){switch(id){case'closeUser':var userBox=$("#dialogBusiness").html();if(userBox!=undefined){$("#dialogBusiness").remove();$("#content-menu, #content, div.post").fadeTo("fast",1);$("div.overlay").hide();$("div.modalPostFeed").hide();$("body").css({"overflow-y":"auto"})}break}return false}})}else{$("#dialogBusiness").remove();$("#content-menu, #content, div.post").fadeTo("fast",1);$("div.overlay").hide();$("div.modalPostFeed").hide();$("body").css({"overflow-y":"auto"})}}});return false});follow();userBusiness();descchange(urlUser,login);$(".revoke").livequery("click",function(event){var id=$(this).attr("id");var answer=confirm("Are you sure want to revoke your "+id+" account?\n(You may also need to manualy revoke Rockto Apps from your "+id+" account)");if(answer)return true;return false})}function newUploadPic(status){ajaxUser=$.ajax({global:false,beforeSend:function(){$("div.ajax-load-page").show();$("#content-menu, #content").fadeTo("fast",0.25)},type:"POST",timeout:50000,url:urlx+"/other",data:{status:status},success:function(msg){if(msg){$("body").css({"overflow-y":"hidden"});$("div.ajax-load-page").hide();$("div.overlay").show();$("div.modalPostFeed").html(msg);$("div.modalPostFeed").show();$("div.overlay").animate({scrollTop:0},'slow');chgImgNew();saveThumb();$("a.btnConfirm").livequery("click",function(event){var id=$(this).attr("id");if(id!=undefined){switch(id){case'uploadImg':$(".frm_upload").submit();break;case'closeUser':var userBox=$("#dialogBusiness").html();if(userBox!=undefined){$("#dialogBusiness").remove();$("#content-menu, #content, div.post").fadeTo("fast",1);$("div.overlay").hide();$("div.modalPostFeed").hide();$("body").css({"overflow-y":"auto"})}break}return false}})}else{$("#dialogBusiness").remove();$("#content-menu, #content, div.post").fadeTo("fast",1);$("div.overlay").hide();$("div.modalPostFeed").hide();$("body").css({"overflow-y":"auto"})}}})}function follow(){$("a.btn-user").livequery("click",function(event){if(login!="login"){var status=$(this).attr("status");if((status=="follow")||(status=="unfollow")){var curid=$(this);var targetID=$(this).attr("member");var from=$(this).attr("from");$.ajax({global:false,beforeSend:function(){$(curid).attr("status","wait");if(from=="suggestion"){$(curid).parent().parent().fadeTo("fast",0.5);$(curid).removeAttr("action")}},type:"POST",url:urlUser+"/follow",data:{targetID:targetID,status:status},timeout:60000,success:function(msg){var spl=msg.split("##");if(spl[0]=="success"){switch(from){case'notif':$(curid).remove();break;case'suggestion':var suggest=$("input[name=\'suggests\']").val();$.ajax({type:"POST",url:urlx+"/suggestion",data:{status:"single",id:targetID,suggest:suggest,post:"people"},success:function(msg){var spl=msg.split("##");$(curid).parent().parent().replaceWith(spl[0]);$("input[name=\'suggests\']").val(spl[1])}});break;default:var newstat=(status=="follow")?"unfollow":"follow";$(curid).attr("status",newstat);if(newstat=="follow"){$(curid).find("#followBtnPlus").html("+");$(curid).find("#followSign").removeClass("a3").addClass("a1");$(curid).find("#followBtnText, #followText").html("Follow")}else{$(curid).find("#followBtnPlus").html("-");$(curid).find("#followSign").removeClass("a1").addClass("a3");$(curid).find("#followBtnText, #followText").html("Unfollow")}$("#followerList").find("span:not(.transp-75)").html(spl[1]);break}$.jGrowl("You've succesfully "+status+"ed this person!")}else if(spl[0]=="error"){$.jGrowl(spl[1])}return false},error:function(request,errorType,errorThrown){try{if(errorType!=null){$(curid).attr("id",status);$.jGrowl("Something went wrong, please try again.")}}catch(e){}}})}}else{$dialogLogin.jqmShow()}return false});$("a.btn-topic").livequery("click",function(event){if(login!="login"){var status=$(this).attr("status");if((status=="follow")||(status=="unfollow")){var curid=$(this);var targetID=$(this).attr("member");var from=$(this).attr("from");var topiclink=(status=='follow')?urlx+"/addTopic":urlx+"/removeTopic";$.ajax({global:false,beforeSend:function(){$(curid).attr("status","wait")},type:"POST",url:topiclink,data:{newTopic:targetID},timeout:60000,success:function(msg){var spl=msg.split("##");if(spl[0]=="success"){if(from!="notif"){var newstat=(status=="follow")?"unfollow":"follow";$(curid).attr("status",newstat);if(newstat=="follow"){$(curid).find("#followBtnPlus").html("+");$(curid).find("#followSign").removeClass("a3").addClass("a1");$(curid).find("#followBtnText, #followText").html("Follow")}else{$(curid).find("#followBtnPlus").html("-");$(curid).find("#followSign").removeClass("a1").addClass("a3");$(curid).find("#followBtnText, #followText").html("Unfollow")}$("#topicFollower").replaceWith(spl[1])}else{$(curid).remove()}$.jGrowl("You've succesfully "+status+"ed this topics!")}else if(spl[0]=="error"){$.jGrowl(spl[1])}return false},error:function(request,errorType,errorThrown){try{if(errorType!=null){$(curid).attr("id",status);$.jGrowl("Something went wrong, please try again.")}}catch(e){}}})}}else{$dialogLogin.jqmShow()}return false})}function userBusiness(){$("#addDeposit").livequery("click",function(event){if(ajaxBusiness)ajaxBusiness.abort();ajaxBusiness=$.ajax({global:false,beforeSend:function(){$("div.ajax-load-page").show();$("#content-menu, #content").fadeTo("fast",0.25)},type:"POST",timeout:50000,url:urlx+"/addDeposit",data:{},success:function(msg){$("body").css({"overflow-y":"hidden"});$("div.ajax-load-page").hide();$("div.overlay").show();$("div.modalPostFeed").html(msg);$("div.modalPostFeed").show();$("div.overlay").animate({scrollTop:0},'slow');$("a.btnConfirm").livequery("click",function(event){var id=$(this).attr("id");if(id!=undefined){switch(id){case'sentEmail':sentEmailBiz();break;case'closeBusiness':var business=$("#dialogBusiness").html();if(business!=undefined){$("#dialogBusiness").remove();$("#content-menu, #content, div.post").fadeTo("fast",1);$("div.overlay").hide();$("div.modalPostFeed").hide();$("body").css({"overflow-y":"auto"})}break}return false}})}});return false});$("#confirmDeposit").livequery("click",function(event){if(ajaxBusiness)ajaxBusiness.abort();ajaxBusiness=$.ajax({global:false,beforeSend:function(){$("div.ajax-load-page").show();$("#content-menu, #content").fadeTo("fast",0.25)},type:"POST",timeout:50000,url:urlx+"/confirmDeposit",data:{},success:function(msg){$("body").css({"overflow-y":"hidden"});$("div.ajax-load-page").hide();$("div.overlay").show();$("div.modalPostFeed").html(msg);$("div.modalPostFeed").show();$("div.overlay").animate({scrollTop:0},'slow');if($("#business_bank").val()=="")$("#business_bank").defaultvalue("dfbank","Bank Account Number");$("#business_amount").defaultvalue("dfamount","Deposit Amount (eg:100000)");$("a.btnConfirm").livequery("click",function(event){var id=$(this).attr("id");if(id!=undefined){switch(id){case'submitDeposit':submitDeposit();break;case'closeBusiness':var business=$("#dialogBusiness").html();if(business!=undefined){$("#dialogBusiness").remove();$("#content-menu, #content, div.post").fadeTo("fast",1);$("div.overlay").hide();$("div.modalPostFeed").hide();$("body").css({"overflow-y":"auto"})}break}return false}})}});return false});$("#addDeal").livequery("click",function(event){if(ajaxBusiness)ajaxBusiness.abort();ajaxBusiness=$.ajax({global:false,beforeSend:function(){$("div.ajax-load-page").show();$("#content-menu, #content").fadeTo("fast",0.25)},type:"POST",timeout:50000,url:urlx+"/addDeal",data:{},success:function(msg){$("body").css({"overflow-y":"hidden"});$("div.ajax-load-page").hide();$("div.overlay").show();$("div.modalPostFeed").html(msg);$("div.modalPostFeed").show();$("div.overlay").animate({scrollTop:0},'slow');$("#deal_name").defaultvalue("dfname","Campaign Name");$("#deal_desc").defaultvalue("dfdesc","Campaign Description");$("#deal_tag").defaultvalue("dftag","Type tag here (max: 3)");$("#deal_tag").autocomplete({minLength:2,delay:0,source:function(req,add){if(req!="Type tag here (max: 3)"){$.getJSON(urlx+"/auto?callback=?",req,function(data){var suggestions=[];$.each(data,function(i,val){if(val)suggestions.push(val.name);else $(".ui-menu-item").remove()});add(suggestions)})}},select:function(e,ui){$("#deal_tag").val("");cek=true;if($("#friends span").length!=0){if($("#friends span").length==3){cek=false;alert("Sorry, maximum tags reached");$("#deal_tag").hide();$("ul.ui-autocomplete").hide()}else{$("#friends span").each(function(index){cur=$(this).find("a").attr("title").replace("Remove ","");if(ui.item.value==cur){cek=false;alert("tag selected already");$("#deal_tag").val("")}})}}if(cek){var friend=ui.item.value;span=$("<span>").text(friend),a=$("<a>").addClass("remove").attr({href:"javascript:",title:"Remove "+friend}).text("x").appendTo(span);hid=$("<input>").attr({name:"sel[]",value:friend,type:"hidden"}).appendTo(span);span.insertBefore("#deal_tag");$("#deal_tag").val("");if($("#friends span").length==4){$("#deal_tag").hide();$("ul.ui-autocomplete").hide()}}return false},change:function(){$("#deal_tag").val("").css("top",2)}});$("#friends").click(function(){$("#deal_tag").focus()});$(".remove",document.getElementById("friends")).live("click",function(){$(this).parent().remove();$("#deal_tag").show();if($("#friends span").length===0){$("#deal_tag").css("top",0)}});$("#deal_reward_other").defaultvalue("dfother","Campaign Reward");$("#deal_stdate").defaultvalue("dfstdate","Campaign Start Date");$("#deal_stdate").datepicker({firstDay:1,changeFirstDay:false,dateFormat:'dd/mm/yy'});$("#deal_enddate").defaultvalue("dfenddate","Campaign End Date");$("#deal_enddate").datepicker({firstDay:1,changeFirstDay:false,dateFormat:'dd/mm/yy'});$(".add_deal").ajaxForm({global:false,beforeSubmit:submitDeal,beforeSend:function(){$("a.btnConfirm").hide()},success:function(data){var spl=data.split("##");if(spl[0]=="success"){$(spl[1]).prependTo("div.campaign-list");var business=$("#dialogBusiness").html();if(business!=undefined){$("#dialogBusiness").remove();$("#content-menu, #content, div.post").fadeTo("fast",1);$("div.overlay").hide();$("div.modalPostFeed").hide();$("body").css({"overflow-y":"auto"})}}else{$("a.btnConfirm").show();$.jGrowl("Something went wrong, please try again later.")}}});$("a.btnConfirm").livequery("click",function(event){var id=$(this).attr("id");if(id!=undefined){switch(id){case'submitDeals':$(".add_deal").submit();break;case'closeBusiness':var business=$("#dialogBusiness").html();if(business!=undefined){$("#dialogBusiness").remove();$("#content-menu, #content, div.post").fadeTo("fast",1);$("div.overlay").hide();$("div.modalPostFeed").hide();$("body").css({"overflow-y":"auto"})}break}return false}})}});return false});$("#deal_reward").livequery("change",function(event){var rew=$(this).val();if(rew=='other')$("#deal_reward_other").show();else $("#deal_reward_other").hide()});$("#deal_duration").livequery("change",function(event){var dur=$(this).val();if(dur=='other')$("#deal_enddate").show();else $("#deal_enddate").hide()});$("a.fbPagePerm").livequery("click",function(event){$("#fbPage").toggle();return false});$("#fbPage").livequery("change",function(event){var pageID=$(this).val();var name=$("#fbPage").find("option[value=\'"+pageID+"\']").html();FB.Connect.showPermissionDialog("publish_stream",function(perms){if(perms=="publish_stream"){if(ajaxBusiness)ajaxBusiness.abort();ajaxBusiness=$.ajax({global:false,beforeSend:function(){$("#fbPage").hide()},type:"POST",url:urlx+"/chgFB",data:{pageID:pageID},success:function(msg){$("#fbPage").prev().html(msg);$.jGrowl("Business Facebook changed successfully")}})}},true,[pageID])});$("#imgLink").livequery("click",function(event){$(this).select()});$("#doSearchCode").livequery("click",function(event){var membCode=$("input[name=\'search_code\']").val();if(membCode&&membCode!='search code...')searchMemberCode(membCode)});$("#doShowAll").livequery("click",function(event){var businessID=$(this).attr("bid");if(ajaxBusiness)ajaxBusiness.abort();ajaxBusiness=$.ajax({global:false,beforeSend:function(){$("#fbPage").hide()},type:"POST",url:urlx+"/getCode",data:{businessID:businessID},success:function(msg){if(msg!='error'){$("#tableList").find("tr:not(#tableHeader)").remove();$(msg).insertAfter("#tableHeader");$("#doShowAll").hide();$("#tableList").show();$("#tableDetail").remove();$("#search_code").defaultvalue("dfMembCode",'search code...')}else $.jGrowl("Something went wrong, please try again.")}})})}function searchMemberCode(membCode){if(ajaxBusiness)ajaxBusiness.abort();ajaxBusiness=$.ajax({global:false,beforeSend:function(){$("#fbPage").hide()},type:"POST",url:urlx+"/getCode",data:{membCode:membCode},success:function(msg){if(msg!='error'){$("#tableList").find("tr:not(#tableHeader)").remove();$(msg).insertAfter("#tableHeader");$("#tableList").show();$("#doShowAll").show();$("#search_code").defaultvalue("dfMembCode",'search code...')}else $.jGrowl("Something went wrong, please try again.")}})}function sentEmailBiz(){if(login!='login'){if(ajaxBusiness)ajaxBusiness.abort();ajaxBusiness=$.ajax({global:false,beforeSend:function(){$("div.ajax-load-page").show();$("#dialogBusiness").remove();$("div.modalPostFeed").hide();$("div.overlay").hide()},type:"POST",url:urlx+"/emailDeposit",data:{},success:function(msg){$("div.ajax-load-page").hide();$("div.overlay").show();$("div.modalPostFeed").html(msg);$("div.modalPostFeed").show();$("#dialog-redeem").jqmShow();$("a.btnConfirm").livequery("click",function(event){var id=$(this).attr("id");if(id=='closeBusiness'){var business=$("#dialogBusiness").html();if(business!=undefined){$("#dialogBusiness").remove();$("#content-menu, #content, div.post").fadeTo("fast",1);$("div.overlay").hide();$("div.modalPostFeed").hide();$("body").css({"overflow-y":"auto"})}return false}})}})}return false}function submitDeposit(){if(login!='login'){var status=new Array(1,1);var ffocus=0;var bank=$("#dialogBusinessForm input[name=\'business_bank\']").val();if(bank==""||bank=="Bank Account Number"){status[0]=1;$("#dialogBusinessForm #errorBank").remove();$("&nbsp;<span style=\"color:red;\" id=\"errorBank\" class=\"errorForm\"><br/>Please enter the bank account number</span>").insertAfter("#dialogBusinessForm input[name=\'business_bank\']");if(!ffocus){$("#dialogBusinessForm input[name=\'business_bank\']").focus();ffocus=1}}else{status[0]=0;$("#dialogBusinessForm #errorBank").remove()}var amount=$("#dialogBusinessForm input[name=\'business_amount\']").val();if(amount==""||amount=="Deposit Amount (eg:100000)"){status[1]=1;$("#dialogBusinessForm #errorAmount").remove();$("&nbsp;<span style=\"color:red;\" id=\"errorAmount\" class=\"errorForm\"><br/>Please enter the amount number you deposited</span>").insertAfter("#dialogBusinessForm input[name=\'business_amount\']");if(!ffocus){$("#dialogBusinessForm input[name=\'business_amount\']").focus();ffocus=1}}else{status[1]=0;$("#dialogBusinessForm #errorAmount").remove()}if(status=="0,0"){if(ajaxBusiness)ajaxBusiness.abort();ajaxBusiness=$.ajax({global:false,beforeSend:function(){$("div.ajax-load-page").show();$("#dialogBusiness").remove();$("div.modalPostFeed").hide();$("div.overlay").hide()},type:"POST",url:urlx+"/submitDeposit",data:{bank:bank,amount:amount},success:function(msg){$("div.ajax-load-page").hide();$("div.overlay").show();$("div.modalPostFeed").html(msg);$("div.modalPostFeed").show();$("#dialog-redeem").jqmShow();$("a.btnConfirm").livequery("click",function(event){var id=$(this).attr("id");if(id=='closeBusiness'){var business=$("#dialogBusiness").html();if(business!=undefined){$("#dialogBusiness").remove();$("#content-menu, #content, div.post").fadeTo("fast",1);$("div.overlay").hide();$("div.modalPostFeed").hide();$("body").css({"overflow-y":"auto"})}return false}})}})}}return false}function submitDeal(formData,jqForm,options){if(login!='login'){var status=new Array(1,1,1,1,1,1,1,1);var ffocus=0;var name=$("#dialogBusinessForm #deal_name").fieldValue();if(name==""||name=="Campaign Name"){status[0]=1;$("#dialogBusinessForm #errorName").remove();$("&nbsp;<span style=\"color:red;\" id=\"errorName\" class=\"errorForm\"><br/>Please enter the campaign's name.</span>").insertAfter("#dialogBusinessForm #deal_name");if(!ffocus){$("#dialogBusinessForm #deal_name").focus();ffocus=1}}else{status[0]=0;$("#dialogBusinessForm #errorName").remove()}var type=$("#dialogBusinessForm #deal_type").fieldValue();if(type==""){status[1]=1;$("#dialogBusinessForm #errorType").remove();$("&nbsp;<span style=\"color:red;\" id=\"errorType\" class=\"errorForm\"><br/>Please choose the campaign's type.</span>").insertAfter("#dialogBusinessForm #deal_type");if(!ffocus){$("#dialogBusinessForm #deal_type").focus();ffocus=1}}else{status[1]=0;$("#dialogBusinessForm #errorType").remove()}var desc=$("#dialogBusinessForm #deal_desc").fieldValue();if(desc==""||desc=="Campaign Description"){status[2]=1;$("#dialogBusinessForm #errorDesc").remove();$("&nbsp;<span style=\"color:red;\" id=\"errorDesc\" class=\"errorForm\"><br/>Please enter the campaign's description.</span>").insertAfter("#dialogBusinessForm #deal_desc");if(!ffocus){$("#dialogBusinessForm #deal_desc").focus();ffocus=1}}else{status[2]=0;$("#dialogBusinessForm #errorDesc").remove()}var tag=$("#dialogBusinessForm #friends span").length;if(tag==0){status[3]=1;$("#dialogBusinessForm #errorTag").remove();$("&nbsp;<span style=\"color:red;\" id=\"errorTag\" class=\"errorForm\"><br/>Please enter one tag minimum.</span>").insertAfter("#dialogBusinessForm #friends");if(!ffocus){$("#dialogBusinessForm #deal_tag").focus();ffocus=1}}else{status[3]=0;$("#dialogBusinessForm #errorTag").remove()}var reward=$("#dialogBusinessForm #deal_reward").fieldValue();if(reward==""){status[4]=1;$("#dialogBusinessForm #errorReward").remove();$("&nbsp;<span style=\"color:red;\" id=\"errorReward\" class=\"errorForm\"><br/>Please choose the campaign's reward.</span>").insertAfter("#dialogBusinessForm #deal_reward");if(!ffocus){$("#dialogBusinessForm #deal_reward").focus();ffocus=1}}else{if(reward=="other"){var other=$("#dialogBusinessForm #deal_reward_other").fieldValue();if(other==""||other=="Campaign Reward"){status[4]=1;$("#dialogBusinessForm #errorReward").remove();$("&nbsp;<span style=\"color:red;\" id=\"errorReward\" class=\"errorForm\"><br/>Please enter the campaign's reward.</span>").insertAfter("#dialogBusinessForm #deal_reward_other");if(!ffocus){$("#dialogBusinessForm #deal_reward_other").focus();ffocus=1}}else{status[4]=0;$("#dialogBusinessForm #errorReward").remove()}}else{status[4]=0;$("#dialogBusinessForm #errorReward").remove()}}var stdate=$("#dialogBusinessForm #deal_stdate").fieldValue();if(stdate==""||stdate=="Campaign Start Date"){status[5]=1;$("#dialogBusinessForm #errorStDate").remove();$("&nbsp;<span style=\"color:red;\" id=\"errorStDate\" class=\"errorForm\"><br/>Please enter the campaign's start date.</span>").insertAfter("#dialogBusinessForm #deal_stdate");if(!ffocus){$("#dialogBusinessForm #deal_stdate").focus();ffocus=1}}else{status[5]=0;$("#dialogBusinessForm #errorStDate").remove()}var duration=$("#dialogBusinessForm #deal_duration").fieldValue();if(duration==""){status[6]=1;$("#dialogBusinessForm #errorDuration").remove();$("&nbsp;<span style=\"color:red;\" id=\"errorDuration\" class=\"errorForm\"><br/>Please choose the campaign's duration.</span>").insertAfter("#dialogBusinessForm #deal_duration");if(!ffocus){$("#dialogBusinessForm #deal_duration").focus();ffocus=1}}else{if(duration=="other"){var enddate=$("#dialogBusinessForm #deal_enddate").fieldValue();if(enddate==""||enddate=="Campaign End Date"){status[6]=1;$("#dialogBusinessForm #errorDuration").remove();$("&nbsp;<span style=\"color:red;\" id=\"errorDuration\" class=\"errorForm\"><br/>Please choose the campaign's enddate.</span>").insertAfter("#dialogBusinessForm #deal_enddate");if(!ffocus){$("#dialogBusinessForm #deal_enddate").focus();ffocus=1}}else{status[6]=0;$("#dialogBusinessForm #errorDuration").remove()}}else{status[6]=0;$("#dialogBusinessForm #errorDuration").remove()}}var img=$("#dialogBusinessForm #userfile").fieldValue();if(img==""){status[7]=1;$("#dialogBusinessForm #errorImg").remove();$("&nbsp;<span style=\"color:red;\" id=\"errorImg\" class=\"errorForm\"><br/>Please choose the campaign's image.</span>").insertAfter("#dialogBusinessForm #userfile");if(!ffocus){$("#dialogBusinessForm #userfile").focus();ffocus=1}}else{status[7]=0;$("#dialogBusinessForm #errorImg").remove()}if(status!="0,0,0,0,0,0,0,0")return false}else{return false}}function descchange(urlUser,login){$("#userdesc").elastic();$(".desc-change").tipsy({gravity:'e',opacity:0.9});$("body").livequery("click",function(event){$("#userdesc").blur();$(".desc-change").show();$(".desc-change").tipsy({gravity:'e',opacity:0.9})});$(".desc-change").livequery(function(event){$(this).hover(function(){$(this).css({"background-color":"#FFCC66","cursor":"pointer"})},function(){$(this).css({"background-color":"transparent"})})});$(".desc-change").livequery("click",function(event){var id=$(this).attr("id");var curval=$(this).html();$(this).parent().find("#userdesc").val(curval);$(this).parent().find("#userdesc").show();$(this).hide();event.stopPropagation()});$("#userdesc").livequery("click",function(event){event.stopPropagation()});$("#userdesc").livequery("blur",function(event){var val=$(this).val();var curval=$(this).parent().find("#desc").html();if((val!="")&&(val.length<160)){if(val!=curval){$.ajax({global:false,beforeSend:function(){$("#userdesc").attr("disabled","disabled")},type:"POST",url:urlUser+"/desc",data:{val:val},timeout:5000,success:function(msg){if(msg=='success'){$("#userdesc").removeAttr("disabled");$("#userdesc").hide();$(".desc-change").show();$(".desc-change").tipsy({gravity:'e',opacity:0.9})}else{$("#userdesc").removeAttr("disabled");$.jGrowl("Something went wrong, please try again.")}},error:function(request,errorType,errorThrown){try{if(errorType!=null){$("#userdesc").removeAttr("disabled");$.jGrowl("Something went wrong, please try again.")}}catch(e){}}})}$(this).parent().find("#desc").html(val)}else{var curval=$(this).parent().find("#desc").html();$(this).parent().find("#userdesc").html(curval)}})}function preview(img,selection){var current_width=$('#img-thumb').find('#thumbnail').width();var current_height=$('#img-thumb').find('#thumbnail').height();var scaleX=200/selection.width;var scaleY=200/selection.height;$('#img-thumb').find('#thumbnail_preview').css({width:Math.round(scaleX*current_width)+'px',height:Math.round(scaleY*current_height)+'px',marginLeft:'-'+Math.round(scaleX*selection.x1)+'px',marginTop:'-'+Math.round(scaleY*selection.y1)+'px'});$('#x1').val(selection.x1);$('#y1').val(selection.y1);$('#x2').val(selection.x2);$('#y2').val(selection.y2);$('#w').val(selection.width);$('#h').val(selection.height)}function chgImg(){}function chgImgNew(){if(ajaxUser)ajaxUser.abort();ajaxUser=$(".frm_upload").ajaxForm({global:false,beforeSend:function(){$("div.ajax-load-page").show();$("a.btnConfirm").hide()},success:function(data){$("div.ajax-load-page").hide();$("a.btnConfirm").show();ajaxUser=null;if(data){var spl=data.split("#");if(spl[0]=="error"){$(".error").html(spl[1]);$(".error").show()}else{$('#dialogBusiness h1').html('Choose Thumbnail');var action=$(".frm_upload").attr("action");var saveThumb=(action==base_url+'user/change-img-prof')?'save_thumb':'save_thumb_biz';$('#uploadImg').html('Continue');$('#uploadImg').attr("id",saveThumb);$('#modal-content').hide();$('#modal-content').next().hide();$("#img-thumb").html('<div id="imgHandler" class="column span-12" style="margin-right: 10px;"><img src="'+spl[1]+'_original'+spl[2]+'" style="float:left;" id="thumbnail" alt="Create Thumbnail" width="100%"/></div><h2>Preview</h2><div style="border:1px #e5e5e5 solid; float:left; position:relative; overflow:hidden; width:200px; height:200px;"><img src="'+spl[1]+'_original'+spl[2]+'" style="position: relative;" id="thumbnail_preview" alt="Thumbnail Preview" /></div><input type="hidden" name="x1" value="" id="x1" /><input type="hidden" name="y1" value="" id="y1" /><input type="hidden" name="x2" value="" id="x2" /><input type="hidden" name="y2" value="" id="y2" /><input type="hidden" name="w" value="" id="w" /><input type="hidden" name="h" value="" id="h" />');$("#img-thumb").show();$('#img-thumb').find('#thumbnail').imgAreaSelect({aspectRatio:'1:1',onSelectChange:preview,parent:'#imgHandler',minWidth:200,minHeight:200,handles:true})}}}})}function saveThumb(){$('#save_thumb, #save_thumb_biz').livequery("click",function(event){var id=$(this).attr("id");var Link=(id=="save_thumb")?'/save-img-prof':'/save-img-biz';var x1=$('#x1').val();var y1=$('#y1').val();var x2=$('#x2').val();var y2=$('#y2').val();var w=$('#img-thumb').find('#thumbnail_preview').width();var h=$('#img-thumb').find('#thumbnail_preview').height();var curw=$('#img-thumb').find('#thumbnail').width();var curh=$('#img-thumb').find('#thumbnail').height();if(x1==""||y1==""||x2==""||y2==""||w==""||h==""){alert("You must make a selection first");return false}else{$('#img-thumb').find('#thumbnail').imgAreaSelect({disable:true,hide:true});$.ajax({global:false,beforeSend:function(){$("div.ajax-load-page").show();$("a.btnConfirm").hide()},type:'POST',url:urlUser+Link,data:{x1:x1,y1:y1,x2:x2,y2:y2,w:w,h:h,curw:curw,curh:curh},cache:false,success:function(response){if(response=='success'){$("#save_thumb, #save_thumb_biz").attr("value","Save Thumbnail");$("#save_thumb, #save_thumb_biz").attr("class","btn-submit text span-3");$("#save_thumb, #save_thumb_biz").removeAttr("disabled");$("body").fadeTo("fast",0.5);location.reload()}else{$("div.ajax-load-page").hide();$("a.btnConfirm").show();$.jGrowl("Something went wrong, please try again.");$("#img-thumb").show();$('#img-thumb').find('#thumbnail').imgAreaSelect({aspectRatio:'1:1',onSelectChange:preview,parent:'#imgHandler',minWidth:200,minHeight:200,handles:true,disable:false})}}});return false}})}function badgeChange(selector,urlUser){hist_id=$(selector).attr("hist_id");cate=$(selector).attr("cate");goto=$(selector).attr("href");member=$(selector).attr("member");$.ajax({global:false,beforeSend:function(){},type:"POST",url:urlUser+"/stream",timeout:50000,data:{status:"badge",hist_id:hist_id,member:member},success:function(msg){$("#badgeBig").html(msg)},error:function(request,errorType,errorThrown){try{if(errorType!=null){$.jGrowl("Something went wrong, please try again.")}}catch(e){}}});window.location="#"+goto}function settings(status){$(".cekjs").hide();$(".form_settings").show();$(".error_box").hide();if(status=="")status=$("#setting_type").val();if(login!="login"){switch(status){default:cekUsername();cekEmail();break}}$("#settings_save").livequery("click",function(event){var status=$("#setting_type").val();switch(status){case'password':$(".invalid").remove();if(validatePassword())$(".form_settings").submit();break;case'connection':$(".form_settings").submit();break;case'notices':$(".form_settings").submit();break;default:if(validateAccount()){$(".password-dialog").show();$("#save_password").livequery("click",function(event){pass=$("#auth_password").val();$.ajax({global:false,beforeSend:function(){$("#save_password").hide()},type:"POST",url:base_url+"/ajax/ajaxRegis",data:{pass:pass,key:"passwc"},success:function(msg){if(msg==0)$("#save_password").show();else $(".form_settings").submit()}});return false});$("#cancel_link, .modal-close").livequery("click",function(event){$(".password-dialog").hide();return false})}break}return false})}function account(login){$(".cekjs").hide();$(".form_account").show();$(".error_box").hide();$("#account_save").livequery("click",function(event){$(".invalid").remove();if(validatePassword('account'))$(".form_account").submit();return false});$("#confirm_delete").livequery("click",function(event){$(".password-dialog").show();$("#save_password").livequery("click",function(event){pass=$("#auth_password").val();$.ajax({global:false,beforeSend:function(){$("#save_password").hide()},type:"POST",url:base_url+"/ajax/ajaxRegis",data:{pass:pass,key:"passwc"},success:function(msg){if(msg==0)$("#save_password").show();else $(".form_account").submit()}});return false});$("#cancel_link, .modal-close").livequery("click",function(event){$(".password-dialog").hide();return false})})}function validateAccount(){var status=new Array(1,1,1);var setfoc=new Array(0,0);$(".error_box").hide();var fullname=$("#user_fullname").val();if(fullname==""){$("#reg_fullname_error").find("td").html("Please enter your fullname.").addClass("error");$("#reg_fullname_error").show();status[0]=1;if(setfoc[0]==0){$("#user_fullname").focus();setfoc[0]=1}}else{if(fullname.match(/[^a-zA-Z0-9 _]/)){$("#reg_fullname_error").find("td").html("Sorry, no special character allowed for fullname.").addClass("error");$("#reg_fullname_error").show();status[0]=1;if(setfoc[0]==0){$("#user_fullname").focus();setfoc[0]=1}}else{status[0]=0}}var username=$("#user_screen_name").val();if(username==""){$("#user_screen_name").parent().find(".msg").show("slow");$("#user_screen_name").parent().find(".msg").css({"color":"red"});$("#user_screen_name").parent().find(".msg").html("Please enter your username");status[1]=1;if(setfoc[0]==0){$("#user_screen_name").focus();setfoc[0]=1}}else{if(username.match(/\W/)){$("#user_screen_name").parent().find(".msg").show("slow");$("#user_screen_name").parent().find(".msg").css({"color":"red"});$("#user_screen_name").parent().find(".msg").html("Sorry, no special character allowed for username.");status[1]=1;if(setfoc[0]==0){$("#user_screen_name").focus();setfoc[0]=1}}else{$("#user_screen_name").parent().find(".msg").hide();status[1]=0}}var email=$("#user_email").val();if(email==""){$("#user_email").parent().find(".msg").show("slow");$("#user_email").parent().find(".msg").css({"color":"red"});$("#user_email").parent().find(".msg").html("Please enter your email address.");status[2]=1;if(setfoc[0]==0){$("#user_email").focus();setfoc[0]=1}}else{if(!isValidEmail(email)){$("#user_email").parent().find(".msg").show("slow");$("#user_email").parent().find(".msg").css({"color":"red"});$("#user_email").parent().find(".msg").html("Please enter valid email address.");status[2]=1;if(setfoc[0]==0){$("#user_email").focus();setfoc[0]=1}}else{$("#user_email").parent().find(".msg").hide();status[2]=0}}if(status=="0,0,0"){return true}else{return false}return false}function validatePassword(key){var status=(key=="")?new Array(1,1,1):new Array(0,1,1);var setfoc=new Array(0,0);$(".error_box").hide();if(key==""){var cur_pass=$("#current_password").val();if(cur_pass==""){$("#reg_current_password_error").find("td").html("Please enter your current password.").addClass("error");$("#reg_current_password_error").show();status[0]=1;if(setfoc[0]==0){$("#current_password").focus();setfoc[0]=1}}else{if(cur_pass.length<6){$("#reg_current_password_error").find("td").html("Please enter a password that is at least 6 characters long.").addClass("error");$("#reg_current_password_error").show();status[0]=1;if(setfoc[0]==0){$("#current_password").focus();setfoc[0]=1}}else{status[0]=0}}}var pass=$("#user_password").val();if(pass==""){$("#reg_user_password_error").find("td").html("Please enter new your password.").addClass("error");$("#reg_user_password_error").show();status[1]=1;if(setfoc[0]==0){$("#user_password").focus();setfoc[0]=1}}else{if(pass.length<6){$("#reg_user_password_error").find("td").html("Please enter a password that is at least 6 characters long.").addClass("error");$("#reg_user_password_error").show();status[1]=1;if(setfoc[0]==0){$("#user_password").focus();setfoc[0]=1}}else{status[1]=0}}var pass=$("#user_password").val();var conf=$("#user_password_confirmation").val();if(conf==""){$("#reg_user_password_confirmation_error").find("td").html("Please enter the confirmation password.").addClass("error");$("#reg_user_password_confirmation_error").show();status[2]=1;if(setfoc[0]==0){$("#user_password_confirmation").focus();setfoc[0]=1}}else{if(conf!=pass){$("#reg_user_password_confirmation_error").find("td").html("Make sure the password you enter are the same.").addClass("error");$("#reg_user_password_confirmation_error").show();status[2]=1;if(setfoc[0]==0){$("#user_password_confirmation").focus();setfoc[0]=1}}else{status[2]=0}}if(status=="0,0,0"){return true}else{return false}return false}function isValidEmail(str){var s=$.trim(str);var at="@";var dot=".";var lat=s.indexOf(at);var lstr=s.length;var ldot=s.indexOf(dot);if(s.indexOf(at)==-1||(s.indexOf(at)==-1||s.indexOf(at)==0||s.indexOf(at)==lstr)||(s.indexOf(dot)==-1||s.indexOf(dot)==0||s.indexOf(dot)==lstr)||(s.indexOf(at,(lat+1))!=-1)||(s.substring(lat-1,lat)==dot||s.substring(lat+1,lat+2)==dot)||(s.indexOf(dot,(lat+2))==-1)||(s.indexOf(" ")!=-1)){return false}return true}function cekUsername(status,setfoc){var uname=$("#current_uname").val();$("#user_screen_name").val(uname);$("#user_screen_name").parent().find(".msg").hide();$("#user_screen_name").livequery("keyup",function(event){val=$(this).val();if(val!=""){$(".url").find("span").html(val);if(val.match(/\W/)){$("#user_screen_name").parent().find(".msg").show("slow");$("#user_screen_name").parent().find(".msg").css({"color":"red"});$("#user_screen_name").parent().find(".msg").html("Only use letters, numbers and '_'")}else{if(val!=uname){$.ajax({global:false,beforeSend:function(){$("#user_screen_name").parent().find(".availability").show();$("#user_screen_name").parent().find(".msg").hide();$("#user_screen_name").parent().find(".msg").html("")},type:"POST",url:base_url+"/ajax/ajaxRegis",data:{uname:val,key:"uname"},success:function(msg){$("#user_screen_name").parent().find(".availability").hide();var reply=(msg==0)?'Available':'Username has already been taken';var color=(msg==0)?'green':'red';$("#user_screen_name").parent().find(".msg").show("slow");$("#user_screen_name").parent().find(".msg").css({"color":color});$("#user_screen_name").parent().find(".msg").html(reply)}})}else{$("#user_screen_name").parent().find(".msg").show("slow");$("#user_screen_name").parent().find(".msg").css({"color":"green"});$("#user_screen_name").parent().find(".msg").html("That's You!")}}}})}function cekEmail(){var email=$("#current_email").val();$("#user_email").val(email);$("#user_email").parent().find(".msg").hide();$("#user_email").livequery("keyup",function(event){val=$(this).val();if(val!=""){if(!isValidEmail(val)){$("#user_email").parent().find(".msg").show("slow");$("#user_email").parent().find(".msg").css({"color":"red"});$("#user_email").parent().find(".msg").html("Please enter valid email address.")}else{if(val!=email){$.ajax({global:false,beforeSend:function(){$("#user_email").parent().find(".availability").show();$("#user_email").parent().find(".msg").hide();$("#user_email").parent().find(".msg").html("")},type:"POST",url:base_url+"/ajax/ajaxRegis",data:{email:val,key:"email"},success:function(msg){$("#user_email").parent().find(".availability").hide();var reply=(msg==0)?'Available':'Email has already been taken';var color=(msg==0)?'green':'red';$("#user_email").parent().find(".msg").show("slow");$("#user_email").parent().find(".msg").css({"color":color});$("#user_email").parent().find(".msg").html(reply)}})}else{$("#user_email").parent().find(".msg").show("slow");$("#user_email").parent().find(".msg").css({"color":"green"});$("#user_email").parent().find(".msg").html("That's You!")}}}})}
