//var ServerHost = "nefius.com/news";
var ServerHost = '127.0.0.1:8080/nefius.com/news';
var ServerBaseURL = "http://" + ServerHost + "/";

function nm_showStoryList(type,lang){
    var allbutton = document.getElementById('story_list_menu_1');
    var hotbutton = document.getElementById('story_list_menu_2');
    var popularbutton = document.getElementById('story_list_menu_3');
    //var followbutton = document.getElementById('pagelist_menuitem_follow');
    allbutton.className='';
    hotbutton.className='';
    popularbutton.className='';
    // followbutton.className='menu_item';

    var articleType = 'top';
    if (type=='1'){
        allbutton.className='story-list-menuitem-selected';
        nm_getStoryList(false,articleType,lang);
    //        var liElements = document.getElementById("ulTodayNewsList").getElementsByTagName('li');
    //        for(var i=0;i<liElements.length;i++){
    //            liElements[i].style.display = 'block';
    //        }
    } else
    if (type=='2'){
        hotbutton.className='story-list-menuitem-selected';
        nm_getStoryList(true,articleType,lang);
    //        var liElements2 = document.getElementById("ulTodayNewsList").getElementsByTagName('li');
    //        for(var i=0;i<liElements2.length;i++){
    //            if (liElements2[i].className.indexOf("new")>-1){
    //                liElements2[i].style.display = 'block';
    //            } else {
    //                liElements2[i].style.display = 'none';
    //            }
    //        }
    } else
    if (type=='3'){
        articleType = 'pop';
        popularbutton.className='story-list-menuitem-selected';
        nm_getStoryList(false,articleType,lang);
    //        followbutton.className='menu_item_selected';
    //        nm_getPageList(false,true);
    }else {
        alert('what?: '+type);
    }
    return;
}

function nm_selectBigStoryMenu(type,lang){
    var optionMy = document.getElementById('bsm-0');
    var optionAll = document.getElementById('bsm-1');
    var optionHot = document.getElementById('bsm-2');
    var optionPopular = document.getElementById('bsm-3');
    if (optionMy) {
        optionMy.className='story-list-menuitem-myselected_bg';
    }
    optionAll.className='';
    optionHot.className='';
    optionPopular.className='';
     
    var articleType = 'top';
    if (type==0){
        optionMy.className='story-list-menuitem-myselected';
        nm_getMyStories(lang);
    } else if (type==1){
        optionAll.className='story-list-menuitem-selected';
        nm_getStoryList(false,articleType,lang);
    } else if (type==2){
        optionHot.className='story-list-menuitem-selected';
        nm_getStoryList(true,articleType,lang);
    } else if (type==3){
        articleType = 'pop';
        optionPopular.className='story-list-menuitem-selected';
        nm_getStoryList(false,articleType,lang);
    }else if (type==4){
        articleType = 'hl';
        //optionPopular.className='story-list-menuitem-selected';
        nm_getHL(lang);
    }else {
        alert('what?: '+type);
    }
    return;
}

function nm_selectUserChoiceGroup(id){
    var userSelectionMenu = document.getElementById('user-selection-group-menu');
    for(var i in userSelectionMenu.childNodes){
        var node=userSelectionMenu.childNodes[i];
        if(node.id == 'ng-'+id){
            node.className='selected';
        } else {
            node.className='';
        }
    }

    var userSelectionList = document.getElementById('user-selection-group-list');
    for(var j in userSelectionList.childNodes){
        var nodeL = userSelectionList.childNodes[j];
        if (!nodeL)
            continue;
        
        var header = null;
        var children = nodeL.childNodes;

        for (var k=0; k < children.length; k++) {
            if (children[k].getAttribute('name')== "story-list-group-header") {
                header = children[k];
                break;
            }
        }
        if (id=='all'){
            nodeL.style.display='block';
            if(header)
                header.style.display = 'block';
        } else {
            if(nodeL.id == 'usgl-'+id){
                nodeL.style.display='block';
            } else {
                nodeL.style.display='none';               
            }
            if(header)
                header.style.display = 'none';
        }
    }
    
    return;
}

function nm_getHL(lang) {
    var info ='';
    switch (lang){
        case 'tr':
            info = 'Biz sayfayı oluştururken, lütfen bir kaç saniye bekleyiniz...';
            break;
        case 'en':
        default:
            info = 'Please wait while we are fetching page list...';
            break;
    }

    document.getElementById('page_list').innerHTML =
    '<div class="today_news_list_wait">'+info+'<br><br><span id="wait_span"></span> </div>';
    document.getElementById('wait_span').innerHTML = waitIcon();
    //addWait(document.getElementById('wait_span'),0);
    var xmlHttp = nm_CreateXmlHttpObject();
    var url = ServerBaseURL+'story_list.php?a=hl';

    xmlHttp.onreadystatechange=function(){
        if (xmlHttp.readyState==4)
        {
            var story_list_array= eval('('+xmlHttp.responseText+')');
            //var time= story_list_array.time;
            article_info_list = story_list_array.article_info_list;                       
            document.getElementById('page_list').innerHTML = story_list_array.story_list_html;           
            document.getElementById('top_time').innerHTML = story_list_array.time_html;
        }
    };
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}


function nm_getMyStories(lang) {
    var info ='';
    switch (lang){
        case 'tr':
            info = 'Biz sayfayı oluştururken, lütfen bir kaç saniye bekleyiniz...';
            break;
        case 'en':
        default:
            info = 'Please wait while we are fetching page list...';
            break;
    }

    document.getElementById('page_list').innerHTML =
    '<div class="today_news_list_wait">'+info+'<br><br><span id="wait_span"></span> </div>';
    document.getElementById('wait_span').innerHTML = waitIcon();
    //addWait(document.getElementById('wait_span'),0);
    var xmlHttp = nm_CreateXmlHttpObject();
    var url = ServerBaseURL+'story_list.php?a=m';

    xmlHttp.onreadystatechange=function(){
        if (xmlHttp.readyState==4)
        {
            var story_list_array= eval('('+xmlHttp.responseText+')');
            //var time= story_list_array.time;
            article_info_list = story_list_array.article_info_list;
            var myArticles = story_list_array.story_list_html;
            if (myArticles){
                document.getElementById('page_list').innerHTML = story_list_array.story_list_html;
            } else {
                var xmlHttp2 = nm_CreateXmlHttpObject();
                var url = ServerBaseURL+'izz_advice_content.php';
                xmlHttp2.onreadystatechange=function(){
                    if (xmlHttp2.readyState==4)
                    {
                        document.getElementById('page_list').innerHTML = xmlHttp2.responseText;
                    }
                };
                xmlHttp2.open("GET", url, true);
                xmlHttp2.send(null);
            }
            //document.title= story_list_array.time_title;
            document.getElementById('top_time').innerHTML = story_list_array.time_html;
        }
    };
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function showxPageList(type,lang){
    var allbutton = document.getElementById('pagelist_menuitem_top');
    var hotbutton = document.getElementById('pagelist_menuitem_hot');
    var popularbutton = document.getElementById('pagelist_menuitem_pop');
    //var followbutton = document.getElementById('pagelist_menuitem_follow');
    allbutton.className='menu_item';
    hotbutton.className='menu_item';
    popularbutton.className='menu_item';
    // followbutton.className='menu_item';

    var articleType = 'top';
    if (type=='1'){
        allbutton.className='menu_item_selected';
        nm_getPageList(false,articleType,lang);
    //        var liElements = document.getElementById("ulTodayNewsList").getElementsByTagName('li');
    //        for(var i=0;i<liElements.length;i++){
    //            liElements[i].style.display = 'block';
    //        }
    } else
    if (type=='2'){
        hotbutton.className='menu_item_selected';
        nm_getPageList(true,articleType,lang);
    //        var liElements2 = document.getElementById("ulTodayNewsList").getElementsByTagName('li');
    //        for(var i=0;i<liElements2.length;i++){
    //            if (liElements2[i].className.indexOf("new")>-1){
    //                liElements2[i].style.display = 'block';
    //            } else {
    //                liElements2[i].style.display = 'none';
    //            }
    //        }
    } else
    if (type=='3'){
        articleType = 'pop';
        popularbutton.className='menu_item_selected';
        nm_getPageList(false,articleType,lang);
    //        followbutton.className='menu_item_selected';
    //        nm_getPageList(false,true);
    }else {
        alert('what?: '+type);
    }
    return;
}


function runTicker(showItem){
    
    var tickerList = document.getElementById('news_ticker_list');
    if (tickerList){
        var liElements = tickerList.getElementsByTagName('li');
        //        alert(liElements.length);
        if ((showItem>=liElements.length)||(showItem<0)){
            showItem = 0;
        }
        var tickerLine = document.getElementById('ticker_line');

        if (tickerLine&&liElements[showItem]){
            tickerLine.innerHTML = liElements[showItem].innerHTML;
        }
        //        for(var i=0;i<liElements.length;i++){
        //            liElements[i].style.display = 'none';
        //        }
        //         alert(showItem);
        //        liElements[showItem].style.display = 'block';
        setTimeout(function (){
            showItem++;
            runTicker(showItem);
        },
        4000);
    }

}

//ajax sync url
function postURL (uri, postData){
    var returnObj = new Object();
    var xRequest;
    var retries = 3;
    for (var i = 1; i <= retries; i++)
    {
        xRequest = nm_CreateXmlHttpObject();
        //netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
        xRequest.open("POST", uri, false);
        xRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        try {
            xRequest.send(postData);
            break;
        }
        catch (e) {
            if (i == retries)
            {
                // Failed on 3nd try, bail out
                returnObj.error = e;
                returnObj.responseText = "";
                returnObj.status = 1;
                return returnObj;
            }
        }
    }
    returnObj.error = "";
    returnObj.responseText = xRequest.responseText;

    if (typeof(returnObj.responseText) == "undefined")
        returnObj.responseText = "";
    returnObj.status = xRequest.status;
    return returnObj;
}
    
function nm_CreateXmlHttpObject() {
    if (window.XMLHttpRequest)
    {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        return new XMLHttpRequest();
    }
    if (window.ActiveXObject)
    {
        // code for IE6, IE5
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
    alert("Your browser does not support AJAX!");
    return null;
}

//if addon installed on browser, go to link with directURL,
//otherwise goto URL with page.php
function gotoLink( linkElement, pageURL, directURL){
    if ((document.getElementById('addon')!=null)&&(document.getElementById('addon').value=='true')){
        linkElement.href = directURL;
    //linkElement.target='_blank';
    } else {        
// linkElement.href = pageURL;
}
}

function justifyImage(imgElement){
    if(!imgElement){
        return;
    }
    var height_justified = false;
    if (imgElement.height>imgElement.parentNode.clientHeight){
        imgElement.style.height=imgElement.parentNode.clientHeight+'px';
        height_justified = true;
    } else {
        imgElement.parentNode.style.height = imgElement.height+'px';
    }
    
    if (imgElement.width>imgElement.parentNode.clientWidth){
        imgElement.style.width=imgElement.parentNode.clientWidth+'px';
        if (!height_justified){
            imgElement.parentNode.style.height = imgElement.height+'px';
        }

    } else {
        imgElement.parentNode.style.width = imgElement.width+'px';
    }

}


function showArticlePreview(thisElement, story_id, article_id){
    var article_panel =document.getElementById("article_panel_"+story_id);
    if (thisElement){
        var main_article_span = document.getElementById("article_id_"+story_id);
        var main_article_span_id = main_article_span.innerHTML;
        if (main_article_span_id == article_id){
            return;
        }
    }

    var title = document.getElementById("article_title_"+story_id);
    var short_content = document.getElementById("article_short_content_"+story_id);
    var article_image = document.getElementById("article_image_"+story_id);
    var article_site = document.getElementById("article_site_"+story_id);
    var article_time = document.getElementById("article_time_"+story_id);
    
    var panelHeight= article_panel.clientHeight;
    article_panel.style.height=panelHeight+'px';
    panelHeight= article_panel.clientHeight;
    article_panel.style.height=panelHeight+'px';
    //article_panel.style.height='270px';

    var article_info = article_info_list['\''+article_id+'\''];
    
    title.innerHTML = article_info.title;
    short_content.innerHTML= article_info.short_content;
    article_image.innerHTML=article_info.image_html;    
    if (article_site) {
        article_site.innerHTML=article_info.site;
    }
    if (article_time) {
        article_time.innerHTML=article_info.time;
    }
    
    var article_image_element = document.getElementById("image_of_"+story_id);
    if (article_image_element){
        function justifyThisImage(){
            justifyImage(article_image_element);
        }
        if(article_image_element.addEventListener){
            article_image_element.addEventListener ('load',justifyThisImage ,false);
        }else if(article_image_element.attachEvent){
            article_image_element.attachEvent('onload', justifyThisImage );
        }
    }


    //current_article_span.innerHTML =article_id;
    if (thisElement){
        function rewindPreview(){
            // alert('-'+main_article_span_id+'-');
            showArticlePreview(null,story_id, main_article_span_id);
        }
        if(thisElement.addEventListener){
            thisElement.addEventListener ('mouseout',rewindPreview ,false);
        }else if(thisElement.attachEvent){
            thisElement.attachEvent('onmouseout', rewindPreview );
        }
    }
}

//var a = 0;
function showArticlePanel(panel){
    panel.style.display='block';

    if (panel.parentNode.clientWidth>0){
        panel.style.width =panel.parentNode.clientWidth+'px';
    }
    var hide_function =function(){
        //alert('out');
        unholdSlide();
        hidePanel(panel);
    //        if(panel.addEventListener){
    //            main_object.removeEventListener('mouseout',arguments.callee,false);
    //        } else if(panel.detachEvent){
    //            main_object.detachEvent('onmouseout',arguments.callee);
    //        }
    };
    
    if(panel.addEventListener){
        panel.addEventListener ('mouseout',hide_function ,false);
        panel.parentNode.addEventListener('mouseout',hide_function,false);
    }else if(panel.attachEvent){
        panel.attachEvent('onmouseout', hide_function );
        panel.parentNode.attachEvent('onmouseout',hide_function);
    }
}

function showArticlePreviewPanel(panel){
    //        panel.parentNode.style.zIndex='199';
    //        panel.style.zIndex='200';
    //        alert( panel.parentNode.style.zIndex+'-'+panel.style.zIndex);

    panel.style.display='block';
    panel.onmouseout = function(){
        hidePanel(panel);
    };
    panel.parentNode.onmouseout = function(){
        hidePanel(panel);
    };
                
}

function hidePanel(panel){
    // panel.className='';
    panel.style.display='none';    
}

function hideArticle(id){
    var articlemenu = document.getElementById("ap_"+id);
    var liarticle = articlemenu.parentNode;
    disappearDiv(liarticle,100,null);
}

function disappearDiv(divF,percenta,height)
{
    if (height==null){
        height = divF.offsetHeight;
    }
    if (percenta <100) {
        divF.style.height =  (height*percenta*percenta/10000)+'px';
        divF.style.filter = "alpha(opacity="+percenta+")";
        divF.style.opacity = "."+percenta;
    }
    if (percenta<1){
        divF.parentNode.removeChild(divF);
    }
    setTimeout(function (){
        disappearDiv(divF, percenta-5,height);
    },
    40);
}

function nm_getSimilarURLList(id) {
    var xmlHttp = nm_CreateXmlHttpObject();
    var url = ServerBaseURL+'html_response.php?a=su&id='+id;
    xmlHttp.open("GET", url, false);
    xmlHttp.send(null);
    if (xmlHttp.status == 200) {
        return xmlHttp.responseText;
    }
    return '';
}

function nm_changeLanguage(language) {
    var xmlHttp = nm_CreateXmlHttpObject();
    var url = ServerBaseURL+'json_response.php?a=cl&l='+language;
    xmlHttp.open("GET", url, false);
    xmlHttp.send(null);
    if (xmlHttp.status == 200) {
        window.location.reload(true);
    }
}



function findPosX(obj)
{
    var curleft = 0;
    if(obj.offsetParent)
        while(1)
        {
            curleft += obj.offsetLeft;
            if(!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj)
{
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
            curtop += obj.offsetTop;
            if(!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}

function toggleSimilarURLPanel(id, container){
    var divSimilarURL =  document.getElementById("divSimilarURL");
    if (divSimilarURL){
        var parentNode =divSimilarURL.parentNode;
        divSimilarURL.parentNode.removeChild(divSimilarURL);
        if (parentNode==container){
            //zaten burada ise sadece kapa
            return;
        }
    }
    divSimilarURL = document.createElement("div");
    divSimilarURL.id = "divSimilarURL";
    divSimilarURL.className ="similar_url_outer";
    container.appendChild(divSimilarURL);
    
    //alert(findPosX(element));
    //    divSimilarURL.style.top=findPosY(element)+20;
    //    divSimilarURL.style.left=findPosX(element);
    divSimilarURL.innerHTML ='loading...';
    var responseText = nm_getSimilarURLList(id);

    if (responseText.length>3){
        //        alert('['+responseText+']');
        divSimilarURL.innerHTML =responseText;
    } else {
        //        divSimilarURL.style.width='50px';
        divSimilarURL.style.padding='2 px';
        divSimilarURL.style.textAlign='center';
        divSimilarURL.innerHTML ='-none-';
    }
//divSimilarURL.onmouseout = hideSimilarURLPanel();
//    divSimilarURL.onmouseover=function(){
//        divSimilarURL.style.border='1px solid blue';
//    };
}

//function hideSimilarURLPanel(){
//    var divSimilarURL =  document.getElementById("divSimilarURL");
//    if (divSimilarURL){
//        document.body.removeChild(divSimilarURL);
//    }
//}


function nm_updateURLTrack(id,type) {
    var xmlHttp = nm_CreateXmlHttpObject();
    var url = ServerBaseURL+'json_response.php?a=utu&id='+id+'&t='+type;
    xmlHttp.open("GET", url, false);
    xmlHttp.send(null);
    if (xmlHttp.status == 200) {
        var json_result = eval("(" + xmlHttp.responseText + ")");
        if (json_result) {
            if (json_result.status == '1'){
                return true;
            } else if (json_result.error) {
                alert('ERROR:\n' + json_result.error);
                return false;
            }
        }else {
            return false;
        }
    }
    return false;
}

/*
function toggleFollowURLPanel(container){
    var divFollowURL =  document.getElementById("divFollowURL");

    if (divFollowURL){
        var parentNode =divFollowURL.parentNode;
        divFollowURL.parentNode.removeChild(divFollowURL);
        if (parentNode==container){
            //zaten burada ise sadece kapa
            return;
        }
    }
   
    divFollowURL = document.createElement("div");

    divFollowURL.id = "divFollowURL";
    divFollowURL.className ="follow_url_outer";
    container.appendChild(divFollowURL);
    //alert(findPosX(element));
    //    divSimilarURL.style.top=findPosY(element)+20;
    //    divSimilarURL.style.left=findPosX(element);
    divFollowURL.innerHTML ='loading...';
    var responseText = nm_getFollowURLList();

    if (responseText.length>3){
//        alert('['+responseText+']');
        divFollowURL.innerHTML =responseText;
    } else {
//        divSimilarURL.style.width='50px';
        divFollowURL.style.padding='2 px';
        divFollowURL.style.textAlign='center';
        divFollowURL.innerHTML ='-none-';
    }
//divSimilarURL.onmouseout = hideSimilarURLPanel();
//    divSimilarURL.onmouseover=function(){
//        divSimilarURL.style.border='1px solid blue';
//    };
}
*/
function nm_getFollowURLList() {
    var xmlHttp = nm_CreateXmlHttpObject();
    var url =ServerBaseURL+'html_response.php?a=fu';
    xmlHttp.open("GET", url, false);
    xmlHttp.send(null);
    if (xmlHttp.status == 200) {
        return xmlHttp.responseText;
    }
    return '';
}

function nm_getPageList(hot,articleType,lang) {
    var info ='';
    switch (lang){ 
        case 'tr':
            info = 'Biz sayfayı oluştururken, lütfen bir kaç saniye bekleyiniz...';
            break;
        case 'en':
        default:
            info = 'Please wait while we are fetching page list...';
            break;
    }

    document.getElementById('page_list').innerHTML =
    '<div class="today_news_list_wait">'+info+'<br><br><span id="wait_span"></span> </div>';
    document.getElementById('wait_span').innerHTML = waitIcon();
    //addWait(document.getElementById('wait_span'),0);
    var xmlHttp = nm_CreateXmlHttpObject();
    var url = ServerBaseURL+'page_list.php?a=pl';
    if (hot){
        url+='&h=t';
    }
    url+='&t='+articleType;

    xmlHttp.onreadystatechange=function(){
        if (xmlHttp.readyState==4)
        {
            document.getElementById('page_list').innerHTML = xmlHttp.responseText;
        }
    };
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

var article_info_list = null;

function nm_getStoryList(hot,articleType,lang) {
    var info ='';
    switch (lang){
        case 'tr':
            info = 'Biz sayfayı oluştururken, lütfen bir kaç saniye bekleyiniz...';
            break;
        case 'en':
        default:
            info = 'Please wait while we are fetching page list...';
            break;
    }

    document.getElementById('page_list').innerHTML =
    '<div class="today_news_list_wait">'+info+'<br><br><span id="wait_span"></span> </div>';
    document.getElementById('wait_span').innerHTML = waitIcon();
    //addWait(document.getElementById('wait_span'),0);
    var xmlHttp = nm_CreateXmlHttpObject();
    var url = ServerBaseURL+'story_list.php?a=pl';
    if (hot){
        url+='&h=t';
    }
    url+='&t='+articleType;

    xmlHttp.onreadystatechange=function(){
        if (xmlHttp.readyState==4)
        {
            var story_list_array= eval('('+xmlHttp.responseText+')');
            var time= story_list_array.time;
            article_info_list = story_list_array.article_info_list;
            document.getElementById('page_list').innerHTML = story_list_array.story_list_html;
            // document.title= story_list_array.time_title;
            document.getElementById('top_time').innerHTML = story_list_array.time_html;
        }
    };
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function nm_getQuickTopStoryList() {
    var xmlHttp = nm_CreateXmlHttpObject();
    var url = ServerBaseURL+'list/article_info_list.json';
    xmlHttp.onreadystatechange=function(){
        if (xmlHttp.readyState==4)
        {
            article_info_list= eval('('+xmlHttp.responseText+')');
        }
    };
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function nm_getUserUrlChoicesList() {
    var contentElement = document.getElementById('user_url_choices_list');
    var chooseInfo = document.getElementById('choose_iz_list_info');
    chooseInfo.style.display='none';
    contentElement.innerHTML = waitIcon();

    var url = ServerBaseURL+'html_response.php';
    var postData = 'a=uc';

    var xmlHttp =nm_CreateXmlHttpObject();
                
    xmlHttp.onreadystatechange  = function()
    {
        if(xmlHttp.readyState  == 4)
        {
            if(xmlHttp.status  == 200)
            {
                if (xmlHttp.responseText=='0'||xmlHttp.responseText==''){//login first
                    chooseInfo.style.display='block';
                    contentElement.innerHTML ='';
                } else {
                    contentElement.innerHTML = xmlHttp.responseText;
                }
            }
            else
            {
                contentElement.innerHTML='';
                chooseInfo.style.display='block';
            }
        }
    };

    xmlHttp.open('POST', url+'?'+postData,  true);
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(null);

}


function nm_getStory(storyId,lang) {
    var info ='';
    switch (lang){
        case 'tr':
            info = 'Biz sayfayı oluştururken, lütfen bir kaç saniye bekleyiniz...';
            break;
        case 'en':
        default:
            info = 'Please wait while we are fetching page list...';
            break;
    }

    document.getElementById('page_list').innerHTML =
    '<div class="today_news_list_wait">'+info+'<br><br><span id="wait_span"></span> </div>';
    document.getElementById('wait_span').innerHTML = waitIcon();
    //addWait(document.getElementById('wait_span'),0);

    var url = ServerBaseURL+'story_list.php';
    var postData = 'story_id='+storyId;
    var returnPost = postURL(url,postData);
    if (returnPost.error){
        alert(returnPost.error);
        //error
        return;
    }else {
        var responseText= returnPost.responseText;
        var story_list_array= eval('('+responseText+')');
        var time= story_list_array.time;
        article_info_list = story_list_array.article_info_list;
        document.getElementById('page_list').innerHTML = story_list_array.story_list_html;
        //document.title= story_list_array.time_title;
        document.getElementById('top_time').innerHTML = story_list_array.time_html;
    }
    
}


function nm_showCommentPanel(story_id,lang) {
    var comment_panel=document.getElementById('comment_panel_'+story_id);
    comment_panel.style.display='block';
    comment_panel.innerHTML =
    '<div class="comment_list_wait"><span id="wait_span_'+story_id+'"></span> </div>';
    document.getElementById('wait_span_'+story_id).innerHTML = waitIcon();
    //addWait(document.getElementById('wait_span'),0);
    var xmlHttp = nm_CreateXmlHttpObject();
    var url = ServerBaseURL+'comments_on_story.php?id='+story_id;

    xmlHttp.onreadystatechange=function(){
        if (xmlHttp.readyState==4)
        {

            if (xmlHttp.responseText=='0'||xmlHttp.responseText==''){//login first
                comment_panel.innerHTML = '<a href="#top">'+document.getElementById('not_logged_in_info').value+'</a>';
            } else {
                comment_panel.innerHTML = xmlHttp.responseText;                
                nm_addCommentBox(story_id);
            }
        }
    };
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function nm_addCommentBox(story_id){
    var commentButton = document.getElementById('comment_button_'+story_id);
    function sendThisMessage(){
        var commentArea = document.getElementById('comment_area_'+story_id);
        nm_addComment(story_id,commentArea.value);
    }
    if(commentButton.addEventListener){
        commentButton.addEventListener ('click',sendThisMessage ,false);
    }else if(commentButton.attachEvent){
        commentButton.attachEvent('onclick', sendThisMessage );
    }
}

function trim(str){
    return str.replace(/^\s+/, '').replace(/\s+$/, '');
}
function nm_addComment(story_id,text) {
    text=trim(text);
    if (!text){
        return;
    }
    var page_id= trim(document.getElementById('article_id_'+story_id).innerHTML);
    var url = ServerBaseURL+'comments_on_story.php';
    var postData = 'a=a&id='+page_id+'&t='+text;
    var returnPost = postURL(url,postData);
    if (returnPost.error){
        //error
        return;
    }else {
        var responseText= returnPost.responseText;
        nm_showCommentPanel(story_id,'');
    }
}
function nm_addLike(story_id) {
    var page_id= trim(document.getElementById('article_id_'+story_id).innerHTML);
    var url = ServerBaseURL+'comments_on_story.php';
    var postData = 'a=a&id='+page_id+'&ctype=1';
    var returnPost = postURL(url,postData);
    if (returnPost.error){
        //error
        return;
    }else {
        var responseText= returnPost.responseText;
        nm_showCommentPanel(story_id,'');
    }
}

function nm_deleteComment(story_id,page_id,comment_id) {    
    var url = ServerBaseURL+'comments_on_story.php';
    var postData = 'a=d&id='+page_id+'&tid='+comment_id;
    var returnPost = postURL(url,postData);
    if (returnPost.error){
        //error
        return;
    }else {
        var responseText= returnPost.responseText;
        nm_showCommentPanel(story_id,'');
    }
}

function waitIcon(){
    return '<img src="'+ServerBaseURL+'images/wait16.gif" style="vertical-align:text-top;">';
}
function addWait(element,i){
//    if (element==null){
//        return;
//    }
//    if (i==5){
//        i=0;
//        element.innerHTML ='';
//    }
//    i++;
//    element.innerHTML += waitIcon();
//    setTimeout(function (){
//        addWait(element,i);
//        },
//        1000);
//    return;
}
function getHtmlResponse(inputs){
    var xmlHttp = nm_CreateXmlHttpObject();
    var url=ServerBaseURL+"html_response.php?"+inputs;
    xmlHttp.open("GET",url,false);
    xmlHttp.send(null);
    if (xmlHttp.status==200){
        return xmlHttp.responseText;
    }
    return '';
}
 

