/*
  Author: A. J. Jerzak
  $Archive: /LocumNet/ISNServer/wwwroot/listings/view_listing.js $
  $Revision: 26 $
  $Modtime: 11-03-13 21:08 $
  $Author: Kuba $
*/

// Funkcje związane z view_listing.asp

/*
  action - jeśli nie pusty, to podstawiany do form.action; dodatkowo: jeśli zaczyna się
           od //, to oznacza względem katalogu wirtualnego aplikacji i dodajemy
           tenże
  target - jeśli nie pusty, to podstawiany do form.target
  Odtwarza form.action i form.target po wysłaniu.
*/
function VLSubmitForm(action, target, act)
{
  if(act) vl_form.elements['act'].value = act;
  LNSubmitForm(vl_form, action, target);
}

// Przywraca ofertę z archiwum do normalności. Odświeża listę.
function RestoreArchivedListing(ListingID)
{
  if(!confirm('This function will remove the listing from archive. Do you wish to proceed?')) return;
  vl_form.RestoreArchivedListingID.value = ListingID;
  PageChainSetGoBack(vl_form);
  BackASPSubmitForm(vl_form, 'RestoreArchivedListing.asp')
}

// Kopiuje ofertę z archiwum.
function CopyArchivedListing(ListingID)
{
  if(!confirm('A copy of the listing will be made. Do you want to proceed?')) return; //transl
  vl_form.CopyArchivedListingID.value = ListingID;
  vl_form.action = LInputFileName(vl_PropertyTypeID, vl_TypeOfListing, vl_MultiUnit) +
                '?mode=' + LI_MODIFY_NEW;
  BackASPSubmitForm(vl_form, 'ListingCopyFromArchive.asp');
}

function VLWwwApprove(approved)
{
  vl_form.act.value = 'WwwApprove';
  BackASPSubmitForm(vl_form, 'save_listing.asp', 'WwwApproved=' + (approved ? 1 : 0));
}

// Powoduje ustawienie się strony na zadanej grupie pól oferty
function Gr(grid) {
 if(highlighted!=0) eval('document.getElementById("grt'+highlighted+'").style.color="#000000"')
 eval('document.getElementById("grt'+grid + '").style.color="#FF0000"')
 highlighted = grid
 window.location.href = "#gr" + grid
}

function PageTop() {
 if(highlighted!=0) eval('document.getElementById("grt'+highlighted+'").style.color="#000000"')
 highlighted = 0
 window.location.href = "#PageTop"
}

function BackToList()
{ 
  PageChainSubmitGoBack(vl_form);
}
    
function ShowPrevOrNextListing(recordNoOffset, id)
{
  vl_form.recordNoOffset.value = recordNoOffset
  PageChainSubmitNewPage(vl_form, 'view_listing.asp', 0);
}

// liMode - może być LI_ARCHIVE_SOLD lub nic
function EditListing(liMode) {
 form = vl_form;
 form.ListingID.value = form.elements[C_VL_ListingID].value
 form.action = LInputFileName(vl_PropertyTypeID, vl_TypeOfListing, vl_MultiUnit) +
               '?ListingInputPage=Main' + (liMode ? '&mode=' + liMode : '');
 form.submit();
}

function Deactivate()
{
  VLSubmitForm("ModState.asp", "workarea", "deactivate");
}    

function Post()
{
  VLSubmitForm("ModState.asp", "workarea", "extend");
}

function SetFeaturedProperty() {
 window.open(VirtDir + '/listings/SetFeaturedProperty.asp?action=set&id=' + ListingId +
             '&LinkToWebPage=' + vl_LinkToWebPage, 'workarea')
 document.getElementById('eksponuj1_text').innerHTML='Undo featured';
 document.getElementById('eksponuj2_text').innerHTML='Undo featured';
 document.getElementById('eksponuj1_href').href='javascript:UnsetFeaturedProperty()';
 document.getElementById('eksponuj2_href').href='javascript:UnsetFeaturedProperty()';
}

function UnsetFeaturedProperty() {
 window.open(VirtDir + '/listings/SetFeaturedProperty.asp?action=unset&id=' + ListingId, 'workarea')
 document.getElementById('eksponuj1_text').innerHTML='Featured'; //transl
 document.getElementById('eksponuj2_text').innerHTML='Featured'; //transl
 document.getElementById('eksponuj1_href').href='javascript:SetFeaturedProperty()';
 document.getElementById('eksponuj2_href').href='javascript:SetFeaturedProperty()';
}

var NewPictureUpload;   // pamięta rodzaj zlecenia ładownia zdjęcia
function OnPicUploaded(pict)
{
  form = vl_form;    
  form.action = GetVirtDir() + "listings/view_listing.asp"
  form.LstDispMode.value = 3
  if(pict && NewPictureUpload) form.DisplayedPictureNo.value = 0; // powoduje wyświetlenie ostatniego (właśnie załadowanego) zdjęcia
  form.submit()
}

function ShowCalculatorExtra(price, currency) {
  VLSubmitForm('//calculators/CalculatorExtra.asp?ce_price=' + price + 
       '&ce_currency=' + currency + '&ce_showReturnToFullViewButton=1');
}

// na razie currency nie istotne, bo cena ma być w zł
function ShowCalculatorCredit(price, currency) {
  VLSubmitForm('//calculators/CalculatorCredit.asp?cc_housePrice=' + price + 
     '&cc_currency=' + currency + '&cc_showReturnToFullViewButton=1');
}

function ShowCalculatorExtraV3(price, currency) {
  VLSubmitForm('//calculators/CalculatorExtraV3.asp?ce_price=' + price + 
       '&ce_currency=' + currency + '&ce_showReturnToFullViewButton=1');
}

// na razie currency nie istotne, bo cena ma być w zł
function ShowCalculatorCreditV3(price, currency) {
  VLSubmitForm('//calculators/CalculatorCreditV3.asp?cc_housePrice=' + price + 
     '&cc_currency=' + currency + '&cc_showReturnToFullViewButton=1');
}

function vp(id) {
  VLSubmitForm('//vp.asp?' + C_vp_UnitMode +'=fv&' + C_vp_UserID + '='+id);
}

function Gallery(aspFile) {
  if(aspFile.substr(0, 2) == '//') aspFile = VirtDir + aspFile.substr(1);
  VLSubmitForm(aspFile);
}

function ListingStats(ListingId)
{
  VLSubmitForm('//statistics/listing_stat.asp?SelListing=' + ListingId);
}  

function Contact() {
 if(vl_form.email.value == "") {
  alert("Option not available!\nListing's owner did not provide e-mail address!");  //transl
  return;
 }
 VLSubmitForm("//listings/contact.asp");
}

// printoutTarget - dla kogo wydruk (client, agency)
function Print(listID, printoutTarget)
{
  var form = vl_form;
  var oldAction = form.action;
  var w;
  if (true || navigator.appVersion.search(/MSIE [5-9]/) > -1)
  {
    w = window.open("",
      "Printing",
      'scrollbars=no,status=no,width=700,height=600,dependent=yes,toolbar=no' );
     form.action = VirtDir + "/listings/print_main_frame.asp?lpr_ShowOfferer=1"
  }
  else
  {
     w = window.open("print_list.html",
      "Printing",
      'scrollbars=yes,status=no,width=700,height=500,dependent=yes,toolbar=yes' );
     form.action = "print_listing.asp?WithListingPicture=" + form.print_photo.value
  }

  form.target = "Printing"
  form.list_view_select.value = (printoutTarget == 'client') ? '1' : '2';
  form.elements[FLD_PRINTOUT_TARGET].value = printoutTarget;
  form.submit()
  w.focus();
  form.target = ""
  form.action = oldAction;
}

function SendEmail(emailType) {
  VLSubmitForm('//listings/email.asp?' + C_Email_ListingIDs + '=' + ListingId+'&EmailType='+emailType);
}

function FetchAddress(listingID, ForArchive)
{
  open(VirtDir + '/listings/view_listing_show_address.asp?ListingID=' + listingID + '&ForArchive=' + (ForArchive ? 1 : 0),
       'vl_address_iframe');
}

// val - 0 lub 1
function VLMiniSearchSetFeatured(val)
{ 
  BackASPSubmitForm(vl_form, '//listings/MiniSearchSetFeatured.asp',
    'MSFPSetIDs=' + vl_form.elements[C_VL_ListingID].value + '&MSFPSetVal=' + val)
}

function ShowMUViewInNewWindow(multiListingID, action)
{
  open(action + '?' + C_MUVL_ListingID + '=' + multiListingID, '_blank');
}

function WriteMsgOnFullView(msg) {
  if(msg=='') document.getElementById('MesgDiv').innerHTML='';
  else document.getElementById('MesgDiv').innerHTML='<span class=InfoMsg>' + msg + '<\/span>';
}
    
function VLLMovieShow()
{
  var ytElem = document.getElementById('VLLMovieElement');
  document.getElementById('VLMainTable').style.visibility = 'hidden';
  ytElem.style.width = (document.getElementById('VLMainTable').offsetWidth) + 'px'; 
  ytElem.style.height = (document.getElementById('VLMainTable').offsetHeight) + 'px'; 
  ShowElement(ytElem);
}

function VLLMovieHide()
{
  var ytElem = document.getElementById('VLLMovieElement');
  if(ytElem) HideElement(ytElem);
  document.getElementById('VLMainTable').style.visibility = 'visible';
}

