function CommentSubmit(art_id)
{
    //var username = document.getElementById("username").value;
    //var email = document.getElementById("email").value;
    //var content = document.getElementById("editor_textarea").value;
    var content = document.getElementById("editor_textarea").value;
    var username='';
    var email='';
    if(!document.login_status)
    {
        username = document.getElementById("username")?document.getElementById("username").value:'';
        email = document.getElementById("username")?document.getElementById("email").value:'';
        if(username.length < 1 || username.length > 50)
        {   
            alert("请正确填写昵称");
            return;
        }   
        if(email.length < 1 || email.length > 100)
        {   
            alert("请正确填写Email");
            return;
        }
    }
    if(content.length < 1) 
    {   
        alert("请正确填写评论");
        return;
    }
     $.post('http://'+document.domain+'/include/deal_data.php',{'username':username,'email':email,'content': content,'art_id' :art_id,'yzm':$('#yzm').val() ,'type' : 'com_sub'}, function(data) { 
            if(data > 0)
            {
            alert("回复成功！");window.location.reload();
            }
            else if(data == '0')alert("内容不能为空！");
            else if(data == '-1')alert('验证码不正确！');
            else if(data == '-3') 
            {
                alert('您可能在别的地方已登陆,请重新登陆！');
                document.location='http://passport.metroer.com/logout.php?forward='+transform(document.location.href);
            }
            else alert("回复未成功！");
            });
}
function FormSub()
{
    var username = document.getElementById("username").value;
    var email = document.getElementById("email").value;
    var content = document.getElementById("content").value;
    if(username.length < 1 || username.length > 50) 
    {   
        alert("请正确填写昵称");
        return false;
    }   
    if(email.length < 1 || email.length > 100)
    {   
        alert("请正确填写Email");
        return false;
    }   
    if(content.length < 1)  
    {   
        alert("请正确填写评论");
        return false;
    }
    var form1 = document.getElementById("form1");
    form1.submit()

}
function Comsubmit(formid)
{
    var username = $("#username").val();
    var email = $("#email").val();
    var content = $("#content").val();
    if(username.length < 1 || username.length > 50)
    {   
        alert("请正确填写昵称");
        return;
    }   
    if(email.length < 1 || email.length > 100)
    {   
        alert("请正确填写Email");
        return;
    }
    if(content.length < 1) 
    {   
        alert("请正确填写评论");
        return;
    } 
    $.post('http://'+document.domain+'/include/deal_data.php',{'username': $('#username').val(),'email': $('#email').val(),'content': $('#content').val(),'art_id' :$('#art_id').val(),'yzm':$('#yzm').val(),'type' : 'concom_add'}, function(data) {
            if(data == 1)
            { 
            alert("回复成功！");window.location=window.location;
            }
            else if(data == '-1') alert('验证码不正确！');
            else if(data == '-3') 
            {
                alert('您可能在别的地方已登陆,请重新登陆！');
                document.location='http://passport.metroer.com/logout.php?forward='+transform(document.location.href);
            }
            //else  alert("请求错误！");
            else alert(data);
            }); 
}
function AddLinkByKey(keys,containerId)
{
    var containerId = containerId?containerId:'contentContainer';
    var container = document.getElementById(containerId);

    if(!container || keys.length==0)return;
    replaceNodeValue(container,keys);
}
function replaceNodeValue(obj,keys)
{
    chg_flag = false;
    if(obj.childNodes.length>0)
    {
        for(var i=0;i<obj.childNodes.length;i++)
        {
            node = obj.childNodes[i];
            if(node.nodeType ==3 && !chg_flag)
            {
                var text =node.nodeValue;
                for(var j=0;j<keys.length;j++)
                {
                    text = text.replace(keys[j].tag_name,"<a style=\"color:#8FC320\" href=\""+keys[j].link+"\">"+keys[j].tag_name+"</a>");
                }
                if(text !=node.nodeValue)
                {
                    $(node).replaceWith(text); 
                    chg_flag = true;
                }
            }
            else if(obj.childNodes[i].nodeType ==1 && !chg_flag )replaceNodeValue(obj.childNodes[i],keys);
        }
    }   
}
function goPos(id)
{
    var obj = document.getElementById(id);
    var  t=obj.offsetTop; 
    while(obj=obj.offsetParent){ 
        t+=obj.offsetTop;
    }
    if (document.body && document.body.scrollTop)
        document.body.scrollTop =t;
    if (document.documentElement && document.documentElement.scrollTop)
        document.documentElement.scrollTop=t;
    // if (window.pageYOffset)window.pageYOffset=t;
    return ;
}
function goQuote(obj)
{
    var pobj = $(obj).parent().parent();
    var comhead=''
        var cld = $(pobj).find('p').children();
    for(var i =0;i<cld.length;i++)
    {
        comhead += $(cld[i]).text()+' ';
    }
    var combody='';var dot='\n';
    var quote = $(pobj).find('.comment_content FIELDSET:first').attr('innerHTML');
    if('' == quote) combody = $(pobj).find('.comment_content').attr('innerHTML');
    else
    {
        var comment_content = $(pobj).find('.comment_content').clone();
        comment_content.find('FIELDSET:first').remove();
        combody = comment_content.attr('innerHTML');
        //dot='';
    }
    //$('#editor_iframe').attr('innerHTML','[quote]'+comhead+dot+combody+'[/quote]\r\n');
    Editor.setIframeValue('[quote]'+comhead+'<br>'+combody+'[/quote]<br>&nbsp;');
    //$('#content').val('[quote]'+comhead+dot+combody+'[/quote]\r\n');
    goPos('entry_commentform');
}
/*
   function goQuote(obj)
   {
   obj = arguments[0];
   contentId = arguments[1];
   if(!contentId)contentId='content';
   var pobj = $(obj).parent().parent();
   var comhead=''
   var cld = $(pobj).find('p').children();
   for(var i =0;i<cld.length;i++)
    {
        comhead += $(cld[i]).text()+' ';
    }
    var combody='';var dot='\r\n';
    var quote = $(pobj).find('.comment_content FIELDSET:first').text();
    if('' == quote) combody = $(pobj).find('.comment_content').text();
    else 
    {
        var comment_content = $(pobj).find('.comment_content').clone();
        comment_content.find('FIELDSET:first').remove();
        combody = comment_content.text();
        dot='';
    }
    $('#'+contentId).val('[quote]'+comhead+dot+combody+'[/quote]\r\n');
    //$('#content').val('[quote]'+comhead+dot+combody+'[/quote]\r\n');
    goPos('entry_commentform');
}
*/
var mycookie = document.cookie;  
var timeid = 0;
function GetCookie(name) 
{ 
    var start1 = mycookie.indexOf(name + "="); 
    if (start1== -1) 
        return false;
    else 
    { 
        start=mycookie.indexOf("=",start1)+1;  
        var end = mycookie.indexOf(";",start); 
        if (end==-1) 
        { 
            end=mycookie.length;
        } 
        var value=unescape(mycookie.substring(start,end)); 
        return value;
    } 
}
function SetCookie(name, value)
{
    var expdate = new Date();
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
    document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
        +((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
        +((secure == true) ? "; secure" : "");
}
function DelCookie(name)
{
    var exp = new Date();
    exp.setTime (exp.getTime() - 1);
    var cval = GetCookie (name);
    document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}
function setPlay(aid, auto_link)
{
    clearTimeout(timeid);
    var class_name = document.getElementById( 'playbutton' ).className;
    if(class_name == 'play')
    {
        autoPlay(auto_link);
        document.getElementById( 'playbutton' ).className="pause";
        SetCookie('autoflag'+aid, '0');
    }
    else
    {
        document.getElementById( 'playbutton' ).className="play";
        SetCookie('autoflag'+aid, '1');
    }
}
function autoPlay(auto_link)
{
    timeid = window.setTimeout("window.location='" +auto_link+ "'", 7000);
}

