//for Commdity
//GET Quotes Commodity

var arrExchange =  new Array('NCDEX','NCDEX','NCDEX','NCDEX','NCDEX','NCDEX','NCDEX','NCDEX','NCDEX','NCDEX','NCDEX','NCDEX','NCDEX','NCDEX','NCDEX','NCDEX' );
var arrCategoryVal =  new Array('Agro Products','Metals','NCDEX Energy','Others','Precious Metals');
var arrCategoryTxt =  new Array('Agro Products','Metals','NCDEX Energy','Others','Precious Metals');
var arrCategoryValM =  new Array('Bullion','Cereals','Energy','Fibre','Metal','Oil | Oil Seeds','Others','Petro Chemicals','Plantations','Pulses','Spices');
var arrCategoryTxtM =  new Array('Bullion','Cereals','Energy','Fibre','Metal','Oil & Oil Seeds','Others','Petro Chemicals','Plantations','Pulses','Spices');

function ChangeCategory(sym)
	{		
	//alert(sym)
		var arrCatVal;		
		var Category = document.getElementById("ctl09_DD_Category");
		//var Category = document.getElementById("_ctl3_DD_Category");
		if(sym != '')
		{
			if(sym == 'NCDEX')
			{
				//document.getElementById('DD_Category').style.height='20px'; 
				arrCatVal	 = arrCategoryVal;
				arrCatValTxt = arrCategoryTxt;
			}
			else if(sym == 'MCX')
			{
				arrCatVal	 = arrCategoryValM;
				arrCatValTxt = arrCategoryTxtM;
			}
		}			
		cnt=1;
		Category.length=0;
		//Category.
		Category.options[0] = new Option(); 
		Category.options[0].value = "";
		Category.options[0].text = "All";
		//alert(arrCatVal.length);
		for(var i=0; i < arrCatVal.length; i++)
		{
		 
		 Category.options[cnt] = new Option();
		 Category.options[cnt].value = arrCatVal[i];
		 Category.options[cnt].text = arrCatValTxt[i];
		  
		 cnt = cnt + 1;
			
		}
		//document.getElementById("mm").style.display="inline";
		
		
		//alert("gggggg");
		
	}
	function ChangeCategoryh(sym)
	{		
	   //alert(sym);
		var arrCatVal;
		//alert(document.getElementById("_ctl3_DD_Category"));
		
		//var Category = document.getElementById('<%=DD_Category.ClientID%>');
		var Category = document.getElementById("ctl09_DD_Category");
		//var Category = document.getElementById("_ctl3_DD_Category");
		//document.getElementById('DD_Category').style.height='336px';
		
					
		if(sym != '')
		{
			if(sym == 'NCDEX')
			{
				//document.getElementById('DD_Category').style.height='20px'; 
				arrCatVal	 = arrCategoryVal;
				arrCatValTxt = arrCategoryTxt;
			}
			else if(sym == 'MCX')
			{
				arrCatVal	 = arrCategoryValM;
				arrCatValTxt = arrCategoryTxtM;
			}
		}			
		cnt=1;
		Category.length=0;
		//Category.
		Category.options[0] = new Option(); 
		Category.options[0].value = "";
		Category.options[0].text = "All";
		//alert(arrCatVal.length);
		for(var i=0; i < arrCatVal.length; i++)
		{
		 
		 Category.options[cnt] = new Option();
		 Category.options[cnt].value = arrCatVal[i];
		 Category.options[cnt].text = arrCatValTxt[i];
		  
		 cnt = cnt + 1;
			
		}
		
	}

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 CommCharts1()
		{
		//alert("technical");
		var f = document.getElementById("exxpdate");
		var CommQuotesTbl = document.getElementById("CommQuotesTbl");
		var Exchg13  = document.getElementById("Exchg13").value;
		var Symbol   = document.getElementById("Symbol").value;
		var ExpDate   = document.getElementById("ExpDate").value;
		var Type   = document.getElementById("<%=DD_CType.ClientID%>").value;
		var Period   = document.getElementById("<%=DD_Period.ClientID%>").value;
		
		var si = document.getElementById("Symbol").selectedIndex;
		//var Exchgi = document.getElementById("Exchg12").selectedIndex;
		var Expi = document.getElementById("ExpDate").selectedIndex;
		
		var StrUrl = "../Commodity/Commodity.aspx?id=7&opt=11&Exchg="+Exchg13+"&Symbol="+Symbol+"&ExpDate="+ExpDate+"&Type="+Type+"&Period="+Period+"&si="+si+"&Expi="+Expi;
		//alert(StrUrl);
		if(Exchg13=="")
			alert("Please Select an Exchange..!");
		else if(Symbol=="")
			alert("Please Select a Symbol..!");
//		else if(ExpDate=="")
//			alert("Please Select Expiry Date..!");
        else if(f.value == "0")
		{
		    alert("Please Select Expiry Date..!");
		    document.getElementById("ExpDate").focus();
		}
		else if(f.value == "1")
		{
		    alert("Please Select Some Other Symbol..!");
		    document.getElementById("Symbol").focus();
		}
		else if(Type=="")
			alert("Please Select a Chart Type..!");
		else if(Period=="")
			alert("Please Select Period..!");
		else
		{
			window.location = StrUrl;
		}
	}	


var xmlHttp
var browser = new Browser();

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;
  }
  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

function ExchngTimeClock(Exchg) {
	 var time = new Date()
	 var hour = time.getHours()
	 if (hour >= 10 && hour <= 20)
		  clockTimeoutID = setTimeout("getTickerData('"+ Exchg +"')",600000);
	}


  
//For Commodity ExpDate Using AJAX
function GetExpDate(Exchg,Symbol)
{
        //alert("ssssssssss");       
        CreateXmlHttp();
		document.body.style.cursor = "progress";
		var requestUrl = "../Commodity/ExpDateData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+ new Date().getTime() +"&Exchg="+ Exchg +"&Symbol="+Symbol;
		//document.write(requestUrl);
		//alert(requestUrl);
		if(XmlHttp)	{
					XmlHttp.onreadystatechange = function(){getDateResp()};
					XmlHttp.open("GET", requestUrl,  true);
					XmlHttp.send(null);
				}
}


function GetExpDate(Exchg,Symbol)
{
        //alert("ssssssssss");       
        CreateXmlHttp();
		document.body.style.cursor = "progress";
		var requestUrl = "../Commodity/ExpDateData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+ new Date().getTime() +"&Exchg="+ Exchg +"&Symbol="+Symbol;
		//document.write(requestUrl);
		//alert(requestUrl);
		if(XmlHttp)	{
					XmlHttp.onreadystatechange = function(){getDateResp()};
					XmlHttp.open("GET", requestUrl,  true);
					XmlHttp.send(null);
				}
}
function getDateResp()
{

	// 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 ExpDate = document.getElementById("ExpDate");
			    //alert(ExpDate.value);		    	
			   	var f = document.getElementById("exxpdate");
			   	ExpDate.options[0] = new Option();
				ExpDate.options[0].value = "Loading...";
				ExpDate.options[0].text = "";
				var strData = XmlHttp.responseText
				//alert(strData);
				if(strData != "")
				{	
				//alert("asdf");
					var arrExpDate = strData.split("|");
					//alert(arrExpDate);
					//alert("aaaaaaaaaaaaaaaa");
					ExpDate.length = 0; 	
					for(i=0; i<arrExpDate.length-1; i++) 
					{	
						var strDate = arrExpDate[i];
						var arrExpDateCode = strDate.split("~");
						ExpDate.options[i] = new Option();
						ExpDate.options[i].value = arrExpDateCode[0];
						ExpDate.options[i].text = arrExpDateCode[1];
						//alert(ExpDate.options[i].value);
					}
					f.value="2";
				}
		
				else 
				{
					ExpDate.length = 0;
					
					ExpDate.options[0] = new Option(); 
					ExpDate.options[0].value = "";
					ExpDate.options[0].text = "No Exp Date";
					
                   f.value="1";
                    
//						if (d = "No Exp Date")
//						{
//						alert ( "No Exp Date Avilable, Please Select Some Other Symbol..!");
//						}
					
					//alert(ExpDate.options[1].text);		
				}
		
				document.body.style.cursor = "auto";	
			
			}
			else
			{
			
					ExpDate.length = 0;
					ExpDate.options[0] = new Option(); 
					ExpDate.options[0].value = "";
					ExpDate.options[0].text = "server is not ready1";
					document.body.style.cursor = "auto";		
			}
	}
	
}
   
   

//Commodity
function getCommQuotes()
	{
	    
		var f = document.getElementById("exxpdate");
		//alert(f.value);
		var Exchg11  = document.getElementById("Exchg11").value;
		var Symbol   = document.getElementById("Symbol").value;
		var ExpDate   = document.getElementById("ExpDate").value;// alert(f.vlaue);	
		//alert(ExpDate);    
		var si = document.getElementById("Symbol").selectedIndex;
		var Exchgi = document.getElementById("Exchg11").selectedIndex;
		var Expi = document.getElementById("ExpDate").selectedIndex;

		var StrUrl = "../Commodity/Commodity.aspx?id=601&opt=612&Exchg="+ Exchg11 +"&Symbol="+ Symbol +"&ExpDate="+ ExpDate+"&si="+si+"&Expi="+Expi
      //alert(StrUrl);
		if(Exchg11=="")
		{
			alert("Please Select an Exchange..!");
			document.getElementById("Exchg11").focus();
		}
		else if(Symbol=="")
		{
			alert("Please Select a Symbol..!");
			document.getElementById("Symbol").focus();
		}
		else if(f.value == "0")
		{
		    alert("Please Select Expiry Date..!");
		document.getElementById("ExpDate").focus();
		}
		else if(f.value == "1")
		{
		    alert("Please Select Some Other Symbol..!");
		document.getElementById("Symbol").focus();
		}	
		else
		{
			window.location = StrUrl;			
		}
 }
 
 
 



//for dropdwon selected//

function selIndex1(si)
	{
		//alert(si);
		document.getElementById('Symbol').selectedIndex=si;
		GetExpDate(document.getElementById('Exchg12').value,document.getElementById('Symbol').value)
		window.setTimeout('test2()', 1000)
	}
function test2()	
	{	
		//alert("BB");
		document.getElementById("ExpDate").selectedIndex = document.getElementById("hid_ExpselIndex1").value;
	}

 
 
 function CommCharts()
		{
		var f = document.getElementById("exxpdate");
//		alert(f.value);
		var CommQuotesTbl = document.getElementById("CommQuotesTbl");
		var Exchg12   = document.getElementById("Exchg12").value;
		var Symbol   = document.getElementById("Symbol").value;
		var ExpDate   = document.getElementById("ExpDate").value;
		var Type   = document.getElementById("DD_CType").value;
		var Period   = document.getElementById("DD_Period").value;
		
		var si = document.getElementById("Symbol").selectedIndex;
		var Exchgi = document.getElementById("Exchg12").selectedIndex;
		var Expi = document.getElementById("ExpDate").selectedIndex;
//		alert(Expi);
		//
		/*var StrUrl = "../Commodity/Commodity.aspx?id=1&opt=12&Exchg="+ Exchg11 +"&Symbol="+ Symbol +"&ExpDate="+ ExpDate+"&si="+si+"&Expi="+Expi*/
		
		var StrUrl = "../Commodity/Commodity.aspx?id=607&opt=611&Exchg="+ Exchg12 +"&Symbol="+ Symbol +"&ExpDate="+ ExpDate+"&Type="+ Type +"&Period="+ Period+"&si="+si+"&Expi="+Expi;
//		alert(StrUrl);
		if(Exchg12=="")
		{
			alert("Please Select an Exchange..!");
			document.getElementById("Exchg12").focus();
		}
		else if(Symbol=="")
		{
			alert("Please Select a Symbol..!");
			document.getElementById("Symbol").focus();
		}
//		else if(ExpDate=="")
//		{
//			alert("Please Select Expiry Date..!");
//			document.getElementById("ExpDate").focus();
//		}
        else if(f.value == "0")
		{
		    alert("Please Select Expiry Date..!");
		document.getElementById("ExpDate").focus();
		}
		else if(f.value == "1")
		{
		    alert("Please Select Some Other Symbol..!");
		document.getElementById("Symbol").focus();
		}
		else if(Type=="")
		{
			alert("Please Select a Chart Type..!");
			document.getElementById("DD_CType").focus();
		}
		else if(Period=="")
		{
			alert("Please Select Period..!");
			document.getElementById("DD_Period").focus();
		}
		else
		{
			window.location = StrUrl;
		}
	}	
	
	
	
	
