
/*****************************************************************************/
function fill_phone_number_header()
{
  var q = new Request();
  document.getElementById("phone_number_header").innerHTML = q.phone.replace(/\#/,"");
}// end fill_phone_number_header()



/*****************************************************************************/
function validateSearch( form )
{
  var phone = form.phone.value;

  // Trim leading/trailing whitespace:
  phone = phone.replace(/^\s+/, "").replace(/\s+$/,"").replace(/[^\d]/g,"");
  
  // Does it look like a phone number?:
  if( ! /^[\d]{10,10}$/.test( phone ) )
  {
    alert("Invalid phone number");
    form.phone.focus();
    return false;
  }// end if()

  var parts = /^(\d{3,3})(\d{3,3})(\d{4,4})$/.exec( phone );
  parts.shift();
  form.phone.value = parts.join("-");

  window.setTimeout(function() {
    document.location = "/tracing?redir_url=" + escape(form.action + "?phone=" + form.phone.value);
  }, 10);
  return false;

  if( form.outerHTML )
  {
    // IE
    form.submit();
  }
  else
  {
    return true;
  }
}


/*****************************************************************************/
var original_action;
function prepare_page3()
{
  var q = new Request();
  
  try {
  document.getElementById("val_phone_number").innerHTML         = q.phone;
  }catch(e) { };
  try {
  document.getElementById("phone_number_header").innerHTML         = q.phone;
  }catch(e) { };
  try {
  document.getElementById("formatted_phone_premium").innerHTML  = q.phone;
  }catch(e) { };
  try {
  document.getElementById("formatted_phone_one_time").innerHTML = q.phone;
  }catch(e) { };
  try {
  document.getElementById("val_search_date").innerHTML          = (new Date()).toDateString();
  }catch(e) { };
  try {
  document.getElementById("val_search_time").innerHTML          = (new Date()).toLocaleTimeString();
  }catch(e) { };
  try {
  document.getElementById("val_area").innerHTML                 = [ q.City, q.State ].join(", ");
  }catch(e) { };
  try {
  document.getElementById("val_county").innerHTML               = q.County;
  }catch(e) { };
  try {
  document.getElementById("val_line_type").innerHTML            = q.Wireless.toString() == "false" ? "Landline" : "Wireless";
  }catch(e) { };
  try {
  document.getElementById("val_query_id").innerHTML             = q.QueryID;
  }catch(e) { };
  
//  var form = document.getElementById("rpd_form");
 // original_action = form.action;
 // form.onsubmit = function() {
  //  var next_page = this.action;
//    window.setTimeout(function() {
//      document.location = next_page;
//    },10);
//    return false;
//  };
  
  // Initialize the membership level selection:
//  handle_membership_level_changed();
}// end prepare_page3()


/*****************************************************************************/
function handle_membership_level_changed()
{
  var options = document.getElementsByName("membership_level");
  for( var i = 0; i < options.length; i++ )
  {
    if( options[i].checked )
    {
      var level = options[i].id;
      return set_membership_level( level, options[i].form );
    }// end if()
  }// end for()
}// end handle_membership_level_changed()


/*****************************************************************************/
function set_membership_level( level, form )
{
  // First set everything to '0' values:
  var q = new Request();
  
	//alert(level);
  switch( level ) {
    case 'premium_level':
      if( form.make_my_data_private.checked )
      {
        form.action = original_action + "&items[]=2197&items[]=2196"
      }
      else
      {
        form.action = original_action + "&items[]=2197"
      }// end if()
    
      break;

    case 'single_report':
      if( form.make_my_data_private.checked )
      {
        form.action = original_action + "&items[]=2182&items[]=2196"
      }
      else
      {
        form.action = original_action + "&items[]=2182"
      }// end if()
      
      break;
    
    default:
      break;
  };
  
  // Now add on the other non-empty tracking params:
  //var tracking_form = document.forms['tracking_form'];
  //var fields = tracking_form.elements;
  //for( var i = 0; i < fields.length; i++ )
  //{
 //   if( fields[i].value != "" )
  //  {
   //   form.action += "&" + escape(fields[i].name) + "=" + escape(fields[i].value);
    //}// end if()
 // }// end for()
  
}// end set_membership_level( level )


function Request()
{
  var url = document.location.toString().split(/\?/);
  if( url.length < 2 )
    return;

  var parts = url[1].split(/&/);
  var params = new Object();
  for( var i = 0; i < parts.length; i++ )
  {
    var str = parts[i].split(/\=/);
    params[ unescape(str[0]) ] = unescape( str[1] );
  }// end for()

  return params;
}// end Request()



/*****************************************************************************/
function forwardWaitPage()
{
  window.setTimeout(function() {
    var q = new Request();
    document.location.replace( q.redir_url );
  }, 750);
}// end function()



var circleRadius = 10;
var circle;
var centerMarker;
var circleUnits = 'MI';
var zoom = 6;
var centerPoint;
var map;

/**
 * Filled circle overlay
 */
var MapCircleOverlay = function(center, radius, strokeWeight, strokeColor, strokeOpacity, fillColor, fillOpacity) {
	this.center = center;
	this.radius = radius;
	this.strokeWeight = strokeWeight;
	this.strokeColor = strokeColor;
	this.strokeOpacity = strokeOpacity;
	this.fillColor = fillColor;
	this.fillOpacity = fillOpacity;
 
	this.circlePolygon = null;
 
	// 50 lines look like a pretty good circle
	this.numPoints = 50;
 
	this.d2r = Math.PI / 180;
 
	this.bound = null;
 
	this.setCenter = function( latLng ) {
		this.center = latLng;
		this.draw();
	};
 
	this.setRadius = function( radius ) {
		this.radius = radius;
		this.draw();
	};
};
 
/* base class overloads follow this comment */
MapCircleOverlay.prototype = new google.maps.OverlayView;
 
// Calculate all the points and draw them
// Base method must be implemented like this
MapCircleOverlay.prototype.draw = function() {	
	if ( ! isFinite( this.radius ) || ! isFinite( this.center.lat() ) || ! isFinite( this.center.lng() ) ) {
		if ( console != undefined ) 
			console.error('Radius has to be a number !');
		return;
	}
 
	circleLatLngs = new Array();
 
        // Remove the "* 0.621371192" to use miles instead of kilometers
	var circleLat = this.radius * 0.621371192 * 0.014483;  // Convert statute into miles and miles into degrees latitude
	var circleLng = circleLat / Math.cos( this.center.lat() * this.d2r);
 
	// 2PI = 360 degrees, +1 so that the end points meet
	for (var i = 0; i < this.numPoints+1; i++) { 
		var theta = Math.PI * (i / (this.numPoints / 2)); 
		var vertexLat =  this.center.lat() + (circleLat * Math.sin(theta)); 
		var vertexLng =  this.center.lng() + (circleLng * Math.cos(theta));
		var vertextLatLng = new google.maps.LatLng(vertexLat, vertexLng);
		circleLatLngs.push( vertextLatLng );
	}
 
	// Before drawing the new polygon, we have to remove the old one
	this.clear();
 
	this.circlePolygon = new google.maps.Polygon({
	  paths: circleLatLngs,
	  strokeColor: this.strokeColor,
	  strokeOpacity: this.strokeOpacity,
	  strokeWeight: this.strokeWeight,
	  fillColor: this.fillColor,
	  fillOpacity: this.fillOpacity
	});
 
	this.circlePolygon.setMap( this.map );
};
 
MapCircleOverlay.prototype.clear = function() {
	if ( this.circlePolygon != null ) {
		this.circlePolygon.setMap( null );
		this.circlePolygon = null;
	}
};
 
MapCircleOverlay.prototype.onRemove = function() {
	this.clear();
};



