﻿var HostAddressInJSfileForPages="http://money.livemint.com";
var containerid="contentarea";var bustcachevar=1
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""
var XmlHttp;
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();
		}
	}


function StockRecommKeypress(sevent,id)    
             {                    
                 var Stkey   
                 if(window.event) // IE                                                
                   { Stkey = sevent.keyCode   ;        
                    }         
               else if(sevent.which) // Netscape/Firefox/Opera                
                   {   
                   Stkey = sevent.which ;
                   }  
                    if (Stkey == 13)      
                      {    
                     
                          CallPage(id) ;  
                          return false;
                       }           
                       
                  }
                  
                  var schemeObject=null;
      var Fund ;
      var scheme;  
      var category;
 
    function ProcessSearchData()
        {        
                try 
                { 
                    schemeObject = new ActiveXObject('Msxml2.XMLHTTP');
                }
                catch(e)
                {
                    try 
                    {
                        schemeObject = new ActiveXObject('Microsoft.XMLHTTP'); 
                    } 
                    catch(e1) 
                    { 
                        schemeObject = null; 
                         if(!schemeObject && typeof XMLHttpRequest != "undefined") 
		                      {
			                    schemeObject = new XMLHttpRequest();
		                      }
                    } 
                 } 
         
         
       
                  Fund = document.getElementById("ExplorerCtrl1_ddlAMC");                  
                   
                                             
                  category = document.getElementById("ExplorerCtrl1_ddlCategory");   
           
                  // document.getElementById("loading").style.display = "inline";
	               document.body.style.cursor = "progress";
        
                 if(schemeObject != null)
                    {   
                      
                        var queryString = "../MutualFund/MutualFundScheme.aspx?timenow=" + new Date().getTime() + "&Fund=" + Fund.value +"&Category=" + category.value;         
                      
                        schemeObject.onreadystatechange = function(){ProcessSchemeData();};  
                      // schemeObject.onreadystatechange = ProcessSchemeData();
                        schemeObject.open('GET', queryString ,  true); 
                        schemeObject.send(null);  
                    }    
           
                 return false; 
          }
          
             function ProcessSchemeData(scheme)
           {
            
            if(schemeObject.readyState == 4) //complete , the request has completed and all response data has been downloaded. 
             {
                if(schemeObject.status == 200) //HTTP response OK. 
                {                  
                      var listItemc;       
                      var dsRoot = schemeObject.responseXML.documentElement;   
                      
               
           
                                      var ddlCat = category;  
                                      ddlCat.options.length=0; 
                                     
                                      if(dsRoot.getElementsByTagName('className')!=null)
                                         {
                                             var textc; 
                                             var valuec;
                                             var CatName = dsRoot.getElementsByTagName('className');                        
                                             var CatCodes = dsRoot.getElementsByTagName('classcode');
                                             ddlCat.length=0;
                                        
                                                for (var count = 0; count < CatName.length; count++)
                                                {
                                                    textc = (CatName[count].textContent || CatName[count].innerText || CatName[count].text);
                                          
                                                    valuec = (CatCodes[count].textContent || CatCodes[count].innerText || CatCodes[count].text);
                                        
                                                    listItemc = new Option(textc, valuec,  false, false);
                                                    ddlCat.options[ddlCat.length] = listItemc;    
                                                    //document.getElementById("FundCatCtrl1_ddlScheme").style.display="inline";
                                                }
                                          

                                         }
                             
                                  document.body.style.cursor = "auto";  
                                  //document.getElementById("loading").style.display = "none";
                                }  
                                else
                                        {     
                                            listItemc = new Option("Scheme is not available", "");
		                                    ddlSchem.length = 1;
                                            ddlSchem.options[0] = listItemc;   
                                                                           
                                            listItemc = new Option("Category is not available", "");
	                                        ddlCat.length = 1;
                                            ddlCat.options[0] = listItemc;   
                                            //document.getElementById("loading").style.display = "none";   
                                         }
                         
                        }    
                }

          function redirect_page()
          {
             var f1 = document.getElementById("ExplorerCtrl1_ddlAMC").value; 
             var f2 = document.getElementById("ExplorerCtrl1_ddlFundType").value; 
             var f3 = document.getElementById("ExplorerCtrl1_ddlCategory").value; 
             if(f1=="")
             {
             alert("Select a Fund.");
             document.getElementById("ExplorerCtrl1_ddlAMC").focus();
             return false;
             }
             var surl="../Calculator/MFScreener/Advancesearch.aspx?id=16&Fund="+f1+"&Type="+f2+"&Catg="+f3;
             window.location.href=surl;
          }
          function MFScreenerKeypress(me)    
             {                    
                 var Mkeynum   
                 if(window.event) // IE                                                
                   { Mkeynum = me.keyCode   ;        
                    }         
               else if(me.which) // Netscape/Firefox/Opera                
                   {   
                   Mkeynum = me.which ;
                   }  
                    if (Mkeynum == 13)      
                      {    
                     
                          redirect_page()    ;  
                          return false;
                       }           
                       
                  }
                  
                  
                   function addLocation(value)
                  { if(value=='S')
                 {
                    var Location = new Array("Select Instrument","Futures","Options"); 
                    var LocationId =  new Array("","FUTSTK","OPTSTK");                                                    
                }
                else
                {
                    
                    var Location = new Array("Select Instrument","Futures","Options"); 
                    var LocationId =  new Array("","FUTIDX","OPTIDX");    
                }
                    var LocationDrp  = document.getElementById("FAndOTracker2_InstrumentType");
                
                 LocationDrp.length = Location.length;              
                  for(var i=0; i < Location.length; i++)
                    {
                    
                        LocationDrp.options[i] = new Option(); 
                        LocationDrp.options[i].value = LocationId[i];			
                        LocationDrp.options[i].text = Location[i];			
                       
                    }	
    }
function ShowData(value)
	{	
	var InstName 
	var Symbol
	if(value=='F')
	{document.getElementById("tblFirst").style.display="";
	  document.getElementById("tblSecond").style.display="none";
	   document.getElementById("inp_hid1").value="F";
	}
	if(value=='S')
	{
	  document.getElementById("tblSecond").style.display="";
	  document.getElementById("tblFirst").style.display="none";
	    document.getElementById("inp_hid1").value="S";
	}
	Symbol = document.getElementById("ddlSymbol");
	InstName = document.getElementById("FAndOTracker2_InstrumentType");
	  addLocation(value);
	   Get_SymbolHome(value);
      var OptionType = document.getElementById("OptionType");
 	  var StrikePrice = document.getElementById("StrikePrice");
 	  var ExpDt = document.getElementById("ExpiryDate");
					 InstName.value="";
					 Symbol.length = 0;
                     Symbol.options[0] = new Option(); 
					 Symbol.options[0].value = "";
					 Symbol.options[0].text = "Select Symbol";
					 
					 OptionType.length = 0;
                     OptionType.options[0] = new Option(); 
					 OptionType.options[0].value = "";
					 OptionType.options[0].text = "Select Option";
					 
					 StrikePrice.length = 0;
                     StrikePrice.options[0] = new Option(); 
					 StrikePrice.options[0].value = "";
					 StrikePrice.options[0].text = "Select Strike Price";
					 
					 ExpDt.length = 0;
                     ExpDt.options[0] = new Option(); 
					 ExpDt.options[0].value = "";
					 ExpDt.options[0].text = "Select Expiry Date";
					 document.body.style.cursor = "auto";
					 
   
    }

     function FillOption()
{
var InstName = document.getElementById("FAndOTracker2_InstrumentType");
var OptionType = document.getElementById("OptionType");
var StrikePrice = document.getElementById("StrikePrice");

            if(InstName.value=="OPTIDX")
			{
				OptionType.options[1] = new Option();
				OptionType.options[1].value="PE";
				OptionType.options[1].text="PE";
				OptionType.options[2] = new Option();
				OptionType.options[2].value="CE";
				OptionType.options[2].text="CE";
			}
			else if(InstName.value=="OPTSTK")
			{
				OptionType.options[1] = new Option();
				OptionType.options[1].value="PA";
				OptionType.options[1].text="PA";
				OptionType.options[2] = new Option();
				OptionType.options[2].value="CA";
				OptionType.options[2].text="CA";
			}
			else
			{
				OptionType.length = 0;
				OptionType.options[0] = new Option();
				OptionType.options[0].value="";
				OptionType.options[0].text="Select Option Type";
				
				StrikePrice.length = 0;
				StrikePrice.options[0] = new Option();
				StrikePrice.options[0].value="";
				StrikePrice.options[0].text="Select Strike Price";
			}
}     


function Get_SymbolHome(value)
 {
 var Symbol,InstName;
  InstName = document.getElementById("FAndOTracker2_InstrumentType");
		
	     Symbol = document.getElementById("ddlSymbol");
		
 		var OptionType = document.getElementById("OptionType");
 		var StrikePrice = document.getElementById("StrikePrice");
 			
		CreateXmlHttpNew();
		document.body.style.cursor = "progress";
		var requestUrl =  HostAddressInJSfileForPages+"/LiveHome/GetSymbolAjax.aspx?timeStamp="+ new Date().getTime() +"&InstName="+value;
		
		if(XmlHttpFO)	{
					XmlHttpFO.onreadystatechange = function(){getSymbolResp(Symbol)};
					XmlHttpFO.open("GET", requestUrl,  true);
					XmlHttpFO.send(null);
				}
		
 }
 
 //Called when response comes back from server Only For Symbol
function getSymbolResp(ig_)
{

	// To make sure receiving response data from server is completed
	if(XmlHttpFO.readyState == 4)
	{
		var ig_;
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpFO.status == 200)
		{		
				
			var strData = XmlHttpFO.responseText
			
			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";	
					
					
					/*to clear expiry date*/
                    var ExpDt = document.getElementById("ExpiryDate");
                     ExpDt.length = 0;
                     ExpDt.options[0] = new Option(); 
					 ExpDt.options[0].value = "";
					 ExpDt.options[0].text = "Select Expiry Date";
					 document.body.style.cursor = "auto";
					
					
					
			}
			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 Get_ExpDate(optD)
 {

	     var InstName = document.getElementById("FAndOTracker2_InstrumentType");
	  		
 		var Symbol = document.getElementById("ddlSymbol");
 		var ExpiryDate = document.getElementById("ExpiryDate");
 				
		CreateXmlHttpNew();
		document.body.style.cursor = "progress";
		var requestUrl = HostAddressInJSfileForPages+"/LiveHome/GetExpDateAjax.aspx?timeStamp="+ new Date().getTime() +"&InstName="+InstName.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)
		{
			var strData = XmlHttpFO.responseText
			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 Get_StrikePrice(optP)
 {
 var InstName = document.getElementById("FAndOTracker2_InstrumentType");
 
	 var Symbol = document.getElementById("ddlSymbol");
	
 		
 		var ExpiryDate = document.getElementById("ExpiryDate");
 		var OptionType = document.getElementById("OptionType");
 		var StrikePrice = document.getElementById("StrikePrice"); 
		CreateXmlHttpNew();
		document.body.style.cursor = "progress";
		var requestUrl = HostAddressInJSfileForPages +"/LiveHome/GetStrikePriceAjax.aspx?timeStamp="+ new Date().getTime() +"&InstName="+InstName.value +"&Symbol="+Symbol.value+"&ExpDate="+ExpiryDate.value+"&OptionType="+OptionType.value;
	
		
		if(XmlHttpFO)	{
					XmlHttpFO.onreadystatechange = function(){Get_StrikePriceResp(StrikePrice)};
					XmlHttpFO.open("GET", requestUrl,  true);
					XmlHttpFO.send(null);
				}
				
		
 }
 
 
 //Called when response comes back from server Only For Strike Price
function Get_StrikePriceResp(ig_)
{
	// To make sure receiving response data from server is completed
	if(XmlHttpFO.readyState == 4)
	{
		if(XmlHttpFO.status == 200)
		{
			//alert(ig_)
			//var availSchemes   = document.getElementById(ig_);
			var strData = XmlHttpFO.responseText;
			//alert(strData)
			if(strData != "") {	
			    
				var arrPrice = strData.split("|");
				ig_.length = 0; 	
				
				for(i=0; i<arrPrice.length-1; i++) {	
								
					var strPrice = arrPrice[i];
					var arrPriceCode = strPrice.split("~");
					
					ig_.options[i] = new Option();
					
					ig_.options[i].value = arrPriceCode[0];
					ig_.options[i].text = arrPriceCode[1];
				}
				
			}
			else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "Price 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 ValidateFormHome(opt)
{

    var InstType ="";
	var Symbol   ="";
	var ExpDate  ="";
	var OptType  ="";
	var StkPrice ="";
	opthdd=document.getElementById("inp_hid1").value
	  InstType = document.getElementById("FAndOTracker2_InstrumentType")
	   	 Symbol   = document.getElementById("ddlSymbol");
 if(opthdd=="S")
 {
    ExpDate  = document.getElementById("ExpiryDate");
	 OptType  = document.getElementById("OptionType");
	 StkPrice = document.getElementById("StrikePrice");
 }
else
{
	 ExpDate  = document.getElementById("ExpiryDate");
	 OptType  = document.getElementById("OptionType");
	 StkPrice = document.getElementById("StrikePrice");
 
}
	
	if(InstType.value=="")
		{
			alert("Please select the Instrument Type before you proceed");
			InstType.focus();
			return false;
		}
			if(Symbol.value=="Select Symbol")	
			{
			alert("Please select Symbol before you proceed");
			Symbol.focus();
			return false;
			}
			
		if ((InstType.value=="OPTIDX")||(InstType.value=="OPTSTK"))
		{
		
		 if(OptType.value=="")
			{
			alert("Please select Option Type before you proceed");
			OptType.focus();
			return false;
			}
			else if(StkPrice.value=="Select Strike Price" || StkPrice.value=="" || StkPrice.value=="Select Strike Price")
			{
			alert("Please select Price before you proceed");
			StkPrice.focus();
			return false;
			}
		
		}

		var url="InstType="+InstType.value+"&Symbol="+Symbol.value+"&ExpDate="+ExpDate.value+"&OptType="+OptType.value+"&StkPrice="+StkPrice.value+"&Home=True&UserId=";
		var strUrlDer="../LiveMarket/GetQuotes.aspx?id=75&"+url;
		//alert(strUrlDer)
		var newWindow = window.open(strUrlDer, '_parent'); 
	    newWindow.focus(); 
        return false; 

}

function fadnoKeypress(fe)    
             {            
          //   alert();        
                 var Fkeynum   
                 if(window.event) // IE                                                
                   { Fkeynum = fe.keyCode   ;        
                    }         
               else if(fe.which) // Netscape/Firefox/Opera                
                   {   
                   Fkeynum = fe.which ;
                   }  
                    if (Fkeynum == 13)      
                      {    
                     
                          ValidateFormHome('Inn') ;  
                          return false;
                       }           
                       
                  }
                  
                  var MRSE;
function CreateMRSE()
{
	try
		{
			MRSE = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{  
				MRSE = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				MRSE = false;	
			}
		}
		//Creating object of XmlHttp in Mozilla and Safari 
		if (!MRSE && typeof XMLHttpRequest!='undefined') 
		{
	        try 
	        {
		        MRSE = new XMLHttpRequest();
	        } 
	        catch (e) 
	        {
		        MRSE=false;
	        }
        }

}
        function ChangeMost(Opt)
        {
            document.getElementById("RTD_1").className="NewsFirstTabSelectedWhite";
            document.getElementById("ETD_1").className="NewsTabSelectedWhite";
            document.getElementById("STD_1").className="NewsTabSelectedWhite";
            
            if (Opt=='R')
            {
            document.getElementById(Opt+"TD_1").className="NewsFirstTabWSelected";
            }
            else
            {
            document.getElementById(Opt+"TD_1").className="NewsTabWSelected";
            }
          
            if(Opt!='S')
            {
               document.getElementById("trreademail").style.display="";
               document.getElementById("trsearch").style.display="none";
               ShowReadEmail(Opt);
            }
            else
            {
               document.getElementById("trreademail").style.display="none";
               document.getElementById("trsearch").style.display="";
            }
           } 
      function GetMRSE()
        {
	    if(MRSE.readyState == 4)
	    {
		    if(MRSE.status == 200)
		    {
		    document.getElementById("MRSEdetails").innerHTML=MRSE.responseText;
		    }
	    }	
	    }
	    var strurl=document.location.href;var sopt;
	    if (strurl.indexOf("/LIVEHOME/"))
        {
            sopt = "";
        }
        else if (strurl.indexOf("/LIVEMARKET/"))
        {
            sopt = "Market";
        }
        else if (strurl.indexOf("/MUTUALFUND/"))
        {
            sopt = "MF";
        }
        else if (strurl.indexOf("/COMMODITY/"))
        {
            sopt = "Commodity";
        }
	    function ShowReadEmail(Opt)
	    {
	          CreateMRSE();
            var MRSEUrl = HostAddressInJSfileForPages+"/LiveMarket/AjaxMostReadSearched.aspx?type="+Opt+"&section="+sopt+"&timeStamp="+ new Date().getTime();
                if(MRSE)	
	        {
				MRSE.onreadystatechange = function(){GetMRSE()}
				MRSE.open("GET", MRSEUrl,  true);
				MRSE.send(null); 
			}
	    }
	    
	    function ModalPopupsCustom1Save() {   
    var custom1Name = ModalPopups.GetCustomControl("inputusername");  
     var custom1pass = ModalPopups.GetCustomControl("inputpassword");     
    if(custom1Name.value == "") {   
        alert("Please submit a username");   
        custom1Name.focus();   
        return false;
    }   
     if(custom1pass.value == "") {   
        alert("Please submit a password");   
        custom1pass.focus(); 
        return false;  
    }   
    else {   
      var ReqUrl='../LiveHome/AjaxCheckUser.aspx?UserName='+custom1Name.value +"&Password="+custom1pass.value;
          ajaxpopuppage(ReqUrl,'errmsg')
    }   
}  

function ajaxpopuppage(url,containerid){var page_request=false;if(window.XMLHttpRequest)page_request=new XMLHttpRequest();else if(window.ActiveXObject){try{page_request=new ActiveXObject("Msxml2.XMLHTTP")}catch(e){try{page_request=new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}}}page_request.onreadystatechange=function(){loadpage(page_request,containerid)};if(bustcachevar)bustcacheparameter=(url.indexOf("?")!=-1)?"&"+new Date().getTime():"?"+new Date().getTime()
page_request.open('GET',url+bustcacheparameter,true)
document.body.style.cursor="auto";page_request.send(null)}
function loadpage(page_request,containerid){
if(page_request.readyState==4&&(page_request.status==200||window.location.href.indexOf("http")==-1))
{var strData=page_request.responseText;if(strData =='../default.aspx'){redirectUrl(strData);}
else {document.getElementById(containerid).innerHTML=strData;}
}} 
 function redirectUrl(url){document.location=url;}
function ModalPopupsCustom1Cancel() {   
    //alert('You pressed Cancel');   
    ModalPopups.Cancel("idCustom1");   
}  

function ModalPopupsCustom1() {
    ModalPopups.Custom("idCustom1",
        "Enter login information",
        "<div style='padding: 25px;padding-bottom:0px'>" + 
        "<table>" + 
         "<tr><td></td><td id=errmsg></td></tr>" + 
        "<tr><td> User Name</td><td><input type=text id='inputusername' style='width:100px;'></td></tr>" +    
        "<tr><td>Password</td><td><input type=password id='inputpassword' style='width:100px;'></td></tr>" +   
         "<tr><td  style='padding-top:10px'><a  href='../WealthTracker/Forgot_psswrd.aspx?Opt=0&Option=1'> Forgot Password </a></td><td  align='center' style='padding-top:10px'><a href='http://money.livemint.com/Registration.aspx'>Register</a></td></tr>" +   
        "</table>" + 
        "</div>", 
        {
            width: 300,
            buttons: "ok,cancel",
            okButtonText: "Login",
            cancelButtonText: "Cancel",
            onOk: "ModalPopupsCustom1Save()",
            onCancel: "ModalPopupsCustom1Cancel()"
        }
    );
            
    ModalPopups.GetCustomControl("inputusername").focus(); 
}

