/* Copyright by Huang Guan (2008-8-29) *
* Email: gdxxhg AT gmail.com
* 2008-12-14 15:24:05 Updated
*/
var activeMenu = 'autobio';
var isAdmin = 0;
bindClick( 'goback', function(){
reloadContent();
} );
bindClick( 'closewindow', function(){
window.close();
} );
function loadMenu(editing)
{
makeRequest( 'apps.php?item=menu_list', 'GET', null, function(xhr){
$('SideBar').innerHTML = xhr.responseText;
if( $('menu-admin').parentNode.parentNode.firstChild.firstChild==null || editing ){
pushMenu( 'admin' );
}else{
pushMenu( $('menu-admin').parentNode.parentNode.firstChild.firstChild.id.split('-')[1] );
}
});
}
bindClick( "menu", pushMenu );
function pushMenu(s){
var m = $('menu-' + s );
var p = m.parentNode.parentNode.firstChild;
for(; p!=null; p=p.nextSibling ){
if( p.lastChild )
p.lastChild.className = "SideMenuLink";
}
if(m)
m.className = "SideMenuLinkActive";
page = 0;
switch(s){
case 'server':
showFront();
break;
case 'contact':
showLeave();
break;
case 'recent':
setContentUrl( 'apps.php?item=comment_list&topic_id=-1' );
break;
case 'admin':
setContentUrl( 'apps.php?item=login' );
break;
default:
setContentUrl( 'apps.php?item=topic_list&type_id='+s);
}
activeMenu = s;
}
bindClick( 'submit_comment', function(id){
var url, data, content, temp;
content = $('m_content').value;
url = 'apps.php?item=comment_post';
if( $('m_name').value == '' && $('m_mail').value == '' ){
$('m_error').innerHTML = ('Please input the guest name or your Email address.');
return false;
}
if( content.length < 3 ){
$('m_error').innerHTML = ('Please say something more.');
return false;
}
$('submit_comment-'+id).innerHTML= '';
data = 'topic_id=' + id +
'&name=' + encodeURIComponent($('m_name').value) +
'&content=' + encodeURIComponent(content) + '&mail=' + encodeURIComponent($('m_mail').value);
temp = $('submit_comment-'+id).innerHTML;
makeRequest( url, 'POST', data, function(xhr){
var s = xhr.responseText;
$('submit_comment-'+id).innerHTML = temp;
if( s!= '0' ){
showError(s);
}else{
//reload the page.
reloadContent();
}
$('submit_comment-' + id).style.visibility = 'hidden';
} );
} );
function setContent( s )
{
$('Content').innerHTML = s;
}
var contentUrl = '';
var page = 0;
function setContentUrl( url )
{
contentUrl = url;
reloadContent();
}
function reloadContent()
{
makeRequest( contentUrl+'&page='+page, 'GET', null, function(xhr){
setContent( xhr.responseText );
});
}
function showFront()
{
var buf;
buf = '
Server Information
' +
' (These website needs AJAX to run in perfect mode.)
';
setContent( buf );
makeRequest( '/admin/server_info.xiaoxia', 'GET', null, function(xhr){
buf += xhr.responseText;
setContent( buf );
} );
}
function showError( s )
{
var buf, line;
buf = ' Error
';
buf += 'Error: ' + s;
setContent( buf );
}
function showLeave()
{
var url = 'apps.php?item=comment_list&topic_id=0';
makeRequest( url, 'GET', null, function(xhr){
setContent( xhr.responseText );
contentUrl = url;
});
}
function getAbsoluteTop(e){
var offset=e.offsetTop;
if(e.offsetParent!=null) offset+=getAbsoluteTop(e.offsetParent);
return offset;
}
bindClick( 'setpage', function(id){
makeRequest( contentUrl + '&page=' + id, 'GET', null, function(xhr){
page = id;
reloadContent();
window.scrollTo( 0, getAbsoluteTop($('page_scroll_top'))-32 );
});
});
bindClick( 'login', function(){
makeRequest( 'apps.php?item=login', 'POST', 'password=' + $('password').value, function(xhr){
var s = xhr.responseText;
if( s != '0' ){
isAdmin = 0;
showError(s);
}else{
isAdmin = 1;
pushMenu('admin');
}
} );
} );
bindClick( 'logout', function(){
makeRequest( 'apps.php?item=logout', 'GET', null, function(xhr){
var s = xhr.responseText;
isAdmin = 0;
if( s != '0' ){
showError(s);
}else{
pushMenu('admin');
}
} );
} );
bindClick( 'backup', function(){
$('td_backup').innerText = 'Waiting';
makeRequest( 'apps.php?item=backup', 'GET', null, function(xhr){
var s = xhr.responseText;
$('td_backup').innerHTML = s;
} );
} );
bindClick( 'edit', function(id){
makeRequest( 'apps.php?item=topic_edit', 'POST', 'topic_id='+id, function(xhr){
setContent( xhr.responseText );
} );
} );
bindClick( 'newtopic', function(){
makeRequest( 'apps.php?item=topic_edit', 'POST', 'topic_id=0', function(xhr){
setContent( xhr.responseText );
} );
} );
bindClick( 'submit_edit', function(){
var url, data, content;
url = 'apps.php?item=topic_post'
if( $('m_content')!=null && $('m_content').value!=null ){
content = $('m_content').value;
}else{
content = window.frames[0].getData();
}
data = 'topic_id=' + $('m_id').value + '&type_id=' + $('m_belong').value +
'&name=' + ($('m_name').value) + '&title=' + encodeURIComponent($('m_title').value) +
'&content=' + encodeURIComponent(content) + '&ctime=' + $('m_dateTime').value +
'&access=' + $('m_clicks').value + '&comments=' + $('m_comments').value +
'&private=' + $('m_private').value;
makeRequest( url, 'POST', data, function(xhr){
var s = xhr.responseText;
if( s != '0' ){
showError(s);
}else{
setContent('Edit OK. ');
}
} );
} );
bindClick( 'deltopic', function(id){
var url, data;
url = 'apps.php?item=topic_delete';
if( confirm('Warning: Are you sure to delete "' + id + '"?' ) == false ){
return false;
}
makeRequest( url, 'POST', 'topic_id=' + id, function(xhr){
var s = xhr.responseText.split(':');
if( s!= '0' ){
showError(s);
}else{
setContent('Delete OK. ');
}
} );
} );
bindClick( 'delcomment', function(id){
var url, data;
url = 'apps.php?item=comment_delete';
if( confirm('Warning: Are you sure to delete "' + id + '"?' ) == false ){
return false;
}
makeRequest( url, 'POST', 'comment_id='+id, function(xhr){
var s = xhr.responseText;
if( s != '0' ){
showError(s);
}else {
reloadContent();
}
} );
} );
bindClick( 'lockcomment', function(id){
var url, data;
url = 'apps.php?item=comment_enable';
makeRequest( url, 'POST', 'comment_id='+id, function(xhr){
var s = xhr.responseText;
if( s != '0' ){
showError(s);
}else {
reloadContent();
}
} );
} );
bindClick( 'advance_edit', function(id){
var p = $('m_content').parentNode;
var s = $('m_content').value;
$('advance_edit').innerHTML=' ';
$('Main').content = s;
p.innerHTML = '';
} );
bindClick('edittype', function(id){
var type_name = $('type_name_'+id).innerText;
var type_order = $('type_order_' + id).innerText;
var type_style = $('type_style_' + id).innerText;
$('m_id').innerText = id;
$('m_typename').value = type_name;
$('m_typestyle').value = type_style;
$('m_typeorder').value = type_order;
});
bindClick('deltype', function(id){
var type_name = $('type_name_'+id).innerText;
if( confirm('您确定要删除类型'+type_name +'的所有信息吗?' ) == false ){
return false;
}
makeRequest( 'apps.php?item=type_delete', 'POST', 'type_id='+id, function(xhr){
if( xhr.responseText!='0' )
setContent(xhr.responseText);
else{
loadMenu(true);
}
} );
});
function doSaveType()
{
var data = 'type_id='+$('m_id').innerText +
'&type_name='+$('m_typename').value +
'&type_style='+$('m_typestyle').value +
'&type_order='+$('m_typeorder').value;
makeRequest( 'apps.php?item=type_edit', 'POST', data, function(xhr){
if( xhr.responseText!='0' )
setContent(xhr.responseText);
else{
loadMenu(true);
}
} );
}
bindClick( 'option_harmonize', function(id){
var text = $(id);
text.focus();
if (document.selection && document.selection.type == "Text") {
var range = document.selection.createRange();
var oldstr = range.text, newstr = '';
var code = String.fromCharCode(1161);
for(var i=0; i