﻿//跳转到登录地址
function redirectUrl() {
    window.location.href = '/fetionactivity/login.aspx?returnurl=' + window.location.href;
}

//图片投票
function ImageVote_Submit(TopicId, VoteId, OptionId) {
	$.ajax(
		            { type: "POST",
		            	url: "ImageVote.aspx",
		            	data: "OptionId=" + OptionId,
		            	success: function(data) {
		            		if (data == 1) {
		            			alert("投票成功,感谢您的参与！");
		            			voteInit(VoteId);
		            			openWin2(TopicId, VoteId);
		            		}
		            		else {
		            			alert("对不起，网络故障，请稍后重试！");
		            		}
		            	}
		            }
	            )
}


//一键添加群功能
//<script src="../js/jquery-1.4.1.min.js" type="text/javascript"></script>
//        <script src="js/custom.js" type="text/javascript"></script>
//         <a href="javascript:void(0);" 
//        onclick ="AddGroups_Submit('群Id');">testGroups</a> 
function AddGroups_Submit(GroupId) {
    $.ajax(
		            { type: "POST",
		                url: "OneTouchAddGroups.aspx",
		                data: "GroupId=" + GroupId,
		                success: function(data) {

		                    switch (data) {
		                        case "0":
		                            alert("成功！");
		                            break;
		                        case "1":
		                            alert("群组不存在!");
		                            break;
		                        case "2":
		                            alert("此用户不存在！");
		                            break;
		                        case "3":
		                            alert("此用户不可用！");
		                            break;
		                        case "4":
		                            alert("加入群组已达上限！");
		                            break;
		                        case "5":
		                            alert("此群人数已满！");
		                            break;
		                        case "6":
		                            alert("此群拒绝加入！");
		                            break;
		                        case "7":
		                            alert("等待群主验证！");
		                            break;
		                        case "8":
		                            alert("用户已经加入群！");
		                            break;
		                        case "20":
		                            alert("传入的参数非法！");
		                            break;
		                        case "21":
		                            alert("用户未登录！");
		                            break;
		                        default:
		                            alert("对不起，网络故障，请稍后重试！");
		                            break;


		                    }
		                }
		            }
	            )
}

function radio_submit(TopicID, voteid) {
	var ops = "";
	var eless = document.getElementsByName("radio" + voteid);
	for (var j = 0; j < eless.length; j++) {
		if (eless[j].checked) {
			ops += eless[j].value + ",";
		}
	}
	if (ops.length == 0) {
		alert("对不起，您至少要选择一个选项！");
	}
	else {
		postVote(TopicID, voteid, ops);
	}
}

function postVote(TopicID, voteid, ops) {
	$.ajax(
		            { type: "POST",
		            	url: "vote.aspx",
		            	data: "ops=" + ops,
		            	success: function(data) {
		            		if (data == 1) {
		            			alert("投票成功,感谢您的参与！");
		            			voteInit(voteid);
		            			openWin2(TopicID, voteid);
		            		}
		            		else {
		            			alert("对不起，网络故障，请稍后重试！");
		            		}
		            	}
		            }
	            )
}

function voteInit(voteid) {
	var eless2 = document.getElementsByName("radio" + voteid);
	for (var j = 0; j < eless2.length; j++) {
		eless2[j].checked = false;
	}
}

function input_submit(TopicID, ArticleID) {
	var ops = document.getElementsByName("MessageText").item(0).value;
	if (ops.length <= 0) {
		alert("对不起，请您先填写评论内容！");
		$("#MessageText").focus();
	}
	else if (ops.length > 200) {
		alert("对不起，您的评论超过200字了！");
	}
	else {
		postComment(TopicID, ops, ArticleID);
		document.getElementsByName("MessageText").item(0).value = "";
	}

}


function postComment(TopicID, ops, ArticleID) {
	$.ajax(
		            { type: "POST",
		            	url: "Comment.aspx",
		            	data: "AID=" + ArticleID + "&topicID=" + TopicID + "&ops=" + escape(ops),
		            	success: function(data) {
		            		if (data == 1) {
		            			alert("发布成功！");
		            			location.reload();
		            		}
		            		else {
		            			alert("对不起，出现网络故障，请稍后重试！");
		            		}
		            	}
		            }
	            )
}

function openWin1(TopicId) {
	var url = window.location.href;
	url = url.replace("index.aspx", "ShowComment.aspx");	
	window.open(url, 'commentResult', 'height=430, width=610, top=0, left=0, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no');
}
function openWin2(TopicId, VoteID) {
	var url = window.location.href;
	url = url.replace("index.aspx", "ShowVote.aspx") + "&VoteID=" + VoteID;	
	window.open(url, 'voteResult', 'height=300, width=440, top=0, left=0, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no');
}

//响应键盘事件----------------------------------------------------------------------------

function isKeyTrigger(e, keyCode) {
	var argv = isKeyTrigger.arguments;
	var argc = isKeyTrigger.arguments.length;
	var bCtrl = false;
	if (argc > 2) {
		bCtrl = argv[2];
	}
	var bAlt = false;
	if (argc > 3) {
		bAlt = argv[3];
	}

	var nav4 = window.Event ? true : false;

	if (typeof e == 'undefined') {
		e = event;
	}

	if (bCtrl &&
        !((typeof e.ctrlKey != 'undefined') ?
            e.ctrlKey : e.modifiers & Event.CONTROL_MASK > 0)) {
		return false;
	}
	if (bAlt &&
        !((typeof e.altKey != 'undefined') ?
            e.altKey : e.modifiers & Event.ALT_MASK > 0)) {
		return false;
	}
	var whichCode = 0;
	if (nav4) whichCode = e.which;
	else if (e.type == "keypress" || e.type == "keydown")
		whichCode = e.keyCode;
	else whichCode = e.button;

	return (whichCode == keyCode);
}

function ctrlEnter_1(e) {
	var ie = navigator.appName == "Microsoft Internet Explorer" ? true : false;
	if (ie) {
		if (event.ctrlKey && window.event.keyCode == 13) { redirectUrl(); }
	} else {
		if (isKeyTrigger(e, 13, true)) { redirectUrl(); }
	}
}

function ctrlEnter_2(e, TopicID, ArticleID) {
	var ie = navigator.appName == "Microsoft Internet Explorer" ? true : false;
	if (ie) {
		if (event.ctrlKey && window.event.keyCode == 13) { input_submit(TopicID, ArticleID); }
	} else {
		if (isKeyTrigger(e, 13, true)) { input_submit(TopicID, ArticleID); }
	}
}

//function poplogin() {
//	$("#Lu").click();
//}


