$(document).ready(function(){
  $("#currency-converter").tooltip({
    effect: 'slide'
  }).dynamic({
    bottom: {
    direction: 'down',
    bounce: true
    }
  });

	$('#photos').galleryView({
		panel_width: 618,
		panel_height: 400,
		transition_interval: 0,
		frame_width: 100,
		frame_height: 100
	});

  swapValues = [];
  $(".swap_value").each(function(i){
      swapValues[i] = $(this).val();
      $(this).focus(function(){
          if ($(this).val() == swapValues[i]) {
              $(this).val("");
          }
      }).blur(function(){
          if ($.trim($(this).val()) == "") {
              $(this).val(swapValues[i]);
          }
      });
  });

	$('#submit1').click(function () {
		var reference_code1 = $('input[name=reference_code1]');
		var url1 = $('input[name=url1]');
		var email1 = $('input[name=email1]');
		var contact_type1 = $('input[name=contact_type1]');
		if (email1.val()=='') {
			email1.addClass('hightlight');
			return false;
		}else if (email1.val()=='Your Email Address') {
			email1.addClass('hightlight');
			return false;
		} else email1.removeClass('hightlight');
		var data = 'reference_code=' + reference_code1.val() + '&email=' + email1.val() + '&contact_type=' + contact_type1.val() + '&url=' +url1.val();
//		$('#text1).attr('disabled','true');
		$.ajax({
			url: "http://www.thailand-property-for-sale.net/process.php",
			type: "GET",
			data: data,
			cache: false,
			success: function (html) {
				if (html==1) {
					//hide the form
					$('#property_brochure_form').fadeOut('slow');
					$('#property_brochure_post').fadeIn('slow');
				} else if (html==2) {
				  alert('Sorry, you entered an invalid email address.');
				} else alert('Sorry, unexpected error. Please try again later.');
			}		
		});
		return false;
	});

	$('#submit2').click(function () {
		var reference_code2 = $('input[name=reference_code2]');
		var url2 = $('input[name=url2]');
		var email2 = $('input[name=email2]');
		var contact_type2 = $('input[name=contact_type2]');
		if (email2.val()=='') {
			email2.addClass('hightlight');
			return false;
		}else if (email2.val()=='Your Email Address') {
			email2.addClass('hightlight');
			return false;
		} else email2.removeClass('hightlight');
		var data = 'reference_code=' + reference_code2.val() + '&email=' + email2.val() + '&contact_type=' + contact_type2.val() + '&url=' +url1.val();
//		$('#text2').attr('disabled','true');
		$.ajax({
			url: "http://www.thailand-property-for-sale.net/process.php",
			type: "GET",
			data: data,
			cache: false,
			success: function (html) {
				if (html==1) {
					//hide the form
					$('#property_alert_form').fadeOut('slow');
					$('#property_alert_post').fadeIn('slow');
				} else if (html==2) {
				  alert('Sorry, you entered an invalid email address.');
				} else alert('Sorry, unexpected error. Please try again later.');
			}		
		});
		return false;
	});
});

function showContentNoFocus(showId) {
	var element = document.getElementById(showId);
	if (!element)
		return true;
	if (element.style.display == "none") {
		element.style.display = "block";
	} else {
		element.style.display = "block";
	}
	return true;
}

// hides the content
function hideContent(hideId) {
	var e = document.getElementById(hideId);
	if (e.style.display == "block") {
		e.style.display = "none";
	} else {
		e.style.display = "none";
	}
	return true;
}

function divScroll(divId, value)
{
	var element = document.getElementById(divId);
	element.scrollTop += value;
	
}

function divScrollTop(divId, value)
{
	var element = document.getElementById(divId);
	element.scrollTop -= value;
}
