$(function(){
	$.yf_base = {
		isSignedin : function(open){
			if(document.cookie.indexOf("YF_FRONT_SSO") > -1){
				return true;
			}else{
				if(open !== false) this.signinMsg();
				return false;
			}
		},      
        signinMsg : function(){
        },
		checkForm : function(el){
			var els = el.find("input, select, textarea");
			return this.checkInputs(els);
		},
		checkInputs : function(els){
			var r = true;
            var ob = this;
            els.each(function(){
                var tel = $(this);
              if(tel.data("check")){
                  if(tel.data("checked") == undefined){
                      if(!ob.inputCheck(tel)){
                          r = false;
                      }
                  }else{
                      if(tel.data("checked") == "error"){
                          r = false;
                      }
                  }
              }
            });
			return r;
		},
		inputAction : function(els){
			var ob = this;
			els.each(function(){
                el = $(this);
				ob.inputExplainShow(el);
				el.on("focus", function(){
					ob.inputExplainHidden($(this));
					ob.inputTips($(this));
				}).on("blur", function(){
					ob.inputCheck($(this));
					ob.inputExplainShow($(this));
                    ob.buttonTips($(this));
				});
			});
		},
		inputExplainShow : function(el){
			if(el.attr("type") == "password") return;
			var v = $.trim(el.val()),
			e = el.data("explain");
			if(e && (v == "" || v == e)){
				el.addClass("input-explain");
				el.val(e);
			}
		},
		inputExplainHidden : function(el){
			var t = el.data("type");
			if(el.hasClass("input-explain")){
				el.removeClass("input-explain");
				el.val("");
				if(t != ""){
					el.attr("type", t);
				}
			}
		},
		inputCheck : function(el){
			var fd = this, c = el.data("check"), v = $.trim(el.val()), r = true;
			if(!c) return;
			el.data("checked", "");
			if(c && c != ""){
				eval("c = "+c);
				if(!$.isArray(c)) c = [c];
				for(i in c){
					if(c[i].sl){
						var len = c[i].sl.split(",");
						if(v.length < len[0]/1){
							r = false;
						}else if(len[1] && v.length > len[1]/1){
							r = false;
						}else{
							r = true;
						}
					}else if(c[i].u){
						fd.inputTips(el, "loading");
						el.data("checked", "loading");
						return false;
					}else{
						c[i].we = c[i].we != 'empty' ? c[i].we : eval('/^(|'+el.data("explain")+')$/');
						if(c[i].re && !c[i].re.test(v) || c[i].we && c[i].we.test(v)){
							r = false;
							break;
						}
					}
				}
			}
			if(r) {
				fd.inputTips(el, "success");
			}else{
				fd.inputTips(el, "error", c[i].t);
			}
			return r;
		},
		inputTips : function(el, type, text){
			text = text || "";
			var a_el = el.parent("dd") || el.parent(".btn");
			if(0 === a_el.length) return;
			var em_el = a_el.find(".input-tips");
			if(em_el.length>0){
				em_el.attr("class", "input-tips input-tips-"+type);
				em_el.html('<i>&lt;</i>'+text);
			}else{
				a_el.append('<em class="input-tips input-tips-'+type+'"><i>&lt;</i>'+text+'</em>');
			}
			if(type) el.data("checked", type);
			el.removeClass('input-error').addClass('input-'+type);
		},
        buttonTips : function(el) {
            var t_el = el.parents("form").find("button[type=submit]:last").next("em");
            if (t_el.length>0 && t_el.hasClass("input-tips"))
                t_el.removeClass("input-tips-error input-tips-success btn-loading");
                
        },
		jumpPage : function(url){
			window.location.href=url;
		},
		rechargeMsg : function(){
			jAlert("充值");
		}
   } 
});


$(function(){
    /* 统一处理身份认证提示 */
    $("#user .user-acc-nomobile").attr("title", "手机未认证");        
    $("#user .user-acc-mobile").attr("title", "手机已认证");        
    $("#user .user-acc-noemail").attr("title", "邮箱未认证");        
    $("#user .user-acc-email").attr("title", "邮箱已认证");        
    $("#user .user-acc-noidcard").attr("title", "身份未认证");        
    $("#user .user-acc-idcard").attr("title", "身份已认证");        
});
// 输入字数提醒与限制
function storeCaret (textEl) {
	if (textEl.createTextRange){textEl.caretPos = document.selection.createRange().duplicate();}
	var len = getLength(textEl.value);
	/* 限制输入，超出自动截取 */
	if (len > 1000) {
		$(".input-limit").val(textEl.value.substring(0, 1000));
	}
	$(".input-counter").html(rem(len));
}
/* 字数统计提示 */
function rem(len){
	var html = '';
	if(len>0){html='(<em>'+(1000-len)+'</em>/1000)';}
	//if(len>140){html='已超出<em>'+(140-len)*(-1)+"</em>字";}
	if(len===0){html='(<em>1</em>/1000)';}
	return html;
}
/* 计算内容长度 */
function getLength(str) {
	var len = jQuery.trim(str).length;
	if (len > 0) {
		return Math.ceil(bLength(jQuery.trim(str)) / 2);
	} else {
		return 0;
	}
}
/* 计算汉字长度，一个汉字算两个字符 */
function bLength(str){
    if (typeof str == "undefined") {
        return 0;
    }
    var aMatch = str.match(/[^\x00-\x80]/g);
    return (str.length + (!aMatch ? 0 : aMatch.length));
}
/* 中文字符串截取，中文字两个字节 */
function cnSubString(str,len) {
    var strlen = 0; 
    var s = "";
    for(var i = 0;i < str.length;i++) {
        if(str.charCodeAt(i) > 128){
            strlen += 2;
        }else{ 
            strlen++;
        }
        s += str.charAt(i);
        if(strlen >= len){ 
            return s;
        }
    }
    return s;
}
/* 关闭提示 */
$(".pormpt_closeBtn").on("click", function(){
   $(this).parent().slideUp("slow");	  
});
/* 关注滑动提示框 */
(function(win) {	

	var tips = function(obj,msg) {
			var _animate = $(obj).attr('data-animate');
			if (!!_animate) { return false;}
			$(obj).attr('data-animate','animate')
			var w = $(obj).outerWidth();
			var h = $(obj).outerHeight();
			var _duration = 300;				// 动画持续时间
			var _delay = 600;							// 提示显示时间
			var offset = $(obj).offset();
			var t = offset.top;
			var $tip = $("<div class='tipLayer' style='top:"+t+"px'><div class='m_m'><i></i>"+msg+"</div><div class='arrow'><b class='outter'></b><b class='inner'></b></div></div>");
			$('body').append($tip);
			//$(obj).toggleClass(_class).text(_text[state]);
			$tip.find('.m_m').css('display','block');
			var ww = $tip.outerWidth();
			var l = offset.left + w/2 - ww/2;
			$tip.find('.arrow').fadeIn(_duration);
			//$tip.find('.m_m').fadeIn(_duration);
			$tip.find('.m_m').animate({opacity:1},_duration)
			$tip.css({
				left:l,
				display:'block'
			}).animate({'margin-top':(-1*h - 7)},_duration);
			setTimeout(function() {
				$(obj).removeAttr('data-animate');				
				$tip.animate({
					'margin-top':-2*h
				},_duration,function() {
					$(this).remove();
				});
				$tip.find('.arrow').fadeOut(_duration);
				$tip.find('.m_m').fadeOut(_duration);
			},(_delay+_duration));

	}
	win.tips = tips;

})(window);
/* 顶部菜单 */
    (function($) {

			$.fn.YF_sliderMenu = function(target) {
				var delay = 50;							// 鼠标放上去延迟显示下拉菜单
				var timer ;
				$(this).each(function() {
					$(this).bind('mouseenter',msOver);
					$(this).bind('mouseleave',msLeave);
				});
			
				function msOver () {
					var $self = $(this);
					timer = setTimeout(function() {
						$self.addClass('header-info-hover');
					},delay)
				}
				function msLeave () {
					clearTimeout(timer);
					$(this).removeClass('header-info-hover');
				}
			};

    })(jQuery);


