/* Copyright (c) Clean Power Research, 1998-2003.  All rights reserved.*/
oldDefaultResult = ""

function general_showResults()
{
    if(window.document.movieShade != null)
    {
        general_showResults_WithMovieShade();
    }
    else
    {
        general_showResults_WithoutMovieShade();
    }
}

function general_showResults_WithMovieShade() {

	defaultResult = result.defaultResult
	defaultResultNumber = result.defaultResultNumber
	
	if (document.navForm.navDisplayOptions.value.indexOf("Graphs") > -1) {
		// The user can view graphic results
	
		if (browserVersion != "Netscape4") {
			if ((defaultResult.indexOf("Graph")>=0) || (defaultResult.indexOf("Build System")>=0))
			{
			    if(defaultResult.indexOf("Shading Analysis") > -1)
			    {
				    window.document.movieShade.height = movieObjectHeight;
				    window.document.movie.height = 1;
		        }
		        else
		        {
		            window.document.movieShade.height = 1;
		            window.document.movie.height = movieObjectHeight;
		        }
			}
			else
			{
			    window.document.movieShade.height = 1;
				window.document.movie.height = 1;
			}
		}

		// Get the shading analysis results and store them in result.obstructionElevation
		if (oldDefaultResult.indexOf("Shading Analysis")>=0) {
			// The shading analysis is about to be unloaded; get the results
			plots_GetElevationObstructionResults();
			// Results need to be recalculated
			calculateBillSavings();
		}
		
		// Determine where the movies should be loaded from
		var baseref = location.href.substring(0,location.href.lastIndexOf("/") +1);

		if (location.protocol.indexOf("http")>-1) {
			// This is run from the internet
			var movieLocation = baseref + "movies/";
		} else {
			// This is run from a file
			var movieLocation = baseref;
		}
		
		// Load the correct movie
		if (defaultResult.indexOf("Build System")>=0) {
			if (defaultResult != oldDefaultResult) {
				// The name of the movie file is embeded in the value name
				movieFileName = movieLocation + defaultResult.substring(13,defaultResult.length) + ".swf"
				window.document.movie.LoadMovie(0, movieFileName);
			}
		
			// Pass the PV system rating in Watts to flash
			PVSystemRatingVariable = result.PVSystemNameplateTotal*1000
			window.document.movie.SetVariable("PVSystemRatingVariable",PVSystemRatingVariable)
		} else if (defaultResult.indexOf("Shading Analysis")>=0) {
			//if(oldDefaultResult.indexOf("Shading Analysis") == -1)
			//{
			   //here's a Flash swf property list
			   //http://www.adobe.com/support/flash/publishexport/scriptingwithflash/scriptingwithflash_04.html
			    
			    //var shadingMovieName = "shading.swf";
			    //movieFileName = movieLocation + shadingMovieName;
			    //var urlIndex = 15;
			    //var loadedName = window.document.movie.TGetProperty("/", urlIndex);
			    //alert(loadedName);
			    //var frameCount = window.document.movie.TGetProperty("/", 5);
			    //alert(frameCount);
			    //if(loadedName.indexOf(shadingMovieName) < 0)
			    //{
			    //    alert("Loading shading movie");
			    //    window.document.movie.LoadMovie(0, movieFileName);
			    //}
			    
			    
			//}
			// Set the results
			plots_SetElevationObstructionResults();
			
		}
		else
		{
			if ((oldDefaultResult.indexOf("Build System")>=0) || (oldDefaultResult.indexOf("Shading Analysis")>=0) || ((oldDefaultResult == "") && (defaultResult.indexOf("Shading Analysis") < 0)))
			{
				// Reload the graphs
				//movieFileName = movieLocation + "graphs.swf";
				//window.document.movie.LoadMovie(0,movieFileName)
			}
			// Populate the graphs	
			plots_ProduceGraph(defaultResult,defaultResultNumber)
		} 

	}
	
	// The user can view text  results
	if (document.navForm.navDisplayOptions.value.indexOf("Text") > -1) {
		text_showDetailsMainPage(defaultResult,defaultResultNumber)
	}
		
	// Save this for the next result
	oldDefaultResult = defaultResult
}

function general_showResults_WithoutMovieShade() {

	defaultResult = result.defaultResult
	defaultResultNumber = result.defaultResultNumber
	
	if (document.navForm.navDisplayOptions.value.indexOf("Graphs") > -1) {
		// The user can view graphic results
	
		if (browserVersion != "Netscape4") {
			if ((defaultResult.indexOf("Graph")>=0) || (defaultResult.indexOf("Build System")>=0)) {
				window.document.movie.height = movieObjectHeight
			} else {
				window.document.movie.height = 1
			}
		}

		// Get the shading analysis results and store them in result.obstructionElevation
		if (oldDefaultResult.indexOf("Shading Analysis")>=0) {
			// The shading analysis is about to be unloaded; get the results
			plots_GetElevationObstructionResults();
			// Results need to be recalculated
			calculateBillSavings();
		}
		
		// Determine where the movies should be loaded from
		var baseref = location.href.substring(0,location.href.lastIndexOf("/") +1);

		if (location.protocol.indexOf("http")>-1) {
			// This is run from the internet
			var movieLocation = baseref + "movies/";
		} else {
			// This is run from a file
			var movieLocation = baseref;
		}
		
		// Load the correct movie
		if (defaultResult.indexOf("Build System")>=0) {
			if (defaultResult != oldDefaultResult) {
				// The name of the movie file is embeded in the value name
				movieFileName = movieLocation + defaultResult.substring(13,defaultResult.length) + ".swf"
				window.document.movie.LoadMovie(0, movieFileName);
			}
		
			// Pass the PV system rating in Watts to flash
			PVSystemRatingVariable = result.PVSystemNameplateTotal*1000
			window.document.movie.SetVariable("PVSystemRatingVariable",PVSystemRatingVariable)
		} else if (defaultResult.indexOf("Shading Analysis")>=0) {
			movieFileName = movieLocation + "shading.swf";
			window.document.movie.LoadMovie(0, movieFileName);
			// Set the results
			plots_SetElevationObstructionResults();
		} else {
			if ((oldDefaultResult.indexOf("Build System")>=0) || (oldDefaultResult.indexOf("Shading Analysis")>=0)) {
				// Reload the graphs
				movieFileName = movieLocation + "graphs.swf";
				window.document.movie.LoadMovie(0,movieFileName)
			}
			// Populate the graphs	
			plots_ProduceGraph(defaultResult,defaultResultNumber)
		} 

	}
	
	// The user can view text  results
	if (document.navForm.navDisplayOptions.value.indexOf("Text") > -1) {
		text_showDetailsMainPage(defaultResult,defaultResultNumber)
	}
		
	// Save this for the next result
	oldDefaultResult = defaultResult
}
				
/* Navigation functions */
function general_CheckZipCode() {
	zipCodeTemp = document.navForm.navZipcode.value
	if (zipCodeTemp!="") {
		zipCodeTemp = parseInt(document.navForm.navZipcode.value*1)
		// Show or hide detailed results for all but Netscape4 - it is not enabled for that version
		if (isNaN(zipCodeTemp) || (zipCodeTemp <1) || (zipCodeTemp>99999)) {
			alert("This is not a valid zip code, please re-enter it")
			document.navForm.navZipcode.value = ""
		}
	}
}

function general_SubmitState(temp) {
	// Assign a value for the state and submit
	document.navForm.navState.value = temp
	document.navForm.submit()
}

function general_SubmitCityLetter(temp) {
	// Assign a value for the state and cityLetterand submit
	document.navForm.navCityLetter.value = temp
	document.navForm.submit()
}

function general_SubmitCity(temp) {
	// Assign a value for the city number
	document.navForm.navCity.value = temp
	document.navForm.submit()
}

function general_SubmitRate(temp) {
	// Assign a value for the city number and rate
	document.navForm.navNowRate.value = temp
	document.navForm.submit()
}

function general_SubmitProposedRate(temp) {
	// Assign a value for the city number and rate
	document.navForm.navProposedRate.value = temp
	document.navForm.submit()
}

function general_SubmitRateAndCity(tempCity,tempRate) {
	// Assign a value for the city number and rate
	document.navForm.navCity.value = tempCity
	document.navForm.navNowRate.value = tempRate
	document.navForm.submit()
}

// Miscenalleous functions
function general_CheckBrowserVersion() {
	// Determine the correct browserVersion when the program is first run
	browserVersion = 'Version3'
	//browserVersion = 'IE5'
	if (navigator.appName.indexOf("Netscape") != -1) {
		if (parseInt(navigator.appVersion) >= 5) {
			browserVersion = 'Netscape6'
		}
		if (parseInt(navigator.appVersion) == 4) {
			browserVersion = 'Netscape4'
		}
	} else {
		if (navigator.appVersion.indexOf("MSIE 4") != -1) {
			browserVersion = 'IE4'
		}
		if (navigator.appVersion.indexOf("MSIE 5") != -1) {
			browserVersion = 'IE5'
		}
		if (navigator.appVersion.indexOf("MSIE 6") != -1) {
			browserVersion = 'IE5'
		}
		if (navigator.appVersion.indexOf("MSIE 7") != -1) {
			browserVersion = 'IE5'
		}
		if (navigator.appVersion.indexOf("MSIE 8") != -1) {
			browserVersion = 'IE5'
		}
	}
}


function general_CheckFlashVersion() {
	flashVersion = 5
	
	if (navigator.platform.indexOf("Win")==-1) {
		// This is not a windows platform and graphs do not work
		flashVersion =0
		
		return
	}
	if (navigator.appName.indexOf("Netscape") != -1) {
		// See if the plugin is version 4
		flashVersion = 0
		
		if (browserVersion == "Netscape6") {
			// prevernt the user from viewing the graphics
			return
		}
		
		// Eventually, these lines should be activated.  For now (11/11/01) Flash does not work with layers.
		
		for (var i=0;i<navigator.plugins.length;i++) {
			if (navigator.plugins[i].name == "Shockwave Flash") {
				// Flash is installed
				flashInstalled = true
				flashDescription = navigator.plugins[i].description
				flashVersionPosition = flashDescription.lastIndexOf("Shockwave Flash ")
				flashVersion = flashDescription.substr(flashVersionPosition+16,1)
				break
			}
		}
	}
}

// List visibility and position functions
// This function changes the visibility of a div or layer tag
function general_ChangeLayerObjectDisplay(layerNameTemp,visibleOrHidden) {
  
    if ((browserVersion == 'Netscape6')||(browserVersion == 'IE5')) {
		document.getElementById(layerNameTemp).style.visibility = visibleOrHidden
	}
    if (browserVersion == 'IE4') {
		eval ('document.all.' + layerNameTemp + '.style.visibility = "' + visibleOrHidden + '"')
	}
    if (browserVersion == 'Netscape4') {
		eval ('document.' + layerNameTemp + '.visibility = "' + visibleOrHidden + '"')
	}
} 

// This function changes the x position of a layer or div
function general_ChangeLeftPosition(layerNameTemp,newPositionTemp,relativeOrAbsoluteTemp) {
	// Get the current position if necessary
	if (relativeOrAbsoluteTemp == "relative") {
		if ((browserVersion == 'Netscape6')||(browserVersion == 'IE5')) {
			currentPositionTemp = document.getElementById(layerNameTemp).offsetLeft
		}
		if (browserVersion == 'IE4') {
			currentPositionTemp = eval ('document.all.' + layerNameTemp + '.style.pixelLeft')
		}
		if (browserVersion == 'Netscape4') {
			currentPositionTemp = eval ('document.' + layerNameTemp + '.left')
		}
	} else {
		currentPositionTemp = 0
	}

	newPositionTemp = newPositionTemp + currentPositionTemp
	// Set the new position
    if ((browserVersion == 'Netscape6')||(browserVersion == 'IE5')) {
		document.getElementById(layerNameTemp).style.left = newPositionTemp
	}
    if (browserVersion == 'IE4') {
		eval ('document.all.' + layerNameTemp + '.style.pixelLeft = ' + newPositionTemp)
	}
    if (browserVersion == 'Netscape4') {
		eval ('document.' + layerNameTemp + '.left = ' + newPositionTemp)
	}
} 

// This function changes the y position of a layer or div
function general_ChangeTopPosition(layerNameTemp,newPositionTemp,relativeOrAbsoluteTemp) {
	// Get the current position if necessary
	if (relativeOrAbsoluteTemp == "relative") {
		if ((browserVersion == 'Netscape6')||(browserVersion == 'IE5')) {
			currentPositionTemp = document.getElementById(layerNameTemp).offsetTop
		}
		if (browserVersion == 'IE4') {
			currentPositionTemp = eval ('document.all.' + layerNameTemp + '.style.pixelTop')
		}
		if (browserVersion == 'Netscape4') {
			currentPositionTemp = eval ('document.' + layerNameTemp + '.top')
		}
	} else {
		currentPositionTemp = 0
	}

	newPositionTemp = newPositionTemp + currentPositionTemp
	// Set the new position
    if ((browserVersion == 'Netscape6')||(browserVersion == 'IE5')) {
		document.getElementById(layerNameTemp).style.top = newPositionTemp
	}
    if (browserVersion == 'IE4') {
		eval ('document.all.' + layerNameTemp + '.style.pixelTop = ' + newPositionTemp)
	}
    if (browserVersion == 'Netscape4') {
		eval ('document.' + layerNameTemp + '.top = ' + newPositionTemp)
	}
} 

function general_getTopPosition(layerNameTemp) {
	// Get the current position
	if ((browserVersion == 'Netscape6')||(browserVersion == 'IE5')) {
		currentPositionTemp = document.getElementById(layerNameTemp).offsetTop
	}
	if (browserVersion == 'IE4') {
		currentPositionTemp = eval ('document.all.' + layerNameTemp + '.style.pixelTop')
	}
	if (browserVersion == 'Netscape4') {
		currentPositionTemp = eval ('document.' + layerNameTemp + '.top')
	}
	return currentPositionTemp
} 

/* Copyright (c) Clean Power Research, 1998-2003.  All rights reserved.*/


