﻿// JScript File
//Global Variables
var XmlHttp;

//Creating object of XMLHTTP For AJAX Method
function CreateXmlHttpNew()
	{
		//Creating object of XMLHTTP in IE
		try
		{
			XmlHttpFO = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttpFO = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpFO = null;	
			}
		}
		//Creating object of XMLHTTP in Mozilla and Safari 
		if(!XmlHttpFO && typeof XMLHttpRequest != "undefined") 
		{
			XmlHttpFO = new XMLHttpRequest();
		}
	}
	
	
	
	//For Getting Symbol Drop Down Contains fillCategory
	
	 function fillSymbol()
     {
   // alert("asd");		
	 var Excha = document.getElementById("Exchg");
	 var Symbol = document.getElementById("Symbol");		
    var ExpiryDate = document.getElementById("ExpDate");    
		
		CreateXmlHttpNew();
		document.body.style.cursor = "progress";
		var requestUrl = "GetSymbolAjax.aspx?timeStamp="+ new Date().getTime() +"&Excha="+Excha.value;
		//alert(requestUrl)
		if(XmlHttpFO)	{
					XmlHttpFO.onreadystatechange = function(){fillSymbolResp(Symbol)};
					XmlHttpFO.open("GET", requestUrl,  true);
					XmlHttpFO.send(null);
				}
		
 }
 
 //Called when response comes back from server Only For Symbol
function fillSymbolResp(ig_)
{

	// To make sure receiving response data from server is completed
	if(XmlHttpFO.readyState == 4)
	{
		
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpFO.status == 200)
		{		
			//alert(ig_)
			//var availSchemes   = document.getElementById(ig_);
			    for (var count = ExpiryDate.options.length-1; count >-1; count--)
	            {
		            ExpiryDate.options[count] = null;
	            }
			var strData = XmlHttpFO.responseText
			//alert(strData)
			if(strData != "") {	
			    
				var arrSchm = strData.split("|");
				ig_.length = 0; 	
				
				for(i=0; i<arrSchm.length-1; i++) {	
								
					var strSchm = arrSchm[i];
					var arrSchmCode = strSchm.split("~");
					
					ig_.options[i] = new Option();
					
					ig_.options[i].value = arrSchmCode[0];
					ig_.options[i].text = arrSchmCode[1];
				}
				
			}
			else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "Symbol not available";			
			}
			document.body.style.cursor = "auto";	
		}
		else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "server is not ready";
					document.body.style.cursor = "auto";		
		}
	}
}

//End of Symbol Function///////////////////////////////////////////////////////////


var XmlHttpCommNews;
function CreateXmlHttpCommNews()
	{
		//Creating object of XMLHTTP in IE
		try
		{
			XmlHttpCommNews = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttpCommNews = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpCommNews = null;	
			}
		}
		//Creating object of XMLHTTP in Mozilla and Safari 
		if(!XmlHttpCommNews && typeof XMLHttpRequest != "undefined") 
		{
			XmlHttpCommNews = new XMLHttpRequest();
		}
	}



    function CreateXmlHttpPop()
	{
		//Creating object of XMLHTTP in IE
		try
		{
			XmlHttpPop= new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttpPop = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpPop = null;	
			}
		}
		//Creating object of XMLHTTP in Mozilla and Safari 
		if(!XmlHttpPop && typeof XMLHttpRequest != "undefined") 
		{
			XmlHttpPop = new XMLHttpRequest();
		}
	}
	
   function GetNewsDetail(secId,SubSecId,NewsID,opt)
	{
    
		var NewsWin = document.getElementById("divNews").style.display='inline';
		 
		var currentDivObj;	
		
			currentDivObj = document.getElementById("TdNews");
		
			currentDivObj.innerHTML ="<img src=../App_Themes/Common/images/loading.gif>"; 
		
		CreateXmlHttpPop();
		document.body.style.cursor = "progress";
		var requestUrl = "../PopupNewsData.aspx?SecId="+ secId +"&SubSecId="+ SubSecId+"&NewsID="+NewsID+"&timeStamp="+new Date().getTime()+"opt="+opt;
		//alert(requestUrl);
		if(XmlHttpPop)	{
					XmlHttpPop.onreadystatechange = function(){getDetailsResp();};
					XmlHttpPop.open("GET", requestUrl,  true);
					XmlHttpPop.send(null);					
				}
	}
	
	
	function getDetailsResp()
	{
		// To make sure receiving response data from server is completed
		if(XmlHttpPop.readyState == 4)
		{
			// To make sure valid response is received from the server, 200 means response received is OK
			if(XmlHttpPop.status == 200)
			{
				
				
					document.getElementById("TdNews").innerHTML = XmlHttpPop.responseText;
				//alert(XmlHttpPop.responseText);
				document.body.style.cursor = "auto";
			}
			else
			{
				
					document.getElementById("TdNews").innerHTML = "<img src=../App_Themes/Common/images/ajax-loader.gif>";
				
			}
		}
	}
	
  function openCommHome(SecId,SubSecId)
    {
        
      
        
        	CreateXmlHttpCommNews();
		document.body.style.cursor = "progress";
		var requestUrl = "CommNewsAjax.aspx?timeStamp="+ new Date().getTime() +"&SecId="+SecId+"&SubSecID="+SubSecId;
		// alert(requestUrl)
		if(XmlHttpCommNews)	{
					XmlHttpCommNews.onreadystatechange = function(){getNewsRespCorpHome()};
					XmlHttpCommNews.open("GET", requestUrl,  true);
					XmlHttpCommNews.send(null);
				}
    }
    
    function getNewsRespCorpHome()
{

	if(XmlHttpCommNews.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
	
	//  alert(XmlHttpCommNews.status) 
	    
			var	Td_HotS = document.getElementById("Td_CommN");
		if(XmlHttpCommNews.status == 200)//
		{
		   var data=XmlHttpCommNews.responseText
		 
			Td_HotS.innerHTML = data;
		
				
			document.body.style.cursor = "auto";		
		}
		else
		{
			Td_HotS.innerHTML='There was a problem retrieving data from the server.';
			
			document.body.style.cursor = "auto";
		}
	}
}
// For Chart Data

 function HomeChart(ex,symbol)
{
 var Gold=document.getElementById("GoldS");
 var Silver=document.getElementById("SilverS");

        if (symbol=="GOLD" || symbol=="GLDPURMUMK")
	    {
	         document.getElementById("tdGold").className="SensexNiftyOn";
	        document.getElementById("tdSilver").className="SensexNiftyOff";
	       document.getElementById("GoldS").style.display="inline";
	        document.getElementById("SilverS").style.display="none";
	      
	    }
	    else
	    {
	     document.getElementById("tdGold").className="SensexNiftyOff";
	    document.getElementById("tdSilver").className="SensexNiftyOn";
	      document.getElementById("SilverS").style.display="inline";
	      document.getElementById("GoldS").style.display="none";
	      
	    }
    if (ex == "")
    {
   
	
	    if (symbol=="GOLD")
	    {
	       
	      
	       document.getElementById("GS").value = "GOLD"
	    }
	    else
	    {
	         
	        document.getElementById("GS").value = "SILVER"
	    }
    }
        else
        {
	        if(ex=="MCX")
	        {
	          

		        document.getElementById("Ech").value = "MCX"
	        }
	            else
	            {
	           
	          
	                
            	
		            document.getElementById("Ech").value = "NCDEX"
	            }
        	
        }
      
	        var requestUrl="Chart.aspx?sid=" + Math.random() + "&Exchange="+document.getElementById("Ech").value +"&Symbol="+symbol ;
	    document.getElementById("ChartComm").src=requestUrl;
	
	
}

function ShowGoldData() 
{ 

if(XmlHttpSymb.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpSymb.status == 200)
		{			
			var GoldData   = document.getElementById("Chart");
		var strData = XmlHttpSymb.responseText;
			//alert(strData);
			if(strData != "")
			{
				GoldData.innerHTML   =  strData;
			}
			document.body.style.cursor = "auto";	
		}
		else
		{
			GoldData.innerHTML = "There was a problem retrieving data from the server.";
			
			document.body.style.cursor = "auto";
		}
	}

	
} 

//For Getting Symbol Drop Down Contains 
	
	 function fillCategory()
    {//alert("Asd");
		
	    var Excha = document.getElementById("ctl00_ContentPlaceHolder1_Exchg");
	   var Symbol = document.getElementById("ctl00_ContentPlaceHolder1_ddlCategory");
		
 				
		CreateXmlHttpNew();
		document.body.style.cursor = "progress";
		var requestUrl = "GetCategoryAjax.aspx?timeStamp="+ new Date().getTime() +"&Excha="+Excha.value;
		//alert(requestUrl)
		if(XmlHttpFO)	{
					XmlHttpFO.onreadystatechange = function(){fillSymbolResp(Symbol)};
					XmlHttpFO.open("GET", requestUrl,  true);
					XmlHttpFO.send(null);
				}
		
    }
 
 //Called when response comes back from server Only For Symbol
function fillSymbolResp(ig_)
{

	// To make sure receiving response data from server is completed
	if(XmlHttpFO.readyState == 4)
	{
		
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpFO.status == 200)
		{		
			//alert(ig_)
			//var availSchemes   = document.getElementById(ig_);
			var strData = XmlHttpFO.responseText
			//alert(strData)
			if(strData != "") {	
			    
				var arrSchm = strData.split("|");
				ig_.length = 0; 	
				
				for(i=0; i<arrSchm.length-1; i++) {	
								
					var strSchm = arrSchm[i];
					var arrSchmCode = strSchm.split("~");
					
					ig_.options[i] = new Option();
					
					ig_.options[i].value = arrSchmCode[0];
					ig_.options[i].text = arrSchmCode[1];
				}
				
			}
			else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "Category not available";			
			}
			document.body.style.cursor = "auto";	
		}
		else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "server is not ready";
					document.body.style.cursor = "auto";		
		}
	}
}

//End of Symbol Function///////////////////////////////////





//For Getting Expiry Date

function GetExpDate()
 {
        var Excha = document.getElementById("Exchg");
  		var Symbol = document.getElementById("Symbol");
 		var ExpiryDate = document.getElementById("ExpDate"); 
 				
		CreateXmlHttpNew();
		document.body.style.cursor = "progress";
		var requestUrl = "GetExpDateAjax.aspx?timeStamp="+ new Date().getTime() +"&Excha="+Excha.value +"&Symbol="+Symbol.value;
	
		if(XmlHttpFO)	{
					XmlHttpFO.onreadystatechange = function(){getDateResp(ExpiryDate)};
					XmlHttpFO.open("GET", requestUrl,  true);
					XmlHttpFO.send(null);
				}
		
 }
 
 //Called when response comes back from server Only For Symbol
function getDateResp(ig_)
{

	// To make sure receiving response data from server is completed
	if(XmlHttpFO.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpFO.status == 200)
		{
			//alert(ig_)
			//var availSchemes   = document.getElementById(ig_);
			var strData = XmlHttpFO.responseText
			//alert(strData);
			if(strData != "") {	
				var arrSchm = strData.split("|");
				ig_.length = 0; 	
				for(i=0; i<arrSchm.length-1; i++) {	
					var strSchm = arrSchm[i];
					var arrSchmCode = strSchm.split("~");
					ig_.options[i] = new Option();
					ig_.options[i].value = arrSchmCode[0];
					ig_.options[i].text = arrSchmCode[1];
				}
			}
			else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "Date not available";			
			}
			document.body.style.cursor = "auto";	
		}
		else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "server is not ready";
					document.body.style.cursor = "auto";		
		}
	}
}


function ClearAndSetExpListItems(countryNode)
{
    var stateList = document.getElementById("ExpDate");
	//Clears the state combo box contents.
	for (var count = stateList.options.length-1; count >-1; count--)
	{
		stateList.options[count] = null;
	}

	var stateNodes = countryNode.getElementsByTagName('ExpDate');
	var textValue; 
	var optionItem;
	//Add new states list to the state combo box.
	for (var count = 0; count < stateNodes.length; count++)
	{
   		textValue = GetInnerText(stateNodes[count]);
		optionItem = new Option( textValue, textValue,  false, false);
		stateList.options[stateList.length] = optionItem;
	}
}
// End of Expiry Date Funtion////////////////

/*VolumeValue*/
function ShowVolValData(typ)
{

  if(typ=="Vol")
  {
  document.getElementById("Vol").className="RedBoldDer"
  document.getElementById("Val").className="UnselectBoldDer"
  }
  else
  {
   document.getElementById("Val").className="RedBoldDer"
  document.getElementById("Vol").className="UnselectBoldDer"
  }
  
   LookUpData1(typ)

}

function LookUpData1(typ)
{ 

  str = document.getElementById("ctl00_ContentPlaceHolder1_VolumeValue1_Dp_Value1").value;

        if (str=="MCX")
        {
        	    
	        ShowBseGL1('MCX',typ)
	         
        }
        else
        {
       	 
	       ShowBseGL1('NCDEX',typ)
	
	       
	      }
	
} 
var XmlHttpGL1;
function CreateXmlHttpGL1()
	{
		//Creating object of XMLHTTP in IE
		try
		{
			XmlHttpGL1 = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttpGL1 = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpGL1 = null;	
			}
		}
		//Creating object of XMLHTTP in Mozilla and Safari 
		if(!XmlHttpGL1 && typeof XMLHttpRequest != "undefined") 
		{
			XmlHttpGL1 = new XMLHttpRequest();
		}
	}
	

 function ShowBseGL1(str,glctrl)
{


     if(str=="" && glctrl=="Vol")
     {
        document.getElementById("MCXID1").value = "MCX"
	      document.getElementById("VV1").value = "Vol"
	  }
	   if(str=="" && glctrl=="Val")
     {
        document.getElementById("MCXID1").value = "MCX"
	      document.getElementById("VV1").value = "Val"
	  }
 
     if(str=="MCX" && glctrl=="Vol")
     {
    
        document.getElementById("MCXID1").value = "MCX"
	      document.getElementById("VV1").value = "Vol"
	  }
	 if(str=="MCX" && glctrl=="Val")
	  {
	    document.getElementById("MCXID1").value = "MCX"
	     document.getElementById("VV1").value = "Val"
	    
	  }
	  if(str=="NCDEX" && glctrl=="Vol")
	  {
	 
	    document.getElementById("MCXID1").value = "NCDEX"
	     document.getElementById("VV1").value = "Vol"
	    
	  }
	  if(str=="NCDEX" && glctrl=="Val")
	  {
	    document.getElementById("MCXID1").value = "NCDEX"
	     document.getElementById("VV1").value = "Val"
	    
	  }
	    
	 
   
        CreateXmlHttpGL1();
        

	var requestUrl="AjaxVolumeValue.aspx?sid=" + Math.random() + "&Exchg="+document.getElementById("MCXID1").value+"&typeGL="+document.getElementById("VV1").value;

	
	
	if(XmlHttpGL1)	
			{
					//alert("hi");
					XmlHttpGL1.onreadystatechange = function(){ShowShowGLData1();}; 
					XmlHttpGL1.open("GET", requestUrl,  true);
					XmlHttpGL1.send(null);
			}
	
}

function ShowShowGLData1() 
{ 
//alert(XmlHttpGL.status);
if(XmlHttpGL1.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpGL1.status == 200)
		{			
			var ShowGLData1   = document.getElementById("ShowGLData1");
		var strData = XmlHttpGL1.responseText;
		//alert(strData);
			if(strData != "")
			{
				ShowGLData1.innerHTML   =  strData;
			}
			document.body.style.cursor = "auto";	
		}
		else
		{
			ShowGLData1.innerHTML = "There was a problem retrieving data from the server.";
			
			document.body.style.cursor = "auto";
		}
	}

	
} 

/*GainersLosers*/

function LookUpData(str,typ)
{ 


        if (str=="MCX")
        {
        	
	     
	       
	        ShowBseGL('MCX','G')
        }
        else
        {
       	        
	     
	      
	       ShowBseGL('NCDEX','G')
        }
	
} 
var XmlHttpGL;
function CreateXmlHttpGL()
	{
		//Creating object of XMLHTTP in IE
		try
		{
			XmlHttpGL = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttpGL = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpGL = null;	
			}
		}
		//Creating object of XMLHTTP in Mozilla and Safari 
		if(!XmlHttpGL && typeof XMLHttpRequest != "undefined") 
		{
			XmlHttpGL = new XMLHttpRequest();
		}
	}
	

 function ShowBseGL(ex,glctrl)
{

 if (ex == "")
    {
       ex=="MCX";
         if (glctrl=="G")
	    {
	        document.getElementById("GL").value = "G"
	    }
	    else
	    {
	    document.getElementById("GL").value = "L"
	    }
	 }
	 else
        {
	        if(ex=="MCX")
	        {

		        document.getElementById("MCXID").value = "MCX"
	        }
	        else
	        {
        	
		        document.getElementById("MCXID").value = "NCDEX"
	        }
        	
        }
   
        CreateXmlHttpGL();
        //alert(document.getElementById("GL").value);

	var requestUrl="AjaxGainerLoser.aspx?sid=" + Math.random() + "&Exchg="+document.getElementById("MCXID").value+"&typeGL="+document.getElementById("GL").value;
	//alert(requestUrl);
	
	
	if(XmlHttpGL)	
			{
					//alert("hi");
					XmlHttpGL.onreadystatechange = function(){ShowShowGLData();}; 
					XmlHttpGL.open("GET", requestUrl,  true);
					XmlHttpGL.send(null);
			}
	
}

function ShowShowGLData() 
{ 
//alert(XmlHttpGL.status);
if(XmlHttpGL.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpGL.status == 200)
		{			
			var ShowGLData   = document.getElementById("ShowGLData");
		var strData = XmlHttpGL.responseText;
		//alert(strData);
			if(strData != "")
			{
				ShowGLData.innerHTML   =  strData;
			}
			document.body.style.cursor = "auto";	
		}
		else
		{
			ShowGLData.innerHTML = "There was a problem retrieving data from the server.";
			
			document.body.style.cursor = "auto";
		}
	}

	
} 


function CreateXmlHttp1()
	{
		//Creating object of XmlHttp in IE
		try
		{
			XmlHttp1 = new ActiveXObject("Msxml2.XmlHttp");
		}
		catch(e)
		{
			try
			{
				XmlHttp1 = new ActiveXObject("Microsoft.XmlHttp");
			} 
			catch(oc)
			{
				XmlHttp1 = null;	
			}
		}
		//Creating object of XmlHttp in Mozilla and Safari 
		if(!XmlHttp1 && typeof XmlHttpRequest != "undefined") 
		{
			XmlHttp1 = new XmlHttpRequest();
		}
	}
 
 function CreateXmlHttp()
	{
		//Creating object of XmlHttp in IE
		try
		{
			XmlHttp1 = new ActiveXObject("Msxml2.XmlHttp");
		}
		catch(e)
		{
			try
			{
				XmlHttp1 = new ActiveXObject("Microsoft.XmlHttp");
			} 
			catch(oc)
			{
				XmlHttp1 = null;	
			}
		}
		//Creating object of XmlHttp in Mozilla and Safari 
		if(!XmlHttp1 && typeof XmlHttpRequest != "undefined") 
		{
			XmlHttp1 = new XmlHttpRequest();
		}
	}
	
 function HomeTicker(ex,typ)
{
    if (ex == "")
    {
	
	    if (typ=="S")
	    {
	
	    document.getElementById("SF").value = "S"
	    }
	    else
	    {
	
	    document.getElementById("SF").value = "F"
	    }
    }
        else
        {
	        if(ex=="MCX")
	        {

		        document.getElementById("Ech").value = "MCX"
	        }
	        else
	        {
        	
		        document.getElementById("Ech").value = "NCDEX"
	        }
        	
        }
        CreateXmlHttp1();
	var requestUrl="CommTicker.aspx?sid=" + Math.random() + "&Exchg="+document.getElementById("Ech").value+"&type="+document.getElementById("SF").value
	
	
	if(XmlHttp1)	
			{
					//alert("hi");
					XmlHttp1.onreadystatechange = function(){ShowTickerData();}; 
					XmlHttp1.open("GET", requestUrl,  true);
					XmlHttp1.send(null);
			}
	
}

function ShowTickerData() 
{ 

if(XmlHttp1.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp1.status == 200)
		{		
		var arrCol,Time,Code,CompName,ClPrice,DiffVal,DiffImg;
			var ExchgDet="",stkDet="";	
			var TikerData   = document.getElementById("TikerData");
		var strData = XmlHttp1.responseText;
			
			if(strData != "")
			    var arrNse = strData.split("|");
			   // alert(arrNse);
				for(var i=0; i<arrNse.length-1; i++)
				 {
					arrCol = arrNse[i].split("~");
					//alert(arrCol[0]);
						CompName = arrCol[0];
						ClPrice  = arrCol[1];
						DiffVal  = arrCol[2];
						
					if(i==0)
					ExchgDet = " <span  class=DataCommL>"+ CompName +"</span><span  class=DataCommR>" + " &nbsp; "+ ClPrice+"&nbsp;&nbsp; "  +"<b>"+ DiffVal+ "</b>"+"</span> </span>&nbsp;&nbsp;&nbsp;";
					else 
					stkDet += "<span  class=DataCommL>" + CompName +"</span><span  class=DataCommR>" + " &nbsp; "+ ClPrice +"&nbsp;&nbsp;" +"<b>"+ DiffVal+ "</b>"+"</span>  &nbsp;</span>&nbsp;";						
						
				}
				
				
				
				TikerData.innerHTML   =  "<marquee onmouseover='this.stop();' onmouseout='this.start();' trueSpeed scrollAmount='1' scrollDelay='40'  direction='Left' loop='repeat' width='100%'>" + ExchgDet + stkDet + "</marquee>";
			
			document.body.style.cursor = "auto";	
		}
		else
		{
			TikerData.innerHTML = "There was a problem retrieving data from the server.";
			
			document.body.style.cursor = "auto";
		}
	}

	
} 