﻿    function CheckComment()
    {
//        if(!IsMem())
//            return;
        var content = document.getElementById('txtContent');
	            
        if ((content.value==null)||(content.value==""))
        {
            alert("Bạn chưa nhập nội dung bình luận!");
            content.focus();
		    return false;
        }
        
        return true;
    }
    function CheckPhoto()
    {
        
        var filename=$('[ten^="uploadphoto"]').attr("value");
        if(filename.length==0)
        {
            $('#lblCheckPhoto').text('Bạn chưa chọn photo!');
            return false;
        }
        else
        {
            $('#lblCheckPhoto').text('');
        }
        filename = filename.toLowerCase();
        if(filename.indexOf(".gif")>=0 || filename.indexOf(".jpg")>=0)
        {
            $('#lblCheckPhoto').text('');
            return true;
        }
        else
        {
            $('#lblCheckPhoto').text('Photo của bạn chưa đúng định dạng!');
            return false;
        }
        return true;
    }
    function CheckLink(title,link)
    {
//        var link=$('[ten^="txtlink"]').attr("value");
//        var gioithieu=$('[ten^="txtgioithieu"]').attr("value");
        if(link.length==0)
        {
            $('#lblCheckLink').text('Bạn chưa nhập link!');
            return false;
        }
        else
        {
            $('#lblCheckLink').text('');
        }
        if(title.length==0)
        {
            $('#lblCheckGioithieu').text('Bạn chưa nhập lời giới thiệu!');
            return false;
        }
        else
        {
            $('#lblCheckGioithieu').text('');
        }
        return true;
    }
    
    function VideoFormat(embed)
    {
        if (embed.toLowerCase().indexOf("<embed") == -1  || embed.toLowerCase().indexOf("width") == -1 || embed.toLowerCase().indexOf("height") == -1)
        {
            if(embed.toLowerCase().indexOf("</embed>") >0 || embed.toLowerCase().indexOf("/>") >0)
            {}
            else
            {
                Response.Write("<script>alert('Định dạng Video Code chưa đúng! Mời bạn xem lại.');</script>");
                return "";
            }
        }
        if(embed.toLowerCase().indexOf("<object")>-1)
            if (embed.toLowerCase().indexOf("</object>") == -1)
            {
                Response.Write("<script>alert('Định dạng Video Code chưa đúng! Mời bạn xem lại.');</script>");
                return "";
            }
        var posEmbed = embed.toLowerCase().indexOf("<embed");
        var posCloseEmbed = embed.toLowerCase().indexOf("</embed>");
        var tagEmbed = embed.substr(posEmbed, posCloseEmbed - posEmbed + 8);
        var width = tagEmbed.substr(tagEmbed.indexOf("width=") + 7,3);
        var height = tagEmbed.substr(tagEmbed.indexOf("height=") + 8, 3);

        var w = 200;
        var h = 175;
        width = parseInt(width);
        //int.TryParse(height, out h);
        if (width > 200)
        {
            embed = embed.replace(width, "200").replace(width, "200");
            embed = embed.replace(height, "175").replace(height, "175");
        }
        if(width <100)
            return "";
        if (tagEmbed.indexOf("width=") == -1)
        {
            alert('Định dạng Video Code chưa đúng! Mời bạn xem lại.');
            return "";
        }
        if (tagEmbed.indexOf("height=") == -1)
        {
            alert('Định dạng Video Code chưa đúng! Mời bạn xem lại.');
            return "";
        }
        if (tagEmbed.indexOf("src") == -1)
        {
            alert('Định dạng Video Code chưa đúng! Mời bạn xem lại.');
            return "";
        }
        return embed;
    }
    function CheckEmbedVideo(title,embed)
    {
        
//        var embed=$('[ten^="txtembedVideo"]').attr("value");
        
        
        
        if(embed.length==0)
        {
            $('#lblCheckembed').text('Bạn chưa nhập Video Code!');
            return false;
        }
        if(title.length==0)
        {
            $('#lblCheckVideo').text('Bạn chưa nhập lời giới thiệu!');
            return false;
        }
        else
        {
            $('#lblCheckVideo').text('');
        }
        return true;
    }
    function CheckEmbed(title,embed)
    {
//        var embed=$('[ten^="txtembed"]').attr("value");
        
        if(embed.length==0)
        {
            $('#lblCheckEmbed').text('Bạn chưa nhập Embed Code!');
            return false;
        }
        else
        {
            $('#lblCheckEmbed').text('');
        }
        return true;
    }
    
    function IsMem()
    {
        var ip = $('#ipMemID').attr('value');
        if(ip=="0")
            return false;
        return true;
    }
    function CheckBoxTogether(chk)
    {
        $(".hidenick input").attr("checked",chk.checked);
    }
    function CheckValidMember()
    {
        var content = document.getElementById('txtContent');
        
        if ((content.value==null)||(content.value==""))
        {
            alert("Bạn chưa nhập nội dung bình luận!");
            content.focus();
	        return false;
        }
        
        return true;
    }
    
    
    function Maxstr(id)
    {
        var content = document.getElementById(id);	            
        if(content.value.length > 160)
            content.value = content.value.substring(0,159);
    }