﻿
$(document).ready(function(){	
	var loginname = getcookie("uchome_loginuser");
	if(loginname != null && loginname != ''){
		$("#login_div").hide();
		$("#login_span").html("欢迎" + loginname + ", 请留言");
	}
	$("#userlogin").click(function(){
		username=$("#loginname").val();
		$.getJSON("http://comments.china.com.cn/comments/servlet/UserLogin?jsoncallback=?",{loginname:username, password:$("#password").val()}, function(data){
//		$.getJSON("http://comments.china.com.cn/comments/servlet/UserLogin?jsoncallback=?",{loginname:$("#loginname").val(), password:$("#password").val()}, function(data){
			var obj = eval(data);
				if(obj == null){
						$("#login_span").html("用户不存在，请注册或重试。");
				}else if(obj.username==null || obj.username==''){
						$("#login_span").html("信息不完整，请补充。");
						//window.open('http://comments.china.com.cn/comments/admin/RegUser.jsp?idsid='+obj.idsid+'&loginname='+$("#loginname").val(),'zhuce','height=600, //width=800, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
						var puburl = $("input[name='puburl']").val();
						window.location.href='http://comments.china.com.cn/comments/admin/RegUser.jsp?idsid='+obj.idsid+'&loginname='+$("#loginname").val()+"&puburl="+puburl;
				}else{
						$("#login_div").hide();
//						$("#login_span").html(obj.loginname + "已登录, 请留言" );
						$("#login_span").html(username + "已登录, 请留言" );
						setcookie(username);
				}				
        });
         });
});

function setcookie(username){
	document.forms["myform"].author.value = username;
	setcookie2("uchome_loginuser", username, 20);
}

function setcookie2(cookieName, cookieValue, seconds, path, domain, secure) {
	var expires = new Date();
	expires.setTime(expires.getTime() + seconds*3600000);
	expires = expires ? '; expires=' + expires.toGMTString() : '';
	var temp = escape(cookieName) + '=' + escape(cookieValue) + expires + ';path=/;domain=china.com.cn';
	document.cookie = temp;	
}
function getcookie(name) {     
var start = document.cookie.indexOf( name + "=" );     
var len = start + name.length + 1;     
if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {         
return null;     
}     
if ( start == -1 ) return null;     
var end = document.cookie.indexOf( ';', len );     
if ( end == -1 ) end = document.cookie.length;    
return unescape( document.cookie.substring( len, end ) ); } 


function viewComment() {
var nodeid=0;
var nsid=0;
try{
nodeid=document.forms["myform"].nodeid.value;
nsid=document.forms["myform"].nsid.value;
}catch(e){}
	document.forms["myform"].action = "http://comments.china.com.cn/comments/servlet/DisplayComments?nodeid="+nodeid+"&nsid="+nsid;
	document.forms["myform"].submit();
}
function submitCheck() {
	var fid = getcookie("uchome_loginuser");
	if (fid != null && fid != '') {
		document.forms["myform"].author.value = fid;
		if (document.forms["myform"].content.value.length > 1000) {
			alert("评论内容过长！");
			return false;
		}
		if (document.forms["myform"].content.value.indexOf("<script") != -1 || document.forms["myform"].content.value.indexOf("</") != -1) {
			alert("评论内容不能包含脚本！");
			return false;
		}
		if (trim(document.forms["myform"].content.value) == "" || trim(document.forms["myform"].content.value) =="文明上网 登录发帖") {
			alert("评论内容不能为空！");
			return false;
		}
		document.forms["myform"].author.value = fid;
		alert("感谢您的回复，谢谢您对中国网的支持！");
		document.forms["myform"].submit();
		document.location.href=document.location.href;
	} else {
		alert('登录后才可以发表评论，请登录。');
		document.forms["myform"].loginname.focus();
	}
}

function setField(objid){
	var elem;
	//1、用户名，必填
	elem = document.getElementById(objid);
	if(objid=="content"&&elem.value=="文明上网 登录发帖"){
		elem.value="";
	}
	//return true;
}

