// displays hint text on any input element with the 'title' attribute set
$(document).ready(function() {
wireUpDisplayTextboxes();
wireUpDisplayTextArea();
});

function wireUpDisplayTextboxes() {
var el = $('input[Title]');

// show the display text
el.each(function(i) {
    $(this).attr('value', $(this).attr('title'));
});

// hook up the blur & focus
el.focus(function() {
    if ($(this).attr('value') == $(this).attr('title'))
        $(this).attr('value', '');
}).blur(function() {
    if ($(this).attr('value') == '')
        $(this).attr('value', $(this).attr('title'));
});
}

function wireUpDisplayTextArea() {
var el = $('textarea[Title]');

// show the display text
el.each(function(i) {
    $(this).attr('value', $(this).attr('title'));
});

// hook up the blur & focus
el.focus(function() {
    if ($(this).attr('value') == $(this).attr('title'))
        $(this).attr('value', '');
}).blur(function() {
    if ($(this).attr('value') == '')
        $(this).attr('value', $(this).attr('title'));
});
}

//// Tab News /////////
$(function() {  
	$('#promo_news').tabs({ fxAutoHeight: true });
});

//// Tab Search /////////
$(function() { 
	$('#search_form').tabs({ fxAutoHeight: true });
});
/*//// Swap Forminput ///////////////////////////*/
function swapus(){
document.getElementById("swapus").innerHTML = '' ;
document.getElementById("swapus").innerHTML = '<input name="password" type="password" id="passwd" title="--------------- ???????? ---------------">' ;
document.getElementById("passwd").focus();
document.getElementById("passwd").focus();
}

/*//// Banner Slide //////////////////////////////*/

	$(function(){
		$('#banner_slide').loopedSlider({
			autoStart: 5000

		});
	});
	
////// Jquery PNG Fix //////
$(function() {
	$.ifixpng('../images/pixel.gif'); 
	$('#login').ifixpng();
	$('#newsletter').ifixpng();
	$('#property_info_bg').ifixpng();
	$('#header_top').ifixpng();
	$('.comunity_sub').ifixpng();
	$('.knowledge_sub').ifixpng();
	$('.advice_sub').ifixpng();
});

/*//// Link Dropdown //////////////////////////*/
$(function() {
    $('#mlink,#menu_link').droppy();
  });

/*//// Jobs Position Accordian //////////////////////*/

$(document).ready(function(){
	
                $(".jobs_position h4:first").addClass("active");
                $(".jobs_position .jobscontent:not(:first)").hide();
                /*$(".jobs_position .jobscontent").hide();*/
                $(".jobs_position h4").click(function(){
                    $(this).next(".jobscontent").slideToggle("medium")
                    .siblings(".jobscontent:visible").slideUp("medium");
                    $(this).toggleClass("active");
                    $(this).siblings("h4").removeClass("active");
                });

            });

/*//// Downloads Accordian //////////////////////*/

$(document).ready(function(){
	
                $(".downloads_list h4:first").addClass("active");
                $(".downloads_list .downloads_content:not(:first)").hide();
                /*$(".jobs_position .jobscontent").hide();*/
                $(".downloads_list h4").click(function(){
                    $(this).next(".downloads_content").slideToggle("medium")
                    .siblings(".downloads_content:visible").slideUp("medium");
                    $(this).toggleClass("active");
                    $(this).siblings("h4").removeClass("active");
                });

            });

/*$(document).ready( function(){
  $('#news_list ul li').corners('4px');
  $('#news_list ul li.hover').corners('4px');
});*/
/*//// Popup Map ///////////////////////////////////////////*/
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
/*//// Float Box ////////////////////////////////////*/
(function($) {
$(document).ready(function() {
$("a.forgot").fancybox({
		'hideOnContentClick': false,
		'frameWidth'			: 440,
		'frameHeight'				:218,
		'overlayShow':		true,
		'padding' :  0,
		'overlayOpacity': 0.8
	});
$("#mail_btn").click(function() {
	email =  $('#email_subscribes').val() ;
	ischk = false ;
	
	if (( email  == '-------- อีเมล์แอดเดรสของท่าน ---------') ||  ( email  == '' )) {
		alert('กรุณากรอก อีเมล์');
		return false ;
		}
		
		isvalidemail = (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) ;
		
		if (!isvalidemail) {	
		alert('กรุณากรอก อีเมล์ ที่ถูกต้อง ');
		$('#email_subscribes').focus();
		return false ;			
		}
	
		
	ischk = $('#scancel').is(':checked');
	//alert(ischk);
	 if  (ischk){
	unsub = '1' ; 		 
		 }else {
	unsub = '0' ;  
		 }
		
    $('<a href="subscribe.php?q='+unsub+'|'+email+'">toiframe</a>').fancybox({
        'hideOnContentClick': false,
		'frameWidth'			: 440,
		'frameHeight'				:218,
		'overlayShow':		true,
		'padding' :  0,
		'overlayOpacity': 0.8
    }).click();
});
/*
$("#subscribe_form").click(function() {
    $('<a href="subscribe.php">dff</a>').fancybox({
        'hideOnContentClick': false,
		'frameWidth'			: 440,
		'frameHeight'				:218,
		'overlayShow':		true,
		'padding' :  0,
		'overlayOpacity': 0.8
    }).click();
});*/

});
})(jQuery);


/*//// BG Hover //////////////////////////////////////////*/
$(function() {
  $("#promo_news li,#announce_table tr,#persells li,#perrent li,.tPromotion .bgRow").hover(
   function() {
    $(this).addClass("hover");
   },
   function() {
    $(this).removeClass("hover");
   });
 });
/*//// List Box /////////////////////////////////////////*/
$(document).ready(function() {
  $('#checklist').hide();  
  $('#checklist_bg').hide();
  $('#searchlist1, #searchlist2, #searchlist3').click(function() {
    $('#checklist, #checklist_bg').slideToggle(300); 
	/*$(this).click(function() {
    $('#checklist').hide(); });*/
  });
  $('#apply_select').click(function() {
    $('#checklist, #checklist_bg').hide();
	var selt='';
		for(i=1;i<8;i++){
			if(document.getElementById('cat_'+i).checked){
				selt+=document.getElementById('cat_'+i).value+",";
			}
		}
		var cur_table=document.getElementById('cur_table').value;
		if(selt!=''){
			selt=selt.substr(0,(selt.length-1));	
			document.getElementById('cate'+cur_table).value=selt;
		}
		else{
			document.getElementById('cate'+cur_table).value='- ระบุประเภทอสังหาริมทรัพย์';
		}
  });
 
});
$(function(){
 
	$("#checkall").click(function(){
 
		$(":checkbox").attr("checked","checked");
 
	});
	$("#uncheckall").click(function(){
 
		$(":checkbox").attr("checked","");
 
	});

	$("#searchlist1").click(function(){
 
		$(":checkbox").attr("checked","");
 
	});
	
	$("#searchlist2").click(function(){ 
 
		$(":checkbox").attr("checked","");
 
	});
	
	$("#searchlist3").click(function(){
 
		$(":checkbox").attr("checked","");
 
	});
 
})

/*//// Start Bookmark //////////////////////////////////////////*/
function bookmark(url,title){
if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
window.external.AddFavorite(url,title);
} else if (navigator.appName == "Netscape") {
window.sidebar.addPanel(title,url,"");
} else {
alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
/*//// End Bookmark //////////////////////////////////////////*/
$(document).ready(function(){ 
$('#clickme').click();
}); 
