﻿// +-------------------------------------------------------+ //
// +-------------------------------------------------------+ //
// +-------------------------------------------------------+ //
/*##############################
# JQUERY LOADING
##############################*/
function jquery_loading(element) 
{
	$(element).show().fadeOut('slow');
}
/*##############################
# SEARCH
##############################*/
function do_search() 
{
	keyword = encodeURIComponent($('#keyword').val());
	type = $('#type').val();
	if (keyword) window.location.href = _WEBSITE_URL+'?do=movie&type='+type+'&search='+keyword;
	return false;
}
/*##############################
# POLL
##############################*/
function do_poll(questions_id, answer_id)
{   
	$.post
	(
	       _WEBSITE_URL+'index.php',
		   {
			    poll: true,
				questions_id: questions_id,
				answer_id: answer_id
		   },
		   function(data)
		   {
		        $('#poll_loading').html(data);
				jquery_loading('#loading-layer');
		   }
	);
   return false;
}
/*##############################
# CAPTCHA
##############################*/
function captcha(id, src_name)
{ 
	var captcha = $(id);
    var a = new Date();
    var ms = a.getMilliseconds();
    var s = a.getSeconds();
    var mn = a.getMinutes();
    var h = a.getHours();
    var d = a.getDay();
    var m = a.getMonth();
    var y = a.getFullYear();
    var t = y+'.'+m+'.'+d+'-'+h+':'+mn+':'+s+':'+ms;
	captcha.attr('src', src_name+'&ts='+t);
    return false;
}
/*##############################
# RATE
##############################*/
function do_rate(movie_id, point) 
{
	$.post
	(
		   _WEBSITE_URL+'index.php',
		   {
				rate: true,
				movie_id: movie_id,
				point: point
				
		   },
		   function (data) 
		   {
			   $('#rate_loading').html(data);
			   jquery_loading('#loading-layer');
		   }
	);
}


    // pre-fetch image
    (new Image()).src = RATE_OBJECT_IMG;
    (new Image()).src = RATE_OBJECT_IMG_BG;
	
	function show_star(starNum,rate_text) 
	{
		remove_star();
		document.getElementById('rate_text_d').innerHTML = '<sup>'+rate_text+'</sup>';
		full_star(starNum);
	}
	
	function full_star(starNum) 
	{
		for (var i=1; i<=starNum; i++)
		{
			document.getElementById('star'+i).src = RATE_OBJECT_IMG;
		}
	}
	function remove_star() 
	{
		for (var i=1; i<=5; i++)
		{
			document.getElementById('star'+i).src = RATE_OBJECT_IMG_BG;
		}
	}
	function show_rating_process() 
	{
		if (document.getElementById('rating_process')) document.getElementById('rating_process').style.display = 'block';
		if (document.getElementById('rate_s')) document.getElementById('rate_s').style.display = 'none';
	}
	function hide_rating_process() 
	{
		document.getElementById('rating_process').style.display = 'none';
		if (document.getElementById('rate_s')) document.getElementById('rate_s').style.display = 'block';
	}
/*##############################
# POPUP
##############################*/
function do_popup(obj, url, width, height)
{
    obj.href='javascript://';
    if (width == null)  width  = 800;
	if (height == null) height = 300;
    window.open(url, 'newwin', 'fullscreen=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+width+',height='+height);
}
