function setHomePage() {
    if (document.all) {
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage('http://luocbao.com/');
    }
    else if (window.sidebar) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                alert("Trình duyệt của bạn không hỗ trợ tính năng này!");
            }
        }
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
        prefs.setCharPref('browser.startup.homepage', 'http://luocbao.com/');
    }
}
 function lienhe(){
    $("#lienhe").colorbox({
        width:"600", height:"350", iframe:true,
        onClosed:function(){ location.reload(); }
    });                               
 }
 function updatequantri(id){
    $("#updatequantri"+id).colorbox({
        width:"400", height:"450", iframe:true,
        onClosed:function(){ location.reload(); }
    });                               
 }
function timkiem(){
      var key =$('#key').val();
      $(window.location).attr('href',url+'timkiem/'+key);
}
function poll(){
    
    var loader=$('#loader');
    var pollcontainer=$('#pollcontainer');
    loader.fadeIn();
    //Load the poll form
    $.get(url+'poll', '', function(data, status){
        pollcontainer.html(data);
        animateResults(pollcontainer);
        pollcontainer.find('#viewresult').click(function(){
            //if user wants to see result
            loader.fadeIn();
            $.get(url+'index.php', 'c=poll&result=1', function(data,status){
                pollcontainer.fadeOut(1000, function(){
                    $(this).html(data);
                    animateResults(this);
                });
                loader.fadeOut();
            });
            //prevent default behavior
            return false;
        }).end()
        .find('#pollform').submit(function(){
            var selected_val=$(this).find('input[name=poll]:checked').val();
            if(selected_val!=''){
                //post data only if a value is selected
                loader.fadeIn();
                $.post(url+'poll', $(this).serialize(), function(data, status){
                    $('#formcontainer').fadeOut(100, function(){
                        $(this).html(data);
                        animateResults(this);
                        loader.fadeOut();
                    });
                });
            }
            //prevent form default behavior
            return false;
        });
        loader.fadeOut();
    });
    
    function animateResults(data){
        $(data).find('.bar').hide().end().fadeIn('slow', function(){
                            $(this).find('.bar').each(function(){
                                var bar_width=$(this).css('width');
                                $(this).css('width', '0').animate({ width: bar_width }, 1000);
                            });
                        });
    }
    
}
// Ma bao ve
function mabaove(){
    
    $.post(url+"ajax/mabaove",{},function(data)
    {
        $("#maso").html(data);                                               
    });    
}


/*****APP*********/
function getFacebook(id){
    $("#facebook").html('<div align="center"><img align="center" src="'+url+'site/templates/images/loading.gif"></div>');
    $.post(url+"ajax/facebook",{'id':id},function(data)
    {
        $("#facebook").html(data);                                               
    });    
}
function getThoitiet(id){
    $("#thoitiet").html('<div align="center"><img align="center" src="'+url+'site/templates/images/loading.gif"></div>');
    $.post(url+"ajax/thoitiet",{'id':id},function(data)
    {
        $("#thoitiet").html(data);                                               
    });    
}
function getChungkhoan(id){
    $("#chungkhoan").html('<div align="center"><img align="center" src="'+url+'site/templates/images/loading.gif"></div>');
    $.post(url+"ajax/chungkhoan",{'id':id},function(data)
    {
        $("#chungkhoan").html(data);                                               
    });    
}
function getThoitiet(id){
    $("#thoitiet").html('<div align="center"><img align="center" src="'+url+'site/templates/images/loading.gif"></div>');
    $.post(url+"ajax/thoitiet",{'id':id},function(data)
    {
        $("#thoitiet").html(data);                                               
    });    
}
function getTruyenhinh(id){
    $("#truyenhinh").html('<div align="center"><img align="center" src="'+url+'site/templates/images/loading.gif"></div>');
    $.post(url+"ajax/truyenhinh",{'id':id},function(data)
    {
        $("#truyenhinh").html(data);                                               
    });    
}
function getxoso(id){
    $("#xoso").html('<div align="center"><img align="center" src="'+url+'site/templates/images/loading.gif"></div>');
    $.post(url+"ajax/xoso",{'id':id},function(data)
    {
        $("#xoso").html(data);                                               
    });    
}
function getgiavang(id){
    $("#giavang").html('<div align="center"><img align="center" src="'+url+'site/templates/images/loading.gif"></div>');
    $.post(url+"ajax/giavang",{'id':id},function(data)
    {
        $("#giavang").html(data);                                               
    });    
}
function gettygia(id){
    $("#tygia").html('<div align="center"><img align="center" src="'+url+'site/templates/images/loading.gif"></div>');
    $.post(url+"ajax/tygia",{'id':id},function(data)
    {
        $("#tygia").html(data);                                               
    });    
}
/********END APP*********/
function addFavorite() {
    var title = "Lược báo - Chọn tin nhanh - Cập nhật sớm ";
    if (document.all) {
        window.external.AddFavorite('http://www.luocbao.com/', title);
    } else if (window.sidebar) {
        window.sidebar.addPanel(title, 'http://www.luocbao.com/', "");
    }
}

function getrating(id){
    $("#rating_news").html('<div align="center"><img align="center" src="'+url+'site/templates/images/loading.gif"></div>');
    $.post(url+"ajax/rating",{'id':id},function(data)
    {
        $("#rating_news").html(data);                                               
    });    
}
function getcomment(id){
    $("#comment_news").html('<div align="center"><img align="center" src="'+url+'site/templates/images/loading.gif"></div>');
    $.post(url+"ajax/comment",{'id':id},function(data)
    {
        $("#comment_news").html(data);                                               
    });    
}

function addcomment(id){
    var fullname = $('#fullname').val();
    var email = $('#email').val();
    var tieude = $('#tieude').val();
    var content = $('#content').val();
    var mabaove = $('#mabaove').val();
    var noidung ='Vui lòng viết bằng tiếng việt có dấu, không dùng từ ngữ đả kích thậm tệ.'
    if(fullname =='' || email =='' || content==noidung || content =='' || tieude=='' || mabaove == ''){
        alert('Vui lòng điền đầy đủ thông tin');   
    }else if(!isValidEmailAddress(email)){
        alert('Email không đúng.');
    }else{
        $("#load").html('<div align="center"><img align="center" src="'+url+'site/templates/images/loading.gif"></div>');
        $.post(url+"ajax/addcomment",{'fullname':fullname,'email':email,'content':content,'id':id,'mabaove':mabaove,'tieude':tieude},function(data)
        {
            if(data!='error'){
                alert('Gửi bình luận thành công. Bình luận của bạn cần duyệt');
                $('#fullname').val('');
                $('#email').val('');
                $('#content').val('');
                $('#tieude').val('');
                $('#mabaove').val('');
                getcomment(id);
            }else{
                
                alert('Gửi bình luận không thành công!');
                 $.post(url+"ajax/mabaove",{},function(data)
                    {
                        $("#maso").html(data);                                               
                    });    
                document.getElementById('fullname').value = fullname;
                document.getElementById('email').value = email;
                document.getElementById('content').value = content;
                document.getElementById('tieude').value = tieude;
               $("#load").html(''); 
                
            } 
            $("#load").html('');                                              
        });
   }    
}
function isValidEmailAddress(email) {
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
return pattern.test(email);
}

function resetcomment(){
    $('#fullname').val('');
    $('#email').val('');
    $('#content').val('');                                                  
    $('#mabaove').val('');                                                  
    $('#tieude').val('');                                                  
}
function mycarousel_initCallback(carousel)
{
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });
    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};
jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        auto: 5,
        wrap: 'last',
        scroll:1,
        initCallback: mycarousel_initCallback
    });
});

$(document).ready(function() {

    //When page loads...
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content

    //On Click Event
    $("ul.tabs li").click(function() {

        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active ID content
        return false;
    });

});
$(document).ready(function(){
    var newsoption1 = {
        firstname: "mynews",
        secondname: "showhere",
        thirdname:"news_display",
        fourthname:"news_button",
        newsspeed:'7000',
        effectis:'4',
        mouseover:false,
        newscountname:"test",
        disablenewscount:false
    }
    $.init_news(newsoption1);
});
$(document).ready(function(){
    var newsoption2 = {
        firstname: "mynews1",
        secondname: "showhere1",
        thirdname:"news_display",
        fourthname:"news_button",
        newsspeed:'7000',
        effectis:'4',
        mouseover:false,
        newscountname:"test",
        disablenewscount:false
    }
    $.init_news(newsoption2);
});
(function($) {

    $.fn.easySlider = function(options){
      
        // default configuration properties
        var defaults = {            
            prevId:         'prevBtn',
            prevText:         'Previous',
            nextId:         'nextBtn',    
            nextText:         'Next',
            controlsShow:    true,
            controlsBefore:    '',
            controlsAfter:    '',    
            controlsFade:    true,
            firstId:         'firstBtn',
            firstText:         '',
            firstShow:        true,
            lastId:         'lastBtn',    
            lastText:         '',
            lastShow:        true,                
            vertical:        false,
            speed:             0,
            auto:            true,
            pause:            5000,
            t1:              0,
            t2: 500,
            continuous:        true
        }; 
        
        var options = $.extend(defaults, options);  
                
        this.each(function() {  
            var obj = $(this);                 
            var s = $("li", obj).length;
            var w = $("li", obj).width(); 
            var h = $("li", obj).height(); 
            obj.width(w); 
            obj.height(h); 
            obj.css("overflow","hidden");
            var ts = s-1;
            var t = 0;
            $("ul", obj).css('width',s*w);            
            if(!options.vertical) $("li", obj).css('float','left');
            
            if(options.controlsShow){
                var html = options.controlsBefore;
                if(options.firstShow) html += '<span id="'+ options.firstId +'"><a href=\"javascript:void(0);\">'+ options.firstText +'</a></span>';
                html += ' <span id="'+ options.prevId +'"><a href=\"javascript:void(0);\"></a></span>';
                html += ' <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\"></a></span>';
                if(options.lastShow) html += ' <span id="'+ options.lastId +'"><a href=\"javascript:void(0);\">'+ options.lastText +'</a></span>';
                html += options.controlsAfter;                        
                $(obj).after(html);                                        
            };
    
            $("a","#"+options.nextId).click(function(){        
                animate("next",true);
            });
            $("a","#"+options.prevId).click(function(){        
                animate("prev",true);                
            });    
            $("a","#"+options.firstId).click(function(){        
                animate("first",true);
            });                
            $("a","#"+options.lastId).click(function(){        
                animate("last",true);                
            });        
            
            function animate(dir,clicked){
                var ot = t;                
                switch(dir){
                    case "next":
                        t = (ot>=ts) ? (options.continuous ? 0 : ts) : t+1;                        
                        break; 
                    case "prev":
                        t = (t<=0) ? (options.continuous ? ts : 0) : t-1;
                        break; 
                    case "first":
                        t = 0;
                        break; 
                    case "last":
                        t = ts;
                        break; 
                    default:
                        break; 
                };    
                
                var diff = Math.abs(ot-t);
                var speed = diff*options.speed;                        
                if(!options.vertical) {
                    p = (t*w*-1);
                    if(t == 0 || t==10){
                        $("ul",obj).animate(
                            { marginLeft: p }, 
                            speed = 0
                        ); 
                    }else{
                        $("ul",obj).animate(
                            { marginLeft: p }, 
                            speed = 500
                        ); 
                    }
               
                } else {
                    p = (t*h*-1);
                    if(t=10){
                        $("ul",obj).animate(
                            { marginTop: p }, 
                            speed = 0
                        );
                    }else{
                        $("ul",obj).animate(
                            { marginTop: p }, 
                            speed = 500
                        );
                    }                    
                    
                };
                
                if(!options.continuous && options.controlsFade){                    
                    if(t==ts){
                        $("a","#"+options.nextId).hide();
                        $("a","#"+options.lastId).hide();
                    } else {
                        $("a","#"+options.nextId).show();
                        $("a","#"+options.lastId).show();                    
                    };
                    if(t==0){
                        $("a","#"+options.prevId).hide();
                        $("a","#"+options.firstId).hide();
                    } else {
                        $("a","#"+options.prevId).show();
                        $("a","#"+options.firstId).show();
                    };                    
                };                
                
                if(clicked) clearTimeout(timeout);
                if(options.auto && dir=="next" && !clicked){;
                
                    timeout = setTimeout(function(){
                        animate("next",false);
                    },diff*options.speed+options.pause);
                };
                
            };
            // init
            var timeout;
            if(options.auto){;
                timeout = setTimeout(function(){
                    animate("next",false);
                },options.pause);
            };        
        
            if(!options.continuous && options.controlsFade){                    
                $("a","#"+options.prevId).hide();
                $("a","#"+options.firstId).hide();                
            };                
            
        });
      
    };

})(jQuery);






