﻿// JScript File



var xmlHttp
function GetXmlHttpObject(handler)
{ 
		var objXmlHttp=null

		if (navigator.userAgent.indexOf("Opera")>=0)
		{
			alert("This example doesn't work in Opera") 
			return 
		}
		if (navigator.userAgent.indexOf("MSIE")>=0)
		{ 
			var strName="Msxml2.XMLHTTP"
			if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
			{
				strName="Microsoft.XMLHTTP"
			} 
			try
			{ 
				objXmlHttp=new ActiveXObject(strName)
				objXmlHttp.onreadystatechange=handler 
				return objXmlHttp
			} 
			catch(e)
			{ 
				alert("Error. scripting for ActiveX might be disabled") 
			return 
			} 
			} 
		if (navigator.userAgent.indexOf("Mozilla")>=0)
		{
			objXmlHttp=new XMLHttpRequest()
			objXmlHttp.onload=handler
			objXmlHttp.onerror=handler 
			return objXmlHttp
		}
} 

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;
//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 = null;	
			}
		}
		//Creating object of XMLHTTP in Mozilla and Safari 
		if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
		{
			XmlHttp = new XMLHttpRequest();
		}
	}
	



/**/


function FillTwo()
{
    
    //ddlInstrument
    var strScheme = document.getElementById("ctl00_pmsContent_ctl00_ddlInstrument");
    //Fill object
    var lb_Scheme = document.getElementById("ctl00_pmsContent_ctl00_ddlType");
    // lboxvalue
    var sch_name = document.getElementById("ctl00_pmsContent_ctl00_lbCompany");
    var strikePrice = document.getElementById("ctl00_pmsContent_ctl00_ddlStrkePrice");
    
    var Stock;
    
    //-----------------------
    
     if((strScheme.value == "OPTSTK")||(strScheme.value=="OPTIDX"))
     {
        lb_Scheme.disabled=false;
        strikePrice.disabled=false;
        CreateXmlHttp();
        document.body.style.cursor = "progress";
        var requestUrl = "webclients/Instruments/Search_Type.aspx?timeStamp="+ new Date().getTime() +"&strSearch="+sch_name.value+"&strddlInst="+strScheme.value;
        //alert(requestUrl)
       // window.open(requestUrl)
        
        if(XmlHttp){
        XmlHttp.onreadystatechange = function(){getTypeRes(lb_Scheme)};
        XmlHttp.open("GET", requestUrl,  true);
        XmlHttp.send(null);}
     
     }
  else
  {
        lb_Scheme.disabled=true;
        strikePrice.disabled=true;
        ExpiryDate();
  }
        
   
    
}

 //Called when response comes back from server Only For Strike Price
function getTypeRes(ig_)
{ 

//alert(XmlHttp.readyState)
 
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
	 //alert(XmlHttp.status)
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{
		   // var SchResult = document.getElementById("ctl00_pmsContent_ctl00_DD_Two");
		    //SchResult.style.display = "inline"
		     var strData = XmlHttp.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 = "Scheme 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 ValUpdate()
{
         var lblStkEdit = document.getElementById("ctl00_pmsContent_ctl00_lblStkEdit")
        // alert(lblStkEdit.innerHTML)
            if(lblStkEdit.innerHTML=="")
            {
            alert("Select a scrip for edit");
            return false;
            } 
      
    var instrument = document.getElementById("ctl00_pmsContent_ctl00_ddlEditInst");
    var hdnInstmnt = document.getElementById("ctl00_pmsContent_ctl00_hdnInstmnt");
    hdnInstmnt.innerText = instrument[instrument.selectedIndex].value;
  
    
    var ddlEditType = document.getElementById("ctl00_pmsContent_ctl00_ddlEditType");
    var hdnType = document.getElementById("ctl00_pmsContent_ctl00_hdnType");
    hdnType.innerText = ddlEditType[ddlEditType.selectedIndex].value;
   
    
    var ddlEditExpiry = document.getElementById("ctl00_pmsContent_ctl00_ddlEditExpiry");
    var hdnExpDate = document.getElementById("ctl00_pmsContent_ctl00_hdnExpDate");
    hdnExpDate.innerText = ddlEditExpiry[ddlEditExpiry.selectedIndex].value;
   
    
    
    var ddlEditStrikeprice = document.getElementById("ctl00_pmsContent_ctl00_ddlEditStrikeprice");
    var hdnStrikeprice = document.getElementById("ctl00_pmsContent_ctl00_hdnStrikeprice");
    hdnStrikeprice.innerText = ddlEditStrikeprice[ddlEditStrikeprice.selectedIndex].value;
    
    
   
    var txtLotQty=document.getElementById("ctl00_pmsContent_ctl00_txtLotQty")
    var txtDate = document.getElementById("ctl00_pmsContent_ctl00_txtDate");
    var txtPrice = document.getElementById("ctl00_pmsContent_ctl00_txtPrice");
    
   
            //alert(lblStkEdit.innerText) 
    
    if((instrument.value != "OPTIDX")&&(instrument.value != "OPTSTK"))
        {
        //alert1(instrument.value)
        hdnType.value="XX";
        hdnStrikeprice.value="0";
        //alert(hdnType.value)
        }
         if(instrument.value=="0")
        {
            alert("Select  Instrument");
            return false;
        }
        if(((instrument.value=="FUTSTK")||(instrument.value=="FUTIDX")) && (ddlEditExpiry.value=="0"))
        {
            alert("Select  Expiry Date");
            return false;
        }
        
        if(((instrument.value=="OPTIDX")||(instrument.value=="OPTSTK"))&&(ddlEditType.value=="0"))
        {
            alert("Select Option Type");
            return false;
        }
         if(((instrument.value=="OPTIDX")||(instrument.value=="OPTSTK"))&&(ddlEditExpiry.value=="0"))
        {
            alert("Select Expiry Date");
            return false;
        }
        if(((instrument.value=="OPTIDX")||(instrument.value=="OPTSTK"))&&(ddlEditStrikeprice.value=="0"))
        {
            alert("Select Strike Price");
            return false;
        }
      
   
             
            if(txtLotQty.value=="")
            {
            alert("Enter No:Lots");
            txtLotQty.focus();
            return false;
            }
           
            if((txtPrice.value=="")||(parseFloat(txtPrice.value)==0))
                {
                    alert("Enter Price as Non-Zero value");
		            txtPrice.focus();
		            return false;
                }   
            
            if(txtDate.value=="")
            {
            alert("Enter Date");
            txtDate.focus();
            return false;
            }
    
}

function HiddenValues()
{    
    //alert("hidden")
    var strScheme = document.getElementById("ctl00_pmsContent_ctl00_ddlType");
    var hdnType = document.getElementById("ctl00_pmsContent_ctl00_hdnType");
    hdnType.innerText = strScheme[strScheme.selectedIndex].value;
    var strikePrice = document.getElementById("ctl00_pmsContent_ctl00_ddlStrkePrice");
    var hdnStrikeprice = document.getElementById("ctl00_pmsContent_ctl00_hdnStrikeprice");
    hdnStrikeprice.innerText=strikePrice[strikePrice.selectedIndex].value;
    var instrument = document.getElementById("ctl00_pmsContent_ctl00_ddlInstrument");
    var hdnInstmnt = document.getElementById("ctl00_pmsContent_ctl00_hdnInstmnt");
    hdnInstmnt.innerText=instrument[instrument.selectedIndex].value;
    var Expiry = document.getElementById("ctl00_pmsContent_ctl00_ddlExpiryDate");
    var hdnExpDate = document.getElementById("ctl00_pmsContent_ctl00_hdnExpDate");
    hdnExpDate.innerText=Expiry[Expiry.selectedIndex].value;
    var Lotsize = document.getElementById("ctl00_pmsContent_ctl00_txtLotSize");
    var hdnLotsize = document.getElementById("ctl00_pmsContent_ctl00_hdnLotsize");
    hdnLotsize.innerText=Lotsize.innerHTML;
    var lclDate = document.getElementById("ctl00_pmsContent_ctl00_txtDate").value;
    var hdnExpDateLcl = Expiry[Expiry.selectedIndex].value;

   //alert(hdnExpDateLcl);
   //alert(lclDate);
    
  
    if((instrument.value != "OPTIDX")&&(instrument.value != "OPTSTK"))
    {
    //alert(instrument.value)
    hdnType.value="XX";
    hdnStrikeprice.value="0";
    }
    
    
    //alert("derivative val")
    var Qty=document.getElementById("ctl00_pmsContent_ctl00_txtLotQty");
    var Price=document.getElementById("ctl00_pmsContent_ctl00_txtPrice");
    var dt=document.getElementById("ctl00_pmsContent_ctl00_txtDate");
    var lblStock=document.getElementById("ctl00_pmsContent_ctl00_lblStock");

    var currentTime = new Date();
    //alert(currentTime)
    var month = currentTime.getMonth() + 1;
    //alert(month)
    var day = currentTime.getDate();
    var year = currentTime.getFullYear();
    if(eval(day) <= 9)
	day = "0"+day;
	if(eval(month) <=9)
	month = "0"+month;
    var currentDate = month+ "/" + day + "/" + year;
    var arrSdate=lclDate.split("/");
    var Vdate =arrSdate[1]+ "/" +arrSdate[0]+ "/" +arrSdate[2]+' '+'12:00:00 AM';
      
    var arrEdate=hdnExpDateLcl.split("/");
    var Edate =arrEdate[0]+ "/" +arrEdate[1]+ "/" +arrEdate[2];
     
    
    if(month>arrSdate[1])
    {
        alert("Cann't Purchase before current month")
        dt.focus();
        return false;
    }
    
    
    if(Date.parse(Vdate)>Date.parse(Edate))
	        {
		    alert("Purchase date can't be greater than Expiry Date");
		
		    return false;
	        }
	     
    
    
    
    
    
        if(lblStock.innerText=="")
        {
            alert("Please select a Company");
            return false;
        }
       if(instrument.value=="0")
        {
            alert("Select  Instrument");
            return false;
        }
        if(((instrument.value=="FUTSTK") ||(instrument.value=="FUTIDX"))  && (Expiry.value=="0"))
        {
            alert("Select  Expiry Date");
            return false;
        }
        
        if(((instrument.value=="OPTIDX")||(instrument.value=="OPTSTK")) &&(strScheme.value=="0"))
        {
            alert("Select Option Type");
            return false;
        }
         if(((instrument.value=="OPTIDX")||(instrument.value=="OPTSTK"))&&(Expiry.value=="0"))
        {
            alert("Select Expiry Date");
            return false;
        }
        if(((instrument.value=="OPTIDX")||(instrument.value=="OPTSTK"))&&(strikePrice.value=="0"))
        {
            alert("Select Strike Price");
            return false;
        }
        if((Qty.value=="")||(parseFloat(Qty.value)==0))
        {
            alert("Enter Quantity as Non-Zero Value");
            Qty.focus();
            return false;
        }
        if((Price.value=="")||(parseFloat(Price.value)==0))
        {
            alert("Enter Price as  Non-Zero Value");
            Price.focus();
            return false;
        } 
        if(dt.value=="")
        {
            alert("Enter Date");
            dt.focus();
            return false;
        } 
       
      
       
        
    
 
   }


function Strikeprice()
{
        
    //ddlInstrument
        var strScheme = document.getElementById("ctl00_pmsContent_ctl00_ddlType");
        var strInstName = document.getElementById("ctl00_pmsContent_ctl00_ddlInstrument");
        var lb_Scheme = document.getElementById("ctl00_pmsContent_ctl00_ddlStrkePrice");
        // lboxvalue
        var sch_name = document.getElementById("ctl00_pmsContent_ctl00_lbCompany");
        var Stock;
        var ddlExpiry= document.getElementById("ctl00_pmsContent_ctl00_ddlExpiryDate");
            
        if((strInstName.value=="FUTSTK") ||(strInstName.value=="FUTIDX"))
        {
            Lotsize();
        }
        else
        {
            CreateXmlHttp();
            document.body.style.cursor = "progress";
            var requestUrl = "webclients/Instruments/Search_StrikePrice.aspx?timeStamp="+ new Date().getTime() +"&strSearch="+sch_name.value+"&strddlInst="+strScheme.value+"&strInstNm="+strInstName.value+"&strExpiry="+ddlExpiry.value;
            //alert(requestUrl)
            //window.open(requestUrl)
            //var urlExpiry = "Instruments/Search_Expiry.aspx?timeStamp="+ new Date().getTime() +"&strSearch="+sch_name.value;
            if(XmlHttp){
            XmlHttp.onreadystatechange = function(){getTypeResStrikeprice(lb_Scheme)};
            XmlHttp.open("GET",requestUrl,true);
            XmlHttp.send(null);}
        }
        
        
        
        
    
}

function ExpiryDate()
{
    
    //ddlInstrument
    var strScheme = document.getElementById("ctl00_pmsContent_ctl00_ddlInstrument");
    var ddlType = document.getElementById("ctl00_pmsContent_ctl00_ddlType");
    var sch_name = document.getElementById("ctl00_pmsContent_ctl00_lbCompany");
    var Stock;
    var ddlExpiry= document.getElementById("ctl00_pmsContent_ctl00_ddlExpiryDate");
    //alert(strInstName.value)
    //alert(strScheme.value)
    //alert(ddlType.value)
    //alert(sch_name.value)
    //alert(ddlType.value)
        CreateXmlHttp();
        document.body.style.cursor = "progress";
        //var requestUrl = "Instruments/Search_StrikePrice.aspx?timeStamp="+ new Date().getTime() +"&strSearch="+sch_name.value+"&strddlInst="+strScheme.value+"&strInstNm="+strInstName.value;
        //alert(sch_name.value);
//        if(sch_name.value="")
//        {
//            alert("!");
//        }
        var urlExpiry = "webclients/Instruments/Search_Expiry.aspx?timeStamp="+ new Date().getTime() +"&strSearch="+sch_name.value+"&strddlInstrument="+strScheme.value+"&strddlType="+ddlType.value;
        //alert(urlExpiry)
        //window.open(urlExpiry)
        if(XmlHttp){
        XmlHttp.onreadystatechange = function(){getTypeResExpiry(ddlExpiry)};
        XmlHttp.open("GET",urlExpiry,true);
        XmlHttp.send(null);}
      
    
}

function Lotsize()
{
    
     //alert("dfsdfs")
    var sch_name = document.getElementById("ctl00_pmsContent_ctl00_lbCompany");
    var strType= document.getElementById("ctl00_pmsContent_ctl00_ddlType");
    var strInstName = document.getElementById("ctl00_pmsContent_ctl00_ddlInstrument");
    var ddlExpiry= document.getElementById("ctl00_pmsContent_ctl00_ddlExpiryDate");
    var type;
    var strike=document.getElementById("ctl00_pmsContent_ctl00_ddlStrkePrice");
    var txtLotSize= document.getElementById("ctl00_pmsContent_ctl00_txtLotSize");
    //alert(strType.value);
    if(strType.value=="Select Type")
    {
    type="XX";
    }
    else
    {
    type=strType.value;
    }
    //alert(strType.value);
    //alert(type);
    //alert(strInstName.value)
   // alert(strScheme.value)
   //alert(sch_name.value)
        CreateXmlHttp();
        //document.body.style.cursor = "progress";
        //var requestUrl = "Instruments/Search_StrikePrice.aspx?timeStamp="+ new Date().getTime() +"&strSearch="+sch_name.value+"&strddlInst="+strScheme.value+"&strInstNm="+strInstName.value;
        //alert(requestUrl)
        //window.open(requestUrl)
        var urlExpiry = "webclients/Instruments/Search_Lotsize.aspx?timeStamp="+ new Date().getTime() +"&strSearch="+sch_name.value+"&strddlInst="+type+"&StrPrice="+strike.value+"&strInstNm="+strInstName.value+"&strExpiry="+ddlExpiry.value;
        if(XmlHttp){
        XmlHttp.onreadystatechange = function(){getTypeResLotSize(txtLotSize)};
        XmlHttp.open("GET",urlExpiry,true);
        XmlHttp.send(null);}
 
}

function getTypeResLotSize(ig_)
{ 

//alert(XmlHttp.readyState)
 
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
	 //alert(XmlHttp.status)
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{  
		    //var SchResult = document.getElementById("ctl00_pmsContent_ctl00_DD_Two");
		    //SchResult.style.display = "inline"
		     var strData = XmlHttp.responseText;
		 //alert(XmlHttp.ralert(strData)esponseText)
		 //alert(strData)
			if(strData != "")
			 {								
				ig_.innerHTML=strData;
				//alert(ig_.innerHTML)
				
				}
							
			
	}

}
}
function getTypeResStrikeprice(ig_)
{ 

//alert(XmlHttp.readyState)
 
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
	 //alert(XmlHttp.status)
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{
		    //var SchResult = document.getElementById("ctl00_pmsContent_ctl00_DD_Two");
		    //SchResult.style.display = "inline"
		     var strData = XmlHttp.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 getTypeResExpiry(ig_)
{ 

//alert(XmlHttp.readyState)
 
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
	 //alert(XmlHttp.status)
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{
		    //var SchResult = document.getElementById("ctl00_pmsContent_ctl00_DD_Two");
		    //SchResult.style.display = "inline"
		     var strData = XmlHttp.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 DervativeLabel()
{
//alert("dfgdfgd");
 var strScheme = document.getElementById("ctl00_pmsContent_ctl00_lbCompany");
  var lblStock = document.getElementById("ctl00_pmsContent_ctl00_lblStock");
 lblStock.innerText=strScheme[strScheme.selectedIndex].text;
}




function InstrumentName()
{
       
 //alert("dsfsdfsdfsdfsdfsdfsdf");
    //ddlInstrument
    //alert("strScheme.value")
    var strScheme = document.getElementById("ctl00_pmsContent_ctl00_lbCompany")
    var hdnSymbol=document.getElementById("ctl00_pmsContent_ctl00_hdnSymbol")
    var lblStock = document.getElementById("ctl00_pmsContent_ctl00_lblStock");
    
    var ddlInst = document.getElementById("ctl00_pmsContent_ctl00_ddlInstrument");
    
    var ddlExpiry= document.getElementById("ctl00_pmsContent_ctl00_ddlExpiryDate");
    lblStock.innerText=strScheme[strScheme.selectedIndex].text;
    var Stock;
    //lblStock.innerText=strScheme[strScheme.selectedIndex].text;
    //alert(strInstName.value)
    //alert(hdnSymbol.value);
        CreateXmlHttp();
        document.body.style.cursor = "progress";
        var requestUrl = "WebClients/Instruments/Search_Instrument.aspx?timeStamp="+ new Date().getTime() +"&strSearch="+strScheme.value;
        
      //alert(requestUrl)
        //window.open(requestUrl)
        
        if(XmlHttp){
        XmlHttp.onreadystatechange = function(){getTypeResInstrument(ddlInst)};
        XmlHttp.open("GET", requestUrl,  true);
        XmlHttp.send(null);}
        
//        CreateXmlHttp();
//        document.body.style.cursor = "progress";
//        var urlExpiry = "Instruments/Search_Expiry.aspx?timeStamp="+ new Date().getTime() +"&strSearch="+strScheme.value;
//        if(XmlHttp){
//        XmlHttp.onreadystatechange = function(){getTypeResExpiry(ddlExpiry)};
//        XmlHttp.open("GET", urlExpiry,  true);
//        XmlHttp.send(null);}
          
   
    
}





function getTypeResInstrument(ig_)
{ 

//alert(XmlHttp.readyState)
 	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
	 //alert(XmlHttp.status)
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{
		    //var SchResult = document.getElementById("ctl00_pmsContent_ctl00_DD_Two");
		    //SchResult.style.display = "inline"
		     var strData = XmlHttp.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 = "Instrument Name is 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 UdateVal()
{
   //alert("shibin")
    var lblStkEdit = document.getElementById("ctl00_pmsContent_ctl00_lblStkEdit")
    var txtLotQty=document.getElementById("ctl00_pmsContent_ctl00_txtLotQty")
    var txtDate = document.getElementById("ctl00_pmsContent_ctl00_txtDate");
    var txtPrice = document.getElementById("ctl00_pmsContent_ctl00_txtPrice");
    var lclDate = document.getElementById("ctl00_pmsContent_ctl00_txtDate").value;
    //var lclExp = document.getElementById("ctl00_pmsContent_ctl00_txtSellExpiry").value;
    ALERT(lclDate)
    //var hdnPurchdate = document.getElementById("ctl00_pmsContent_ctl00_hdnPurchdate").value;
    var hdnExpVal = document.getElementById("ctl00_pmsContent_ctl00_hdnExpVal").value;
    ALERT(hdnExpVal)
       
    var currentTime = new Date();
    //alert(currentTime)
    var month = currentTime.getMonth() + 1;
    //alert(month)
    var day = currentTime.getDate();
    var year = currentTime.getFullYear();
    if(eval(day) <= 9)
	day = "0"+day;
	if(eval(month) <=9)
	month = "0"+month;
    var currentDate = month+ "/" + day + "/" + year;
    var arrSdate=lclDate.split("/");
    var Vdate =arrSdate[1]+ "/" +arrSdate[0]+ "/" +arrSdate[2]+' '+'12:00:00 AM';
      
    var arrEdate=hdnExpDateLcl.split("/");
    var Edate =arrEdate[0]+ "/" +arrEdate[1]+ "/" +arrEdate[2];
     
    
    if(month>arrSdate[1])
    {
        alert("Cann't Purchase before current month")
        dt.focus();
        return false;
    }
    
    
    if(Date.parse(Vdate)>Date.parse(Edate))
	        {
		    alert("Purchase date can't be greater than Expiry Date");
		
		    return false;
	        }
    
    
    
    
    
            if(lblStkEdit.innerText=="")
            {
            alert("Select a scrip for edit");
            return false;
            }
         
            if(txtLotQty.value=="")
            {
            alert("Enter LotQuantity");
            txtLotQty.focus();
            return false;
            }
            if(txtPrice.value=="")
            {
            alert("Enter Price");
            txtPrice.focus();
            return false;
            }
            if(txtDate.value=="")
            {
            alert("Enter Date");
            txtDate.focus();
            return false;
            }
            
}            
function SellVal()
{
    //alert("shibin")
    var lblStkSell = document.getElementById("ctl00_pmsContent_ctl00_lblStkSell")
    var txtSellBuyQty = document.getElementById("ctl00_pmsContent_ctl00_txtSellBuyQty")
    var txtSellPrice=document.getElementById("ctl00_pmsContent_ctl00_txtSellPrice")
    var txtSellDate = document.getElementById("ctl00_pmsContent_ctl00_txtSellDate");
    var hdnQty = document.getElementById("ctl00_pmsContent_ctl00_hdnQty");
    var lclDate = document.getElementById("ctl00_pmsContent_ctl00_txtSellDate").value;
    //var lclExp = document.getElementById("ctl00_pmsContent_ctl00_txtSellExpiry").value;
    
    var hdnPurchdate = document.getElementById("ctl00_pmsContent_ctl00_hdnPurchdate").value;
    var hdnExpVal = document.getElementById("ctl00_pmsContent_ctl00_hdnExpVal").value;
   //alert(hdnExpVal);
    var currentTime = new Date();
    //alert(currentTime)
    var month = currentTime.getMonth() + 1;
    //alert(month)
    var day = currentTime.getDate();
    var year = currentTime.getFullYear();
    if(eval(day) <= 9)
	day = "0"+day;
	if(eval(month) <=9)
	month = "0"+month;
    var currentDate = month+ "/" + day + "/" + year;
    var arrSdate=lclDate.split("/");
    var Vdate =arrSdate[1]+ "/" +arrSdate[0]+ "/" +arrSdate[2];
    //alert(Vdate)
    var arrPdate=hdnPurchdate.split("/");
    var Pdate =arrPdate[1]+ "/" +arrPdate[0]+ "/" +arrPdate[2];
   //alert(Pdate)
    var arrEdate=hdnExpVal.split("/");
    var Edate =arrEdate[1]+ "/" +arrEdate[0]+ "/" +arrEdate[2];
    //alert(Edate)
            if(Date.parse(Vdate)>Date.parse(Edate))
	        {
		    alert("Sell Date can't be greater than Expiry Date");
		
		    return false;
	        }
            if(Date.parse(Vdate)<Date.parse(Pdate))
	        {
		    alert("Sell Date can't be less than Purachase Date");
		
		    return false;
	        }
            if(lblStkSell.innerText=="")
            {
            alert("Select a scrip for sell");
            return false;
            }
            
            if(parseFloat(txtSellBuyQty.value)>parseFloat(hdnQty.value))
            {
            alert("Sell quantity can't be more than the quantity you have");
            txtSellBuyQty.focus();
            return false;
            }
    
         
            if(txtSellBuyQty.value=="")
            {
            alert("Enter LotQuantity");
            txtSellBuyQty.focus();
            return false;
            }
            if(txtSellPrice.value=="")
            {
            alert("Enter Price");
            txtSellPrice.focus();
            return false;
            }
            if(txtSellDate.value=="")
            {
            alert("Enter date");
		    txtSellDate.focus();
		    return false;
	        }  
            /*if(Date.parse(currentDate)<Date.parse(Vdate))
	        {
		    alert("Sell Date can't be greater than Current Date");
	
		    return false;
	        }*/
	        
	        
	        
	        
	        
           
            
}

//For updating

function ForEditType()
{
    //alert("dfsdfs")
    //ddlInstrument
    var strScheme = document.getElementById("ctl00_pmsContent_ctl00_ddlEditInst");
    //Fill object
    var lb_Scheme = document.getElementById("ctl00_pmsContent_ctl00_ddlEditType");
    // lboxvalue
     var hdnScrip=document.getElementById("ctl00_pmsContent_ctl00_hdnScrip")
    //var sch_name = document.getElementById("ctl00_pmsContent_ctl00_lbCompany");
    var strikePrice = document.getElementById("ctl00_pmsContent_ctl00_ddlEditStrikeprice");
    //alert(hdnScrip.value)
    //alert(strScheme.value)
    var Stock;
    
    //-----------------------
    
     if((strScheme.value == "OPTSTK")||(strScheme.value=="OPTIDX"))
     {
        lb_Scheme.disabled=false;
        strikePrice.disabled=false;
        CreateXmlHttp();
        document.body.style.cursor = "progress";
        var requestUrl = "Instruments/Search_Type.aspx?timeStamp="+ new Date().getTime() +"&strSearch="+hdnScrip.value+"&strddlInst="+strScheme.value;
        //ert(requestUrl)
        //window.open(requestUrl)
        
        if(XmlHttp){
        XmlHttp.onreadystatechange = function(){getTypeRes(lb_Scheme)};
        XmlHttp.open("GET", requestUrl,  true);
        XmlHttp.send(null);}
     
     }
  else
  {
        lb_Scheme.disabled=true;
        strikePrice.disabled=true;
        ForEditExpiryDate();
  }
   
    
}


function ForEditExpiryDate()
{
    
    //alert("man")
    var strScheme = document.getElementById("ctl00_pmsContent_ctl00_ddlEditInst");
    var ddlType = document.getElementById("ctl00_pmsContent_ctl00_ddlEditType");
    var sch_name = document.getElementById("ctl00_pmsContent_ctl00_hdnScrip");
    var Stock;
    var ddlExpiry= document.getElementById("ctl00_pmsContent_ctl00_ddlEditExpiry");
    //alert(strInstName.value)
    //alert(strScheme.value)
    //alert(ddlType.value)
    //alert(sch_name.value)
    //alert(ddlType.value)
        CreateXmlHttp();
        document.body.style.cursor = "progress";
        //var requestUrl = "Instruments/Search_StrikePrice.aspx?timeStamp="+ new Date().getTime() +"&strSearch="+sch_name.value+"&strddlInst="+strScheme.value+"&strInstNm="+strInstName.value;
        //alert(sch_name.value);
//        if(sch_name.value="")
//        {
//            alert("!");
//        }
        var urlExpiry = "Instruments/Search_Expiry.aspx?timeStamp="+ new Date().getTime() +"&strSearch="+sch_name.value+"&strddlInstrument="+strScheme.value+"&strddlType="+ddlType.value;
        //alert(urlExpiry)
        //window.open(urlExpiry)
        if(XmlHttp){
        XmlHttp.onreadystatechange = function(){getTypeResExpiry(ddlExpiry)};
        XmlHttp.open("GET",urlExpiry,true);
        XmlHttp.send(null);}
      
    
}

function ForEditStrikeprice()
{
        
    //ddlInstrument
        var strScheme = document.getElementById("ctl00_pmsContent_ctl00_ddlEditType");
        var strInstName = document.getElementById("ctl00_pmsContent_ctl00_ddlEditInst");
        var lb_Scheme = document.getElementById("ctl00_pmsContent_ctl00_ddlEditStrikeprice");
        // lboxvalue
        var sch_name = document.getElementById("ctl00_pmsContent_ctl00_hdnScrip");
        var Stock;
        var ddlExpiry= document.getElementById("ctl00_pmsContent_ctl00_ddlEditExpiry");
            
        if((strInstName.value=="FUTSTK")||(strInstName.value=="FUTIDX"))
        {
            ForEditLotsize();
        }
        else
        {
            CreateXmlHttp();
            document.body.style.cursor = "progress";
            var requestUrl = "Instruments/Search_StrikePrice.aspx?timeStamp="+ new Date().getTime() +"&strSearch="+sch_name.value+"&strddlInst="+strScheme.value+"&strInstNm="+strInstName.value+"&strExpiry="+ddlExpiry.value;
            //            alert(requestUrl)
            //window.open(requestUrl)
            //var urlExpiry = "Instruments/Search_Expiry.aspx?timeStamp="+ new Date().getTime() +"&strSearch="+sch_name.value;
            if(XmlHttp){
            XmlHttp.onreadystatechange = function(){getTypeResStrikeprice(lb_Scheme)};
            XmlHttp.open("GET",requestUrl,true);
            XmlHttp.send(null);}
        }
        
        
        
        
    
}

function ForEditLotsize()
{
    
    //alert("dfsdfs")
    var sch_name = document.getElementById("ctl00_pmsContent_ctl00_hdnScrip");
    var Stock;
    var txtLotSize= document.getElementById("ctl00_pmsContent_ctl00_txtLotSize");
    //alert(strInstName.value)
   // alert(strScheme.value)
   //alert(sch_name.value)
        CreateXmlHttp();
        //document.body.style.cursor = "progress";
        //var requestUrl = "Instruments/Search_StrikePrice.aspx?timeStamp="+ new Date().getTime() +"&strSearch="+sch_name.value+"&strddlInst="+strScheme.value+"&strInstNm="+strInstName.value;
        //alert(requestUrl)
        //window.open(requestUrl)
         var urlExpiry = "Instruments/Search_Lotsize.aspx?timeStamp="+ new Date().getTime() +"&strSearch="+sch_name.value;
        if(XmlHttp){
        XmlHttp.onreadystatechange = function(){getTypeResLotSize(txtLotSize)};
        XmlHttp.open("GET",urlExpiry,true);
        XmlHttp.send(null);}
 
}



////Insure DDl







 
 
 
