﻿function QuestionUtils() 
{
    var _this = this;
    var _childcategory;
    this.InitializeCategory = function(arr)
    {
        _childcategory  =  arr;
        
        $("#BigCategoryID").change(function()
		{
		    _this.ChangeOption();
		});
		_this.ChangeOption();
    }
    
    this.ChangeOption = function()
    {
        var ci = $('#CategoryID');
	    ci.clearAll();
	    ci.addOption("请选择", "0");
	    var childvalue = $("#TCategoryID").val();
	    var index = 0;
	    selected = $("#BigCategoryID").getSelectedValue();
	    count = 1;
        for(i=0; i<_childcategory.length; i++)
        {
            if(_childcategory[i][0].toString() == selected) 
            {
                ci.addOption(_childcategory[i][2], _childcategory[i][1]);
                if ( childvalue == _childcategory[i][1] )
                {
                    index = count;
                }
                count = count+1;
            }
        }
        ci.setSelectedIndex(index);
    }
}

function Search()
{
    var question = document.getElementById("q").value;
    if(question == ""){
		alert('请输入查询词');
		document.getElementById("q").focus();
		return false;
	}
    var keystr = document.getElementById('q').value;
    window.location = "/blogs/SearchQuestion.rails?SearchWord="+keystr;
}

function AddReply() {
    editor.sync();
    var txt = document.getElementById("Reply").value;
    if(txt.length < 5 ){
		alert('回答不得少于5个字');
		return false;
	}
    return true;
}

function AddComment() {
    editor.sync();
    var txt = document.getElementById("Comment").value;
    if(txt.length < 5 ){
		alert('评论不得少于5个字');
		document.getElementById("Comment").focus();
		return false;
	}
    return true;
}

function AddAddition()
{
    var txt = document.getElementById("Addition").value;
    if(txt.length < 5 ){
		alert('问题补充不得少于5个字');
		document.getElementById("Addition").focus();
		return false;
	}
    return true;
}
