﻿// 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 url;
var containerid="contentarea";
var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""


var browser = new Browser();
 var dragObj = new Object();
dragObj.zIndex = 0;
function dragStart(event, id) {

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}
//Global Variables
var XmlHttp;

//Creating object of XMLHTTP For AJAX Method
function CreateXmlHttp()
	{
		//Creating object of XMLHTTP in IE
		try
		{
			XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{  
				XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttp = false;	
			}
		}
		//Creating object of XmlHttp in Mozilla and Safari 
		if (!XmlHttp && typeof XMLHttpRequest!='undefined') 
		{
	        try 
	        {
		        XmlHttp = new XMLHttpRequest();
	        } 
	        catch (e) 
	        {
		        XmlHttp=false;
	        }
        }
        if (!XmlHttp && window.createRequest) 
        {
	        try 
	        {
		        XmlHttp = window.createRequest();
	        } 
	        catch (e)
	        {
		        XmlHttp=false;
	        }
        }
	
	}
	var XmlHttpTick;

//Creating object of XMLHTTP For AJAX Method
function CreateXmlHttpTick()
	{
		//Creating object of XMLHTTP in IE
		try
		{
			XmlHttpTick = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{  
				XmlHttpTick = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpTick = false;	
			}
		}
		//Creating object of XmlHttp in Mozilla and Safari 
		if (!XmlHttpTick && typeof XMLHttpRequest!='undefined') 
		{
	        try 
	        {
		        XmlHttpTick = new XMLHttpRequest();
	        } 
	        catch (e) 
	        {
		        XmlHttpTick=false;
	        }
        }
        if (!XmlHttpTick && window.createRequest) 
        {
	        try 
	        {
		        XmlHttpTick = window.createRequest();
	        } 
	        catch (e)
	        {
		        XmlHttpTick=false;
	        }
        }
	
	}
	
		
function CreateXmlHttpVV()
	{
		//Creating object of XmlHttp in IE
		try
		{
			XmlHttpVV = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{  
				XmlHttpVV = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpVV = false;	
			}
		}
		//Creating object of XmlHttp in Mozilla and Safari 
		if (!XmlHttpVV && typeof XMLHttpRequest!='undefined') 
		{
	        try 
	        {
		        XmlHttpVV = new XMLHttpRequest();
	        } 
	        catch (e) 
	        {
		        XmlHttpVV=false;
	        }
        }
        if (!XmlHttpVV && window.createRequest) 
        {
	        try 
	        {
		        XmlHttpVV = window.createRequest();
	        } 
	        catch (e)
	        {
		        XmlHttpVV=false;
	        }
        }
	
	}


function CreateXmlHttpVVol()
	{
		//Creating object of XmlHttp in IE
		
        try
		{
			XmlHttpVVol = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{  
				XmlHttpVVol = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpVVol = false;	
			}
		}
		//Creating object of XmlHttp in Mozilla and Safari 
		if (!XmlHttpVVol && typeof XMLHttpRequest!='undefined') 
		{
	        try 
	        {
		        XmlHttpVVol = new XMLHttpRequest();
	        } 
	        catch (e) 
	        {
		        XmlHttpVVol=false;
	        }
        }
        if (!XmlHttpVVol && window.createRequest) 
        {
	        try 
	        {
		        XmlHttpVVol = window.createRequest();
	        } 
	        catch (e)
	        {
		        XmlHttpVVol=false;
	        }
        }
	}
	
	// For DeriHomeGLVaVu Control (Gainers & Losers) AND (Volume & value)


function ExchngTimeClock(ex,typ)
 {
	 var time = new Date()
	 var hour = time.getHours()
	 if (hour >= 10 && hour <= 20)
			  clockTimeoutID = setTimeout("HomeTicker('"+ ex +"','"+ typ +"')",600000);
	}


//********** Main Function (Onclick)***********//
function LookUpData(str,typ)
{ 
//alert(str);   
        document.getElementById("hdType").value = str;
    	var Type = document.getElementById("Select1").value;
        if (str=="FUT")
        {
            ShowVolumeValue('FUT','Val');
	        ShowBseGL('FUT','G');
        }
        else
        {
            ShowVolumeValue('OPT','Val');
	        ShowBseGL('OPT','G');
	    }
 } 
//********** End of main function ************//


 function ShowBseGL(ex,glctrl)
{
 var requestUrl="AjaxGainLose.aspx?sid=" + Math.random() + "&Exchg="+ex+"&typeGL="+glctrl;
	derajaxpage(1,requestUrl,"ShowGLData");
}


function ShowVolumeValue(ex,glctrl)
{     var requestUrl="AjaxValueVol.aspx?sid=" + Math.random() + "&Exchg="+ex+"&typeGL="+glctrl;
	   derajaxpage(1,requestUrl,"ShowVVData");
}

//*****************end*****************//
	

function futopt(val)
{
    if(val=='FUT')
    {
        // document.getElementById("Blend").style.filter = "blendTrans(Duration=1.0,Transition=0)";
             ShowVolumeValue('FUT','Vol');
	        ShowBseGL('FUT','G')
        document.getElementById('tdFUT').src="../App_Themes/Common/images/deriv_Future.gif";
        document.getElementById('tdOPT').src="../App_Themes/Common/images/deriv_option.gif";
           
        
    }
    else
    {
     //document.getElementById("Blend").style.filter = "blendTrans(Duration=1.0,Transition=0)";
                ShowVolumeValue('OPT','Vol');
	             ShowBseGL('OPT','G')
       
        document.getElementById('tdFUT').src="../App_Themes/Common/images/deriv_Future.gif";
        document.getElementById('tdOPT').src="../App_Themes/Common/images/deriv_option.gif";
       
       
       
    return true;
}


return true;
}


function CreateXmlHttpNews()
	{
		//Creating object of XmlHttp in IE
		try
		{
			XmlHttpNews = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{  
				XmlHttpNews = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpNews = false;	
			}
		}
		//Creating object of XmlHttp in Mozilla and Safari 
		if (!XmlHttpNews && typeof XMLHttpRequest!='undefined') 
		{
	        try 
	        {
		        XmlHttpNews = new XMLHttpRequest();
	        } 
	        catch (e) 
	        {
		        XmlHttpNews=false;
	        }
        }
        if (!XmlHttpNews && window.createRequest) 
        {
	        try 
	        {
		        XmlHttpNews = window.createRequest();
	        } 
	        catch (e)
	        {
		        XmlHttpNews=false;
	        }
        }
	}	
 function GetNiftyOI(){var requestUrl="AjaxNiftyOI.aspx?sid=" + Math.random();derajaxpage(1,requestUrl,'Td_NiftyOI')}
function HomeDerNews(){var requestUrl =  "../Derivatives/AjaxDerHomeNews.aspx";derajaxpage(1,requestUrl,'TdDerNews')}

function CreateXmlHttpNew1()
	{
		//Creating object of XMLHTTP in IE
		try
		{
			XmlHttpFO = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{  
				XmlHttpFO = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttpFO = false;	
			}
		}
		//Creating object of XmlHttp in Mozilla and Safari 
		if (!XmlHttpFO && typeof XMLHttpRequest!='undefined') 
		{
	        try 
	        {
		        XmlHttpFO = new XMLHttpRequest();
	        } 
	        catch (e) 
	        {
		        XmlHttpFO=false;
	        }
        }
        if (!XmlHttpFO && window.createRequest) 
        {
	        try 
	        {
		        XmlHttpFO = window.createRequest();
	        } 
	        catch (e)
	        {
		        XmlHttpFO=false;
	        }
        }
	}
	
    function openNews(NewsID)
    {
 
       //  document.getElementById("NewsDetails").style.display="inline";
        
        	CreateXmlHttpNew1();
        	document.getElementById("divNews").style.display = "inline";
		document.body.style.cursor = "progress";
		
		var requestUrl = "DerNews.aspx?timeStamp="+ new Date().getTime() +"&SecId=&SubSecID=&NewsID="+NewsID;
		//alert(requestUrl)
		if(XmlHttpFO)	{
					XmlHttpFO.onreadystatechange = function(){getNewsResp()};
					XmlHttpFO.open("GET", requestUrl,  true);
					XmlHttpFO.send(null);
				}
    }
    
    function getNewsResp()
{

	if(XmlHttpFO.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		
	   // alert(XmlHttpFO.status)
		if(XmlHttpFO.status == 200)//
		{
		//alert(NewTd.innerHTML);
		
			//var NewTd = document.getElementById("TDNews");
			//NewTd.innerHTML = XmlHttpFO.responseText;
		document.getElementById("NewsPop").innerHTML=XmlHttpFO.responseText;
			
			
						
			document.body.style.cursor = "auto";		
		}
		else
		{
			document.getElementById("NewsPop").innerHTML =  "There was a problem retrieving data from the server.";
			
			document.body.style.cursor = "auto";
		}
	}
}




/*Get FII/MF Activity */



function CreateXmlHttpFII()
{
	try
	{
		XmlHttpFII = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpFII = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			XmlHttpFII = null;				
		}
	}
	if(!XmlHttpFII && typeof XMLHttpRequest != "undefined")
	{
		XmlHttpFII = new XMLHttpRequest();
	}
}


function GetFIIAct()
{
    CreateXmlHttpFII()
	document.body.style.cursor = "progress";
	
	var requestUrl = "AjaxFIIMF.aspx";

	derajaxpage('1',requestUrl,'FIIMF');
}


	
	
	var url;
    var containerid="contentarea";
var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""
	
	
	
	
	
	
	function DerGetNewsDetail(secId,SubSecId,NewsID,opt)
	{
	     document.getElementById("divNews").style.display='inline';
		// var requestUrl = "../PopupNewsData.aspx?SecId="+ secId +"&SubSecId="+ SubSecId+"&NewsID="+NewsID+"&timeStamp="+new Date().getTime()+"opt="+opt;
		var requestUrl = "../News/GetNews.aspx?SecId="+ secId +"&SubSecId="+ SubSecId+"&NewsID="+NewsID+"&timeStamp="+new Date().getTime()+"opt="+opt;
		
		 derajaxpage('1',requestUrl,'NewsPop');
	}
	
	function derajaxpage(id,url, containerid,fincode)
{

//document.getElementById(containerid).innerHTML = "<table cellspacing=0 cellpadding=0 width=100%><tr><td height=60></td></tr><tr><td align=center><img src='../App_Themes/Common/images/loading.gif'></td></tr></table>";
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject)
{ // if IE
        try {
            page_request = new ActiveXObject("Msxml2.XMLHTTP")
            } 
        catch (e){
                try{
                    page_request = new ActiveXObject("Microsoft.XMLHTTP")
                }
                catch (e){}
                }
}
else
return false
page_request.onreadystatechange=function()
{
    derloadpage(page_request, containerid)
}

if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function derloadpage(page_request, containerid)
{
    if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
  //alert(page_request.responseText)
    document.getElementById(containerid).innerHTML=page_request.responseText
}
