package com.xt.hb.utils
{
	import flash.display.DisplayObject;
	
	import mx.core.FlexGlobals;
	import mx.formatters.DateFormatter;
	import mx.managers.PopUpManager;
	
	import spark.components.TitleWindow;
	import spark.effects.Scale;

	public class CommonUtils
	{
		public function CommonUtils()
		{
		}
		
		/** YYYY年MM月DD日 HH:NN:SS */
		public static var DATE_SECOND_FMT:String = 'YYYY年MM月DD日 HH:NN:SS';
		/** yyyy-MM-dd HH:mm */
		public static var DATE_MIN_FMT:String = 'YYYY-MM-DD HH:NN';
		
		/**
		 * 日期格式化：YYYY年MM月DD日 HH:NN:SS
		 */
		public static function formatDate(date:Date):String{
			var df:DateFormatter = new DateFormatter(); 
			df.formatString = DATE_SECOND_FMT; 
			var st1:String = df.format(date); 
			return st1 ;
		}
		/**
		 * 日期格式化, 根据指定格式
		 */
		public static function formatPatternDate(date:Date, pattern:String):String{
			var df:DateFormatter = new DateFormatter(); 
			df.formatString = pattern; 
			var st1:String = df.format(date); 
			return st1 ;
		}
		/**
		 * 显示弹出窗口
		 */
		public static function showTitleWindow(win:TitleWindow,model:Boolean = true,x:Number = -1,y:Number = -1):void
		{
			PopUpManager.addPopUp(win,DisplayObject(FlexGlobals.topLevelApplication),model);
			PopUpManager.centerPopUp(win);
			if(x > 0 && y > 0)
			{
				win.x = x;
				win.y = y;
			}
			var scale:Scale = new Scale();
			scale.autoCenterTransform = true;    //设置以中心点缩放
			scale.target = win;　　　　//设置Scale的作用对象为windowView
			scale.duration = 500;　　　　　　//设置效果的持续时间
			scale.scaleXFrom = 0;　　　　　　//设置scaleX和scaleY的起始，终点大小
			scale.scaleXTo = 1;
			scale.scaleYFrom = 0;
			scale.scaleYTo = 1;
			scale.play();
		}
		public static function formatETA(eta:String):String{
			var numEte:int = Number(eta);
			if(numEte==0)
				return "" ;
			var month:Number = int(numEte/65536.0);
			var day:Number = int((numEte - month * 65536)/2048.0);
			var hour:Number = int((numEte - month * 65536 - day * 2048)/64.0);
			var min:Number = numEte - month * 65536 - day * 2048 - hour * 64;
			return month+"月"+day+"日"+hour+"时"+min+"分" ;
		}
		/**
		 * null or undefined 处理
		 */
		public static function nullToEmpty(str:String):String{
			if(null == str || "undefined" == str || "null" == str) {
				return "";
			} else {
				return str;
			}
			
		}
	}
}