var included_files=new Array();var unload_msg='';$().ready(function(){auto_redirect=0;if((window.location["pathname"]=="/login")||(window.location["pathname"]=="/login/")){auto_redirect=1;displayLoginRegisterModal(null)}bindLoginButtons()});function bindLoginButtons(){$('.Login.Button, .silverleaf.login.button').unbind('click');$('.Login.Button, .silverleaf.login.button').click(function(e){e.preventDefault();displayLoginRegisterModal(null)})}function setConfirmUnload(a){if(a){unload_msg=a;window.onbeforeunload=unloadMessage}else{unload_msg='';window.onbeforeunload=null}}function unloadMessage(){return unload_msg}function include_once(a){if(!in_array(a,included_files)){included_files[included_files.length]=a;include_dom(a)}}function include_dom(a){var b=document.getElementsByTagName('head').item(0);t=a.substring(a.lastIndexOf('.')+1);if(t=='js'){var c=document.createElement('script');c.setAttribute('language','javascript');c.setAttribute('type','text/javascript');c.setAttribute('src',a)}else if(t=='css'){var c=document.createElement('link');c.setAttribute('rel','stylesheet');c.setAttribute('type','text/css');c.setAttribute('href',a)}b.appendChild(c);return false}function in_array(a,b){for(var i=0;i<b.length;i++){if(b[i]==a){return true}}return false}function displayLoginRegisterModal(a){var b={"action":"fetch-login-register-form"};createModalPopup(null,true,'auth',b,login_form_display);if($('#auth_email',modal).val()=='')$('#auth_email',modal).focus();else $('#auth_pwd',modal).focus()}function login_form_display(b){if(typeof $('response-code',b)=='undefined'){$('.modal-status-message',modal).html('<pre>'+$(this).text()+'</pre><p style="margin-top:20px;"><a href="#" class="close button">close</a></p>').show();$('.modal-status-message .close.button',modal).click(function(e){e.preventDefault();$('.modal-status-message',modal).html('').hide();$('.modalBody',modal).show()})}else{$(b).find('response-code').each(function(){if($(this).text()=="0"){$(b).find('response-message').each(function(){$('.modal-status-message',modal).html('<h2>Error</h2><pre>'+$(this).text()+'</pre><p style="margin-top:20px;"><a href="#" class="close button">close</a></p>').show();$('.modal-status-message .close.button',modal).click(function(e){e.preventDefault();$('.modal-status-message',modal).html('').hide();$('.modalBody',modal).show();hideModal(modal)})})}else if($(this).text()=="1"){var a=$('response-message',b);$('.modal-status-message',modal).html('').hide();$('.modalBody',modal).html($(a).text()).show();$('.modal-user-registration-form #reg_email, .modal-user-registration-form #reg_email2',modal).bind('change',function(e){email=$('.modal-user-registration-form #reg_email',modal).val();email2=$('.modal-user-registration-form #reg_email2',modal).val();if((email!='')&&(email2!='')&&(email!=email2)){$('.reg-msgs',modal).html("The two email addresses you've entered do not match.")}else{$('.reg-msgs',modal).html("&nbsp;")}});$('*:input[type!=hidden]:first',modal).focus()}else{a="<h1>"+$('sl-form',b).attr("title")+"</h1>";$(b).find('xhtml').each(function(){a+=$(this).text()});$('.modal-status-message',modal).html('').hide();$('.modalBody',modal).html(a).show();$('*:input[type!=hidden]:first',modal).focus()}})}}function checkLoginForm(a){email=$('#auth_email',a).val();pwd=$('#auth_pwd',a).val();if($('#auth_email',a).val()=='')return false;if($('#auth_pwd',a).val()=='')return false;$('.modal-status-message',modal).html('<h1>Logging in...</h1>').show();$('.modalBody',modal).hide();$.ajax({'type':"POST",async:false,'url':"/cms/ajax/",'data':{'mod':"auth",'action':"login",'auto-redirect':auto_redirect,'auth_email':email,'auth_pwd':pwd,'remember_me':$('#remember_me',a).val()},'success':userLoginSubmitSuccess,'error':ajaxError});return false}function userLoginSubmitSuccess(a){$(a).find('response-code').each(function(){if($(this).text()=="0"){$(a).find('response-message').each(function(){$('.system-messages',modal).html('<p>Login Failed: '+$(this).text()+'</p>');$('#auth_pwd',modal).val('');$('.modal-status-message',modal).html('').hide();$('.modalBody',modal).show();$('#auth_pwd',modal).focus()})}else if($(this).text()=="1"){if(typeof original_modal_callback!="undefined"){hideModal(modal);original_modal_callback(self._name,self.type)}else{redirect_url=$('redirect',a);if(typeof(redirect_url)!='undefined'){redirect_url=redirect_url.text();if(redirect_url!=''){$('.modal-status-message',modal).html('<p>Login Succeeded. Redirecting to: '+redirect_url+'</p>');window.location.href=$('redirect',a).text()}else{window.location.reload()}}else{window.location.reload()}}}else{modal_body="<h1>"+$('sl-form',a).attr("title")+"</h1>";$(a).find('xhtml').each(function(){modal_body+=$(this).text()});$('.modal-status-message',modal).html('').hide();$('.modalBody',modal).html(modal_body).show();$('*:input[type!=hidden]:first',modal).focus()}})}function checkAuthentication(){if(typeof(current_user)!='undefined'){$('body').addClass('authenticated');$('.silverleaf.login.button').closest('div').html('<a href="/me/" title="click here to visit your personal page" class="silverleaf my-page button">'+current_user['display-name']+'</a> | <a href="./?action=logout" title="Click here to end your session and log out" class="silverleaf logout button">Logout</a>');return true}else return false}function checkUserRegForm(a){email=$('#reg_email',a).val();email2=$('#reg_email2',a).val();if((email!='')&&(email2!='')&&(email!=email2)){$('.reg-msgs',modal).html("The two email addresses you've entered do not match.")}else{$('.reg-msgs',modal).html("&nbsp;")}if((email!='')&&(email2!='')&&(email!=email2)){$('.reg-msgs',a).html("The two email addresses you've entered do not match.")}else if(email==""||email2==""){$('.reg-msgs',a).html("&nbsp;")}else{$('.reg-msgs',a).html("&nbsp;");$('.modal-status-message',modal).html('<h1>Sending user registration information...</h1>').show();$('.modalBody',modal).hide();$.ajax({'type':"POST",async:false,'url':"/cms/ajax/",'data':{'mod':"users",'action':"create-new-user",'email':email},'success':userRegSuccess,'error':ajaxError})}return false}function userRegSuccess(a){$(a).find('response-code').each(function(){if($(this).text()!="1"){$(a).find('response-message').each(function(){$('.modal-status-message',modal).html('<h2 style="margin-bottom:15px;">Error:</h2>'+$(this).text()+'<p style="margin-top:20px;"><a href="#" class="close button">close</a></p>').show();$('.modal-status-message .close.button',modal).click(function(e){e.preventDefault();$('.modal-status-message',modal).empty().hide();$('.modalBody',modal).show()})})}else if($(this).text()=="1"){$('.modal-status-message',modal).empty().hide();$('.modalBody',modal).empty().html($('response-message',a).text()).show();$('*:input[type!=hidden]:first',modal).focus()}});return false}function submitActivationCode(a){key=$('#activation-key',a).val();pwd=$('#pwd',a).val();if(key=='')return false;if(pwd!=$('#pwd2',a).val()){$('.system-messagess',a).text('The two passwords you entered do not match.');return false}$('.modal-status-message',modal).html('<h1>Sending activation key...</h1>').show();$('.modalBody',modal).hide();$.ajax({'type':"POST",async:false,'url':"/cms/ajax/",'data':{'mod':"users",'action':"activate-pwd",'key':key,'new_pwd':pwd,'uid':$('#uid',a).val()},'success':userAcctActivationSuccess,'error':ajaxError});return false}function userAcctActivationSuccess(a){$(a).find('response-code').each(function(){if($(this).text()=="0"){$(a).find('response-message').each(function(){$('.system-messages',modal).html('<p>Account activation failed: '+$(this).text()+'</p>');$('.modal-status-message',modal).html('').hide();$('.modalBody',modal).show()})}else if($(this).text()=="1"){if(typeof original_modal_callback!="undefined"){if(typeof modal!=='undefined'){hideModal(modal);delete modal}original_modal_callback(self._name,self.type)}else{$('.modal-status-message',modal).html('').hide();$('.modalBody',modal).html('<p>Account activation succeeded! You should automatically be redirected to the page you originally requested. If not, <a href="'+$('redirect',a).text()+'">please click this link to go there immediately.</a></p>').show();window.location.href=$('redirect',a).text()}}else{modal_body="<h1>"+$('sl-form',a).attr("title")+"</h1>";$(a).find('xhtml').each(function(){modal_body+=$(this).text()});$('.modal-status-message',modal).html('').hide();$('.modalBody',modal).html(modal_body).show();$('*:input[type!=hidden]:first',modal).focus()}});return false}function ajaxError(a,b,c){if(typeof(ajax_status)!='undefined')ajax_status='';if(typeof(modal)!='undefined'){$('.modal-status-message',modal).html('<h2>AJAX request error: &quot;'+b+'&quot; : &quot;'+c+'&quot;</h2><p>Server response:</p><pre>'+a.responseText+'</pre><p style="margin-top:20px;"><a href="#" class="close button">close</a></p>').show();$('.modal-status-message .close.button',modal).click(function(e){e.preventDefault();$('.modal-status-message',modal).html('').hide();$('.modalBody',modal).show()})}else{alert('AJAX request error: "'+b+' : "'+c+"\n\nServer response: "+a.responseText)}}function createModalPopup(a,b,c,d,f){if($('#modal-window-container').css('display')=="none"){modal=$('#modal-window-container');$('.modalBody',modal).hide();$('.modal-status-message',modal).html('<h1>Loading content...</h1>').show();if(window.onbeforeunload==null){$('.modal-button-close, .cancel.button',modal).click(function(e){e.preventDefault();$(this).parents('.silverleaf.modal').removeClass('modal-page-properties');hideModal(modal);setConfirmUnload(false)})}else{$('.modal-button-close, .cancel.button',modal).click(function(e){e.preventDefault();$(this).parents('.silverleaf.modal').removeClass('modal-page-properties');hideModal(modal)})}revealModal(modal);if(b!==false){d["mod"]=c;$.ajax({'type':"GET",async:false,'url':"/cms/ajax/",'data':d,'success':f,'error':ajaxError})}else{$('.modalBody',modal).html(a)}}else{alert('WARNING!!!\n\nThere is already a visible modal window open!\n\nUnable to open new modal window.')}}function revealModal(a){$(a).show();$('html, body').scrollTop(0)}function hideModal(a,b){if(typeof(b)=='undefined')$(a).hide();else $(a).delay(b).hide('slow')}
