﻿// 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 clockTimeoutID;
//Global Variables
var XmlHttp;
var XmlHttp2;
var XmlHttp3;
var XmlHttpTOP;
var XmlHttpNews;

function CreateXmlHttp()
{
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			XmlHttp = null;				
		}
	}
	if(!XmlHttp && typeof XMLHttpRequest != "undefined")
	{
		XmlHttp = new XMLHttpRequest();
	}
}

function CreateXmlHttpNFO()
{
	try
	{
		XmlHttpNFO = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpNFO = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			XmlHttpNFO = null;				
		}
	}
	if(!XmlHttpNFO && typeof XMLHttpRequest != "undefined")
	{
		XmlHttpNFO = new XMLHttpRequest();
	}
}


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 GetNFO()
	{	
		var requestUrl = "AjaxNFOData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
		ajaxpage('1',requestUrl,'NFOID');
		}
	
	function loadPerformData(Period,Category,TopGl)
    {

	  document.getElementById("Y").value = document.getElementById("ctl00_ContentPlaceHolder1_FundPerformance1_ddlReturn").value;
	  document.getElementById("C").value = document.getElementById("ctl00_ContentPlaceHolder1_FundPerformance1_ddlCategory").value;
 // alert(document.getElementById("Ech").value)
	    if(document.getElementById("Ech").value=="T")
	    {
		    document.getElementById("Ech").value = "T"
	    }
	    else
	    {
		    document.getElementById("Ech").value = "B"
	    }
   
    
	var requestUrl = "AjaxFundData.aspx?Period="+  document.getElementById("Y").value +"&Category="+ Category +"&Type="+document.getElementById("Ech").value;	
	ajaxpage('1',requestUrl,'FundPerformance');
	}
	
	
	
function ajaxpage(id,url,containerid)
{

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()
{
    loadpage(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 loadpage(page_request, containerid)
{
    if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))

    document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}

function GetTalkingStockHot(SecID,SubSec)
	{	
		var requestUrl = "TalkingStockAjax.aspx?Sec="+ SecID +"&SubSec="+SubSec+"&IpTrack="+ window.location.hostname +"&timeStamp="+new Date().getTime();
		ajaxpage('1',requestUrl,'TalkingStockTD');
	}
	
	
 function GetNewsDetail(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;
		 ajaxpage('1',requestUrl,'TdNews');
	}

//For top performers data
function loadGLData(Period,Category,TopGl)
{
//alert("as");
	CreateXmlHttp()
	document.body.style.cursor = "progress";
	var TopGl;
	if(Period=='')
		Period = "1YEAR";
	if(Category=='')	
		Category="ALL";
	
	var requestUrl = "AjaxFundData.aspx?Period="+ Period +"&Category="+ Category +"&TopGl="+ TopGl;

	
	if(XmlHttp)	{
				XmlHttp.onreadystatechange = function(){GLResponse(TopGl)}
				XmlHttp.open("GET", requestUrl,  true);
				XmlHttp.send(null);
			}
}	
	
	function GLResponse(TopGl)
{
            var FundPerformance = document.getElementById("FundPerformance");
			
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK

		if(XmlHttp.status == 200)
		{	
			var strGlData = XmlHttp.responseText
			
				FundPerformance.innerHTML = strGlData;
			 
				
			document.body.style.cursor = "auto";		
		}
		else
		{
			
				FundPerformance.innerHTML = "There was a problem retrieving data from the server.";
			
			
			document.body.style.cursor = "auto";
		}
	}
}	

function CategoryCtrl(Type)
{
	var Type;
	var option=document.getElementById("PeriodDropList").value;
	
	var EquityId = document.getElementById("Categoryretctrl2_EquityId");
	var DebtId  =  document.getElementById("CategoryRetCtrl2_DebtId");
	var BalancedId  =  document.getElementById("CategoryRetCtrl2_BalancedId");
		document.getElementById("hdType").value = Type;
		
		if (Type=="EQUITY")
		{
				document.getElementById("TrEquity").style.display="inline";
				document.getElementById("TrDebt").style.display="none";
				document.getElementById("TrHybrid").style.display="none";
				
				loadCatRet(Type,option);
				
					
		}
		else if (Type=="Debt")
		{
				document.getElementById("TrEquity").style.display="none";
				document.getElementById("TrDebt").style.display="inline";
				document.getElementById("TrHybrid").style.display="none";
				loadCatRet(Type,option);
				
		}
		
		else if (Type=="Hybrid")
		{
				document.getElementById("TrEquity").style.display="none";
				document.getElementById("TrDebt").style.display="none";
				document.getElementById("TrHybrid").style.display="inline";
				loadCatRet(Type,option);
				
				
					
		}
	
		
}

function ChangeTB(Type,Year,cat)
{
    document.getElementById("Ech").value=Type;
    document.getElementById("Y").value = document.getElementById("ctl00_ContentPlaceHolder1_FundPerformance1_ddlReturn").value;
	document.getElementById("C").value = document.getElementById("ctl00_ContentPlaceHolder1_FundPerformance1_ddlCategory").value;
    if(Type=="T")
    {
        document.getElementById("TP").className ="ExchangeClass";
        document.getElementById("BP").className ="SwitchClass";
       
    }
    else
    {
         document.getElementById("TP").className ="SwitchClass";
        document.getElementById("BP").className ="ExchangeClass";
       
    }
   
   loadPerformData( document.getElementById("Y").value,document.getElementById("C").value,Type)
    
}




function loadCatRet(Type,option)
	{		
		//alert(Period);
		CreateXmlHttp1();
		document.body.style.cursor = "progress";
		
		var requestUrl = "AjaxCategoryData.aspx?Type="+Type+"&option="+option;
		//alert(XmlHttp1);
		if(XmlHttp1)	
			{
					//alert("hi");
					XmlHttp1.onreadystatechange = function(){CatRetResponse();}; 
					XmlHttp1.open("GET", requestUrl,  true);
					XmlHttp1.send(null);
			}
			
	}	
	
	//Called when response comes back from server Only For Category Return
function CatRetResponse()
{
	// To make sure receiving response data from server is completed
	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 EquityId   = document.getElementById("EquityId");
//			var DebtId     = document.getElementById("Categoryretctrl2_DebtId");
//			var BalancedId = document.getElementById("Categoryretctrl2_BalancedId");
			//window.alert(XmlHttp.responseText);
			var strData = XmlHttp1.responseText;
			//alert(strData);
			if(strData != "")
			{
//				var arrDateSplit = strData.split("|");
				EquityId.innerHTML   = strData;
//				DebtId.innerHTML     = arrDateSplit[1];
//				BalancedId.innerHTML = arrDateSplit[2];
			}
			document.body.style.cursor = "auto";	
		}
		else
		{
			EquityId.innerHTML = "There was a problem retrieving data from the server.";
			DebtId.innerHTML = "There was a problem retrieving data from the server.";
			BalancedId.innerHTML = "There was a problem retrieving data from the server.";
			document.body.style.cursor = "auto";
		}
	}
	
}

	 
 function ItemMouseOver(currentRow)
    {
        oRow = document.getElementById(currentRow);

            oRow.originalBackgroundColor = oRow.style.backgroundColor
            oRow.style.backgroundColor = '#e5f3fe';
            
    }

    function ItemMouseOut(currentRow)
    {
        oRow = document.getElementById(currentRow);

            oRow.style.backgroundColor = oRow.originalBackgroundColor;

    }
    
    
    function NFOUpdateCtrl(Option)
{

		
		
		if (Option=="ENFO")
		{
		       // document.getElementById("Existing").style.display = 'inline';
		        //document.getElementById("Forthcoming").style.display = 'none';
				document.getElementById("ImgCurrent").src="../App_Themes/CommonTheme/images/ExeNFOOn.gif";
				document.getElementById("ImgForthcomming").src="../App_Themes/CommonTheme/images/ForthNFOOff.gif";
//				document.getElementById("HBTD").src="../App_Themes/CommonTheme/images/hybridoff.gif";
				
				
				
					
		}
		else 
		{
		      //  document.getElementById("Forthcoming").style.display = 'inline';
		      //  document.getElementById("Existing").style.display = 'none';
    			document.getElementById("ImgCurrent").src="../App_Themes/CommonTheme/images/ExeNFOOff.gif";
				document.getElementById("ImgForthcomming").src="../App_Themes/CommonTheme/images/ForthNFOOn.gif";
//				document.getElementById("HBTD").src="../App_Themes/CommonTheme/images/hybridoff.gif";
				
		}
						
		LoadNFOUpdate(Option);
		
		
		
}


function LoadNFOUpdate(Option)
	{		
		CreateXmlHttpNFO();
		document.body.style.cursor = "progress";
		
		var requestUrl = "AjaxNFOUpdateData.aspx?&Option="+Option;
		
		if(XmlHttpNFO)	
			{
					
					XmlHttpNFO.onreadystatechange = function(){NFOUpdateResponse();}; 
					XmlHttpNFO.open("GET", requestUrl,  true);
					XmlHttpNFO.send(null);
			}
	}
	
	
	function NFOUpdateResponse()
{

	// To make sure receiving response data from server is completed
	if(XmlHttpNFO.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpNFO.status == 200)
		{	
		//alert("in respnse OK")	;	
			var NFOId   = document.getElementById("NFOId");
			
			var strData = XmlHttpNFO.responseText;
			//alert(strData);
			if(strData != "")
			{
			
				NFOId.innerHTML   = strData;
				

			}
			document.body.style.cursor = "auto";	
		}
		else
		{
			NFOId.innerHTML = "There was a problem retrieving data from the server.";
			document.body.style.cursor = "auto";
		}
	}
}
	
	
	
    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)
//	{
//       // alert(requestUrl);
//		var NewsWin = document.getElementById("divNews").style.display='inline';
//		var currentDivObj;	
//		
//			currentDivObj = document.getElementById("TdNews");
//			//alert(currentDivObj);
//			currentDivObj.innerHTML ="<img src=../App_Themes/Common/images/ajax-loader.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;
//				
//				document.body.style.cursor = "auto";
//			}
//			else
//			{
//				
//					document.getElementById("NewsId").innerHTML = "<img src=../App_Themes/Common/images/ajax-loader.gif>";
//				
//			}
//		}
//	}
	
function open_win(url)
   {
   window.open(url,'welcome','width=505,height=350,menubar=yes,status=yes,location=yes,toolbar=yes,scrollbars=yes');
   }

 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);
  }
}
