// JavaScript Document




function indiaVolatility()
{
	var indexXmlHttp;
	
	indexXmlHttp = ajaxFunction(indexXmlHttp);
	
	if( typeof(indexXmlHttp) == "Boolean" )
	{
		if(indexXmlHttp == false)
		{
			return;
		}
	}
	
		
	indexXmlHttp.onreadystatechange=function(){indiaVolatilityGet(indexXmlHttp);};
		
	indiaVolatilityLoopFunction();
}

function indiaVolatilityGet(indexXmlHttp)
{
	var xmlHttp = indexXmlHttp;
	
	var greencolor = "#339933";
	var redcolor  = "#CC0000";

	if(xmlHttp.readyState==4)
    {
	  if( xmlHttp.responseXML != null )
	  {		
        var xmldocEle = xmlHttp.responseXML.documentElement;
			
	  
	    if(xmldocEle != null)
	    {	   
		    var eleArr = xmldocEle.getElementsByTagName('IndiaVIX');
		    if(eleArr != null)
		    {
			  	var length = eleArr.length;
				var i;
				
				
				var htmlText="";
				//htmlText = htmlText + "<span>&nbsp;</span>";  
				
				for(i=0; i<length; i++)
				{
			      var topEle = eleArr[i];
				  var childArr = topEle.childNodes;
				  var childLength = childArr.length;
				  var text = "";
				  
				  var name, ltp, chg, perChg, timeStamp;
				  //alert(topEle.nodeName);
				  
				  for(j=0; j<childLength; j++)
				  {
					var node = childArr[j];
					var nodename = node.nodeName;
					name = "India VIX";
						
					
					
					if( nodename == "PrevClose")
					{
						ltp = node.childNodes[0].nodeValue;
					}
					
					if( nodename == "Chg")
					{
						chg = node.childNodes[0].nodeValue;
					}
					
					if( nodename == "PerChg")
					{
						perChg = node.childNodes[0].nodeValue;
					}
					
					if( nodename == "TimeStamp")
					{
						timeStamp = node.childNodes[0].nodeValue;
					}
					/*if( nodename == "PerChg")
					{
						perChg = node.childNodes[0].nodeValue;
						
					}*/
					
				  }
				  
				    
				  

				  addRow("indiaTable", name, ltp, chg, perChg, timeStamp);
				  
				}
				
				
				
				
					
					
				//var indiaVolatilityEle = document.getElementById('indiaVolatility');
				//indiaVolatilityEle.innerHTML = htmlText;
				
				//alert(htmlText)

			
		    }//end if eleArr
			

			
	    }
	  
	  }
	  
    }

	
}



function indiaVolatilityLoopFunction()
{
	var indexXmlHttp;
	
	indexTimeout=setTimeout(function(){indiaVolatilityLoopFunction();},60000);
	//alert(indexURL);

    indexXmlHttp = ajaxFunction();

	indexXmlHttp.onreadystatechange=function(){indiaVolatilityGet(indexXmlHttp);};

	indexXmlHttp.open(hJ,w1_mM,true);
	indexXmlHttp.send(null);
	
	

}

 function addRow(tableId, name, ltp, chg, perChg, timeStamp){
    var tbody = document.getElementById
(tableId).getElementsByTagName("TBODY")[0];


	//Delete the existing rows
    var nodelist = tbody.childNodes;

	var reqdEle = document.getElementById(name+"ltp");
	var oldVal=null;
	if(reqdEle != null)
	{
		oldVal = reqdEle.childNodes[0].nodeValue;
		//alert(name + " " + oldVal);
	}
	
	var oldRowNode = null; /* document.getElementById(name+"Row"); */
	//alert(oldRowNode);
	
	if(nodelist!=null || nodelist!=undefined)
	{
		var nodecount = nodelist.length;
		var toContinue=true;
		for(i=0; i<nodecount; i++)
		{
			var node = nodelist[i];
			if( node.nodeName.toLowerCase == "TR".toLowerCase )
			{
				if(node.id==name+"Row")
					oldRowNode = node;
			}
		}
	}
	


    var row = document.createElement("TR")
	row.id=name+"Row";
    var td1 = document.createElement("TD")
    td1.appendChild(document.createTextNode(name))
	td1.id=name;
	
	
    var td2 = document.createElement("TD")
	td2.setAttribute('tdType', 'ltp');
	td2.id=name+"ltp";
    td2.appendChild (document.createTextNode(ltp))
	
	var td3 = document.createElement("TD")
	td3.setAttribute('tdType', 'chg');
	td3.id=name+"Chg";
	td3.appendChild (document.createTextNode(chg))
	
	var td4 = document.createElement("TD")
	td4.setAttribute('tdType', 'perChg');
	td4.id=name+"PerChg";
	td4.appendChild (document.createTextNode(perChg))
	
	
	
	var td5 = document.createElement("TD")
	td5.id=name+"timeStamp";
    td5.appendChild (document.createTextNode(timeStamp))
	td5.style.fontSize="7pt";

	//Create the new <a>
	var td6 = document.createElement("TD")
        //var aElem = document.createElement('a');
        //aElem.href="http://marketlive.in/charts/technical-charts.php?symbol=VIX";
        //Create a text node to hold the text of the <a>
        var aElemTN = document.createTextNode('Chart');
        //Append the <a> text node to the <a> element
        //aElem.appendChild(aElemTN);
        //Append the new link to the td element
        td6.appendChild(aElemTN);



	
	if(chg >0)
	{
		td4.style.color="#006600";
		td3.style.color="#006600";
	}
	else
	{
		td4.style.color="#CC0000";
		td3.style.color="#CC0000";
	}
	
	
    row.appendChild(td1);
    row.appendChild(td2);
	row.appendChild(td3);
	row.appendChild(td4);
	row.appendChild(td5);
	row.appendChild(td6);
    
	if(oldRowNode != null)
	{
		tbody.replaceChild(row, oldRowNode );
	}
	else
	{
		tbody.appendChild(row);
	}
	
	if(oldVal!=null)
		blinkColors(td2, oldVal, ltp, 0, "#EFF4FB"); 
  }
