function LoadScript(url) {
	document.write( '<script type="text/javascript" src="' + url + '" onerror="alert(\'Error loading \' + this.src);"><\/script>' ) ;
}

function LoadCss(url) {
	document.write( '<link href="' + url + '" type="text/css" rel="stylesheet" onerror="alert(\'Error loading \' + this.src);" />' ) ;
}

LoadScript('js/JsHttpRequest.js');

function viewform(m, w, h) {
   var scroll = 'yes';
   var settings;
   var LeftPosition;
   var TopPosition;
   var win;

   LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
   TopPosition = (screen.height) ? (screen.height-h)/2 : 0;

   settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll;
   settings = settings + ',resizable=yes,maximize=no,status=no,toolbar=no,directories=no,menubar=no,location=no';

   win = window.open(m, 'pre', settings);
   win.name = 'name';
   win.focus();
}

function onStateChange(state, city_) {
   req = new JsHttpRequest();
   window.city = city_;
   req.onreadystatechange = changeState;
   req.open(null, 'ajax.php', true);
   req.send({act:'cities', ref_state:window.document.getElementById(state).value});
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_ClickImage_() { //v3.0
  var i,j=0,x,a=MM_ClickImage_.arguments;
  document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=5)
   if ((x=MM_findObj(a[i]))!=null){
      document.MM_sr[j++]=x; 
      if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
      MM_findObj('descr').innerHTML = a[4];
   }  
}
function changeState() {
   city = window.city
   if (req.readyState != 4) return null;
   var options = req.responseJS.rows;
   window.document.getElementById(city).options.length=0;
   for (option in options) {
      window.document.getElementById(city).options.length++;
      window.document.getElementById(city).options[window.document.getElementById(city).options.length-1].text=options[option].City;
      window.document.getElementById(city).options[window.document.getElementById(city).options.length-1].value=options[option].City;
   }
}

function i__(id_) {
   return window.document.getElementById(id_);
}

function openWindow(url, name, width, height, features) {
	var win;
	var top = 0;
	var left = 0;
	
	if (screen.width > width) left = (screen.width - width) / 2;
	if (screen.height > height) top = (screen.height - height) / 2;
	
	if (typeof(features) == "undefined") win = window.open(url, '_blank', 'left='+left+',top='+top+',screenX='+left+',screenY='+top+',width='+width+',height='+ height);
	else win = window.open(url, '_blank', 'left='+left+',top='+top+',screenX='+left+',screenY='+top+',width='+width+',height='+ height +', ' + features);
		
	if (navigator.appName != 'Microsoft Internet Explorer')  { if ( window.focus )  win.focus()};
}

function member_photo_edit(photoId) {
   if (photoId>0) {
      window.document.getElementById("property_photo_"+photoId).style.visibility="hidden";
      if (window.document.getElementById("photo_id").value>0) window.document.getElementById("property_photo_"+window.document.getElementById("photo_id").value).style.visibility="visible";
      window.document.getElementById("img_edit").src = window.document.getElementById("photo_"+photoId).src;
      window.document.getElementById("img_edit").style.visibility="visible";
      window.document.getElementById("photo_description").value=window.document.getElementById("description_"+photoId).innerHTML;
      window.document.getElementById("photo_id").value = photoId;
   } else {
   window.document.getElementById("property_photo_edit2").style.visibility="visible";
   window.document.getElementById("property_photo_edit2").style.display="block";
   window.document.getElementById("property_photo_edit3").style.visibility="visible";
   window.document.getElementById("property_photo_edit3").style.display="block";

   }
   window.document.getElementById("property_photo_edit").style.visibility="visible";
   window.document.getElementById("property_photo_edit").style.display="block";
}

function resize() {
var i=0;
var LeftPosition;
var TopPosition;
var w;
var h;
  if (navigator.appName == 'Netscape') i=40;
  if (document.images[0].name != 'close') 
  { 
    w = document.images[0].width+100;
    h = document.images[0].height+130-i;
    window.resizeTo(w, h);
    LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
    window.moveTo(LeftPosition, TopPosition); 
  }else{
    w = 420;
    h = 370;   
    window.resizeTo(w, h);
    LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
    window.moveTo(LeftPosition, TopPosition); 

  }
  self.focus();
}


// JS Calendar
var calendar = null; // remember the calendar object so that we reuse
// it and avoid creating another

// This function gets called when an end-user clicks on some date
function selected(cal, date) {
	cal.sel.value = date; // just update the value of the input field
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks the "Close" (X) button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
	cal.hide();			// hide the calendar

	// don't check mousedown on document anymore (used to be able to hide the
	// calendar when someone clicks outside it, see the showCalendar function).
	Calendar.removeEvent(document, "mousedown", checkCalendar);
}

// This gets called when the user presses a mouse button anywhere in the
// document, if the calendar is shown.  If the click was outside the open
// calendar this function closes it.
function checkCalendar(ev) {
	var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
	for (; el != null; el = el.parentNode)
	// FIXME: allow end-user to click some link without closing the
	// calendar.  Good to see real-time stylesheet change :)
	if (el == calendar.element || el.tagName == "A") break;
	if (el == null) {
		// calls closeHandler which should hide the calendar.
		calendar.callCloseHandler(); Calendar.stopEvent(ev);
	}
}

// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id) {
	var el = document.getElementById(id);
	if (calendar != null) {
		// we already have one created, so just update it.
		calendar.hide();		// hide the existing calendar
		calendar.parseDate(el.value); // set it to a new date
	} else {
		// first-time call, create the calendar
		var cal = new Calendar(true, null, selected, closeHandler);
		calendar = cal;		// remember the calendar in the global
		cal.setRange(1900, 2070);	// min/max year allowed
		calendar.create();		// create a popup calendar
	}
	calendar.sel = el;		// inform it about the input field in use
	calendar.showAtElement(el);	// show the calendar next to the input field

	// catch mousedown on the document
	Calendar.addEvent(document, "mousedown", checkCalendar);
	return false;
}

function validate_listing() {
   if (parseInt(window.document.getElementById('listingForm').get_Price.value) != window.document.getElementById('listingForm').get_Price.value) {
      alert('Please do not use any symbols when entering the price');
      window.document.getElementById('listingForm').get_Price.focus();
      return false;
   } else {
      window.document.getElementById('listingForm').submit();
   }
}
function conf() {
   return confirm('This record will be permanently deleted. Do you want to continue?');
}

function initSearch(){
//			if (getCookie('customsearch') != "1"){
   dsDiv.style.display = "block";
   start = dsDiv.offsetHeight;
   dsDiv.style.top = 0-start;
   scrollSearch(0,1);
}
//		}
var searchtimer;
var start = 0;
function scrollSearch(start,inc){
   if(parseInt(dsDiv.style.top) < start){
      dsDiv.style.top = parseInt(dsDiv.style.top)+inc+'px';
      searchtimer = window.setTimeout ("scrollSearch("+start+","+inc+");", 10);}
   else {
      clearTimeout(searchtimer);}
   }
function searchClose(){
   scrollSearch(start,-1);
}

