function goBack(video)
{
	document.getElementById('vidcontent').innerHTML = '';
	history.go(-1);
}

//<![CDATA[

/***** START MAP SECTION ******/
function displayMap(lt,lng,destAddr,firstdivtitle,firstdivcontent)
{
  	if (GBrowserIsCompatible()) 
  	{
	    var map = new GMap2(document.getElementById("map"));
	    map.setCenter(new GLatLng(lt,lng),13);
	    map.addControl(new GSmallMapControl());
	    map.addControl(new GMapTypeControl());
	    map.addControl(new GOverviewMapControl());
	    
	    // Our info window content
		var infoTabs = 
		[
			new GInfoWindowTab(firstdivtitle,firstdivcontent), 
			new GInfoWindowTab('Directions', '<form action=\'#\' onsubmit=\'setDirections(this.from.value,"'+destAddr+'");return false;\'><table><tr><td align=\'center\'>From:</td></tr><tr><td><input type=\'text\' size=\'50\' id=\'fromAddress\' name=\'from\' value=\'\'/><br><small><I>StreetAddress&nbsp;&nbsp;&nbsp;Zip</I></small></td></tr><tr><td align=\'center\'><input name=\'submit\' type=\'submit\' value=\'Get Directions!\' /></td></tr></table></form>')
		];
	
		// Place a custom marker in the center of the map
		var icon = new GIcon();
		icon.image =  "http://images.harmonhomes.com/img/11/design/clean-hh_II/pages/listing-detail/map/map_marker_image.gif";
		icon.shadow = "http://images.harmonhomes.com/img/11/design/clean-hh_II/pages/listing-detail/map/map_marker_shadow.gif";
		icon.iconAnchor = new GPoint(7,50);
		icon.infoWindowAnchor = new GPoint(30,7)
		icon.iconSize = new GSize(35,50);
		icon.shadowSize = new GSize(45,50);
		var marker = new GMarker(map.getCenter(), icon);
		GEvent.addListener(marker, "click", 
			function() {marker.openInfoWindowTabsHtml(infoTabs,{maxWidth:300,maxheight:200});});
		map.addOverlay(marker);
		marker.openInfoWindowTabsHtml(infoTabs);
	}
}

function setDirections(fromAddr,destAddr)
{
// A BackButtonControl is a GControl that displays textual "Back to Map" button
	function BackButtonControl()
	{
	}
	BackButtonControl.prototype = new GControl();
	
	// Creates a  DIV for the button and place it in a container
	// DIV which is returned as our control element. We add the control to
	// to the map container and return the element for the map class to
	// position properly.
	BackButtonControl.prototype.initialize = function(map)
	{
	  var container = document.createElement("div");
	
	  var backButton = document.createElement("div");
	  this.setButtonStyle_(backButton);
	  container.appendChild(backButton);
	  backButton.appendChild(document.createTextNode("Back to Map"));
	  GEvent.addDomListener(backButton, "click", function() {
	   mapGoBack();
	  });
	
	  map.getContainer().appendChild(container);
	  return container;
	}
	
	// By default, the control will appear in the top left corner of the
	// map with 7 pixels of padding.
	BackButtonControl.prototype.getDefaultPosition = function()
	{
	  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
	}
	
	// Sets the proper CSS for the given button element.
	BackButtonControl.prototype.setButtonStyle_ = function(button)
	{
	  button.style.textDecoration = "underline";
	  button.style.color = "#000000";
	  button.style.backgroundColor = "white";
	  button.style.font = "small Arial";
	  button.style.border = "1px solid black";
	  button.style.padding = "3px";
	  button.style.marginBottom = "3px";
	  button.style.textAlign = "center";
	  button.style.width = "6em";
	  button.style.cursor = "pointer";
	}

	toggle('map','map2');
	var map2 = new GMap2(document.getElementById("map2"));
	map2.addControl(new BackButtonControl());
    var directionsPanel = document.getElementById("dirs");
    if (directionsPanel.style.display == 'none')
    {
    	toggle('dirs');
    }
    var directions = new GDirections(map2, directionsPanel);
    directions.load("from: " + fromAddr + " to: " + destAddr);
    GEvent.addListener(directions, "error", function() 
	{
		if(directionsPanel.style.display == 'none')
		{
			toggle('dirs');
		}
	 	directionsPanel.innerHTML = "<br/><br/><strong>I'm sorry, but we were unable to locate the address you entered.<br/><br/>Please click the 'Back to Map' button on the left and try again.</strong><br/><br/>You may enter your address in many formats, including:<br/><br/><I>123 Elm St. 23456<br/>123 Elm Street, Norfolk, VA 23518<br/>Norfolk, VA</I>";
	});
	GEvent.addListener(directions, "addoverlay", function() 
	{
		if(document.getElementById('dirstop').style.display == 'none')
		{
			toggle('dirstop');
		}
	});
}
   
function mapGoBack()
{
	document.getElementById('dirs').innerHTML = '';
	document.getElementById('map2').innerHTML = '';
	toggle('map2','map','dirs');
	document.getElementById('dirstop').style.display = 'none';
}

function toggle()
{
	for(var i=0;i<toggle.arguments.length;i++)
	{
		if (toggle.arguments[i] == '')
		{
			continue;
		}
		elm = document.getElementById(toggle.arguments[i]);
		if (elm.style.display == "none")
		{
			elm.style.display = "";
		}
		else
		{
			elm.style.display = 'none';
		}
	}
}
    //]]>
/***** END MAP SECTION ******/
    

    
/***** START CALCULATOR SECTION ******/ 
function calcCleanup(obj)
{
	var toreturn = obj.value.replace(/[^0-9.]/,'');
	obj.value = toreturn;
	
}

function calculate(amt,apr,yrs)
{
	if (document.getElementById('calcgraph_load').style.display == 'block' || document.getElementById('calcresult_load').style.display == 'block' || document.getElementById('results').style.display == 'none')
	{
		return;
	}
	var url="/ajax_stub.php?calculator=1&amt="+amt+"&apr="+apr+"&yrs="+yrs;
	httpRequest("GET",url,true,handleResponse_calculate);
	toggle('calcgraph_load','calcresult','results');
}

function handleResponse_calculate()
{
	if (request.readyState == 4)
	{
		if(request.status == 200)
		{
			var json = eval('(' + request.responseText + ')');
//			document.getElementById('ammortization').innerHTML = json.ammortization
			document.getElementById('results').innerHTML = json.graph;		// Commented out to temporarily remove graph
			document.getElementById('monthpay').innerHTML = json.paymentF;
			document.getElementById('total').innerHTML = json.totalF;
			document.getElementById('interest').innerHTML = json.interestF;
			ShowHide('results');
			ShowHide('calcresult');
			ShowHide('calcgraph_load');
		}
	}
}

function ShowHide(identifier)
{
	var elm = document.getElementById(identifier);
	if (elm.style.display == "none")
	{
		elm.style.display = "block";
	}
	else
	{
		elm.style.display = 'none';
	}
}

var flashvidstuff = ''; // Global variable to hold flashcontent innerHTML for hide/show

function show_hide(show)
{
	// tabs
	document.getElementById('tab_'+current_tab+'_active').style.display = "none";
	document.getElementById('tab_'+current_tab+'_inactive').style.display = "inline";
	
	document.getElementById('tab_'+show+'_active').style.display = "inline";
	document.getElementById('tab_'+show+'_inactive').style.display = "none";
	
	// content
	document.getElementById('content_'+current_tab).style.display = "none";
	document.getElementById('content_'+show).style.display = "block";
	
	switch (show)
	{
		case 'mapview':
			displayMap(lati,longi,destAddr,firstdivtitle,firstdivcontent);
			break;
		case 'detail-calc':
			if(document.getElementById('calcgraph_load').style.display != 'none') 
				toggle('calcgraph_load');
			break;
		case 'school-info':
			showSchoolInfo();
			break;	
		case 'area-profile':
			showAreaProfile();
			break;
		case 'video':
			document.getElementById('vidcontent').innerHTML = flashvidstuff;
			break;
	}
	
	switch (current_tab)
	{
		case 'video':
			// do this to kill the sound from playing
			var vid = document.getElementById('vidcontent');
			flashvidstuff = vid.innerHTML;
			vid.innerHTML = '';
			break
	}
	current_tab = show;	
	
}

function rollover_on ( imgId )
{
  if ( document.images )
  {
  	if (imgId == 'imggraph')
  	{ 
  		document.getElementById(imgId).src = "http://images.harmonhomes.com/img/11/design/clean-hh_II/pages/listing-detail/calculator/GraphTab_Red.gif"
  	}
  	else
  	{
  		document.getElementById(imgId).src = "http://images.harmonhomes.com/img/11/design/clean-hh_II/pages/listing-detail/calculator/DetailsTab_Red.gif"
  	}
  }
}

function rollover_off ( imgId )
{
  if ( document.images )
  {
    if (imgId == 'imggraph')
  	{ 
  		document.getElementById(imgId).src = "http://images.harmonhomes.com/img/11/design/clean-hh_II/pages/listing-detail/calculator/GraphTab_Inactive.gif"
  	}
  	else
  	{
  		document.getElementById(imgId).src = "http://images.harmonhomes.com/img/11/design/clean-hh_II/pages/listing-detail/calculator/Details_Inactive.gif"
  	}
  }
}

function recalcbuttonOn()
{
	calculate(amt.value,apr.value,yrs.value);
}
/***** END CALCULATOR SECTION ******/
