function elt_value( id ) { return document.getElementById( id ).value; }

function height_value() { return elt_value( 'height' ) }

function hide_options() {
	toggle = document.getElementById( 'options_toggle' );
	toggle.innerHTML =
			"<a href=\"#\" onClick=\"show_options()\">Show options</a>";
	options_div = document.getElementById( 'options_div' )
	options_div.style.visibility = 'hidden';
	options_div.style.display = 'none';
}

function iframe_html( place, width, height, map_type ) {
  host = window.location.host;
  src = "http://" + host + "/map/show/" + place + "\?w=" + width +
        "&h=" + height + "&mt=" + map_type;
  html = "<iframe src=\"" + src + "\" width=\"" + width + "\" height=\"" +
         height + "\" frameborder=\"0\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\"></iframe>";
  return html;
}

function map_type_value() {
	map_type_ary = document.getElementById( 'place_form' ).map_type;
	mtv = '';
	for (i = 0; i < map_type_ary.length; i++) {
		if ( map_type_ary[i].checked ) {
			mtv = map_type_ary[i].value;
		}
	}
	return mtv;
}

function place_value() { return elt_value( 'place' ); }

function preview_google_map() {
  url = "/mini_search/preview?place=" + place_value() + "&w=" + width_value() +
	      "&h=" + height_value() + "&mt=" + map_type_value();
  window.open( url, 'preview_window' );
}

function show_options() {
	toggle = document.getElementById( 'options_toggle' );
	toggle.innerHTML =
			"<a href=\"#\" onClick=\"hide_options()\">Hide options</a>";
	options_div = document.getElementById( 'options_div' )
	options_div.style.visibility = 'visible';
	options_div.style.display = 'block';
	options_div.style.backgroundColor = '#eee';
}

function update_iframe_html() {
  textarea = document.getElementById( 'iframe_html' );
  textarea.value = iframe_html(
		place_value(), width_value(), height_value(), map_type_value()
	);
}

function width_value() { return elt_value( 'width' ) }

