String.prototype.strToNum = function ()
{
   var r = '';

   for(var i = 0; i < this.length; i++)
   {
      if( ((this.charCodeAt(i) >= 48) && (this.charCodeAt(i) <= 57)) || (this.charCodeAt(i) == 46))
         r += this.charAt(i);
   }

   return Number(r);
}

Number.prototype.numToDollar = function ()
{
   var o = ''+this;
   var r = '';
   var j = 1;
   var d = o.indexOf('.');
   var l = o.length - 1;

   // Test if there is no decimal
   if(d == -1)
      o += '.00';
   // Test if there are more than 2 decimal digits
   else if(d < (l - 2))
      o = o.substr(0, d+3);
   // Test if there is one decimal digit
   else if(d > (l - 2))
      o += '0';

   // Check length again, it may have changed
   l = o.length - 1;
   for(var i = l; i >= 0; i--)
   {
      d = o.charAt(i);
      r = d + r;
      // Add a comma if the place is exactly divisible by 3, there are more characters left in the number and the current character is not a decimal point
      if(((j / 3) == Math.floor(j / 3)) && (i > 0) && (d != '.'))
         r = ',' + r;
      j++;
   }

   return '$' + r;
}

function toggleVis(id)
{
   var x = document.getElementById(id); 

   if(x.style.display != "block")
   {
      // element is not current visible, so turn display to block
      x.style.display = "block";
   }
   else
   {
      // element is currently visible, so turn display to none
      x.style.display = "none";
   }
}

function isDefined(v)
{
   return (typeof(v) == "undefined") ? false : true;
}

//*******************************************************
//    Window resizing code Begin
//*******************************************************

function getWindowSize()
{
   var e = new Object();
   if(window.self && self.innerWidth)
   {
      e.width = self.innerWidth;
      e.height = self.innerHeight;
   }
   else if(document.documentElement && document.documentElement.clientHeight)
   {
      e.width = document.documentElement.clientWidth;
      e.height = document.documentElement.clientHeight;
   }
   else
   {
      e.width = document.body.clientWidth;
      e.height = document.body.clientHeight;
   }
	
   return e;
}

window.onresize = function()
{
   var NS = getWindowSize();
	// - document.getElementById("listings").offsetHeight
   document.getElementById("map").style.height = (NS.height - document.getElementById("status_div").offsetHeight - document.getElementById("header").offsetHeight) + 'px';
   resizingFlag = true;
   if(resizingInterval == null)
      resizingInterval = setInterval("checkResizeEnd()", 100);
};

function checkResizeEnd()
{
   if(!resizingFlag && isDefined(map))
   {
      map.checkResize();
      clearInterval(resizingInterval);
      resizingInterval = null;
   }

   resizingFlag = false;
}

//*******************************************************
//    Window resizing code End
//*******************************************************

//*******************************************************
//    Asynchronous handling code Begin
//*******************************************************
function show_working(id, message)
{
	var x = document.getElementById(id);
	x.innerHTML = "<h1>"+message+"</h1>";
}

function GetXmlHttpObject(handler)
{ 
	var objXmlHttp=null
		
	if (navigator.userAgent.indexOf("Opera")>=0)
	{
		alert("This example doesn't work in Opera") 
		return 
	}

	if (navigator.userAgent.indexOf("MSIE")>=0)
	{ 
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
			strName="Microsoft.XMLHTTP"
		} 
		try
		{ 
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler 
			return objXmlHttp
		} 	
		catch(e)
		{
		 	alert("Error. Scripting for ActiveX might be disabled");
			return;
		} 
	} 
	
	if (navigator.userAgent.indexOf("Mozilla")>=0)
	{
		objXmlHttp=new XMLHttpRequest();
		objXmlHttp.onload=handler;
		objXmlHttp.onerror=handler; 
		return objXmlHttp;
	}
}

//
//	Generic asynchronous process call displays waiting message and then results in the main div
//
function asProcess(url, args, msg, func)
{
	var rand = parseInt(Math.random()*99999999);  // cache buster

	if(args)
		args = args + "&";
	args = args + "rand=" + rand;

	xmlHttp = GetXmlHttpObject(func);
	show_working("status", msg);
	xmlHttp.open("GET", url+"?"+args, true);
	xmlHttp.send(null);
}

//
// Generic function to handle as process.  Dumps text to id = main
//
function handleASProcess()
{
	if(xmlHttp.readyState == 4)
	{
		var x = document.getElementById("main");
		x.innerHTML = xmlHttp.responseText;
   }
	else
		show_working("main", "Fetching page...");
}
//*******************************************************
//    Asynchronous handling code End
//*******************************************************

