﻿function infoLinks(id, shwPriceAlert, shwSchShowing){
    document.write(puContact(id,'Ask a Question','lnkMal'));
    if(shwPriceAlert) document.write(puPrcAlrt(id,'Create a Price Alert','lnkPrc'));
    document.write(prnt('Print','lnkPrt') + '<br /><div style="width:100%"></div>');
    if(shwSchShowing) document.write(puSchdule(id,'Schedule a Showing','lnkShw'));
    document.write(addThisScript());
}
function descLnks(id, shwSchShowing){
    document.write(puContact(id,'Contact','')+' ');
    if(shwSchShowing) document.write(puSchdule(id,'Schedule a Showing','')+' ');
    document.write(puSendFrd(id,'Send to a Friend',''));
}
function contactLnks(id, shwSchShowing){
    document.write(prnt('Print this Listing','nav'));
    document.write(puContact(id,'Ask a Question','nav'));
    if(shwSchShowing) document.write(puSchdule(id,'Schedule a Showing','nav'));
    document.write(puSendFrd(id,'Send this Listing to a Friend','nav'));
}
function runPics(listing,viewPhotoHref) {
    var picsTable = getEle(getEle("picID").value+"_dlPics");
    picsTable.className = show('table');
    showRows("show", "hide");
    showTxt('0');
    buildPhotoBase(listing,1,viewPhotoHref,true);
}
function descBase(id){
    document.write(' ' + puContact(id,'Get more information',''));
}
function getDirections(id){
    document.write(' ' + puContact(id,'Get Directions to view listing',''));
}
function showRows(first, last){
    var picRows = getEle(getEle("picID").value+"_dlPics").rows;
    for(x=0; x<picRows.length; x++){
        if(x < 5) {
            if(first=="show"){
                picRows[x].style.display = showRow();
            } else {
                picRows[x].style.display = "none";
            }
        } else {
            if(last=="show"){
                picRows[x].style.display = showRow();
            } else {
                picRows[x].style.display = "none";
            }
        }
    }   
}
var isLarge = false;
function showPic(listing, pic, from, txt, pLW, pLH, pMW, pMH){
    var id = getEle("picID").value+"_";
    var size;
    var imgTbl = getEle(id+"imgTbl");
    var infoDiv = getEle("info");
    var imgLnk = getEle(id+"mainLink");
    var picTD = getEle(id+"picTD");
    var mainPic = getEle(id+"mainPic");
    var viewPhotoAlt = "View Larger Photo";
    
    if((isLarge && from=="sml") || (!isLarge && from=="lrg")) {
        size = "L";
        isLarge = true;
        viewPhotoAlt = "Return to Smaller Photo";
        picTD.style.width = "766px";
        imgTbl.style.width = "950px";
        infoDiv.style.display = "none"
        mainPic.width = pLW;
        mainPic.height = pLH;
    } else {
        size = "M";
        isLarge = false;
        picTD.width = "344px";
        imgTbl.style.width = "599px";
        infoDiv.style.display = "block"
        mainPic.width = pMW;
        mainPic.height = pMH;
    }
    
    mainPic.src = "/pics/" + listing + "-" + pic + size + ".jpg";
    if(pLW>(pMW+100) && pLH>(pMH+100)){
        imgLnk.href = "javascript:showPic(" + listing + "," + pic + ",'lrg'," + txt + "," + pLW + "," + pLH + "," + pMW + "," + pMH + ")";;
        imgLnk.title = viewPhotoAlt;
    } else {
        imgLnk.href = "javascript:{}";
        imgLnk.title = "No Larger Photo";
    }

    showTxt(txt);
    buildPhotoBase(listing, pic, imgLnk.href);
}

function buildPhotoBase(listing, viewingPic, viewPhotoHref,firstLoad){
    var rtn = "";
    var picCount = parseInt(getEle(getEle("picID").value+"_PicCount").value);
    var picPrevious = viewingPic - 1;
    var picNext = viewingPic + 1;
    var phNav = getEle("photoNav");
    
    if(picPrevious < 1) picPrevious = picCount;
    if(viewingPic==picCount) picNext = 1;
    
    if((viewingPic >=1 && viewingPic <= 10) && firstLoad==undefined){
        chgTab("first");
    } else if(firstLoad==undefined){
        chgTab("next");
    }

    if(picCount>1) {
        rtn = rtn + "<a class=\"photoPrev\" href=\"" + getEle("picID"+picPrevious).href + "\" title=\"Previous Photo\"></a>";
    } else {
        rtn = rtn + "<div class=\"photoLft\"></div>";
    }    
    if(viewPhotoHref == "javascript:{}") {
        rtn = rtn + puContact(listing,'','photoGetInfo2');
    } else {
        if(isLarge){
            phNav.style.margin = "0px 0px 0px 190px";
            rtn = rtn + "<a href=\"" + viewPhotoHref + "\" class=\"photoSmaller\" title=\"View Smaller Photo\"></a>";
        } else {
            phNav.style.margin = "0";
            rtn = rtn + "<a href=\"" + viewPhotoHref + "\" class=\"photoLarger\" title=\"View Larger Photo\"></a>";
        }
        rtn = rtn + puContact(listing,'','photoGetInfo');
    }
    if(picCount>1) {
        rtn = rtn + "<a href=\"" + getEle("picID"+picNext).href + "\" class=\"photoNext\" title=\"Next Photo\"></a>";
    } else {
        rtn = rtn + "<div class=\"photoRght\"></div>";
    }
    phNav.innerHTML = rtn;
}

function showTxt(pic) {
    var picCount = getEle(getEle("picID").value+"_PicCount").value;
    for(x=0; x<picCount; x++){
        if(pic != x) {
            getEle("txt" + x).className = "hide";
        } else {
            getEle("txt" + x).className = "show";
        }
    }
}

function chgTab(show) {
    var links = getEle(getEle("picID").value+"_picTabs");
    if(show == "first") {
        links.className = "imgTab tableft";
        showRows("show", "hide");
    } else if(show == "next") {
        links.className = "imgTab tabright";
        showRows("hide", "show");
    }
}
function showGoogleMap(view) {
    var descRow = getEle("ctl00_cp_descRow");
    var mapRow = getEle("mapRow");
    var mapSize = getEle("mapDiv");
    if(view == "small") {
        mapRow.colspan = "1";
        mapRow.style.width = "370px";
        mapSize.style.width = "360px";
        mapSize.style.height = "240px";
    } else if(view == "large") {
        mapRow.colspan = "2";
        mapRow.style.width = "750px";
        mapSize.style.width = "740px";
        mapSize.style.height = "450px";
    } else {
        descRow.colspan = "2";
        descRow.style.width = "750px";
        mapRow.className = "hide";
    }
}
function showLrgMap() {
    var descRow = getEle("ctl00_cp_descRow");
    var mapLink = getEle("mapLink");
    if(mapRow.colspan == "2") {
        descRow.className = show('cell');
        showGoogleMap("small");
        mapLink.innerHTML = "View Larger Map";
        map.checkResize();
    } else {
        descRow.className = "hide";
        showGoogleMap("large");
        mapLink.innerHTML = "Back to Smaller Map";
        map.checkResize();
    }
}
function getPhone(id,lID,uID){
    var pnlPhnRqu = getEle(id+"_pnlPhnRqu");
    if(pnlPhnRqu != undefined) pnlPhnRqu.style.display = "none";
    
    var pnlPhone1 = getEle(id+"_pnlPhone1");
    if(pnlPhone1 != undefined) pnlPhone1.style.display = "block";
    
    var pnlPhone2 = getEle(id+"_pnlPhone2");
    if(pnlPhone2 != undefined) pnlPhone2.style.display = "block";

    var url = "/action.aspx?phn="+lID+"&uid="+uID;
    ajaxCall(url);
    
    var msg = getEle("ctl00_cp_Msg");
    if(msg.value==""){
        getEle("emH2").className = "clrTxt bdrBtm grnAni";
        msg.value = "[ Get your questions answered ]";
        setTimeout ( function() { 
            if(msg.value=="[ Get your questions answered ]"){
                setTimeout ( function() { 
                    msg.value = "# No personal information required #";
                    setTimeout ( function() { 
                        if(msg.value=="# No personal information required #"){
                            msg.value="";
                            getEle("ctl00_cp_Msg").focus();
                        }                    
                    }, 1500);
                }, 1500);
            }
        }, 1500);
    }
}
function clrMsg(){
    var msg = getEle("ctl00_cp_Msg");
    if(msg.value=="[ Get your questions answered ]" || msg.value=="# No personal information required #"){
        msg.value="";
    }
}
var map;

function showAddress(lat,lng) {
    if (GBrowserIsCompatible()) {
        map = new GMap2(getEle("mapDiv"));
        var geocoder = new GClientGeocoder();
    }
    if (geocoder) {
        geocoder.getLatLng(
            getEle('MapAdd').value,
            function(point) {
                if (point) {
                    var mapVals = getEle('MapVals').value.split("_");
                    map.setCenter(point, parseInt(mapVals[0]));
                    var marker = new GMarker(point);
                    if(mapVals[2] == "True") map.addOverlay(marker);
                    if(mapVals[1] == "True") map.addControl(new GSmallMapControl());
                } else {
                    showGoogleMap(false);
                }
            }
        );
    } else {
        showGoogleMap(false);
    }
}

function showLrgAddress() {
  if (GBrowserIsCompatible()) {
        var geocoder = new GClientGeocoder();
    }
  if (geocoder) {
    geocoder.getLatLng(
      getEle('MapAdd').value,
      function(point) {
        if (point) {
          map.checkResize();
          map.setCenter(point, 8);
          var marker = new GMarker(point);
          map.addOverlay(marker);
          map.checkResize();
        }
      }
    );
  }
}