﻿//跳转到登录地址
function redirectUrl() {
	window.location.href = 'https://www.fetion.com.cn/account/login?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("对不起，网络故障，请稍后重试！");
		            		}
		            	}
		            }
	            )
}

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=" + 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();
//}

