(function($){$(function(){if(typeof pageLoaded!="undefined"){switch(pageLoaded){case"iscrizione":initSignIn();break;case"moreInfo":initMoreInfo();break;case"scheda":initScheda();break;case"battleMiss":initBattleMiss();break;case"resumeMiss":initResumeMiss();break;case"profile":initMoreInfo();initScheda();break;case"home":initHome();break}}function initHome(){$(".jsChooseSex").click(function(){var submitForm=window.document.createElement("FORM");var page=window.location.href;var check=new RegExp("/(?:"+lingue.join("|")+")/");if(check.exec(page)){lang=check.exec(page)}else{lang="/"}submitForm.method="POST";submitForm.action=lang+"showall.php";var inp=window.document.createElement("INPUT");inp.type="HIDDEN";inp.name="sex";inp.value=$(this).attr("alt");submitForm.appendChild(inp);$("body").append(submitForm);$(submitForm).submit()})}function checkIsSubmittable(sel){if(typeof $("input.MultiFile")!="undefined"&&$("input.MultiFile").length>1){$(sel).attr("disabled","");return true}$(sel).attr("disabled","disabled");return false}function initSignIn(){$.validator.addMethod("datacheck",function(){return checkDate()});$.validator.addMethod("nickcheck",function(){return checkNick()});$("#T1").MultiFile({list:"#T1-list",afterFileAppend:function(){checkIsSubmittable("#submit")},afterFileRemove:function(){checkIsSubmittable("#submit")}});$("#form1").validate({rules:{email:{required:true,maxlength:60,email:true},nickname:"nickcheck",password:{required:true,minlength:5},confirm_password:{required:true,minlength:5,equalTo:"#password"},sex:{required:true},anno:"datacheck"},errorElement:"span",errorClass:"Error"});$("#password").blur(function(){$("#confirm_password").valid()});$("#email,#nickname").keyup(function(){if(typeof $(this).next("span.Error")!="undefined"&&$(this).next("span.Error").length>0){$(this).removeClass("Error").next("span.Error").remove()}});$("#giorno,#mese,#anno").change(function(){if(checkDate("a")){$("#datanasci").removeClass("Error");$("#anno").removeClass("Error");$("#datanasci  span.Error").remove()}else{$("#datanasci").addClass("Error");if(typeof $("#datanasci span.Error")!="undefined"&&$("#datanasci span.Error").length<1){$("#error_date").clone().appendTo("#datanasci").removeClass("Hidden").show()}}});$("#submit").attr("disabled","disabled")}function initMoreInfo(){$("#img_current").attr("value",$("ul.Gall li.Active img").attr("id"));$("#real_img_current").attr("value",$("ul.Gall li.Active img").attr("id"));$("ul.Gall .Thb").click(function(){$(this).parents("li").addClass("Active").siblings().removeClass("Active");$("#img_current").attr("value",$(this).find("img").attr("id"));return false})}function initScheda(){$("#T1").MultiFile({list:"#T1-list"});$(".infoPhp").remove();$("ul.Gall input").remove();$(".jsX").removeClass("Hidden");var form1=$("#form1").serialize();$("#submit").click(function(){$("input[name=save]").val(1)});$("#unsub").click(function(){$("input[name=save]").val(1)});$("#giorno,#mese,#anno").change(function(){if(checkDate("a")){$("#datanasci").removeClass("Error");$("#datanasci  span.Error").remove();$("#submit").attr("disabled","")}else{$("#datanasci").addClass("Error");$("#submit").attr("disabled","disabled");if(typeof $("#datanasci span.Error")!="undefined"&&$("#datanasci span.Error").length<1){$("#error_date, #error_major").addClass("Hidden");$("#error_date").clone().appendTo("#datanasci").removeClass("Hidden").show()}}});window.onbeforeunload=function(){var form2=$("#form1").serialize();if($("input[name=save]").val()!=1&&form1!=form2){return msg_conf}}}function initBattleMiss(){$("a.Vote").click(function(){$.post("/battle_miss.php",{ccod:$("input[name=ccod]").val(),id:$(this).attr("rel"),sex:$("input[name=sex]").val()},function(){window.location.reload()})})}$("a[rel^='lightbox']").slimbox({counterText:"{x} / {y}",loop:true},null);function initResumeMiss(){var winPub=$("#WinPublish");var winSend=$("#WinSendTo");var fb=$("#jsFbPublish");var wl=$("#jsWlPublish");var ms=$("#jsMsPublish");var sendBut=$("#jsSendTo");var chooseBut=$("#jsSendChoose",winSend);$("#jsAddEmail",winSend).live("click",function(){var c=$("#jsWinPublish li.jsRcpt:eq(0)").clone();c.find("input").val("");$("#jsWinPublish").append(c);return false});$("a.jsRcptDel",winSend).live("click",function(){if($(".jsRcptDel",winSend).length>1){$(this).parents("li").remove()}return false});$(sendBut).click(function(){$(winSend).modal({persist:false,overlayId:"modalOverlay",onClose:function(){$(chooseBut).show();$(".jsResponse",winSend).remove();$("div.jsStep",winSend).addClass("Hidden");$("#jsSendInviteStep2 #jsContacts>ul",winSend).empty();$(":input:not(:hidden)",winSend).each(function(){$(this).val("")});$.modal.close()}});return false});$(fb).add(ms).add(wl).click(function(e){if($(this).is("#jsMsPublish")){pageTracker._trackPageview("/stat-step3-myspace");$("input[name=type]",winPub).val("ms")}else{if($(this).is("#jsFbPublish")){pageTracker._trackPageview("/stat-step3-facebook");$("input[name=type]",winPub).val("fb")}else{pageTracker._trackPageview("/stat-step3-live");$("input[name=type]",winPub).val("wl")}}if($("input[name=public]",winSend).val()!=1){$(winPub).modal();if($("input[name=public]",winSend).val()!=1){return false}}return true});$("button.BotG",winPub).click(function(){var form=$("#form1",winPub);var err=$("input[type=text]",winPub).filter(function(){return !$(this).val()}).length;if(!err){$.ajax({type:"POST",url:"/ajax.php",data:$(form).serialize(),dataType:"html",success:function(data){$(".Bod",winPub).empty().append('<div class="jsResponse">'+data+"</div>");$("input[name=public]",winSend).val(1)},error:function(xhr,text,status){$(".Bod",winPub).empty().append('<div class="jsResponse">'+text+"</div>")}})}return false});$("a",chooseBut).live("click",function(){var type=$(this).attr("rel");$(chooseBut).hide();if(type=="jsSendInvite"){$("#simplemodal-container").addClass("LargeModal")}$("#"+type,winSend).removeClass("Hidden");return false});function handleError(xhr,text,status){error="Error";if(xhr.responseText){data=eval("("+xhr.responseText+")");if(data.errors){error=data.errors.join("<br/>")}}$(".Bod",winSend).prepend('<div class="jsResponse Error">'+error+"</div>");$(".Loading").addClass("Hidden")}$(winSend).bind("ajaxStart",function(){$(".jsResponse",winSend).remove();$(".Loading",this).removeClass("Hidden")}).bind("ajaxComplete",function(){$(".Loading",this).addClass("Hidden")});$("#jsSendInvite button",winSend).live("click",function(){var form=$("#form2",winSend);var err=$("input[type=text]",form).filter(function(){return !$(this).val()}).length;if(!err){$(".Loading",form).removeClass("Hidden");$.ajax({type:"POST",url:"/ajax.php",data:$(form).serialize(),dataType:"json",success:function(data){$("#jsSendInviteStep2 input[name=provider]").val($("#jsSendInvite input[name=provider]:checked").val());$("#jsSendInviteStep2 input[name=email]",winSend).val($("input[name=email]",form).val());$("#jsSendInviteStep2 input[name=sessID]",winSend).val(data.sessID);var ul=$("<ul>");for(contact in data.contacts){var name=data.contacts[contact];$(ul).append('<li><input type="checkbox" name="contacts[]" value="'+name+"#"+contact+'" checked="checked" />&nbsp;'+name+"</li>")}$("#jsSendInviteStep2 #jsContacts>ul",winSend).replaceWith(ul);$("#jsSendInvite",winSend).addClass("Hidden");$("#jsSendInviteStep2",winSend).removeClass("Hidden");$("input[name=public]",winSend).val(1)},error:handleError})}return false});$("#jsSendInvite .Providers label").live("click",function(){$(this).addClass("Sel").siblings().removeClass("Sel").find(":input").attr("checked","");$(this).find(":input").attr("checked","checked").blur()});$("#jsSendInviteStep2 #jsSelect",winSend).live("click",function(e){var a=e.target;var checks=$(a).parent().next().find(":input");if($(e.target).is(".jsAll")){$(checks).attr("checked","checked")}else{$(checks).attr("checked","")}return false});$("#jsSendInviteStep2 button",winSend).live("click",function(){var form=$("#form3",winSend);$(".Loading",form).removeClass("Hidden");$.ajax({type:"POST",url:"/ajax.php",data:$(form).serialize(),dataType:"json",success:function(){$(".Loading").addClass("Hidden");pageTracker._trackPageview("/stat-step3-sendinvite");$("div.jsStep",winSend).addClass("Hidden");$("#jsSendInviteStep3",winSend).removeClass("Hidden");$(".jsWinTitle").remove()},error:handleError});return false});$("#jsSendInviteStep3 button",winSend).live("click",function(){$(winSend).parent().find(".modalCloseImg").trigger("click");return false});$("#jsSendNormal button",winSend).live("click",function(){var form=$("#form1",winSend);var err=$("li:not(.jsRcpt) input[type=text]",form).filter(function(){return !$(this).val()}).length;var rcptOk=$("li.jsRcpt input[type=text]",form).filter(function(){return $(this).val()}).length;$(winSend).find(".jsResponse").remove();if(!err&&rcptOk>0){$.ajax({type:"POST",url:"/ajax.php",data:$(form).serialize(),dataType:"html",success:function(data){$(".Bod",winSend).prepend('<div class="jsResponse">'+data+"</div>");$("input[name=public]",winSend).val(1);$(".jsWinTitle").remove();$("li.jsRcpt input[type=text]",winSend).val("");pageTracker._trackPageview("/stat-step3-sendmail")},error:function(xhr,text,status){$(".Bod",winSend).prepend('<div class="jsResponse">'+xhr.responseText+"</div>")}})}return false})}})})(jQuery);function checkDate(e){var c=new Date();var d=parseInt($("#giorno").val().replace(/^0/,""));var a=parseInt($("#mese").val().replace(/^0/,""));a=(!isNaN(a)&&a>0)?(a-1):"";var b=parseInt($("#anno").val());if(a===""||d===""||b===""){if(typeof e=="undefined"){setColoreErrData(true)}return false}c.setFullYear(b,a,d);if(c.getMonth()!=a){if(typeof e=="undefined"){setColoreErrData(true)}whichError="data_errata";return false}else{if(checkAge(d,a,b)){if(typeof e=="undefined"){setColoreErrData(false)}return true}else{if(typeof e=="undefined"){setColoreErrData(true)}whichError="maggiorenne";return false}}}function checkNick(b){var a=$("#nickname").val();return(a.match(/^[A-Za-z0-9 ]{3,30}$/))}function setColoreErrData(a){if(a==true){$("#datanasci span.Error").remove();$("#datanasci").addClass("Error")}else{$("#datanasci").removeClass("Error")}}function checkAge(b,d,c){var f=18;var e=new Date((c+f),d,b);var a=new Date;if((a.getTime()-e.getTime())<0){return false}else{return true}}function deleteImg(d,b){if(!confirm(d)){return false}if(b==$("#img_current").val()){$("#err_del_img").show();$("#err_del_img_ex").hide();return false}else{if(b==$("#real_img_current").val()){$("#err_del_img").hide();$("#err_del_img_ex").show();return false}else{var a=$("#nick").val();var c=$("#lastid").val();$("#err_del_img").hide();$.ajax({type:"POST",url:"/ajax.php",data:"img="+b+"&nick="+a+"&id_u="+c+"&a=deleteImgAjax",dataType:"html",success:function(e){$("#gall_"+b).remove()},error:function(f,g,e){alert(f+" "+g+" "+e)}})}}};