﻿// JScript File

 var http_request = false;

    function makeRequest(url) {

        

        http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        
       
            http_request.onreadystatechange = function() {

                    if (http_request.readyState == 4) {
                        if (http_request.status == 200) {
                           
                           try
                           {
                            var doc = http_request.responseXML;
				            var node = doc.getElementsByTagName('root')[0];
				            
				            var code  = node.getElementsByTagName('Code');
				           
				            var colh = 18;
				            var numofrow = 6;
				            
				            for(j = 0; j < code.length; j++ )
				            {
				                var subcode = code[j];
				            
				               var header  = subcode.getElementsByTagName('DataHeader')[0];
				               var item  = subcode.getElementsByTagName('DataItem');
				               var footer  = subcode.getElementsByTagName('DataFooter')[0];
				            				            
				                var content = "";				            
				                content = "<table width='100%' class='pricetable' border='0'  cellspacing='0' cellpadding='0'>";
				                content += "<tr><td height='"+colh+"'  >"+header.attributes[0].value+"</td><td width='100px' align='center'>"+header.attributes[1].value+"</td><td width='80px' align='center'>"+header.attributes[2].value+"</td></tr>";
                                    for(i = 0; i < item.length; i++ )
                                    {
                                        if( i % 2 == 0 )
                                            rowcolor = "#EEEEEE";
                                         else
                                            rowcolor = "#FFFFFF";
                                    
                                    
                                    
                                            var data = item[i];
                                        if( data.attributes[3].value != "HKVOL" )
                                        {
                                            content += "<tr bgcolor='"+rowcolor+"'><td style='padding-left:5px' height='"+colh+"'  >"+data.attributes[0].value +"</td>"+
                                            "<td align='center'>"+ data.attributes[1].value + "</td>"+
                                            "<td align='center'>"+ 
                                            quoteprice(data.attributes[2].value, data.attributes[4].value)+"</td></tr>";
                                            
                                            
                                          
                                            
                                           
                                            
                                        }
                                        else
                                        {
                                            content += "<tr><td height='"+colh+"' colspan='3'></td></tr><tr><td height='"+colh+"' colspan='3' style='padding-left:5px;'>* "+data.attributes[0].value +": "+data.attributes[1].value +"</td></tr>";
                                            i++;
                                        }
                                           
                                    }	                
				                
				                
				                for(k = 0; k < numofrow - i ; k++ )
				                    content += "<tr><td colspan='3' height='"+colh+"' ></td></tr>";
				                
				                
				                //var remainh = 150 - i * colh;
				                //alert(remainh);
				               // content += "<tr><td height='"+remainh+"' colspan='3'></td></tr>";
				                
				                content += "<tr><td  height='"+colh+"'  colspan='3' align='right' style='padding-right:5px;padding-top:8px;color:#777;font-size:11px;'  >"+footer.attributes[0].value+": "+footer.attributes[1].value+"</td></tr>";
                                 
				                 content += "</table>";
				            
				                 document.getElementById(subcode.attributes[0].value).innerHTML = content;
				                 
				                 
				               
				            }
				            
				            
                            }
                            catch(err) {
                            }
                        
                        } else {
                            //document.write('There was a problem with the request.');
                        }
                    }
            }
       
       
       
       
        
        http_request.open('GET', url, true);
        http_request.send(null);

    }

var count = 0;

function quoteprice(price, id)
{


if( price > 0 )
    pricetext = "<span  style='color:#008800; font-weight:bold'>+";
else if(price < 0 )
    pricetext = "<span  style='color:#FF0000; font-weight:bold'>";
else
    pricetext = "<span  style='color:#000000;' >";




pricetext += price+"</span>"

return pricetext;
}



function priceupdate(url)
{
    setInterval("makeRequest('"+url+"' )", 60000);

    
}

