// version 1.0 t
function focus_login(el,option,val){ // for username & password text show
	if(option == 1){ // on focus input
		el_val = document.getElementById(el).value;
		if(el_val == val){
			document.getElementById(el).value = "";
		}
	}
	if(option == 0){ // on blur input
		el_val = document.getElementById(el).value;
		if(el_val == ""){
			document.getElementById(el).value = val;
		}
	}
	if(option == 3){ // on focus input password
		//document.getElementById(el).type = "password" ;
		el_val = document.getElementById(el).value;
		if(el_val == val){			
			document.getElementById(el).value = "";
		}
	}
}

function check_local(value){
	if(value == 0){
		$("#tab_region").css("display","none");
		$("#tab_continent").css("display","table-row");
	}else if(value == 1){
		$("#tab_region").css("display","table-row");
		$("#tab_continent").css("display","none");
	}
}

$(document).ready(function(){
		MM_preloadImages('images/bg.jpg','images/menu_bg.jpg','images/header_r1_c10_f2.jpg','images/header_r4_c9.jpg','images/header_r1_c14_f2.jpg','images/header_r1_c17_f2.jpg','images/header_r1_c20_f2.jpg','images/header_r1_c25_f2.jpg','images/main_menu_r1_c1_f2.jpg','images/main_menu_r1_c3_f2.jpg','images/main_menu_r1_c5_f2.jpg','images/main_menu_r1_c8_f2.jpg','images/main_menu_r1_c10_f2.jpg','images/main_menu_r1_c12_f2.jpg','images/main_menu_r1_c14_f2.jpg','images/main_menu_r1_c16_f2.jpg','images/main_menu_r1_c18_f2.jpg','images/main_menu_r1_c20_f2.jpg','images/left_r4_c5_f2.jpg','images/left_r6_c5_f2.jpg','images/regis_button_f2.jpg','images/ns_club_banner_f2.jpg','images/more_f2.jpg');
				   
		$("input[type=text],input[type=password],input[type=email],textarea,select").focus(function () {
			$(this).addClass('input_focus');
		});
		$("input[type=text],input[type=password],input[type=email],textarea,select").blur(function () {
			$(this).removeClass('input_focus');
			$(this).removeClass('input_alert');
		});
		
		$(".btn_search").hover(
			function () {
			  $(this).attr("src", "images/left_r6_c5_f2.jpg");
			  $(this).css("cursor","pointer");
			}, 
			function () {
			  $(this).attr("src", "images/left_r6_c5.jpg");
			}
		);
		$("#btn_main_search").hover(
			function () {
			  $(this).attr("src", "images/left_r4_c5_f2.jpg");
			  $(this).css("cursor","pointer");
			}, 
			function () {
			  $(this).attr("src", "images/left_r4_c5.jpg");
			}
		);
		$("#btn_enews").hover(
			function () {
			  $(this).attr("src", "images/regis_button_f2.jpg");
			  $(this).css("cursor","pointer");
			}, 
			function () {
			  $(this).attr("src", "images/regis_button.jpg");
			}
		);
		$("#btn_main_search").click(function() {
			$("#frm_search").submit();
		});
		$("#btn_key_search").click(function() {
			$("#frm_search").submit();
		});
		
		$("#frm_enews").submit(function() {
			$.post("scripts/ajax-enews.php", $("#frm_enews").serialize(),
				function(data){
					if(data.chk_result == 0){
						$("#span_e_result").html("กรุณาใส่อีเมล");
					}else if(data.chk_result == 1){
						$("#span_e_result").html("กรุณาใส่อีเมลให้ถูกต้อง");
					}else if(data.chk_result == 2){
						$("#span_e_result").html("อีเมลนี้เคยสมัครแล้ว");
					}else if(data.chk_result == 9){
						$("#span_e_result").html("สมัครสมาชิกเรียบร้อย");
					}
					// add effect
					$("#div_frm_enews").fadeToggle("slow", function() {
					 	$("#div_result_enews").fadeToggle("slow", "linear");
						$("#div_result_enews").queue(function () {
							$("#frm_enews")[0].reset();
							$(this).delay(3000).fadeToggle("slow", function() {
								$("#div_frm_enews").fadeToggle("slow", "linear");
							});
							$(this).dequeue();
						});
					});
				 //alert(data.chk_result); // John
				 //console.log(data.time); //  2pm
				}, "json");
			return false;
		});
});
