$(function() {
	var O_ShowWinAsk = $("#O_ShowWinAsk");
	var O_AskSubmit = $("#O_AskSubmit");
	var O_CloseAsk = $("#O_CloseAsk");
	O_ShowWinAsk.click(function() { showAsk(); });
	O_AskSubmit.click(function() { addAsk(); });
	// 关闭窗口
    O_CloseAsk.click(function() {
        // 清空所有内容
        $("#doing").hide();
        $("#divAsk").hide();
        $("#divAskF").hide();
    });

    $divAsk = $("#divAsk");
    $divAskF = $("#divAskF");
    var windowObj = $(window); // 获取window对象
    var browserWidth = windowObj.width(); // 获取当前浏览器长度
    var browserHeight = windowObj.height(); // 获取当前浏览器宽度
    var scrollLeft = windowObj.scrollLeft();
    var scrollTop = windowObj.scrollTop();
    var cwinWidth = $divAsk.width();
    var cwinHeight = $divAsk.height();
    var left = scrollLeft + (browserWidth - cwinWidth) / 2;
    var top = scrollTop + (browserHeight - cwinHeight) / 2;
    $divAsk.css("top", top).css("left", left);
    $divAskF.css("top", top).css("left", left);
    $(window).scroll(function() {
        var windowObj = $(window);//获取window对象
        var browserWidth = windowObj.width();//获取当前浏览器长度
        var browserHeight = windowObj.height();//获取当前浏览器宽度
        var scrollLeft = windowObj.scrollLeft();
        var scrollTop = windowObj.scrollTop();
        var cwinWidth = $divAsk.width();
        var cwinHeight = $divAsk.height();
        var left = scrollLeft + (browserWidth - cwinWidth) / 2;
        var top = scrollTop + (browserHeight - cwinHeight) / 2;
        $divAsk.css("top", top).css("left", left);
        $divAskF.css("top", top).css("left", left);
    });
});
//弹出提问框
function showAsk(){
	//启动浏览模式
	var range = getRange();
	var obj_doing = document.getElementById("doing");
	if(range != null && obj_doing != null) {
		obj_doing.style.width = range.width + "px";
		obj_doing.style.height = (range.height+100)+ "px";
		obj_doing.style.display = "block";
	}
	var divAsk = document.getElementById("divAsk");
	if(divAsk != null) { divAsk.style.display = ""; }
	var divAskF = document.getElementById("divAskF");
	if(divAskF != null) { divAskF.style.display = ""; }
}
//添加问答
function addAsk(){
	var basePath = $($("body")[0]).attr("base");
	var O_Title = $("#O_Title");
	var O_Content = $("#O_Content");
	var O_MemberId = $("#O_MemberId");
	var O_HotelId = $("#O_HotelId");
	var v_title = O_Title.val();
	var v_content = O_Content.val();
	var v_memberId = O_MemberId.val();
	var v_hotelId = O_HotelId.val();
	$.post(basePath + "?m=question.createQuestion.php",{ title:v_title, content:v_content, categoryName:'hotel', categoryRelId:v_hotelId, memberId:v_memberId },function(data) {//alert(data);
		alert(data[1]);
		if(data[0] == "success") {
			O_Title.val("");
			$("#O_CloseAsk").triggerHandler("click");
			window.location.reload();
		} else {
			O_Title.focus();
		}
	}, "json");
}