﻿
    var xmlhttp;

    function JumpPage( page){
        
        getTrailerList( page);
    
    }
    
    function getTrailerList( page){

        var url;

        url = '../xml/xml_movie_trailer_im_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;
        var xmlroot;
        var content;
        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="440" border="0" cellspacing="0" cellpadding="0">\n';
                content += ' <tr><td height="25" colspan="4" align="left" valign="top"><img src="images/imhottit.png" width="118" height="16" /></td></tr>\n';
                
                j = 0;

                for( i = 0; i < total; i ++){

                    j ++;

                    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;
                    
                    url = 'trailer_watch.aspx?sn=' + serialno + '&jump=' + currentpage;

                    if( j == 1) content += ' <tr>\n';

                    content += '  <td width="110" height="80" align="center" valign="top">\n';
                    content += '   <table width="80" border="0" cellspacing="0" cellpadding="0">\n';
                    content += '    <tr><td height="80" align="center" valign="top"><a href="' + url + '"><img src="' + thumb + '" width="100" height="68" border="0" /></a></td></tr>\n';
                    content += '    <tr><td height="30" align="center" valign="top"><a href="' + url + '" class="u_wh12" title="' + subject + '">' + subject.cutting(10) + '</a></tr>\n';
                    content += '   </table>\n';
                    content += '  </td>\n';

                    if( j == 4){
                    
                        content += ' </tr>\n';
                    
                        j = 0;
                        
                    }

                }

                if( j != 0 && j != 4){
                
                    for( i = j; i < 4; i ++){
                    
                        content += '  <td width="110" height="80">&nbsp;</td>\n';

                    }                

                    content += ' </tr>';
                
                }

                content += ' <tr>\n';
                content += '  <td height="40" colspan="5" align="center">\n';

                if( totalpages > 1){
                    
                  content += '   <table width="280" border="0" cellspacing="0" cellpadding="0" style="text-align:center;">\n';
                  content += '    <tr>\n';
                  content += '     <td width="50">';
                  
                  if( currentpage != 1) content += '<a href="javascript: JumpPage(1);"><img src="images/imlist_back.png" width="22" height="16" border="0" /></a>';
                  
                  content += '</td>\n';
                  content += '     <td width="50">';
                  
                  if( currentpage != 1) content += '<a href="javascript: JumpPage(' + ( currentpage - 1) + ');" class="u_wh12">上一頁</a>';
                  
                  content += '</td>\n';
                  content += '     <td width="80" class="org12">' + currentpage + '/' + totalpages + '</td>\n';
                  content += '     <td width="50">';
                  
                  if( currentpage != totalpages) content += '<a href="javascript: JumpPage( ' + ( currentpage + 1) + ');" class="u_wh12">下一頁</a>';
                  
                  content += '</td>\n';
                  content += '     <td width="50">';
                  
                  if( currentpage != totalpages) content += '<a href="javascript: JumpPage(' + totalpages + ');"><img src="images/imlist_prv.png" width="22" height="16" border="0" /></a>';
                  
                  content += '</td>\n';
                  content += '    </tr>\n';
                  content += '   </table>\n';
                    
                }

                content += '  </td>\n';
                content += ' </tr>\n';
                content += '</table>\n';

                document.getElementById('MoreResult').innerHTML = content;

            }

        }    
    
    }    

