 /*---------------------------------------------------
 // 日期格式化
 // 格式 YYYY/yyyy/YY/yy 表示年份
 // MM/M 月份
 // W/w 星期
 // dd/DD/d/D 日期
 // hh/HH/h/H 时间
 // mm/m 分钟
 // ss/SS/s/S 秒
 //-----------------------------------------------**/
 Date.prototype.Format = function(formatStr)
 {
	 var str = formatStr;
	 var Week = ['日','一','二','三','四','五','六'];

	 str=str.replace(/yyyy|YYYY/,this.getFullYear());
	 str=str.replace(/yy|YY/,(this.getYear() % 100)>9?(this.getYear() % 100).toString():'0' + (this.getYear() % 100));

	 str=str.replace(/MM/,this.getMonth()>8?(1+this.getMonth()).toString():'0' + (1 + this.getMonth()));
	 str=str.replace(/M/g,this.getMonth() + 1);

	 str=str.replace(/w|W/g,Week[this.getDay()]);

	 str=str.replace(/dd|DD/,this.getDate()>9?this.getDate().toString():'0' + this.getDate());
	 str=str.replace(/d|D/g,this.getDate());

	 str=str.replace(/hh|HH/,this.getHours()>9?this.getHours().toString():'0' + this.getHours());
	 str=str.replace(/h|H/g,this.getHours());
	 str=str.replace(/mm/,this.getMinutes()>9?this.getMinutes().toString():'0' + this.getMinutes());
	 str=str.replace(/m/g,this.getMinutes());

	 str=str.replace(/ss|SS/,this.getSeconds()>9?this.getSeconds().toString():'0' + this.getSeconds());
	 str=str.replace(/s|S/g,this.getSeconds());

	 return str;
 }

if (typeof kcms=="undefined"){kcms={};}
kcms.getCookie = function( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

kcms.setCookie = function( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

kcms.deleteCookie = function( name, path, domain ) {
	if ( kcms.getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

kcms.getUserInfo = function(){
	var tmp = {};
	var tmp_ = unescape(kcms.getCookie("jjv"));
	if (tmp_)
	{
		var and = tmp_.split("&");
		for (var _i in and)
		{
			var _j = and[_i].split("=");
			tmp[_j[0]] = unescape(_j[1]);
		}
	}
	return tmp;
}
String.prototype.replaceAll  = function(s1,s2){   
return this.replace(new RegExp(s1,"gm"),s2);   
}  
kcms.isowner = function(){return kcms.info && kcms.info.u_id && kcms.info.u_id==kcms.getUserInfo()['uid']}
kcms.isadmin = function(){return kcms.getUserInfo()['am']=='1';}
kcms.islogin = function(){return kcms.getUserInfo()['uid']}
kcms.showLogin = function(url){
	if(kcms.islogin()){return 0;}
	$.fancybox.showActivity();
	$.fancybox(url,{
        'autoScale'     	: false,
		'width'             :  460,
		'height'            : 160,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'scrolling'            : 'no',
		'autoDimensions'    : false,
		'type'				: 'iframe'});	
}

kcms.checklogin = function(){
	$.post("/kcms/blog/islogin",{},function(data){
           if(data.uid == 0){
                kcms.deleteCookie("jjv");
                kcms.deleteCookie("session_id_kcms");
         	$("#topnologin").show();
		$("#toplogin").hide();		
          }else{
	       	$("#topnologin").hide();
		$("#toplogin").show();
          }
        },"json");
}

//window.setInterval("kcms.checklogin()",10000);

