//select search type
function set_active_search(item){
    if(item != 'Items'){
        $('search_items').style.display='none';
    }else{
        $('search_items').style.display='block';    
    }
    if(item != 'Services'){
        $('search_services').style.display='none';
    }else{
        $('search_services').style.display='block';    
    }    
    
    if(item != 'Members'){
        $('search_members').style.display='none';
    }else{
        $('search_members').style.display='block';    
    }    
    
    if(item != 'TtCircles'){
        $('search_circles').style.display='none';
    }else{
        $('search_circles').style.display='block';    
    }
    return false;
}

function showLayer(id)
{
    $('showitem').setStyle({"visibility":"visible"});
    var result=new Ajax.Updater('showitem','/items/preview/'+id,
                {asynchronous:true, evalScripts:true});        
    return true;
}
        
function hideLayer()
{
    $('showitem').setStyle({"visibility":"hidden"});
}

function showUserLayer(id)
{
    $('showitem').setStyle({"visibility":"visible"});
    var result=new Ajax.Updater('showitem','/member/profile/preview/'+id,
                {asynchronous:true, evalScripts:true});        
    return true;
}
 
 
function showLayer_FloatV(ctlLayer,id)
{
    var IE = document.all?true:false;
    var offsets = new Position.cumulativeOffset($(ctlLayer));
    var result=new Ajax.Updater('showitem','/items/preview/'+id,
        {asynchronous:true, evalScripts:true});
    $('showitem').setStyle({"visibility":"visible"});
    $('showitem').setStyle({"top":offsets[1] + "px"});
    if (IE) {
        $('showitem').setStyle({"position":"absolute"});    
    }
    else {
        $('showitem').setStyle({"position":"fixed"});
    }

    return true;
}

var OnlineListTimerID = 0;
var OnlineListInterval = 120000;

function refreshOnlineList()
{
    if ($('moreonline'))
    {
        bShow = $('moreonline').getStyle('display');
   
        if (bShow == 'none')
        {
            res = new Ajax.Updater('onlinelist', '/mediaflow/tthome/getonlinelist', {asynchronous:true, evalScripts:true}); 
        }
        else
        {
            res = new Ajax.Updater('onlinelist', '/mediaflow/tthome/getonlinelist/1', {asynchronous:true, evalScripts:true});     
        }
    }
    else
    {
        res = new Ajax.Updater('onlinelist', '/mediaflow/tthome/getonlinelist', {asynchronous:true, evalScripts:true}); 
    }
    OnlineListTimerID = setTimeout("refreshOnlineList()", OnlineListInterval);
    return true;
}

function startOnlineList()
{
    if (OnlineListTimerID == 0)
    {
        res = new Ajax.Updater('onlinelist', '/mediaflow/tthome/getonlinelist', {asynchronous:true, evalScripts:true}); 
        OnlineListTimerID  = setTimeout("refreshOnlineList()", OnlineListInterval);
    }
    Element.toggle('onlinelist');
}

function stopOnlineList()
{
   if(OnlineListTimerID) {
      clearTimeout(OnlineListTimerID);
      OnlineListTimerID  = 0;
   }
    Element.toggle('onlinelist');      
}

var msgID_del='';

function deleteMultiMsg()
{
    if (msgID_del=='')
    {
        alert('No messages selected!');
        return false;
    }
    
    if (confirm('Are you sure you want to delete the selected message thread?')) 
    { 
        IDArr=msgID_del.split(";");

        for (i=0;i<IDArr.length-1;i++)
        {
        
        id=IDArr[i].substring(6,IDArr[i].length);
        new Ajax.Request('/myaccount/mymessages/delete_message_thread/'+id, 
            {asynchronous:true,
             evalScripts:true} 
            );
        Element.hide('msg'+id);
        };
        msgID_del='';
     };
    return false;    
}

function clickMsg(checkbox,type)
{
        if ($(checkbox).getValue()=='on')
        {
            msgID_del=msgID_del+checkbox+";";
        }
        else
        {
            msgID_del=removeMsgID(msgID_del,checkbox+";")        
        }
}

function removeMsgID(IDStr,key)
{
    if (IDStr==key) return '';
    
    i=IDStr.indexOf(key);
    if (i>=0)
    {
        j=IDStr.indexOf(";",i);
        substr1=IDStr.substring(0,i);
        substr2=IDStr.substring(j+1,IDStr.length);
        return substr1+substr2;
    }
    else
    {
        return IDStr;
    }
}

var msgID_Pub_del='';

function deleteMultiPubMsg()
{
    if (msgID_Pub_del=='')
    {
        alert('No messages selected!');
        return false;
    }
    
    if (confirm('Are you sure you want to delete selected message?')) 
    { 
        IDArr=msgID_Pub_del.split(";");

        for (i=0;i<IDArr.length-1;i++)
        {
        
        id=IDArr[i].substring(9,IDArr[i].length);
        new Ajax.Request('/member/profile/delete_public_msg/'+id, 
            {asynchronous:true,
             evalScripts:true} 
            );
        Element.hide('publicmsg'+id);
        };
        msgID_Pub_del='';
     };
    return false;    
}

function clickPubMsg(checkbox,type)
{
        if ($(checkbox).getValue()=='on')
        {
            msgID_Pub_del=msgID_Pub_del+checkbox+";";
        }
        else
        {
            msgID_Pub_del=removePubMsgID(msgID_Pub_del,checkbox+";")        
        }
}

function removePubMsgID(IDStr,key)
{
    if (IDStr==key) return '';
    
    i=IDStr.indexOf(key);
    if (i>=0)
    {
        j=IDStr.indexOf(";",i);
        substr1=IDStr.substring(0,i);
        substr2=IDStr.substring(j+1,IDStr.length);
        return substr1+substr2;
    }
    else
    {
        return IDStr;
    }
}


function refreshPublicMessage(id)
{
    new Ajax.Updater('public_message_list', '/member/profile/show_public_msg_list/'+id, {asynchronous:true, evalScripts:true}); 
}

