   /*

Quick hack here until the AJAX is complete. 

*/

var g_aTempResults = new Array();

function CPicFlow_Resting(iTrKey)
{
   var pInfo = document.getElementById('propertypreviewpane');
   if( pInfo ) {
      pInfo.innerHTML = '';
      var strUrl = '/xml-bin/propertydetail?id='+iTrKey;   
      g_AjaxQueue.schedule("PhotoFlowPreview", strUrl, OnCompleteShowPicFlowPreview);
      c21Reporting( 'listing', 'Detail', iTrKey );
   }
}


function OnCompleteShowPicFlowPreview( pThisAjaxReq ) 
{
   if(pThisAjaxReq.readyState != 4) {
      return;
   }
   var pPropertyNode = pThisAjaxReq.responseXML.getElementsByTagName('property');
   if( !pPropertyNode.length || pPropertyNode.length == 0 ) {
      alert("Could not load property preview.");
      return;
   }   
   var iTrKey = GetNodeValue(pThisAjaxReq.responseXML, 'provider-listingid');
   if( iTrKey.substring(0, 3) == "C21" ) {
      iTrKey = iTrKey.substring(3);
   }
   if( !iTrKey || iTrKey == '' ) {
      alert("Could not load property preview.");
      return;
   }   

   var strOfficeName = GetNodeValue(pThisAjaxReq.responseXML, 'provider-officename');
   if( !strOfficeName ) strOfficeName = '';

   try {
      var listingid = GetNodeValue(pThisAjaxReq.responseXML, 'provider-listingid');
      if( listingid.substring(0, 3) == "C21" ) {
         listingid = listingid.substring(3);
      }
      var strDescription = GetNodeValue(pThisAjaxReq.responseXML, 'description');
      var strStreetAddress = GetNodeValue(pThisAjaxReq.responseXML, 'street-address');
      var strDisplayAddressYesNo = GetNodeValue(pThisAjaxReq.responseXML, 'display-address');
      if( strDisplayAddressYesNo == 'no' ) {
         strStreetAddress = '';
      }
      var strCity = GetNodeValue(pThisAjaxReq.responseXML, 'city-name');
      var strState = GetNodeValue(pThisAjaxReq.responseXML, 'state-code');
      var strZip = GetNodeValue(pThisAjaxReq.responseXML, 'zipcode');
      var strFormattedPrice = '$' + AddCommas(GetNodeValue(pThisAjaxReq.responseXML, 'price'));
      var lBedrooms = GetNodeValue(pThisAjaxReq.responseXML, 'num-bedrooms');
      var lFullBaths = GetNodeValue(pThisAjaxReq.responseXML, 'num-full-bathrooms');
      var lHalfBaths = GetNodeValue(pThisAjaxReq.responseXML, 'num-half-bathrooms');
      var strBathrooms = '';
      var strBedrooms = '';
      if( lBedrooms != '0' ) strBedrooms = lBedrooms + ' br';
      else strBedrooms = '-';
      if( lFullBaths != '0' || lHalfBaths != '0' ) {
         if( lFullBaths != '0' ) {
            strBathrooms += lFullBaths + ' full<br>';
         }
         if( lHalfBaths != '0' ) {
            strBathrooms += lHalfBaths + ' half';
         }      
      } else {
         strBathrooms = '-';
      }
      var strSqFoot = '';
      var lSqFoot = GetNodeValue(pThisAjaxReq.responseXML, 'square-feet');
      if( lSqFoot != '' && lSqFoot != '0' ) {
         strSqFoot = lSqFoot + ' sq.ft'
      } else {
         strSqFoot = '-';
      }
      var strListDate = '';
      try {
         var dtListDate = null;//new Date();

      //--- Remove first '-' from input date as date.Parse does not eat YYYY-MM-DD, it will only eat YYYY MM-DD 
         var strTmpDate = GetNodeValue(pThisAjaxReq.responseXML, 'date-listed');
         dtListDate = new Date(strTmpDate.substring(0,4), strTmpDate.substring(5,7)-1, strTmpDate.substring(8,10));
         strListDate = (dtListDate.getMonth()+1) + '/' + dtListDate.getDate() + '/' + dtListDate.getFullYear();
      }catch( e ) {
      }      
      try {
         //var pDate = new Date(parseInt(dtListDate)*1000);
         //strListDate = dtListDate; //(pDate.getMonth()+1) + '/' + pDate.getDay() +'/' + pDate.getYear();
      } catch (e) {
         alert( e.message );
      }
   
      

      var strAgentId = GetNodeValue(pThisAjaxReq.responseXML, 'crest-agent-key');
      var strAgentPhotoUrl = GetNodeValue(pThisAjaxReq.responseXML, 'agent-picture-url');
      var strAgentName = GetNodeValue(pThisAjaxReq.responseXML, 'agent-name');

      var strOfficeId = GetNodeValue(pThisAjaxReq.responseXML, 'crest-office-key');

      var strContactShownIs = GetNodeValue(pThisAjaxReq.responseXML, "office-listing-contact-display");
      var strDirectEmailTo = GetNodeValue(pThisAjaxReq.responseXML, "office-sa-contact-email");
      var bShowSAProfileLink = GetNodeValue(pThisAjaxReq.responseXML, "office-sa-profile-link");

      var strContactLink;
      var strContactLinkOnClickFunction;
      var strContactName;
      var strContactPhotoUrl;
      var strContactButtonUrl;


      if (strContactShownIs == 'agent') {

         strContactLink = '/agent/index.jsp?id='+strAgentId;
         strContactOnClickFunction = 'ShowContactAgentForm(event, \''+strAgentId+'\', \''+iTrKey+'\', \'JsPhotoflow\')';
         strContactName = strAgentName;
         strContactPhotoUrl = strAgentPhotoUrl;
         strContactButtonUrl = '/images/search/contactagent.gif';
      } else {

         strContactLink = '/office/index.jsp?id='+strOfficeId;
         strContactOnClickFunction = 'ShowContactOfficeForm(event, \''+strOfficeId+'\', \''+iTrKey+'\')';
         strContactName =  GetNodeValue(pThisAjaxReq.responseXML, "office-name");
         strContactPhotoUrl = GetNodeValue(pThisAjaxReq.responseXML, 'office-picture-url');
         strContactButtonUrl = '/images/search/contactoffice.gif';
      }

      if (bShowSAProfileLink == 0) {
         strContactLink = '/office/index.jsp?id='+strOfficeId;
         strContactOnClickFunction = 'ShowContactOfficeForm(event, \''+strOfficeId+'\', \''+iTrKey+'\')';
         strContactButtonUrl = '/images/search/contactoffice.gif';
      }

      if( iTrKey.charAt(0) >= 'A' && iTrKey.charAt(0) <= 'Z' ) {
         strContactLink = '/idxproperty/contactoffice.jsp?id='+iTrKey;
         strContactOnClickFunction = 'ShowContactIdxPropertyForm(event, \''+iTrKey+'\')';
         strContactButtonUrl = '/images/search/contactoffice.gif';
      }

      if( strDescription == '' ) {
         strDescription = 'Please contact ' + strContactName + ' for more information.';
      }
      var aAgentNames = strAgentName.split(' ');
      if( aAgentNames.length > 1 ) {
         strAgentName = '';
         for( var i in aAgentNames ) {
            strAgentName += aAgentNames[i] + '<br>';
         }
      }
      var strDetailUrl = '/property/index.jsp?id=' + iTrKey; 
      var propType = "property";
      var isIdx= false;
      if( iTrKey.charAt(0) >= 'A' && iTrKey.charAt(0) <= 'Z' ) {
         strDetailUrl = '/idxproperty/index.jsp?id=' + iTrKey;
         propType = "idx";
         isIdx= true;
      }
      var strPreviewHtml = 
            '<table cellspacing="0" cellpadding="2" style="width:100%">' +
            '   <tr>' +
            '      <th style="border-top:1px solid #666666;border-bottom:1px solid #666666;font-size:0.85em;">ADDRESS</th>' +
            '      <th style="border-top:1px solid #666666;border-bottom:1px solid #666666;font-size:0.85em;">PRICE</th>' +
            '      <th style="border-top:1px solid #666666;border-bottom:1px solid #666666;font-size:0.85em;">BEDS</th>' +
            '      <th style="border-top:1px solid #666666;border-bottom:1px solid #666666;font-size:0.85em;">BATHS</th>' +
            '      <th style="border-top:1px solid #666666;border-bottom:1px solid #666666;font-size:0.85em;">FOOTAGE</th>' +
            '      <th style="border-top:1px solid #666666;border-bottom:1px solid #666666;font-size:0.85em;">LISTED DATE</th>' +
            '   </tr>' +
            '   <tr>' +
            '      <td valign="top" style="font-weight:bold;">'+strStreetAddress+'<br>'+strCity+', '+strState+' '+strZip+'</td>' +
            '      <td valign="top" style="font-weight:bold;font-size:1.1em;">'+strFormattedPrice+'</td>' +
            '      <td valign="top" style="font-weight:bold;">'+strBedrooms+'</td>' +
            '      <td valign="top" style="font-weight:bold;">'+strBathrooms+'</td>' +
            '      <td valign="top" style="font-weight:bold;">'+strSqFoot+'</td>' +
            '      <td valign="top" style="font-weight:bold;">'+strListDate+'</td>' +
            '   </tr>' +
            '</table>' +
            '<div class="clearfloat" style="padding-top:1.25em"></div>';

      if (!isIdx) {
          strPreviewHtml += '<div style="float:left;">' +
                '   <div class="portraitthumbnailcontainer2">               ' +
                '      <a href="' + strContactLink + '"><img src="'+strContactPhotoUrl+'" width="118" height="79" alt="" border="0" class="portraitthumbnail"></a>' +
                '      <div class="tl"></div><div class="tr"></div><div class="bl"></div><div class="br"></div>' +
                '   </div>' +
                '   <div style="line-height:1.3em;font-weight:bold;">' +
                '      ' + strContactName +
                '   </div>'  +
                '</div>         ';
      }
      strPreviewHtml += '<div style="float:left;margin-left:20px;">' +
            '   <div>' +
            '      <a href="#" class="myc21_button" onclick="return savePropertyToMyC21(this, \''+ iTrKey +'\');"><img id="save_img'+ iTrKey +'" src="/images/search/myc21add.gif" border="0"></a>' +
            '      <a href="'+ strDetailUrl +'"><img src="/images/search/viewlisting.gif" border="0"></a>' +
            '      <a href="' + strContactLink + '" onclick="return ' + strContactOnClickFunction + ';"><img src="' + strContactButtonUrl + '" border="0"></a>' +
            '   </div>';
      if( strOfficeName != '' ) {
         strPreviewHtml += '<div class="photoflowcourtesy">Courtesy of '+ strOfficeName +'</div>';
      }
      strPreviewHtml += 
            '</div>' +
            '<div style="float: left;width:600px;margin-left:20px;">' +
            '   <div>' +
            '      <div class="descriptionlabel" style="padding-top:1em">' +
            '         DESCRIPTION:' +
            '      </div>' +
            '      <div>' +
            strDescription + 
            '      </div>' +
            '   </div>' +
            '</div>' +
            '<div id="listingid" style="display:none;">'+listingid+'</div>' +
            '<div id="propertyType" style="display:none;">'+propType+'</div>';

      var pInfo = document.getElementById('propertypreviewpane');
      if( pInfo ) {
         pInfo.innerHTML = strPreviewHtml;
      }
   } catch (e) {
      alert( e.message );
   }



   return true;
}
