function DoSearch()
{
    var searckKey = $("SearchKey");
    if ( searckKey == null )
    {
	    return false;
    }
    if ( searckKey.value == "" )
    {
	    alert("search key is required!");
	    return false;
    }
    return true;
}
function VerifyCode()
{
    var numkey = Math.random();
    numkey = Math.round(numkey*10000);

    $("imgVerifyCode").src = "/VerifyCode.aspx?k=" + numkey;
}
    
function doComment()
{    
    var author      = $("tbName").value;
    var verifyCode  = $("tbVerifyCode").value;
    var webSite     = $("tbWebSite").value;
    var content     = $("tbContent").value;

    if ( author == "" )
    {
        $("tbName").focus();
        $("lbAlertInfo").innerHTML = "<img src='/Images/ajax_error.gif' />your name is required!";
        return false;
    }
    if ( verifyCode == "" )
    {
        $("tbVerifyCode").focus();
        $("lbAlertInfo").innerHTML = "<img src='/Images/ajax_error.gif' />the verifycode is required!";
        return false;
    }
    if ( content == "" || content == "[antispam]")
    {
        $("lbAlertInfo").innerHTML = "<img src='/Images/ajax_error.gif' />the comment content is required!";
        return false;
    }

    if (!confirm('sure to submit the words above?'))
    {
        return false;
    }
    
    SetCookie("author", escape(author), new Date(2099,1,1));
    SetCookie("website", escape(webSite), new Date(2099,1,1));

    $("lbAlertInfo").innerHTML = "<img src='/Images/loading.gif' />submitting...";
    
    new Ajax.Request('/AjaxHandler.aspx?cmd=docomment'
                    + '&articleid=' + articleID
                    + '&author=' + escape(author)
                    + '&verifycode=' + escape(verifyCode)
                    + '&website=' + escape(webSite)
                    + '&content=' + escape(content)
                    ,{method: 'get', onComplete: onCommentSucc, onFailure: onCommentError});
}
function onCommentSucc(oReq)
{
    var resText = oReq.responseText;

    if ( resText == null || resText.length < 2 )
	{
		return;
	}

	var retCode = resText.substring(0, 1);
	var retText = resText.substring(2, resText.length);
	
	if ( retCode > 0 )
	{
	    $("lbAlertInfo").innerHTML = "<img src='/Images/ajax_error.gif' />" + retText;
	    switch(retCode)
	    {
	        case 1:
	            $("tbName").focus();
	            break;
            case 2:
                $("tbVerifyCode").focus();
	            break;
            case 3:
                $("tbContent").focus();
	            break;    
            default:
                break;
	    }
	}
	else
	{
	    $("lbAlertInfo").innerHTML = "<img src='/Images/ajax_ok.gif' />comment submitted. the page will be refreshed automatically in 3 seconds.";
	    window.setInterval(function(){window.location.href=window.location.href}, 3000); 
	}
}
function onCommentError(oReq)
{
    $("lbAlertInfo").innerHTML = "<img src='/Images/ajax_error.gif' />something wrong while sumbitting the comment.";
}