function validEmail(address)
{
	var regex = /^\S+@\S+\.\w{2,}$/;
	return String(address).search(regex) != -1;
}

/**
 * Freeze a (generally) submit button to prevent multiple submissions
 * @param boolean state dictates whether the button is to become disabled
 * @param string button id of button
 * @param string newCaption (optional) new caption for button (i.e. "Working")
 */
function freezeButton(state, button)
{
	var newCaption = (null !== arguments[2])?arguments[2]:null;
	var button = $(button);
	new PeriodicalExecuter(function(pe)
	{
		button.disabled = state;
		if(null !== newCaption) button.update(newCaption);
		pe.stop();
	}, .2);
}

/**
 * Negated $F() Utility Function
 * @see $F() in prototype.js
 */
function $f(e){ return !$F(e); }

function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects
		for(var item in arr) {
			var value = arr[item];
	 
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}


// Display Box with Message (Relative to elSubject)
function displayBox(elSubject,elBox) {
	// elSubject is element containing msg (attribute msg)
	// elBox is element of "box" that displays message
   //$('dispmsgbox').innerHTML = '<p>'+el.readAttribute('msg')+'</p>';
   elBox.innerHTML = '<p>'+elSubject.readAttribute('msg')+'</p>';
   
   var tmp = elSubject; 
   mLeft = mTop = 0;
    
   while(tmp.offsetParent)
   {   
      mLeft += tmp.offsetLeft;
      mTop += tmp.offsetTop;
      tmp = tmp.offsetParent;
   }   
   
   //msgboxDim = $('dispmsgbox').getDimensions();
   msgboxDim = elSubject.getDimensions();
   
   //$('dispmsgbox').style.top = (mTop+10)+'px';
   //$('dispmsgbox').style.left = (mLeft-msgboxDim.width-10)+'px';
   elBox.style.top = (mTop+20)+'px';
   elBox.style.left = (mLeft-msgboxDim.width-10)+'px';
	WCH.Apply(elBox);
}

function hideBox(elBox) {
	WCH.Discard(elBox);
	elBox.style.left='-1000px';
}
// Open Map Window Function
function showMapPopUpWindow(rID)  {
	url = "http://www.rentals-mls.com/maps/getmap/rid/"+rID;
	winname = "mapswindow";

	width = 500;
	height = 300;
	
	wopen(url, winname, width, height);
	//MapWindow = window.open("http://www.rentals-mls.com/maps/getmap/rid/"+rID,"mapswindow","width=630,height=430,menubar=yes,resizable=yes,scrollbars=no,toolbar=no,location=no,directories=0,status=0");
	//MapWindow.moveTo(500,300);
}

function wopen(url, name, w, h)
{
  // Fudge factors for window decoration space.
  w += 32;
  h += 96;
  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  // IE5 and other old browsers might allow a window that is
  // partially offscreen or wider than the screen. Fix that.
  if (wleft < 0) {
    w = screen.width;
    wleft = 0;
  }
  if (wtop < 0) {
    h = screen.height;
    wtop = 0;
  }
  var win = window.open(url,
    name,
    'width=' + w + ', height=' + h + ', ' +
    'left=' + wleft + ', top=' + wtop + ', ' +
    'location=no, menubar=no, ' +
    'status=yes, toolbar=no, scrollbars=yes, resizable=no');
  // Just in case width and height are ignored
  win.resizeTo(w, h);
  // Just in case left and top are ignored
  win.moveTo(wleft, wtop);
  win.focus();
}
