String.prototype.Trim  = function(){return this.replace(/^\s+|\s+$/g,"");}
function baidu_query(){
	var obj = {
		param:{},
		construct:function(){
			var name, value, index;		
			var query = location.search.substr(1);
			var pairs = query.split("&");
			for(var i=0;i < pairs.length; i++){
				index = pairs[i].indexOf("=");
				if(index){
					name    = pairs[i].substr(0,index);
					value   = pairs[i].substr(index+1);
					this.param[name] = value;
				}
			}
			return this;
		},
		getParam: function(name, def){
			return this.param[name]==undefined?def:this.param[name];
		}
	};
	return obj.construct();
}
function valid_message()
{
	objMess = document.lea_mess.message;
	objname = document.lea_mess.name;
	objContact = document.lea_mess.contact;
	objmail = document.lea_mess.mail;
	objMess.value = objMess.value.Trim();
	objname.value = objname.value.Trim();
	objContact.value = objContact.value.Trim();
	objmail.value = objmail.value.Trim();

	strMess = objMess.value;
	strname = objname.value;
	strContact = objContact.value;
	strmail = objmail.value;
	
	if (strMess.length > 200)
	{
		alert('Your message is too long, please reduce to 200 words, thank you!');
		return false;
	}
	if (strname.length > 50)
	{
		alert('Your Name too long, please reduce to 50 words, thank you!');
		return false;
	}
	if (strContact.length > 50)
	{
		alert('Your Contacts too long, please reduce to 50 words, thank you!');
		return false;
	}
	if (strmail.length > 50)
	{
		alert('Your E-mail too long, please reduce to 50 words, thank you!');
		return false;
	}
	if ((strMess.length < 1 || strMess==objMess.defaultValue) && strContact.length>0 && strmail.length>0 && strname.length>0)
	{
		alert('You have not filled out the contents of guestbook, please fill in the box after the contents of guestbook submission, thank you!');
		return false;
	}
	if ((strname.length < 1 || strname==objname.defaultValue) && strMess.length>0 && strmail.length>0 && strContact.length>0)
	{
		alert('You have not filled out name, please fill out the name box End of submission, thank you!');
		return false;
	}
	if ((strContact.length < 1 || strContact==objContact.defaultValue) && strMess.length>0 && strmail.length>0 && strname.length>0)
	{
		alert('You have not filled out Contact us, please fill out the Contact us box End of submission, thank you!');
		return false;
	}
	if ((strmail.length < 1 || strmail==objmail.defaultValue) && strMess.length>0 && strContact.length>0 && strname.length>0)
	{
		alert('You have not filled out E-mail, please fill out the E-mail box End of submission, thank you!');
		return false;
	}
	if ((strContact.length < 1 && strMess.length<1 && strmail.length<1 && strname.length<1) ||  (strMess==objMess.defaultValue && strContact==objContact.defaultValue && strmail==objmail.defaultValue && strname==objname.defaultValue))
	{
		alert('Hello, Guest Book should not be empty, thank you!');
		return false;
	}
	if(!confirm('Send is successful, we will reply as soon as possible with you, thank you for your participation!')) 
	{
		return false;
	}
	document.lea_mess.userid.value = userid;
	document.lea_mess.submit();
	msee_init();
	return false;
}
function msee_init () {
	document.lea_mess.message.value = document.lea_mess.message.defaultValue;
	document.lea_mess.contact.value = document.lea_mess.contact.defaultValue;
        document.lea_mess.mail.value = document.lea_mess.mail.defaultValue;
	document.lea_mess.name.value = document.lea_mess.name.defaultValue;
}

var query = baidu_query();
var userid = query.getParam('userid');