var agt=navigator.userAgent.toLowerCase();
var is_IE = (navigator.appName.indexOf('Microsoft') > -1);

function show(typ){
	var show = 'show';
	if(typ=="row") {
		show = 'showRow';
	} else if(typ=='cell') {
		show = 'showCell';
	} else if(typ=='table') {
		show = 'showTable';
	}
	if(is_IE) show = 'show';
	return show;
}
function showRow(){
    if(is_IE) return 'block';
	return 'table-row';
}
function prsGo(e){
     var key;      
     if(window.event) {
          key = window.event.keyCode; //IE
     } else if(e.which) {
          key = e.which; //firefox
     }
     if(key == 13 || key == "13") {
        vwChg();
        return false;
     }
}
function addThisScript(){
    var rtn = '<a class="lnkPls" href="http://www.addthis.com/bookmark.php?v=250" onmouseover="return addthis_open(this, \'\', \'[URL]\', \'[TITLE]\')" onmouseout="addthis_close()" onclick="return addthis_sendto()">';
    rtn = rtn + 'Bookmark & Share</a>';
    rtn = rtn + '<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js?pub=abradley81"></script>';
    return rtn;
}
function quickSearch(){
    var prcSel = getEle("qkSrcPrice");
    var bdsSel = getEle("qkSrcBeds");
    var rdtUrl = "";
    if(prcSel.selectedIndex>0){
        var prc = prcSel.options[prcSel.selectedIndex].value.split("-");
        rdtUrl = rdtUrl + "&np=" + prc[0] + "&xp=" + prc[1];
    }
    if(bdsSel.selectedIndex>0){
        rdtUrl = rdtUrl + "&bd=" + bdsSel.options[bdsSel.selectedIndex].value;
    }
    if(rdtUrl>'') {
        location.href= '/view.aspx?zip=&ty=1' + rdtUrl;
    } else if(getEle("go").value>'') {
        vwChg();
    } else {
        location.href= '/search.aspx';
    }
}
function vwChg(){
    var go = getEle("go").value.replace(/ /g,'');
    if(go.length > 2 && isNumeric(go)) {
        location.href= '/view.aspx?listingID=' + go;
    }
}
function chgSort(url,prnt){
    var srtURL = getEle("srtURL").value;
    if(prnt==1) parent.window.location.href=unescape(srtURL + url);
    location.href = unescape(srtURL + url);
    if(updSrch());
}
function isNumeric(sText){
    var ValidChars = "0123456789.";
    var isNum=true;
    var Char;
    for (i=0;i<sText.length&&isNum==true;i++) { 
        Char = sText.charAt(i); 
        if (ValidChars.indexOf(Char) == -1)isNum = false;
    }
    return isNum;
}
function copywrite(){
    var curdate = new Date();
    var out='<i>This information, provided by seller, listing broker, and other parties, may not have been verified. ';
    out=out+'This site does not display the <br>entire SCWMLS Internet Data Display database. ';
    out=out+'&nbsp; &copy;' + curdate.getYear() + ' South Central Wisconsin MLS Corporation. All rights reserved.</i>';
    document.write(out);
}
function popUp(strUrl,strWinname,intWidth,intHeight){
    strFeatures = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=" + intWidth + ",height=" + intHeight;
    strWinname = strWinname.replace(/-/g,"").replace(/@/g,"").replace(/./g,"");
    sealWin = window.open(strUrl,strWinname,strFeatures);
}
function getImageX(obj) {
    var x = 0;
    if (obj.x) x = obj.x
    if ((obj.offsetLeft || obj.offsetParent)&& x == 0) {
        do {
          x += obj.offsetLeft;
          obj = obj.offsetParent;
        } while(obj);
    }
    return x + 90;
}
function getImageY(obj) {
    var y = 0;
    if (obj.y) y = obj.y;
    if ((obj.offsetTop || obj.offsetParent)&& y==0) {
        do {
          y += obj.offsetTop;
          obj = obj.offsetParent;
        } while(obj);
    } 
    return y - 95;
}
var thmTimer;
function thmOver(img,lstID,nm){	  
	  thmTimer = setTimeout ( function() { thmOverShow(img, lstID,nm); }, 250 );
}
function thmOverShow(img,lstID,nm){
    img.alt='';
    if(nm==undefined)nm='1';

    getEle("pUpImg").src = "/pics/" + lstID + "-"+nm+"M.jpg";
    if (document.getElementById && !document.all) {
        obj = getEle("pUp");
        obj.style.left = getImageX(img) + "px";
        obj.style.top  = getImageY(img) + "px";
        obj.style.display = "block";
    } else if (document.layers) {
        obj = document.layers["pUp"];
        obj.left = getImageX(img) + "px";
        obj.top  = getImageY(img) + "px";
        document.layers["pUp"].display = "block";
    } else if (document.all) {
        obj = document.all["pUp"];
        obj.style.pixelLeft = getImageX(img);
        obj.style.pixelTop  = getImageY(img);
        document.all["pUp"].style.display = "block";
    }
}
function thmOut(){
    clearTimeout(thmTimer);
    getEle("pUpImg").src = "/css/s.gif";
    if (document.getElementById && !document.all) {
        getEle("pUp").style.display = "none";
    } else if (document.layers) {
        document.layers["pUp"].display = "none";
    }  else if (document.all) {
        document.all["pUp"].style.display = "none";
    }
}
var xmlHttp;
function ajaxCall(url) {
    getAjax(url);
}
function getAjax(url,success){
    try {
        xmlHttp=new XMLHttpRequest();
    } catch (e) {
        try {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e)	{
            try {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                return false;
            }
        }
    }
    if(success!=undefined) xmlHttp.onreadystatechange=success;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function favFormat(checked){
    var favRow = getEle("ctl00_cp_favRow");
    var tag = getEle("linkFavTag");
    var chkBox = getEle("ctl00_cp_chFav");
    if(checked) {
        favRow.className = "favRemove";
        tag.innerHTML = "Saved to My Favorites";
        tag.style.fontWeight = "bold";
        chkBox.checked = true;
    } else {
        favRow.className = "favSave";
        tag.innerHTML = "Save to My Favorites";
        tag.style.fontWeight = "normal";
        chkBox.checked = false;
    }    
}
function cbFav(chkBox, lid, uid) {
    favAjax(uid,lid,chkBox.checked)
    favFormat(chkBox.checked);
}
function linkFav(lid, uid){
    var fav;
    var tag = getEle("linkFavTag");
    if(tag.innerHTML.indexOf('Save ')>-1) {
        fav="1";
        favFormat(true);
    } else if(tag.innerHTML.indexOf('Saved ')>-1) {
        fav="0";
        favFormat(false);
    }
    favAjax(uid,lid,fav);
}
function viewFav(chkBox, id){
    if(chkBox.checked) {
        setFav(id, true);
    } else {
        setFav(id, false);
    }
}
function favAjax(uid,lid,fav){
    ajaxCall("/action.aspx?fav="+fav+"&lid="+lid+"&uid="+uid);
} 
function setVw(){
    var parWin = parent.document;
    if(parWin != undefined){
        var prnt = parWin.getElementById("viewContainer");
        if(prnt != undefined) {
            prnt.style.height = (getEle('pgImg').offsetTop + 20)+"px";
            parWin.title = document.title+' | '+parWin.title;
        }
    }
}
function puContact(id,txt,cls){ return popupLnk('/send.aspx?listing='+id,txt,cls,425); }
function puSchdule(id,txt,cls){ return puContact(id+'&shw=',txt,cls); }
function puSendFrd(id,txt,cls){ return popupLnk('/send.aspx?send='+id,txt,cls,330); }
function puSrchSav(lnk,txt,cls){ return popupLnk(lnk,txt,cls,280); }
function puSrchSnd(lnk,txt,cls,cnt){ return popupLnk(lnk+'&cnt='+cnt,txt,cls,420); }
function puFavFrwd(txt,cls){ return popupLnk('/favorite-forward.aspx?',txt,cls,400); }
function puPrcAlrt(id,txt,cls){ return popupLnk('/price-alerts.aspx?id='+id,txt,cls,260); }
function prnt(txt,cls) { return '<a class="'+cls+'" href="javascript:window.print()">'+txt+'</a>'; }

function popupLnk(lnk,txt,cls,hgt){
    return '<a class="'+cls+'" href="'+lnk+'" onclick="return showPopup(event,1,\''+lnk+'&pg=f\','+hgt+');">'+txt+'</a>';
}

function showPopup(e,show,win,hgt){ 
	//parent.document.body.focus();
	if(show) {
        if(document.getElementById('ajaxPopup') == undefined){
            $(parent.document.body).append(
                '<div class="popup" id="ajaxPopup">' + puCSS() + 
                '<table cellspacing="0" cellpadding="0" onclick="ign(event);">' +
                '<tr><td class="pu">&nbsp;</td><td class="pu ptm">&nbsp;</td><td class="pu ptr">&nbsp;</td></tr>' +
                '<tr><td class="pu pml">&nbsp;</td><td class="bg"><a rel="nofollow" href="" onclick="return showPopup(event,0);" class="cls">Close Window</a>' +
                '<div id="ajaxPopup_div"><div><iframe src="'+win+'" height="'+hgt+'" width="400" scrolling="no" frameborder="0">&nbsp;</iframe></div></div><div class="clsWin"><a rel="nofollow" href="" onclick="return showPopup(event,0);">Close Window</a></div></td>' +
                '<td class="pu pmr">&nbsp;</td></tr><tr><td class="pu pbl">&nbsp;</td><td class="pu pbm">&nbsp;</td><td class="pu pbr">&nbsp;</td></tr></table>' +
                '</div>'
            );
        }

	    $('#ajaxPopup').centerInClient();
	} else {
	    $('#ajaxPopup').remove();
	}
	return false;
}
function puCSS(url){
    url = '';
    return "<style type=\"text/css\">" +
    ".popup {position:absolute; z-index: 1500;}" + 
    ".pu { background-color:transparent; background-image:url('" + url + "/css/popup_ds.png'); font-size:1px; }" +
    ".popup .ptm { background-position:-24px 0px; }" +
    ".popup .ptr { width:24px; height:24px; background-position:top right }" +
    ".popup .pml { width:24px; background-position:left -24px }" +
    ".popup .pmr { width:24px; background-position: right -24px}" +
    ".popup .pbl { width:24px; height:24px; background-position:bottom left }" +
    ".popup .pbm { background-position:-24px bottom; }" +
    ".popup .pbr { width:24px; height:24px; background-position:bottom right }" +
    ".popup .bg { background: #EEE url('" + url + "/css/pop_bg.gif') repeat-x; border: 1px solid black; border:1px solid black; width:440px; margin:12px 6px 6px 12px; padding:3px 0px 3px 0px;}" +
    ".popup a.cls:link,.popup a.cls:visited{background: url('" + url + "/css/icons.gif?v=1a') right -560px no-repeat; text-decoration:none; font-size:10px; color:black; margin-right:7px; height:17px; width:84px; float:right;}" +
    ".popup a.cls:hover{text-decoration:underline}" +
    ".popup div div {background-color: #FFF;border: 1px dotted black;margin:0px 8px 3px 18px;padding:0px 10px 0px 10px;clear:both;display:block}" +
    ".popup .clsWin { font-size:10px; text-align:center;}" +
    ".popup .clsWin a{color:black}" +
    ".pUp { background:url('" + url + "/css/movewait.gif') no-repeat center white; border:1px solid gray; position:absolute; width:386px; height:297px;}" +
    ".pUp td  { width:386px; height:297px; text-align:center; vertical-align:middle; }" +
    "</style>";
}
$.fn.centerInClient = function(options) {
    var opt = { forceAbsolute: false,
                container: window,    // selector of element to center in
                completeHandler: null
              };
    $.extend(opt, options);
   
    return this.each(function(i) {
        var el = $(this);
        var jWin = $(opt.container);
        var isWin = opt.container == window;

        // force to the top of document to ENSURE that 
        // document absolute positioning is available
        if (opt.forceAbsolute) {
            if (isWin)
                el.remove().appendTo("body");
            else
                el.remove().appendTo(jWin.get(0));
        }

        // have to make absolute
        el.css("position", "absolute");

        // height is off a bit so fudge it
        var heightFudge = isWin ? 2.0 : 1.8;

        var x = (isWin ? jWin.width() : jWin.outerWidth()) / 2 - el.outerWidth() / 2;
        var y = (isWin ? jWin.height() : jWin.outerHeight()) / heightFudge - el.outerHeight() / 2;

        el.css("left", x + jWin.scrollLeft());
        el.css("top", y + jWin.scrollTop());

        // if specified make callback and pass element
        if (opt.completeHandler)
            opt.completeHandler(this);
    });
}
function showElement(show,el){
	if(show) deleteClass(el, 'hide');
	else insertClass(el, 'hide');
}
function ign(e){
	if (e && typeof(e) != 'undefined') {
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
	}
	return false;
}
function getEle(el) {
	if (typeof(el) == 'undefined' || !el) {
		return null;
	} else if (typeof(el.tagName) == 'undefined' || !el.tagName) {
		if (document.all) el = document.getElementById(el) ? document.getElementById(el) : document.all[el];
		else el = document.getElementById(el);
		if (el) return el;
	} else if (el.tagName) {
		return el;
	}
	return document.getElementById(el);
}
function hasClass(el, findClass) {
	var arrClass = el.className.split(' ');
	for(var cl in arrClass) {
		if (arrClass[cl] == findClass) return true;
	}
	return false;
}
function deleteClass(el, classDelete) {
	var arrClass = el.className.split(' ');
	var updClass = false;	
	for (var i in arrClass) {
		if (arrClass[i] == classDelete) {
			arrClass.splice(i, 1);
			updClass = true;
		}
	}
	if (updClass) el.className = arrClass.join(' ');
	return updClass;
}
function insertClass(el, classInsert){
  if (!el || hasClass(el, classInsert)) return false;
  el.className = el.className + ' ' + classInsert;
  return true;
}
function getObjDimensions(el) {
	var objWidth = 0;
	var objHeight = 0;
	if (el.offsetWidth || el.offsetWidth === 0) {
		objWidth = el.offsetWidth;
		objHeight = el.offsetHeight;
	} else if (document.defaultView.getComputedStyle) {
		objHeight = document.defaultView.getComputedStyle(el, "").getPropertyValue("height");
		objWidth = document.defaultView.getComputedStyle(el, "").getPropertyValue("width");
	} else if (el.clip) {
		objWidth = el.clip.width;
		objHeight = el.clip.height;
	}
	return { 'height':objHeight, 'width':objWidth };
}
function getClientSize(){
  var brw = new Object;
  brw.width = getClientWidth();
  brw.height = getClientHeight();
  brw.scrollLeft = getScrollLeft();
  brw.scrollTop =  getScrollTop();
  return brw;
}
function getClientWidth() {
  return filterRslts
  (
    window.innerWidth ? window.innerWidth : 0,
    document.documentElement ? document.documentElement.clientWidth : 0,
    document.body ? document.body.clientWidth : 0
  );
}
function getClientHeight() {
  return filterRslts
  (
    window.innerHeight ? window.innerHeight : 0,
    document.documentElement ? document.documentElement.clientHeight : 0,
    document.body ? document.body.clientHeight : 0
  );
}
function getScrollLeft() {
  return filterRslts
  (
    window.pageXOffset ? window.pageXOffset : 0,
    document.documentElement ? document.documentElement.scrollLeft : 0,
    document.body ? document.body.scrollLeft : 0
  );
}
function getScrollTop() {
  return filterRslts
  (
    window.pageYOffset ? window.pageYOffset : 0,
    document.documentElement ? document.documentElement.scrollTop : 0,
    document.body ? document.body.scrollTop : 0
  );
}
function filterRslts(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel))) n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}