window.iptDefautVars = new Array();
$(".iptfrom input.text").focusin(function () {
    if( window.iptDefautVars[ this.id ] == null || window.iptDefautVars[ this.id ] == '' ) {
    	window.iptDefautVars[ this.id ] = ($(this).val()=="")?"css:"+$(this).css('background-image'):$(this).val();
    }
    if( $(this).val()=='' ) {
        if(("css:"+$(this).css('background-image'))==window.iptDefautVars[ this.id ] ) {
            $(this).css('background-image','none');
        }
    } else {
        if($(this).val()==window.iptDefautVars[ this.id ] ) {
            $(this).val('');
        }
    }
});
$(".iptfrom input.text").focusout(function () {
    if( $(this).val()=='' ) {
        if( window.iptDefautVars[ this.id ].slice(0,3)=='css' ) {
        	$(this).css('background-image', window.iptDefautVars[ this.id ].slice(4) );
        } else {
        	$(this).val( window.iptDefautVars[ this.id ] );
        }
    }
});

// ck_ipt
function ck_ipt(obj,errTarget){
	var name,key,alt,msg,val=$(obj).val();
	var oShow=(errTarget==null)?"#err_"+$(obj).attr('name'):errTarget;
	alt=$(obj).attr("alt");
	if(alt==""||alt.indexOf(":")<0) return true;
	name=alt.slice(0,alt.indexOf(":"));
	key="/"+alt.slice(alt.indexOf(":")+1)+"/";
	$(oShow).hide();
	if(key.indexOf("/无内容/")>-1&&val==""){
		msg="请输入"+((name=="pwd")?"密码":name);
		$(oShow).show();
		$(oShow).html(msg);
		return false;
	}
	if(ms=key.match("/([0-9]*)-([0-9]+)/|/([0-9]+)-([0-9]*)/")){
		small=ms[1];
		max=ms[2];
		if(small){
			if(max){
				checked=strLen(val)<small||strLen(val)>max;
				msg=((name=="pwd")?"密码":name)+"长度必须在"+small+"位和"+max+"位之间";
			}else{
				checked=strLen(val)<small;
				msg=((name=="pwd")?"密码":name)+"长度不能小于"+small+"位";
			}
		}else if(max){
			checked=strLen(val)>max;
			msg=((name=="pwd")?"密码":name)+"长度不能大于"+max+"位";
		}else{
			checked=false;
		}
		if(checked){
			$(oShow).show();
			$(oShow).html(msg);
			return false;
		}
	}
	if(key.indexOf("/怪字符/")>-1&&(/>|<|,|\[|\]|\{|\}|\?|\/|\+|=|\||\'|\\|\"|:|;|\~|\!|\@|\#|\*|\$|\%|\^|\&|\(|\)|`/i).test(val)){
		msg=name+"请勿使用特殊字符";
		$(oShow).show();
		$(oShow).html(msg);
		return false
	}
	if(key.indexOf("/有空格/")>-1&&val.indexOf(" ")>-1){
		msg=name+"不能包含空格符";
		$(oShow).show();
		$(oShow).html(msg);
		return false
	}
	if(key.indexOf("/全数字/")>-1&&val!=""&&!isNaN(val)){
		msg=name+"不可以全是数字";
		$(oShow).show();
		$(oShow).html(msg);
		return false;
	}
	if(key.indexOf("/有大写/")>-1&&/[A-Z]/.test(val)){
		msg=name+"不能有大写字母";
		$(oShow).show();
		$(oShow).html(msg);
		return false;
	}
	if(key.indexOf("/英文数字/")>-1&&!/^[a-zA-Z0-9_]*$/.test(val)){
		msg=name+"只能为英文、数字和下划线";
		$(oShow).show();
		$(oShow).html(msg);
		return false;
	}
	if(key.indexOf("/有全角/")>-1&&/[ａ-ｚ０-９]/.test(val)){
		msg=name+"不能有全角字符";
		$(oShow).show();
		$(oShow).html(msg);
		return false;
	}
	if(key.indexOf("/有汉字/")>-1&&escape(val).indexOf("%u")>-1){
		msg=name+"不能有汉字";
		$(oShow).show();
		$(oShow).html(msg);
		return false;
	}
	if(key.indexOf("/下划线/")>-1&&(val.slice(0,1)=="_"||val.slice(val.length-1)=="_")){
		msg=name+"开头和结尾不能是下划线";
		$(oShow).show();
		$(oShow).html(msg);
		return false;
	}
	if(key.indexOf("/确认密码/")>-1){
		if($("#"+name).val()!=val){
			msg="确认密码不一致";
			$(oShow).show();
			$(oShow).html(msg);
			return false;
		}
	}
	if(key.indexOf("/验证码/")>-1){
		if($("#"+name).val()!=val){
			msg="验证码不一致";
			$(oShow).show();
			$(oShow).html(msg);
			return false;
		}
	}
	if(key.indexOf("/email/")>-1){
		var filter  = /^(\s*)([a-zA-Z0-9_\.\-+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+(\s*)$/;
		if (!filter.test(val)) 
		{
			msg="Email格式不正确";
			$(oShow).show();
			$(oShow).html(msg);
			return false;
		}
	}
	return true;
}

// doReply
function doReply(cid) {
	$('#replyform').remove();
	$('#comment_'+cid+'>div.c').after('<div id="replyform" class="ccmtform">'+$('#commentform').html()+'</div>');
	$('#replyform h2').html('回复');
	$('#replyform div.tip').hide();
	$('#replyform div.cmtvotes').remove();
	$("#replyform input[name='cid']").val(cid);
	$("#replyform textarea").width( $("#replyform h2").width()-8 );
	$("#replyform input[name='submit']").val('回复');
}

// doCommentAppend
function doCommentAppend(id,cid,t) {
	if(cid>0) {
		$('#ccommentlist_'+cid).append(t);
	} else {
		$('#comment div.nocomment').remove();
		if($('ul#commentlist').length<1) {
			$('#comment').append('<ul id="commentlist" class="commentlist"></ul>');
		}
		$('ul#commentlist').prepend(t);
		onScrollTo('#comment');
	}
	$('#comment_'+id).hide();
	$('#comment_'+id).slideDown("slow");
}

// doCommentSubmit
function doCommentSubmit(fm) {
	$(fm).find("div.tip").html("正在提交，请稍后...");
	$(fm).find("div.tip").show();
	return ajax_submit(fm,function(rs){
		if( ajax_result(rs) ) {
			$(fm).find("textarea").val("");
			$(fm).find("div.tip").html(rs.msg);
			onUpdatePopWin('<center>'+rs.data+'</center>');
			setTimeout('$("div.tip").fadeOut("slow");$("#replyform").slideUp("slow",function(){$("#replyform").remove();});',1500);
			onClosePopWin();
		} else {
			$(fm).find("div.tip").html(rs.msg);
			if( rs.msg=='对不起，你还没有登录，请先登录！') {
				onCreatPopWin('<center>'+rs.msg+'</center>')
				onUpdatePopWin(rs.data);
				setTimeout('$("div.tip").fadeOut("slow")',1500);
			} else {
				onUpdatePopWin('<center>'+rs.msg+'</center>',1);
				setTimeout('$("div.tip").fadeOut("slow")',1500);
				onClosePopWin();
			}
		}
		ajax_finished(fm,rs.msg);
	});
}
