function trim($str){
	return $str.replace(/(^\s*)|(\s*$)/g, "");
}

function isabc($val) {
	var pattern = /^[a-z]*$/i;
	if(pattern.exec($val)) {
		return true;
    } else {
		return false;
	}
}

function isnum($val) {
	var pattern = /^([\d|\+|\-|\*|\/|=])*$/;
	if(pattern.exec($val)) {
		return true;
    } else {
		return false;
	}
}

function istel($val) {
	var pattern =/^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;
    if(!pattern.exec($val)) {
		return false;
    } else {
		return true;
	}
}

function isemail($val) {
	var pattern =/^[a-zA-Z0-9_\-]{1,}@[a-zA-Z0-9_\-]{1,}\.[a-zA-Z0-9_\-.]{1,}$/;
    if(!pattern.exec($val)) {
		return false;
    } else {
		return true;
	}
}

function ismobile($val) {
	var pass = false;
	var reg0 = /^(([0\+]\d{2,3})?(13\d{9}))$/;
	var reg1 = /^(([0\+]\d{2,3})?(15\d{9}))$/;
	if(reg0.exec($val)) pass = true;
	if(reg1.exec($val)) pass = true;
	if (pass == true) {
		return true;
	} else {
		return false;
	}
}

function checkform($eform) {
	$objs = $eform.getElementsByTagName("input");
	for ($i=0;$i<$objs.length;$i++) {
		if ($objs[$i].getAttribute("need") == 1) {
			if (($objs[$i].type == "text" || $objs[$i].type == "file" || $objs[$i].type == "password") && trim($objs[$i].value) == "") {
				alert("“"+$objs[$i].getAttribute("notify")+"”"+$error['isrequire']);
				$objs[$i].focus();
				return false;
			}
			if ($objs[$i].type == "radio" || $objs[$i].type == "checkbox") {
				$check = 0;
				for ($j=0;$j<$objs.length;$j++) {
					if ($objs[$j].name == $objs[$i].name && $objs[$j].checked) $check = 1;
				}
				if ($check == 0) {
					alert("“"+$objs[$i].getAttribute("notify")+"”"+$error['isrequire']);
					document.getElementsByName($objs[$i].name)[0].focus();
					return false;
				}
			}
		}
		$ctype = $objs[$i].getAttribute("ctype");
		if ($ctype == "num" && isnum($objs[$i].value) == false && trim($objs[$i].value) != "") {
			alert("“"+$objs[$i].getAttribute("notify")+"”"+$error['onlynum']);
			$objs[$i].focus();
			return false;
		}
		if ($ctype == "abc" && isabc($objs[$i].value) == false && trim($objs[$i].value) != "") {
			alert("“"+$objs[$i].getAttribute("notify")+"”"+$error['onlyabc']);
			$objs[$i].focus();
			return false;
		}
		if ($ctype == "tel" && istel($objs[$i].value) == false && trim($objs[$i].value) != "") {
			alert("“"+$objs[$i].getAttribute("notify")+"”"+$error['onlytel']);
			$objs[$i].focus();
			return false;
		}
		if ($ctype == "mobile" && ismobile($objs[$i].value) == false && trim($objs[$i].value) != "") {
			alert("“"+$objs[$i].getAttribute("notify")+"”"+$error['onlymobile']);
			$objs[$i].focus();
			return false;
		}
		if ($ctype == "email" && isemail($objs[$i].value) == false && trim($objs[$i].value) != "") {
			alert("“"+$objs[$i].getAttribute("notify")+"”"+$error['onlyemail']);
			$objs[$i].focus();
			return false;
		}
	}
	$objs = $eform.getElementsByTagName("textarea");
	for ($i=0;$i<$objs.length;$i++) {
		if ($objs[$i].getAttribute("need") == 1 && trim($objs[$i].value) == "") {
			alert("“"+$objs[$i].getAttribute("notify")+"”"+$error['isrequire']);
			$objs[$i].focus();
			return false;
		}
		if ($objs[$i].getAttribute("maxlen")) {
			$maxlen = $objs[$i].getAttribute("maxlen");
			if ($objs[$i].value.length > $maxlen) {
				alert("“"+$objs[$i].getAttribute("notify")+"”"+$error['overlength']+$maxlen);
				$objs[$i].focus();
				return false;
			}
		}
	}
	$objs = $eform.getElementsByTagName("select");
	for ($i=0;$i<$objs.length;$i++) {
		if ($objs[$i].getAttribute("need") == 1 && trim($objs[$i].value) == $objs[$i].getAttribute("init")) {
			alert("“"+$objs[$i].getAttribute("notify")+"”"+$error['isrequire']);
			$objs[$i].focus();
			return false;
		}
	}
}

function showconfirm(msg,url) {
	if (confirm(msg)) {
		location.href = url;
	}
}

//$pos有两个参数,一个就是在$btn下面;一个是自动居中.$type有三个可选属性,ajax,iframe,msg默认为ajax,如果为ajax时$method有两个可选属性get跟post
function showwin($url,$target,$btn,$title,$w,$h,$pos,$type,$method) {
	if (!$w || $w == '') $w = 500;
	if (!$h || $h == '') $h = 300;
	$w = parseInt($w,10);
	$h = parseInt($h,10);
	if (!$pos || $pos == '') $pos = 'fixed';
	if (!$type || $type == '') $type = 'ajax';
	if (!$method || $method == '') $method = 'get';
	$("body").append('<div id="mask" style="position:absolute;left:0px;top:0px;width:'+$(window).width()+'px;height:'+$("body").height()+'px;background:#ffffff;z-index:999;opacity:0.6;filter:alpha(opacity:60);"></div>');
	$("body").append('<div id="popwin" style="position:absolute;width:'+$w+'px;height:'+$h+'px;border:#cccccc 3px solid;background:#ffffff;z-index:1000;overflow:hidden;"><div id="wintitle" style="clear:both;padding:0px 5px;background:#ebebeb;height:30px;line-height:30px;font-size:14px;font-weight:bold;" onselectstart="return false;" oncontextmenu="return false;"><span style="float:left">'+$title+'</span><span style="float:right"><a href="javascript:void(0);" onclick="hidewin()">关闭</a></span></div><div id="wincontent" style="clear:both;line-height:16px;text-align:left;"></div></div>');
	if ($pos == 'att') {
		$pos_x = $("#"+$btn).position().left;
		$pos_y = $("#"+$btn).position().top;
		$pos_h = $("#"+$btn).height();
		if ($pos_x+$w > $(window).width()) {
			$("#popwin").css({left:($(window).width()-$w-10)+"px",top:($pos_y+$pos_h+6)+"px"});
		} else {
			$("#popwin").css({left:$pos_x+"px",top:($pos_y+$pos_h+6)+"px"});
		}
	} else if ($pos = 'fixed') {
		$st = $(window).scrollTop();
		$mt = parseInt(($(window).height()-$h)/2,10);
		$ml = parseInt(($(window).width()-$w)/2,10);
		$("#popwin").css({left:$ml+"px",top:($mt+$st)+"px"});
	}
	if ($type == 'msg') {
		$("#wincontent").html(unescape($url));
	} else if ($type == 'ajax') {
		$("#wincontent").html("Loading...");
		$.get($url,{target:$target,sid:Math.random()},function(data){$("#wincontent").html(data);});
	} else if ($type == 'iframe') {
		$("#wincontent").html('<iframe frameborder="0" width='+$w+'px height='+($h-30)+'px scrolling="auto" src="'+$url+'"></iframe>');
	}
}

function hidewin() {
	$("#mask").remove();
	$("#popwin").remove();
}

function comment_good($comment_id){
    if (GetCookie("comment_goodbad").indexOf(","+$comment_id+",") != -1) {
        alert("先喝杯茶休息会吧！");
        return;
    }
    $.post(
        cfg_root+'plus/ajax.php',
        {
            act:'commentgood',
            comment_id:$comment_id
        },
        function(data){
            if (data.match(/^msg/i)) {
                alert(data.replace('msg:',''));
            } else {
                $("#comment_good_"+$comment_id+">span").html(data);
                $("#comment_good_"+$comment_id).removeAttr("href");//这里是发表以后就不可再点击,但刷新页面可再点击
                $("#comment_bad_"+$comment_id).removeAttr("href");
                if (GetCookie("comment_goodbad") == "") SetCookie("comment_goodbad",",");
                SetCookie("comment_goodbad",GetCookie("comment_goodbad")+$comment_id+",");
            }
        });
}

function comment_bad($comment_id){
    if (GetCookie("comment_goodbad").indexOf(","+$comment_id+",") != -1) {
        alert("先喝杯茶休息会吧！");
        return;
    }
    $.post(
        cfg_root+'plus/ajax.php',
        {
            act:'commentbad',
            comment_id:$comment_id
        },
        function(data){
            if (data.match(/^msg/i)) {
                alert(data.replace('msg:',''));
            } else {
                $("#comment_bad_"+$comment_id+">span").html(data);
                $("#comment_bad_"+$comment_id).removeAttr("href");//这里是发表以后就不可再点击,但刷新页面可再点击
                $("#comment_good_"+$comment_id).removeAttr("href");
                if (GetCookie("comment_goodbad") == "") SetCookie("comment_goodbad",",");
                SetCookie("comment_goodbad",GetCookie("comment_goodbad")+$comment_id+",");
            }
        });
}

function digg_up($aid) {
    if (GetCookie("digg").indexOf(","+$aid+",") != -1) {
        alert("先喝杯茶休息会吧！");
        return;
    }
    $.post(
        cfg_root+'plus/ajax.php',
        {
            act:'diggup',
            aid:$aid
        },
        function(data){
            $("#digg_up>span").html(data);
            $("#digg_up").removeAttr("href");
            $("#digg_down").removeAttr("href");
            if (GetCookie("digg") == "") SetCookie("digg",",");
            SetCookie("digg",GetCookie("digg")+$aid+",");
        });
}

function digg_down($aid) {
    if (GetCookie("digg").indexOf(","+$aid+",") != -1) {
        alert("先喝杯茶休息会吧！");
        return;
    }
    $.post(
        cfg_root+'plus/ajax.php',
        {
            act:'diggdown',
            aid:$aid
        },
        function(data){
            $("#digg_down>span").html(data);
            $("#digg_down").removeAttr("href");
            $("#digg_up").removeAttr("href");
            if (GetCookie("digg") == "") SetCookie("digg",",");
            SetCookie("digg",GetCookie("digg")+$aid+",");
        });
}

function digg_score($aid,$score) {
    if (GetCookie("digg_score").indexOf(","+$aid+",") != -1) {
        alert("先喝杯茶休息会吧！");
        return;
    }
    $.post(
        cfg_root+'plus/ajax.php',
        {
            act:'diggscore',
            aid:$aid,
            score:$score
        },
        function(data){
            showscore(data,$score);
            if (GetCookie("digg_score") == "") SetCookie("digg_score",",");
            SetCookie("digg_score",GetCookie("digg_score")+$aid+",");
        });
}

function SetCookie(name,value) {
   var argv=SetCookie.arguments;
   var argc=SetCookie.arguments.length;
   var expires=(2<argc)?argv[2]:null;
   var path=(3<argc)?argv[3]:null;
   var domain=(4<argc)?argv[4]:null;
   var secure=(5<argc)?argv[5]:false;
   document.cookie=name+"="+escape(value)+((expires==null)?"":("; expires="+expires.toGMTString()))+((path==null)?"":("; path="+path))+((domain==null)?"":("; domain="+domain))+((secure==true)?"; secure":"");
}

function GetCookie(Name) {
   var search = Name + "=";
   var returnvalue = "";
   if (document.cookie.length > 0)
   {
      offset = document.cookie.indexOf(search);
   if (offset != -1)
   {
   offset += search.length;
         end = document.cookie.indexOf(";", offset);
   if (end == -1)
            end = document.cookie.length;
         returnvalue=unescape(document.cookie.substring(offset,end));
       }
    }
    return returnvalue;
}
