// JavaScript Document
$(document).ready(function(){
	$("#sent_to_fr").hover(
		function(){
			$(this).css({'cursor':'pointer','color':'#143264'});
		},
		function(){
			$(this).css({'color':'#333'});
		}
	);
	$("#sent_get_dr").hover(
		function(){
			$(this).css({'cursor':'pointer','color':'#143264'});
		},
		function(){
			$(this).css({'color':'#333'});
		}
	);
	$("#sent_to_fr").click(
		function(){
			$(this).fadeOut(500);
			$(this).fadeIn(500);
			if($("#blue_panel_1").is(":hidden")){
				$("#blue_panel_1").slideDown("slow");
				$("#blue_panel2").slideUp("slow");
				$("#blue_panel_1").css({'position':'absolute'});
			}else{
				$("#blue_panel_1").slideUp("slow");
				
			}
		}
	);
	$("#form1").submit(
		function(){
			var url = 'ajax_frSuggestEvent.php';
			var data_set = {f_name: $("#f_name").val(), f_mail: $("#f_mail").val(), t_name: $("#t_name").val(), t_mail: $("#t_mail").val(), vr_code: $("#vr_code").val(), hid_event: $("#hid_event").val(), info_inquiry: $("#info_inquiry").val()};
			$.post(
				url,
				data_set,
				function(resp){
					//alert($("#hid_event").val());
					//alert(resp);
					$("#blue_panel_1").slideUp("slow");
					$('#jresult').prepend(resp).show();
					$('#jresult').css({'color':'red'});
				}
			);
			return false;
		}
	);
	

	var end = new Date();
	$('#from_cat').change(function(){
		var cat = '';
		$('#from_cat option:selected').each(function () {
			cat += $(this).val();
		});
		
		
		
		var post_url = 'ajax_jSuggest.php?ts='+end.getTime();;
		var data_set = { todo_detail: cat}
		$.post(
			post_url ,
			data_set,
			function(resp){
				var txt = '';
				//alert(resp);
				//txt += "<ul>";
				
				//$('#business_name').val(resp);
				p = resp.split(",");
				$('#list_bus').remove();
				for(var i = 0; i<p.length; i++)
				{
					if(p[i]){
						q = p[i].split("|");
						txt += "<li><a href='javascript:void(0)' name='todo_id[]'>"+q[1]+"</a></li>";
					}
				}
				//txt += "</ul>";
				$('#result_bus').prepend("<ul id='list_bus'>"+txt+"<li><span>Powered By Indigomedia.co.th</span></li></ul>").slideToggle("slow");
			}
					 
		);
		
		// Test
		$('#result_bus').hide();	

		
	});
	
		$('[name^=todo_id]').live( 'click' , function(){
		//alert($(this).text());
		$('#business_name').val($(this).text());
		$('#result_bus').hide();
	});
	// Phuket Event Direction
	$("#sent_get_dr").click(
		function(){
			$(this).fadeOut(500);
			$(this).fadeIn(500);
			if($("#blue_panel2").is(":hidden")){
				$("#blue_panel2").slideDown("slow");
				$("#blue_panel_1").slideUp("slow");
				$("#blue_panel2").css({'position':'absolute'});
			}else{
				$("#blue_panel2").slideUp("slow");
			}
		}
	);
	
	$('#fcat').change(function(){
		var cat = '';
		$('#fcat option:selected').each(function () {
			cat += $(this).val();
		});
		$('#fromAddress').empty();
		//alert(cat);
		var post_url = 'ajax_getList.php?ts='+end.getTime();;
		var data_set = { todo_detail: cat}
		$.post(
			post_url ,
			data_set,
			function(resp){
				p = resp.split(",");
				for(var i = 0; i<p.length; i++)
				{
					q = p[i].split("|");
					if(q[0]){
						$('#fromAddress').append("<option value='" + q[0] + "'>" + q[1] + "</option>").show();
					}
				}
			}
		);			   
	});
});
