﻿function $(o){return document.getElementById(o);}
function $F(o){return $(o).value;}
function $Q(){var r = arguments[0]+'='+ escape($F(arguments[0])); for(var i=1;i<arguments.length;i++)r+='&'+arguments[i]+'='+ escape($F(arguments[i])); return r;}

function getCookie(name){var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));if(arr != null) return unescape(arr[2]); return null;}
function setCookie(cookiename,cookievalue,cookieexpdate)
{
    document.cookie = cookiename + "=" + escape(cookievalue)
    + "; domain=.svnhost.cn"
    + "; path=" + "/"
    + "; expires=" + cookieexpdate.toGMTString();
}
String.prototype.JSON = function(){return eval('('+this+')');}
function IsNull(id,str){if($F(id)==''){alert(str);$(id).focus();return true;}else return false;}
function reset(id){$(id).value='';}

var Try = {
  these: function() {
    var returnValue;

    for (var i = 0, length = arguments.length; i < length; i++) {
      var lambda = arguments[i];
      try {
        returnValue = lambda();
        break;
      } catch (e) { }
    }

    return returnValue;
  }
};

function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}

function SendComment(userid, typeid,objectid)
{
    if(IsNull('c_name', '请填写姓名')){}
    else if (IsNull('c_content', '请填写评论内容')){}
    else if (IsNull('c_code', '请填写验证码')){}
    else
    {
        var data = $Q('c_name', 'c_home', 'c_email', 'c_code', 'c_content')+'&isPrivate='+isPrivate.checked+'&userid='+String(userid)+'&typeid='+String(typeid)+'&objectid='+String(objectid);
        var xh = new XHConn();
        xh.connect('/Comment/s.aspx', 'POST', data, fSendComment);
        if($('jz').checked)
        {
            var d = new Date();
            d.setTime(d.getTime()+1000*60*60*24*30);
            setCookie('u', $F('c_name'), d);
            setCookie('email', $F('c_email'), d);
            setCookie('home', $F('c_home'), d);
        }
    }
}
function fSendComment(o)
{
    var r = o.responseText;
    var i=r.indexOf(',');
    var code = r.substr(0,i);
    if (code>0)
	{
        $('comments').innerHTML += r.substr(i+1);
		reset('c_content');
	}
    else if(code==-1)
        alert('验证码错误');
    else if(code==-2)
        alert('您回复的太快了，休息下再回复吧');
        
    ChangeVali();
    reset('c_code');
}
function setHistory()
{
    if(getCookie('u')!=null)$('c_name').value=getCookie('u');
    if(getCookie('email')!=null)$('c_email').value=getCookie('email');
    if(getCookie('home')!=null)$('c_home').value=getCookie('home');
}
function Update(element, url, method, data, call)
{
    var xh = new XHConn();
    xh.connect(url, method, data, function(o){$(element).innerHTML = o.responseText;call();});
}
function Reply(u)
{
    $('c_content').value+='@'+u;
    $('c_content').focus();
}
function Quote(id,u)
{
    $('c_content').value+='\n[Quote=引用 ' + id + ' 楼 '+u+' 的回复：]'+($('con_'+id).innerText||$('con_'+id).textContent) + '[/Quote]';
    $('c_content').focus();
}
function ChangeVali()
{
    $('code').src='/ValidateImg.aspx?'+Math.random();
}
function digg(type,id)
{
    var img = new Image();
    img.src = '/js_s/setdigg.aspx?type='+String(type)+'&id='+String(id);
    $('showdigg').innerHTML = String(parseInt($('showdigg').innerHTML)+1);
}