
function VerifySunImage_BackUpADay(daysBack)
{
	if(!document.SpaceWeatherSunImage.complete)
	{
		daysBack--;
		document.SpaceWeatherSunImage.src = GetSpaceWeatherImageFolderURL(SetSpaceWeatherDate(daysBack)) + GetSpaceWeatherDefaultImageName();
		if(daysBack > -5)
		{
			setTimeout("VerifySunImage_BackUpADay(" + daysBack + ")",1000);
		}
	}
}

    function GetSpaceWeatherDefaultImageName()
    {
        //return 'midi140.gif';
        return 'midi163.gif';
    }

	function GetSpaceWeatherImageTag(theDate, imageType)
	{
	    var imageName, imageHeight, imageWidth;
		switch(imageType)
		{
			case 'coronal': 
			    imageName = 'coronalhole_sxi.gif';
			    imageHeight = '128';
			    imageWidth = '128';
			    break;
			case 'coronalBlank': 
			    imageName = 'coronalhole_sxi_blank.gif';
			    imageHeight = '128';
			    imageWidth = '128';
			    break;
			case 'coronalSoho': 
			    imageName = 'coronalhole_soho.gif';
			    imageHeight = '140';
			    imageWidth = '140';
			    break;
			case 'coronalSohoBlank': 
			    imageName = 'coronalhole_soho_blank.gif';
			    imageHeight = '512';
			    imageWidth = '512';
			    break;
			case 'midi512': 
			    imageName = 'midi512_blank.gif';
			    imageHeight = '512';
			    imageWidth = '512';
			    break;
			default: //midi140
			    //imageName = 'midi140.gif';
			    //imageHeight = '140';
			    //imageWidth = '140';
			    imageName = 'midi163.gif';
			    imageHeight = '163';
			    imageWidth = '163';
			    break;
		}
		return('<img name="SWI'+imageType+'" src="' +  GetSpaceWeatherImageFolderURL(theDate) + imageName + '" alt="" width="'+imageHeight+'" height="'+imageWidth+'" border="0">');
	}
	

	
	function GetSpaceWeatherImageFolderURL(theDate)
	{
		var url = 'http://www.spaceweather.com';
		url += '/images' +  theDate.getYear();
		url += '/' + GetTwoDigitDay(theDate) + GetMonthString(theDate) + GetTwoDigitYear(theDate);
		url += '/';
		return url;
	}
	
	function GetSunSetImageURL(theDate)
	{

		var url = '';
		url += 'SunsetsDateNamed';
		url += '/20' + GetTwoDigitYear(theDate) + GetTwoDigitMonth(theDate) + GetTwoDigitDay(theDate);
		url += '.jpg';
		//alert(url);
		return url;
	}
	
	function SetSpaceWeatherDate(daysBack)
	{
		var theDate = new Date();
		if(daysBack != 0)
		{
			theDate = dateAdd('d', daysBack, theDate);
		}
		return theDate;
	}
	
	function FormatShortDate(theDate)
	{
		//return theDate.getMonth()+1 + '/' + GetTwoDigitDay(theDate) + '/' + theDate.getYear();
		return datePart('m', theDate) + '/' + datePart('d', theDate) + '/' + datePart('yyyy', theDate);
	}
	
	function SetFirstDateOfWeek(theDate, firstDayOfWeekAsText)
	{
		var localDate = theDate;
		for(var cnt=0; cnt > -7; cnt--)
		{
			localDate = dateAdd('y', cnt, theDate)
			if(weekdayName(localDate, false) == firstDayOfWeekAsText)
			{
				return localDate;
			}
		}
		return theDate;
	}
	function SetFirstDateOfMonth(theDate)
	{
		return theDate.getMonth()+1 + '/1/' + theDate.getYear();
	}
	

	
	function GetTwoDigitYear(theDate)
	{
		var yearNumber = theDate.getYear();
		return (yearNumber > 2000) ? AddTwoDigitZero(yearNumber - 2000) : yearNumber;
	}
	
	function GetTwoDigitDay(theDate)
	{
		var dayNumber = theDate.getDate();
		return AddTwoDigitZero(dayNumber);
	}
	
		function GetTwoDigitMonth(theDate)
	{
		var monthNumber = theDate.getMonth();
		monthNumber += 1;
		return AddTwoDigitZero(monthNumber);
	}
	
	function AddTwoDigitZero(theNumber)
	{
		return (theNumber < 10) ? '0' + theNumber : theNumber;
	}
	
	function GetMonthString(theDate)
	{
		var monthNumber = theDate.getMonth();
		monthNumber += 1;
		switch(monthNumber)
		{
			case 1: return 'jan';
			case 2: return 'feb';
			case 3: return 'mar';
			case 4: return 'apr';
			case 5: return 'may';
			case 6: return 'jun';
			case 7: return 'jul';
			case 8: return 'aug';
			case 9: return 'sep';
			case 10: return 'oct';
			case 11: return 'nov';
			case 12: return 'dec';
		}
	}
	
	
	
	function SetSpaceWeatherFirstDayOfMonthXXX(monthsBack)
	{
		var theDate = new Date();
		theDate = dateAdd('m', monthsBack, theDate);
		theDate = theDate.getMonth()+1 + '/1/' + theDate.getYear();
		return theDate;
	}
	
		function formatTheDateXXX(theDate)
	{
		return (theDate.getMonth()+1) + '-' + theDate.getDate() + '-' + theDate.getYear();
	}