﻿
function GoogleAnalytics(Tag)
{
	// wait until for the page to load and all the other initialization to occur before 
	// wasting resources on Google.
	setTimeout("GoogleAnalyticsDoIt('" + Tag + "')",5000);
}

function GoogleAnalyticsDoIt(Tag)
{
	try {
	var pageTracker = _gat._getTracker("UA-6536077-1");
	pageTracker._initData();
	var PageName = document.location.href.replace(document.domain,"");
	PageName = PageName.replace("http://","")
	if (Tag) PageName += "/" + Tag
	pageTracker._trackPageview(PageName);
	} catch(e){}

}

function FixNoCookieLinks()
{
	for (var i=0; i<document.links.length; i++)
	{
		var oLink = document.links[i]
		oLink.href = CreateNoCookieURL(oLink.href);
	}
}

function CreateNoCookieURL(URL)
{
	if (document.cookie.indexOf("VisitorID")>-1) return URL; // Have cookies, no need to pass visitorid
	URL += (-1==URL.indexOf("?")) ? "?" : "&";
	var ohEncrypted = document.getElementById("hEncryptedVisitorID");
	if (!ohEncrypted) alert("Missing LitePage: " + document.location.href);
	URL += "vidx=" + ohEncrypted.value;
	URL += "&t=" + document.getElementById("hTS").value; // ExpireDate
	return URL;
}

function GetScreenHeight()
{
  if (window.innerHeight) return parseInt(window.innerHeight,10); // Netscape
  if (document.documentElement && document.documentElement.clientHeight) return parseInt(document.documentElement.clientHeight,10);
  if (document.body) return parseInt(document.body.clientHeight,10);
  return 500;
}

function toProperCase(str) {
    return str.replace(/\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
}

function GoToHomePage(Site){
	
	var url= "HomePage" + Site + ".aspx"; 
	if (Site=="") url = "index.aspx"
	if (Site=="Demo") url = "HomePage.aspx"; 
	document.location.href=FullURL(url);
}

function GetScreenWidth()
{
  if (window.innerWidth) return parseInt(window.innerWidth,10); // Netscape
  if (document.documentElement && document.documentElement.clientWidth) return parseInt(document.documentElement.clientWidth,10);
  if (document.body) return parseInt(document.body.clientWidth,10)-5;
  return 500;
}

//  Display any errors that occur
function FailedCallback(error) {
    //stop here and get error before it proceeds and loses orig message
    
    var message = error.get_message() + '\n' + document.location.href;
    
    
    //prompt("Failed Callback",message);
    //if ((document.domain.toLowerCase().indexOf("localhost")>-1) ||
	//			(document.domain.toLowerCase().indexOf("edmyersxp")>-1) )
    //{   
	//		throw(message);
	//	} else {
		    alert('Failed Callback: unhandled exception:\n' + message);
	//	}	
		
}		

function ShapeInfo(Data){
	var Info =(Data+",,,").split(",");
	this.PropNum = parseInt(Info[0],10);
	this.Source = Info[1];
	this.SysID = parseInt(Info[2]);
	// if PropNum is empty then the data values are Lat Lon 
	this.Lat = parseFloat(Info[1]);
	this.Lon = parseFloat(Info[2]);
	// If PropNum is -1 then the data is Address and Zipcode
	this.Address = Info[3];
	this.Zipcode = Info[4];
	
}

function PropInfo(PropData,Num){
	var Prop = (PropData[Num]+"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n").split("\n");
	this.Lat = parseFloat(Prop[0]);
	this.Lon = parseFloat(Prop[1]);
	this.Source = Prop[2];	
	this.SysID = Prop[3]; 
	this.PhotoURL = GetPhotoPath(Prop[4]);
	this.Address = Prop[5];
	this.LP = Prop[6];
	this.MLNum = Prop[7];
	this.Beds = Prop[8];
	this.Bath = Prop[9];
	this.SqFt = Prop[10];
	this.Lot = "&nbsp;" + Prop[11];
	this.YrBuilt = Prop[12];
	this.PriceK = Prop[13];	
	this.BathsFull = Prop[14];	
	this.BathsPartial = Prop[15];	
	this.GarageSpaces = Prop[16];	
	this.HOAFeeMo = Prop[17];	
	this.TaxesMo = Prop[18];	
	this.AssessedValue = Prop[19];	
	this.CDOM = Prop[20];	
	this.PropTypeDesc = Prop[21];
	this.Pool = Prop[22];
	this.City = Prop[23];
	this.Zipcode = Prop[24];
	this.County = Prop[25];
	this.Neighborhood = Prop[26];
	this.ElemSchool = Prop[27];
	this.MiddleSchool = Prop[28];
	this.HighSchool = Prop[29];
	this.Feature1 = Prop[30]
	this.Search1 = Prop[31]
	this.Search2 = Prop[32]
	this.Search3 = Prop[33]
	this.Search4 = Prop[34]
	this.Search5 = Prop[35]
	this.Search6 = Prop[36]
	this.BrokerName = Prop[37]
	this.FavID = parseInt(Prop[38],10);
	this.OpenHouse = Prop[39];
	this.SoldDate = Prop[40];
	this.PriceSF = Prop[41];
	this.isValid= (!isNaN(this.Lat)) && (!isNaN(this.Lon)) // bad lat/long values (probably empty)
	this.Desc = this.Address + "(" + this.PriceK + ")"

	this.isAggregate = "AGGREGATE"==this.Source;
	this.Area = Prop[5];
	this.Qty = (Prop[3]>999)? (parseInt(Prop[3]/1000)+"K") : Prop[3];	

	this.Baths = "";
	var fBaths = parseInt(this.BathsFull,10)
	var hBaths = parseInt(this.BathsPartial,10)
	if (isNaN(fBaths)&& isNaN(hBaths)) this.Baths="";
	else if (isNaN(fBaths)) this.Baths=this.BathsPartial; 
		else if (isNaN(hBaths)) this.Baths = this.BathsFull;
		else this.Baths = (hBaths + fBaths) + "";

}

function PropInfoShort2(Num){
	var Prop = (PropListData[Num]+"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n").split("\n");
	this.Lat = parseFloat(Prop[0]);
	this.Lon = parseFloat(Prop[1]);
	this.Source = Prop[2];
	this.SysID = Prop[3];
	this.PhotoURL = GetPhotoPath(Prop[4]);
	this.Address = Prop[5];
	this.LP = Prop[6];
	//this.MLNum = Prop[7];
	this.Beds = Prop[8];
	this.Bath = Prop[9];
	this.SqFt = Prop[10];
	this.Lot =  Prop[11];
	this.YrBuilt = Prop[12];
	this.isValid= (!isNaN(this.Lat)) && (!isNaN(this.Lon)) // bad lat/long values (probably empty)
} 

function PropInfoShort(Data,Num){
	var Prop = (Data[Num]+"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n").split("\n");
	this.Lat = parseFloat(Prop[0]);
	this.Lon = parseFloat(Prop[1]);
	this.Source = Prop[2];
	this.SysID = Prop[3];
	this.PhotoURL = GetPhotoPath(Prop[4]);
	this.Address = Prop[5];
	this.LP = Prop[6];
	//this.MLNum = Prop[7];
	this.Beds = Prop[8];
	this.Bath = Prop[9];
	this.SqFt = Prop[10];
	this.Lot =  Prop[11];
	this.YrBuilt = Prop[12];
	this.PriceK = Prop[13];	


	//this.BathsFull = Prop[14];	
	//this.BathsPartial = Prop[15];	
	//this.GarageSpaces = Prop[16];	
	//this.HOAFeeMo = Prop[17];	
	//this.TaxesMo = Prop[18];	
	//this.AssessedValue = Prop[19];	
	//this.CDOM = Prop[20];	
	this.PropTypeDesc = Prop[21];
	//this.Pool = Prop[22];
	//this.City = Prop[23];
	//this.Zipcode = Prop[24];
	//this.County = Prop[25];
	//this.Neighborhood = Prop[26];
	//this.ElemSchool = Prop[27];
	//this.MiddleSchool = Prop[28];
	//this.HighSchool = Prop[29];
	//this.Feature1 = Prop[30]
	//this.Search1 = Prop[31]
	//this.Search2 = Prop[32]
	//this.Search3 = Prop[33]
	//this.Search4 = Prop[34]
	//this.Search5 = Prop[35]
	//this.Search6 = Prop[36]
	//this.BrokerName = Prop[37]
	//this.FavID = parseInt(Prop[38],10);
	this.OpenHouse = Prop[39];
	this.SoldDate = Prop[40];
	//this.PriceSF = Prop[41];
	this.isValid= (!isNaN(this.Lat)) && (!isNaN(this.Lon)) // bad lat/long values (probably empty)
	this.Desc = this.Address + "(" + this.LP + ")"
	
	this.isAggregate = "AGGREGATE"==this.Source;
	this.Area = Prop[5];
	this.Qty = (Prop[3]>999)? (parseInt(Prop[3]/1000)+"K") : Prop[3];	
	
} 	
function PropInfoValueYourHome(Num){
	var Prop = (PropMapData[Num]+"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n").split("\n");
	this.Lat = parseFloat(Prop[0]);
	this.Lon = parseFloat(Prop[1]);
	this.Source = Prop[2];
	this.SysID = Prop[3];
	this.PropType = Prop[4];
	this.PropStatus = Prop[5];
	this.ClosedDate = Prop[6];
	this.PhotoURL = GetPhotoPath(Prop[7]);
	this.Address = Prop[8];
	this.Price = Prop[9];
	this.MLNum = Prop[10];
	this.Beds = MakeInt(Prop[11]);
	this.BathsFull = MakeInt(Prop[12]);
	this.BathsPartial = MakeInt(Prop[13]);
	this.SqFt = MakeInt(Prop[14]);
	this.YrBuilt = Prop[15];
	this.DOM = MakeInt(Prop[16]);
	this.PriceK = Prop[17];	
	this.LP = MakeInt(Prop[18]);	

	this.isValid= (!isNaN(this.Lat)) && (!isNaN(this.Lon)) // bad lat/long values (probably empty)
	this.Desc = this.Address + " (" + this.PriceK + ")"

	this.isAggregate = "AGGREGATE"==this.Source;
	this.Area = Prop[8];
	this.Qty = (Prop[3]>999)? (parseInt(Prop[3]/1000)+"K") : Prop[3];	
}

function MemberInfo(DataMap,Num){
	var Data = (DataMap[Num]+"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n").split("\n");
	this.Lat = parseFloat(Data[0]);
	this.Lon = parseFloat(Data[1]);
	this.Source = Data[2];
	this.SysOfficeID = Data[3];
	this.SysUserID = Data[4];
	//this.OfficeCode = Data[5];
	this.AgentFirstName = Data[6];
	this.AgentLastName = Data[7];
	this.AgentName = Data[8];
	this.OfficeName = Data[9];
	this.Address1 = Data[10];
	//this.Address2 = Data[11];
	//this.Address3 = Data[12];
	//this.City = Data[13];
	//this.State = Data[14];
	this.Zipcode = Data[15];
	this.Phone = Data[16];
	//this.FaxPhone = Data[17];	
	this.URL = Data[18];	
	this.EmailAddress = Data[19];	
	this.Photo = "";
	if (0<Data[20].length) this.Photo = "http://"+Data[20]; 
	
	this.isValid = (!isNaN(this.Lat)) && (!isNaN(this.Lon)); // bad lat/long values (probably empty)
} 	



function ToggleDisplay(CtrlID){
	var oCtrl = $get(CtrlID)
	if (oCtrl) oCtrl.style.display = (oCtrl.style.display=="block") ? "none" :  "block"
}


function GetPhotoPath(URL){
	if (0<URL.length) return URL;
	return FullURL("/../Icons/NoPhoto_147.jpg").replace("http://","");
	//var Path = location.pathname
	//Path = Path.substring(0,Path.lastIndexOf("/"))
	//return location.host + Path + "/../Icons/NoPhoto_147.jpg" 
}

function Expand(evt,id){
	// Browser independent
	var oTbl = $get(id+"Detail");
	var oImg = $get(id+"Image");
	var myEvent = null;
	var oTR = $get(id);
	
	if (window.event) {
		myEvent = window.event; 
	} else {
		myEvent = evt; 
	} 
		
	switch (myEvent.type){
		case "mouseover": oTR.style.color = "Navy";	oTR.style.fontWeight="bold"; break;
		case "mouseout": oTR.style.color = "black";		oTR.style.fontWeight="normal"; break;
		case "click": var Open = oImg.src.indexOf("_Up")>0;
				if (Open){ // close
					oImg.src = oImg.src.replace("_Up","_Dn"); 
					oTbl.style.display = "none";
				
				} else { // open
					oImg.src = oImg.src.replace("_Dn","_Up"); 
					oTbl.style.display = "block";
				}
				break;
				
		default: alert("Missing EventType Arg to Expand: " + myEvent.type);
	}
}


function Tab(evt){
	// Browser independent
	var oImg = null;
	var myEvent = null;
	
	if (window.event) {
		myEvent = window.event; 
		oImg = myEvent.srcElement;
	} else {
		myEvent = evt; 
		oImg = evt.target; 
	} 

	if (!oImg) return;
	if(!oImg.src) return;
	var src = oImg.src;
	switch (myEvent.type){
		case "mouseover": src = src.replace("-default","-over"); break;
		case "mouseout": src = src.replace("-over","-default"); src=src.replace("-down","-default"); break;
		case "mousedown": src = src.replace("-default","-down"); src=src.replace("-over","-down");break;
		default: alert("Missing EventType Arg to Tab: " + myEvent.type);
	}
	oImg.src=src;
}


// for Netscape 6/Mozilla by Thor Larholm me@jscript.dk
if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement)
{
	HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
	{
		switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this)
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling) this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else this.parentNode.appendChild(parsedNode);
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
	{
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}


	HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
	{
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}
	
}

if (!document.all) {
  HTMLElement.prototype.__defineGetter__("innerText", 
              function () { return(this.textContent); });
  HTMLElement.prototype.__defineSetter__("innerText", 
              function (txt) { this.textContent = txt; });
}



function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}


function MakeInt(Val){
	Val = (Val+"").replace("$","").replace(/,/g,"");
	var iVal = parseInt(Val,10)
	if(isNaN(iVal)) return 0;
	return iVal; // already a number
}

function MakeFloat(Val){
	var fVal = parseFloat(Val);
	if (isNaN(fVal)) return 0.0;
	return fVal;
}

function CommaFmt(Num) {
   // Add commas to large numbers
   var Result,IX,Trailer
   Result = "";
   Num=Num.toString()
   IX=Num.indexOf('.',0);
   if (IX<0) {
	  IX=Num.length
	 } else {
		Num=Num+"00"	
	 }	
   if ((Num.length-IX)>3) Num=Num.substring(0,IX+3) // only 2 decimal places past .
   if (IX<=4) return Num; // too short for commas
   Result=Num.substring(IX,Num.length)
   Num=Num.substring(0,IX)
   while (Num.length > 3) {
      Result = "," + Num.substring(Num.length-3,Num.length)+ Result;
      Num = Num.substring(0,Num.length-3)
   }
   Result = Num + Result;
   return Result;
}

function Watermark(evt){
	// Browser independent
	var oCtrl = null;
	var myEvent = null;
	
	if (window.event) {
		myEvent = window.event; 
		oCtrl = myEvent.srcElement;
	} else {
		myEvent = evt; 
		oCtrl = evt.target; 
	} 

	switch (myEvent.type){
		case "blur":
			var Val = oCtrl.value.replace(/ /gi,"");
			if (Val.length==0) {
				oCtrl.value=oCtrl.title;
				oCtrl.style.color="gray";
			} 
			break;
			
		case "focus": 
			if ((!oCtrl.title) || (oCtrl.title==oCtrl.value)) {
				oCtrl.title=oCtrl.value; // Save the watermark
				oCtrl.value="";
				oCtrl.style.color = "black";
			}
			break;
		
		default: alert("No Watermark Handler: " + myEvent.type);
		myEvent.cancelBubble = true;
		break;
	}
	

}

function Glue(a, Data, b){
	if (!Data) return "";
	if (0==Data.length) return ""
	return a + Data + b;
}

function GlueNum(a, Data, b){
	if (!Data) return "";
	if (isNaN(Data)) return ""
	if (0==Data) return ""
	if (99999999==Data) return "";
	return a + Data + b;

}

// For sorting arrays in numeric order e.g. Arrray.sort[numOrdA]
function numOrdA(a, b){ return (a-b); }


function SetCriteria(Field,Value){
	// make the correct radio button checked
	var oCtrl = document.forms[0][Field]
	var oCtrlY = document.forms[0][Field+"Y"]
	if (oCtrlY) oCtrl = document.forms[0][Field+"N"]
	if (!oCtrl) return;
	
	switch (""+oCtrl.type){
	case "select-one": 
		for(var i=0;i<oCtrl.length;i++){
			if (oCtrl[i].value!=Value) continue;
				oCtrl.selectedIndex = i;
				return;
			}
			// If not found maybe because this is a dynamic dropdown
			oCtrl.selectedIndex = 1;
			oCtrl[1].value=Value;
			oCtrl[1].text=Value;
			break;

	case "select-multiple":
		Values=Value.split(",");
		var isNoneSelected = true;
		for(var i=0;i<oCtrl.length;i++){
			var isFound = false;
			for(var j=0;j<Values.length;j++){
				if ((oCtrl[i].value.length>0)&&(oCtrl[i].value==Values[j])) 
				{
					isFound=true;				
					isNoneSelected=false;
				}
			}
			oCtrl[i].selected = isFound;
		}
		if (oCtrl[0].value.length==0) oCtrl[0].selected = isNoneSelected; // Select "All Areas" if nothing is selected
		break;
		
	
	case "radio":
			for (var i=0;  i<oCtrl.length; i++){
				if (oCtrl[i].value==Value) {
					oCtrl[i].checked=true;	
					CriteriaChange(oCtrl[i]);			
				}
			}

	case "checkbox": 
		if (oCtrl) oCtrl.checked = oCtrl.value==Value;
		if (oCtrlY) oCtrlY.checked=oCtrlY.value==Value;
		break;	
	
	case "text": 
		if ((Value=="") || (Value=="0") || (Value=="99999999"))
		{
		 oCtrl.value = oCtrl.title;
		 oCtrl.style.color = "gray";
		}
		else 
		{
			oCtrl.value = Value;
			oCtrl.style.color = "black";
		}
		break;
		
	case "undefined": break;
	
	default: alert("Missing SetCriteria Handler for Field=" + Field + "; " + oCtrl.type); break;
	}
	
}

function TRIM(Str)
{
	if (null==Str) return "";
	return Str.replace(/^\s+|\s+$/g, '');
}


function GetAttr(Obj, Field, DefVal){
	if (!Obj) return DefVal;
	if (!Obj.getAttribute) return DefVal;
	var Val = Obj.getAttribute(Field);
	if (!isFinite(DefVal)) return parseInt(Val,10);
	Val = parseInt(Val,10);
	if (isNaN(Val)) return DefVal;
	return Val;
}

function GetAttrStr(Obj, Field, DefVal){
	if (!Obj) return DefVal;
	if (!Obj.getAttribute) return DefVal;
	var Val = Obj.getAttribute(Field);
	if (!Val) return DefVal;
	if (0<Val.length) return Val;
	return DefVal;
}

function RememberChanges(oFld,FldName)
{
	MyAjaxService.RememberSetting(FldName,oFld.value,$get("hEncryptedVisitorID").value)		
}

function FullURL(URL){
// Expand relative URL to a full URL
	if (document.location.href.toLowerCase().indexOf("proto")>0) URL = "Proto/" + URL;
		if (URL.indexOf("vidx")>0){
			URL = "http://" + document.domain + "/" + URL;
		} else {
			URL = CreateNoCookieURL("http://" + document.domain + "/" + URL);
		}
	return (URL);
}

function WatchForCR(evt){
	// onKeydown event handler to make CR=keypress
	var event = (window.event)? window.event : evt;
	var oCtrl = (window.event)? window.event.srcElement : evt.target;
	var isShift = event.shiftKey;
	var kCode = event.which || event.keyCode;
	if (kCode!=13) return true;
	
	var code=oCtrl.getAttribute("onenter");
	eval(code);
	return true;  //  CR
}

var LastKeycode = "";
function Lookup(evt){
	// Browser independent
	var event = (window.event)? window.event : evt;
	var oCtrl = (window.event)? window.event.srcElement : evt.target;
	var isShift = event.shiftKey;
	var kCode = event.which || event.keyCode;
	
	//var text = oCtrl.options[oCtrl.selectedIndex].text + String.fromCharCode(kCode);
	var WatermarkText = oCtrl.title;
	var Entry = oCtrl.options[0].text.replace(WatermarkText,""); 
	
	if(kCode==27) alert(LastKeycode);
	LastKeycode = kCode;

	switch (kCode)
	{
	case 8: Entry = Entry.substring(0,Math.max(0,Entry.length-1)); break; // BS
	
	case 13: var code=oCtrl.getAttribute("onenter");
		eval(code);
		return true;  //  CR

	
	case 9:  // Tab
	case 16: 
	case 33: // PgUp
	case 34: // PgDn
	case 35: //End
	case 36: // Home
	case 37: // Left 
	case 38: 
	case 39:  // Right
	case 40: 
	case 45: // Insert
	case 46: // Delete
	
	case 106: // Big *
	case 107: // Big +
	case 109: // Big -
	case 110: // Del - .
	case 111: // Big /
	case 112: // F1
	case 113: // F2
	case 114: // F3
	case 115: // F4
	case 116: // F5
	case 117: // F6
	case 118: // F7
	case 119: // F8
	case 120: // F9
	case 121: // F10
	case 122: // F11
	case 123: // F12	
	case 144: // NumLock
		return true; // Key is ignored
	
	
	case 96: kCode=48; break; // Insert - 0
	case 97: kCode=49; break; // End - 1
	case 98: kCode=50; break; // Dn - 2
	case 99: kCode=51; break; //PgDn - 3
	case 100: kCode=52; break; // Left - 4
	case 101: kCode=53; break; // Center - 5
	case 102: kCode=54; break; // Right - 6
	case 103: kCode=55; break; // Home - 7
	case 104: kCode=56; break; // Up - 8
	case 105: kCode=57; break; // PgUp - 9

	case 48: if (event.shiftKey) kCode = 41; break;  // 0 or )
	case 49: if (event.shiftKey) kCode = 33; break;  // 1 or !
	case 50: if (event.shiftKey) kCode = 64; break;  // 2 or @
	case 51: if (event.shiftKey) kCode = 35; break;  // 3 or #
	case 52: if (event.shiftKey) kCode = 36; break;  // 4 or $
	case 53: if (event.shiftKey) kCode = 37; break;  // 5 or %
	case 54: if (event.shiftKey) kCode = 94; break;  // 6 or ^
	case 55: if (event.shiftKey) kCode = 38; break;  // 7 or &
	case 56: if (event.shiftKey) kCode = 42; break;  // 8 or *
	case 57: if (event.shiftKey) kCode = 40; break;  // 9 or (
	case 186: if (event.shiftKey) kCode = 58; else kCode=59; break; // ; :
	case 187: if (event.shiftKey) kCode = 43; else kCode=61; break; // = +
	case 188: if (event.shiftKey) kCode = 60; else kCode=44; break; // , <
	case 189: if (event.shiftKey) kCode = 95; else kCode=45; break; // - _
	case 190: if (event.shiftKey) kCode = 62; else kCode=46; break; // . >
	case 191: if (event.shiftKey) kCode = 63; else kCode=47; break; // / ?
	case 192: if (event.shiftKey) kCode = 126; else kCode=96; break; // ` ~
	case 219: if (event.shiftKey) kCode = 123; else kCode=91; break; // [ {
	case 220: if (event.shiftKey) kCode = 124; else kCode=92; break; // \ |
	case 221: if (event.shiftKey) kCode = 125; else kCode=93; break; // ] }
	case 222: if (event.shiftKey) kCode = 34; else kCode=39; break; // ] }
	
	 
	default: 
		if ((kCode>64) && (kCode<91) && (!event.shiftKey)) kCode +=32 //lc letters
	}
	if (kCode>31) Entry += String.fromCharCode(kCode); 	
	//LastKeyCode = kCode;
	oCtrl.options[0].text  = Entry;
	oCtrl.options[0].value  = Entry;
	oCtrl.options[0].selected = true; 

	event.cancelBubble = true;  
  if (event.returnValue) event.returnValue = false;  
  if (event.stopPropagation) event.stopPropagation();
  var fields = oCtrl.getAttribute("fields")
	MyAjaxService.Lookup(25, oCtrl.id, fields, Entry, LookupCallback, FailedCallback)
	return false
}

function LookupCallback(List)
{
	if(List.length==0) return;
	var oCtrl = $get(List[0]);
	for (var i=1; i<oCtrl.options.length; i++)
	{
		var Item;
		if (List.length>i)	Item = List[i];
		else Item = ""
		oCtrl.options[i].text = Item;
		oCtrl.options[i].value = Item;
	}
}

function LookupClear(oCtrl)
{
	oCtrl.options[0].text = ""; //oCtrl.getAttribute("defaultvalue");
	oCtrl.options[0].value = "";
	oCtrl.size=oCtrl.length;
	var action = "document.getElementById('" + oCtrl.id + "').size=" + oCtrl.length 
	setTimeout(action,100);
}
function LookupClose(oCtrl)
{
	oCtrl.size=1;
}

var GoToURL = "";


function SearchML(id){
	setTimeout("SearchML0('" + id + "')",50) // Need a breather so that selectedIndex gets set 
}

function SearchML0(id){
	var oCtrl = $get(id);
	var ML = "";
	if (oCtrl.type=="select-one") ML = oCtrl[oCtrl.selectedIndex].text;
	if (oCtrl.type=="text") ML = oCtrl.value;
	var ML = TRIM(ML);
	LastAddress=ML // Save in case we need to just position map

	if (0==ML.length) return;
	// Was ML# included in the text
	if (ML.lastIndexOf("#:")>0)
	{ 
		ML=ML.substring(ML.lastIndexOf("#:")+2,ML.length);
		MyAjaxService.PropertyMLLookup(ML, "0,0,0,0", SearchMLCallBack, FailedCallback);		
		return;
	}
	// If a single word then assume it is an ML#
	if (ML.split(" ").length==1)
	{ 
		MyAjaxService.PropertyMLLookup(ML, "0,0,0,0", SearchMLCallBack, FailedCallback);
		return;
	}
	// else look up as an address

	SearchAddr1(id);

	//var aAddr = ML.split(",");
	//var Zip="";
	//if (aAddr.length>1) Zip = TRIM(aAddr[aAddr.length-1]);
	//if (Zip.length>5) Zip=Zip.substr(Zip.length-5,5);
	//MyAjaxService.PropertyAddressLookup(TRIM(aAddr[0]),Zip,AddrCallBack, FailedCallback);
	
}

function SearchMLCallBack(Result){
	if (0==Result.length){
			var ML = LastAddress
			if ("0"==ML.substring(0,1)){ // Try replacing 0 with the letter O
				MyAjaxService.PropertyMLLookup("O"+ML.substr(1), "0,0,0,0", SearchMLCallBack, FailedCallback);
			} else {
				 	alert("Listing Not found: " + LastAddress);	
				 	//maybe it is an address
				 	//MyAjaxService.PropertyAddressLookup(TRIM(ML),"",SearchAddrCallBack, FailedCallback)
			}
		 return;
		}
		AddrCallBack(Result);	
}

function AddrCallBack(SysPropID)
	{	
	// If this address is for an active listing, then show the detail, else just go to 
	// regular property search centered on this address
		if (SysPropID.length>0)	{
		
			var parms = SysPropID.split(",");
			var Site = parent.$get("hSiteCode").value;
			switch (Site){
			case "HHI": parent.ShowDetailFrame("../PropDetail_B.aspx?N=0&S=" + SysPropID.replace(",","&Id="));
								return;
			
			case "INR":	parent.ShowDetailFrame("../PropDetail.aspx?N=0&S=" + SysPropID.replace(",","&Id=")); 
								return;
												
			case "OKC":
			case "MFR": document.location.href=FullURL("SiteContent/PropDetail.aspx?N=0&S=" + SysPropID.replace(",","&Id="));
								return;
	
			case "DFW": parent.ShowDetailFrame("PropDetail.aspx?N=0&S=" + SysPropID.replace(",","&Id="));
								break;						
								
			default:	alert("Missing AddrCallBack handler for " + parms[0]);		
				break;
			}
		

		} else parent.ContentFrame.FindAddress(LastAddress)


}







function SearchAddr(id){
	setTimeout("SearchAddr1('" + id +"')",50);
}

function SearchAddr1(id){
	// Look up an address entered from the home page
	var oCtrl = $get(id);
	var SiteCode = $get("hSiteCode").value;
	var Addr = "";
	if (oCtrl.type=="select-one") Addr = oCtrl[oCtrl.selectedIndex].text;
	if (oCtrl.type=="text") Addr = oCtrl.value;
	Addr = TRIM(Addr);
	if (0==Addr.length) return;
	var aAddr = Addr.split(",");
	var Zip="";
	if (aAddr.length>1) Zip = TRIM(aAddr[aAddr.length-1]);
	if (Zip.length>5) Zip=Zip.substr(Zip.length-5,5);

	LastAddress=Addr;
	// Incase there is no address match, prepare redirect.
	var url = "?Addr=" + escape(Addr) + "&CityStZip=" + escape(Zip)
 	switch (SiteCode){
 	case "DFW": GoToURL=null; if (Addr.length>0) parent.ContentFrame.FindAddress(Addr); 
 							break; // No home page, move map in ajoining window.
 	case "INR": GoToURL = null; break; // Stay here if not found						
 	case "MFR": GoToURL = null; break; //FullURL("SiteContent/PropertySearch.aspx" + url); break;
 	case "OKC": GoToURL = FullURL("SiteContent/PropertySearch.aspx" + url); break;
 	case "LAS": GoToURL = FullURL("SiteContent/LAS/PropertySearchLAS.aspx" + url); break;
 	case "Demo": GoToURL = FullURL("SiteContent/DEMO/PropertySearchDemo.aspx" + url); break;
 	default:alert("Missing SiteCode Handler in SearchAddr():" + SiteCode);
 	}	
	
	var ML=""
	if (Addr.lastIndexOf("#:")>0)
	{ ML=Addr.substring(Addr.lastIndexOf("#:")+2,Addr.length);
		MyAjaxService.PropertyMLLookup(ML, "0,0,0,0", SearchAddrCallBack, FailedCallback);
		
	} else 
	MyAjaxService.PropertyAddressLookup(TRIM(aAddr[0]),Zip,SearchAddrCallBack, FailedCallback);
}
	
function SearchAddrCallBack(SysPropID)
	{	
	// If this address is for an active listing, then show the detail, else just go to 
	// regular page centered on this address
		if (SysPropID.length==0)	{
			if (GoToURL!=null) document.location.href=GoToURL;
			else alert("Not Found: "+LastAddress);
			return;
		};
		
		var aProps = SysPropID.split(";")
		if (aProps.length>1) 
		{
			var Display = "Mutiple possibilities...be more specific\n" 
			var N = aProps.length
			for (var i=0; i<N; i++)
			{
				var aText = (aProps[i]+",,").split(",")
				var Text = aText[2];
				Display += "\n" + Text;
			}
			alert(Display);
			return;
		}
		
		var parms = SysPropID.split(",");
		var qparms = "?N=0&S=" + SysPropID.replace(",","&Id=");
		switch ($get("hSiteCode").value){
		case "DFW": break;
		case "HHI": document.location.href = FullURL("SiteContent/PropDetail_B.aspx" + qparms); break;
		case "INR": parent.ShowDetailFrame(FullURL("SiteContent/PropDetail.aspx" + qparms)); break;
		case "DEMO": document.location.href = FullURL("SiteContent/Demo/PropDetailDemo.aspx" + qparms); break;
		default:		document.location.href = FullURL("SiteContent/PropDetail.aspx" + qparms);
		break;
		}
		
		
}
