//RATE CLIP, MOVIE, ACTOR
function rate_update(target, id, vote) {
	if(target == 'clip' || target == 'dvd' || target == 'actor'){
		if(id == ''){
			alert(mess_err_form);
			return 0;
		}
	}
	else{
		alert(mess_err_form);
		return 0;
	}

	$.getJSON("json/rate.php",{target:target, id:id, vote:vote}, print_rate_result);
	//alert("json/rate.php?id="+id+"&pass_site_id="+site_id+"&target="+target+"&vote="+vote);

}

function print_rate_result(vote){
	if(vote.result == 1){
		//showContent('thx_voted_' + vote.id);
		alert(mess_thx_vote);
	}
	else if(vote.result == 2){
		alert(mess_already_update);
	}
	else{
		alert(mess_err_vote);
	}
}

//ADD FAVORITE CLIP, MOVIE, ACTOR
function add_favorite(target, id) {
	if(target == 'clip' || target == 'dvd' || target == 'actor'){
		if(id == ''){
			alert(mess_err_form);
			return 0;
		}
	}
	else{
		alert(mess_err_form);
		return 0;
	}

	$.getJSON("json/add_favorites.php",{target:target, id:id}, print_favorite_result);
	//alert("json/add_favorites.php?id="+id+"&pass_site_id="+site_id+"&target="+target);
}

function print_favorite_result(entry){
	if(entry.result == 1){
		alert(mess_thx_fav);
	}
	else if(entry.result == 2){
		alert(mess_already_fav);
	}
	else{
		alert(mess_err_fav);
	}
}

//USER ACCOUNT & LANGUAGE
function set_language(id){

	if(id == ''){
		alert(mess_err_empty);
		return 0;
	}

	// We must use a POST request here because IE caches our json query.
	// By using a post, we are sure the set_language.php always gets called to save the user language preference.
	// The two other alternative is to pass a random value as parameter or set the meta no cache to the page.
	// ref: http://ajaxian.com/archives/ajax-ie-caching-issue

	//$.getJSON("json/set_language.php",{id:id}, print_language_result);
	$.post("json/set_language.php",{id:id}, print_language_result,"json");
	//window.location.reload(true);

}

function print_language_result(entry){
	if(entry.result == 1){
		//alert(mess_thx_lang);

		// PATCH :  We must reload the page when a user changes his language.
		//			For some reason the javascript reload will only work here after the alert.
		//			Perhaps we should revove the alert entirely when it is a success and simply
		//			let the page refresh (the refresh command in the calling function set_language()).
		window.location.reload(true);

	}
	else{
		alert(mess_err_lang);
	}
}

