﻿//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 fillSymbol(Exchg)
{
	var Symbol = document.getElementById("Symbol");
	cnt=1;
	if(Exchg!='')
	{
		if(Exchg=='MCX')
		{
			arrSymbol     = arrM_Symbol;
			arrSymbolText = arrM_CommName;
		}
		else if(Exchg=='NCDEX')
		{
			arrSymbol	  = arrN_Symbol;
			arrSymbolText = arrN_CommName;
		}
		Symbol.length = 0;
		Symbol.options[0] = new Option();
		Symbol.options[0].value = "";
		Symbol.options[0].text = "Select  Symbol";
		for(var i=0; i < arrSymbol.length; i++)
		{
				Symbol.options[cnt] = new Option(); 
				Symbol.options[cnt].value = arrSymbol[i];
				Symbol.options[cnt].text = arrSymbolText[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();
		}
	}
	
		


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)
{
    CreateXmlHttp();
	document.body.style.cursor = "progress";
	var requestUrl = "/Commodity/ExpDateData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+ new Date().getTime() +"&Exchg="+ Exchg +"&Symbol="+Symbol;
	//alert(requestUrl);
	if(XmlHttp)	{
				XmlHttp.onreadystatechange = function(){getDateResp()};
				XmlHttp.open("GET", requestUrl,  true);
				XmlHttp.send(null);
			}
}
function GetExpDate1()
{
   	//alert("dfs");
   	//document.getElementById("ExpDate").value = "";
   	document.getElementById("ExpDate").options.length = 0;

   	var ExpDate = document.getElementById("ExpDate");
   	ExpDate.options[0] = new Option();
	ExpDate.options[0].value = "";
	ExpDate.options[0].text = "Select Date";
}
function getDateResp()
{
	//alert("sdfsd");
	// 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");
			   	var f = document.getElementById("exxpdate");
			   	
			   	ExpDate.options[0] = new Option();
				ExpDate.options[0].value = "Loading...";
				ExpDate.options[0].text = "";
				
				var strData = XmlHttp.responseText;
				if(strData != "")
				{	
				  var arrExpDate = strData.split("|");
					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[0].text = "Select Date";
						//ExpDate.options[i].value = arrExpDateCode[0];
						ExpDate.options[i].value = arrExpDateCode[1];
						ExpDate.options[i].text = arrExpDateCode[1];
						
					}
					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";
                }
				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(type)
	{
	    
		
		var f = document.getElementById("exxpdate");
		var Exchg11;
		if(type =="1")
		{
		    Exchg11  = document.getElementById('Exchg11').value;
		}
		else
		{
		    Exchg11  = document.getElementById('hid_inexchg').value;
		}
		var Symbol   = document.getElementById("Symbol").value;
		var ExpDate   = document.getElementById("ExpDate").value;// alert(f.vlaue);	
		var si = document.getElementById("Symbol").selectedIndex;
		var Expi = document.getElementById("ExpDate").selectedIndex;
        var StrUrl = "/Commodity/Get-Quotes/"+Exchg11+"/"+ Symbol +"/"+ ExpDate;
		//var 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;			
		}
 }
// 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=4&opt=11&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;
//		}
//	}	
function CommCharts(type)
		{
		//alert("technical");
		var f = document.getElementById("exxpdate");
		var Exchg12;
		if(type =="1")
		{
		    Exchg12  = document.getElementById('Exchg12').value;
		}
		else
		{
		   Exchg12  = document.getElementById('hid_inexchg').value;
		}
		
		var Symbol   = document.getElementById("Symbol").value;
		var ExpDate   = document.getElementById("ExpDate").value;// alert(f.vlaue);	
		var si = document.getElementById("Symbol").selectedIndex;
		var Expi = document.getElementById("ExpDate").selectedIndex;
		
		var Type1   = document.getElementById("DD_CType").value;
		var Period   = document.getElementById("DD_Period").value;
		
		//var StrUrl = "/Commodity/Commodity.aspx?id=4&opt=11&Exchg="+Exchg13+"&Symbol="+Symbol+"&ExpDate="+ExpDate+"&Type="+Type+"&Period="+Period+"&si="+si+"&Expi="+Expi;
		var StrUrl = "/Commodity/Commodity.aspx?id=4&opt=11&Exchg="+ Exchg12 +"&Symbol="+ Symbol +"&ExpDate="+ ExpDate+"&Type="+Type1+"&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(Type=="")
		{
			alert("Please Select a Chart Type..!");
		}
		else if(Period=="")
		{
			alert("Please Select Period..!");
		}
		
		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;			
		}
	
	}	
function changeinner(Exchg,Opt)
{
	document.getElementById("hid_ingain").value=Opt;
	document.getElementById("hid_inexchg").value=Exchg;
	if(Opt == 'Gain')
	{
	    document.getElementById("tdinngain").className="InnTextON1";
		document.getElementById("tdinnlose").className="InnTextOFF1";
		document.getElementById("ainngain").className="TextlnkON";
		document.getElementById("ainnlose").className="TextlnkOFF";
		
		if(Exchg == 'MCX')
		{
		    document.getElementById("tdinnmcx").className="InnTextON";
		    document.getElementById("tdinnncdex").className="InnTextOFF";
		    document.getElementById("lnkinamcx").style.cursor="default";
		    document.getElementById("lnkinancdex").style.cursor="pointer";
	    }
		else
		{
		    document.getElementById("tdinnmcx").className="InnTextOFF";
		    document.getElementById("tdinnncdex").className="InnTextON";
		    document.getElementById("lnkinamcx").style.cursor="pointer";
		    document.getElementById("lnkinancdex").style.cursor="default";
		}
	}
	else if(Opt =='Lose')
	{
	    document.getElementById("tdinngain").className="InnTextOFF1";
		document.getElementById("tdinnlose").className="InnTextON1";
		document.getElementById("ainngain").className="TextlnkOFF";
		document.getElementById("ainnlose").className="TextlnkON";
		if(Exchg == 'MCX')
		{
		    document.getElementById("tdinnmcx").className="InnTextON";
		    document.getElementById("tdinnncdex").className="InnTextOFF";
		    document.getElementById("lnkinamcx").style.cursor="default";
		    document.getElementById("lnkinancdex").style.cursor="pointer";
	    }
		else
		{
		    document.getElementById("tdinnmcx").className="InnTextOFF";
		    document.getElementById("tdinnncdex").className="InnTextON";
		    document.getElementById("lnkinamcx").style.cursor="pointer";
		    document.getElementById("lnkinancdex").style.cursor="default";
		}
	}
	
}
function changeinnerHL(Exchg,Opt)
{
	document.getElementById("hid_ingain").value=Opt;
	document.getElementById("hid_inexchg").value=Exchg;
	if(Opt == 'Highs')
	{
	    document.getElementById("tdinngain").className="InnTextON1";
		document.getElementById("tdinnlose").className="InnTextOFF1";
		document.getElementById("ainngain").className="TextlnkON";
		document.getElementById("ainnlose").className="TextlnkOFF";
		
		if(Exchg == 'MCX')
		{
		    document.getElementById("tdinnmcx").className="InnTextON";
		    document.getElementById("tdinnncdex").className="InnTextOFF";
		    document.getElementById("lnkinamcx").style.cursor="default";
		    document.getElementById("lnkinancdex").style.cursor="pointer";
	    }
		else
		{
		    document.getElementById("tdinnmcx").className="InnTextOFF";
		    document.getElementById("tdinnncdex").className="InnTextON";
		    document.getElementById("lnkinamcx").style.cursor="pointer";
		    document.getElementById("lnkinancdex").style.cursor="default";
		}
	}
	else if(Opt =='Lows')
	{
	    document.getElementById("tdinngain").className="InnTextOFF1";
		document.getElementById("tdinnlose").className="InnTextON1";
		document.getElementById("ainngain").className="TextlnkOFF";
		document.getElementById("ainnlose").className="TextlnkON";
		if(Exchg == 'MCX')
		{
		    document.getElementById("tdinnmcx").className="InnTextON";
		    document.getElementById("tdinnncdex").className="InnTextOFF";
		    document.getElementById("lnkinamcx").style.cursor="default";
		    document.getElementById("lnkinancdex").style.cursor="pointer";
	    }
		else
		{
		    document.getElementById("tdinnmcx").className="InnTextOFF";
		    document.getElementById("tdinnncdex").className="InnTextON";
		    document.getElementById("lnkinamcx").style.cursor="pointer";
		    document.getElementById("lnkinancdex").style.cursor="default";
		}
	}
	
}
function Formvalidinner()
{
    var Opt=document.getElementById("hid_ingain").value;
    var Exchg=document.getElementById("hid_inexchg").value;
	var hid=document.getElementById("hidg_id").value;
	var hopt=document.getElementById("hidg_opt").value;
    var Category = document.getElementById("ctl04_DD_Category").value;
	var S_Category=Category.replace("&","|");
	
	if(hopt=="6")
	{
	    //var Period = document.getElementById("ctl04_DD_Period").value;
	    //document.location = "/Commodity/Commodity.aspx?id="+hid+"&opt="+hopt+"&Exchng="+Exchg+"&Category="+S_Category+"&Top="+Opt+"&Period="+Period;	
	    document.location = "/Commodity/Commodity.aspx?id="+hid+"&opt="+hopt+"&Exchng="+Exchg+"&Category="+S_Category+"&Top="+Opt;
	   // alert(document.location);			
	}
	else
	{
	   
	    document.location = "/Commodity/Commodity.aspx?id="+hid+"&opt="+hopt+"&Exchng="+Exchg+"&Category="+S_Category+"&Top="+Opt;		
	}
} 
function Formvalidinner1()
{
    var Exchg=document.getElementById("hid_inexchg").value;
	var hid=document.getElementById("hidg_id").value;
	var hopt=document.getElementById("hidg_opt").value;
	if(hopt == "8" || hopt == "9")
	{
	    var htype=document.getElementById("HidType").value;
	    document.location = "/Commodity/Commodity.aspx?id="+hid+"&opt="+hopt+"&Exchng="+Exchg+"&EodType="+htype;		
	}
	else
	{
	    document.location = "/Commodity/Commodity.aspx?id="+hid+"&opt="+hopt+"&Exchng="+Exchg;		
	}
}
function changeinner1(Exchg)
{
	document.getElementById("hid_inexchg").value=Exchg;
	if(Exchg == 'MCX')
	{
	    document.getElementById("tdinnmcx").className="InnTextON";
		document.getElementById("tdinnncdex").className="InnTextOFF";
		document.getElementById("lnkinamcx").style.cursor="default";
		document.getElementById("lnkinancdex").style.cursor="pointer";
	}
	else
	{
	    document.getElementById("tdinnmcx").className="InnTextOFF";
		document.getElementById("tdinnncdex").className="InnTextON";
		document.getElementById("lnkinamcx").style.cursor="pointer";
		document.getElementById("lnkinancdex").style.cursor="default";
	}
}

//function white_space(s)
//    {
//    
//        var i
//        i=0;
//        alert(s.length);
//        for(i=0;i<=s.length;i++)
//            {
//                s = s.replace(" % "," ");
//               // s = s.replace(';',',');
//            }
//            
//        return(s)
//    }
/*function ChangeCategory(sym)
{		
    var strURL = window.location.search;
    var ig_b=strURL.split("&");
    for(var ig_c1=0;ig_c1<ig_b.length;ig_c1++)
	{
	    var ig_d=ig_b[ig_c1].indexOf("Category=");
		if(ig_d!=0)continue;
		var ig_c=ig_b[ig_c1].substring(9);
		//white_space(ig_c);
		ig_c=ig_c.replace("%20"," ");
		//ig_c=ig_c.replace("%20"," ");
	}
    alert(ig_c);
    document.getElementById("hid_inexchg").value=sym;
    var arrCatVal;
	var Category = document.getElementById("ctl04_DD_Category");
					
	if(sym != '')
	{
		if(sym == 'NCDEX')
		{
			arrCatVal	 = arrCategoryVal;
			arrCatValTxt = arrCategoryTxt;
		}
		else if(sym == 'MCX')
		{
			arrCatVal	 = arrCategoryValM;
			arrCatValTxt = arrCategoryTxtM;
		}
	}			
	cnt=1;
	Category.length=0;
	Category.options[0] = new Option(); 
	Category.options[0].value = "";
	Category.options[0].text = "All";
	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];
	    if(strURL.indexOf("Category="+arrCatVal[i]+"&") != -1)
	    //if(Category.options[cnt].value==ig_c)
        {
        alert(Category.options[cnt].value)
            Category.options[i+1].selected = true;
		}
		
		cnt = cnt + 1;
	    
	}
}
	*/
