﻿
    var xmlhttp;
    var _current;

    function init(n){
        
        _current = n;

    }
    
    function getTrailer(n){
        
        _current = n;
        
        getTrailerList(1);
        
    }

    function JumpPage( page){
        
        getTrailerList( page);
    
    }
    
    function getTrailerList( page){

        var url;
        
        if( _current == 2) url =  '../xml/xml_movie_trailer_search_list.aspx?ins=' + document.getElementById('_keywords').innerText + '&jump=' + page;

        else url = '../xml/xml_movie_trailer_new_list.aspx?jump=' + page;

        if( window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
        else if( window.ActiveXObject) xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
        
        xmlhttp.open( 'GET', url, false);
              
        if( navigator.appName == 'Netscape'){

            xmlhttp.send( null);
            setTrailerList();
        
        }
        
        else{

            xmlhttp.onreadystatechange = setTrailerList;
            xmlhttp.send( null);
            
        }

    }

    function setTrailerList(){

        var i, j;
        var total;
        var totalpages, currentpage;
        var serialno, subject, thumb, sysdate;
        var xmlroot;
        var content;
        var bgcolor;
        var n, m, p;
        var link;
        var url;

        if( xmlhttp.readyState == 4 && xmlhttp.status == 200){ 

            xmlroot = xmlhttp.responseXML.documentElement;

            if( xmlroot.selectSingleNode('./result/totalpages').firstChild.nodeValue != null) totalpages = parseInt( xmlroot.selectSingleNode('./result/totalpages').firstChild.nodeValue);
            if( xmlroot.selectSingleNode('./result/currentpage').firstChild.nodeValue != null) currentpage = parseInt( xmlroot.selectSingleNode('./result/currentpage').firstChild.nodeValue);

            total = parseInt( xmlroot.selectNodes('./result/single').length);

            if( total > 0){

                content = '<table width="630" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="text-align:center;">\n';
                
                j = 0;
                n = 0;

                for( i = 0; i < total; i ++){

                    j ++;
                    
                    bgcolor = n == 0 ? 'movwh' : 'movgr';

                    serialno = xmlroot.selectNodes('./result/single/serialno')[i].firstChild.nodeValue;
                    subject = xmlroot.selectNodes('./result/single/subject')[i].firstChild.nodeValue;
                    thumb = xmlroot.selectNodes('./result/single/thumb')[i].firstChild.nodeValue;
                    sysdate = xmlroot.selectNodes('./result/single/sysdate')[i].firstChild.nodeValue;
                    
                    url = 'watch.aspx?sn=' + serialno + '&jump=' + currentpage;

                    if( j == 1) content += ' <tr>\n';

                    content += ' <td width="315" valign="top" class="' + bgcolor + '">\n';
                    content += '  <table width="290" border="0" cellspacing="0" cellpadding="0" style="text-align:left;">\n';
                    content += '   <tr>\n';
                    content += '    <td width="110" rowspan="3" valign="top"><a href="' + url + '"><img src="' + thumb + '" width="100" height="68" border="0" class="picb1" /></a></td>\n';
                    content += '    <td width="190"><a href="' + url + '" class="u_blu15b">' + subject + '</a></td>\n';
                    content += '   </tr>\n';
                    content += '   <tr><td height="25" class="bk12"><img src="../images/ent_orgdot.gif" width="11" height="6" />' + sysdate + ' 更新</td></tr>\n';
                    content += '   <tr><td height="20" valign="bottom"><a href="' + url + '" onmouseout="ImageRestore();" onmouseover="ImageOver( \'V' + serialno + '\', \'../images/trailerplayover.gif\');"><img src="../images/trailerplay.gif" width="58" height="17" border="0" id="V' + serialno + '" /></a></td></tr>\n';
                    content += '  </table>\n';
                    content += ' </td>\n';

                    if( j == 2){
                    
                        content += ' </tr>\n';
                        
                        n ++;
                    
                        j = 0;
                        
                        if( n == 2) n = 0;
                        
                    }

                }

                if( j == 1){
                
                    content += '  <td width="315" class="' + bgcolor + '"></td>\n';
                    content += ' </tr>\n';
                
                }

                content += ' <tr>\n'; 
                content += '  <td height="60" colspan="2" bgcolor="#FFFFFF">\n'; 

                if( totalpages > 1){
       
                    if( currentpage % 5 == 0) p = currentpage / 5;
                    
                    else p = parseInt( currentpage / 5) + 1;
        
                    n = ( p - 1) * 5 + 1;
                    m = n + 4;
        
                    content += '    <table border="0" align="center" cellpadding="0" cellspacing="4" class="gr12p">\n';
                    content += '     <tr>\n';
        
                    if( currentpage != 1) link = '<a href="javascript: JumpPage(1);" onmouseout="ImageRestore();" onmouseover="ImageOver( \'prv-page\', \'../images/video_bt_pr2.gif\');"><img src="../images/video_bt_pr1.gif" width="22" height="16" border="0" id="prv-page"></a>';
        
                    else link = '<img src="../images/video_bt_pr2.gif" width="22" height="16" border="0">';
        
                    content += '      <td width="30" align="center">' + link + '</td>\n';
                    content += '      <td width="10" align="center">∣</td>\n';
        
                    if( currentpage != 1) link = '<a href="javascript: JumpPage(' + ( currentpage - 1) + ');" class="u_gr">上頁</a>';
                
                    else link = '<span class="gy">上頁</a>';
        
                    content += '      <td width="30" align="center">' + link + '</td>\n';
                    content += '      <td width="10" align="center">∣</td>\n';
        
                    for( i = n; i <= m; i ++){
        
                        if( i == currentpage) link = '<span style="color:#000000; font-weight: bold; text-decoration:underline;">' + i + '</span>';
                        
                        else if( i <= totalpages) link = '<a href="javascript: JumpPage(' + i + ');" class="u_gr">' + i + '</a>';
        
                        else link = '<span class="gy">' + i + '</span>';
        
                        content += '     <td width="30" align="center" class="u_gr">' + link + '</td>\n';
                        content += '     <td width="10" align="center">∣</td>\n';
        
                    }
        
                    if( currentpage != totalpages) link = '<a href="javascript: JumpPage(' + ( currentpage + 1) + ');" class="u_gr">下頁</a>';
                
                    else link = '<span class="gy">下頁</a>';
        
                    content += '     <td width="30" align="center">' + link + '</td>\n';
                    content += '     <td width="10" align="center">∣</td>\n';
        
                    if( currentpage != totalpages) link = '<a href="javascript: JumpPage(' + totalpages + ');" onmouseout="ImageRestore();" onmouseover="ImageOver( \'next-page\', \'../images/video_bt_nx2.gif\');"><img src="../images/video_bt_nx1.gif" width="22" height="16" border="0" id="next-page"></a>';
                    
                    else link = '<img src="../images/video_bt_nx2.gif" width="22" height="16" border="0">';
        
                    content += '     <td width="30" align="center">' + link + '</td>\n';
        
                    content += '    </tr>\n';
                    content += '   </table>\n';
        
                }

                content += '  </td>\n';
                content += ' </tr>\n';
                content += '</table>\n';

                document.getElementById('MoreResult').innerHTML = content;

            }

        }    
    
    }    
