//调用opacityBase.js

//boxString;box的html;
//o.closeElement;
/*
	事件：
		初始事件,initE
		关闭事件,closeE
		点确认事件,confirm
		点取消事件,cencelE
		内容载入事件,contentInitE

*/
/*
var boxINI={
	title:"div.dialogTitleContent",--------------标题element
	content:"div.dialogContent",--------------内容element
	close:"div.dialogClose",--------------关闭element
	buttonA:"button.buttonA",--------------确认button
	buttonB:"button.buttonB",--------------取消button
	buttonAcontent:"button.buttonA div.buttonRight",--------------默认确认button内容
	buttonBcontent:"button.buttonB div.buttonRight",--------------默认取消button内容
	autoWidth:"320px"--------------默认宽度
};
*/

//InuBox.alert(content,title);
//InuBox.confirm(content,title,o);o.confirmE//确认事件
//InuBox.window(content,title,o);
	/*
	o.width;宽度
	o.base;灰色背景是否存在，默认存在,
	o.confirmText;确认按钮中的文本
	o.cencelText;取消按钮中文本
	o.buttonA(hide,show)确认按钮是否存在,默认存在;
	o.buttonB(hide,show)取消按钮是否存在,默认存在;
	o.confirmE；确认事件,
	o.cencelE;取消事件
	o.contentInitE;初始事件
	*/

var escObject=null;
jQuery(document).keydown(function(event){
	if(event.keyCode==27)
	{
		if(escObject!=null){escObject.hide();}
	}
});
var confirm=null;
jQuery(document).keydown(function(event){
	if(event.keyCode==13&&event.target.tagName.toLocaleLowerCase()!="textarea"&&event.target.className.indexOf("buttonA")<0)
	{
		if(escObject!=null){escObject.buttonA.focus();}
	}
});

function InuBox(boxString,o)
{
	o=o||{};
	var id="id"+new Date().getTime()+""+Math.round(Math.random()*100);
	boxString=boxString.replace(">"," id='"+id+"'>");
	
	jQuery(document.body).append(boxString);
	this.box=jQuery("#"+id);
	this.box.css("position","absolute");
	this.box.hide();
	
	this.autoWidth=o.autoWidth||"320px";
	
	this.title=this.box.find(o.title||"");
	this.content=this.box.find(o.content||"");
	this.close=this.box.find(o.close||"");
	this.buttonA=this.box.find(o.buttonA||"");
	this.buttonB=this.box.find(o.buttonB||"");
	this.buttonAcontent=this.box.find(o.buttonAcontent||"");
	this.buttonBcontent=this.box.find(o.buttonBcontent||"");
	this.form=this.box.find("form");
	
	this.title.xiaoliMoveDiv(this.box);
	
	this.initE();
	
}

InuBox.prototype.hide=function()
{
	this.box.hide();
	opacityBase.hide();
	escObject=null;
}

InuBox.prototype.alert=function(content,title)
{
	this.box.show();
	this.box.css("width",this.autoWidth);
	opacityBase.show();
	if(this.title.length>0){this.title.html(title||pageText["boxTitle"])};
	content='<div class="alertContent">'+content+'</div>';
	if(this.content.length>0){
		this.content.html(content||"");
	};
	
	if(this.buttonA.length>0)
	{
		this.buttonA.show();
		this.buttonA[0].onclick=function(){xThis.closeE.call(xThis)};
	};
	if(this.buttonAcontent.length>0){this.buttonAcontent.html(pageText["alertConfirm"])};
	
	if(this.buttonB.length>0){this.buttonB.hide()};
	if(this.buttonBcontent.length>0){this.buttonBcontent.html(pageText["cencel"])};
	
	this.box.xiaoliCenter();
	
	if(this.close.length>0)
	{
		var xThis=this;
		this.close[0].onclick=function(){xThis.closeE.call(xThis)};
	}
	escObject=this;//Enter,Esc
}

InuBox.prototype.confirm=function(content,title,o)
{
	var o=o||{};
	this.box.show();
	this.box.css("width",this.autoWidth);
	opacityBase.show();
	if(this.title.length>0){this.title.html(title||pageText["boxTitle"])};
	content='<div class="alertContent">'+content+'</div>';
	if(this.content.length>0){
		this.content.html(content||"");
	};
	
	if(this.buttonA.length>0){
		this.buttonA.show();
		this.buttonA[0].onclick=function(){
			if(o.confirmE!=undefined)
			{
				if(o.confirmE.call(xThis)!=false)
				{
					xThis.confirmE.call(xThis);
				}
			}else{
				xThis.confirmE.call(xThis);
			}
		};
		
	};
	if(this.buttonAcontent.length>0){this.buttonAcontent.html(pageText["confirm"])};
	
	if(this.buttonB.length>0){
		this.buttonB.show();
		var xThis=this;
		this.buttonB[0].onclick=function(){xThis.cencelE.call(xThis)};
	};
	if(this.buttonBcontent.length>0){this.buttonBcontent.html(pageText["cencel"])};
	
	this.box.xiaoliCenter();
	if(this.close.length>0)
	{
		var xThis=this;
		this.close[0].onclick=function(){xThis.closeE.call(xThis)};
	}
	escObject=this;//Enter,Esc
}

InuBox.prototype.window=function(content,title,o)
{
	var o=o||{};
	this.box.show();
	this.box.css("width",o.width||this.autoWidth);
	o.base||opacityBase.show();
	if(this.title.length>0){this.title.html(title||pageText["boxTitle"])};
	var xThis=this;
	if(this.content.length>0){
		if(typeof content=="string")
		{
			this.content.html(content||"");
			if(o.contentInitE!=undefined)
			{
				o.contentInitE.call(xThis);
			}
		}
		else if(typeof content=="object")
		{
			if(content["type"]=="jquery")
			{
				this.content.html(content["value"].html()||content["value"].val());
				if(o.contentInitE!=undefined)
				{
					o.contentInitE.call(xThis);
				}
			}else if(content["type"]=="url"){
				var url=content["value"];
				jQuery.get(url, function(data)
				{
					xThis.content.html(data);
					if(o.contentInitE!=undefined)
					{
						o.contentInitE.call(xThis);
					}
					xThis.box.xiaoliCenter();
				});//jQuery.get
			}//if
		}//if
	};//if
	
	if(this.buttonA.length>0){
		if(o.buttonA=="hide")
		{
			this.buttonA.hide()
		}else{
			this.buttonA.show();
		}
		this.buttonA[0].onclick=function(){
			if(o.confirmE!=undefined)
			{
				if(o.confirmE.call(xThis)!=false)
				{
					xThis.confirmE.call(xThis);
				}
			}else{
				xThis.confirmE.call(xThis);
			}
		};
		
	};
	if(this.buttonAcontent.length>0){
		this.buttonAcontent.html(o.confirmText||pageText["confirm"]);
	};
	
	if(this.buttonB.length>0){
		if(o.buttonA=="hide")
		{
			this.buttonB.hide()
		}else{
			this.buttonB.show();
		}
		var xThis=this;
		this.buttonB[0].onclick=function(){
			if(o.cencelE!=undefined)
			{
				if(o.cencelE.call(xThis)!=false)
				{
					xThis.cencelE.call(xThis);
				}
			}else{
				xThis.cencelE.call(xThis);
			}
		};
	};
	if(this.buttonBcontent.length>0){this.buttonBcontent.html(o.cencelText||pageText["cencel"])};
	
	this.box.xiaoliCenter();
	if(this.close.length>0)
	{
		var xThis=this;
		this.close[0].onclick=function(){
			if(o.cencelE!=undefined)
			{
				if(o.cencelE.call(xThis)!=false)
				{
					xThis.cencelE.call(xThis);
				}
			}else{
				xThis.cencelE.call(xThis);
			}
		};
	}
	escObject=this;//Enter,Esc
}

InuBox.prototype.initE=function()
{
}
InuBox.prototype.closeE=function()
{
	this.box.hide();
	opacityBase.hide();
}
InuBox.prototype.confirmE=function()
{
	this.box.hide();
	opacityBase.hide();
}
InuBox.prototype.cencelE=function()
{
	this.box.hide();
	opacityBase.hide();
}
InuBox.prototype.contentInitE=function()
{
}
InuBox.prototype.hideE=function()
{
}