/*
// global vars
var symbol_color_list 	= '';
var today = getToday();
var currdate = getcurrdate();
var date_1M = date_before(31);
var date_3M = date_before(93);
var date_6M = date_before(186);
var date_1Y = date_before(365);
var date_3Y = date_before(1095);
var date_5Y = date_before(1825);

function y2k(number) { 
	return (number < 1000) ? number + 1900 : number; 
} // end of y2k


function isDate (day,month,year) {
    var test = new Date(year,month,day);
        
    if ( (y2k(test.getYear()) == year) &&
         (month == test.getMonth()) &&
         (day == test.getDate()) ) {
        return true;
    } else {
        return false
        }
} // end of isDate


function getToday () {
	var date = new Date();
	var d  = date.getDate();
	var day = (d < 10) ? '0' + d : d;
	var m = date.getMonth() + 1;
	var month = (m < 10) ? '0' + m : m;
	var yy = date.getYear();
	var year = (yy < 1000) ? yy + 1900 : yy;
	return year + '' + month + '' + day;
} // end of get Today 

function getcurrdate () {
	var date = new Date();
	var d  = date.getDate();
	var day = (d < 10) ? '0' + d : d;
	var m = date.getMonth() + 1;
	var month = (m < 10) ? '0' + m : m;
	var yy = date.getYear();
	var year = (yy < 1000) ? yy + 1900 : yy;

	return year + '-' + month + '-' + day;

} // end of currdate


function date_before(difference) { // difference in days
        // sdate = today, variables are from the init part
        var sdate = new Date(today.substr(0,4), today.substr(4,2)-1, today.substr(6,2)); 
        // figure out day, month, year of the difference ago
        var odate = new Date(sdate.getTime() - (difference * 86400000));
        // greates the return string
        var dd  = odate.getDate();
        var day1 = (dd < 10) ? '0' + dd : dd;
        var mm = odate.getMonth() + 1;
        var month1 = (mm < 10) ? '0' + mm : mm;
        var yyyy = odate.getYear();
        var year1 = (yyyy < 1000) ? yyyy + 1900 : yyyy;
        var returnDate = year1 + '-' + month1 + '-' + day1;
        // return value
        return returnDate;

} // end of date_before
*/
function ChangeExchg(EXCHG)
	{	
		window.location = "SharePrice.aspx?Exchg="+EXCHG;		
	}
function ChangeExchgChart(EXCHG)
	{	
		window.location = "SharePricechart.aspx?Exchg="+EXCHG;		
	}	
function ChangeExchgHistory(EXCHG)
	{	
		window.location = "HistoricSharePrice.aspx?Exchg="+EXCHG;		
	}	
function ChangeExchgstockChart(EXCHG)
	{	
		window.location = "stockchart.aspx?Exchg="+EXCHG;		
	}	
function ChangeExchgHigh(EXCHG)
	{	
		window.location = "WeeklyHighLow.aspx?Exchg="+EXCHG;		
	}	
	function changeStyle(exch)
	{
	if(exch=="BSE")
		{
			document.getElementById("trBSE").style.display="inline";
			document.getElementById("trNSE").style.display="none";
		}
		else
		{
			document.getElementById("trNSE").style.display="inline";
			document.getElementById("trBSE").style.display="none";
		}	
	}

function setCustomDateRange() {

	SetDropDownValue('drp_Fday', today.substr(6,2));
	SetDropDownValue('drp_Tday', today.substr(6,2));
	SetDropDownValue('drp_Fmonth', today.substr(4,2));
	SetDropDownValue('drp_Tmonth', today.substr(4,2));
	SetDropDownValue('drp_Fyear', (today.substr(0,4)-1));
	SetDropDownValue('drp_Tyear', today.substr(0,4));

} 

function LoadSimpleChart(Exchg) 
{
	ImgURL = document.getElementById("ChartImg");
	SelDateRange = '?period='+ImageForm.DateRange.value;		
	PlotType = '&PlotType='+ ImageForm.PlotType.value
	
	if(document.ImageForm.Index.checked==true)
	{
		Index = '&Index=Y';	
	}
	else
	{
		Index = '&Index=N';	
	}		

	ChartParams = SelDateRange +  Index + PlotType ;
	ImgURL.src = "ChartSimplePeriod.aspx" + ChartParams+'&Exchg='+Exchg; 	
	return false;
} 


function LoadCustomChart(Exchg) 
{
	ImgURL = document.getElementById("ChartImg");
	var arrDaysinMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);	
	SelDateRange = '&SelDateRange='+ImageForm.DateRange.value;	
	start_date = 'start_date=' + GetDropDownValue("drp_Fyear") +  '-' + GetDropDownValue("drp_Fmonth") + '-' + GetDropDownValue("drp_Fday");
	end_date = '&end_date=' +  + GetDropDownValue("drp_Tyear") +  '-' + GetDropDownValue("drp_Tmonth") + '-' + GetDropDownValue("drp_Tday");		
	sdate=GetDropDownValue("drp_Fyear") +  '-' + GetDropDownValue("drp_Fmonth") + '-' + GetDropDownValue("drp_Fday");
	edate=GetDropDownValue("drp_Tyear") +  '-' + GetDropDownValue("drp_Tmonth") + '-' + GetDropDownValue("drp_Tday");		
	var daysdiff=0;
	var sdays = 0;
	
	var aryDate = sdate.split('-');
		varDay = aryDate[2];
		varMonth = aryDate[1];
		varYear = aryDate[0];
	var aryEndDate = edate.split('-');
		varEndDay = aryEndDate[2];
		varEndMonth = aryEndDate[1];
		varEndYear = aryEndDate[0];
	//alert(varDay + " " + varEndDay)	;
	//alert(varMonth + " " + varEndMonth);
	//alert(varYear + " " + varEndYear);
	if (parseInt(varYear) > parseInt(varEndYear))
	{
		alert("Starting Year should not be Greater Than Ending Year");
		return false;
	}
	else if ((parseInt(varMonth) > parseInt(varEndMonth)) && (parseInt(varYear) == parseInt(varEndYear)))
	{
		alert("Starting month should not be Greater Than Ending month")
		return false;
	}
	else if ((parseInt(varDay) > parseInt(varEndDay)) && (parseInt(varMonth) == parseInt(varEndMonth)) && (parseInt(varYear) == parseInt(varEndYear)))
	{
		alert("Starting Date should not be Greater Than Ending Date");
		return false;
	}	
	if ((parseInt(varEndYear) == parseInt(varYear) ) && ((parseInt(varEndMonth) - parseInt(varMonth)) == 1))
	{
		sdays = arrDaysinMonth[parseInt(varMonth)-1];
		daysdiff = sdays - parseInt(varDay);		
		if (daysdiff < 7)
		{			
			if((daysdiff + parseInt(varEndDay)) < 7)
			{
				alert("Please select atleast 7 days to plot the Chart");
				return false;			
			}
		}
	}
	if ((parseInt(varEndYear) == parseInt(varYear) ) && (parseInt(varEndMonth) == parseInt(varMonth)))
	{
		// daysdiff =  parseInt(varEndDay) - parseInt(varDay);
		daysdiff =  varEndDay - varDay;
		if (daysdiff < 7)
		{			
				alert("Please select atleast 7 days to plot the Chart");
				return false;			
		}
	}		
	if(document.ImageForm.Index.checked==true)
	{
		Index = '&Index=Y';	
	}
	else
	{
		Index = '&Index=N';	
	}

	PlotType = '&PlotType='+ ImageForm.PlotType.value
		
	ChartUrl =  start_date + end_date + Index +PlotType  +"&Button=2";
//	alert(ChartUrl);
	
	ImgURL.src = "ChartSimplePeriod.aspx?" + ChartUrl+'&Exchg='+Exchg;	
	getDefaulPrice('C');
	return false;
} 


function SetDropDownValue (ElementName, value) {
	
	for(i = 0; i < eval('document.ImageForm.' + ElementName + '.length'); i++) {
		if (eval('document.ImageForm.' + ElementName + '.options[' + i + '].value') == value) {
			eval('document.ImageForm.' + ElementName + '.options[' + i + '].selected = true');
		}
	}

} // end of SetDropDownValue


function GetDropDownValue (ElementName) {
	for(i = 0; i < eval('document.ImageForm.' + ElementName + '.length'); i++) {
        if (eval('document.ImageForm.' + ElementName + '.options[' + i + '].selected') == true) {
			return (eval('document.ImageForm.' + ElementName + '.options[' + i + '].value'))
        }
	}

} // end of GetDropDownValue

//For Bottom Table
function getDefaulPrice(SelOption,Exchg)
{	
	if(SelOption=="S")
	{
		Params = '?Exchg='+Exchg+'&period='+ ImageForm.DateRange.value;			
	}
	else if(SelOption=="C")
	{
		fromPeriod = ImageForm.drp_Fyear.value + '-' + ImageForm.drp_Fmonth.value + '-' + ImageForm.drp_Fday.value
		toPeriod = ImageForm.drp_Tyear.value + '-' + ImageForm.drp_Tmonth.value + '-' + ImageForm.drp_Tday.value
		Params = '?Exchg='+Exchg+'&FromDate='+fromPeriod+'&ToDate='+toPeriod;
	}	
	var Url = "PriceData.aspx"+Params;
	//alert(Url);
	document.getElementById("TdSelPeriodPrice").innerHTML="<table cellpadding='0' cellspacing='0' width='100%' border='0'><tr><td  align='center' width='390px' height='130px'><img src='images/loading.gif'></td></tr></table>";
	var ajax = new Ajax.Updater('TdSelPeriodPrice',Url);
}

function DownloadData(SelOption,Exchg)
{	
	if(SelOption=="S")
	{
		Params = '?Exchg='+Exchg+'&period='+ ImageForm.DateRange.value;			
	}
	else if(SelOption=="C")
	{
		fromPeriod = ImageForm.drp_Fyear.value + '-' + ImageForm.drp_Fmonth.value + '-' + ImageForm.drp_Fday.value
		toPeriod = ImageForm.drp_Tyear.value + '-' + ImageForm.drp_Tmonth.value + '-' + ImageForm.drp_Tday.value
		Params = '?Exchg='+Exchg+'&FromDate='+fromPeriod+'&ToDate='+toPeriod;
	}	
	var Url = "DownloadData.aspx"+Params;	
		document.location.href = Url;	
}


