﻿function loadTextFile(){
httpObj = createXMLHttpRequest(displayData);
if (httpObj){
httpObj.open("GET","../../csv_utf8/topic.csv",true);
httpObj.send(null);
}
}

var ajax_filter = function(t){return t};
if(navigator.appVersion.indexOf( "KHTML" ) > -1){
    ajax_filter = function(t){
        var esc = escape(t);
        return(esc.indexOf("%u") < 0 && esc.indexOf("%") > -1) ? decodeURIComponent(esc) : t
    }
}

function displayData(){
    if ((httpObj.readyState == 4) && (httpObj.status == 200)){
        var text = ajax_filter(httpObj.responseText);
        document.getElementById("result").innerHTML = parseText(text);
    }
}

/*function parseText(str){
    var resultText="<table border=0>";
    var CR = String.fromCharCode(13);
    var LF = String.fromCharCode(10);
    lineData = str.split(CR);

    for (var i=0; i<lineData.length; i++){
        strText = lineData[i].split(",");
        resultText += "<tr>";
        
        for (var j=0; j<strText.length; j++){
            if (i < 300){
                if(j == 0){
                    resultText += "<td>"+strText[j]+"</td>";
                }
                if(j == 1){
                    if (i == 301){
                        resultText += "<td>";
                    }else{
                        resultText += "<td><a href="+strText[j]+">";
                    }
                }
                if(j == 2){
                    if (i == 301){
                        resultText += strText[j]+"</td>";
                    }else{
                        resultText += strText[j] +"</a></td>";
                    }
                }
                if(j == 3){
                    resultText += "<td>"+strText[j]+"</td>";
                }
            }
        }
        resultText += "</tr>";
    }
    return resultText;
}*/

function parseText(str){
    var resultText="<table border='0' cellspacing='0' cellpadding='0'>";
    var CR = String.fromCharCode(13);
    var LF = String.fromCharCode(10);
    lineData = str.split(CR);

    for (var i=0; i<lineData.length; i++){
        strText = lineData[i].split(",");
        resultText += "<tr>";
        
        for (var j=0; j<strText.length; j++){
            if (i < 1000){
                if(j == 0){                    
                    if (i == 0){
                        resultText += "<!-- start -->";
                    }else{
                        resultText += "<td class='top_w_sub'>"+strText[j]+"</td>";
                    }
                }
                if(j == 1){
                    if (i == 0){
                        resultText += "";
                    }else{
                        resultText += "<td class='top_w_sub'><img src='../image_info/"+strText[j]+".gif'></td>";
                    }
                }
                if(j == 2){
                    if (i == 0){
                        resultText += "";
                    }else{
                        resultText += "<td class='top_w_sub'><a href='"+strText[j]+"";
                    }
                }
                if(j == 3){
                    if (i == 0){
                        resultText += "";
                    }else{
                        resultText += ""+strText[j]+"' ";
                    }
                }
                if(j == 4){
                    if (i == 0){
                        resultText += "";
                    }else{
                        resultText += "target='"+strText[j]+"'>";
                    }
                }
                if(j == 5){
                    if (i == 0){
                        resultText += "";
                    }else{
                        resultText += strText[j] +"</a></td>";
                    }
                }
            }
        }
        resultText += "</tr>";
    }
    return resultText;
}