/***************************************
// Project : Showwin
// Function : 自定义窗口
// CreateDate:2007.05.31
// Need Library: drag.js
// Version: 0.1 beta
// Powered by Showwin All Right
		(c) 2007 http://blog.csdn.net/showwin
***************************************/
DiyWindow = function()
{
	this._DEFAULT_ID = "Showwin:Window";	//默认窗口ID
	this.isDrag = true;						//是否可以拖动
	this.isIE = 200;							
	this.id = this._DEFAULT_ID;
	this.identity = 0;						//自动增加标识
	this.create = createWindow;				
	this.size = {width:200,height:150}		//宽度,高度
	this.pos = {left:0,top:0};				//位置
	this.style = "";						//样式字符串
	this.isTitle = true;					//是否有标题栏
	this.zindex = 1;
	this.css = "";							//关联css样式
	this.winObj;							//生成窗口的对象引用
	this.title = "标题";					//标题
	this.titleColor = "#FF9933";			//标题背景颜色
	this.backgroundColor = "#6699cc";		//背景色
	this.del = deleteWindow;				//删除窗口
	this.closeEvent = null;	//关闭事件关联
}
function isNull(v)
{
	if(v != "" && typeof(v) != "undefined" && typeof(v) != "null" && v != null)
	{
		return false;
	}
	else
	{
		return true;
	}
}
function createWindow(_id,_width,_height,_posX,_posY,_backColor,_isTitle,_titleName,_titleColor,_closeEvent)
{

	if(_id == "" || _id == null)
	{
		this.id = this._DEFAULT_ID + "_" + this.identity;
		this.identity++;
	}
	else
	{
		if(document.all(_id) != null)
		{
			this.id = this._DEFAULT_ID + "_" + this.identity;
			this.identity++;
		}
		else
		{
			this.id = _id;
		}
	}
	
	if(!isNull(_width))
	{
		this.size.width = _width;
	}

	if(!isNull(_height))
	{
		this.size.height = _height;
	}
	
	if(!isNull(_posX))
	{
		this.pos.x = _posX;
	}

	if(!isNull(_posY))
	{
		this.pos.y = _posY;
	}
	
	if(!isNull(_backColor))
	{
		this.backgroundColor = _backColor;
	}
	
	var WinElement = document.createElement("div");
	if(_isTitle)
	{
		if(!isNull(_titleName))
		{
			this.title = _titleName;
		}
		if(!isNull(_titleColor))
		{
			this.titleColor = _titleColor;
		}
		if(!isNull(_closeEvent))
		{
			//	关联窗口关闭过程
			this.closeEvent = _closeEvent;
		}
		else
		{
			//	默认窗口关闭过程
			this.closeEvent = "javascript:MyWin.del(&quot;"+this.id+"&quot;)";
		}
		WinElement.innerHTML = '<div style="line-height:20px;vertical-align:middle;font-size:12px;cursor:move;border-bottom:1px solid #000;background-color:'+this.titleColor+';width:100%;" onmousedown="MoveWin(&quot;'+this.id+'&quot;)"><span style="float:left">'+this.title+'</span><img onclick="'+this.closeEvent+'" style="float:right;cursor:hand;margin-right:2px;margin-top:3px;width:11px;height:11px;" src="img/close.gif"></div><div id="Showwin:Context" style="padding-left:4px;height:0px;line-height:20px;overflow:hidden;background-color:'+this.backgroundColor+';font-size:0px"></div>';
	}
	WinElement.id = this.id;
	this.style = "color:#fff;position:absolute;width:" + this.size.width + "px; height:" + this.size.height + "px;z-index:" +this.zindex + ";border:1px solid #000; background-color:"+this.backgroundColor+";left:"+this.pos.x+"px;top:"+this.pos.y+"px";
	WinElement.style.cssText = this.style;
	WinElement.css = this.css;
	document.body.appendChild(WinElement);
	this.winObj = WinElement;
	return this.id;
}
function deleteWindow(id)
{
	document.all(id).removeNode(true);
}
function setStyle(_styleString)
{
	this.style = _styleString;
}
var MyWin = new DiyWindow();
