//###############################
//# Declarations                #
//###############################


//###############################
//# Functions                   #
//###############################
function mfDeleteProperty(pintPId)
{
  var strSep = '';
  
  if (confirm('You are about to delete the selected property!\n\nAre you sure?'))
  {
    if (window.location.href.indexOf('?') == -1)
      strSep = '?';
    else
      strSep = '&';
      
    window.location.href = window.location.href + strSep + 'DPId=' + pintPId;
  }
}

function _icb_AddItemToShortList(pstrPropertyRef, pintPPCId, pstrByPass)
{

  //Declarations  
  var strParams       = '';
  var intPropertyId    = 0;
  var objHTTPRequest  = ICB_CreateHTTPRequestObject();  //Create an ajax request object
  var Today           = new Date();
        
    //Show that we are adding this product the shopping basket
    if (document.getElementById('div' + pstrPropertyRef))
    {    
      document.getElementById('div' + pstrPropertyRef).innerHTML = 'Adding property to shortlist, please wait...';
      document.getElementById('div' + pstrPropertyRef).style.display = '';
    }
      
    //Get the Quantity and Product Id
    intPropertyId = pstrPropertyRef.substring(pstrPropertyRef.lastIndexOf('_') + 1);
    
    //Build are form post parameters
    strParams = '_icb_PropertyId='  + intPropertyId + '&' +
                '_icb_PropertyRef=' + pstrPropertyRef;


    objHTTPRequest.open("GET", '/Modules/ICB/Property/Scripts/AddToShortList.aspx?CS=' + Today.getSeconds() * Today.getMilliseconds() + '&' + strParams, true);
    objHTTPRequest.onreadystatechange = function()
                                        {
                                          if (objHTTPRequest.readyState==4) 
                                            _icb_AddItemToShortListResponse(objHTTPRequest.responseText, pstrPropertyRef, pstrByPass);
                                        };
    objHTTPRequest.send(null);  	  
}

function _icb_AddItemToShortListResponse(pstrResponse, pstrPropertyRef, pstrByPass)
{

  //Declarations
  var strResult     = '';

  //If we have received the expected result and PropertyRef tags continue
  if (pstrResponse.toLowerCase().indexOf('<result>') != -1 && pstrResponse.toLowerCase().indexOf('<propertyref>') != -1)
  {
    //Extract the result
    strResult = pstrResponse.substring(pstrResponse.toLowerCase().indexOf('<result>') + 8);
    strResult = strResult.substring(0, strResult.toLowerCase().indexOf('<'));
  
    //Extract the PropertyRef
    strPropertyRef = pstrResponse.substring(pstrResponse.toLowerCase().indexOf('<propertyref>') + 12);
    strPropertyRef = strPropertyRef.substring(0, strPropertyRef.toLowerCase().indexOf('<'));

    //If we received a result of OK tell the user that ? number of items have been added to their basket
    if (strResult.toUpperCase() == "OK")
    {
      if (document.getElementById('div' + pstrPropertyRef))
        document.getElementById('div' + pstrPropertyRef).innerHTML = 'The property has been added successfully<br />To remove it click on the trash can in the My Shortlist area<br /><br />';            
      
      //If this page contains a short list summary call a function to refresh the basket summary

      if (pstrByPass != "no")
        window.location.href = "/Buying/Buying-Enquiry.aspx";
      try
      { 
        _icb_RefreshAllShortlistSummaryComponents();
      }
      catch(e){}

    }
    else
    {
      //Add call failed to tell the user
      if (document.getElementById('div' + pstrPropertyRef))
        document.getElementById('div' + pstrPropertyRef).innerHTML = 'Add to shortlist failed!<br />Please refresh this page and try again';
    }    
  }
  else
  {
    if (document.getElementById('div' + pstrPropertyRef))
      document.getElementById('div' + pstrPropertyRef).innerHTML = 'Add to shortlist failed!<br />Please refresh this page and try again';
  }
}



