var sControl;
var objXmlHttp;
var sSec;
var sControl1;
var objXmlHttp1;
var sControl2;
var objXmlHttp2;

///The below function is used to get dynamic data based on the Market Section that the user has clicked.
function getMarketContent(sSection, sCtrl){
getMarketContentNew(sSection,sCtrl);}

///Function called when asynchronous response received.
function stateChanged()
{
if (objXmlHttp.readyState==4 || objXmlHttp.readyState=="complete"){
var sData = objXmlHttp.responseText;
document.getElementById(sControl).innerHTML = sData;
if(sSec=="MORE"){
GetIndices();CommPrices();
}
CheckCookie();
}}

function showDecimals(nValue, nDecimals){
var sDec = nValue.toString().split('.');
var sRetVal = nValue.toString();
if(sDec.length==1){
sRetVal = sRetVal + ".";
for(i=0; i < nDecimals; i++){sRetVal = sRetVal + "0";}
}
else{
if(sDec[1].length > nDecimals){sRetVal = Math.round(nValue, nDecimals);}
else if(sDec[1].length < nDecimals){
for(i=sDec[1].length; i < nDecimals; i++){sRetVal = sRetVal + "0";}
}}
return sRetVal;}

///initailises the Xml Http object as per the user's browser
function GetXmlHttpObject(handler){
var objXHttp=null;
if (navigator.userAgent.indexOf("MSIE")>=0 || navigator.userAgent.indexOf("Opera")>=0){
if (window.XMLHttpRequest){
// code for all new browsers
objXHttp=new XMLHttpRequest();
if(handler!=null) {objXHttp.onreadystatechange=handler;}
return objXHttp;
}
else if (window.ActiveXObject){
// code for IE5 and IE6
objXHttp=new ActiveXObject("Microsoft.XMLHTTP");
if(handler!=null){objXHttp.onreadystatechange=handler;}
return objXHttp;
}
if(objXHttp==null){
var strName="Msxml2.XMLHTTP";
if (navigator.appVersion.indexOf("MSIE 5.5")>=0){strName="Microsoft.XMLHTTP";}
try{
objXHttp=new ActiveXObject(strName);
if(handler!=null){objXHttp.onreadystatechange=handler;}
return objXHttp;
}
catch(e){
alert("Error. Scripting for ActiveX might be disabled");return;}
}}
if (navigator.userAgent.indexOf("Mozilla")>=0){
objXHttp=new XMLHttpRequest();
if(handler!=null){
objXHttp.onload=handler;objXHttp.onerror=handler;
}
return objXHttp;
}
}//end of function GetXmlHttpObject(handler)

function getMarketContentNew(sSection, sCtrl){
sSec = "";sSec = sSection;sUrl = "";sControl = sCtrl;
if(sSection=="MktMon"){sUrl = "/mktmon/indmonhome_new.html";}
else if(sSection=="NSE"){sUrl = "/nse50_new.asp";}
else if(sSection=="BSE"){sUrl = "/bse30_new.asp";}
else if(sSection=="MORE"){sUrl = "/home_more_new.asp";}
    
document.getElementById(sControl).innerHTML = "<table cellspacing='0' cellpadding='0' border='0' width='100%' height='165px'>"+
" <tr style='height: 165px'>"+
"     <td align='center' valign='middle'><img src='/images/loading.gif' alt='Loading...' /></td>"+
" </tr>"+
"</table>";
    
if(sUrl != ""){
objXmlHttp = null;objXmlHttp = GetXmlHttpObject(stateChanged);
objXmlHttp.open("GET", sUrl , true);objXmlHttp.send(null);
}
else{document.getElementById(sControl).innerHTML = "";}
}//end of function getMarketContentNew(section)

function getPopularStories(sCtrl){
objXmlHttp1 = null;sControl1 = sCtrl;
var sUrl1 = "/popular_new.asp";
objXmlHttp1 = GetXmlHttpObject(stateChanged1);objXmlHttp1.open("GET", sUrl1 , true);objXmlHttp1.send(null);
}//end of function getPopularStories()

function getQVote(sCtrl){
objXmlHttp2 = null;sControl2 = sCtrl;
var sUrl2 = "/QVote.asp";
objXmlHttp2 = GetXmlHttpObject(stateChanged2);objXmlHttp2.open("GET", sUrl2 , true);objXmlHttp2.send(null);
}//end of function getQVote()

///Function called when asynchronous response received.
function stateChanged1(){
if (objXmlHttp1.readyState==4 || objXmlHttp1.readyState=="complete"){
var sData = objXmlHttp1.responseText;
document.getElementById(sControl1).innerHTML = sData;
}
}
function stateChanged2(){
if (objXmlHttp2.readyState==4 || objXmlHttp2.readyState=="complete"){
var sData = objXmlHttp2.responseText;
document.getElementById(sControl2).innerHTML = sData;
}}
startList=function()
{if(document.all&&document.getElementById)
{navRoot=document.getElementById("nav");for(i=0;i<navRoot.childNodes.length;i++)
{node=navRoot.childNodes[i];if(node.nodeName=="td")
{node.onmouseover=function()
{this.className+=" over";}
node.onmouseout=function()
{this.className=this.className.replace(" over","");}}}}}
window.onload=startList;

function SetHomeTabDefault(sTabName)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+3650);
                
     document.cookie = "EQTMTAB=" + escape(sTabName) + ";expires="+ exdate.toUTCString() + ";path=/";
     document.getElementById('spnDefault_' + sTabName).style.display = 'none';           
     return false;
}
function CheckCookie()
{
    if(sTabName == "")
    {
        c_name = "EQTMTAB";
        c_start=document.cookie.indexOf(c_name + "=");

        c_start=c_start + c_name.length+1;

        var c_value = unescape(document.cookie.substring(c_start));
        if(c_value.indexOf(";") > 0)
            c_value = c_value.substring(0, c_value.indexOf(";"));
            
        if(c_value == "MKT")
        {
           sTabName = "MktMon";
        }
        else if(c_value == "NSE")
        {
           sTabName = "NSE";              
        }   
        else if(c_value == "BSE")
        {
           sTabName = "BSE";
        }
    }

    if(sTabName == "BSE")
    {
        document.getElementById('spnDefault_BSE').style.display = 'none';
    }

    if(sTabName == "NSE")
    {
        document.getElementById('spnDefault_NSE').style.display = 'none';  
    }   
}
