﻿
var m_names = new Array("Jan", "Feb", "Mar", 
"Apr", "May", "June", "July", "Aug", "Sep", 
"Oct", "Nov", "Dec");

var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
             
// AJAX API For Loading the Market Page

var xmlReq = new Array(); // ARRAY OF XML-HTTP REQUESTS 
var xmlIndex = new Array(0); // ARRAY OF XML-HTTP REQUEST INDEXES
xmlIndex[0] = 1; // FIRST INDEX SET TO 1 MAKING IT AVAILABLE


function xhrRequest(type) 
{
    if (!type) 
    {
        type = 'html';
    }
    // xhrsend IS THE xmlIndex POSITION THAT GETS PASSED BACK
    // INITIALIZED TO THE LENGTH OF THE ARRAY(LAST POSITION + 1)
    var xhrsend = xmlIndex.length;

    // GO THROUGH AVAILABLE xi VALUES
    for (var i=0; i<xmlIndex.length; i++) 
    {
        // IF IT'S 1 (AVAILABLE), ALLOCATE IT FOR USE AND BREAK
        if (xmlIndex[i] == 1) 
        {
            xmlIndex[i] = 0;
            xhrsend = i;
            break;
        }
    }
    // SET TO 0 SINCE IT'S NOW ALLOCATED FOR USE
    xmlIndex[xhrsend] = 0;


    // SET UP THE REQUEST
    if (window.ActiveXObject) 
    {
        try 
        {
            xmlReq[xhrsend] = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) 
        {
            try 
            {
                xmlReq[xhrsend] = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e) 
            {
                
            }
        }
    } 
    else if (window.XMLHttpRequest) 
    {
        xmlReq[xhrsend] = new XMLHttpRequest();
        if (xmlReq[xhrsend].overrideMimeType) 
        {
            xmlReq[xhrsend].overrideMimeType('text/' + type);
        }
    }
    return (xhrsend);
}

var strHTML = "";
function 
(url, reqType) 
{
    var xhri = xhrRequest('html');
    xmlReq[xhri].open('GET', url, true);
    xmlReq[xhri].onreadystatechange = function() 
    {                     
        if (xmlReq[xhri].readyState == 4 && xmlReq[xhri].status == 200) 
        {           
            // Logic for displaying the Market Stats
            if(url == "AJAXMarket/MarketStats.aspx?Page=State")
            {            
                var arResponce;
                var Output = xmlReq[xhri].responseText; 
                var arOutput = Output.split(';');
                // Sensex Data                
                if(arOutput[0].split('##')[0] == "SENSEX")
                {
                    // Negative
                    if(arOutput[0].split('##')[2].charAt(0) == "-")
                    {
                        document.getElementById("sensex_img").src = "MarketImages/img23051484.jpg";
                        document.getElementById("Sensex").innerHTML = arOutput[0].split('##')[1].substring(0, arOutput[0].split('##')[1].length-2)
                        document.getElementById("a_chng").innerHTML = arOutput[0].split('##')[2];
                        document.getElementById("p_chng").innerHTML = arOutput[0].split('##')[3] + "%";                        
                        document.getElementById("a_chng").className = "Red";
                        document.getElementById("p_chng").className = "Red";
                        document.getElementById("lblBSEDate").innerHTML = arOutput[0].split('##')[4];
                        document.getElementById("lblBSETime").innerHTML = arOutput[0].split('##')[5];
                    }  
                    // Positive
                    else
                    {
                        document.getElementById("sensex_img").src = "MarketImages/paste64.jpg";
                        document.getElementById("Sensex").innerHTML = arOutput[0].split('##')[1].substring(0, arOutput[0].split('##')[1].length-2)
                        document.getElementById("a_chng").innerHTML = arOutput[0].split('##')[2];
                        document.getElementById("p_chng").innerHTML = arOutput[0].split('##')[3] + "%";                        
                        document.getElementById("a_chng").className = "Green";
                        document.getElementById("p_chng").className = "Green";
                        document.getElementById("lblBSEDate").innerHTML = arOutput[0].split('##')[4];
                        document.getElementById("lblBSETime").innerHTML = arOutput[0].split('##')[5];
                    }                  
                }     
                // Nifty Data
                if(arOutput[1].split('##')[0] == "NIFTY")
                {
                    if(arOutput[1].split('##')[2].charAt(0) == "-")
                    {                        
                        document.getElementById("nifty_img").src = "MarketImages/img23051484.jpg";
                        document.getElementById("nifty").innerHTML = arOutput[1].split('##')[1].substring(0, arOutput[0].split('##')[1].length-3)
                        document.getElementById("a_chng1").innerHTML = arOutput[1].split('##')[2];
                        document.getElementById("p_chng1").innerHTML = arOutput[1].split('##')[3] + "%";                        
                        document.getElementById("a_chng1").className = "Red";
                        document.getElementById("p_chng1").className = "Red";
                        document.getElementById("lblNSEDate").innerHTML = arOutput[1].split('##')[4];
                        document.getElementById("lblNSETime").innerHTML = arOutput[1].split('##')[5];                        
                    }  
                    // Positive
                    else
                    {                                                
                        document.getElementById("nifty_img").src = "MarketImages/paste64.jpg";
                        document.getElementById("nifty").innerHTML = arOutput[1].split('##')[1].substring(0, arOutput[0].split('##')[1].length-3)
                        document.getElementById("a_chng1").innerHTML = arOutput[1].split('##')[2];
                        document.getElementById("p_chng1").innerHTML = arOutput[1].split('##')[3] + "%";                        
                        document.getElementById("a_chng1").className = "Green";
                        document.getElementById("p_chng1").className = "Green";
                        document.getElementById("lblNSEDate").innerHTML = arOutput[1].split('##')[4];
                        document.getElementById("lblNSETime").innerHTML = arOutput[1].split('##')[5];                        
                    }
                }      
            }  
            //Logic to create Chartxmlfile
            if(url == "AJAXMarket/BseNseChartXml.aspx")
            {           
                var Output = xmlReq[xhri].responseText;
                var arOutput = Output.split('##');
                document.getElementById("BsePrevCl").innerHTML=arOutput[0];
                document.getElementById("NsePrevCl").innerHTML=arOutput[1];
            }  
            // Logic for displaying the Markets Commentary Data Pre Session
            if(url == "AJAXMarket/MarketCommentary.aspx?Page=Pre")
            {
                var Output = xmlReq[xhri].responseText;
                if(Output != "<table width=330px height=150px></table>")
                {
                    document.getElementById("spnMMData").innerHTML = Output;
                }
                else
                {
                    document.getElementById("spnMMData").innerHTML = "<table width=330px height=75px><tr><td width=150px align=center>No Data Found!</td></tr></table>";    
                }
            }   
            // Logic for displaying the Markets Commentary Data Mid Session
            if(url == "AJAXMarket/MarketCommentary.aspx?Page=Mid")
            {
                var Output = xmlReq[xhri].responseText; 
                if(Output != "<table width=330px height=150px></table>")
                {
                    document.getElementById("spnMMData").innerHTML = Output;
                }
                else
                {
                    document.getElementById("spnMMData").innerHTML = "<table width=330px height=75px><tr><td width=150px align=center>No Data Found!</td></tr></table>";   
                }                                
            }  
            // Logic for displaying the Markets Commentary Data End Session
            if(url == "AJAXMarket/MarketCommentary.aspx?Page=End")
            {            
                var Output = xmlReq[xhri].responseText; 
                if(Output != "<table width=330px height=150px></table>")
                {
                    document.getElementById("spnMMData").innerHTML = Output;
                }
                else
                {
                    document.getElementById("spnMMData").innerHTML = "<table width=330px height=75px><tr><td width=150px align=center>No End Session Market Commentary data Found!</td></tr></table>";    
                }                                
            }
            // Logic for displaying the Markets News Data
            if(url == "AJAXMarket/MarketNews.aspx?Page=State")
            {
                var Output = xmlReq[xhri].responseText; 
                document.getElementById("spnMarketNews").innerHTML = Output;                
                
            }                         
            // Logic for displaying the ADR Prices Data
            if(url == "AJAXMarket/ADRPrices.aspx?Page=State")
            {
                var arResponce;
                var Output = xmlReq[xhri].responseText; 
                var arOutput = Output.split(';');
                strHTML = "";
                strHTML = "<table width=100% cellpadding=5 cellspacing=0 style=padding-top:5px;>";
                //strHTML += "<tr><td width=185px>Company</td><td width=50px>Price</td><td width=50px>Change</td><td width=70px>% Change</td></tr>";        
                strHTML += "<th bgcolor=#F0F0F0>Company</th><th align='left' bgcolor=#F0F0F0>Price</th><th bgcolor=#F0F0F0>Change</th><th bgcolor=#F0F0F0>% Change</th>";
                for(var i=0; i < arOutput.length; i++)
                {
                    arResponce = "";
                    arResponce = arOutput[i].split('##');                    
                    strHTML += "<tr>";
                    strHTML += "<td width=180px class=ADR style=\"border-bottom: 1px solid #c2c2c2\">" + arResponce[0] + "</td>";
                    strHTML += "<td width=50px align=left style=\"border-bottom: 1px solid #c2c2c2\">" + arResponce[1].substring(0, arResponce[1].length-2) + "</td>";
                    if(arResponce[2].charAt(0) == "-") // Red Label
                    {
                        strHTML += "<td 'width=50px' class='RedText' align='left' style=\"border-bottom: 1px solid #c2c2c2\">" + arResponce[2].substring(0, arResponce[2].length-2) + "</td>";
                    }
                    else // Green Label
                    {
                        strHTML += "<td width=50px class='GreenText' align='left' style=\"border-bottom: 1px solid #c2c2c2\">" + arResponce[2].substring(0, arResponce[2].length-2) + "</td>";
                    }
                    if(arResponce[3].charAt(0) == "-") // Red Label
                    {
                        strHTML += "<td width=70px class='RedText'  style='padding-left:10px;border-bottom: 1px solid #c2c2c2'>" + arResponce[3].substring(0, arResponce[3].length-2) + " %</td>";
                    }
                    else // Green Label
                    {
                        strHTML += "<td width=70px class='GreenText' style='padding-left:10px;border-bottom: 1px solid #c2c2c2'>" + arResponce[3].substring(0, arResponce[3].length-2) + " %</td>";
                    }                    
                    strHTML += "</tr>";
                }
                strHTML += "<td colspan=4 align=right style=padding-right:8px;padding-top:20px><img height=\"5\" width=\"5\" border=\"0\" alt=\"\" src=\"MarketImages/paste69.jpg\"/>&nbsp;&nbsp;<a href=\"adrprices.aspx\" title=\"\" class=\"Links\">More</a></td>";  
                strHTML += "</table>"; 
                document.getElementById("spnFIIADR").innerHTML = strHTML;                
            }    
            // Logic for displaying the Currency Rates Data 
            if(url == "AJAXMarket/CurrencyRates.aspx?Page=State")
            {
                var arResponce;
                var Output = xmlReq[xhri].responseText; 
                var arOutput = Output.split(';');
                strHTML = "";
                strHTML = "<table width=100% cellpadding=5 cellspacing=0 style=padding-top:5px;>";
                strHTML += "<th align='left' bgcolor=#F0F0F0>Currency</th><th align='left' bgcolor=#F0F0F0>Rate</th>";
                for(var i=0; i < arOutput.length; i++)
                {
                    arResponce = "";
                    arResponce = arOutput[i].split('##');
                    strHTML += "<tr>";
                    strHTML += "<td width=80px align='left' style=\"border-bottom: 1px solid #c2c2c2\">" + arResponce[0] + "</td>";
                    strHTML += "<td width=50px align='left' style=\"border-bottom: 1px solid #c2c2c2\">Rs. " + arResponce[1] + "</td>";
                    strHTML += "</tr>";
                }
                strHTML += "<td colspan=2 align=right style=padding-right:8px;padding-top:15px;><img height=\"5\" width=\"5\" border=\"0\" alt=\"\" src=\"MarketImages/paste69.jpg\"/>&nbsp;&nbsp;<a href=\"Currency-Rates.aspx\" title=\"\" class=\"Links\">More</a></td>";
                strHTML += "</table>"; 
                document.getElementById("spnCurrencyWorld").innerHTML = strHTML; 
            }  
            // Logic for displaying the Global Indices data
            if(url == "AJAXMarket/GlobalIndices.aspx?Page=State")
            {
                var arResponce;
                var Output = xmlReq[xhri].responseText; 
                var arOutput = Output.split(';');
                strHTML = "<table width=100% cellpadding=5 cellspacing=0 style=padding-top:5px;>";                
                strHTML += "<th align='left' bgcolor=#F0F0F0>Indices</th><th align='left' bgcolor=#F0F0F0>Index</th><th align='center' bgcolor=#F0F0F0>Change</th><th bgcolor=#F0F0F0>% Change</th>";
                for(var i=0; i < arOutput.length; i++)
                {
                    arResponce = "";
                    arResponce = arOutput[i].split('##');
                    strHTML += "<tr>";
                    strHTML += "<td width=100px align='left' style=\"border-bottom: 1px solid #c2c2c2\">" + arResponce[0] + "</td>";
                    strHTML += "<td width=60px style=\"border-bottom: 1px solid #c2c2c2\">" + arResponce[1] + "</td>";
                    if(arResponce[2].charAt(0) == "-") // Red Label
                    {
                        strHTML += "<td 'width=80px' style='padding-left:5px;border-bottom: 1px solid #c2c2c2' class='RedText' align='center'>" + arResponce[2] + "</td>";
                    }
                    else // Green Label
                    {
                        strHTML += "<td width=80px style='padding-left:5px;border-bottom: 1px solid #c2c2c2' class='GreenText' align='center'>" + arResponce[2] + "</td>";
                    }
                    if(arResponce[3].charAt(0) == "-") // Red Label
                    {
                        strHTML += "<td width=70px class='RedText' style='padding-left:5px;border-bottom: 1px solid #c2c2c2' align='center'>" + arResponce[3] + " %</td>";
                    }
                    else // Green Label
                    {
                        strHTML += "<td width=70px class='GreenText' style='padding-left:5px;border-bottom: 1px solid #c2c2c2' align='center'>" + arResponce[3] + " %</td>";
                    }                    
                    strHTML += "</tr>";
                }  
                strHTML += "<td colspan=4 align=right style=padding-right:8px;padding-top:40px;><img height=\"5\" width=\"5\" border=\"0\" alt=\"\" src=\"MarketImages/paste69.jpg\"/>&nbsp;&nbsp;<a href=\"World-Markets.aspx\" title=\"\" class=\"Links\">More</a></td>";
                strHTML += "</table>"; 
                document.getElementById("spnCurrencyWorld").innerHTML = strHTML;
            }   
            // Logic for displaying the FII Stats data  
            if(url == "AJAXMarket/FIIStats.aspx?Page=FII")
            {                             
                var Output = xmlReq[xhri].responseText; 
                var arOutput = Output.split('##');
                strHTML = "";
                strHTML = "<table width=100% cellpadding=5 cellspacing=0 style=padding-top:5px;>";
                strHTML += "<th align='left' bgcolor=#F0F0F0>Investment Type</th><th align='left' bgcolor=#F0F0F0>Debt*</th><th align='left' bgcolor=#F0F0F0>Equity*</th>";                                
                strHTML += "<tr>";                
                strHTML += "<td width=80px style=\"border-bottom: 1px solid #c2c2c2\">Purchase</td>";
                strHTML += "<td width=50px style=\"border-bottom: 1px solid #c2c2c2\">" + arOutput[0] + "</td>";
                strHTML += "<td width=50px style=\"border-bottom: 1px solid #c2c2c2\">" + arOutput[1] + "</td>";
                strHTML += "</tr>";                
                strHTML += "<tr>";                
                strHTML += "<td width=80px style=\"border-bottom: 1px solid #c2c2c2\">Sales</td>";
                strHTML += "<td width=50px style=\"border-bottom: 1px solid #c2c2c2\">" + arOutput[2] + "</td>";
                strHTML += "<td width=50px style=\"border-bottom: 1px solid #c2c2c2\">" + arOutput[3] + "</td>";
                strHTML += "</tr>"; 
                strHTML += "<tr>";                
                strHTML += "<td width=80px style=\"border-bottom: 1px solid #c2c2c2\">Net Investment</td>";
                strHTML += "<td width=50px style=\"border-bottom: 1px solid #c2c2c2\">" + arOutput[4] + "</td>";
                strHTML += "<td width=50px style=\"border-bottom: 1px solid #c2c2c2\">" + arOutput[5] + "</td>";
                strHTML += "</tr>"; 
                strHTML += "<tr>"; 
                strHTML += "<td colspan=3 align=left style=padding-top:5px>* Value in Crores, Currency in INR. (" + curr_date + " " + m_names[curr_month] + ")</td>";
                strHTML += "</tr>";
                strHTML += "<td colspan=3>";
                strHTML += "</td>";
                strHTML += "<tr>";
                strHTML += "</tr>";
                strHTML += "<tr>"; 
                strHTML += "<td colspan=3 align=right style=padding-right:8px;padding-top:25px;><img height=\"5\" width=\"5\" border=\"0\" alt=\"\" src=\"MarketImages/paste69.jpg\"/>&nbsp;&nbsp;<a href=\"FII-Investment.aspx\" title=\"\" class=\"Links\">More</a></td>";
                strHTML += "</tr>";
                strHTML += "</table>"; 
                document.getElementById("spnMutual").innerHTML = strHTML; 
            } 
            // Logic for displaying the MFI data
            if(url == "AJAXMarket/FIIStats.aspx?Page=MFI")
            {
                var Output = xmlReq[xhri].responseText; 
                var arOutput = Output.split('##');
                strHTML = "";
                strHTML = "<table width=100% cellpadding=5 cellspacing=0 style=padding-top:5px;>";
                strHTML += "<th align='left' bgcolor=#F0F0F0>Investment Type</th><th align='left' bgcolor=#F0F0F0>Debt*</th><th align='left' bgcolor=#F0F0F0>Equity*</th>";                                
                strHTML += "<tr>";                
                strHTML += "<td width=80px style=\"border-bottom: 1px solid #c2c2c2\">Purchase</td>";
                strHTML += "<td width=50px style=\"border-bottom: 1px solid #c2c2c2\">" + arOutput[0].substring(0, arOutput[0].length-2) + "</td>";
                strHTML += "<td width=50px style=\"border-bottom: 1px solid #c2c2c2\">" + arOutput[1].substring(0, arOutput[1].length-2) + "</td>";
                strHTML += "</tr>";                
                strHTML += "<tr>";                
                strHTML += "<td width=80px style=\"border-bottom: 1px solid #c2c2c2\">Sales</td>";
                strHTML += "<td width=50px style=\"border-bottom: 1px solid #c2c2c2\">" + arOutput[2].substring(0, arOutput[2].length-2) + "</td>";
                strHTML += "<td width=50px style=\"border-bottom: 1px solid #c2c2c2\">" + arOutput[3].substring(0, arOutput[3].length-2) + "</td>";
                strHTML += "</tr>"; 
                strHTML += "<tr>";                
                strHTML += "<td width=80px style=\"border-bottom: 1px solid #c2c2c2\">Net Investment</td>";
                strHTML += "<td width=50px style=\"border-bottom: 1px solid #c2c2c2\">" + arOutput[4].substring(0, arOutput[4].length-2) + "</td>";
                strHTML += "<td width=50px style=\"border-bottom: 1px solid #c2c2c2\">" + arOutput[5].substring(0, arOutput[5].length-2) + "</td>";
                strHTML += "</tr>"; 
                strHTML += "<tr>"; 
                strHTML += "<td colspan=3 align=left style=padding-top:5px>* Value in Crores, Currency in INR. (" + curr_date + " " + m_names[curr_month] + ")</td>";
                strHTML += "</tr>";
                strHTML += "</tr>";
                strHTML += "<td colspan=3>";
                strHTML += "</td>";
                strHTML += "<tr>";
                strHTML += "<tr>"; 
                strHTML += "<td colspan=3 align=right style=padding-right:8px;padding-top:25px;><img height=\"5\" width=\"5\" border=\"0\" alt=\"\" src=\"MarketImages/paste69.jpg\"/>&nbsp;&nbsp;<a href=\"Mutual-Fund-Investment.aspx\" title=\"\" class=\"Links\">More</a></td>";
                strHTML += "</tr>";
                strHTML += "</table>"; 
                document.getElementById("spnMutual").innerHTML = strHTML;
            }
            // Logic for displaying the BSE Gainers and Losers  data
            if(url == "AJAXMarket/BSEGainersLosers.aspx?Page=State")
            {                       
                var arResponce;
                var Output = xmlReq[xhri].responseText;   // Getting the Responce from Server              
                var arOutput = Output.split(';'); // Splitting the Responce and storing in array
                var lastElement = arOutput[arOutput.length-1]; // Sets the Last Element of Array
                // Table Formation for displaying the BSE - Top Gainers Data
                strHTML = "";
                strHTML = "<table width=250px style=padding-left:8px>";                
                for(var i=0; i < lastElement; i++)
                {
                    arResponce = "";
                    arResponce = arOutput[i].split('##');
                    strHTML += "<tr>";                    
                    strHTML += "<td width=130px><a href=Getquotenew.aspx?id="+ arResponce[3] + ">" + arResponce[0] + "</a></td>";
                    strHTML += "<td>" + arResponce[1].substring(0, arResponce[1].length-2) + "</td>";
                    if(arResponce[2].charAt(0) == "-") // Red Label
                    {
                        strHTML += "<td class='RedText' align='center'>" + arResponce[2].substring(0, arResponce[2].length-2) + "</td>";
                    }
                    else // Green Label
                    {
                        strHTML += "<td class='GreenText' align='center'>" + arResponce[2].substring(0, arResponce[2].length-2) + "</td>";
                    }                    
                    strHTML += "</tr>";
                }
                strHTML += "</table>"; 
                document.getElementById("spnBSEGainers").innerHTML = strHTML; 
                // IF Containts Empty Dataset                                
                if(arOutput[parseInt(lastElement)+1] == undefined)
                {
                    strHTML = "";
                    strHTML = "<table width=250px height=120px style=padding-left:8px;padding-top:4px>";
                    strHTML += "<tr>";
                    strHTML += "<td align=center>Currently No Data Available.";
                    strHTML += "</td>";
                    strHTML += "</tr>";
                    strHTML += "</table>"; 
                    document.getElementById("spnBSELosers").innerHTML = strHTML; 
                } 
                // If the Dataset is Not Empty 
                else
                {           
                    // Table Formation for displaying the BSE - Top Losers Data
                    strHTML = "";
                    strHTML = "<table width=250px style=padding-left:8px;padding-top:4px>";                
                    for(var i=lastElement; i < arOutput.length-1; i++)
                    {
                        arResponce = "";
                        arResponce = arOutput[i].split('##');                    
                        strHTML += "<tr>";                    
                        strHTML += "<td width=130px><a href=Getquotenew.aspx?id="+ arResponce[3] + ">" + arResponce[0] + "</a></td>";
                        strHTML += "<td>" + arResponce[1].substring(0, arResponce[1].length-2) + "</td>";
                        if(arResponce[2].charAt(0) == "-") // Red Label
                        {
                            strHTML += "<td class='RedText' align='center'>" + arResponce[2].substring(0, arResponce[2].length-2) + "</td>";
                        }
                        else // Green Label
                        {
                            strHTML += "<td class='GreenText' align='center'>" + arResponce[2].substring(0, arResponce[2].length-2) + "</td>";
                        }                    
                        strHTML += "</tr>";
                    }
                    strHTML += "</table>"; 
                    document.getElementById("spnBSELosers").innerHTML = strHTML; 
                }
            }
            //Logic for filling the dropdown based on change in Index
            if(url == "markets/BSEGainersLosers.aspx?Page=BSE" || url == "markets/BSEGainersLosers.aspx?Page=NSE")
            {
                var arResponce;
                var Output = xmlReq[xhri].responseText;
                arResponce = Output.split("|");                   
                //To Remove All Items of Drop Down
                var ddl = document.getElementById("ddlGroup");
                (ddl).length = 0;    
                //To Add Items In Drop Down
                for(var i = 0; i < arResponce.length; i++)
                {
                    (ddl).options[i] = new Option(arResponce[i].split(":")[0],arResponce[i].split(":")[1]);
                }
                if(url == "markets/BSEGainersLosers.aspx?Page=NSE")
                {
                    (ddl).selectedIndex = 11;   
                } 
                else
                {
                    (ddl).selectedIndex = 16;    
                }               
            }
            //Logic for filling the dropdown based on change in Index
            if(url == "markets/NSEGainersLosers.aspx?Page=BSE" || url == "markets/NSEGainersLosers.aspx?Page=NSE")
            {
                var arResponce;
                var Output = xmlReq[xhri].responseText;
                arResponce = Output.split("|");                   
                //To Remove All Items of Drop Down
                var ddl = document.getElementById("ddlGroup1");
                (ddl).length = 0;    
                //To Add Items In Drop Down
                for(var i = 0; i < arResponce.length; i++)
                {
                    (ddl).options[i] = new Option(arResponce[i].split(":")[0],arResponce[i].split(":")[1]);
                }
                if(url == "AJAXMarket/NSEGainersLosers.aspx?Page=NSE")
                {
                    (ddl).selectedIndex = 11;   
                } 
                else
                {
                    (ddl).selectedIndex = 16;    
                }
            }
            
            // Logic for displaying the 52 Week Data
            if(url == "AJAXMarket/52WeekAndCurrent.aspx?Page=Year&Index=BSE&GroupName=Bse_Sensex")
            {
                var arResponce;
                var arOut;
                var Output = xmlReq[xhri].responseText;   // Getting the Responce from Server              
                var arResponce = Output.split(';');                    
                // Table Formation for displaying the 52 Week Data
                strHTML = "";
                strHTML = "<table width=575px cellpadding=5 style=padding-left:8px;padding-top:5px cellspacing=0>";
                strHTML += "<th width=115px align=left bgcolor=#F0F0F0>Company Name</th><th bgcolor=#F0F0F0>High</th><th bgcolor=#F0F0F0>High Date</th><th bgcolor=#F0F0F0>Low</th><th bgcolor=#F0F0F0>Low Date</th>";                
                for(var i=0; i < arResponce.length; i++)
                {    
                    arOut = "";            
                    arOut = arResponce[i].split('##');
                    strHTML += "<tr>";                    
                    strHTML += "<td width=115px style=\"border-bottom: 1px solid #c2c2c2\"><a href=Getquotenew.aspx?id="+ arOut[5] + " class=Week52>" + arOut[0] + "</a></td>";
                    strHTML += "<td align=left width=100px class=Green style=\"border-bottom: 1px solid #c2c2c2\">" + arOut[1].substring(0, arOut[1].length-2) + "</td>";
                    strHTML += "<td width=115px style=\"border-bottom: 1px solid #c2c2c2\">" + arOut[2] + "</td>";  
                    strHTML += "<td width=115px class=Red style=\"border-bottom: 1px solid #c2c2c2\">" + arOut[3].substring(0, arOut[3].length-2) + "</td>";                  
                    strHTML += "<td width=115px style=\"border-bottom: 1px solid #c2c2c2\">" + arOut[4] + "</td>"; 
                    strHTML += "</tr>";
                }
                strHTML += "</table>"; 
                document.getElementById("spnWeekCurrent").innerHTML = strHTML;
            }      
            // Logic for displaying the Gainers Data
            if(url == "AJAXMarket/GainersLosers.aspx?Page=Gainers&Index=BSE&GroupName=Bse_Sensex")
            {
                var arResponce;
                var arOut;
                var Output = xmlReq[xhri].responseText;   // Getting the Responce from Server              
                var arResponce = Output.split(';');            
                strHTML = "";
                strHTML = "<table width=100% cellspacing=0 cellpadding=5 style=padding-left:8px;padding-top:5px>";
                strHTML += "<th width=150px align=left bgcolor=#F0F0F0>Company Name</th><th bgcolor=#F0F0F0>LTP (Rs.)</th><th bgcolor=#F0F0F0>Volume</th><th bgcolor=#F0F0F0>% Change</th>";
                for(var i=0; i < arResponce.length; i++)
                {    
                    arOut = "";            
                    arOut = arResponce[i].split('##');
                    strHTML += "<tr>";                    
                    strHTML += "<td width=130px style=\"border-bottom: 1px solid #c2c2c2\"><a href=Getquotenew.aspx?id="+ arOut[5] + " class=Week52>" + arOut[0] + "</a></td>";
                    //strHTML += "<td align=left width=100px>" + arOut[1].substring(0, arOut[1].length-2) + "</td>"; 
                    strHTML += "<td align=left width=100px style=\"border-bottom: 1px solid #c2c2c2\">" + arOut[2].substring(0, arOut[2].length-2) + "</td>";
                    strHTML += "<td align=left width=100px style=\"border-bottom: 1px solid #c2c2c2\">" + arOut[3] + "</td>";
                    if(arOut[4].charAt(0) != "-")
                    { 
                        strHTML += "<td align=left width=100px class=Green style=\"border-bottom: 1px solid #c2c2c2\">+ " + arOut[4].substring(0, arOut[4].length-2) + "</td>";
                    }
                    else
                    {
                        strHTML += "<td align=left width=100px class=Red style=\"border-bottom: 1px solid #c2c2c2\">" + arOut[4].substring(0, arOut[4].length-2) + "</td>";    
                    }
                    strHTML += "</tr>";
                }
                strHTML += "</table>"; 
                document.getElementById("spnGainLose").innerHTML = strHTML;     
            }                                          
            // Logic for Displaying the Market Summary
            if(url == "AJAXMarket/MarketSummary.aspx?Page=BSE&GroupName=Bse_Sensex")
            {
                document.getElementById("lblGroupName").innerHTML = "Bse_Sensex";
                var arrBSE;
                var arrNSE;
                var Output = xmlReq[xhri].responseText;   // Getting the Responce from Server              
                var arOutput = Output.split(';'); // Splitting the Responce and storing in array  
                              
                // Getting BSE Data. It Contains Advance##Declines##Unchange
                arrBSE = arOutput[0];
                // Getting NSE Data. It Contains Advance##Declines##Unchange
                arrNSE = arOutput[1];
                
                // Displaying the Market Summary for BSE
                if(arrBSE.split('##')[0] == "0")
                {
                    document.getElementById("BSE_Advance").style.width = "0%";
                    document.getElementById("BSE_Decline").style.width = "0%";
                    //document.getElementById("BSE_Unchange").style.width = "0%";
                }
                else
                {   
                    // Calculation  
                    var PerAdvanceBSE;
                    var PerDeclineBSE;
                    var PerUnchngBSE;                                    
                    var TotalBSE;
                    TotalBSE = parseInt(arrBSE.split('##')[0]) + parseInt(arrBSE.split('##')[1]) + parseInt(arrBSE.split('##')[2]);
                    PerAdvanceBSE = Math.ceil((arrBSE.split('##')[0] / TotalBSE) * 100);
                    PerDeclineBSE = Math.ceil((arrBSE.split('##')[1] / TotalBSE) * 100);
                    //PerUnchngBSE = Math.ceil((arrBSE.split('##')[2] / TotalBSE) * 100);                    
                    // Setting the Width of the TD Where the image is shown
                    document.getElementById("BSE_Advance").style.width = PerAdvanceBSE + "%";
                    document.getElementById("BSE_Decline").style.width = PerDeclineBSE + "%";
                    //document.getElementById("BSE_Unchange").style.width = PerUnchngBSE + "%";
                    // Setting the Values in the Label
                    document.getElementById("lblBSEAdvance").innerHTML = arrBSE.split('##')[0];
                    document.getElementById("lblBSEDecline").innerHTML = arrBSE.split('##')[1];
                    //document.getElementById("lblBSEUnchange").innerHTML = arrBSE.split('##')[2];                    
                }                              
            }            
            xmlIndex[xhri] = 1;
            xmlReq[xhri] = null;
        }
        else
        {        
            //displayStaticMessage('<img src=images/Progress/kms_progress.gif alt=\"\" /> <span style=\"font-size:10px\">Please wait.......</span>',false);                             
        }
    };
    xmlReq[xhri].send(null);
}
// Method Called during the Page Load



function loadMulti() 
{  

         
    // CALL A FUNCTION THAT USES xmlHttp MULTIPLE TIMES 
    document.getElementById('spnMMData').innerHTML = "<table width=330px height='220px'><tr><td align=center style=padding-left:75px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";  
    document.getElementById('spnMarketNews').innerHTML = "<table width=100% height='250px'><tr><td align=center valign=middle style=padding-left:50px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";
    document.getElementById('spnGainLose').innerHTML = "<table width=100% height='145px'><tr><td align=center valign=middle style=padding-left:50px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";
    document.getElementById('spnWeekCurrent').innerHTML = "<table width=100% height='165px'><tr><td align=center valign=middle style=padding-left:50px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";
    document.getElementById('spnCurrencyWorld').innerHTML = "<table width=100% height='125px'><tr><td align=center valign=middle style=padding-left:50px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";
    document.getElementById('spnMutual').innerHTML = "<table width=100% height='125px'><tr><td align=center valign=middle style=padding-left:50px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";
    document.getElementById('spnFIIADR').innerHTML = "<table width=100% height='140px'><tr><td align=center valign=middle style=padding-left:50px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";
    LoadRequest('AJAXMarket/BseNseChartXml.aspx'); 
    LoadRequest('AJAXMarket/MarketStats.aspx?Page=State');
    LoadRequest('AJAXMarket/MarketCommentary.aspx?Page=Pre');
    LoadRequest('AJAXMarket/MarketNews.aspx?Page=State');                 
    LoadRequest('AJAXMarket/GlobalIndices.aspx?Page=State');
    LoadRequest('AJAXMarket/FIIStats.aspx?Page=FII'); 
    LoadRequest('AJAXMarket/ADRPrices.aspx?Page=State');
    LoadRequest('AJAXMarket/52WeekAndCurrent.aspx?Page=Year&Index=BSE&GroupName=Bse_Sensex');                                 
    LoadRequest('AJAXMarket/GainersLosers.aspx?Page=Gainers&Index=BSE&GroupName=Bse_Sensex'); 
    LoadRequest('AJAXMarket/MarketSummary.aspx?Page=BSE&GroupName=Bse_Sensex');
}
// On change event for the Index dropdown
function getGroup(object,value)
{
    debugger;
    var obj = object;    
    if(obj.name == "ctl00$content$ddlIndex")
    {       
        LoadRequest('markets/BSEGainersLosers.aspx?Page='+value);
        setTimeout("LoadGainerLosers('ALL')", 500);                
    }
    else
    {        
        LoadRequest('markets/NSEGainersLosers.aspx?Page='+value);                        
        setTimeout("Load52WeekAndCurrent('ALL')", 500);              
    }
}
// Script for making like tabs for Commentary Section
function SetMMTab(a) 
{
    document.getElementById('TDG').className = "txtNewsBottom";
    document.getElementById('TDL').className = "txtNewsBottom";
    document.getElementById('TDA').className = "txtNewsBottom"; 
    document.getElementById('aPre').style.fontWeight = "";  
    document.getElementById('aMid').style.fontWeight = ""; 
    document.getElementById('aEnd').style.fontWeight = ""; 
    if (a == "P") 
    {
        document.getElementById('TDG').className = "txtNewsBottomBold";       
        document.getElementById('aPre').style.fontWeight = "bold";         
        document.getElementById('spnMMData').innerHTML = "<table width=100% height='220px'><tr><td align=center style=padding-left:75px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";
        LoadRequest('AJAXMarket/MarketCommentary.aspx?Page=Pre');           
        document.getElementById('aPre').className = "Links";      
    }
    else if (a == "M")
    {
       document.getElementById('TDL').className = "txtNewsBottomBold"; 
       document.getElementById('aMid').style.fontWeight = "bold";       
       document.getElementById('spnMMData').innerHTML = "<table width=100% height='220px'><tr><td align=center style=padding-left:75px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";
       LoadRequest('AJAXMarket/MarketCommentary.aspx?Page=Mid');          
       document.getElementById('aMid').className = "Links";           
    }    
    else
    {
        document.getElementById('TDA').className = "txtNewsBottomBold";  
        document.getElementById('aEnd').style.fontWeight = "bold";        
        document.getElementById('spnMMData').innerHTML = "<table width=100% height='220px'><tr><td align=center style=padding-left:75px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>"; 
        LoadRequest('AJAXMarket/MarketCommentary.aspx?Page=End');           
        document.getElementById('aEnd').className = "Links";              
    }
}
// Script for making like tabs for Currency Section
function SetMMTab1(a) 
{
    document.getElementById('TDC').className = "txtNewsBottom";
    document.getElementById('TDW').className = "txtNewsBottom";    
    document.getElementById('aCur').style.fontWeight = "";  
    document.getElementById('aWor').style.fontWeight = "";     
    if (a == "C") 
    {
        document.getElementById('TDC').className = "txtNewsBottomBold";       
        document.getElementById('aCur').style.fontWeight = "bold";         
        document.getElementById('spnCurrencyWorld').innerHTML = "<table width=100% height='125px'><tr><td align=center valign=middle style=padding-left:50px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";
        LoadRequest('AJAXMarket/CurrencyRates.aspx?Page=State');
        document.getElementById('aCur').className = "Links";                                 
    }      
    else
    {
        document.getElementById('TDW').className = "txtNewsBottomBold";  
        document.getElementById('aWor').style.fontWeight = "bold";        
        document.getElementById('spnCurrencyWorld').innerHTML = "<table width=100% height='125px'><tr><td align=center valign=middle style=padding-left:50px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>"; 
        LoadRequest('AJAXMarket/GlobalIndices.aspx?Page=State'); 
        document.getElementById('aWor').className = "Links";                             
    }
}
// Script for making like tabs for ADR Section
function SetMMTab2(a) 
{
    LoadRequest('AJAXMarket/ADRPrices.aspx?Page=State');          
    document.getElementById('aADR').className = "Links";    
}
// Script for making like tabs for 52 Week Section
function SetMMTab3(a) 
{
    document.getElementById('TD52W').className = "txtNewsBottom";
    document.getElementById('TDCURR').className = "txtNewsBottom";    
    document.getElementById('a52Week').style.fontWeight = "";  
    document.getElementById('aCurrent').style.fontWeight = "";     
    if (a == "W") 
    {
        document.getElementById('TD52W').className = "txtNewsBottomBold";       
        document.getElementById('a52Week').style.fontWeight = "bold";        
        Load52WeekAndCurrent(document.getElementById("ddlGroup1").value);
        document.getElementById('a52Week').className = "Links";                                        
    }      
    else
    {
        document.getElementById('TDCURR').className = "txtNewsBottomBold";  
        document.getElementById('aCurrent').style.fontWeight = "bold";        
        Load52WeekAndCurrent(document.getElementById("ddlGroup1").value);
        document.getElementById('aCurrent').className = "Links";                                      
    }
}
// Script for making like tabs for FII Section
function SetMMTab4(a) 
{
    document.getElementById('TDFII').className = "txtNewsBottom";
    document.getElementById('TDMF').className = "txtNewsBottom";    
    document.getElementById('aFII').style.fontWeight = "";  
    document.getElementById('aMUT').style.fontWeight = "";     
    if (a == "F") 
    {
        document.getElementById('TDFII').className = "txtNewsBottomBold";       
        document.getElementById('aFII').style.fontWeight = "bold";        
        document.getElementById('spnMutual').innerHTML = "<table width=100% height='125px'><tr><td align=center valign=middle style=padding-left:50px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>"; 
        LoadRequest('AJAXMarket/FIIStats.aspx?Page=FII'); 
        document.getElementById('aFII').className = "Links";                                              
    }      
    else
    {
        document.getElementById('TDMF').className = "txtNewsBottomBold";  
        document.getElementById('aMUT').style.fontWeight = "bold";        
        document.getElementById('spnMutual').innerHTML = "<table width=100% height='125px'><tr><td align=center valign=middle style=padding-left:50px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";
        LoadRequest('AJAXMarket/FIIStats.aspx?Page=MFI');  
        document.getElementById('aMUT').className = "Links";                                   
    }
}


function loadGainLose()
{
alert('hi');
     document.getElementById('ctl00_content_dvGainersUpdate').style.display = "block"; 
        document.getElementById('ctl00_content_dvLosersUpdate').style.display = "none"; 
}

// Script for making like tabs for Gainers Section
function SetMMTab5(a) 
{
    //debugger;
    //alert('Hello');
    document.getElementById('TDGain').className = "txtNewsBottom";
    document.getElementById('TDLose').className = "txtNewsBottom";    
    document.getElementById('aGain').style.fontWeight = "";  
    document.getElementById('aLose').style.fontWeight = "";     
    if (a == "G") 
    {
        document.getElementById('TDGain').className = "txtNewsBottomBold";       
        document.getElementById('aGain').style.fontWeight = "bold";        
        //LoadGainerLosers(document.getElementById("ddlGroup").value);
        document.getElementById('aGain').className = "Links";
        
        document.getElementById('dvGainersUpdate').style.display = "block"; 
        document.getElementById('dvLosersUpdate').style.display = "none"; 
    }      
    else if (a == "L")
    {
        document.getElementById('TDLose').className = "txtNewsBottomBold";  
        document.getElementById('aLose').style.fontWeight = "bold";         
        //LoadGainerLosers(document.getElementById("ddlGroup").value);
        document.getElementById('aLose').className = "Links";
        
        document.getElementById('dvLosersUpdate').style.display = "block";                                             
        document.getElementById('dvGainersUpdate').style.display = "none"; 
    }
    
    else if(a=="B")
    {
        document.getElementById('TDGain').className = "txtNewsBottomBold";       
        document.getElementById('aGain').style.fontWeight = "bold";        
        document.getElementById('aGain').className = "Links";
        document.getElementById('dvBSEAD').style.display="block";                                             
        document.getElementById('dvNSEAD').style.display="none"; 
    }
    else if(a=="N")
    {
        document.getElementById('TDLose').className = "txtNewsBottomBold";  
        document.getElementById('aLose').style.fontWeight = "bold";         
        document.getElementById('aLose').className = "Links";
        document.getElementById('dvNSEAD').style.display="block";                                             
        document.getElementById('dvBSEAD').style.display="none"; 
    }
    
}
// Showing the Graph
function showGraph(Exchng)
{
    if (Exchng=="NSE")
    {
        LoadRequest('AJAXMarket/BseNseChartXml.aspx');
        document.getElementById('graph').style.display = "none";
        document.getElementById('graphNse').style.display = "block";
        LoadRequest('AJAXMarket/MarketStats.aspx?Page=State');
    }
    else
    {
        LoadRequest('AJAXMarket/BseNseChartXml.aspx');
        document.getElementById('graphNse').style.display = "none";
        document.getElementById('graph').style.display = "block";
        LoadRequest('AJAXMarket/MarketStats.aspx?Page=State');
    }
}
// Navigating to the Get Quotes Page
function GetQuotes()
{
    if(document.getElementById("ctl00_txtGetQuote_hidden").value == "")
    {
        alert("Please select a Company Name from List");
        document.getElementById("ctl00_txtGetQuote").focus();
        return false;
    }
    else
    {
        var URL = "Getquotenew.aspx?id=" + document.getElementById("ctl00_txtGetQuote_hidden").value;        
        window.open(URL,'_parent');
        return false;
    }
}
///////////////////////////  Seprate AJAX Object for Loading 52 Week and Current Status //////////////////////////
var xmlHttp;
function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}
// Calling the AJAX Based method to load the data's for 52 Week and Current Status
function Load52WeekAndCurrent(GroupName)
{        
    var Page;
    var Index = document.getElementById("ddlIndex1").value;
    if(document.getElementById('TD52W').className == "txtNewsBottomBold")
    {
        Page = "Year";
    }
    else
    {
        Page = "CurrentStatus";
    }
    xmlHttp = GetXmlHttpObject(); 
    if (xmlHttp==null) 
    { 
        alert ("Browser does not support HTTP Request");
         return; 
    } 
    //you can provide your page URL which will fetch you the values from your database
    var url = "AJAXMarket/52WeekAndCurrent.aspx"; 
    url = url + "?Page="+ Page + "&Index="+ Index + "&GroupName=" + GroupName;
    //state change event-this will occur ass soon as response comes from the url
    if(Page == "Year")
    {
        xmlHttp.onreadystatechange = SteadyStateChangefor52Week;
    }
    else
    {
        xmlHttp.onreadystatechange = SteadyStateChangeforCurrent;
    }    
    xmlHttp.open("GET",url,true); 
    xmlHttp.send(null);
}
// Method is called when Steady State is 4
function SteadyStateChangefor52Week()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") 
    { 
        //Display contents 
        var xmlResponse = xmlHttp.responseText; 
        if (xmlResponse!='') 
        {             
            var arResponce;
            var arOut;
            var Output = xmlResponse;   // Getting the Responce from Server              
            var arResponce = Output.split(';');                    
            // Table Formation for displaying the 52 Week Data
            strHTML = "";
            strHTML = "<table width=575px cellpadding=5 style=padding-left:8px;padding-top:5px cellspacing=0>";
            strHTML += "<th width=115px align=left bgcolor=#F0F0F0>Company Name</th><th bgcolor=#F0F0F0>High</th><th bgcolor=#F0F0F0>High Date</th><th bgcolor=#F0F0F0>Low</th><th bgcolor=#F0F0F0>Low Date</th>";                
            for(var i=0; i < arResponce.length; i++)
            {    
                arOut = "";            
                arOut = arResponce[i].split('##');
                strHTML += "<tr>";                    
                strHTML += "<td width=115px style=\"border-bottom: 1px solid #c2c2c2\"><a href=Getquotenew.aspx?id="+ arOut[5] + " class=Week52>" + arOut[0] + "</a></td>";
                strHTML += "<td align=left style=\"border-bottom: 1px solid #c2c2c2\" width=100px class=Green>" + arOut[1].substring(0, arOut[1].length-2) + "</td>";
                strHTML += "<td width=115px style=\"border-bottom: 1px solid #c2c2c2\">" + arOut[2] + "</td>";  
                strHTML += "<td width=115px class=Red style=\"border-bottom: 1px solid #c2c2c2\">" + arOut[3].substring(0, arOut[3].length-2) + "</td>";                  
                strHTML += "<td width=115px style=\"border-bottom: 1px solid #c2c2c2\">" + arOut[4] + "</td>"; 
                strHTML += "</tr>";
            }
            strHTML += "</table>"; 
            document.getElementById("spnWeekCurrent").innerHTML = strHTML;                             
        } 
        else 
        { 
            strHTML = "";
            strHTML = "<table width=575px style=padding-left:8px>";
            strHTML += "<tr>";
            strHTML += "<td height=150px align=center valign=middle> No data found ! </td>";
            strHTML += "</tr>";
            strHTML += "</table>";   
            document.getElementById("spnWeekCurrent").innerHTML = strHTML;         
        } 
    }
    else
    {
        document.getElementById("spnWeekCurrent").innerHTML = "<table width=100% height='160px'><tr><td align=center style=padding-left:75px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";
    } 
}
// Method is called when Steady State is 4
function SteadyStateChangeforCurrent()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") 
    { 
        //Display contents 
        var xmlResponse = xmlHttp.responseText; 
        if (xmlResponse!='') 
        {             
            var arResponce;
            var arOut;
            var Output = xmlResponse;   // Getting the Responce from Server              
            var arResponce = Output.split(';');                            
            // Table Formation for displaying the 52 Week Data
            strHTML = "";
            strHTML = "<table width=100% cellpadding=5 style=padding-left:8px;padding-top:5px cellspacing=0>";
            strHTML += "<th width=130px align=left bgcolor=#F0F0F0>Company Name</th><th bgcolor=#F0F0F0 width=10px></th><th bgcolor=#F0F0F0>Curr. Price</th><th bgcolor=#F0F0F0>Today's High</th><th bgcolor=#F0F0F0>52Week High</th><th bgcolor=#F0F0F0>Today's Low</th><th bgcolor=#F0F0F0>52Week Low</th>";                
            for(var i=0; i < arResponce.length; i++)
            {    
                arOut = "";            
                arOut = arResponce[i].split('##');
                strHTML += "<tr>";                    
                strHTML += "<td width=130px style=\"border-bottom: 1px solid #c2c2c2\"><a href=Getquotenew.aspx?id="+ arOut[6] + " class=Week52>" + arOut[0] + "</a></td>";
                if(arOut[4].charAt(0) == "-")
                {
                    strHTML += "<td width=10px style=\"border-bottom:1px solid #c2c2c2;\">H</td>";    
                }
                else  
                {
                    strHTML += "<td width=10px style=\"border-bottom:1px solid #c2c2c2;\">L</td>";
                }
                strHTML += "<td align=center width=100px style=\"border-bottom: 1px solid #c2c2c2\">" + arOut[1].substring(0, arOut[1].length-2) + "</td>";                                
                if(arOut[2].charAt(0) == "-")
                {
                    strHTML += "<td width=100px style=\"padding-left:25px;border-bottom:1px solid #c2c2c2;\">" + arOut[2] + "</td>";
                }
                else
                {
                    strHTML += "<td width=100px class=Green style=\"padding-left:15px;border-bottom:1px solid #c2c2c2;\">" + arOut[2].substring(0, arOut[2].length-2) + "</td>";    
                }                                
                if(arOut[3].charAt(0) == "-")  
                {
                    strHTML += "<td width=100px style=\"padding-left:25px;border-bottom:1px solid #c2c2c2;\">" + arOut[3] + "</td>";
                }
                else
                {
                    strHTML += "<td width=100px style=\"padding-left:15px;border-bottom:1px solid #c2c2c2;\">" + arOut[3].substring(0, arOut[3].length-2) + "</td>";                  
                }
                if(arOut[4].charAt(0) == "-")  
                {
                    strHTML += "<td width=100px style=\"padding-left:15px;border-bottom:1px solid #c2c2c2;\">" + arOut[4] + "</td>";
                }
                else
                {
                    strHTML += "<td width=100px style=\"padding-left:15px;border-bottom: 1px solid #c2c2c2\" class=Red>" + arOut[4].substring(0, arOut[4].length-2) + "</td>";                 
                }
                if(arOut[5].charAt(0) == "-")  
                {
                    strHTML += "<td width=100px style=\"padding-left:15px;border-bottom:1px solid #c2c2c2;\">" + arOut[5] + "</td>";
                }
                else
                {
                    strHTML += "<td width=100px style=\"padding-left:15px;border-bottom:1px solid #c2c2c2;\">" + arOut[5].substring(0, arOut[5].length-2) + "</td>";                 
                }                 
                strHTML += "</tr>";
            }
            strHTML += "</table>"; 
            document.getElementById("spnWeekCurrent").innerHTML = strHTML;                             
        } 
        else 
        { 
            strHTML = "";
            strHTML = "<table width=575px style=padding-left:8px>";
            strHTML += "<tr>";
            strHTML += "<td height=150px align=center valign=middle> No data found ! </td>";
            strHTML += "</tr>";
            strHTML += "</table>";   
            document.getElementById("spnWeekCurrent").innerHTML = strHTML;         
        } 
    }
    else
    {
        document.getElementById("spnWeekCurrent").innerHTML = "<table width=100% height='160px'><tr><td align=center style=padding-left:75px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";
    } 
}
// Calling the AJAX Based method to load the data's for Gainers and Losers
function LoadGainerLosers(GroupName)
{      
    var Page;
    if(document.getElementById('TDGain').className == "txtNewsBottomBold")
    {
        Page = "Gainers";
    }
    else
    {
        Page = "Losers";
    }          
    var Index = document.getElementById("ddlIndex").value;    
    xmlHttp = GetXmlHttpObject(); 
    if (xmlHttp==null) 
    { 
        alert ("Browser does not support HTTP Request");
         return; 
    } 
    //you can provide your page URL which will fetch you the values from your database
    var url = "AJAXMarket/GainersLosers.aspx"; 
    url = url + "?Page="+ Page + "&Index="+ Index + "&GroupName=" + GroupName;
    //state change event-this will occur ass soon as response comes from the url    
    xmlHttp.onreadystatechange = SteadyStateChangeGainLoser;  
    xmlHttp.open("GET",url,true); 
    xmlHttp.send(null);
}
function SteadyStateChangeGainLoser()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") 
    { 
        //Display contents 
        var xmlResponse = xmlHttp.responseText; 
        if (xmlResponse!='') 
        {
            var arResponce;
            var arOut;
            var Output = xmlResponse;   // Getting the Responce from Server              
            var arResponce = Output.split(';');            
            strHTML = "";
            strHTML = "<table width=100% cellspacing=0 cellpadding=5 style=padding-left:8px;padding-top:5px>";
            strHTML += "<th width=150px align=left bgcolor=#F0F0F0>Company Name</th><th bgcolor=#F0F0F0>LTP (Rs.)</th><th bgcolor=#F0F0F0>Volume</th><th bgcolor=#F0F0F0>% Change</th>";
            for(var i=0; i < arResponce.length; i++)
            {    
                arOut = "";            
                arOut = arResponce[i].split('##');
                strHTML += "<tr>";
                strHTML += "<td width=130px style=\"border-bottom: 1px solid #c2c2c2\"><a href=Getquotenew.aspx?id="+ arOut[5] + " class=Week52>" + arOut[0] + "</a></td>";
                //strHTML += "<td align=left width=100px>" + arOut[1].substring(0, arOut[1].length-2) + "</td>"; 
                strHTML += "<td align=left width=100px style=\"border-bottom: 1px solid #c2c2c2\">" + arOut[2].substring(0, arOut[2].length-2) + "</td>";
                strHTML += "<td align=left width=100px style=\"border-bottom: 1px solid #c2c2c2\">" + arOut[3] + "</td>";
                if(arOut[4].charAt(0) != "-")
                { 
                    strHTML += "<td align=left width=100px class=Green style=\"border-bottom: 1px solid #c2c2c2\">+ " + arOut[4].substring(0, arOut[4].length-2) + "</td>";
                }
                else
                {
                    strHTML += "<td align=left width=100px class=Red style=\"border-bottom: 1px solid #c2c2c2\">" + arOut[4].substring(0, arOut[4].length-2) + "</td>";    
                }
                strHTML += "</tr>";
            }
            strHTML += "</table>"; 
            document.getElementById("spnGainLose").innerHTML = strHTML;             
            LoadAdvanceDecline(document.getElementById("ddlGroup").value);
        }
    }
    else
    {
        document.getElementById("spnGainLose").innerHTML = "<table width=100% height='150px'><tr><td align=center style=padding-left:100px;><img src=images/Progress/up_spinner.gif /><span class='heading_color'>Loading Data.....</span></td></tr></table>";
    }    
}
// Script for Displaying for Advances and Declines
function LoadAdvanceDecline(GroupName)
{         
    document.getElementById("lblGroupName").innerHTML = GroupName;
    var Index = document.getElementById("ddlIndex").value;    
    xmlHttp = GetXmlHttpObject(); 
    if (xmlHttp==null) 
    { 
        alert ("Browser does not support HTTP Request");
         return; 
    } 
    //you can provide your page URL which will fetch you the values from your database
    var url = "AJAXMarket/MarketSummary.aspx"; 
    url = url + "?Page="+ Index + "&GroupName=" + GroupName;
    //state change event-this will occur ass soon as response comes from the url    
    xmlHttp.onreadystatechange = SteadyStateforAdvance;  
    xmlHttp.open("GET",url,true); 
    xmlHttp.send(null);
}
// Steady State is 4
function SteadyStateforAdvance()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") 
    { 
        //Display contents 
        var xmlResponse = xmlHttp.responseText;
        if (xmlResponse!='') 
        {
            var arrBSE;
            var arrNSE;
            var Output = xmlResponse;   // Getting the Responce from Server              
            var arOutput = Output.split(';'); // Splitting the Responce and storing in array  
                          
            // Getting BSE Data. It Contains Advance##Declines##Unchange
            arrBSE = arOutput[0];
            // Getting NSE Data. It Contains Advance##Declines##Unchange
            arrNSE = arOutput[1];
            
            // Displaying the Market Summary for BSE
            if(arrBSE.split('##')[0] == "0")
            {
                document.getElementById("BSE_Advance").style.width = "0%";
                document.getElementById("BSE_Decline").style.width = "0%";
                //document.getElementById("BSE_Unchange").style.width = "0%";
            }
            else
            {   
                // Calculation  
                var PerAdvanceBSE;
                var PerDeclineBSE;
                var PerUnchngBSE;                                    
                var TotalBSE;
                TotalBSE = parseInt(arrBSE.split('##')[0]) + parseInt(arrBSE.split('##')[1]) + parseInt(arrBSE.split('##')[2]);
                PerAdvanceBSE = Math.ceil((arrBSE.split('##')[0] / TotalBSE) * 100);
                PerDeclineBSE = Math.ceil((arrBSE.split('##')[1] / TotalBSE) * 100);
                //PerUnchngBSE = Math.ceil((arrBSE.split('##')[2] / TotalBSE) * 100);                    
                // Setting the Width of the TD Where the image is shown
                document.getElementById("BSE_Advance").style.width = PerAdvanceBSE + "%";
                document.getElementById("BSE_Decline").style.width = PerDeclineBSE + "%";
                //document.getElementById("BSE_Unchange").style.width = PerUnchngBSE + "%";
                // Setting the Values in the Label
                document.getElementById("lblBSEAdvance").innerHTML = arrBSE.split('##')[0];
                document.getElementById("lblBSEDecline").innerHTML = arrBSE.split('##')[1];
                //document.getElementById("lblBSEUnchange").innerHTML = arrBSE.split('##')[2];                    
            }     
        }
    }
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
                    window.open(theURL,winName,features);
            } 
            
            
// Script for making like tabs
function SetTabResearch(a) 
{
debugger;
    document.getElementById('TDOverview').className = "txtNewsBottom";
    document.getElementById('TDAnalysis').className = "txtNewsBottom";  
    document.getElementById('TDTechnical').className = "txtNewsBottom";   
    document.getElementById('ao').style.fontWeight = "";  
    document.getElementById('aw').style.fontWeight = "";  
    document.getElementById('at').style.fontWeight = "";    
    if (a == "o") 
    {
        document.getElementById('TDOverview').className = "txtNewsBottomBold";       
        document.getElementById('ao').style.fontWeight = "bold"; 
        document.getElementById('ao').className = "Links"; 
        document.getElementById('div1').style.display = "block";   
        document.getElementById('div2').style.display = "none"; 
        document.getElementById('div3').style.display = "none";                             
    }      
    else if (a == "w") 
    {
        document.getElementById('TDAnalysis').className = "txtNewsBottomBold";  
        document.getElementById('aw').style.fontWeight = "bold";
        document.getElementById('aw').className = "Links";  
         document.getElementById('div1').style.display = "none";       
        document.getElementById('div2').style.display = "block";    
        document.getElementById('div3').style.display = "none";                                   
    }
    else
    {
     document.getElementById('TDTechnical').className = "txtNewsBottomBold";  
        document.getElementById('at').style.fontWeight = "bold";
        document.getElementById('at').className = "Links";  
         document.getElementById('div1').style.display = "none";       
        document.getElementById('div2').style.display = "none";    
        document.getElementById('div3').style.display = "block";    
    }
}
