/* Javascript */

/* JQuery */

$(function(){	
	
	$('a[href=#top]').click(function(){
        $('html, body').animate({scrollTop:0}, 'slow');
        return false;
    });
	$('a[href=#category]').click(function(){
        //$('html, body').animate({scrollBottom:0}, 'slow');
		$('html, body').animate({scrollTop: $(".category").offset().top});
        return false;
    });

	$("div.contact p.head").click(function(){
        $("#formcontact").slideToggle();
        return false;
    });

	$("a#checkalert").click(function(){
        $("#formalert").slideToggle();
        return false;
    });
	
	$('select#province').change(function(){
		$.ajax({
		  url: root+"/lib/amphur.php",
		  data: "province="+$('select#province').val(),
		  success: function(result){
			$('span#show_amphur').html(result);
		  }
		});
	});

	$('#category').change(function(){
		$.ajax({
		  url: root+"/lib/subcategory.php",
		  data: "category="+$('#category').val()+"&style=text150",
		  success: function(result){
			$('span#show_subcategory').html(result);
		  }
		});
	});

	$('#SearchButton').click(function(){
		if($('#price').val() && isNaN($('#price').val())){
			alert("ราคาต้องเป็นตัวเลข เช่น 1500");
			$('#price').val('');
			return false;
		}else{
			$('#formsearch').submit();
		}
	});
	
	$('select#city').change(function(){
		$.ajax({
		  url: root+"/lib/district.php",
		  data: "province="+$('select#city').val(),
		  success: function(result){
			$('span#show_district').html(result);
		  }
		});
	});

});

function ShowPhoto(source){
	$(".photobig img").attr("src",source);
	return false;
}

function checkfiletype(file) {
    var extension = file.substr( (file.lastIndexOf('.') +1) );
	if(extension=="jpg" || extension=="jpeg" || extension=="png" || extension=="gif"){
		return true;
	}else{
		return false;
	}
}

