function fajax(url,params,callback,ifcache) {
    jQuery.ajaxSetup({
        cache: ifcache
    });
    jQuery.ajax({
        type: "POST",
        url: url,
        data: params,
        cache: false,
        success: callback
    });
}

function countStrLength(stringToCount) { 
     var c = stringToCount.match(/[^ -~]/g);  
     return stringToCount.length + (c ? c.length : 0);  
}

var ftime=null;
jQuery(function() {
    ftime=new Date();
    ftime1=new Date();
    // var ftimeS = '{{$ftime}}'; // Now, located in vheader.tpl
    ftime.setTime(ftimeS);
    ftime1.setTime(ftimeS);
    self.setInterval("flushTime()",1000);

    var determinedate = ftime1;
    var D = determinedate.getDay();
    if(D == 0) 
        D = 7;
    determinedate.setDate(determinedate.getDate() + (4 - D));
    var YN = determinedate.getFullYear();
    var ZBDoCY = Math.floor((determinedate.getTime() - new Date(YN, 0, 1, -6)) / 86400000);
    var WN = 1 + Math.floor(ZBDoCY / 7);

    var determinedate1 = ftime1;
    determinedate1.setMonth(determinedate1.getMonth()-3*(fseasoncount-1));
    var D1 = determinedate1.getDay();
    if(D1 == 0) 
        D1 = 7;
    determinedate1.setDate(determinedate1.getDate() + (4 - D));
    var YN1 = determinedate1.getFullYear();
    var ZBDoCY1 = Math.floor((determinedate1.getTime() - new Date(YN1, 0, 1, -6)) / 86400000);
    var WN1 = 1 + Math.floor(ZBDoCY1 / 7);

    //jQuery("#curWeek").html("第 " + (WN-WN1-1) + " 周 ");
});
var f_firsttime = true;
function flushTime() {
    jQuery("#curTime").html(ftime.getFullYear() + "-" + (ftime.getMonth()+1) + "-" + ftime.getDate() + " " + ftime.getHours() + ":" + ftime.getMinutes() + ":" + ftime.getSeconds());
    ftime.setTime(ftime.getTime() + 1000);
    if( f_firsttime ) {
        jQuery("#ftimezone").fadeIn(2000);
        f_firsttime = false;
    }
}

function checkName(name) {
    //var pattern_cn = /^[a-zA-Z\u4E00-\u9FA5\uFE30-\uFFA0]*$/g;
    var pattern_cn = /^[a-zA-Z\u4E00-\u9FA5\uFE30-\uFFA0]*$/g;
    if(pattern_cn.test(name)) {
        return true;
    } else {
        return false;
    }
}
function checkEmail(str) {
    var reg = /^([.a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,}){1,})$/;
    return reg.test(str);
}

function len(strTemp) {  
    var i,sum;
    sum=0;
    for(i=0;i<strTemp.length;i++) {
        if ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt(i)<=255))
            sum=sum+1;
        else
            sum=sum+2;
    }
    return sum;
}

function checkUname(uname) {
    var name = uname
    var length = len(name);

    if ( length >= 4 && length <= 12 )
    	return true;
    else
    	return false;
//    var pattern_cn = /^[a-zA-Z]+[a-zA-Z0-9\u4E00-\u9FA5\uFE30-\uFFA0]*$/g;
//    var re = new RegExp(pattern_cn);
//    if(re.test(name)) {
//        if( length >= 4 && length < 13 ) {
//            return true;//alert("true");
//        } else {
//            return false;//alert("false");
//        }
//    } else {
//        return false;alert("false");
//    }
}

function checkPassport(passport) {
    var name = passport
    var length = len(name);
    var pattern_cn = /^[a-zA-Z]+[a-zA-Z0-9]*$/g;
    var re = new RegExp(pattern_cn);
    if(re.test(name)) {
        if( length >= 6 && length <= 20 ) {
            return true;//alert("true");
        } else {
            return false;//alert("false");
        }
    } else {
        return false;//alert("false");
    }
}
function checkPasswd(passwd) {
    var passwd = passwd;
    var length = len(passwd);
    if( length > 6 && length < 32 ) {
        return true;//alert("true");
    } else {
        return false;//alert("false");
    }
}

function notice(msg) {
    alert(msg);
}

// 统一Ajax按钮调用 [Start]
var curClickBtnId = "";
var btnHref="";
var btnOnclick="";
function btnEvent(url,id) {
    curClickBtnId = id;
    jQuery("#"+curClickBtnId).attr("disabled","true");
    jQuery("#"+curClickBtnId).addClass("button4");
    fajax(url,"",btnCallback,false);
	btnHref=jQuery("#"+curClickBtnId).attr("href");
	btnOnclick=jQuery("#"+curClickBtnId).attr("onclick");
	jQuery("#"+curClickBtnId).attr("href","");
}

function btnCallback(data) {
    data = eval($.trim(data));
    data = data[0];
    // 显示滚出提示
    // Content Content2_box content_yi
    if( data.res != 'null' ) {
        alert(URLDecode(data.msg));
    }
    // 执行返回函数
    if( data.callback != 'null' ) {
        eval(data.callback);
    }
    jQuery("#"+curClickBtnId).attr("disabled","");
    jQuery("#"+curClickBtnId).removeClass("button4");
    jQuery("#"+curClickBtnId).attr("href",btnHref);
	curClickBtnId = "";
}
// 统一Ajax按钮调用 [End]

function URLEncode(unencodedValue )
{
    return encodeURIComponent(unencodedValue);
};

function URLDecode(encodedValue)
{
    return decodeURIComponent(encodedValue);
};

function flushGif() {
    $(".needFlushImg").each(
        function() {
            $(this).html($(this).html())
        });
}


//导航下拉菜单
function displaySubMenu(li) {
    jQuery("#"+li).css("display","block");
}   
function hideSubMenu(li) {
    jQuery("#"+li).css("display","none");
}
		
//搜索文本框鼠标经过变空	
function defaultText(obj, text) {
	if (obj.value == text) obj.value = "";
	else if (obj.value == "") obj.value = text;
}

//左侧公告显示隐藏
function init(){
		 if(!document.getElementById || !document.getElementsByTagName){retun;}
		 var arrayDiv=document.getElementById("levelmenu");
		 if(!arrayDiv){return;}
		 var divObj=arrayDiv.getElementsByTagName("div");
		 var length=divObj.length;
		 var agreeDiv=new Array();
		 for(var i=0;i<length;i++){
		  if(divObj[i].className.indexOf("unit")>=0){
		   agreeDiv.push(divObj[i]);
		   divObj[i].onclick=function(event){
			showCurrentMenu(agreeDiv,this,event);
		   }
		  }
		 }
		}
		function showCurrentMenu(agreeDiv,currentObj,event){
		 if(!event){event=window.event;}
		 var eventObj=event.srcElement?event.srcElement:event.target;
		 //先隐藏所有ul
		 var length=agreeDiv.length;
		 for(var i=0;i<length;i++){
		  if(eventObj.parentNode==agreeDiv[i] || eventObj.nodeName!="H5"){continue;}
		  agreeDiv[i].className="unit";
		 }
		 if(eventObj.nodeName=="H5"){
		  if(eventObj.parentNode.className=="unit"){
		   eventObj.parentNode.className="unit current"
		  }else{
		   eventObj.parentNode.className="unit"
		  }
		 }
		}
		window.onload = init;
		
//隔行变色
function senfe(o,a,b,c,d){
 var t=document.getElementById(o).getElementsByTagName("tr");
 for(var i=0;i<t.length;i++){
  t[i].style.backgroundColor=(t[i].sectionRowIndex%2==0)?a:b;
  t[i].onclick=function(){
   if(this.x!="1"){
    this.x="1";//本来打算直接用背景色判断，FF获取到的背景是RGB值，不好判断
    this.style.backgroundColor=d;
   }else{
    this.x="0";
    this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b;
   }
  }
  t[i].onmouseover=function(){
   if(this.x!="1")this.style.backgroundColor=c;
  }
  t[i].onmouseout=function(){
   if(this.x!="1")this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b;
  }
 }
}




//按钮点击事件防止重复提交
function btnEventNew(url,idLink) {
	var $state=$("#"+idLink).attr("click");
	if($state=="false"){
		return;
	}
	//发送ajax请求
    fajaxNew(url,"",btnCallbackNew,false,idLink);
	
}
function btnCallbackNew(data) {
    data = eval($.trim(data));
    data = data[0];
    //显示提示信息
    if( data.res != 'null' ) {
        alert(URLDecode(data.msg));
    }
    //执行自定义的js函数
    if( data.callback != 'null' ) {
        eval(data.callback);
    }
    //判断是否需要刷新当前页面
    if(data.isRefresh=="true"){
    	window.location.reload();
    }
}


function fajaxNew(url,params,callback,ifcache,id) {
	var $oldHtml=$("#"+id).html();
	var $oldClass=$("#"+id).attr("class");
    jQuery.ajaxSetup({
        cache: ifcache
    });
    jQuery.ajax({
        type: "POST",
        url: url,
        data: params,
        cache: false,
		beforeSend: function(XMLHttpRequest){
			$("#"+id).attr("click","false");
			$("#"+id).addClass("button4");
			$("#"+id).html("<span>处理中</span>");
		},
		complete: function(XMLHttpRequest, textStatus){
			$("#"+id).attr("click","true");
			$("#"+id).removeClass("button4");
			$("#"+id).html($oldHtml);
		},
        success: callback
    });
}

//禁止点击
//function banClick(idLink){
//	//自动外绕一个层
//	$("#"+idLink).wrap("<div id='btban"+idLink+"' style='position:relative;zoom:1;'></div>");
//	//自动获取父元素
//	var idDiv=$("#"+idLink).parent().attr("id");
//	// 处理父元素信息
//	var parentDiv=$("#"+idDiv);
//	var poffset=parentDiv.offset();
//	var ptop=poffset.top;
//	var pleft=poffset.left;
//	var pwidth=parentDiv.width();
//	var pwidth=parseInt(pwidth);
//	//alert("parentDiv width:"+pwidth+"top:"+ptop+"left:"+pleft);
//	//处理子元素信息
//	var clinkButton=$("#"+idLink);
//	var coffset=clinkButton.offset();
//	var ctop=coffset.top;
//	var cleft=coffset.left;
//	var cwidth=clinkButton.width();
//	var cwidth=parseInt(cwidth);
//	//alert("childDiv width:"+cwidth+"top:"+ctop+"left:"+cleft);
//	//计算元素的定点位置
//	var top=parseInt(ctop)-parseInt(ptop);
//	var left=parseInt(cleft)-parseInt(pleft);
//	var width=cwidth;
//	//alert("top:"+top+"left:"+left+"width:"+width);
//	//动态创建一个层用来覆盖当前点击的按钮，避免点击事件的再次发生
//	$("#"+idDiv).append("<div id='div"+idLink+"' style='width:"+width+"px;position:absolute;top:"+top+"px;left:"+left+"px;'><a class='button4' style='width:"+width+"px;'><span>处理中</span></a></div>"); 
//}
//
////允许点击
//function permitClick(idLink){
//	//获取同辈元素,并克隆，并插入在父元素之后
//	$("#div"+idLink).siblings("a").clone().insertAfter("#btban"+idLink);
//	//移除创建的层，供下次再次调用
//    $("#div"+idLink).remove(); 
//	$("#btban"+idLink).remove();
//}

(function($){
	$().ready(function(){
		$(".viptips").hover(function(){
			$(this).addClass("viptips-hover");

		},
		function(){
			$(this).removeClass("viptips-hover");
		})
	})
})(jQuery)
