

	
	

/*
Copyright: Webdadi Limited
Author: Chris Baldwin
Email: chris@webdadi.com
Commercial use of any code within this document must be authorised by the author.
*/


// check browsers
var ua = navigator.userAgent;
var opera = /opera [56789]|opera\/[56789]/i.test(ua);
var webkit = /webkit/i.test(ua);
var ie = !opera && /MSIE/.test(ua);
var ie50 = ie && /MSIE 5\.[01234]/.test(ua);
var ie6 = ie && /MSIE [6789]/.test(ua);
var ie7 = ie && /MSIE [789]/.test(ua);
var ie8 = ie && /MSIE [89]/.test(ua);
var ieBox = ie && (document.compatMode == null || document.compatMode != "CSS1Compat");
var moz = !opera && !webkit && /gecko/i.test(ua);
var nn6 = !opera && /netscape.*6\./i.test(ua);

function keyCode(e) {return (moz?e.which:e.keyCode);}
function srcElement(e) {return (moz?e.target:e.srcElement);}
function innerText(e) {return (moz?e.textContent:e.innerText);}

var divAnimate = null;
var xh = 10;
var xw = 10;	
var yw = 550;
var yh = 400;
var right = 700;
var animateleft = false;
var top = 100;
var step = 15;

var browser = new Object();
var popup = null;

function AttachEvent(obj, event, func) {
    if (window.innerHeight && window.innerWidth) {
//alert('MZ:' + event);
    	obj.addEventListener(event, func, false);
    } else {
//alert('IE:' + event);
    	obj.attachEvent('on' + event, func);
    }
}

function initbrowser(init) {
    if (window.innerHeight && window.innerWidth) {
        //NN
        browser.height = window.innerHeight;
        browser.width = window.innerWidth;
        browser.top = window.pageYOffset;
        browser.left = window.pageXOffset;
        if (init) {
            window.addEventListener('scroll', initbrowserEx, false);
            window.addEventListener('resize', initbrowserEx, false);
            document.addEventListener('mousemove', function (e) { pagemanager.mousemove(e); }, true);
            document.addEventListener('mouseup', function (e) { pagemanager.mouseup(e); }, true);
 	}
    } else if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) {
        //IE8
        browser.height = document.documentElement.clientHeight;
        browser.width = document.documentElement.clientWidth;
        browser.top = document.documentElement.scrollTop;
        browser.left = document.documentElement.scrollLeft;
        if (init) {
            window.attachEvent('onscroll', initbrowserEx);
            window.attachEvent('onresize', initbrowserEx);
            document.attachEvent('onmousemove', function (e) { pagemanager.mousemove(e); });
            document.attachEvent('onmouseup', function (e) { pagemanager.mouseup(e); });
        }
    } else {
        //other IE
	if (document.body) {
        browser.height = document.body.clientHeight;
        browser.width = document.body.clientWidth;
        browser.top = document.body.scrollTop;
        browser.left = document.body.scrollLeft;
        if (init) {
            window.attachEvent('onscroll', initbrowserEx);
            window.attachEvent('onresize', initbrowserEx);
            document.attachEvent('onmousemove', function (e) { pagemanager.mousemove(e); });
            document.attachEvent('onmouseup', function (e) { pagemanager.mouseup(e); });
        }
	}
    }
    if ((popup)&&(popup.visible)) {
        popup.invalidate();
    }
}
initbrowser(true);

function initbrowserEx() {
    initbrowser(false);
}

function Point(x, y) {
    this.x = x;
    this.y = y;
}

function AddClass(el, className) {
	RemoveClass(el, className);
	el.className += (el.className?' ':'') + className;
}

function RemoveClass(el, className) {
	if (!(el && el.className)) {
		return;
	}
	if (el.className == className) {
		el.className = '';
		return
	}	
	var cls = el.className.split(" ");
	var ar = new Array();
	for (var i = 0; i<cls.length; i++) {
		if (cls[i] != className) {
			ar[ar.length] = cls[i];
		}
	}
	el.className = ar.join(" ");
}

function HasClass(el, className) {
	if (el && el.className) {
		if (el.className == className) {
			return true;
		}	
		var cls = el.className.split(" ");
		for (var i=0; i<cls.length; i++) {
			if (cls[i] == className) {
				return true;
			}
		}
	}
	return false;
}

/* ANIMATION */

_aniwidth = 
_anistart = null;
_anistop = null;

function $id(id, def) {
	var e = document.getElementById(id); 
	return (e?e:def);
}

function selectCTRL(){obj=window.event.srcElement;if((obj.tagName=='INPUT')||(obj.tagName=='TEXTAREA')||(obj.className=='editable'))return true;else return false;}

function Animation() {
    //-- Private
    this._xh = 10;
    this._xw = 10;
    this._yh = 550;
    this._yw = 400;
    this._start = new Point(0,0);
    this._stop = new Point(0,0);
    this._div = null;
    this._animate = function () { 
	    this._xw += (this._yw / step);
    	this._xh += (this._yh / step);
    	if (this.effect != this.aeWiden) this._div.style.left = this._start.x + ((this._stop.x - this._start.x) * (this._xw / this._yw))-14 + 'px';
	    if (this.effect != this.aeWiden) this._div.style.top = this._start.y + ((this._stop.y - this._start.y) * (this._xh / this._yh)) + 'px';
	    this._div.style.width = this._xw + 'px';
	    if (this.effect != this.aeWiden) this._div.style.height = this._xh + 'px';
	    if (this._xw <= this._yw)
		    window.setTimeout('Animator._animate()', this.speed);
		else { 
		    this._div.style.left = this._stop.x + 'px';
		    this._div.style.top = this._stop.y + 'px';
		    TScalableImage.Refresh();
		}
    }    
    //-- Public
    this.step = 10;
    this.speed = 5;
    //-- Animation Effect
    this.aeScreenCenter = 0;this.aeRight = 1;this.aeLeft=2;this.aeWiden=3;
    this.effect = this.aeScreenCenter;
    this.Animate = function (div, width, height, start, stop, e) {
//        alert('animate start');
	if (!start) {
		e = (e?e:window.event);
		start = new Point(screenXtoclientX(div, (e.screenX?e.screenX:e.pageX) - 10), screenYtoclientY(div, (e.screenY?e.screenY:e.pageY) - 25));
	}
	if ((start)&&(!start.x)) start = null;
        this._start = (start?start:new Point((document.body.clientWidth / 2),(document.body.clientHeight / 2)));
        if (stop) {
            this._stop = stop;
        } else {
            switch (this.effect) {
                case this.aeRight:
                        this._stop = new Point(this._start.x, this._start.y  - (height / 2));
                        break;  
                case this.aeLeft:
                        this._stop = new Point(this._start.x - width, this._start.y  - (height / 2));
                        break;           
                case this.aeWiden=3:     
                        this._stop = new Point(this._start.x - width, this._start.y);
                        break;           
                default: // this.aeScreenCenter  
                        //var dy =((document.body.clientHeight / 2) - (height / 2)) + getTop(); 
                        var dy = 100 + getTop();
                        this._stop = new Point((document.body.clientWidth / 2) - (width / 2), dy);                        
                        break;
            }
        }
        
        if (this._div) {
            this._div.style.display = 'none';
        }
        
        
	    this._div = div;
	    this._xw = 10;
	    this._xh = 10;
	    this._yw = width;
	    this._yh = height;
	    	    
	    div.style.display = 'block';        
        Animator._animate();
    }
}
var Animator = new Animation();
/* END OF ANIMATE */

function loadmedia(xmlhttp) {
	if ($id('fpFlashCtrls'))
		$id('fpFlashCtrls').style.display = 'none';
	var flashdiv = document.getElementById('fpFlash');
    flashdiv.style.overflow = 'hidden';
	if (xmlhttp.ajax.responseText.indexOf('//script') > 0) {
	    eval(xmlhttp.ajax.responseText);
	} else {
		flashdiv.innerHTML = xmlhttp.ajax.responseText;
        flashdiv.style.overflow = 'hidden';
        var x = flashdiv.getElementsByTagName("script"); 
        for (var i=0; i<x.length; i++) {
            eval(x[i].text);   
        }           
	}
}

function screenXtoclientX(ele, x) {
	var scrx = 0;
	ele = ele.offsetParent;
	while (ele) {
		scrx += ele.offsetLeft;
		ele = ele.offsetParent;
	}
	return (x - scrx) - (window.screenLeft);
}

function screenYtoclientY(ele, y) {
	var scry = 0;
	ele = ele.offsetParent;
	while (ele) {
		scry += ele.offsetTop;
		ele = ele.offsetParent;
	}
	return (y - scry) - (window.screenTop);
}

function showlogin(e, reqfeature) {
    var f =document.getElementById('lblusefeature');
    
    if (f) 
        f.style.display = (reqfeature?'block':'none');
    return loadDiv(e, 'saveSearchDiv')   
}

function loadDiv(e, div, effect) {
	e = (e?e:window.event);
	var div = document.getElementById(div);
	//-- Current Position of Mouse
	var start = new Point(screenXtoclientX(div, (e.screenX?e.screenX:e.pageX) - 10), screenYtoclientY(div, (e.screenY?e.screenY:e.pageY) - 25));
	
	if (effect)
        Animator.effect = effect;

	Animator.Animate(div, 400, 200, start);

	return false;
}

  function switchImg(obj) {
  if (obj.src.substring(obj.src.length-5, obj.src.length-4).toLowerCase() == 'a')
  obj.src = obj.src.substring(0, obj.src.length-5) + 'o.gif';
  else
  obj.src = obj.src.substring(0, obj.src.length-5) + 'a.gif';
  }

var fpmoreurl = '';
function fpshowmemore() {
	window.location.href = fpmoreurl;
}

var ds_object = null;
var ds_start = null;
function dragscrollstart(e) {
    ds_object = document.getElementById('dfloorplan');
    ds_start = new Object();
    ds_start.x = e.screenX;
    ds_start.y = e.screenY;
}
function dragscrollend(e) {
    ds_object = null;
    ds_start = null;
}
function dragscroll(e) {
     if (ds_object) {
        ds_object.scrollTop = ds_object.scrollTop + (ds_start.y - e.screenY);
        ds_object.scrollLeft = ds_object.scrollLeft + (ds_start.x -  e.screenX);
        ds_start.x = e.screenX;
        ds_start.y = e.screenY;
    }
}

function screenwidth() {
    if (window.innerHeight && window.innerWidth) {
        return window.innerWidth;
    } else if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) {
        return document.documentElement.clientWidth;
    } else {
        return document.body.clientWidth;
    }
}

function tpopup(div) {
    this._div = div;
    this.w = 0;
    this.h = 0;
    this.selects = document.getElementsByTagName('select');
    this.visible = false;
    this.open = function (e, url, w, h) {
    	var popupdiv = $id(this._div);
    	var blackout = $id('blackout');
    	this.noanimate = HasClass(popupdiv,'noanimate');
        if (stopshow) {
            stopshow();
        }
	//-- Start Ajax Load of Content
	document.getElementById('fpFlash').innerHTML = '';
	loadpage(url, loadmedia, 'GET');
	e = (e?e:window.event);	
	
	//Hide selects on ie6
	if (ie6&&!ie7&&!ie8) {
		for (var i = 0; i <this.selects.length; i++) {
			this.selects[i].style.display = 'none';
		}
	}

	if (blackout) {
	//Place a div over everything
		blackout.style.width = parseInt(browser.width) + 'px';
		blackout.style.height = parseInt(browser.height) + 'px';
		blackout.style.display='block';
		
		if (ie6&&!ie7&&!ie8)
		//ie6 does not support position:fixed
			{
			blackout.style.top = browser.top + 'px';
			}
		else
			{
			blackout.style.top = "0px";
			blackout.style.position = "fixed";
			}
	}	   
	if (this.noanimate) {
	//Show the popup div and position and size it correctly
		var stop = new Point(((parseInt(browser.width) - w) / 2) + browser.left, ((parseInt(browser.height) - h) / 2) + browser.top);
		var stopfixed = new Point(((parseInt(browser.width) - w) / 2), ((parseInt(browser.height) - h) / 2));
		
		popupdiv.style.width = w + 'px';
		popupdiv.style.height = h + 'px';
		popupdiv.style.display = 'block';
		if (ie6&&!ie7&&!ie8) //ie6 does not support position:fixed
			{
			popupdiv.style.left = stop.x + 'px';
			popupdiv.style.top = stop.y + 'px';
			}
		else
			{
			popupdiv.style.left = stopfixed.x + 'px';
			popupdiv.style.top = stopfixed.y + 'px';
			popupdiv.style.position = "fixed";
			}
			
	
	} else {
		var start = new Point((e.clientX?e.clientX:e.pageX) - 10, ((e.clientY?e.clientY:e.pageY) - 25) + getTop());
		var stop = new Point(((parseInt(browser.width) - w) / 2) + browser.left, ((parseInt(browser.height) - h) / 2) + browser.top);
		Animator.Animate(popupdiv, w, h, start, stop);
	}

	var hideBox = document.getElementById('paging');
	if (hideBox)
	    hideBox.style.display = 'none';


	this.w = w;
	this.h = h;
	this.visible = true;
    }
    this.close = function() {
	var f = $id('popupframe');
	if (f) {
		f.src = '';
		f.style.display = 'none';
	}
	if (ie6&&!ie7&&!ie8) {
		for (var i = 0; i <this.selects.length; i++) {
			this.selects[i].style.display = 'block';
		}
	}
        $id(this._div).style.display = 'none';
        if (document.getElementById('blackout')) 
	        document.getElementById('blackout').style.display='none';	
	    var hideBox = document.getElementById('paging');
	    if (hideBox)
		    hideBox.style.display = 'block';
        this.visible = false;
    }
    this.invalidate = function() 
	//This function refresh the popup and should be called when the window is scrolled or changes size
	{
	if (this.visible) {
        if (document.getElementById(this._div)) {
			if (ie6&&!ie7&&!ie8) //ie6 does not support position:fixed
				{
				if(parseInt(browser.height) > this.h)
					{
					document.getElementById(this._div).style.top = ((parseInt(browser.height) - this.h) / 2) + browser.top + 'px';
					}
				document.getElementById(this._div).style.left = ((parseInt(browser.width) - this.w) / 2) + browser.left + 'px';
				}
			else
				{
				if(parseInt(browser.height) > this.h)
					{
					document.getElementById(this._div).style.position = "fixed";
					document.getElementById(this._div).style.top = ((parseInt(browser.height) - this.h) / 2) +'px';
					document.getElementById(this._div).style.left = ((parseInt(browser.width) - this.w) / 2) +'px';
					}
				else
					{
					document.getElementById(this._div).style.position = "absolute";
					document.getElementById(this._div).style.top = '15px';
					document.getElementById(this._div).style.left = ((parseInt(browser.width) - this.w) / 2) + browser.left + 'px';
					}
				
				
				}
        }  
        if (document.getElementById('blackout')) {
	        document.getElementById('blackout').style.width = parseInt(browser.width) + 'px';
            document.getElementById('blackout').style.height = parseInt(browser.height) + 'px';
			document.getElementById('blackout').style.display='block';
			
			if (ie6&&!ie7&&!ie8)
			//ie6 does not support the fixed property
				{
				document.getElementById('blackout').style.top = browser.top + 'px';
				}
			else
				{
				document.getElementById('blackout').style.top = "0px";
				document.getElementById('blackout').style.position = "fixed";
				}

	    }  
	}
    }
}


popup = new tpopup('divFP');

function openpopup(e, url, w, h) {
    if (stopshow) {
        stopshow();
    }
	//-- Start Ajax Load of Content
	document.getElementById('fpFlash').innerHTML = '';
	loadpage(url, loadmedia, 'GET');
        e = (e?e:window.event);	
	var start = new Point((e.clientX?e.clientX:e.pageX) - 10, ((e.clientY?e.clientY:e.pageY) - 25) + getTop());
	var stop = new Point(((parseInt(browser.width) - w) / 2) + browser.left, ((parseInt(browser.height) - h) / 2) + browser.top);
	Animator.Animate(document.getElementById('divFP'), w, h, start, stop);
	
	if (document.getElementById('blackout')) {
		document.getElementById('blackout').style.width = parseInt(browser.width) + 'px';
		document.getElementById('blackout').style.height = parseInt(browser.height) + 'px';
	        document.getElementById('blackout').style.top = browser.top + 'px';
	    	document.getElementById('blackout').style.display='block';
		if (document.getElementById('divFP')) {
		    document.getElementById('divFP').style.top = ((parseInt(browser.height) - h) / 2) + browser.top + 'px';
		    document.getElementById('divFP').style.left = ((parseInt(browser.width) - w) / 2) + browser.left + 'px';
		}
	}
	popup.w = w;
	popup.h = h;
	
	var hideBox = document.getElementById('paging');
	if (hideBox)
		hideBox.style.display = 'none';
}




function showmedia(e, id, type, ix) {
    if (stopshow) {
        stopshow();
    }
	//-- Start Ajax Load of Content
	document.getElementById('fpFlash').innerHTML = '';
	loadpage('/p.dtx?f=fpurl.tem&t=page\\results&doctype=false&type=' + (type?type:'fp') + '&propertyid=' + id + '&index=' + ix, loadmedia, 'GET');
	fpmoreurl = '/details.dtx?p=' + id.replace('{','').replace('}','');
    	e = (e?e:window.event);	
	//-- Current Position of Mouse
	//var start = new Point(screenXtoclientX(document.getElementById('divFP'), (e.screenX?e.screenX:e.pageX) - 10), screenYtoclientY(document.getElementById('divFP'), (e.screenY?e.screenY:e.pageY) - 25) + getTop());
	var start = new Point((e.screenX?e.screenX:e.pageX) - 10, ((e.screenY?e.screenY:e.pageY) - 25) + getTop());
	switch (type) {
		case 'flv':Animator.Animate(document.getElementById('divFP'), 340, 320, start); break;
		case 'jpg':Animator.Animate(document.getElementById('divFP'), 500, 380, start); break;
		case 'vtour':Animator.Animate(document.getElementById('divFP'), 400, 460, start); break;
		case 'pdf':return;
		default:Animator.Animate(document.getElementById('divFP'), 800, 600, start); break;
	}
	
	var hideBox = document.getElementById('paging');
	if (hideBox)
		hideBox.style.display = 'none';
		
	if (document.getElementById('blackout')) {
		document.getElementById('blackout').style.width = parseInt(browser.width) + 'px';
		document.getElementById('blackout').style.height = parseInt(browser.height) + 'px';
	        document.getElementById('blackout').style.top = browser.top + 'px';
	    	document.getElementById('blackout').style.display='block';
	}		
}

var switchFP = 0;
function doswitchplan(index, ids) {
	switchFP += index;
	var fpa = ids.split(',');
	document.getElementById('ifloorplan').src = 'http://lemon.datography.com/webresize.aspx?filename=' + fpa[switchFP] + '&width=500&height=943&constrain=true';
	document.getElementById('fpnext').style.visibility = (switchFP == (fpa.length-1)) ? 'hidden':'visible';
	document.getElementById('fpprev').style.visibility = (switchFP == 0) ? 'hidden':'visible';
}

function hidefloorplan() {
	document.getElementById('divFP').style.display = 'none';
    if (document.getElementById('blackout')) 
	    document.getElementById('blackout').style.display='none';	
	var hideBox = document.getElementById('paging');
	if (hideBox)
		hideBox.style.display = 'block';
}

var xmlhttpstack = new Array();

function GetDatogXmlHttp() {
    var xmlhttp = new Object();
    xmlhttp.ajax = GetXmlHttpEx();
    for (var i=0; i<xmlhttpstack.length; i++) {
        if (!xmlhttpstack[i]) {
            xmlhttp.ref = i;
            xmlhttpstack[i] = xmlhttp;
            return xmlhttp;
        }
    }
    xmlhttp.ref = xmlhttpstack.length;
    xmlhttpstack[xmlhttpstack.length] = xmlhttp;
    return xmlhttp;    
}

function GetXmlHttpEx() {
    if (typeof XMLHttpRequest != "undefined") {
        return new XMLHttpRequest;
    } else if (window.ActiveXObject) {
        var aVersions = ["MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft XMLHttp"];
        for (var i = 0; i <aVersions.length; i++) {
            try {
                var x = new ActiveXObject(aVersions[i]);
                return x;
            } catch (oError) {
                //Do nothing
            }
        }
    }
    throw new Error("XMLHttp object could not be created");
}

//var xmlhttp = null;


function loadpage(url, onevent, type, obj, dofade) { 
  if (!type) type = 'POST';
  var xmlhttp = GetDatogXmlHttp();
  if (xmlhttp) {
        xmlhttp.ajax.open(type, url + '&_enc=utf8', true);
        xmlhttp.onevent = onevent;
        xmlhttp.obj = obj;
	xmlhttp.dofade = dofade;
        eval('xmlhttp.ajax.onreadystatechange = function () { loadpageresponse(' + xmlhttp.ref + '); }');
        if (ie)
   	        xmlhttp.ajax.send();
   	    else
   	        xmlhttp.ajax.send(xmlhttp.ajax.responseText);
   }	
}

function loadpageresponse (ref) {
    var xmlhttp = xmlhttpstack[ref];
    //alert(ref + ' - ' + xmlhttp.ajax.readyState);
	if ((xmlhttp.ajax.readyState == 4) && (xmlhttp.ajax.status == 200)) {
	    xmlhttp.onevent(xmlhttp);		        	
        xmlhttpstack[ref] = null;
    }
}	


var partaddr = '';
function docompare(address, part) {
	for (x=1; x<part.length; x++) {
		if ((x >= address.length) || (part.charAt(x) != address.charAt(x))) {
			return part.substring(0, x);
		}
	}
	return part;
}

function dolistload(obj) {
	eval(obj.ajax.responseText);
	if (rdata.length == 0) {
		document.getElementById('addrlist').innerHTML = 'No matching properties';
	} else {
		partaddr = rdata[0];
		for (i=1; i<rdata.length; i++) {
			partaddr = docompare(rdata[i], partaddr)
		}	
		var htmltext = '';
		for (i=0; i<rdata.length; i++) {
			htmltext += '<div onclick="performselectitem(event)" onmouseover="setHighLight(this)"><span>' + partaddr + '</span>' + rdata[i].substring(partaddr.length) + '</div>';
		}
		document.getElementById('addrlist').innerHTML = htmltext;
	}
}

function doselectitem(item) {
    document.getElementById('street').value = innerText(item);
    document.getElementById('addrlist').style.display = 'none';
    if ((document.getElementById('frmcriteria'))&&(!tlookuplist.nosubmit))
       document.getElementById('frmcriteria').submit();        
}

function performselectitem(e) {
    var item = srcElement(e);
    doselectitem(item);
}

var t = null;

function performloadcontent(url) {
    loadpage(url, dolistload);
}

function performlist(ele) {
    window.clearTimeout(t);
	if (ele.value.length > 0) {
		document.getElementById('addrlist').style.display = 'block';
		partaddr = ele.value;
		t = window.setTimeout('performloadcontent(\'/p.dtx?c=addrlist&doctype=false&address1=' + ele.value + '\')', 200);
	} else
		document.getElementById('addrlist').style.display = 'none';
}

function getActiveListElement(parent) {
    var e = parent;
    for (var i = 0; i <e.childNodes.length; i++) {
        if (e.childNodes[i].className != '')
            return i;
    }
    return -1;
}

function doSearchBtnRollOver(img) {
    if (document.getElementById('searchbtn')) {
        document.getElementById('searchbtn').onmouseover = '';
        document.getElementById('searchbtn').onomouseout = '';
        document.getElementById('searchbtn').src = img;
    }
}


/* Cookie */
function TCookie() {
    this.Get = function (name) {
	    // first we'll split this cookie up into name/value pairs
	    // note: document.cookie only returns name=value, not the other components
	    var a_all_cookies = document.cookie.split( ';' );
	    var a_temp_cookie = '';
	    var cookie_name = '';
	    var cookie_value = '';
	    var b_cookie_found = false; // set boolean t/f default f
    	
	    for ( i = 0; i <a_all_cookies.length; i++ )
	    {
		    // now we'll split apart each name=value pair
		    a_temp_cookie = a_all_cookies[i].split( '=' );
    		
    		
		    // and trim left/right whitespace while we're at it
		    cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
    	
		    // if the extracted name matches passed check_name
		    if ( cookie_name == name )
		    {
			    b_cookie_found = true;
			    // we need to handle case where cookie has no value but exists (no = sign, that is):
			    if ( a_temp_cookie.length > 1 )
			    {
				    cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			    }
			    // note that in cases where cookie is initialized but no value, null is returned
			    return cookie_value;
			    break;
		    }
		    a_temp_cookie = null;
		    cookie_name = '';
	    }
	    if ( !b_cookie_found )
	    {
		    return null;
	    }    
    }
    this.Set = function (name, value, expires, path, domain, secure) {
        // set time, it's in milliseconds
        var today = new Date();
        today.setTime( today.getTime() );

        if ( expires )
            expires = expires * 1000 * 60 * 60 * 24;
        var expires_date = new Date( today.getTime() + (expires) );

        document.cookie = name + "=" +escape( value ) +
        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
        ( ( path ) ? ";path=" + path : "" ) + 
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );    
    }
}

var sitestate = new TCookie();

/*------ Start lookup list component --------*/
function getListElements(parent) {
    var e = parent;
    var rtn = 0;
    for (var i = 0; i <e.childNodes.length; i++) {
        rtn++; 
    }
    return rtn;
}
function setHighLight(e) {
    var ele = document.getElementById('addrlist');
    for (var i = 0; i <ele.childNodes.length; i++) {
        ele.childNodes[i].className = '';
    }
    e.className = 'lookupactive';
}


function tlookuplist(element, div, url) {
    this.ele = element;
    this.div = div;
    this.url = url;
    this.partaddr = '';
    this.activeitem = null;
    this.index = null;
    this.keytimer = null;
    this.setactive = function (item) {
        if (this.activeitem) 
            document.getElementById('addrlist').childNodes[this.activeitem].className = '';
        document.getElementById('addrlist').childNodes[item].className = 'lookupactive';
        this.activeitem = item;
    }
    this.onkeydown = function (event) {
        var e = (event.srcElement||event.target);
        if (e) e.style.backgroundPosition = '-500px -500px';
        if (keyCode(event) == 9) {
		    this.ele.value = partaddr;
		    return false;
		} else if (keyCode(event)==38) {
		    if (document.getElementById('addrlist').style.display=='block') {		        
		        var tmp = getActiveListElement(document.getElementById('addrlist'));
		        if (tmp>0) {
		            if (tmp <getListElements(document.getElementById('addrlist'))+1)
		                document.getElementById('addrlist').childNodes[tmp].className = '';
		            document.getElementById('addrlist').childNodes[tmp-1].className = 'lookupactive';
		        }
		    }
		} else if (keyCode(event)==40) {
		    if (document.getElementById('addrlist').style.display=='block') {
		        var tmp = getActiveListElement(document.getElementById('addrlist'));
		        if (tmp <getListElements(document.getElementById('addrlist'))-1) {
		            if (tmp!=-1)
		                document.getElementById('addrlist').childNodes[tmp].className = '';
		            document.getElementById('addrlist').childNodes[tmp+1].className = 'lookupactive';
		        }
		    }
		} else if (keyCode(event)==13) {
		    if (getActiveListElement(document.getElementById('addrlist')) > -1)
		        doselectitem(document.getElementById('addrlist').childNodes[getActiveListElement(document.getElementById('addrlist'))]);
		    return false;
		}		
		return true;
    }     
    this.onkeyup = function (event) {
        var e = (event.srcElement||event.target);
        if (e.value == '') e.style.backgroundPosition = '0px 0px';    
        window.clearTimeout(this.keytimer);
        var kc = keyCode(event);        

        if (!(kc in {37:null,38:null,39:null,40:null,13:null})) {
	        if (this.ele.value.length > 0) {
		        document.getElementById('addrlist').style.display = 'block';
		        partaddr = this.ele.value;
		        this.keytimer = window.setTimeout('performloadcontent(\'' + this.url.replace('%value%', this.ele.value) + '\')', 750);
	        } else
		        document.getElementById('addrlist').style.display = 'none';  
		}  
    }  
    tlookuplist.register(this);
}
tlookuplist.lookups = new Array();
tlookuplist.register = function (lookup) {
    lookup.index = tlookuplist.lookups.length;
    tlookuplist.lookups[tlookuplist.lookups.length] = lookup;
}

/*------ Start slideshow component --------*/

arr_slideshows = new Array();
function updateslideshow(divid) {
  var ss = null;   
  for (var i = 0; i <arr_slideshows.length; i++) {
    if ((arr_slideshows[i].div)&&(arr_slideshows[i].div.id == divid)) {
      ss = arr_slideshows[i];
    }
  }
  if (ss)
    ss.update();
}
tslideshow = function (divid, url, interval, fade, doload) {
  arr_slideshows[arr_slideshows.length] = this;
  this.divid = divid; 
  this.load = function (url, interval, fade, doload) {
      //alert(url);
      this.div = document.getElementById(divid);
      this.url = url;
      this.interval = interval;
      if (doload) 
        this.update();
      else
        this.start();
      this.fade = fade;
  }
  this.update = function () {
    var xmlhttp = GetDatogXmlHttp();
    if (xmlhttp) {
      xmlhttp.ajax.open('GET', this.url, true);
      xmlhttp.slideshow = this;
      eval('xmlhttp.ajax.onreadystatechange = function () { xmlhttpresponse(' + xmlhttp.ref + '); }');
      if (ie)
        xmlhttp.ajax.send();
      else
        xmlhttp.ajax.send(document);
    }
  }
  this.next = function () {
    window.clearTimeout(this.timer);
    updateslideshow(this.divid);
  }
  this.start = function () {
    if ((this.interval)&&(this.interval > 0))
        this.timer = window.setTimeout('updateslideshow(\'' + this.divid + '\')', this.interval);
    else   
        this.timer = null;
  }
  this.load(url, interval, fade, doload);
}
/*------ End slideshow component --------*/
function xmlhttpresponse(ref) {
    var xmlhttp = xmlhttpstack[ref];
    try {
        if (xmlhttp.ajax.readyState == 4) {
            //added regexp to make sure not just whitespace returned - DPJS - 12 Jan 2009
            if (xmlhttp.ajax.status == 200 && /\w/.test(xmlhttp.ajax.responseText)) {
                try {
                    if (xmlhttp.slideshow.fade && !moz &&!nn6) xmlhttp.slideshow.div.filters[0].Apply();  
                } catch (e) {
                    // do nothing
                }
                xmlhttp.slideshow.div.innerHTML = xmlhttp.ajax.responseText;
                try {
                    if (xmlhttp.slideshow.fade && !moz &&!nn6) xmlhttp.slideshow.div.filters[0].Play();
                } catch (e) {
                    // do nothing
                }
            }
    /** Execute script **/
    var x = xmlhttp.slideshow.div.getElementsByTagName("script"); 
    for (var i=0; i<x.length; i++) {
        eval(x[i].text);
    }                
    /** End execute script **/
            xmlhttp.slideshow.start();
            xmlhttpstack[ref] = null;
        }
    } catch (ex) { 
        alert('exception: ' + ex.message);
        xmlhttp.slideshow.timer = null;
    }
  }	


Array.prototype.Add = function (obj, chkexists) {
    if (chkexists)
	for (var r=0; r<this.length; r++) {if (this[r] == obj) return false;}
    this[this.length] = obj;
}

Array.prototype.Remove = function (obj) {
    x = -1;
    for (var r=0; r<this.length; r++) {
	if (this[r] != obj) {
		x++;
		if (x != r) this[x] = this[r];
	}
    }
    if (x <this.length)
	this.length = x+1;
}

/*class Scalable Image*/ 
var TScalableImage = function (id, filename, className) {
    this.id = id;
    this.img = null;
    this.filename = filename;
    this.load = function () {
        if (!this.img)
            this.img = document.getElementById(id);
        var w = this.img.clientWidth;
        this.img.src = '/public/webresize.dll?filename=' + this.filename + '&width=' + w + '&height=1000&constrain=true';
    }
    //-- INIT
    document.write('<img id="' + id + '" class="' + className + '">');
    this.img = document.getElementById(id);
    this.img.src = '/public/images/blank.jpg';
    this.img.onload = function () {
        var l = document.getElementById(this.id + '_load');        
        if (l) {
            l.style.display = 'none';
        }
    }
    TScalableImage.Images.Add(this);    
}
TScalableImage.Images = new Array();

TScalableImage.Refresh = function () {
    for (var i=0; i<TScalableImage.Images.length; i++) {
        TScalableImage.Images[i].load();
    }
}

var timer_resize = null;
window.onresize = function () {
    window.clearTimeout(timer_resize);
    timer_resize = window.setTimeout('TScalableImage.Refresh();', 500);
}

/*
Copyright (c) 2007, Datography! Inc. All rights reserved.
version: 1.0.0.1
*/

//-- System    
tpagemanager = function () {
    //this._dragobject = null;
    this._slider = null;
    this.mousemove = function (evnt) { 
        if (!evnt) evnt = window.event;
        if (this._slider) {
	    	x = this._slider.startOffsetX + evnt.screenX; // Horizontal mouse position relative to allowed slider positions
    	    y = this._slider.startOffsetY + evnt.screenY; // Horizontal mouse position relative to allowed slider positions
    	    if (x <this._slider.min)
    	        x = 0
    	    else if (x > this._slider.max)
    	        x = this._slider.max;
    	        
    	    x = Math.round(x / this._slider.slider.step) * this._slider.slider.step;
    	     
  	        y = 0;	
    	    this.elementleft(this._slider, x);
    	    if (this._slider.slider.doonchange)
    	        this._slider.slider.doonchange();
        }   
    }        
    this.mouseup = function () {
        if (this._slider) {
            this._slider = null;
            document.onmousemove = null;
            document.onmouseup = null;
        }            
    }
    this.elementleft = function (ele, pos) {
        if (!ele.posleft) ele.posleft = 0;
        if (pos) {
            ele.style.left = pos+'px';
            ele.posleft = pos;
        }
        return ele.posleft;
    }
    this.elementtop = function (ele, pos) {
        if (!ele.postop) ele.postop = 0;
        if (pos) {
            ele.style.top = pos+'px';
            ele.postop = pos;
        }
        return ele.postop;
    }   
    this.slide = function (evnt) {
    	if (!evnt) evnt = window.event;
        this._slider = srcElement(evnt);
        this._slider.startOffsetX = this.elementleft(this._slider) - evnt.screenX; 
        this._slider.startOffsetY = this.elementtop(this._slider) - evnt.screenY;
       // document.onmousemove = function (e) { pagemanager.mousemove(e); };
       // document.onmouseup = function (e) { pagemanager.mouseup(e); };
    }
}
pagemanager = new tpagemanager();


//-- Control    
var tslider_orienation = {
    horizontal:0,
    verticle:1
};

tslider = function (ele, dualslider) {
    this._div = ele;
    this._pointers = new Array();
    this.orientation = tslider_orienation.horizontal;
    this.dualslider = dualslider;
    this.min = 0;
    this.max = 100;
    this.step = 1;
this.anytext = 'any';
    //-- Private
    this._addpointer = function (pos) {
        //var p = document.createElement('<div class="slider_point" onmousedown="pagemanager.slide();"></div>');
        // try statement for mozilla fix not supporting <or > in the createElement string - DPJS 01 Feb 2008
        try {
            var p = document.createElement('<div>');
        } catch(e) {
            var p = document.createElement('div');
        }
        p.className = 'slider_point';
        this._div.appendChild(p);
        pagemanager.elementleft(p, pos);
        p.onmousedown = function (e) { pagemanager.slide(e); };
        this._pointers[this._pointers.length] = p; 
        p.min = this.min;           
        p.max = this.max;
        p.slider = this;
    }
    this._settext = function () {
        if (this.textcontrol) {
            var text = '';
            if (this.minvalue == this.maxvalue)
                text = this.displayvalues[this.minvalue];
            else
            if ((this.minvalue == 0)&&(this.maxvalue == this.values.length-1))
                text = this.anytext;
            else
            if (this.minvalue == 0)
                text = 'up to ' + this.displayvalues[this.maxvalue];
            else
            if (this.maxvalue == this.values.length-1)
                text = 'from ' + this.displayvalues[this.minvalue];
            else
                text = this.displayvalues[this.minvalue] + ' - ' + this.displayvalues[this.maxvalue];
            this.textcontrol.innerHTML = text;
        }    
    }
    this.doonchange = function () {
        var newval = 0;
        var newmin = 0;
        var newmax = 0;
        if (this.dualslider) {
            this._pointers[1].min = this._pointers[0].posleft + 12;
            this._pointers[0].max = this._pointers[1].posleft - 12;
            newmin = newval = Math.round(this._pointers[0].posleft / (this.max / (this.values.length-1)));
            newmax = Math.round(this._pointers[1].posleft / (this.max / (this.values.length-1)));
        } else {
            newval = Math.round(this._pointers[0].posleft / (this.max / (this.values.length-1)));
            newmin = newmax = newval;
        }
        if ((newval != this.value)||(newmin != this.minvalue)||(newmax != this.maxvalue)) {
            this.value = newval;
            this.minvalue = newmin;
            this.maxvalue = newmax;
            this._settext();
            if (this.onchange) {
                this.onchange();
            }
        }
    }
    this.IndexOf = function (value) {
        for (i=0; i<this.values.length; i++) {
            if (this.values[i] == value) 
                return i;
        }
        return -1;
    }
    //-- Public
    this.init = function (from, to) {
        var frompos = 0;
        var topos = this.max;
        if (from) {
            i = this.IndexOf(from);
            if (i > 0) 
                frompos = Math.round((i + 0.5) * (this.max / this.values.length));
        }                        
        if (to) {
            i = this.IndexOf(to);
            if (i > 0) 
                topos = Math.round((i + 0.5) * (this.max / this.values.length));
	}                                
        this._addpointer(frompos);
        if (dualslider) {
            this._addpointer(topos);
        }   
        this.doonchange();         
    }
} 
 function displayWarning(msg, icon, clearWarnings) {
    var div = document.getElementById('warnings');
    if (div) {
        if(clearWarnings && div.childNodes[0])
            div.childNodes[0].innerHTML = '';
        var li = document.createElement('div');
        li.innerHTML = '<ul><li>' + ((icon)?'<img src="' + icon + '"> ':'') + msg + '</li></ul>';
        div.appendChild(li);
        div.style.display = 'block';
    }
 }
 
var onloadscript = '';

function TAjax() {
    this.loadinghtml = 'Loading..';  
    this.Request = function (url, target, loadinghtml, append, oncomplete, prepend, dofade) {
	if (target == 'presults') scrollloading = true;
        var dtarget = document.getElementById(target);
	var ltarget = dtarget;
	if (dtarget) {
		if (!dofade) {
	        	ltarget = document.createElement('div');
			ltarget.innerHTML = (loadinghtml||this.loadinghtml);
        		ltarget.backgroundColor = 'silver';
		        if (!append)
        		    dtarget.innerHTML = '';
        		if (!prepend)
		            dtarget.appendChild(ltarget);
		        else
	        	    dtarget.insertBefore(ltarget, dtarget.childNodes[0]);
		}
	} else
	       	ltarget = document.createElement('div');		
        loadpage(url, (oncomplete||updatetarget), 'GET', ltarget, dofade);             
    }
}
var Ajax = new TAjax();

function updatetarget(xmlhttp) {
    scrollloading = false;
    var target = xmlhttp.obj; 
                try {
		    if (xmlhttp.dofade) {
                	    if (!moz &&!nn6) target.filters[0].Apply();  
		    }
                } catch (e) {
                    // do nothing
                }
               
    target.innerHTML = xmlhttp.ajax.responseText;
                try {
		    if (xmlhttp.dofade) {
                	    if (!moz &&!nn6) target.filters[0].Play();
		    }
                } catch (e) {
                    // do nothing
                }
    var x = target.getElementsByTagName("script"); 
    for (var i=0; i<x.length; i++) {
        eval(x[i].text);
    }    
}

function refine() {
	 var params = '&getdata=true';
	 params += '&street=' + document.getElementById('streetarea').value;
	 //-- assign params
	 Ajax.Request('/p.dtx?t=page\\results&f=results.tem' + params, 'presults');
}

function Target(e, div) {
    var element = document.getElementById(div);
	element.innerHTML = 'Loading....';
	loadpage(e.href, updatetarget, 'GET');	
	return false;
}

function setTabActive(e) {
    var parentTr = e.parentNode.parentNode;
    var cells = parentTr.cells;
    for (var i = 0; i <cells.length; i++) {
        cells[i].className = '';
    }
    e.parentNode.className = 'active';
    if (rMap) rMap.clear();
}


var active_img = null;
function switchimage(img) {
    if (active_img != img) {
	    if (active_img)
		    active_img.style.borderColor = '#333333';
	    active_img = img;
	    active_img.style.borderColor = '';
	    document.getElementById('img_main').src = active_img.src.replace('&height=63&width=100','&height=300&width=400');
    }
}





N = (document.all) ? 0 : 1;
var ob;
var lx;
var ly;
function MD(e) {
if (N) {
	//ob = e.target;//document.layers[e.target.name];
	//X=e.x;
	//Y=e.y;
	//return false;
}
else {
	if (event.srcElement.className == 'dragable') {
		ob = event.srcElement;
		if(!ob.style.pixelLeft) {
			ob.style.pixelLeft = 0;
			ob.style.pixelTop = 0;
		}
		lx=event.clientX;
		ly=event.clientY;
	   }
	   }
}




function MM(e) {

if (ob) {
if (N) {
ob.style.moveTo((e.pageX-X), (e.pageY-Y));
}
else {
var l = ob.style.pixelLeft + (event.clientX - lx);
var t = ob.style.pixelTop + (event.clientY - ly);
if (((l + ob.width) > 50)&&((t + ob.height) > 50) && (l <450) && (t <500)) {
    ob.style.pixelLeft = l;
    ob.style.pixelTop = t;
    lx = event.clientX;
    ly = event.clientY;
    if (intfloorplan) intfloorplan.invalidate();  
}
 return false;
      }
   }
}
function MU() {
ob = null;
}

if (N) {
    document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
}

function rollOver(itemid, preload){
    var mainImg = document.getElementById('mainImg');
    if (mainImg) {
        mainImg = mainImg.src;
    var str = mainImg.substring(0, mainImg.indexOf('filename=')+9) + itemid + mainImg.substring(mainImg.indexOf('.jpg'), 1000);
    if(preload)
        return str;
    document.getElementById('mainImg').src = str;
    
    var allImg = document.getElementById('list_0');
    var x = allImg.getElementsByTagName('img');
   
    for(i=0; i <x.length; i++){
		document.getElementById(x[i].id).className = 'nonactiveimg';
    }
    
    document.getElementById(itemid).className = 'activeImg';
}
}

var iA = new Array();
var pA = new Array();		

function preloadNavigationImages() {
    for (var i = 0; i <pA.length; i++) {
        iA[i] = new Image();
        iA[i].src = pA[i];
    }
}
function raiseTab(e, div) {
    var parentE = e.parentNode.parentNode;
    var divs = parentE.getElementsByTagName('DIV');
    for (var i = 0;i <divs.length;i++) {
        if (i == 0)
            divs[i].className = 'first';
        else 
            divs[i].className = '';
    }
    if (e.parentNode==divs[0])
        e.parentNode.className = ' first active';
    else
        e.parentNode.className = 'active';
    if (div) {
        document.getElementById(activeForm).style.display = 'none';
        activeForm = div;
        document.getElementById(activeForm).style.display = 'block';
    }
}
Ajax.loadinghtml = '<div style="text-align:center;padding-top:50px;color:params.darkhighlight;vertical-align:top;">Loading<br/><br/><img src="http://lemon.datography.com/public/files/00000000-2008-0000-0000-000000000000/client_files/lemon-datography-com/img/ajax-loader.gif" style="margin:0px auto 0px auto;" /></div>';


var g_minpage = 0;
var g_maxpage = 0;

function initpaging(page, pages, recs) {
	if (recs || recs == 0) {
		var rc = document.getElementById('reccount');
		if (rc)
			rc.innerHTML = recs;
	}
	var sel = document.getElementById('paging_select');
	if (sel) {
	var oOption = null;
	if (sel.options.length > pages) {
		sel.options.length = pages;
	} else {
		for (var i=sel.options.length+1; i<=pages; i++) {
			oOption = document.createElement("OPTION");
			sel.options.add(oOption);
			oOption.text = i;
			oOption.value = i;
		}
	}
	document.getElementById('paging_pages').innerHTML = pages;
	document.getElementById('paging_back').style.visibility = (page == 1?'hidden':'visible');
	document.getElementById('paging_next').style.visibility = (page == pages?'hidden':'visible');
	if (document.getElementById('paging2')) {
		document.getElementById('paging2_back').style.visibility = (page == 1?'hidden':'visible');
		document.getElementById('paging2_next').style.visibility = (page == pages?'hidden':'visible');
	}
	if (g_minpage == 0) g_minpage = page;
	if (g_maxpage == 0) g_maxpage = page;

	sel.value = page;
	}
}

function changeresultview(url) {
	//-- Reset the paging
	g_minpage = 0
	g_maxpage = 0;
	Ajax.Request(url, 'presults');	
}


function changepage(inc, dofade) {
//changes location.hash. jquery/main.js has a listener that will pick up the change and call changepagefromhash
	
	var sel = document.getElementById('paging_select'); 
	if (inc)
		{
		inc = parseInt(sel.value) + inc;
		}
	else
		{
		inc = sel.value;
		}
		
	
	location.hash="page=" + inc;
}

function changepagefromhash(inc, dofade) {
//This function contains the Ajax call to change the results page
	
	var pages = parseInt(innerText(document.getElementById('paging_pages')));
	if (inc > pages)
		inc = 1;
	if (inc <1) inc = 1;		

	if (rMap) rMap.clear();
	g_minpage = inc;
	g_maxpage = inc;
	if (!dofade) {
		if (document.documentElement)
		    document.documentElement.scrollTop = 0;
		else
            document.body.scrollTop = 0;
		}
	
	//get the queryfield variables (url from '?' to '#')
	var queryfieldvars = location.href.substring((location.href.indexOf("?")+1),location.href.indexOf("#"));
	
	//remove getdata=true
	queryfieldvars = queryfieldvars.replace("getdata=true&", "");
	
	//The page value is still kept in the query field (though will be overidden in the hash) for legacy reason, this may not be nessesary
	Ajax.Request('/p.dtx?t=page\\results&f=results.tem&page=' + inc + "&" + queryfieldvars, 'presults', null, false, scrollcomplete, false, dofade);
}


  var scrollloading = false; 
  function scrollcomplete (xmlhttp) {
    scrollloading = false;
    updatetarget(xmlhttp);
  }
  function scrollcomplete1 (xmlhttp) {
    scrollloading = false;
    updatetarget(xmlhttp);
    if(parseInt(document.getElementById('pitems').clientHeight)>0)
	    document.getElementById('presults').scrollTop = document.getElementById('pitems').clientHeight-105;
    else
	    document.getElementById('presults').scrollTop = 1;
  }
  function scrollpage(e) {
    if (!scrollloading) {
      var el = srcElement(e);
	var rows = parseInt(g_maxpage)-parseInt(g_minpage)+1;
	var rowheight = parseInt(el.scrollHeight)/rows;
	document.getElementById('paging_select').value = Math.floor(parseInt(el.scrollTop) / rowheight)+parseInt(g_minpage);
      if ((el.scrollTop + el.clientHeight) >= (el.scrollHeight)) {
		var page = parseInt(g_maxpage) + 1;
		var pages = document.getElementById('paging_pages').innerHTML;
		if (page <= pages) {
	            g_maxpage = parseInt(page);
	            scrollloading = true;
		    Ajax.Request('/p.dtx?t=page\\results&f=results.tem&page=' + page, 'presults', null, true, scrollcomplete);
		}
      } else if (el.scrollTop <= 0) {
		var page = parseInt(g_minpage) - 1;
		if (page > 0) {
  		    g_minpage = parseInt(page);
	            scrollloading = true;
		    Ajax.Request('/p.dtx?t=page\\results&f=results.tem&page=' + page, 'presults', null, true, scrollcomplete1, true);
		}
      }
    }
  }
  var active_hl = null;
  var active_pin = null;
  var rMap = null;
  function highlightcurrent(e, x, y, index) {
    if (active_hl != e) {
      if (active_hl) {
        RemoveClass(active_hl, 'row_highlight');
      }
      active_hl = e
      AddClass(active_hl, 'row_highlight');
      if (rMap) {
        if (active_pin != null) rMap.switchpin(active_pin, 'result');
        if (x != ''){
            if(rMap._map) {
	            var cz = null;
	            if (x) {
	                cz = new Object();
		cz.x = x;
		cz.y = y;
			    }
                rMap.switchpin(index, 'active', cz);
                active_pin = index;
            }
        } else 
            active_pin=null;
      } 
    }
  }


function validateEmail(emailStr, e) {
    if (/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/.test(emailStr)) {
        if (e)
            e.href = 'http://lemon.datography.com/inlinelogin.dtx?req=pwd&email=' + document.getElementById('LoginUserName').value
        return true;
    }
    displayWarning('Please enter a valid username', 'http://lemon.datography.com/public/files/00000000-2008-0000-0000-000000000000/client_files/00000000-0000-0000-0000-000000000000/img/warning.png', true);
    return false;
}  
function checkForm(){
    var err = '';

    if (document.salesForm.first_name.value=='')
      err += 'First name cannot be blank\n';

    if (document.salesForm.last_name.value == '')
      err += 'Last name cannot be blank\n';

    if (!/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/.test(document.salesForm.email.value))
      err += 'Email must be a valid email address\n';

    if (document.salesForm.phone.value == '')
      err += 'Telephone cannot be blank\n';

    if (err == '') {
      setArea();
      return true;
    } else {
      alert(err);
      return false;
    }
}
function showvideo() {
	document.getElementById('divVideo').style.display = (document.getElementById('divVideo').style.display == 'block'?'none':'block');	
}
 function checkEmail(choice) {
    document.getElementById('contact').value = choice;
    var err = false;

    if(choice == 'sendemail'){   
        if(!/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/.test(document.getElementById('email').value)) {
            document.getElementById('emailerror').innerHTML = ' * invalid email address';
            err = true;
        } else
            document.getElementById('emailerror').innerHTML = '';
          
        if(!/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/.test(document.getElementById('femail').value)) {
            document.getElementById('femailerror').innerHTML = ' * invalid email address';
            err = true;
        } else
            document.getElementById('femailerror').innerHTML = '';
    } else {
        if(document.getElementById('pnumber').value == '') {
            document.getElementById('phoneerror').innerHTML = ' * enter a number';
            err = true;
        } else
            document.getElementById('phoneerror').innerHTML = '';
    }
    if(err)
        return false;
    else
        return true;
}
function validateForm() {
	var err = '';
	if (document.regform._DSLastName.value=='')
		err += 'Last name cannot be blank\n';
	if (!/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/.test(document.regform._DSEmailAddress.value))
		err += 'Email must be a valid email address\n';
	if (document.regform._DSLoginPassword.value == '' || document.regform.ConfPassword.value == '')
		err += 'Password cannot be blank\n';
	if (document.regform._DSTelephone.value == '')
		err += 'Telephone cannot be blank\n';
	if (document.regform._DSLoginPassword.value != document.regform.ConfPassword.value)
		err += 'Password and Confirmation Password do not match';
	if (err == '') {
		
		
		
		document.forms['regform'].submit();
	} else
		alert(err);
	return false;
}
var intfloorplan = null;
function tfloorplan (id, xml) {
	this.fp = null;
  this.id = id;
  this.lastimage = null;
	this.images = new Array();
  this._zoom = 1;
  this.scaling = true;
	this.showimage = function (id) {
    if (id != this.lastimage) {
		document.getElementById('iimage').src = '/webresize.aspx?filename=' + id + '.jpg&width=300&height=1000&constrain=true';
      this.lastimage = id;
    }
	}
	this.add = function (img) {
		var ratio = (this.fp.width / 400);		
		if (parseInt(img.x)) {
			var image = new Object();
			image.id = img.guid;
			image.x = img.x;
			image.y = img.y;
		
		
			image.img = document.createElement('img');
			image.img.src = 'http://lemon.datography.com/public/files/00000000-2008-0000-0000-000000000000/client_files/00000000-0000-0000-0000-000000000000/img/camera.png';
			image.img.className = 'iplan_pin';
			image.img.style.left = this.fp.style.pixelLeft + (image.x * ratio) + 'px';
			image.img.style.top = this.fp.style.pixelTop + (image.y * ratio) + 'px';
			eval('image.img.onmouseover = function () { intfloorplan.showimage("' + image.id + '"); }');
			this.fp.parentElement.appendChild(image.img);	

			this.images.push(image);
			if (this.images.length == 1) 
				this.showimage(image.id);
		}
	}
	this.invalidate = function () {
		var ratio = (this.fp.width / 400);
		for (var i=0; i<this.images.length; i++) {
			this.images[i].img.style.left = this.fp.style.pixelLeft + (this.images[i].x * ratio) + 'px';
			this.images[i].img.style.top = this.fp.style.pixelTop + (this.images[i].y * ratio) + 'px';
		}		
	}
  this.zoom = function (inc) {
    var nz = this._zoom + inc;
    if ((nz >= 0)&&(nz <= 8)) {
        this._zoom = nz;    
        //this.fp.style.pixelLeft = this.fp.style.pixelLeft + ((this.fp.width - (400 + (this._zoom * 100))) / 2);
        this.fp.width = 400 + (this._zoom * 100);
        this.fp.src = '/webresize.aspx?filename=' + this.id + '.gif&height=2000&width=' + this.fp.width + '&constrain=true';		
		    this.invalidate();
    }
                                        
  }                                        
	this.scale = function (e) {
    if (this.scaling) {
    if (e.wheelDelta > 0)
        this.zoom(+1);      
    else
    if (e.wheelDelta <0)
        this.zoom(-1);      
  		
		  this.invalidate();
    }
	}	
	this.fp = document.getElementById('ifloorplan');
  this.fp.ondblclick = function () {
      intfloorplan.zoom(+2);
  }
	var myJsonObject = xml2json.parser(xml);
	var i = 0;
    do {	
		i++;
		img = eval('myJsonObject.image' + i);
		if (img) {	
			this.add(img);
		}
	} while (img);	
	this.invalidate();	
}

function initfp(id, xml) {
	intfloorplan = new tfloorplan(id, xml);
}
function OnAddToFavoritesComplete() {
    updatePortfolio(ATF_Params.propertyid,false,ATF_Params.element,ATF_Params.index);
}

function DoAddToFavorites(PropertyId, Index, ev) {
    ATF_Params.propertyid = PropertyId;
    ATF_Params.index = Index;
    ATF_Params.element = (ev.srcElement||ev.target);
    showLogin('http://lemon.datography.com/p.dtx?c=login', ATF_Params.element, 'False', false, OnAddToFavoritesComplete);
}
    



function updatePortfolio(propertyid,remit,e,index) {
	if (!updateInProgess) {
		updateInProgess = true;
		e.blur();
		e.innerHTML = imgstring + '&nbsp;Please&nbsp;wait...';
		e.style.textDecoration = 'none';
document.getElementById('portfolioIframe').src='addtoportfolio.dtx?propertyid=' + propertyid + '&remove=' + remit + '&index=' + index;
		activeButton = e;
	}
}



function portfolioUpdated(remove, updateAll) {
	if (!updateAll) {
		if (activeButton) {
			if (remove)
				activeButton.innerHTML = imgstring + '<span>&nbsp;Removed&nbsp;from&nbsp;saved properties&nbsp;</span>';
			else
				activeButton.innerHTML = imgstring + '<span>&nbsp;Added&nbsp;to&nbsp;saved properties&nbsp;</span>';
      activeButton.onclick = '';
		}
	} else {
		activeButton.innerHTML = 'Portfolio emptied';
		var obj = document.getElementsByTagName('A');
		for (var i = 0; i <obj.length; i++) {
			if (obj[i].className == 'pinkbutton') {
				obj[i].disabled = true;
				obj[i].parentElement.innerHTML=imgstring+'<span>Removed&nbsp;from&nbsp;saved properties</span>';
			}
		}
	}
	updateInProgess = false;
	activeButton = '';
}
function AddCircle(latin, lonin, radius, gmap) 
{ 
    if (gmap) {
    var locs = new Array(); 
    var x; 
    var center = new GLatLng(latin, lonin);
    var latConv = center.distanceFrom(new GLatLng(center.lat()+0.1, center.lng()))/100;
    var lngConv = center.distanceFrom(new GLatLng(center.lat(), center.lng()+0.1))/100;
    for (x = 0; x <= 360; x+=10) // 36 points per circle 
    { 
	var pint = new GLatLng(center.lat() + (radius/latConv * Math.cos(x * Math.PI/180)), center.lng() + (radius/lngConv * Math.sin(x * Math.PI/180)));
	locs.push(pint);
	//bounds.extend(pint); //this is for fit function
    } 
    locs.push(locs[0]); 
    var poly = new GPolygon(locs, "#0000ff", 2, 0.5, "#0055ff", 0.1, {clickable:false});
    return poly; 
    } else {
    var locs = new Array(); 
    var lat1 = latin * Math.PI/180.0; 
    var lon1 = lonin * Math.PI/180.0; 
    var d = radius/3956; 
    var x; 
    for (x = 0; x <= 360; x+=10) // 36 points per circle 
    { 
        var tc = (x / 90)* Math.PI / 2; 
        var lat = Math.asin(Math.sin(lat1)*Math.cos(d)+Math.cos(lat1)*Math.sin(d)*Math.cos(tc)); 
        lat = 180.0 * lat / Math.PI; 
        var lon; 
         if (Math.cos(lat1)==0) 
        { 
            lon=lonin; // endpoint a pole 
        } 
        else 
        { 
            lon = ((lon1 - Math.asin(Math.sin(tc) * Math.sin(d)/Math.cos(lat1)) + Math.PI) % (2 * Math.PI)) - Math.PI; 
        } 
        lon = 180.0 * lon / Math.PI; 
        var loc = (gmap?new GLatLng(lat,lon):new VELatLong(lat,lon)); 
        locs.push(loc); 
    } 
    var poly = new VEPolyline(999, locs, new VEColor(0,0,255,.8), 2); 
    return poly;
    }
}


  function CalcRange() {
    var d = parseInt(document.getElementById('pdeposit').value);
    var m = parseInt(document.getElementById('pmort').value) * 12;
    var r = parseInt(document.getElementById('prate').value);
    
    m = ((m - (m / 100 * 5)) * 25) + d;

    if ((d > 0)&&(m > 0)) {
        f = m - (m * 0.02);
        t = m * 1.02;
        document.getElementById('pfrom').value = f;
        document.getElementById('pto').value = t;
        document.getElementById('_DSminprice').value = f;
        document.getElementById('_DSmaxprice').value = t;
    }
  }
  	function setkeyword(group, keyword, remove){
		e = document.getElementById(group);			
		v = e.value.split(',');
		r = '';
		for (i=0; i<v.length; i++) {
			if (v[i] != keyword) r += (r == ''?'':',') + v[i];
		}					
		if (!remove) r += (r == ''?'':',') + keyword;
		e.value = r;
		document.getElementById('frmcriteria').submit();
	}
function doAddrlistCollapse(ev) {
    try {
    var e = (event.srcElement||ev.target);
    var element = document.getElementById('addrlist');
    try {
        while (e != element && e.nodeName != 'HTML') {
            if (e==element)
                return;
            e=e.parentNode;
        }
    } catch (e) {
        //silent exception
    }
    if (e.nodeName == 'HTML')
        element.style.display = 'none';
    } catch (e) {
	//silent exception
    }
}


if(!Array.prototype.push){
	Array.prototype.push=function(x){
		this[this.length]=x;
		return true
	}
};

if (!Array.prototype.pop){
	Array.prototype.pop=function(){
  		var response = this[this.length-1];
  		this.length--;
  		return response
	}
};

xml2json={
	parser:function(xmlcode,ignoretags,debug){
		if(!ignoretags){ignoretags=""};
		xmlcode=xmlcode.replace(/\s*\/>/g,'/>');
		xmlcode=xmlcode.replace(/<\?[^>]*>/g,"").replace(/<\![^>]*>/g,"");
		if (!ignoretags.sort){ignoretags=ignoretags.split(",")};
		var x=this.no_fast_endings(xmlcode);
		x=this.attris_to_tags(x);
		x=escape(x);
		x=x.split("%3C").join("<").split("%3E").join(">").split("%3D").join("=").split("%22").join("\"");
		for (var i=0;i<ignoretags.length;i++){
			x=x.replace(new RegExp("<"+ignoretags[i]+">","g"),"*$**"+ignoretags[i]+"**$*");
			x=x.replace(new RegExp("</"+ignoretags[i]+">","g"),"*$***"+ignoretags[i]+"**$*")
		};
		x='<JSONTAGWRAPPER>'+x+'</JSONTAGWRAPPER>';
		this.xmlobject={};
		var y=this.xml_to_object(x).jsontagwrapper;
		if(debug){y=this.show_json_structure(y,debug)};
		return y
	},
	xml_to_object:function(xmlcode){
		var x=xmlcode.replace(/<\//g,"§");
		x=x.split("<");
		var y=[];
		var level=0;
		var opentags=[];
		for (var i=1;i<x.length;i++){
			var tagname=x[i].split(">")[0];
			opentags.push(tagname);
			level++
			y.push(level+"<"+x[i].split("§")[0]);
			while(x[i].indexOf("§"+opentags[opentags.length-1]+">")>=0){level--;opentags.pop()}
		};
		var oldniva=-1;
		var objname="this.xmlobject";
		for (var i=0;i<y.length;i++){
			var preeval="";
			var niva=y[i].split("<")[0];
			var tagnamn=y[i].split("<")[1].split(">")[0];
			tagnamn=tagnamn.toLowerCase();
			var rest=y[i].split(">")[1];
			if(niva<=oldniva){
				var tabort=oldniva-niva+1;
				for (var j=0;j<tabort;j++){objname=objname.substring(0,objname.lastIndexOf("."))}
			};
			objname+="."+tagnamn;
			var pobject=objname.substring(0,objname.lastIndexOf("."));
			if (eval("typeof "+pobject) != "object"){preeval+=pobject+"={value:"+pobject+"};\n"};
			var objlast=objname.substring(objname.lastIndexOf(".")+1);
			var already=false;
			for (k in eval(pobject)){if(k==objlast){already=true}};
			var onlywhites=true;
			for(var s=0;s<rest.length;s+=3){
				if(rest.charAt(s)!="%"){onlywhites=false}
			};
			if (rest!="" && !onlywhites){
				if(rest/1!=rest){
					rest="'"+rest.replace(/\'/g,"\\'")+"'";
					rest=rest.replace(/\*\$\*\*\*/g,"</");
					rest=rest.replace(/\*\$\*\*/g,"<");
					rest=rest.replace(/\*\*\$\*/g,">")
				}
			} 
			else {rest="{}"};
			if(rest.charAt(0)=="'"){rest='unescape('+rest+')'};
			if (already && !eval(objname+".sort")){preeval+=objname+"=["+objname+"];\n"};
			var before="=";after="";
			if (already){before=".push(";after=")"};
			var toeval=preeval+objname+before+rest+after;
			eval(toeval);
			if(eval(objname+".sort")){objname+="["+eval(objname+".length-1")+"]"};
			oldniva=niva
		};
		return this.xmlobject
	},
	show_json_structure:function(obj,debug,l){
		var x='';
		if (obj.sort){x+="[\n"} else {x+="{\n"};
		for (var i in obj){
			if (!obj.sort){x+=i+":"};
			if (typeof obj[i] == "object"){
				x+=this.show_json_structure(obj[i],false,1)
			}
			else {
				if(typeof obj[i]=="function"){
					var v=obj[i]+"";
					//v=v.replace(/\t/g,"");
					x+=v
				}
				else if(typeof obj[i]!="string"){x+=obj[i]+",\n"}
				else {x+="'"+obj[i].replace(/\'/g,"\\'").replace(/\n/g,"\\n").replace(/\t/g,"\\t").replace(/\r/g,"\\r")+"',\n"}
			}
		};
		if (obj.sort){x+="],\n"} else {x+="},\n"};
		if (!l){
			x=x.substring(0,x.lastIndexOf(","));
			x=x.replace(new RegExp(",\n}","g"),"\n}");
			x=x.replace(new RegExp(",\n]","g"),"\n]");
			var y=x.split("\n");x="";
			var lvl=0;
			for (var i=0;i<y.length;i++){
				if(y[i].indexOf("}")>=0 || y[i].indexOf("]")>=0){lvl--};
				tabs="";for(var j=0;j<lvl;j++){tabs+="\t"};
				x+=tabs+y[i]+"\n";
				if(y[i].indexOf("{")>=0 || y[i].indexOf("[")>=0){lvl++}
			};
			if(debug=="html"){
				x=x.replace(/</g,"&lt;").replace(/>/g,"&gt;");
				x=x.replace(/\n/g,"<BR/>").replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;")
			};
			if (debug=="compact"){x=x.replace(/\n/g,"").replace(/\t/g,"")}
		};
		return x
	},
	no_fast_endings:function(x){
		x=x.split("/>");
		for (var i=1;i<x.length;i++){
			var t=x[i-1].substring(x[i-1].lastIndexOf("<")+1).split(" ")[0];
			x[i]="></"+t+">"+x[i]
		}	;
		x=x.join("");
		return x
	},
	attris_to_tags: function(x){
		var d=' ="\''.split("");
		x=x.split(">");
		for (var i=0;i<x.length;i++){
			var temp=x[i].split("<");
			for (var r=0;r<4;r++){temp[0]=temp[0].replace(new RegExp(d[r],"g"),"_jsonconvtemp"+r+"_")};
			if(temp[1]){
				temp[1]=temp[1].replace(/'/g,'"');
				temp[1]=temp[1].split('"');
				for (var j=1;j<temp[1].length;j+=2){
					for (var r=0;r<4;r++){temp[1][j]=temp[1][j].replace(new RegExp(d[r],"g"),"_jsonconvtemp"+r+"_")}
				};
				temp[1]=temp[1].join('"')
			};
			x[i]=temp.join("<")
		};
		x=x.join(">");
		x=x.replace(/ ([^=]*)=([^ |>]*)/g,"><$1>$2</$1");
		x=x.replace(/>"/g,">").replace(/"</g,"<");
		for (var r=0;r<4;r++){x=x.replace(new RegExp("_jsonconvtemp"+r+"_","g"),d[r])}	;
		return x
	}
};


if(!Array.prototype.push){
	Array.prototype.push=function(x){
		this[this.length]=x;
		return true
	}
};

if (!Array.prototype.pop){
	Array.prototype.pop=function(){
  		var response = this[this.length-1];
  		this.length--;
  		return response
	}
};



function domapclick(a, b) {
	globalmap.doonclick(a, b);
}
function domapout(a, b) {
	globalmap.doonmouseout(a, b);		
}
function domapover(a, b) {
	if (a.elementID != null) {
		globalmap.doonmouseover(a, b);		
	}	
}

var _pinwidth = '20px';
var _pinheight = '20px';

var globalmap = null;
function TMap(divid, googlemaps) {
		globalmap = this;
		this.divid = divid;
		this._googlemaps = (GMap2);
		this._pins = new Array();
		this._coords = new Array();
		//this._shapes = new Array();
		this._loaded = false;
		this._map = null;
		this.autozoom = true;
		this.showhint = false;
		this.pinwidth = _pinwidth;
		this.pinheight = _pinheight;
		/* Events */
		this.hovertime = 1000;
		this.onclick = null;
		this.onclickpin = null;
		this.onhoverpin = null;
		this.addpin = function (lon, lat, title, index, state, description, objectid) {
			var pin = this.getpin(index);
			if (pin) return pin;
			var pin = new Object();
			pin.lon = lon;
			pin.lat = lat;
			pin.title = title;
			pin.description = description;
			pin.index = index;
			pin.state = (state?state:'result');
			pin.objectid = objectid;
			pin.propertyid = objectid;
			this._pins.push(pin);
			if (this._map) {
				this.showpin(pin);
			}
			return pin;
		}
		if (this._googlemaps) {
			this.latlng = new Array();
			this.latlngbounds = new GLatLngBounds();
		}
		this.removepin = function (pin) {
		    if (this._googlemaps)
		        this._map.removeOverlay(pin._shape);
		    else   
		        this._map.DeleteShape(pin._shape);
		    this._pins.Remove(pin);		    
		}
		this.removepinsbyid = function (ids) {
		    var pin = null;
		    for (var p=0; p<ids.length; p++) {
			pin = this.getpin(ids[p]);
			if (pin) 
			        this.removepin(pin);
		    }
		}
		this.removepins = function (pins) {
		    for (var p=0; p<pins.length; p++) {
		        this.removepin(pins[p]);
		    }
		}
		this.doonmouseout = function (a, b) {
			window.clearTimeout(this._hovertimer);	
		}
		this.doonmouseover = function (a,b) {
			if (this.onhoverpin) {
			 if (!this._googlemaps) {
			    var shape = this._map.GetShapeByID(a.elementID);
			    if (shape) {
			        active_pin = shape._index;
				this._hovertimer = window.setTimeout(function () {globalmap.dohoverpin();}, this.hovertime);
			    }
			 }
			}
		}
		this.dohoverpin = function () {
			if (this.onhoverpin) {
				this.onhoverpin(this.getpin(active_pin));
			}
		}
		this.doonclick = function (a,b) {
      		        var shape = null;
	    		if (!this._googlemaps) {
			    var shape = this._map.GetShapeByID(a.elementID);
			    if (shape) {
        		        if (active_pin != null) this.switchpin(active_pin, 'result');
				this.clickpin(shape._index);    
			        active_pin = shape._index;
			    }
			}

			if(this.onclick) {
				var lat = null;	var lng = null;
				if (this._googlemaps) {
					if (!b)
						return false;
					lat = b.lat();
					lng = b.lng();
				} else {
					var LL = this._map.PixelToLatLong(new VEPixel(a.mapX, a.mapY));	
					lat = LL.Latitude;
					lng = LL.Longitude;
				}
				this.onclick(lat,lng, shape);
			}
		}
		this.getpin = function (index) {
			    var pin = null;
		    for (var p=0; p<this._pins.length; p++) {
			    if (this._pins[p].index == index) {
				    pin = this._pins[p];
				    break;
			  }
	        	}		
			return pin;
		}
		this.clickpin = function (index) {
			if (this.onclickpin) {
				this.onclickpin(this.getpin(index));
			} else {
				var pin = this.switchpin(index, 'active');
				if (pin.objectid) {
					showmedia(event, pin.objectid, 'jpg', pin.index);
				}
			}
		}
		this.switchpin = function (index, state, centerzoom, highlightrow) {
		    var pin = this.getpin(index);
	        if (pin) {
		        if (this._googlemaps) {
					if (this._activeshape) {
						this._map.removeOverlay(this._activeshape);
					}
					this._activeshape = new GMarker(pin._coord, this._activeicon);	
					this._map.addOverlay(this._activeshape);

					if (centerzoom) {
				        this._map.setCenter(pin._coord);
				        this._map.setZoom(15);		
			        }
		        } else {
			        if (state=='active') {
			            outputImg = 'http://lemon.datography.com/public/files/00000000-2008-0000-0000-000000000000/client_files/00000000-0000-0000-0000-000000000000/img/pin_active.png';
			            zIndex = 1001;
			        } else {
			            outputImg = 'http://lemon.datography.com/public/files/00000000-2008-0000-0000-000000000000/client_files/00000000-0000-0000-0000-000000000000/img/pin_result.png'.replace('pin_result', 'pin_' + pin.state);
			            zIndex = 1000;
            		}
			        var pinObj = '<div id="plotted' + index + '" style="width:' + this.pinwidth + ';height:' + this.pinheight+ ';';
			        if (/MSIE (5\.5|6\.)/.test(navigator.userAgent))
			            pinObj += ';filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + outputImg + '\', sizingMethod=\'scale\');';
			        else
			            pinObj += ';background-image:url(\'' + outputImg + '\');';
			        pinObj += 'text-align:center;padding-top:0px;"></div>';
                        //if (this._shapes[index]) {
  			                pin._shape.SetCustomIcon(pinObj);
    			            pin._shape.SetZIndex(zIndex);
    			        // }
			        if (centerzoom) {	
				        this._map.SetCenterAndZoom(new VELatLong(centerzoom.x, centerzoom.y), this._map.GetZoomLevel());
			        }
		        }
		    }
		    return pin;
		}
		this.showpin = function (pin) {
		//This function places the pin on the map and adds InfoWindows
			if (this._googlemaps) {
			//Add a marker to Googlemaps
			    var coords = new GLatLng(pin.lat,pin.lon);
			    var shape = new GMarker(coords);
			    shape._index = pin.index;
			    pin._shape = shape;
			    pin._coord = coords;
			    this._coords.push(coords);
				

				
				//Add listener for the Click event
			    GEvent.addListener(shape, "click", function() {
				       globalmap.clickpin(this._index);
			            });

			    //if (!document.getElementById('plotted'+pin.index)) {
				    this._map.addOverlay(shape);			
				    //while (this._shapes.length <pin.index) this._shapes[this._shapes.length] = null;
				    //this._shapes[pin.index] = shape;
			    //}
				
				if (this.autozoom) {
			    if (this._pins.length > 0) {
					for (var p=0; p<this._pins.length; p++) {
						this.latlng[p] = new GLatLng(this._pins[p].lat, this._pins[p].lon);
						this.latlngbounds.extend(this.latlng[p]);
					}
					this._map.setCenter(this.latlngbounds.getCenter(), this._map.getBoundsZoomLevel(this.latlngbounds));
				} else
	       			this._map.setCenter(coords);
			    }
			} else {
			//Place the pin on a BING map
			    //var coords = new VELatLong(pin.lat,pin.lon);
			    //var shape = new VEShape(VEShapeType.Pushpin, coords);
    			
			    //this._coords.push(coords);	
			    var outputImg;
//			    if (pin.state=='result')
			        outputImg = 'http://lemon.datography.com/public/files/00000000-2008-0000-0000-000000000000/client_files/00000000-0000-0000-0000-000000000000/img/pin_result.png'.replace('pin_result', 'pin_' + pin.state);
			    //else
			      //  outputImg = 'http://lemon.datography.com/public/files/00000000-2008-0000-0000-000000000000/client_files/00000000-0000-0000-0000-000000000000/img/pin_all.png';
			    var pinObj = '<div id="plotted' + pin.index + '" style="width:' + this.pinwidth + ';height:' + this.pinheight+ ';';
			    if (/MSIE (5\.5|6\.)/.test(navigator.userAgent))
			        pinObj += 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + outputImg + '\', sizingMethod=\'scale\');';
			    else
			        pinObj += 'background-image:url(\'' + outputImg + '\');'
			    pinObj += 'text-align:center;padding-top:0px;"></div>';
			    if (!document.getElementById('plotted'+pin.index)) {
				    var coords = new VELatLong(pin.lat,pin.lon);
				    var shape = new VEShape(VEShapeType.Pushpin, coords);
                    shape._index = pin.index;                				
				    pin._shape = shape;
				    pin._coord = coords;
				    this._coords.push(coords);

				    shape.SetCustomIcon(pinObj);
				    //while (this._shapes.length <pin.index) this._shapes[this._shapes.length] = null;
				    //this._shapes[pin.index] = shape;
				    this._map.ClearInfoBoxStyles();
				    if ((this.showhint)&&(pin.title)) {
  				      shape.SetTitle(pin.title);
				      if (pin.description)
					     shape.SetDescription(pin.description);
				    }
				    this._map.AddShape(shape);
				    if (this.autozoom) {
				    if (this._coords.length <= 1) {
					    this._map.SetCenterAndZoom(coords, 15);
				    } else {
					    this._map.SetMapView(this._coords);
					    if (this._map.GetZoomLevel() > 15) {
					        this._map.SetZoomLevel(15);   
					    }
				    }
				    }
			    }	
			}		
		}
		this.clear = function () {
		//Clears all the pins from the map
		    active_hl = active_pin = null;
			this._pins = new Array();
			this._coords = new Array();
			//this._shapes = new Array();
			if (this._map) {
				if (this._googlemaps) {
					this._map.clearOverlays();		
				} else {
					this._map.Clear();
				}
			}
		}
		this._radial = null;
		this.showradial = function (lat, lng, radius) {
			if (this._googlemaps) {
				if (this._radial) this._map.removeOverlay(this._radial);
				this._radial = AddCircle(lat, lng, radius, true);	
				this._map.addOverlay(this._radial);
        		} else {
          			if (this._radial) {
            				sMap._map.DeletePolyline(999);
          			}
				this._radial = AddCircle(lat, lng, radius, false);
          			this._map.AddPolyline(this._radial);
			}			
		}
		this.showdirections = function (from, to, callback) {
			if (this._googlemaps) {
			} else {
			        var locations = new Array(from, to);
			        var options = new VERouteOptions();
			        options.RouteCallback = callback;
        			options.RouteOptimize = VERouteOptimize.MinimizeDistance;
			        this._map.GetDirections(locations, options);	
			}
		}
		this.loadmap = function (lat, lng, scale, dashboardsize) {
			if (!this._loaded) {
			if (this._googlemaps) {
				this._activeicon = new GIcon();
				this._activeicon.image = 'http://lemon.datography.com/public/files/00000000-2008-0000-0000-000000000000/client_files/00000000-0000-0000-0000-000000000000/img/gmap_active.png';
				this._activeicon.shadow = 'http://lemon.datography.com/public/files/00000000-2008-0000-0000-000000000000/client_files/00000000-0000-0000-0000-000000000000/img/gmap_active.png';
				this._activeicon.iconSize = new GSize(24, 38);
				this._activeicon.shadowSize = new GSize(24, 38);
				this._activeicon.iconAnchor = new GPoint(12, 38);
				this._activeicon.infoWindowAnchor = new GPoint(1, 1);

				this._map = new GMap2(document.getElementById(this.divid));
				this._map.enableScrollWheelZoom();
				this._map.addControl(new GSmallMapControl());

				this._map.setCenter(new GLatLng(lat, lng), scale);

				GEvent.addListener(this._map, "click", domapclick);
		  	} else {
				this._map = new VEMap(this.divid);
				this._mapOptions = new VEMapOptions();
				this._mapOptions.EnableBirdseye = false;
				if(dashboardsize)
				    this._map.SetDashboardSize(dashboardsize);
				this._map.LoadMap(new VELatLong(lat, lng), scale, 'r', false,VEMapMode.Mode2D,false,0,this._mapOptions);					
				this._map.AttachEvent("onclick", domapclick);
				this._map.AttachEvent("onmouseout", domapout);
				this._map.AttachEvent("onmouseover", domapover);
				// Initialise Pins
			}
			for (var p=0; p<this._pins.length; p++) {
				this.showpin(this._pins[p]);
			}
}	
			this._loaded = true;		
		}
	} 
	
function dogrpcheck(e, name) {
	if (name) {
		e = document.getElementById(name);
		if (e)
			e.checked = false;
	} else {
		var p = e.parentNode;
		if (p.className == 'groupli') {
			p = p.nextSibling;
			while ((p.tagName == 'LI')&&(p.className != 'groupli')) {
				var c = p.getElementsByTagName('INPUT');
				if (!c)		
					break;
				c[0].checked = e.checked;
				p = p.nextSibling;
				if (!p)
					break;				
			}
		}
	}
}

function telementmanager() {
	this.highlightclass = null;
	this._active = null;
	this.onclick = null;
	this.onmouseover = null;
	this.doonmouseover = function (e, index) {
		if (this.highlightclass) {
			if (e != this._active) {
				if (this._active)
					RemoveClass(this._active, this.highlightclass);
				this._active = e;
				AddClass(this._active, this.highlightclass);
			}
		}
		if (this.onmouseover) {
		    this.onmouseover(e, index);
		}
	}
	this.doonmouseup = function (e, index) {
		if (this.onclick) {
			this.onclick(e, index);
		}
	}
}

        function hide(id) {
	        var e = document.getElementById(id);
	        if (e) 
		        e.style.display = 'none';
        }

function CMS() {
    this.EditPage = function (type, id) {
        var ed = document.getElementById('cmseditor');
        if (ed) {
            var url = '/application/Version/v5.002/app.dll/';
            if (type == 'property') {
                url += 'property_add.htm?propertyid=' + id;
            } else {
                url += 'content_edit.htm?type=' + type + '&id=' + id;
            }
            ed.style.display = 'block';
            document.getElementById('cmseditorframe').src = url;
            if (type == 'property')
                Animator.Animate(ed, 700, 550);
            else
                Animator.Animate(ed, 600, 500);
        }
    }
    this.Register = function (group, name, type, id) {
        var li = document.createElement('LI');
        li.innerHTML = '<a href="#" onclick="_cms.EditPage(\'' + type + '\',\'' + id + '\');">' + group + ':' + name  + '</a>';
        if (document.getElementById('webdadibar'))
            document.getElementById('webdadibar').appendChild(li);
    }
    this.New = function (id) {
        document.getElementById('cmseditorframe').src = '/application/Version/v5.002/app.dll/content_edit.htm?type=' + id;
    }
    this.Open = function (id) {
        document.getElementById('cmseditorframe').src = '/application/Version/v5.002/app.dll/content_edit.htm?id=' + id;
    }
    this.notifyupdate = function () {
       //alert('here');	
    }
}
var _cms = new CMS();
function W4Hack() {
    this.Manage = function () {
        return _cms;
    }
    this.Complete = function () {
        window.location.reload();
    }
    this.StopTimer = function() {
    }
}
 var FWebDadi4Inst = new W4Hack();


