/*
************************
**Auther:张老黑 AS Commandos Black Hurricane@www.dewsong.com
**E-mail:old-black@163.com
************************
**
************************
*/
var config=new function(){
	this.MaskColor='#F1F9FE';//浮动窗口颜色
	this.CueLeft=16;//默认的提示显示位置
	this.CueTop=16;//默认的提示显示位置
}
//tip对象
var Tip=new function(){
	var style='normal';
	var nomask=false;
	this.ctObj=null;
	this.ctId='';
	this.ctType='';
	this.count=0;
	this.cTO=null;
	this.Tip=function(msg,style,obj){
		if (!obj) Tip.Cue(msg,style);
		else{
			if (ie) document.body.style.height='100.1%';
			var tipObj=$c('div');
			tipObj.id='tip_'+timeStr();
			tipObj.className='cmsUI tip '+style;
			tipObj.innerHTML=msg+'<div class="angle"></div>';
			var of=getOffset(obj);
			tipObj.style.left=of.x+'px';
			tipObj.style.top=(of.y-28)+'px';
			document.body.appendChild(tipObj);
			if (ie) document.body.style.height='100%';//处理ie下border消失Bug
			Tip.ctType='Tip';
			Tip.ctObj=tipObj;
			Tip.ctId=tipObj.id;
			$e(obj,'blur',Tip.Cancel);
		}
	}
	this.Cue=function(msg,style){
		var cueObj=$c('div');
		cueObj.id='cue_'+timeStr();
		cueObj.className='cmsUI cue '+style;
		cueObj.innerHTML=msg;
		cueObj.style.left=config.CueLeft+'px';
		cueObj.style.top=(config.CueTop+getPageSize().sT)+'px';
		document.body.appendChild(cueObj);
		Tip.ctType='Cue';
		Tip.ctObj=cueObj;
		Tip.ctId=cueObj.id;
		Tip.count=3;
		Tip.cTO=setTimeout(Tip.CountDown,1000);
	}
	this.Warn=function(msg,style,nomask,para){//para=string 替换为按钮文字 para=int n秒后自动关闭
		var id='warn_'+timeStr();
		var btn='确定';
		var pt=getObjType(para);
		switch (pt){
			case 'string':
				btn=para;break;
			case 'number':
				btn='窗口将在'+para+'秒后关闭';break;
		}
		msg='<div class="icon"></div><div class="msg">'+msg+'</div><div class="btns"><a class="btn" href="javascript:void(0)" onclick="Tip.Cancel();">'+btn+'</a></div>';
		var warnForm=new floatForm(id,msg,'cmsUI warn '+style,280,nomask);
		warnForm.Show();
		Tip.ctType='Warn';
		Tip.ctObj=warnForm;
		Tip.ctId=id;
		if (pt=='number'){
			clearTimeout(Tip.cTO);
			Tip.count=para;
			Tip.cTO=setTimeout(Tip.CountDown,1000);
		}
	}
	this.Confirm=function(msg,style,nomask){
	}
	this.Cusfirm=function(msg,style,nomask,para){//para=操作数组
		var id='cus_'+timeStr();
		if (getObjType(para)!='array'&&para.length<1){
			Tip.Warn(msg,style,nomask);
		}
		else{
			msg='<div class="icon"></div><div class="msg">'+msg+'</div><div class="btns"></div>';
			var cusForm=new floatForm(id,msg,'cmsUI cusfirm '+style,280,nomask);
			cusForm.Show();
			for (var i in para){
				var btn=$c('a');
				btn.className='btn';
				btn.href='javascript:void(0);';
				btn.innerHTML=para[i][0];
				$e(btn,'click',para[i][1]);
				$a(g(id).childNodes[2],btn);
			}
			Tip.ctType='Cusfirm';
			Tip.ctObj=cusForm;
			Tip.ctId=id;
		}
	}
	this.CountDown=function(){
		if (Tip.count<=0) Tip.Cancel();
		else{
			Tip.count--;
			if (Tip.ctType!='Cue') g(Tip.ctId).childNodes[2].childNodes[0].innerHTML='窗口将在'+Tip.count+'秒后关闭';
			Tip.cTO=setTimeout(Tip.CountDown,1000);
		}
	}

	this.Cancel=function(){
		clearTimeout(Tip.cTO);
		if (Tip.ctObj){
			if (Tip.ctType=='Tip'||Tip.ctType=='Cue'){
				$d(Tip.ctObj);
			}
			else{
				Tip.ctObj.Hide();
			}
		}
	}
}
function getPageSize(){//获得页面实际大小
	var ws={};
	if(window.pageYOffset){
		ws.sT=window.pageYOffset;
		ws.sL=window.pageXOffset;
	}
	else if(document.documentElement&&document.documentElement.scrollTop){
		ws.sT=document.documentElement.scrollTop;
		ws.sL=document.documentElement.scrollLeft;
	}
	else if(document.body){
		ws.sT=document.body.scrollTop;
		ws.sL=document.body.scrollLeft;
	}
	if(window.innerHeight&&window.scrollMaxY){
		ws.xS=document.body.scrollWidth;
		ws.yS=window.innerHeight+window.scrollMaxY;
	}
	else if(document.body.scrollHeight>document.body.offsetHeight){
		ws.xS=document.body.scrollWidth;
		ws.yS=document.body.scrollHeight;
	}
	else{
		ws.xS=document.body.offsetWidth;
		ws.yS=document.body.offsetHeight;
	}
	if (self.innerHeight){
		ws.wW=self.innerWidth;
		ws.wh=self.innerHeight;
	}
	else if(document.documentElement&&document.documentElement.clientHeight){
		ws.wW=document.documentElement.clientWidth;
		ws.wh=document.documentElement.clientHeight;
	}
	else if (document.body){
		ws.wW=document.body.clientWidth;
		ws.wh=document.body.clientHeight;
	}
	ws.pH=ws.yS<ws.wh?ws.wh:ws.yS;
	ws.pW=ws.xS<ws.wW?ws.wW:ws.xS;
	return ws;
}
function getOffset(O){//获取对象实际偏移量
	var of={};
	if (ie){
		of.x=0;
		of.y=0;
		while(O&&O.tagName.toUpperCase()!="BODY") {
			of.x+=O.offsetLeft;
			of.y+=O.offsetTop;
			O=O.offsetParent;
		}
	}
	else{
		of.x=parseInt(O.offsetLeft);
		of.y=parseInt(O.offsetTop);
	}
	return of;
}
function floatForm(id,s,c,w,nm,t){//id,内容,class,宽,遮罩,顶
	var fF=this;
	if (!t) t=120;
	fF.Show=function(){
		if (!nm) fF.Lock();
		if (!g(id)){
			var ps=getPageSize();
			var f=$c('div');
			f.id=id;
			f.className='floatForm '+c;
			f.style.width=w+'px';
			f.style.top=(ps.sT+t)+'px';
			f.style.left=parseInt((ps.pW-w)/2)+'px';
			f.innerHTML=s;
			document.body.appendChild(f);
		}
		else{
			g(id).style.top=(getPageSize.sT+t)+'px';
		}
	}
	fF.Hide=function(){
		if (g(id)){
			g(id).style.top='-9999px';
			if (!nm) $d(g('bM'));
		}
	}
	fF.Lock=function(){
		if (!g('bM')){
			var b=$c('div');
			b.id='bM';
			b.className='bigMask';
			b.style.height=getPageSize().pH+'px';
			b.style.backgroundColor=config.MaskColor;
			ie?b.style.filter='Alpha(opacity=0)':b.style.MozOpacity=0;
			document.body.appendChild(b);
			divAlpha(7,56,b);
		}
	}
}