function load_content(div_return, url)
{
	//var waiting = false;
	//if(arguments[2] == true) waiting = true;
	//if(waiting == true) $('#waiting').show();
	
	$("#"+div_return).load(url, function() {
    	//$('#waiting').fadeOut();
	});
}

function views_photo(img_path, img_name, user, desc, date)
{
	document.getElementById('big_thumb_photos').src=''+img_path+'';
	$('#user_create_img').text(user);
	$('#desphoto').text(desc);
	$('#img_name').text(img_name);
	$('#time_date').text(date);
}


function vote(id,type)
{
	//alert(id);
	$.post(base_url+'home/vote', 'id='+id+'&type='+type, function(msg) {
		if(msg == "yes") {
			
			load_content('row_'+id, base_url+'home/load_vote/'+id);
            $('.linecate2').has('#row_'+id).css('background-color', '#FFFFE0');
		}
		else
			alert(msg);
	});
}

function on_submit()
{
	//alert("");return false;
	if($('input[name=agreed]').is(':checked')) return true;
	else 
	{
		$("#d_agreed").css('display','block');
		$("#d_agreed").html('<b>You not tick on " I have read and agreed with your Terms & Conditions and Privacy Policy"</b>');
		$('input[name=agreed]').focus();
		return false;
	}

}

$(document).ready(function() {
	$("#btn_send_news").click(function(){
		$.post(base_url+'home/add_news_letter', 'email='+$("#email_news_letter").val(), function(msg) {
			if(msg == 'yes') alert('success!');
			else alert(msg);
			return false;
		});	
	});
	
	$("input, select, textarea").focusin(function(){
		var id = $(this).attr('id');
		$('#error_' + id).hide();

		if(id == 'upload_pid') $('#error_upload_did').hide();
		else if(id == 'upload_cid') $('#error_upload_sub_cid').hide();
        else if(id == 'unit_price' || id == 'price' || id == 'mode_price') $('#error_option_price').hide();
		
		$('#tip_' + id).show();
	});
	
	$("input, select, textarea").focusout(function(){
		var id = $(this).attr('id');
		$('#tip_' + id).hide();
	});
	
	$("#view_all").click(function(){
		$(".weather>li").css("display",'block');
	});
	
	//$(".view_map").colorbox();
});

function login(url_referrer)
{
	data={};
	data['email']	=	$("#lo_email").val();
	data['pass']	=	$("#lo_pass").val();
	$.post(base_url + 'user/login/', data, function(msg){
		if(msg == 'yes')
			location.href=url_referrer;
		else
			alert('Email or password is incorrect!');
	});
}

function add_wishlist(tour_id)
{
	var url = '';
	url	=	base_url + 'add_wishlist/' + tour_id;
	$.ajax({
		  url: url,
		  success: function(msg){
			if(msg == 'true'){
				$(this).addClass('add');
				alert('Success!');
			}else if(msg == 'no'){
				alert('Not login!');
			}
			else if(msg == 'false'){
				alert('Try again!');
			}
			else if(msg == 'existed'){
				alert('Tour is existed in your wishlist!');
			}
		  }
	});
}

function search()
{
	window.location =  base_url + 'search/?dest='+$("#dest").val()+'&style='+$("#style").val();
}

function quick_search(dest,style)
{
	window.location=base_url+'search/?dest='+dest+'&style='+style;
}


function get_rate(id)
{
	var url = '';
	url = base_url + "get_rate";
	$.ajax({
		type: "GET",
		url: url,
		data: "id="+id,
		cache: false,
		async: false,
		success: function(result) {
			// apply star rating to element
			//alert(result);
			//result = 70;
			$("#current-rating"+id).css({ width: "" + result + "%" });
		},
		error: function(result) {
			alert("some error occured, please try again later");
		}
	});
}

function rate(id,m)
{
	var url = '';
	url = base_url + "rate";
	$.ajax({
		type: "GET",
		url: url,
		data: "rating="+m+"&do=rate&id="+id,
		cache: false,
		async: false,
		success: function(result) {
			// remove #ratelinks element to prevent another rate
			$("#ratelinks"+id).remove();
			// get rating after click
			//alert(result);
			get_rate(id);
		},
		error: function(result) {
			alert("some error occured, please try again later111");
		}
	});
}
