function showGraph (text) {
	if (currentImagePath == "") {
		//document.getElementById ("live_status").src = "images/live-filler.gif";
		$("#live-sun").attr ("class", "inactive");
		//document.getElementById ("live_button").disabled = false;
	} else {
		textItems = text.split ("~");
		var graphTotals = $("GraphTotals");
		var pageName = "";
		if (document.getElementById ("demositesNavigation"))
			pageName = "demosites.php";
		SetGraphImage (currentImagePath, currentImageName, pageName);
  		graphTotals.innerHTML = textItems[1];
		document.getElementById ("ajax_spinner").src = "images/ajax-spinner-filler-trans.gif";
		
		if (textItems[2] == '1') {
			//document.getElementById ("live_status").src = "images/live.gif";
			$("#live-sun").attr ("class", "active");
			//document.getElementById ("live_button").disabled = true;
		} else {
			$("#live-sun").attr ("class", "inactive");
			//document.getElementById ("live_status").src = "images/live-filler.gif";
			//document.getElementById ("live_button").disabled = false;
		}
	}
}

function updateGraphType (text) {
	if (document.getElementById ("dateselect")) {
		graphTimes = text.split ("~");
		document.dateselect.graphfromdate.value = graphTimes[0];
		document.dateselect.graphtodate.value = graphTimes[1];
		document.getElementById ("ajax_spinner").src = "images/ajax-spinner-filler-trans.gif";
		
		if (graphTimes[2] == '1') {
			$("#live-sun").attr ("class", "active");
			//document.getElementById ("live_status").src = "images/live.gif";
			//document.getElementById ("live_button").disabled = true;
		} else {
			$("#live-sun").attr ("class", "inactive");
			//document.getElementById ("live_status").src = "images/live-filler.gif";
			//document.getElementById ("live_button").disabled = false;
		}
		
		if (document.getElementById("GraphImage")) {
			document.getElementById("GraphImage").src = currentImagePath+"graph"+currentImageName+".png?Id="+(new Date()).getTime();
			document.getElementById("GraphImageBtu").src = currentImagePath+"graph"+currentImageName+"_btu.png?Id="+(new Date()).getTime();
			document.getElementById("GraphImageSun").src = currentImagePath+"graph"+currentImageName+"_sun.png?Id="+(new Date()).getTime();
			if (document.getElementById("GraphImageIrrad")) {
				document.getElementById("GraphImageIrrad").src = currentImagePath+"graph"+currentImageName+"_irrad.png?Id="+(new Date()).getTime();
			}
		}
	}
}

function ChangeInterval () 
{
	currentInterval = document.dateselect.calendar_interval.value;
	if (currentImagePath != "") {
		SetGraphImage (currentImagePath, currentInterval, "");		
	}
}

function SetGraphImage (ImagePath, ImageName, pageName)
{
	if (document.getElementById("GraphImage")) {
		currentImagePath = ImagePath;
		currentImageName = ImageName;
	}
	
	if (ImageName != "custom") {
		document.dateselect.graphtodate.disabled = true;
		document.getElementById("f-calendar-trigger-2").style.display = 'none';
	} else {
		document.dateselect.graphtodate.disabled = false;
		document.getElementById("f-calendar-trigger-2").style.display = '';
	}
	
	document.getElementById("calendar_interval_"+currentImageName).selected = true;

	SetIconImages (currentImagePath);
	HighlightIconImage();
	
	document.getElementById ("ajax_spinner").src = "images/ajax-spinner-white-on-black.gif";
	ajaxCaller.getPlainText ("updategraphtype.php?pageName="+pageName+"&image_name="+ImageName+"&Id="+(new Date()).getTime(), updateGraphType);
}

function updateGraphTimes (text) 
{
	graphTimes = text.split ("~");
	
	document.dateselect.graphfromdate.value = graphTimes[0];
	document.dateselect.graphtodate.value = graphTimes[1];
	if (document.getElementById("GraphImage")) {
		document.getElementById("GraphImage").src = currentImagePath+"graph"+currentImageName+".png?Id="+(new Date()).getTime();
		document.getElementById("GraphImageBtu").src = currentImagePath+"graph"+currentImageName+"_btu.png?Id="+(new Date()).getTime();
		document.getElementById("GraphImageSun").src = currentImagePath+"graph"+currentImageName+"_sun.png?Id="+(new Date()).getTime();
		if (document.getElementById("GraphImageIrrad")) {
			document.getElementById("GraphImageIrrad").src = currentImagePath+"graph"+currentImageName+"_irrad.png?Id="+(new Date()).getTime();
		}
	}
	SetIconImages (currentImagePath);
	document.getElementById ("ajax_spinner").src = "images/ajax-spinner-filler-trans.gif";
	
	if (graphTimes[2] == '1') {
		$("#live-sun").attr ("class", "active");
		//document.getElementById ("live_status").src = "images/live.gif";
		//document.getElementById ("live_button").disabled = true;
	} else {
		$("#live-sun").attr ("class", "inactive");
		//document.getElementById ("live_status").src = "images/live-filler.gif";
		//document.getElementById ("live_button").disabled = false;
	}
}

function SetGraphTimes (pageName)
{
	startTime = document.dateselect.graphfromdate.value;
	endTime = document.dateselect.graphtodate.value;
	
	document.getElementById ("ajax_spinner").src = "images/ajax-spinner-white-on-black.gif";
	ajaxCaller.getPlainText ("updategraphtimes.php?pageName="+pageName+"&start_time="+startTime+
					  				 "&end_time="+endTime+
					  				 "&Id="+(new Date()).getTime(), updateGraphTimes);
}

function SetCurrentGraphTimes (pageName)
{
	document.getElementById ("ajax_spinner").src = "images/ajax-spinner-white-on-black.gif";
	ajaxCaller.getPlainText ("setcurrentgraphtimes.php?pageName="+pageName+"&Id="+(new Date()).getTime(), updateGraphTimes);
}

function SetAllCurrentGraphTimes (pageName)
{
	document.getElementById ("ajax_spinner").src = "images/ajax-spinner-white-on-black.gif";
	ajaxCaller.getPlainText ("setcurrentgraphtimes.php?pageName="+pageName+"&all=1&Id="+(new Date()).getTime(), updateGraphTimes);
}

function PreviousTime (pageName)
{
	startTime = document.dateselect.graphfromdate.value;
	endTime = document.dateselect.graphtodate.value;
	preset = document.dateselect.calendar_presets.value;
	
	document.getElementById ("ajax_spinner").src = "images/ajax-spinner-white-on-black.gif";
	ajaxCaller.getPlainText ("updategraphtimes.php?pageName="+pageName+"&prev="+preset+"&start_time="+startTime+
					  				 "&end_time="+endTime+
					  				 "&Id="+(new Date()).getTime(), updateGraphTimes);
}

function NextTime (pageName)
{
	startTime = document.dateselect.graphfromdate.value;
	endTime = document.dateselect.graphtodate.value;
	preset = document.dateselect.calendar_presets.value;
	
	document.getElementById ("ajax_spinner").src = "images/ajax-spinner-white-on-black.gif";
	ajaxCaller.getPlainText ("updategraphtimes.php?pageName="+pageName+"&next="+preset+"&start_time="+startTime+
					  				 "&end_time="+endTime+
					  				 "&Id="+(new Date()).getTime(), updateGraphTimes);
}

function SetIconImages (ImagePath)
{
	if (document.getElementById("icon1hr")) {
		document.getElementById("icon1hr").src = ImagePath+"icon1hr.png?Id="+(new Date()).getTime(); 
		document.getElementById("icon3hr").src = ImagePath+"icon3hr.png?Id="+(new Date()).getTime(); 
		document.getElementById("icon6hr").src = ImagePath+"icon6hr.png?Id="+(new Date()).getTime(); 
		document.getElementById("icon12hr").src = ImagePath+"icon12hr.png?Id="+(new Date()).getTime(); 
		document.getElementById("icon24hr").src = ImagePath+"icon24hr.png?Id="+(new Date()).getTime(); 
		document.getElementById("icon3day").src = ImagePath+"icon3day.png?Id="+(new Date()).getTime(); 
		document.getElementById("icon7day").src = ImagePath+"icon7day.png?Id="+(new Date()).getTime(); 
		//document.getElementById("iconcustom").src = ImagePath+"iconcustom.png?Id="+(new Date()).getTime(); 
	}
}                                                                                  

function HighlightIconImage ()
{
	if (document.getElementById("icon1hr_td")) {
		document.getElementById("icon1hr_td").style.border = "0px";
		document.getElementById("icon3hr_td").style.border = "0px";
		document.getElementById("icon6hr_td").style.border = "0px";
		document.getElementById("icon12hr_td").style.border = "0px"; 
		document.getElementById("icon24hr_td").style.border = "0px"; 
		document.getElementById("icon3day_td").style.border = "0px"; 
		document.getElementById("icon7day_td").style.border = "0px"; 
		//document.getElementById("iconcustom_td").style.border = "0px"; 
		if (document.getElementById("icon"+currentImageName+"_td"))
			document.getElementById("icon"+currentImageName+"_td").style.border = "2px solid #060";
	}
}                                                                                  
