﻿// JScript File
function Browser() {
  var ua, s, i;
  this.isIE    = false;
  this.isNS    = false;
  this.version = null;
  ua = navigator.userAgent;
  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.
  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}
var browser = new Browser();
var clockTimeoutID;


var XmlHttp;
var XmlHttpTicker;

//Creating object of XMLHTTP For AJAX Method
function CreateXmlHttpNew()
	{
		//Creating object of XMLHTTP in IE
		try
		{
			XmlHttp_One = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttp_One = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttp_One = null;	
			}
		}
		//Creating object of XMLHTTP in Mozilla and Safari 
		if(!XmlHttp_One && typeof XMLHttpRequest != "undefined") 
		{
			XmlHttp_One = new XMLHttpRequest();
		}
	}
	

function CreateXmlHttpTicker()
{
	try
	{
		XmlHttpTicker = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpTicker = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			XmlHttpTicker = null;				
		}
	}
	if(!XmlHttpTicker && typeof XMLHttpRequest != "undefined")
	{
		XmlHttpTicker = new XMLHttpRequest();
	}
}


function getGainLose(Exch,Opt)
{

CreateXmlHttpNew();
var Td_Id=document.getElementById("Td_id");

var requestUrl="AjaxTopLose.aspx?Exch="+Exch+"&Opt="+Opt+"&timeStamp="+new Date().getTime();


	if(XmlHttp_One)
	{
		//alert(requestUrl);
		XmlHttp_One.onreadystatechange=function(){ResponsegetGainLose();};
		XmlHttp_One.open("GET",requestUrl,true);
		XmlHttp_One.send(null);
	}
	
}



				
function ResponsegetGainLose()
{

var Td_Id=document.getElementById("td_id");
			
	if(XmlHttp_One.readyState==4)
	{
	
		if(XmlHttp_One.status == 200)
		{
			
			Td_Id.innerHTML=XmlHttp_One.responseText;
	
			    
		}
		else
		{
		Td_Id.innerHTML="Server is not ready to response !";
		}
	
	}
	
}
// Strat ticker coding


//AttachTicker
function AttachTicker()
{

		
		
	  
	   window.opener.document.getElementById("Tr_Attach").style.display="inline";		 

	 self.close();
}

//DetachTicker
function DetachTicker()
{

     //document.getElementById("Tr_Attach").style.display="none"	
//     var strURL = window.location.href;
//		
//	 document.getElementById("Td_AttDeta").style.display="none";
//	  document.getElementById("DetachNews").style.display="none";
//    document.getElementById("AttachNews").style.display="inline";
	 var newWin=window.open("AttachTicker.aspx?&Chk=yes",'s','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,width=716px,height=50px,screenX=0,screenY=0');	
	 newWin.focus();	 
}	 

 function TickerLeft(){
        document.all.MarqueeNews.direction = "left";
    }
    function TickerRight(){
        document.all.MarqueeNews.direction = "right";
    }
    
function openupDisclaim()
{var isdis=window.open("../Disclaimer.aspx","claim","toolbar=no,location=no,menubar=no,scrollbars=yes,width=600,height=300")}
function openupPrivacy()
{var isdis=window.open("../PrivacyPolicy.aspx","claim","toolbar=no,location=no,menubar=no,scrollbars=yes,width=600,height=300")}





function getTickerData(Exchg)
	{
	
	if(Exchg != "")
	{
	
	   if(Exchg == "BSE")
	   {
	  document.getElementById("Bseimage").style.backgroundImage = "url(App_Themes/CommonTheme/Images/hp17.gif)";
	  document.getElementById("Nseimage").style.backgroundImage = "url(App_Themes/CommonTheme/Images/hp20.gif)";
	  document.getElementById("Foimage").style.backgroundImage = "url(App_Themes/CommonTheme/Images/hp21.gif)";

	    document.getElementById("Bseimage").style.cursor="default";
	    document.getElementById("Nseimage").style.cursor="Hand";
	    document.getElementById("Foimage").style.cursor="Hand";
	   }
	   else
	   {
	      if(Exchg == "NSE")
	      {
	  document.getElementById("Bseimage").style.backgroundImage = "url(App_Themes/CommonTheme/Images/hp18.gif)";
	  document.getElementById("Nseimage").style.backgroundImage = "url(App_Themes/CommonTheme/Images/hp23.gif)";
	  document.getElementById("Foimage").style.backgroundImage = "url(App_Themes/CommonTheme/Images/hp21.gif)";
	      
	        document.getElementById("Bseimage").style.cursor="Hand";
	        document.getElementById("Nseimage").style.cursor="default";
	        document.getElementById("Foimage").style.cursor="Hand";
	        
	      }
	      else
	      {
	      
	  document.getElementById("Bseimage").style.backgroundImage = "url(App_Themes/CommonTheme/Images/hp18.gif)";
	  document.getElementById("Nseimage").style.backgroundImage = "url(App_Themes/CommonTheme/Images/hp20.gif)";
	  document.getElementById("Foimage").style.backgroundImage = "url(App_Themes/CommonTheme/Images/hp22.gif)";

	        document.getElementById("Bseimage").style.cursor="Hand";
	      document.getElementById("Nseimage").style.cursor="Hand";
	      document.getElementById("Foimage").style.cursor="default";
	      }
	   }
	   
	}
	
	var strURL = window.location.href;
	if(strURL.indexOf("&Chk") == -1)
		{
		
		 
 document.getElementById("Td_AttDeta").innerHTML='<span onclick="DetachTicker();">DETACH</span>';
		}
		else
		
		{
		
		 document.getElementById("Td_AttDeta").innerHTML='<span onclick="AttachTicker();">ATTACH</span>';
		
		}	
	
		CreateXmlHttpTicker();
		document.body.style.cursor = "progress";
		//document.getElementById("MarqueeId").innerHTML = " <img src='App_Themes/CommonTheme/images/ajax-loader.gif'>";
		//if(Exchg=="NSE"){document.NseTickImg.src="../images/NSEon.gif";document.BseTickImg.src="../images/BSEoff.gif";}else{document.NseTickImg.src="../images/NSEoff.gif";document.BseTickImg.src="../images/BSEon.gif";}
		var requestUrl = "AjaxTickerData.aspx?Exchange="+ Exchg +"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
		
		if(XmlHttpTicker){
			XmlHttpTicker.onreadystatechange = function(){getDataResponse(Exchg);};
			XmlHttpTicker.open("GET", requestUrl,  true);
			XmlHttpTicker.send(null);
		}
}
function getDataResponse(Exchg)
{
//alert(XmlHttp.status);	
	if(XmlHttpTicker.readyState == 4)
	{	
	
		if(XmlHttpTicker.status == 200)
		{	
				
		
			var arrCol,Time,Code,CompName,ClPrice,DiffVal,DiffImg,classhead;
			var ExchgDet="",stkDet="";
			var MarqueeId = document.getElementById("MarqueeId");
			var TickerData = XmlHttpTicker.responseText;
						
			if(TickerData != "")
			var arrRow = TickerData.split("|");
				for(i=0; i<arrRow.length-1; i++)
				 {
					arrCol = arrRow[i].split("~");
						CompName = arrCol[1];
						ClPrice  = arrCol[2];
						DiffVal  = arrCol[3];
						if(DiffVal>0) 
						{
							//DiffImg= "<img src='../images/up.gif'>";
							clss = "<span class='Green'>" ;
							classhead="Green";
						}
						else if(DiffVal<0) 
						{							
							//DiffImg="<img src='../images/down.gif'>";
							clss = "<span class='Red'>" ;
							classhead="Green";
						}
						else 
						{
							//DiffImg= "<img src='../images/eq.gif'>";
							clss = "<span class='Blue'>"	;	
							classhead="Green";			
						}
						
						//if(i==0)ExchgDet = arrCol[0] +" &nbsp; "+ CompName +": "+ ClPrice +" ["+ DiffVal +"] "+ DiffImg +" &nbsp; ";else stkDet += "<a href='getQuotes.aspx?code="+ arrCol[0] +"' class=TickerLink>" + CompName +"</a>: "+ ClPrice +" ["+ DiffVal +"] "+ DiffImg +" &nbsp; ";    href='../profile/CorpInfo.aspx?id=1&code="+ arrCol[0] +"'
						//if(i==0)ExchgDet = "<span class='BlackNormal'>" + arrCol[0] +" &nbsp; "+ CompName +": "+"<span  class=BlackNormal>" + ClPrice+"&nbsp;"+ clss +" ["  +"<b>"+ DiffVal+ "</b>"+"]</span> </span>&nbsp;&nbsp;&nbsp;";else stkDet += "<span class='TickerLink'>" + "<a href='../companyprofile/QuoteFinder.aspx?id=1&Fincode="+arrCol[0]+"'><span  class=BlackNormal>" + CompName +"</span></a>: " + "<span  class=BlackNormal>" + ClPrice +"&nbsp;"+ clss +" [" +"<b>"+ DiffVal+ "</b>"+"]</span>  &nbsp;</span>&nbsp;";						
						if(i==0)ExchgDet = "<span class='"+ classhead +"' >" + arrCol[0] +" &nbsp; "+ CompName +":"+"<span  class='"+ classhead +"'>" + ClPrice+"&nbsp;"+ clss +" [ "+ DiffVal+ "%"+"]</span> </span>&nbsp;&nbsp;&nbsp;";else stkDet += "<span  class='"+ classhead +"'>" + CompName +":</span><span  class='"+ classhead +"'>" + ClPrice +"&nbsp;"+ clss +" ["+ DiffVal+ "]</span>  &nbsp;</span>&nbsp;";						
						
				}
				
				if(browser)
					MarqueeId.innerHTML = "<marquee id='MarqueeNews' onmouseover='this.stop();' onmouseout='this.start();' trueSpeed scrollAmount='1' scrollDelay='30' direction='left' loop='repeat' width='100%'>" + ExchgDet + stkDet + "</marquee>";
					
				else
					MarqueeId.innerHTML = ExchgDet + stkDet;				
				document.body.style.cursor = "auto";
				ExchngTimeClock(Exchg);
		}
		
		//else
			//MarqueeId.innerHTML = "<img src='../CommonImgs/loading1.gif'>";
	}
}

function ExchngTimeClock(Exchg) {
	 var time = new Date()
	 var hour = time.getHours()
	 if (hour >= 10 && hour <= 20)
			  clockTimeoutID = setTimeout("getTickerData('"+ Exchg +"')",600000);
	}













// End 







// Functions for showing and hiding divs


var tempX = 0;
 var tempY = 0;
 var m_show = 0;
 var f_sc_id = "";
 var f_sc_dispid = "";
 var f_sc_comp = "";
 var f_topic_id = 0;
 var f_buy_id =0;
// smart quotes/buy/ sell/company snapshot/compan/ news/financial summary/chartin
 //var m_urls = Array('../Company_Info/DetailedQuotes.aspx?id=25','https://trade.idbicapital.com/','../Profiles/shareprice.asp?pageOpt=8','../Company_Info/Comp_Snapshot.aspx?id=26','../Company_Info/ScripSearch.aspx?id=33','../profile/FinanceSummary.aspx?mno=4&index=0&id=16','../Technical_Research/Adv_Decline.aspx');
 //var m_urls = Array('../KrcWeb/CompanyProfile/QuaterlyResults.aspx?id=8','../KrcWeb/CompanyProfile/PLAccount.aspx?id=5','../KrcWeb/CompanyProfile/BalanceSheet.aspx?id=4','../CompanyProfile/ChartDisplay.aspx?id=9');


 //setInterval("hide_popup1()",1000);
 
 var IE = document.all?true:false
 
 if (!IE) document.captureEvents(Event.MOUSEMOVE)
 document.onmousemove = getMouseXY;
 
 function getMouseXY(e) 
 {
 	if(IE)
 	{
 	    tempX = event.clientX + document.body.scrollLeft;
 		tempY = event.clientY + document.body.scrollTop;
 	}
 	else
 	{
 		tempX = e.pageX;
 	    tempY = e.pageY;
 	}
 	return true;
 }
 
 function show_popup1(m_im_id, m_im_shortdesc, m_im_desc, m_ff_desc, m_ff_id, m_fundclass)
 {
 	f_im_id = m_im_id;
 	f_im_shortdesc = m_im_shortdesc;
 	f_im_desc = m_im_desc;
 	f_ff_desc = m_ff_desc;
 	f_ff_id = m_ff_id;
 	f_fundclass = m_fundclass;

 	//document.getElementById("head1").innerHTML = " Company Profile " ;
 	document.getElementById("popup").style.left = tempX + "px";
 	document.getElementById("popup").style.top = tempY + "px";
 	document.getElementById("popup").style.visibility = "visible";
 	m_show = 1;
 }
 
 function hide_popup1()
 {

 	if(m_show == 0)
 	{
 		document.getElementById("popup").style.visibility = "hidden";
 	}
 }
// function id_click(m_id)
// {
// 	//alert(m_urls[m_id-1] + "+" + f_im_id + "+" + f_im_desc + "+" + f_ff_desc + "+" + f_ff_id + "+" + f_fundclass);
// 	//return false;

// 	if(m_id == 1)
// 		window.location = m_urls[m_id-1] +"&fincode=" + f_im_id;
// 	else if(m_id == 2)
// 	    window.location = m_urls[m_id-1]+"&fincode=" + f_im_id;
// 	else if(m_id == 3)
// 		window.location = m_urls[m_id-1] +"&fincode=" + f_im_id;
// 	
//  	
// }
 
 function ShowDiv()
        {
        document.getElementById("popup").style.visibility = "visible";
        } 
 
 
         function show_popup(m_im_id, m_im_shortdesc, m_im_desc, m_ff_desc, m_ff_id, m_fundclass)
         {
         
 	        f_im_id = m_im_id;
 	        f_im_shortdesc = m_im_shortdesc;
 	        f_im_desc = m_im_desc;
 	        f_ff_desc = m_ff_desc;
 	        f_ff_id = m_ff_id;
 	        f_fundclass = m_fundclass;

 	        //document.getElementById("head1").innerHTML = " Company Profile " ;
 	        document.getElementById("popup").style.left = tempX + "px";
 	        document.getElementById("popup").style.top = tempY + "px";
 	        document.getElementById("popup").style.visibility = "visible";
 	        m_show = 1;
         }