/*
   =============================================
   Project:		Laforêt
   Version:		1.0.0
   Author:		Paulo Mendes
*/

function page_RemoveBorder()
{
  $('#center').attr('id', 'blank');
}

function dialog_OnInit(w, h, src)
{
  var lb = document.createElement('div');
  var sw = doc_GetHeight();

  if (document.body.scrollHeight > sw) sw = document.body.scrollHeight;

  with (lb) {
    id = 'lightbox';
    style.height = sw + 'px';

    setAttribute("onclick", "dialog_OnUnload();");
  }

  document.body.appendChild(lb);

  dialog_OnLoad(w, h, src);
}

function dialog_OnLoad(w, h, s)
{
  var d = document.createElement('div');

  with (d) {
    id = 'dialog';

    style.width = w + 'px';
    style.height = h + 'px';

    style.top = ($(window).height() - h) / 2 + $(window).scrollTop() + 'px';
  }

  var cd = document.createElement('div');

  with (cd) {
    className = 'close';
    innerHTML = global_GetResource('IFrame', 'CLOSE');

    setAttribute("onclick", "dialog_OnUnload();");
  }

  d.appendChild(cd)

  var i = document.createElement('iframe');

  var mw = 4;
  var mh = 18;

  with (i) {
    width = (w - mw) + 'px';
    height = (h - mh) + 'px';

    setAttribute('frameborder', 0);
    setAttribute('scrolling', 'no');
    setAttribute('src', s);
  }

  d.appendChild(i);
  document.body.appendChild(d);
}

function dialog_OnUnload()
{
  document.body.removeChild(document.getElementById('lightbox'));
  document.body.removeChild(document.getElementById('dialog'));
}


/*
   =============================================
   UserControl: LaforetInTheWorld.ascx
   Pane:        Left
*/
$(function()
{
  $('.intheworld select').change(function() {
    if ($(this).attr("selectedIndex") > 0) window.open('http://' + $(this).val(), '_blank', '');
  });
});


/*
   =============================================
   UserControl: Header.ascx
   Pane:        Top
*/
var cn_CULTURE = 'CULTURE';

$(function()
{
  $('#header .language a').click(function()
  {
    if (!$.cookies.test()) return false;

    if (!$(this).attr('class')) {
      var e = new Date();
      e.setMonth(e.getMonth() + 1);
      
      $.cookies.set(cn_CULTURE, $(this).parent().attr('class'), { expiresAt: e });
      location.reload();
    }
  });
});



/*
=============================================
Group:       Facebook
UserControl: Facebook.ascx
Pane:        Content
*/

$(function ()
{
  var f = '#facebook ';

  $(f + 'p.group select').change(function ()
  {
    var v = ($(this)[0].selectedIndex == 0) ? -1 : $(this).attr('value');

    ddl_Types(f, v, $(f + 'input[name$="ucpLanguage"]').attr('value'), true);

    switch (parseInt($(this).attr('value'))) {
      case 0:
      case 222:
        $(f + 'p.typology select').removeAttr("disabled");
        break;

      default:
        ddl_Disable($(f + 'p.typology select'));
    }
  });

  $(f + 'p.district select').change(function ()
  {
    ddl_Counties(f, true, false, false, true);
  });

  $(f + 'p.county select').change(function ()
  {
    ddl_Parishes(f, true, false, false, true);
  });

  $(f + 'p.search a').click(function ()
  {
    if ($(f + 'p.reference input').val().length > 0) return true;

    var c = $(f + 'input[name$="ucpLanguage"]').attr('value');
    
    if (search_Validate(f + 'div.form fieldset:lt(2)')) {
      tooltip_OnLoad(document.getElementById($(this).attr('id')), global_GetResource('Facebook', 'REQUIRED', c));
      return false;
    }

    if (!search_Range(f, 'txtPriceMin', 'txtPriceMax', $(this), 'Facebook', 'PRICE', c)) return false;

    if (!search_Range(f, 'txtAreaMin', 'txtAreaMax', $(this), 'Facebook', 'AREA', c)) return false;

    return true;
  });
});
