/****
script to popup menu in
***/

function showDates(){
	ta = document.getElementById('t');
	ta.style.visibility = 'visible';
}

function hideDates(){
	ta = document.getElementById('t');
	ta.style.visibility = 'hidden';
}

function switchDates(){
	ta = document.getElementById('t');
	if(ta.style.visibility == 'hidden'){
		showDates();
	} else {
		hideDates();
	}
}

function ValandSub(){
	
//	var from = document.getElementById('from');
//	var to = document.getElementById('to');

	
//	if(from.value > to.value){
//		alert("Please ensure date to plot from is less than the plot to date.");
//	} else if (from.value == to.value){
//		to.value++;
//	} else {
		formid = document.getElementById('customform');
		formid.submit();	
//	}
}

function DrawMenu(code, from, span, option){

	// check dates exist if not use today.

	if(from == ''){
		var t = new Date();
	        var months = t.getMonth() + 1;
        	months = (months < 10) ? "0" + "" + months : months;
	        var dates = t.getDate();
        	dates = (dates < 10) ? "0" + "" + dates : dates;
	        from = t.getFullYear() + "" + months + dates;
	}

	//create link to open menu
	document.writeln('<a href=javascript:switchDates()>Custom dates</a>');

	//create table (hidden) and form within table;
	document.writeln('<form id="customform" action="" method="get">');
	document.writeln('<input type="hidden" name="code" value="' + code + '" />');
        if(option != null) { document.writeln('<input type="hidden" name="option" value="' + option + '" />'); }
	document.writeln('<table id="t" style="width:320px; position:absolute; background-color:Wheat;border:1px solid black;visibility:hidden;">');
	document.writeln('<tr><td colspan="2">Please select 2 dates to display data for</td></tr><tr><td style="width:150px;">');
	document.writeln('From:<br />');
	DateInput('from', 'true', 'YYYYMMDD', from);
	document.writeln('</td><td style="width:170px">');
        document.writeln('<input id="span4" type="radio" name="span" value="4" /> 2 days<br />');
        document.writeln('<input id="span5" type="radio" name="span" value="5" /> 7 days<br />');
        document.writeln('<input id="span6" type="radio" name="span" value="6" /> 30 days<br />');
	document.writeln('</td></tr><tr><td>');
	document.writeln('<input type="button" value="submit" onclick="ValandSub()" />');
	document.writeln('<input type="button" value="cancel" onclick="hideDates()" />');
	document.writeln('</td><td>');
	document.writeln('Hide Predictions : ');
	document.writeln('<input type="checkbox" name="plotpred" />');
	document.writeln('</td></tr></table>');
       
        if(span >= 4 && span <= 6){
	  var name = "span" + span;
	  r = document.getElementById(name);
	  r.checked = true;
        } else {
          document.getElementById('span5').checked = true;
        }
}


