function getScrollTop() {
    var scrollTop=0;
    if(document.documentElement&&document.documentElement.scrollTop) {
        scrollTop=document.documentElement.scrollTop;
    }
    else if(document.body) {
        scrollTop=document.body.scrollTop;
    }
    return scrollTop;
}
function showError(id, msg) {
	if(jQuery("#commonerrshow").size()==0) {
		jQuery('body').append('<div id="commonerrshow" class="sysTip" style="position:absolute; width:190px; display:none; z-index:100001;"><div class="bdy"><span id="commonerrmsg">错误信息</span> <a href="javascript:;" onclick="jQuery(\'#commonerrshow\').animate({left:0, top: 0, opacity: \'hide\'}, 400);">[关闭]</a></div></div>');
		jQuery("#commonerrshow").bind("click", function(){jQuery("#commonerrshow").animate({left:0, top: 0, opacity: 'hide'}, 400);})
	}
	jQuery("#commonerrmsg").html(msg);
	var pop = id;
	if (typeof(pop) == "string") {
		pop = jQuery("#" + id);
	}
	if (getScrollTop() > pop.position().top)
		window.scrollTo(0, pop.offset().top - 200);
	
	if (jQuery("#commonerrshow:visible")[0]) {
		jQuery("#commonerrshow").animate({left:0, top: 0, opacity: 'hide'}, 1);
	}
	
	jQuery("#commonerrshow").animate({left: pop.offset().left + pop.width(), top: pop.offset().top, opacity: 'show'}, 400);
}
function hideError() {
	if(jQuery("#commonerrshow").size() > 0) {
		jQuery('#commonerrshow').animate({left:0, top: 0, opacity: 'hide'}, 400);
	}
}

function formValid(form, validParams) {
	var errmsg = new Array();
	var validReg = {
		Require : /.+/,
		User:/^[\u4e00-\u9fa5a-zA-Z0-9]{2,20}$/,
		Urlname:/^[a-zA-Z0-9]{2,20}$/,
		Chinese:/^[\u4e00-\u9fa5]{2,10}$/,
		Pass:/^.{6,20}$/,
		Email : /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
		Phone : /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/,
		Mobile : /^1[358]\d{9}$/,
		Url : /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/,
		Currency : /^\d+(\.\d+)?$/,
		Number : /^\d+$/,
		Zip : /^[1-9]\d{5}$/,
		QQ : /^[1-9]\d{4,12}$/,
		Integer : /^[-\+]?\d+$/
	}
	for (var i = 0; i < validParams.length; i++) {
		if (null == form[validParams[i].name]){
			alert(validParams[i].name + "不存在");
			return [];
		}
		if (validParams[i].valid == "confirm") {
			if (form[validParams[i].name].value != form[validParams[i].confirm].value ) {
				errmsg.push(validParams[i]);
			}
			continue;
		}
		with (form[validParams[i].name]) {
			if(!validReg[validParams[i].valid].test(value)){
				errmsg.push(validParams[i]);
			}
		}
	}
	if (errmsg.length > 0){
		return errmsg;
	}
	return [];
}
