<!--
// vim: set expandtab tabstop=4 shiftwidth=4 fdm=marker:
// +----------------------------------------------------------------------+
// | Tencent PHP Framework                                                |
// +----------------------------------------------------------------------+
// | Copyright(c)2008 Tencent Inc. All Rights Reserved.                   |
// +----------------------------------------------------------------------+
// | Authors: Club Dev Team, ISRD, Tencent Inc.                           |
// |          Tim liu <timliu@tencent.com>                            |
// +----------------------------------------------------------------------+

try {
    document.domain = "qq.com";
    var URL_RING_DOC = "http://qqring.qq.com/qqling_v1/";
}
catch(x) {
}

/*
quick_login.js
*/
/// begin of quick_login.js
function ptlogin2_onResize(width,height){
if(login_wnd){
login_wnd.style.width=width+"px";login_wnd.style.height=height+"px";login_wnd.style.visibility="visible";show_at_center(width,height);}}
function ptlogin2_onClose(){
login_wnd=$O_1("_login_div_quick_");login_wnd.style.display="none";var temp=$O_1("_login_div_mask_quick_");if(temp){
temp.style.display="none";}}
function openLogin(type,jump_url,mask,x,y){
login_wnd=$O_1("_login_div_quick_");if(!jump_url)jump_url='';if(!$O_1("_login_div_quick_")){
var newDiv=document.createElement("div");newDiv.id="_login_div_quick_";newDiv.style.position="absolute";newDiv.style.zIndex="100";newDiv.style.width="380px";newDiv.style.height="310px";newDiv.style.top="220px";newDiv.style.left="50%"
newDiv.style.visibility="hidden";newDiv.innerHTML='<iframe name="_login_frame_quick_" id="_login_frame_quick_" frameborder="no" scrolling="no" width="100%" height="100%" src=""></iframe>';document.getElementsByTagName("body")[0].appendChild(newDiv);login_wnd=newDiv;}
login_wnd.style.display="block";if(ptui_getActivXVer()<3.9||!ptui_checkQQRunning()){
url="http://ui.ptlogin2.qq.com/cgi-bin/login?link_target=blank&target=self&appid=8000201&f_url=loginerroralert&s_url=";url+=escape("http://imgcache.qq.com/club/portal_new/redirect.html?jump_url="+jump_url);}
else{
switch(type){
case 2:{
url="http://ui.ptlogin2.qq.com/cgi-bin/login?link_target=blank&target=self&appid=8000201&qlogin_jumpname=vipcomm&f_url=loginerroralert&qlogin_auto_login=0"
url+="&s_url="+escape("http://imgcache.qq.com/club/portal_new/redirect.html");url+="&qlogin_param="+escape("jump_url="+escape(jump_url||location.href));}
break;case 3:{
url="http://ui.ptlogin2.qq.com/cgi-bin/login?link_target=blank&target=self&appid=8000201&qlogin_jumpname=vipcomm&f_url=loginerroralert&qlogin_auto_login=1"
url+="&s_url="+escape("http://imgcache.qq.com/club/portal_new/redirect.html");url+="&qlogin_param="+escape("jump_url="+escape(jump_url||location.href));}
break;default:{
url="http://ui.ptlogin2.qq.com/cgi-bin/login?link_target=blank&target=self&appid=8000201&f_url=loginerroralert&s_url=";url+=escape("http://imgcache.qq.com/club/portal_new/redirect.html?jump_url="+jump_url||'');}
break;}}
$O_1("_login_frame_quick_").src=url;if(mask)_quick_login_mask_div=true;if(x)_quick_login_form_x=x;if(y)_quick_login_form_y=y;}
function login_success(){window.location.reload();}
function show_at_center(div_width,div_height){
try{
login_wnd.style.top=(window.innerHeight / 2+pageYOffset)-div_height/2+"px";login_wnd.style.left=(window.innerWidth  / 2+pageXOffset)-div_width/2+"px";}
catch(e){
if(!document.body.scrollTop){
login_wnd.style.top=(document.documentElement.offsetHeight / 2+document.documentElement.scrollTop)-div_height/2+"px";login_wnd.style.left=(document.documentElement.offsetWidth  /2+document.documentElement.scrollLeft)-div_width/2+"px";}
else{
login_wnd.style.top=(document.documentElement.offsetHeight / 2+document.body.scrollTop)-div_height/2+"px";login_wnd.style.left=(document.documentElement.offsetWidth  /2+document.body.scrollLeft)-div_width/2+"px";}}
if(_quick_login_mask_div){
var temp=$O_1("_login_div_mask_quick_");if(!temp){
var newDiv=document.createElement("div");newDiv.id="_login_div_mask_quick_";newDiv.style.position="absolute";newDiv.style.background="#ffffff";newDiv.style.opacity="0.5";newDiv.style.filter="alpha(opacity=50)";newDiv.style.zIndex="99";newDiv.style.width=document.body.scrollWidth+"px";newDiv.style.height=document.body.scrollHeight+"px";newDiv.style.top="0px";newDiv.style.left="0px";document.getElementsByTagName("body")[0].appendChild(newDiv);}
else{
temp.style.display="block";}
_quick_login_mask_div=false;}
if(_quick_login_form_x){login_wnd.style.left=_quick_login_form_x+'px';_quick_login_form_x=false;};if(_quick_login_form_y){login_wnd.style.top=_quick_login_form_y+'px';_quick_login_form_y=false;}}
function ptui_getActivXVer(){
try{
var obj=new ActiveXObject("TimwpDll.TimwpCheck");var ver=obj.GetVersion();return ver;}
catch(e){
return 0;}}
function ptui_checkQQRunning(){
try{
var obj=new ActiveXObject("TimwpDll.TimwpCheck");return obj.CheckQQRunning();}
catch(e){
return false;}}
function $O_1(i){return document.getElementById(i);}
/// end of quick_login.js

function tweb_set_cookie()
{
    var argv = tweb_set_cookie.arguments;
    var argc = argv.length;
    if ( argc < 2 ) {
        return false;
    }

    var name  = argv[0];
    var value = argv[1];
    if ( argv[2] ) { var expires = argv[2]; }
    if ( argv[3] ) { var path    = argv[3]; }
    if ( argv[4] ) { var domain  = argv[4]; }
    if ( argv[5] ) { var secure  = argv[5]; }

    var today   = new Date();
    var expdate = new Date( today.getTime() + ( expires * 60 * 60 * 1000 ) );

    document.cookie = name + "=" + escape( value )
    + ( expires ? ";expires=" + expdate.toGMTString() : "" )
    + ( path    ? ";path=" + path : "" )
    + ( domain  ? ";domain=" + domain : "" )
    + ( secure  ? ";secure" : "" );

    return true;
}
function tweb_get_cookie()
{
    var argv = tweb_get_cookie.arguments;
    var argc = argv.length;
    if ( argc < 1 ) {
        return false;
    }

    var name = argv[0];
    var beg = document.cookie.indexOf( "; " + name + "=" );
    if ( beg == -1 ) {
        beg = document.cookie.indexOf( name + "=" );
        if ( beg == -1 ) {
            return null;
        } else {
            beg = beg + name.length + 1;
        }
    } else {
        beg = beg + name.length + 3;
    }

    var end = document.cookie.indexOf( ";", beg );
    if ( end == -1 ) {
        end = document.cookie.length;
    }

    var value = document.cookie.substring( beg, end );
    value = unescape( value );
    return value;
}
function tweb_delete_cookie()
{
    var argv = tweb_delete_cookie.arguments;
    var argc = argv.length;
    if ( argc < 1 ) {
        return false;
    }

    var name   = argv[0];
    if ( argv[1] ) { var path   = argv[1]; }
    if ( argv[2] ) { var domain = argv[2]; }

    var cookie = tweb_get_cookie( name );
    if ( cookie != null ) {
        document.cookie = name + "="
        + ";expires=Thu, 01 Jan 1970 00:00:01 GMT"
        + ( path    ? ";path=" + path : "" )
        + ( domain  ? ";domain=" + domain : "" );
    }

    return cookie;
}

//导航使用
function $O(i){return document.getElementById(i);};
var $show   = function (e) {try{$O(e).style.display="";} catch(e) {} };
var $hide   = function (e) {try{$O(e).style.display="none";} catch(e) {} };
var v = 0;
function show_more_div()
{
    if(v != 0){
        window.clearTimeout(v);
    }
    try{$show('more_div');}catch(e){}
};
function hide_more_div()
{
    try{v = setTimeout('$hide(\'more_div\')',300);}catch(e){}
};

// vip portal
function vip_goto( url , flag)
{
    var url_flag = "";
    flag==0 ? url_flag="_self" : url_flag="_blank";
    var uin  = tweb_get_cookie("uin");
    var skey = tweb_get_cookie("skey");
    if(uin!=null && uin!="" && skey!=null && skey!="")
    {
        var uri = 'http://clubclient.qq.com/set_cookie.php?uin=' + escape(uin) + '&skey=' + escape(skey) + '&url=' + escape
(url);
        window.open(uri , url_flag);
        return;
    }
    var clientuin  = tweb_get_cookie("clientuin");
    var clientkey = tweb_get_cookie("clientkey");
    if(clientuin!=null && clientuin!="" && clientkey!=null && clientkey!="")
    {
        var uri = 'http://clubclient.qq.com/clubclient_goto.php?clientuin='+escape(clientuin)+'&clientkey='+escape(clientkey)
+'&gotourl='+escape(url);
        window.open(uri , url_flag);
        return;
    }
    window.open(url, url_flag);
};

function hide_header()
{
    try {        
        var page_width = document.body.clientWidth;
        var head = document.getElementById("header");
        if(page_width < 620) { //619 629
            head.style.display = "none";
        } else {
            head.style.display = "block";
        }
    }
    catch(x) {
    }
}

/*
old login -- not use
*/
/// begin 
function client_login( auto )
{
    var clientuin = get_cookie("clientuin");
    var clientkey = get_cookie("clientkey");
    if ( clientuin == null || clientuin == "" ) {
        clientuin = get_cookie("zzpaneluin");
        clientkey = get_cookie("zzpanelkey");
    }
    
    if ( clientuin == null || clientuin == "" || clientkey == null || clientkey == "" ) {
        if ( !auto ) {            
            show_login_form();
            }
        return false;
    }
    
    var goto_url = "http://imgcache.qq.com/club/item/qqring/static_ling/ling_index.html";

    var url = "http://ptlogin2.qq.com/clubclient?clientuin=" + urlencode(clientuin) + "&clientkey=" + urlencode(clientkey)+ "&gotourl=" + urlencode(goto_url);
    
    var frame = document.createElement("iframe");
    frame.setAttribute( "width",       0 );
    frame.setAttribute( "height",      0 );
    frame.setAttribute( "scrolling",   "no" );
    frame.setAttribute( "border",      0 );
    frame.setAttribute( "frameborder", 0 );
    frame.setAttribute( "src",         url );
    document.body.appendChild(frame);
    
    delete_cookie("clientuin");
    delete_cookie("clientkey");
    delete_cookie("zzpaneluin");
    delete_cookie("zzpanelkey");
    
    return true;
}

function load_login_div()
{
	if ( typeof($obj("div_login")) != "undefined" && $obj("div_login") != null ) {
		var url = "http://imgcache.qq.com/qqring/login.html?url="+urlencode(window.location.href);
		var div_login = $obj("div_login");
		div_login.innerHTML = '<a class="close" onclick="javascript:try{hide_login_form();}catch(x){}"></a>'
						  + '<iframe id="ptlogin2frame" width="400" height="285" scrolling="no" border="0" frameborder="0" marginwidth="0" marginheight="0" src="' + url + '"></iframe>';
		div_login.style.display = "none";
		return;
	}
           
	var div_bg = document.body.appendChild( document.createElement("DIV") );
	div_bg.setAttribute( "id", "div_bg" );
	div_bg.className = "div_bg";
	div_bg.style.display = "none";

	var url = "http://imgcache.qq.com/qqring/login.html?url="+urlencode(window.location.href);
	var div_login = document.body.appendChild( document.createElement("DIV") );
	div_login.setAttribute( "id", "div_login" );
	div_login.className = "div_login";
	div_login.innerHTML = '<a class="close" onclick="javascript:try{hide_login_form();}catch(x){}"></a>'
						  + '<iframe id="ptlogin2frame" width="400" height="285" scrolling="no" border="0" frameborder="0" marginwidth="0" marginheight="0" src="' + url + '"></iframe>';
	div_login.style.display = "none";
}

function hide_login_form()
{
	if ( typeof($obj("div_bg")) == "undefined"
			|| $obj("div_bg") == null
			|| typeof($obj("div_login")) == "undefined"
			|| $obj("div_login") == null ) {
		return false;
	}
	$obj("div_bg").style.display = "none";
	$obj("div_login").style.display = "none";	
}

function user_login(flag)
{
    load_login_div();
    hide_login_form();
    return client_login(flag);
}

function show_login_form()
{
    $obj("div_bg").style.display = "";
    $obj("div_login").style.display = "";
}
///end of old login

//----------------  common functions ------------------------//
/* {{{ function urlencode( s ) */
function urlencode( s )
{
    if ( typeof(encodeURIComponent) != "undefined" ) {
        return encodeURIComponent( s );
    }
    return s;
}
/* }}} */

/* {{{ function urldecode( s ) */
function urldecode( s )
{
    if ( typeof(decodeURIComponent) != "undefined" ) {
        return decodeURIComponent( s );
    }
    return s;
}
/* }}} */

function $obj( name )
{
    return document.getElementById( name );
}

function set_text( obj, text )
{
	if ( typeof(obj) == "undefined" || obj == null ) {
		return false;
	}
	if ( typeof(obj.innerText) != "undefined" ) {
		obj.innerText = text;
		return true;
	}
	else if ( typeof(obj.textContent) != "undefined" ) {
		obj.textContent = text;
		return true;
	}
	return false;
}

/* {{{ function str_printf( fmt, ... ) */
function str_printf()
{
    var argv = str_printf.arguments;
    var argc = argv.length;
    if ( argc < 1 ) {
        return "";
    }
    var format = argv[0];

    var _get_value = function ( value, type ) {
        var specifier = type.substring( type.length-1, type.length );
        switch ( specifier ) {
            case "s":
                if ( typeof( value ) == "object" || typeof( value ) == "number" ) {
                    value = value.toString();
                }
                break;

            case "d":
                value = parseInt( value );
                if ( isNaN( value ) ) {
                    value = 0;
                }
                var format = type.substring( 1, type.length-1 );
                if ( format != "" ) {
                    if ( format.substring( 0, 1 ) == "0" ) {
                        var salt = "0";
                    } else {
                        var salt = " ";
                    } // if

                    // fill with zeros or spaces.
                    len = parseInt( format, 10 );
                    value = value.toString();
                    while ( value.length < len ) {
                        value = salt + value;
                    }
                }
                break;

            default:
                break;
        } // switch

        return value;
    }; // function _get_value

    var regex = /%([0-9\.]+)?[a-z%]/gi;
    var m = format.match( regex );

    if ( m == null ) {
        return format;
    }

    var m_length = m.length;
    for ( var i = 0, f = 1; i < m_length; i++ ) {
        if ( m[i] == "%%" ) {
            continue;
        }
        value = _get_value( argv[f++], m[i] );
        format = format.replace( new RegExp( m[i], "i" ), value );
    }
    if ( format.indexOf("%%") != -1 ) {
        format = format.replace( /%%/g, "%" );
    }

    return format;
}
/* }}} */

/* {{{ function str_trim() */
/**
 * Trim the space around the string
 *
 * @param   string  str     The input string.
 * @return  string  output  The trim result.
 */
function str_trim( str )
{
    if ( typeof(str) == "undefined" || str == null ) {
        return "";
    }
    if ( typeof(str) == "object" ) {
        str = str.toString();
    }

    var output = str.replace(/^\s+/, '');
    output = output.replace(/\s+$/, '');
    return output;
}
/* }}} */

/* {{{ cookie functions */
/* {{{ function get_cookie( name ) */
/**
 * Get Cookie
 *
 * @param   string  name  The name of cookie.
 * @return  string        The value of cookie.
 */
function get_cookie()
{
    var argv = get_cookie.arguments;
    var argc = argv.length;
    if ( argc < 1 ) {
        return false;
    }

    /// find begin index 
    var name = argv[0];
    var beg = document.cookie.indexOf( "; " + name + "=" );
    if ( beg == -1 ) {
        beg = document.cookie.indexOf( name + "=" );
        if ( beg == 0 ) {
            beg = beg + name.length + 1;
        }
        else {
            return null;
        }
    } else {
        beg = beg + name.length + 3;
    }///< if

    /// find end index
    var end = document.cookie.indexOf( ";", beg );
    if ( end == -1 ) {
        end = document.cookie.length;
    }

    /// get the value
    var value = document.cookie.substring( beg, end );
    value = urldecode( value );
    return value;
}
/* }}} */

/* {{{ function set_cookie( name, value, ... ) */
/**
 * Set Cookie
 *
 * @param   string   name      The name of cookie
 * @param   string   value     The value of cookie
 * @param   int      expires   The expired hours from now.
 * @param   string   path      The path which is allowd to access cookie.
 * @param   string   domain    The domain of the cookie.
 * @param   string   secure    Whether to send cookie in secure mode.
 */
function set_cookie()
{
    var argv = set_cookie.arguments;
    var argc = argv.length;
    if ( argc < 2 ) {
        return false;
    }

    var name  = argv[0];
    var value = argv[1];
    if ( argv[2] ) { var expires = argv[2]; }
    if ( argv[3] ) { var path    = argv[3]; }
    if ( argv[4] ) { var domain  = argv[4]; }
    if ( argv[5] ) { var secure  = argv[5]; }

    var today   = new Date();
    var expdate = new Date( today.getTime() + ( expires * 60 * 60 * 1000 ) );

    /// write data into cookie
    document.cookie = name + "=" + urlencode( value )
    + ( expires ? ";expires=" + expdate.toGMTString() : "" )
    + ( path    ? ";path=" + path : "" )
    + ( domain  ? ";domain=" + domain : "" )
    + ( secure  ? ";secure" : "" );

    return true;
}
/* }}} */

/* {{{ function delete_cookie( name, ... ) */
/**
 * Delete cookie
 *
 * @param  string   name    The name of cookie.
 * @param  string   path    Path of cookie, optional.
 * @param  string   domain  The domain of cookie, optional.
 * @return  string          The value of cookie which was deleted.
 */
function delete_cookie()
{
    var argv = delete_cookie.arguments;
    var argc = argv.length;
    if ( argc < 1 ) {
        return false;
    }

    var name   = argv[0];
    if ( argv[1] ) { var path   = argv[1]; }
    if ( argv[2] ) { var domain = argv[2]; }

    var cookie = get_cookie( name );
    if ( cookie != null ) {
        document.cookie = name + "="
        + ";expires=Thu, 01 Jan 1970 00:00:01 GMT"
        + ( path    ? ";path=" + path : "" )
        + ( domain  ? ";domain=" + domain : "" );
    }

    return cookie;
}
/* }}} */


/*** ------  铃音试听功能函数 所有页面一致 ------ */

var ring_player_path;                    //铃音试听url
var ring_player_name;                  //铃音试听name 
var ring_player_type;                    //铃音试听type 
var ring_history_len = 5;               //铃音试听记录个数
var ring_history_expire = 24;        //铃音试听记录保存时间
/* {{{ function MM_controlSound() */
/**
 * MM_controlSound 
 *
 * @param  string   sndObj     The name of WMPObject
 * @param  string   url             Path of ring url
 * @param  string   name        ring name
 * @return  string    type          ring type
 */
function MM_controlSound(sndObj,url,name,type)
{
    if(url == undefined) return;
    var wmp = document.getElementById(sndObj);
       
    //object 兼容代码
    if(wmp.playState == 3) {
        wmp.controls.stop();
    } else {
        wmp.controls.play();
    }
    
    // embed 兼容代码
/*    if(navigator.appName=='Netscape') {
//        var ctrlBtn = document.getElementById("player_ctrl_btn");
        if(wmp == null) {
            qqring_preview(url,name,type);
//            ctrlBtn.className = "stop";
        }
        else {
            wmp.parentNode.removeChild(wmp);
//            ctrlBtn.className = "";
        }
    } else {        
        if(wmp.playState == 3) {
            wmp.controls.stop();
        } else {
            wmp.controls.play();
        }
    }*/           
}
/* }}} */

/* {{{ function qqring_preview() */
/**
 * qqring_preview 
 *
 * @param  string   url             Path of ring url
 * @param  string   name        ring name
 * @return  string    type          ring type
 * @return  string    source      from ring_list or play_history list
 */
function qqring_preview(url,name,type,source)
{
    var sndObj;
    if(navigator.appName=='Netscape') {
        sndObj = '<object id="QQRingPlayer" type="application/x-ms-wmp" width="0" height="0"><param name="URL" value="' + url + '" /><param name="autoStart" value="true"><param name="playCount" value="1"></object>'; //依赖插件 有和IE下同样功能
//        sndObj = '<embed type="application/x-mplayer2" src="' + url + '" name="QQRingPlayer" id="QQRingPlayer" width="0" height="0" autostart="1" showcontrols="0"></embed>'; //不依赖插件,无IE下同样功能
    } else {
        sndObj = '<object id="QQRingPlayer" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112" standby="Loading Microsoft Windows? Media Player components..." type="application/x-oleobject" width="0" height="0"><param name="URL" value="' + url + '" /><param name="autoStart" value="true"><param name="playCount" value="1"></object>';
    }
    sndObj += '<script language="JavaScript" type="text/JavaScript" event="PlayStateChange(state)" for="QQRingPlayer">change_playbtn();</script>';
    
    document.getElementById("mpdiv").innerHTML = sndObj;
    document.getElementById("player_ctrl_btn").className = "stop";    
    document.getElementById("mar_name").innerHTML = name;
    
    ring_player_path = url;
    ring_player_name = name;
    ring_player_type = type;
    
    if(arguments.length < 4) {
         write_play_history();
        show_play_history();
    }
    
    // PV
    var url = "http://qqring.qq.com/qqling_v1/pv_log.php";
    var img = new Image(0, 0);
    img.src = url + "?ask=player";
}
/* }}} */

/* {{{ function change_playbtn() */
/**
 * change_playbtn class
 */
function index_click_pv(type)
{
    // PV
    var url = "http://qqring.qq.com/qqling_v1/pv_log.php";
    var img = new Image(0, 0);
    img.src = url + "?ask=index_click_pv&type=" + type;
}
/* }}} */

/* {{{ function change_playbtn() */
/**
 * change_playbtn class
 */
function change_playbtn()
{
    var wmp = document.getElementById("QQRingPlayer");
    var ctrlBtn = document.getElementById("player_ctrl_btn");
    if(wmp.playState == 3) {
        ctrlBtn.className = "stop";
    } else if(wmp.playState == 1) {
        ctrlBtn.className = "";
    }
}
/* }}} */

/* {{{ function OnDSPlayStateChangeEvt() */
/**
 * OnDSPlayStateChangeEvt for FireFox
 * @param  string   NewState  playstate
 */
function OnDSPlayStateChangeEvt(NewState)
{// FF等事件代码
      change_playbtn();
}
/* }}} */

/* {{{ function read_play_history() */
/**
 * read_play_history
 */
function read_play_history()
{
    var history = new Array(ring_history_len);
    for(i = 0; i < ring_history_len; i++)
    {
        history[i] = new Array(3);
        history[i][0] = get_cookie("qqring_play_history_name_" + i);
        history[i][1] = get_cookie("qqring_play_history_type_" + i);
        history[i][2] = get_cookie("qqring_play_history_url_" + i);
    }
    return history;
}
/* }}} */

/* {{{ function read_play_history() */
/**
 * read_play_history
 */
function write_play_history()
{
    var history = read_play_history();
    
    // 单向队列
    for(i = ring_history_len - 1; i > 0; i--)
    {        
        set_cookie("qqring_play_history_name_" + i, history[i -1][0], ring_history_expire);
        set_cookie("qqring_play_history_type_" + i, history[i -1][1], ring_history_expire);
        set_cookie("qqring_play_history_url_" + i, history[i -1][2], ring_history_expire);                  
    }
    
    set_cookie("qqring_play_history_name_" + 0, ring_player_name, ring_history_expire);
    set_cookie("qqring_play_history_type_" + 0, ring_player_type, ring_history_expire);
    set_cookie("qqring_play_history_url_" + 0, ring_player_path, ring_history_expire);
}
/* }}} */

/* {{{ function read_play_history() */
/**
 * read_play_history
 */
function show_play_history()
{
    var history = read_play_history();
    var ulObj = document.getElementById("play_history_ul");
    ulObj.innerHTML = "";    
    
    if(history[0][0] == null || history[0][0] == undefined || history[0][0] == "") {
            var oNewNode = document.createElement("LI");
            oNewNode.innerHTML = '<p class="s_list_name">没有试听记录</p>';
            ulObj.appendChild(oNewNode);
            return;
    }
    
    for(i = 0; i < ring_history_len; i++)
    {
        if(history[i][0] == null || history[i][0] == "null" || history[i][0] == "" || history[i][0] == undefined) {
            return;
        }
        
        var slice_name = history[i][0].slice(0,6);
        if(history[i][0].length > 6)
        {
            slice_name += "..";
        }

        var func = 'javascript:qqring_preview(\'' + history[i][2] + '\', \'' + history[i][0] + '\', \'' + history[i][1] + '\',0)';        
        var oNewNode = document.createElement("LI");
        oNewNode.innerHTML = '<p class="s_list_name"><a href="' + func + '">' + slice_name + '</a></p><p class="s_list_type">' + history[i][1] + '</p>';
        ulObj.appendChild(oNewNode);
    }
}
/* }}} */

/* {{{ function tweb_page_list(this_page, total, length, url) */
function tweb_page_list()
{
    var argv = tweb_page_list.arguments;
    var argc = argv.length;
    if ( argc < 4 ) {
        return false;
    }

    var this_page   = argv[0];
    var total_pages = argv[1];
    var page_length = argv[2];
    var page_url    = argv[3];

    /// Get query string
    var uri = this.location.toString();
    var beg = uri.indexOf( "?" );
    var end = uri.length;
    var qstr = "";
    if ( beg != -1 ) {
        qstr = uri.substring( beg + 1, end );
	}
	qstr = qstr.replace(/page=\d+&?/, '');

    if ( this_page < 1 ) {
        this_page = 1;
    }
    if ( total_pages < 1 ) {
        total_pages = 1;
    }
    if ( this_page > total_pages ) {
        this_page = total_pages;
    }
    var prev_page = this_page - 1;
    if ( prev_page < 1 ) {
        prev_page = 1;
    }
    var next_page = this_page + 1;
    if ( next_page > total_pages ) {
        next_page = total_pages;
    }

    if ( this_page < page_length ) {
        var beg = 1;
        var end = beg + page_length - 1;
    } else {
		if ( this_page % page_length == 0 ) {
			var beg = this_page - this_page % page_length;
			var end = beg + page_length - 1;
		}
		else {
			var beg = this_page - this_page % page_length + 1;
			var end = beg + page_length - 1;
		}
    }
    if ( end > total_pages ) {
        end = total_pages;
    }

    var page_list = "";
    var separator = "&nbsp; ";
    if ( this_page >= page_length ) {
        var prev_url = _str_sprintf( page_url, prev_page );
		if ( qstr != "" ) {
			prev_url = prev_url + "&" + qstr;
		}
        page_list += '<a href="' + prev_url + '">上一页</a>' + separator;
    }
    for ( var i=beg; i<=end; i++ ) {
        if ( i == this_page ) {
            page_list += '<span style="color:#FF0000;font-weight:bold">' + i + '</span>';
        } else {
            var this_url = _str_sprintf( page_url, i );
			if ( qstr != "" ) {
				this_url = this_url + "&" + qstr;
			}
            page_list += '<a href="' + this_url + '">' + i + '</a>';
        }///< if

        if ( i != end ) {
            page_list += separator;
        }
    }///< if
    if ( this_page != total_pages ) {
        var next_url = _str_sprintf( page_url, next_page );
		if ( qstr != "" ) {
			next_url = next_url + "&" + qstr;
		}
        page_list += separator + '<a href="' + next_url + '">下一页</a>';
    }
    document.write( page_list );
}
/* }}} */


/* {{{ function tweb_page_go(page, total, url) */
function tweb_page_go()
{
    var argv = tweb_page_go.arguments;
    var argc = argv.length;
    if ( argc < 3 ) {
        return false;
    }

    var page  = argv[0];
    var total = argv[1];
    var url   = argv[2];

    var re = /[1-9][0-9]*/;
    if ( re.test(page) == false || page > total ) {
        window.alert('请输入正确的页码(共'+total+'页)!');
        return false;
    }

	/// Get query string
	var uri = window.location.toString();
    var beg = uri.indexOf( "?" );
    var end = uri.length;
	var qstr = "";
    if ( beg != -1 ) {
        qstr = uri.substring( beg + 1, end );
	}
	qstr = qstr.replace(/page=\d+&?/, '');

    var url = _str_sprintf( url, page );
	if ( qstr != "" ) {
		url = url + "&" + qstr;
	}
    window.location.href = url;
}
/* }}} */


/* {{{ function tweb_page_enter(obj, event, total, url) */
function tweb_page_enter(){
	try {
		var argv = tweb_page_enter.arguments;
		var argc = argv.length;
		if ( argc < 4 ) {
			return false;
		}

		var page_obj = argv[0];
		var js_event = argv[1];
		var total    = argv[2];
		var url      = argv[3];
		var keycode  = null;

		if ( typeof(window.event) != "undefined" ) {
			var keycode = window.event.keyCode;
		}
		else if ( typeof(js_event) != "undefined" ) {
			var keycode = js_event.which;
		}

		if ( keycode == null ) {
			return;
		}
		if ( keycode == 13 ) {   // Click On Enter
			tweb_page_go(page_obj.value, total, url);
		}
	}
	catch (x) {
		//window.alert( x.message );
	}
}
/* }}} */



/* {{{ function _str_sprintf( format, arg, arg, ... ) */
function _str_sprintf()
{
    var argv = _str_sprintf.arguments;
    var argc = argv.length;
    if ( argc < 1 ) {
        return "";
    }
    var format = argv[0];
    var _get_round = function ( x, y) {  /// for %f
        return Math.round(x * Math.pow(10, y))/Math.pow(10, y);
    }

    var _get_value = function ( value, type ) {
        var specifier = type.substring( type.length-1, type.length );
        //tweb_debug_show_msg( " ---> " + specifier + "<br>" );
        switch ( specifier ) {
            case "s":
                if ( typeof( value ) == "object" || typeof( value ) == "number" ) {
                    value = value.toString();
                }
                break;

            case "d":
                value = parseInt( value );
                if ( isNaN( value ) ) {
                    value = 0;
                }
                var format = type.substring( 1, type.length-1 );
                if ( format != "" ) {
                    if ( format.substring( 0, 1 ) == "0" ) {
                        var salt = "0";
                    } else {
                        var salt = " ";
                    }///< if

                    /// fill with zeros or spaces.
                    len = parseInt( format, 10 );
                    value = value.toString();
                    while ( value.length < len ) {
                        value = salt + value;
                    }
                }
                break;

            case "f":
                value = parseFloat( value );
                if ( isNaN( value ) ) {
                    value = 0;
                }
                var format = type.substring( 1, type.length-1 );
                if ( format != "" ) {
                    var dot_index = format.indexOf( "." );
                    var format_strlen  = format.substring( 0, dot_index );
                    var format_decimal = format.substring( dot_index + 1, format.length );

                    if ( format_decimal != "" ) {
                        format_decimal = parseInt( format_decimal, 10 );
                        value = _get_round( value, format_decimal );
                    }


                    if ( format_strlen != "" ) {
                        if ( format_strlen.substring( 0, 1 ) == "0" ) {
                            var salt = "0";
                        } else {
                            var salt = " ";
                        }///< if
    
                        /// fill with zeros or spaces.
                        var len = parseInt( format_strlen, 10 );
                        value = value.toString();
                        while ( value.length < len ) {
                            value = salt + value;
                        }
                    }
                } else {
                    value = _get_round( value, 2 );
                }///< if
                break;

            default:
                break;
        }///< switch

        return value;
    }///< function _get_value

    var regex = /%([0-9\.]+)?[a-z%]/gi;
    var m = format.match( regex );

    if ( m == null ) {
        return format;
    }

    var m_length = m.length;
    for ( var i = 0, f = 1; i < m_length; i++ ) {
        if ( m[i] == "%%" ) {
            continue;
        }
        value = _get_value( argv[f++], m[i] );
        format = format.replace( new RegExp( m[i], "i" ), value );
    }
    if ( format.indexOf("%%") != -1 ) {
        format = format.replace( /%%/g, "%" );
    }

    return format;
}
/* }}} */

/* {{{ function page_goto_set() */
/**
 * page_goto_set for myset.php
 */
function page_goto_set(num,total)
{
    var page_div = document.getElementById("page_div");
    var pa ="";
    var pb ="";
    var p_html = "";

    if(num == 1) { //first page
        for(i=2; i <= total; i++)
        {
                pa += " | <a href='javascript:page_goto_set(" + i + "," + total + ");'>" + i + "</a>";
        }
        p_html = "<p class='p_splite'>上一页 <strong class='red'>1 </strong>" + pa + " | <a href='javascript:page_goto_set(2," + total + ");'>下一页</a></p>";
    } else if(num > 1 && num < total) { // page between 1~total
        for(i=1; i <= num -1; i++)
        {
                pa += " | <a href='javascript:page_goto_set(" + i + "," + total + ");'>" + i + "</a>";
        }
        p_html = "<p class='p_splite'><a href='javascript:page_goto_set(" + (num - 1) + "," + total + ");'>上一页</a>" + pa;
        p_html += " | <strong class='red'>" + num + "</strong>";
        for(i = num + 1; i <= total; i++)
        {
                pb += " | <a href='javascript:page_goto_set(" + i + "," + total + ");'>" + i + "</a>";
        }
        p_html += pb + " | <a href='javascript:page_goto_set(" + (num + 1) + "," + total + ");'>下一页</a></p>";
    } else if(num == total) { // page max
        for(i=1; i < total; i++)
        {
                pa += " | <a href='javascript:page_goto_set(" + i + "," + total + ");'>" + i + "</a>";
        }
        p_html = "<p class='p_splite'><a href='javascript:page_goto_set(" + (total-1) + "," + total + ");'>上一页</a>" + pa + " | <strong class='red'>" + total + "</strong> | 下一页</p>";
    }
    page_div.innerHTML = p_html;    //show page ist
    
    //    alert(page_div.innerHTML);
    // show friends list
    for(i=0; i < total ; i++)
    {
        var hide_ul = document.getElementById("ul_" + i);
        hide_ul.style.display = "none";
    }
    var show_ul = document.getElementById("ul_" + (num -1));
    show_ul.style.display = "block";
}
/* }}} */

/* {{{ function show_friend_detail() */
/**
 * show_friend_detail for myset.php
 */
var last_li = "";
var li_static = "";
function show_friend_detail(uin)
{
    try {
        // show detail table
        var table_div = document.getElementById("table_div");
        //var all_table_obj = table_div.all.tags("TABLE");
        var all_table_obj = table_div.getElementsByTagName("TABLE");
        var table_len = all_table_obj.length;
        //var li_objs = document.getElementById("ul_0").all.tags("li");
        var li_objs = document.getElementById("ul_0").getElementsByTagName("li");
        
        for(i = 0; i < table_len ; i++)
        {
            all_table_obj[i].style.display = "none";
        }
        
        if(uin == null || uin == "") {
            all_table_obj[0].style.display = "block";
            last_li = li_objs[0].id;
            li_static = li_objs[0].innerHTML;
            li_objs[0].innerHTML = "<strong class='red'>" + li_objs[0].innerText + "<strong>";
        } else {
            if(last_li != "" && li_static != "") {
                var ret_li = document.getElementById(last_li);
                ret_li.innerHTML = li_static;
            }

            var show_li = document.getElementById("li_" + uin);                      
            li_static = show_li.innerHTML;
            last_li = "li_" + uin; 
            show_li.innerHTML = "<strong class='red'>" + show_li.innerText + "<strong>";

            var show_table = document.getElementById("tb_" + uin);
            show_table.style.display = "block";             
        }
    }
    catch (x) {
        alert("没有此号码！");
    }    
}
/* }}} */

function search_ring()
{
    var sInput = document.getElementById("search");    
    var name = sInput.value;
    name = name.replace(/[ ]/g,"");  //trim
    if(name == "" || name == null)
    {        
        alert("温馨提示：请输入要搜索的铃音名称");       
        sInput.focus();
        return;
    }
    if(name.length >12) {
		alert("温馨提示：您输入的名称过长，请重新输入"); 
        sInput.focus();
        return;
	}
	
	name = name.slice(0,12);

    window.open(URL_RING_DOC + "search.php?cate=-1&ftype=-1&name=" + encodeURIComponent(name), "_self");
}

function select_all(flag)
{
    var inputObj = document.getElementsByTagName("INPUT");
    var inputLen = inputObj.length;

    for(i = 0; i < inputLen; i++) 
    {
        if(inputObj[i].type == "checkbox") 
        {
            if(flag)
            {
                inputObj[i].status = true;
            }
            else
            {
                inputObj[i].status = false;
            }            
        }
    }   
}

function del_all_collect()
{
    var inputObj = document.getElementsByTagName("INPUT");
    var inputLen = inputObj.length;
    var cbObj = new Array();
    j=0;
    for(i = 0; i < inputLen; i++) 
    {
        if(inputObj[i].type == "checkbox") 
        {
            if(inputObj[i].status == true && inputObj[i].id != "select_all")
            {
                cbObj[j++] = inputObj[i].value;
            }       
        }
    }  
        
    var ids = cbObj.toString();
    var con = window.confirm("确认要删除这些收藏吗？");
    if(con)
    {
        window.open("http://qqring.qq.com/qqling_v1/ling_collect_cmd.php?cmd=del_collect&ids=" + ids,"_self");
    }
    else
    {
        return;
    }
//    alert(ids);
}
//-->
/*  |xGv00|31db093fd6f08d7c1feceb4efaf2f461 */