var verum = {} ;
var validate = {mail:/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/i}
verum.gotopage = function(url,id)
{
	var regx = /^[1-9]([0-9]*)?$/ ;
	if( regx.test(id) )
	{
		window.location = url+id ;	
		return ;
	}
	alert("Please type a valid number") ;
	return ;
}

verum.validate = function(obj)
{
	var ret = true ;
	var msg = [] ;
	$("input",obj).each(function(){if(this.type=="text" || this.type=="password"){
	var type = -1 ;
	for( var i in validate )
	{
		if(this.name.indexOf(i) != -1)
		{
			type = i ;
			break ;
		}
	}

	if( type != -1 )
	{
		if( !validate[type].test(this.value) )
		{
			msg.push( $(this).attr("MSG") );
			ret = false ;
		}
	}
	else
	{
		if($.trim(this.value).length==0 && this.style.display != "none")
		{
			if( $(this).attr("MSG"))
			{
				msg.push( $(this).attr("MSG") );
				ret = false;
			}
		}
	}
	}});
	$("textarea", obj).each(function(){if($.trim(this.value).length==0){msg.push( $(this).attr("MSG") );ret = false}}) ;
	if( !ret )
	{
		str = "Submit Failed,because of the following message:\n" ;
		for( var kk=0; kk<msg.length; kk++ )
		{
			str += ""+(kk+1)+": "+msg[kk]+".\n" ;
		}
		alert(str) ;
	}
	return ret ;
}

$(document).ready(function()
{
	$("#content div.entry img").each(function(){
		if(this.offsetWidth>507)
		{
			this.style.width = "507px" ;
		}
	}) ;
	$(".nav li.cat a").each(function(idx){$(this).hover(function(){$("img",this).attr("src",menuListImg[idx][0])},function(){$("img",this).attr("src",menuListImg[idx][1])})}) ;
	$("#mct").click(function(){$("#fct").submit();}) ;
	$("form#fct").submit(function(){return verum.validate(this);}) ;
	$("form#mmp").submit(function(){if(!validate.mail.test($("input",this).val())){return false;}}) ;
}) ;
