var VID_PLAYER = '<object type="application/x-shockwave-flash"' +
  '  data="flowplayer/FlowPlayer.swf"' +
  '  width="300" height="190" id="FlowPlayer">' +
  '    <param name="allowScriptAccess" value="sameDomain">' +
  '    <param name="movie" value="flowplayer/FlowPlayer.swf">' +
  '    <param name="quality" value="high">' +
  '    <param name="scale" value="noScale">' +
  '    <param name="wmode" value="transparent">' +
  '    <param name="flashvars" value="config={ videoFile: \'TESTIMONIAL_PATH\', autoRewind: true, loop: false, autoPlay: false, showMenu: false, showFullScreenButton: false }">' +
  '</object>';
var CURRENT_VIDEO_ID = 1;

//<![CDATA[
function loadMap( address )
{
  if ( GBrowserIsCompatible() ) {
    var map = new GMap2(document.getElementById("map"));

    if ( true ) {
      var geocoder = new GClientGeocoder();
      function showAddress( address ) {  
        geocoder.getLatLng( address,    
        function( point ) {
          map.setCenter( point, 15 );
          var marker = new GMarker(point);
          map.addOverlay( marker );
        }
      );
      }

      showAddress( address );	
    }
  }
}
//]]>

function prepNextVideo()
{
  var id = CURRENT_VIDEO_ID;

  if ( CURRENT_VIDEO_ID < TOTAL_VODEOS )
    id++;
  else
    id = 1;

  prepVideo( id );
}

function prepPrevVideo()
{
  var id = CURRENT_VIDEO_ID;

  if ( CURRENT_VIDEO_ID == 1 )
    id = TOTAL_VODEOS;
  else
    id--;

  prepVideo( id );
}

function prepVideo( id )
{
  // Make sure thet we're not trying to view the video that's already
  // playing
  if ( CURRENT_VIDEO_ID != id ) {
    var player = VID_PLAYER;

    // Disable to the old "current" video
    var curFillerImage = document.getElementById( "id-" + CURRENT_VIDEO_ID );
    var curImageContainer = document.getElementById( "image-" + CURRENT_VIDEO_ID );
    var curVideoContent = document.getElementById( "content-" + CURRENT_VIDEO_ID );
    curVideoContent.innerHTML = "";
    curImageContainer.style.display = "block";

    // Get the new "to be played" video containers
    var newFillerImage = document.getElementById( "id-" + id );
    var newImageContainer = document.getElementById( "image-" + id  );
    var newVideoContent = document.getElementById( "content-" + id );
    newImageContainer.style.display = "none";

    // alert( newFillerImage.alt );

    newVideoContent.innerHTML = player.replace( 'TESTIMONIAL_PATH', newFillerImage.alt );

    CURRENT_VIDEO_ID = id;
  }
}

function validateForm()
{
  var errors = "";

  var form = document.getElementById( "requestForm" );

  // First Name
  if ( form.firstName.value.replace(/^\s+|\s+$/g, '') == "" )
    errors += "\nFirst Name is required";
  // Last Name
  if ( form.lastName.value.replace(/^\s+|\s+$/g, '') == "" )
    errors += "\nLast Name is required";
  // Phone
  if ( form.homePhone.value.replace(/^\s+|\s+$/g, '') == "" && form.mobilePhone.value.replace(/^\s+|\s+$/g, '') == "" )
    errors += "\nA Phone Number is required";

  if ( errors != "" ) {
    alert( "Please correct the following before submitting your request:" + errors );
  }
  else {
    form.submit();
  }

}