
/*
// ------------------------------------------------------------------------ //
// Project Name       : Contnew.Mall                                          //
// Program Name       : scripting.windows                                   //
// Copyright          : COPYRIGHT (C) 2006 BY CONTNEW NETWORK               //
// Version            : 2.0                                                 //
// Author             : webmaster@contnew.com                               //
//                                                                          //
// Date        By            Description                                    //
// ---------   ------------- -----------------------------------------------//
// 2005/05/13  SXG           客户端窗口事件								    //
// ------------------------------------------------------------------------ //
*/


function Dialog()
{
	var Method;
	var Params;
	var Splits;
	var Href;
	var Name;
	var ToolBar;
	var MenuBar;
	var ScrollBar;
	var UrlBar;
	var Status;
	var FullScreen;
	var Resize;
	var Width;
	var Height;
	var Place;
	var Top;
	var Left;
	var ReturnValue;
	var TextValue;
	var ConfirmTrue;
	var ConfirmFalse;

	var ua;
	var ie;
	var MinorVer;
	var IEVer;
	var PopTop;
	var oPopup;
	var timer;
	var TimeOut;
}

Dialog.prototype.Init = function()
{
	this.Method = this.Method?this.Method:"open";
	this.Params = this.Params?this.Params:"";
	this.Splits = this.Splits?this.Splits:"|";
	this.Href = this.Href?this.Href:"about:blank";
	this.Name = this.Name?this.Name:Math.round(Math.random() * 100000);
	this.ToolBar = this.ToolBar?this.ToolBar:"no";
	this.MenuBar = this.MenuBar?this.MenuBar:"no";
	this.ScrollBar = this.ScrollBar?this.ScrollBar:"no";
	this.UrlBar = this.UrlBar?this.UrlBar:"no";
	this.Status = this.Status?this.Status:"no";
	this.FullScreen = this.FullScreen?this.FullScreen:"no";
	this.Resize = this.Resize?this.Resize:"no";
	this.Width = this.Width?this.Width:parseInt(screen.width/2);
	this.Height = this.Height?this.Height:parseInt(screen.height/2);
	this.Place = this.Place?this.Place:"center";
	this.Top = this.Top?this.Top:"30";
	this.Left = this.Left?this.Left:"30";
	this.ReturnValue = this.ReturnValue?this.ReturnValue:"";
	this.TextValue = this.TextValue?this.TextValue:"";
	this.ConfirmTrue = this.ConfirmTrue?this.ConfirmTrue:true;
	this.ConfirmFalse = this.ConfirmFalse?this.ConfirmFalse:false;
	this.ua = navigator.userAgent;
	this.ie = navigator.appName=="Microsoft Internet Explorer"?true:false;
	this.MinorVer = navigator.appMinorVersion.split(";");
	this.IEVer = parseFloat(this.ua.substring(this.ua.indexOf("MSIE ")+5,this.ua.indexOf(";",this.ua.indexOf("MSIE "))));
}

Dialog.prototype.Exit = function() {
	if (this.ie)
	{
		if (this.IEVer < 5.5)
		{
			var str = "<object id=\"noTipClose\" classid=\"clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11\">";
			str += "<param name=\"Command\" value=\"Close\"></object>";
			document.body.insertAdjacentHTML("beforeEnd", str);
			document.all.noTipClose.Click();
		}else{
			window.opener = null;
			window.close();
		}
	}else{
		window.close();
	}
};

Dialog.prototype.Open = function()
{
	Dialog.prototype.Init();
	// .toLowerCase()
	switch (this.Method)
	{
		/*
		* 类别:Open
		* 功能:Window.Open 弹出窗口 中所有功能;
		*/
		case "open":
		switch (this.Place)
		{
			case "center":
			OpenWinTopXY = "top="+((screen.availHeight-parseInt(this.Height.replace("px","")))/2)+",left="+((screen.availWidth-parseInt(this.Width.replace("px","")))/2);
			break;
			
			case "top":
			OpenWinTopXY = "top=0,left=0";
			break;
			
			default:
			OpenWinTopXY = "top="+this.Top+",left="+this.Left+"";
		}

		var obj = window.open (this.Href,this.Name,"location=no;toolbar="+this.ToolBar+",menubar="+this.MenuBar+",scrollbars="+this.ScrollBar+",resizable="+this.Resize+",directories="+this.UrlBar+",fullscreen="+this.FullScreen+",status="+this.Status+",titlebar=no,width="+this.Width+",height="+this.Height+","+OpenWinTopXY+"");

		// <summary>
		// 广告拦截错误的容错提示
		// </summary>
		if (obj == null)
		{
			alert ("本功能需要您的浏览器启用弹出窗口功能，如果您的系统已经启用窗口拦截请先关闭或按住CTRL+当前按钮。");
		}

		return (obj);
		break;

		/*
		* 类别:showModlDialog
		* 功能:对话窗口
		*/
		case "showModalDialog":
		var oDialog;
		oDialog = window.showModalDialog (this.Href,""+this.TextValue+"","dialogWidth:'"+this.Width+"';dialogHeight:'"+this.Height+"';status:'"+this.Status+"';scroll='"+this.ScrollBar+"';help:no;edge: Raised");
		return (oDialog);
		break;

		/*
		* 类别:showModelessDialog
		* 功能:对话窗口
		*/
		case "showModelessDialog":
		var oDialog;
		oDialog = window.showModelessDialog (this.Href,""+this.TextValue+"","dialogWidth:'"+this.Width+"';dialogHeight:'"+this.Height+"';status:'"+this.Status+"';scroll='"+this.ScrollBar+"';help:no;edge: Raised");
		return (oDialog);
		break;

		/*
		* 类别:showHelp
		* 功能:HELP帮助
		*/
		case "showHelp":
		window.showHelp(this.Href);
		break;

		/*
		* 类别:Confirm
		* 功能:确认对话框
		*/
		case "confirm":
		var msgbox = window.confirm(this.TextValue);
		if (msgbox)
		{
			eval(this.ConfirmTrue);
		}else{
			eval(this.ConfirmFalse);
		}
		break;

		case "popup":
		if (this.ie)
		{
			this.PopTop=50;
			this.oPopup = window.createPopup();
			var html=this.TextValue;
			this.oPopup.document.body.innerHTML = html;
			popshow();
		}
		break;

		/*
		* 类别:缺省状态
		* 功能:当前页面转发
		*/
		default:
		top.location=this.Href;
		break;
	}
}

Dialog.prototype.Reload = function(frms,url)
{
	// http://tech.httpcn.com/show.asp?id=1802
	// 此处为该页面的名称，别忘了外面应该有一个Form，用hidden空间保留此页面所需的Request.Form的数据！
	// alert (document.forms.length);
	document.forms[frms].action = url;
	document.forms[frms].submit();
}

Dialog.prototype.ie = function()
{
	return (this.ie);
};

Dialog.prototype.getIEVersion = function()
{
	return (this.IEVer);
};

Dialog.prototype.getScriptEngineVersion = function() {
	return ScriptEngine()
		+ " " + ScriptEngineMajorVersion()
		+ "." + ScriptEngineMinorVersion()
		+ "." + ScriptEngineBuildVersion();
};

/**
 * 打开系统对话框
 * @params 标题
 * @params 备注说明
 * @params 事件响应(True,False)
 * @params 窗口宽度
 * @params 窗口高度
 */
function sAlert(title,description,isConfirm,width,height)
{
	var odialog;
	odialog = getDialog(title,description,width,height);

	if (isConfirm)
	{
		if (odialog == 1)
		{
			return true;
		}else{
			return false;
		}
	}else{
		if (odialog == 1)
		{
			return false;
		}else{
			return true;
		}
	}

	/**
	 * 打开系统对话框
	 * @params 标题
	 * @params 备注说明
	 * @params 事件响应(True,False)
	 * @params 窗口宽度
	 * @params 窗口高度
	 */
	function getDialog(title,description,width,height)
	{
		this.url = root.path + "scripting/dialog/confirm.html?title="+title+"&description="+description;
		this.width = width?width:"350px";
		this.height = height?height:"200px";

		dialog.Method = "showModalDialog";
		dialog.Href = this.url;
		dialog.Width = this.width;
		dialog.Height = this.height;
		dialog.Status = "no";
		return (dialog.Open());
	}
}

var dialog = new Dialog();