
$(document).ready( function () {

 $('#barousel_thslide').barousel({
  navWrapper: '#thslide_barousel_nav .thslide_list',
  manualCarousel: 1,
  contentResize: 1,
  navType: 3,
  fadeInSpeed: 600,
  contentResizeSpeed: 600
 });

 $('#thslide_barousel_nav').thslide({
  itemVisible: 3,
  itemOffset: 178,
  scrollOver: 1,
  infiniteScroll: 0,
  slideSpeedSlow: 600,
  slideSpeedFast: 600
 });
 
 $("input.myaccount, textarea.myaccount")
  .focus(function() { $(this).addClass("myaccount_focus"); })
  .blur(function() { $(this).removeClass("myaccount_focus") });
});


function transacTypeChanged()
{
 $("#lf_furnished").css("display", $("#ac_lf_transactype").val() == 2 ? "table-row" : "none" );
 $("#lf_type").css("display", $("#ac_lf_transactype").val() == 1 ? "table-row" : "none" );
}



function TransacChanged()
{
 $("#label_furnish").css("display", $("#fs_transaction").val() == "2" ? "inline" : "none" );
 $("#s_FurnishedRent").css("display", $("#fs_transaction").val() == "2" ? "inline" : "none" );

 $("#label_new").css("display", $("#fs_transaction").val() == "1" ? "inline" : "none" );
 $("#s_NewProperty").css("display", $("#fs_transaction").val() == "1" ? "inline" : "none" );
}


function validForm()
{
 if( $("#ac_gender").val().trim().length == 0 )
 {
  $.prompt("The Title field is mandatory.");
  return;
 }

 $("#myaccount").submit();
}


function searchForm()
{
 if( $("#fs_transaction").val() == "0" )
 {
  $.prompt("The \"Looking for\" field is mandatory.");
  return;
 }
	 
 $("#searchForm").attr( "action", webDirectory + ($("#fs_transaction").val() == "1" ? "SaleListing" : "RentListing" ));
 $("#searchForm").submit();
}


function updateSearch()
{
 $.post( webDirectory + 'front/UpdateSearch',
  {transac: $("#fs_transaction").val() },
  function(res) {
   var selected = $("#s_PropertyTypeFK").val(); 
   $("#s_PropertyTypeFK").empty();
   for (var i in res.PropertyTypes)
   {
    $("#s_PropertyTypeFK").append( "<option value=\"" + i + "\"" + (selected==i ? " selected=\"selected\"" : "") + ">" + res.PropertyTypes[i] + "</option>" );
   }
   
   var selected = $("#s_Location").val(); 
   $("#s_Location").empty();
   var theObj = $("#s_Location");
   for (var i in res.Locations)
   {
    if( i == "d0" || i == "c0" ) {
	 $("#s_Location").append( "<optgroup label=\"" + res.Locations[i] + "\"></optgroup>" );
	 theObj = $("#s_Location").find('optgroup').last();
    } else {
	 theObj.append( "<option value=\"" + i + "\"" + (selected==i ? " selected=\"selected\"" : "") + ">" + res.Locations[i] + "</option>" );
    }
   }
  },
  'json');
}


function toggleOptions()
{
 $(".option_list").slideToggle("slow", "swing");
}



function validContactUs()
{
 if( $("#cu_name").val().trim().length == 0 )
 {
  $.prompt("Please type your Name.");
  return;
 }

 if( $("#cu_email").val().trim().length == 0 )
 {
  $.prompt("Please type your Email.");
  return;
 }

 if( $("#cu_message").val().trim().length == 0 )
 {
  $.prompt("Please type your Message.");
  return;
 }

 $("#contactus").submit();
}

