 $(document).ready(function() {
	/* rate popup */
	$('.v-item .dorate').click(function() {                
		pop = $('#rate-popup');
		pop.hide();
		$(this).parent().parent().append(pop);
		pop.fadeIn('fast');                
	});
	$('#rate-popup .btclose').click(function() {$('#rate-popup').fadeOut('fast')});
	$('#rate-popup .user-rating a').click(function() {            
		var point=0;
		switch ($(this).attr('class')) {
			case 'one-star':point=1;break;
			case 'two-stars':point=2;break;
			case 'three-stars':point=3;break;
			case 'four-stars':point=4;break;
			case 'five-stars':point=5;
		}
		//do something with point here
                var ul = $(this).parent().parent();
                var userid = ul.attr('id');
                var videoid = ul.parent().parent().attr('id');                
                ajax.DoRating(videoid, userid, point);		
		$('#rate-popup').fadeOut('fast');
		
	});

        //process in detailvideo page
        $('.action .cmt').click(function() {            
		pop = $('#rate-popup');                		
		pop.fadeIn('fast');
	});        
        
	/* search option */
	$('#btsearch-opt-top').click(function() {$('#search-pop-btm').hide();$('#search-pop-top').fadeIn('fast');});
	$('#btsearch-opt-btm').click(function() {$('#search-pop-top').hide();$('#search-pop-btm').fadeIn('fast');});
	$('.search-pop a').click(function() {$('.search-pop').hide();});
	$('body').click(function() {$('.search-pop').hide();});
	//emoticons
	$('.emo-list a').click(function() {
                var txtControl = document.getElementById("txtComment");
                if (txtControl.value.length + $(this).attr('id').length < 1000)
                {
                    txtControl.value += $(this).attr('id');
                    txtControl.focus();
                    document.getElementById("spCount").innerHTML = 1000 - txtControl.value.length;
                }                		
		$('#emo-pop').fadeOut('fast')
	});
	
 });

 function showEmoticonPop() {
	pop = $('#emo-pop');
	if (pop.css('display') == 'none') 
		pop.fadeIn('fast');
 }

function GotoForum()
{        
    window.open("http://forum.megavstar.vn");
}
function AddVideoToMyChannelCallback(sourceImageId)
{
    var target = document.getElementById(sourceImageId);
    if (target != null) target.className = "addfav";
}
function AddVideoToMyChannel(userid, videoid, sourceImageId)
{
    if (userid == null || videoid == null) return;
    var target = document.getElementById(sourceImageId);
    if (target != null) target.className = "addingfav";
    ajax.AddVideoToMyChannel(userid,videoid, sourceImageId, AddVideoToMyChannelCallback);
}

function RemoveVideoFromMyChannel(userid, videoid)
{
    if (userid == null || videoid == null) return;    
    ajax.RemoveVideoFromMyChannel(userid,videoid);
    var video = document.getElementById(videoid);
    if (video != null)
    {
        var parent = video.parentNode;
        if (parent != null) parent.removeChild(video);
    }
}
function DownloadCount()
{
    ajax.DownloadCount();
}
function DisableOnSubmit(target)
{
    target.disabled = true;
}
function ShowPlay(me)
{    
    var parent = me.parentNode;    
    var spanElement = document.getElementById("playbutton");    
    spanElement.parentNode.removeChild(spanElement);    
    parent.appendChild(spanElement);    
    spanElement.style.display = "";
}
function HidePlay()
{
    var spanElement = document.getElementById("playbutton");
    spanElement.style.display = "none";
}
function DoSearch(me, option)
{     
    if (document.getElementById(option).className == 'active')
    {
        me.action += '?option=' + 'video';
    }
    else
    {
        me.action += '?option=' + 'actor';
    }
}
function SearchOption(me, nextid)
{
    me.className = "active";
    var next = document.getElementById(nextid);
    if (next != null)
    {
        next.className = "last";
    }
}
function SearchOptionClick(evt)
{
    evt.cancelBubble = true;
}
function Register()
{
    var element = document.getElementById("submit");
    if (element != null) element.disabled = true;
    element =  document.getElementById("username");
    if (element != null) element.readOnly = true;
    element = document.getElementById("pass");
    if (element != null) element.readOnly = true;
    element = document.getElementById("repass");
    if (element != null) element.readOnly = true;
    element = document.getElementById("email");
    if (element != null) element.readOnly = true;
    element = document.getElementById("reemail");
    if (element != null) element.readOnly = true;
    element = document.getElementById("confirmcode");
    if (element != null) element.readOnly = true;
    element = document.getElementById("progressreg");
    if (element != null) element.style.display = "";
}
function setHomePage(source)
{    
    source.style.behavior='url(#default#homepage)';
    source.setHomePage('http://megavstar.vn');
}
function ShowDate(strLang)
{
    var d, day, month, date, x, y, h;
    if (strLang == 'vn') {
        var x = new Array("Chủ nhật", "Thứ hai", "Thứ ba");
        var x = x.concat("Thứ tư", "Thứ năm", "Thứ sáu", "Thứ bảy");
    }
    else {
         var x = new Array("Sun", "Mon", "Tue");
         var x = x.concat("Wed", "Thus", "Fri", "Sat");
    }
    //var x = x.concat("Thứ bảy");
    var y = new Array("1", "2", "3");
    var y = y.concat("4", "5", "6");
    var y = y.concat("7", "8", "9");
    var y = y.concat("10", "11", "12");
    d = new Date();
    day = d.getDay();
    year = d.getFullYear();
    month = d.getMonth();
    date = d.getDate();
    document.write('<div>');
    document.write(x[day]);
    document.write(',  ' + date + '/' + y[month] + '/' + year + '&nbsp;&nbsp;');
    document.write('</div>');
}
function setContentNews()
{    
    var element = document.getElementById("contentnews");
    if (element != null)
    {
        var content = element.innerHTML;
        while(content.indexOf('&lt;') >=0) content = content.replace('&lt;', '<');
        while(content.indexOf('&gt;') >=0) content = content.replace('&gt;', '>');
        while(content.indexOf("&amp;nbsp;") >=0) content = content.replace("&amp;nbsp;", "&nbsp;");
        element.innerHTML = content;
    }
}
function SystemPay()
{
    var element = document.getElementById("bill");
    if (element != null)
    {        
        element.style.display = "";
    }
    else alert("Bạn phải đăng nhập trước khi đăng kí sử dụng.")
        
}
function HiddenBill()
{
    var element = document.getElementById("bill");
    if (element != null)
    {
        element.style.display = "none";
    }    
}