


function Online() {
 new Ajax.Request('/ajax.php?action=Online', {
   method: 'post',
   onSuccess: function(x) {
     x.responseJSON.Online.each( function(s) { 
       var el = Builder.node('div', { id: 'oU'+ s['id'] }, s['nn'] );
       $('useronline').appendChild(el);
     } );
   },
   onFailure: function(x) {
//       alert('Ajax Failed');
   }
 });
}

function DeleteMessage(nMessageId) {
 new Ajax.Request('/ajax.php?action=DeleteMessage', {
   method: 'post',
   parameters: 'nMessageId='+nMessageId,
   onSuccess: function(x) {
       if (x.responseJSON.Status=='1') {
         Effect.Puff('Message'+nMessageId);
       } else {
         alert(x.responseJSON.Msg);
       }
     
   },
   onFailure: function(x) {
       alert('Ajax Failed');
   }
 });
}

function DeleteGuestbook(nMessageId, nUserId) {
 new Ajax.Request('/ajax.php?action=DeleteGuestbook', {
   method: 'post',
   parameters: {'nMessageId': nMessageId, 'nUserId': nUserId},
   onSuccess: function(x) {
       if (x.responseJSON.Status=='1') {
         Effect.Puff('GB'+nMessageId);
       } else {
         alert(x.responseJSON.Msg);
       }
     
   },
   onFailure: function(x) {
       alert('Ajax Failed');
   }
 });
}

function DeleteComment(nImageId, nCommentId) {
 new Ajax.Request('/ajax.php?action=DeleteComment', {
   method: 'post',
   parameters: {'nCommentId': nCommentId, 'nImageId': nImageId},
   onSuccess: function(x) {
       if (x.responseJSON.Status=='1') {
         Effect.Puff('C'+nCommentId);
       } else {
         alert(x.responseJSON.Msg);
       }
     
   },
   onFailure: function(x) {
       alert('Ajax Failed');
   }
 });
}

function DeleteGallery(sGalleryName, sWarning) {
 if (sWarning!='') {
  if (!confirm(sWarning)) {
    return;
  }
 }
 new Ajax.Request('/ajax.php?action=DeleteGallery', {
   method: 'post',
   parameters: {'sGalleryName': sGalleryName},
   onSuccess: function(x) {
       if (x.responseJSON.Status=='1') {
         Effect.Puff('Gallery'+x.responseJSON.Div);
       } else {
         alert(x.responseJSON.Msg);
       }
     
   },
   onFailure: function(x) {
       alert('Ajax Failed');
   }
 });
}

function BoardDelete(nMessageId) {
 new Ajax.Request('/ajax.php?action=DeleteBB', {
   method: 'post',
   parameters: {'nMessageId': nMessageId},
   onSuccess: function(x) {
       if (x.responseJSON.Status=='1') {
         Effect.Puff('Board'+nMessageId);
       } else {
         alert(x.responseJSON.Msg);
       }
     
   },
   onFailure: function(x) {
       alert('Ajax Failed');
   }
 });
}

function BoardAnswer(nMessageId) {
  $('addComment').show();
  if (document.location.href.match(/entry$/)) {
    document.location.href=document.location.href;
  } else {
    document.location.href=document.location.href + '#entry';
  }
   new Ajax.Request('/ajax.php?action=ReplyBB', {
     method: 'post',
     parameters: 'nMessageId='+nMessageId,
     onSuccess: function(x) {
         if (x.responseJSON.Status=='1') {
           document.forms.messageform.body.value=x.responseJSON.xBody;
           document.forms.messageform.subject.value=x.responseJSON.xSubject;
         } else {
    //       alert(x.responseJSON.Msg);
         }
     
     },
     onFailure: function(x) {
  //       alert('Ajax Failed');
     }
   });

}

function Unlock(nUserId, sGallery, sPass) {
 var param = { 'nUserId': nUserId, 'sPass': sPass, 'sGallery': sGallery };
 new Ajax.Request('/ajax.php?action=Unlock', {
   method: 'post',
   parameters: param,
   onSuccess: function(x) {
       if (x.responseJSON.Status=='1') {
         Effect.Fold('unlocker');
         window.setTimeout('top.location.href=top.location.href', 1000);
       } else {
//         Effect.Fold('unlocker', {duration: 0.15});
//         window.setTimeout('top.location.href=top.location.href', 1600);
         Effect.Shake('unlocker');
       }
     
   },
   onFailure: function(x) {
//       alert('Ajax Failed');
   }
 });
 return false;
}

function GalleryMoveUp(nGalleryId) {
 new Ajax.Request('/ajax.php?action=Galleries', {
   method: 'post',
   parameters: 'nGalleryId='+nGalleryId+'&xaction=MoveUp',
   onSuccess: function(x) {
       if (x.responseJSON.Status=='1') {
         g1 = $('Gallery'+nGalleryId);
         $('Gallery'+nGalleryId).Remove();
       } else {
         alert(x.responseJSON.Msg);
       }
     
   },
   onFailure: function(x) {
//       alert('Ajax Failed');
   }
 });
}

function DivIframe(url, w, h) {
 x = Math.round((document.viewport.getWidth()-w)/2)
 y = Math.round((document.viewport.getHeight()-h)/2)
 sw = document.viewport.getWidth();
 sh = document.body.offsetHeight;
 offset = document.viewport.getScrollOffsets();
 y = y + offset.top;

 if ($('lf')!=null) {
   $('lf').remove();
 }
 var MyWin = Builder.node('div', { id: 'lf', style: 'border:solid 1px;position:absolute;width:'+w+'px;height:'+h+'px;left:'+x+'px;top:'+y+'px;' },
                             Builder.node('iframe', {src: url, style: 'width:100%;height:100%;margin:0px;padding:0px;border:0px'}, 
                                   ''
                             )
             );
 var Grey = Builder.node('div', { id: 'grey', style: 'position:absolute;background-color:#000;filter:alpha(opacity=40); -moz-opacity:0.4;width:' + sw + 'px;height:' + sh + 'px;left:0px;top:0px;margin:0;padding:0' } );
 $('igcontainer').appendChild(Grey);
 $('igcontainer').appendChild(MyWin);
}

function Friend(nUserId) {
 DivIframe('/iframe.php?action=AddFriend&nUserId=' + nUserId, 400, 250);
}

function UnFriend(nUserId, sWarning) {
 if (sWarning!='') {
  if (!confirm(sWarning)) {
    return;
  }
 }
 new Ajax.Request('/ajax.php?action=UnFriend', {
   method: 'post',
   parameters: {'nUserId': nUserId},
   onSuccess: function(x) {
       if (x.responseJSON.Status=='1') {
         top.location.href='/user/'+nUserId;
       } else {
         alert(x.responseJSON.Msg);
       }
     
   },
   onFailure: function(x) {
       alert('Ajax Failed');
   }
 });
}

function Message(nUserId, nReplyId) {
 DivIframe('/iframe.php?action=SendMessage&nUserId=' + nUserId + '&nReplyId=' + nReplyId, 400, 400);
}

function SlideToggle(sDiv) {
Effect.toggle(sDiv, 'slide', { delay: 0.5 });
}

function EventCounter() {
 new Ajax.Request('/ajax.php?action=EventCounter', {
   method: 'post',
   onSuccess: function(x) {
     bel = Builder.node('div', {id:'userboxin'}, '');
     x.responseJSON.aCounts.each( function(s) { 
       if (s.href=='') {
         var el = Builder.node('div', {  }, s.txt );
       } else {
         var el = Builder.node('div', {  }, Builder.node('a', { href: s.href }, s.txt) );
       }
       bel.appendChild(el);
     } );
     $('userboxin').replace(bel);
   },
   onFailure: function(x) {
//       alert('Ajax Failed');
   }
 });
}

window.onload = function() { EventCounter(); }
window.setInterval('EventCounter()', 15000);