$(document).ready(function() {

	$('#CommentLayout').addClass('hidden');

    document.getElementById('q').focus();	
});


function switchComment() {
	$('#CommentLayout').toggleClass('hidden');
}


function checkWholeForm(theForm) {
    var why = "";
    why += checkQ(theForm.q.value);

    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function checkQ (strng) {
 var error = "";
 var ll = 0;

 var illegalChars = /^[u4E00-u9FA5]*$/;
 if (!illegalChars.test(strng)) {
    ll = 2;
 }
 else
 {
 	ll = 2;
 }

 if (strng == "") {
    error = "請輸入欲查詢之文字\n";
 }
 else if (strng.length < ll) {
    error = "輸入長度太短\n";
 }
 return error;
}

function checkWholeForm2(theForm) {
    var why = "";
    why += checkUsername(theForm.username.value);
    why += checkUrl(theForm.userurl.value);
    why += checkComment(theForm.usercomment.value);		

    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function checkUsername (strng) {
 var error = "";
 if (strng == "") {
    error = "請輸入您的暱稱\n";
 }
 else if (strng.length < 1) {
    error = "暱稱長度太短\n";
 }
 return error;
}

function checkUrl (strng) {
 var error = "";
 var illegalChars = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
 if (strng != "" && !illegalChars.test(strng)) {
    error = "網址需為 http:// 開頭之正確格式\n";
 }
 return error;
}

function checkComment (strng) {
 var error = "";
 if (strng == "") {
    error = "請輸入您的迴響\n";
 }
 return error;
}

function clearQ()
{
	var panel = document.getElementById('q');
	panel.value='';
	panel.focus();
}