﻿<!--
		
//
// Function to modify the contents of the 'freq' so as to not be so granular
//
function ddchange()
{
	var SelectedValue, ListLength, Selectedary
	
	Selectedary = document.WebForm.time.selectedIndex;
	freqListLength = document.WebForm.freq.length;
	
	if( Selectedary > 4 )			//take don't let -dayly b shown in other list
	{  
		if( freqListLength == 9 )	//make sure they r not already taken out
		{  
			document.WebForm.freq.options[0] = null;	//use 0 on all  
			document.WebForm.freq.options[0] = null;
			document.WebForm.freq.options[0] = null;
			document.WebForm.freq.options[0] = null;
			document.WebForm.freq.options[0].select;
		}
	}
	else
	{
		if( freqListLength == 5 )	//check if items already removed if so add again
		{ 
		document.WebForm.freq.options[0] = new Option( "1 Minute (intraday)", "1mi" )
		document.WebForm.freq.options[1] = new Option( "5 Minute (intraday)", "5mi" )
		document.WebForm.freq.options[2] = new Option( "15 Minute (intraday)", "15mi" )
		document.WebForm.freq.options[3] = new Option( "Hourly (intraday)", "1hr" )
		document.WebForm.freq.options[4] = new Option( "Daily", "1dy" )
		document.WebForm.freq.options[5] = new Option( "Weekly", "1wk" )
		document.WebForm.freq.options[6] = new Option( "Monthly", "1mo" )
		document.WebForm.freq.options[7] = new Option( "Quarterly", "3mo" )
		document.WebForm.freq.options[8] = new Option( "Yearly", "1yr" )
		}
	}
}

//
// fetches a new chart
//
function swapchart()
{
	var timeframetxt, timeframeval, freqtxt, freqval, ImgSRC, compval
	
	timeframeval = (document.WebForm.time.options[document.WebForm.time.selectedIndex].value);
	timeframetxt = (document.WebForm.time.options[document.WebForm.time.selectedIndex].text);

	freqval = (document.WebForm.freq.options[document.WebForm.freq.selectedIndex].value);
	freqtxt = (document.WebForm.freq.options[document.WebForm.freq.selectedIndex].text);

	compval = (document.WebForm.comp.options[document.WebForm.comp.selectedIndex].value);

	ImgSRC = 'http://chart.bigcharts.com/custom/ccbn-com/stockchart/chart.asp?symb=GMET&time='+timeframeval+'&freq='+freqval+'&compidx='+compval+'&uf=0&style=453&size=2&comp=&ma=1&maval=0&type=2&startdate=&enddate=&rightfill=0&sectype=&onerr=&onnosymb=&rand=8189&lf=1&sid=678594';
	NewImage = new Image();
	NewImage.src = ImgSRC;
	document.images['stockchart'].src = NewImage.src;
					
	return false;
}


function validate_date(mm, dd, yyyy)
{
	if (date_validate(mm,dd,yyyy)==false)
		{
		alert('You have selected an invalid date.  Please select a valid date');
		return false
		}
	else if (is_historical_date(mm, dd, yyyy)==false)
		{
		alert('You have entered a date in the future therefore no historical data is available.  Please enter a past date.');
		return false
		};
	return true
}
					
function date_validate(mm, dd, yyyy)
{
	var chk    = 0;
	var maxDay = 0;

	if (mm<1||mm>12) return false;
						
	if (yyyy.length==2) yyyy='20'+yyyy;
						
	if (yyyy<1970||yyyy>2010) return false;
						
	// calling function to get maximum day for this month
	maxDay = max_day(mm, yyyy);  

	if((dd <= 0) || (dd > maxDay))
		return false
	else if((mm <= 0) || (mm > 12))
		return false
	else if((yyyy <= 0))
		return false
	else
		return true
}

// function for calculating maximum day 
function max_day(mn, yr)
{
   var mDay;
	if((mn == 4) || (mn == 6) || (mn == 9) || (mn == 11))
		{ 
		mDay = 30;
		}
	else if(mn == 2)
		{
		//calling leap year function 
		mDay = isLeapYear(yr) ? 29 : 28;    
		}
	else
		{
		mDay = 31;
		}
	return mDay; 
}

	// function to check leap year
function isLeapYear(yr)
{
	if (yr % 4 == 0) 
	  return true;
	  
	return false;
}

function is_historical_date(mm, dd, yyyy)
{
	mm=mm-1; //Month is zero based
	var today = new Date();
	var target = new Date(yyyy, mm, dd);
	diff = target.getTime() - today.getTime();
	
	if (diff > 0)
		return false
	else
		return true;
}					
// -->		
