
/*
// ------------------------------------------------------------------------ //
// Project Name       : Contnew.Mall                                          //
// Program Name       : scripting.js.public									//
// Copyright          : COPYRIGHT (C) 2006 BY CONTNEW NETWORK               //
// Version            : 2.0                                                 //
// Author             : webmaster@contnew.com                               //
//                                                                          //
// Date        By            Description                                    //
// ---------   ------------- -----------------------------------------------//
// 2005/05/13  SXG           客户端共用操作类						        //
// ------------------------------------------------------------------------ //
*/

var _private_Login_Status = false;

/*
 * 隐藏窗体加载效果
 */
function hideLayer(_hidden)
{
	this._hidden = _hidden?_hidden:"hidden";

	// IE5+, NN6+
	if (document.getElementById)
	{
		oElement = document.getElementById("ie");
	// IE4
	}else if (document.all){
		oElement = document.all("ie");
	// NN4
	}else if (document.layers){
		oElement = document.layers["ns"];
	}

	if (oElement != null && document.layers)
	{
		oElement.visibility = this._hidden;
	}else if (oElement != null){
		oElement.style.visibility = this._hidden;
	}
}

/*
 * 重设高度
 * @params 控件名称
 * @params 操作工具栏高度
 */
function resizeHeight(oElementByName,oToolHeight)
{
	var clientHeight = document.body.clientHeight;
	this.oElementByName = oElementByName?oElementByName:"eachitem";
	this.oToolHeight = oToolHeight?oToolHeight:30;

	if (document.body.clientHeight > this.oToolHeight)
	{
		try {
			document.getElementById(this.oElementByName).height = parseInt(clientHeight - this.oToolHeight);
		}catch(e){;}
	}
}

/*
 * 该功能类似 ASP 里的 Request,获取并分析URL的附带参数
 * @params 需要获取参数名称
 * @params 需要获取参数的地址
 */
function request(QueryString,strHref)
{
	var strParameter;
	strHref = strHref?strHref:window.location.href;

	if(strHref.search(/\?/)!=-1)
	{
		strHref=strHref.substr(strHref.search(/\?/)+1);
		strHref=strHref.split(/&/);
		for(var i = 0; i<strHref.length; i++)
		{
			if(strHref[i].search("^"+QueryString+"=")!=-1)
			{
				strParameter=strHref[i].substr(QueryString.length+1)
			}
		}
		
		return(strParameter);
	}
}

/*
 * 附选框全选控件(BUG)
 * 函数使用：表单名称，不被选择对象
 */
function checkBoxALL(oForm,object,oSelect,oviewType)
{
	var displayValue;
	var num = 0;
	this.oviewType = oviewType?oviewType:"normal";
	
	if (object.name == oSelect)
	{
		for (var i=0;i<oForm.elements.length;i++)
		{
			var e = oForm.elements[i];
			if (e.type == "checkbox")
			{
				if ((e.name != oSelect) && (e.name != "status"))
				{
					if (object.checked)
					{
						e.checked = true;
						displayValue = "block";
					}else{
						e.checked = false;
						displayValue = "none";
					}

					if (this.oviewType == "view")
					{
						eval(oSelect+"_inner").style.display = "block";
					}else if (this.oviewType == "noview"){
						eval(oSelect+"_inner").style.display = "none";
					}else{
						eval(oSelect+"_inner").style.display = displayValue;
					}
				}
			}
		}
	}else{
		if (object.checked)
		{
			object.checked = true;
			eval(oSelect+"_inner").style.display = "block";
		}else{

			object.checked = false;

			for (var i=0;i<oForm.elements.length;i++)
			{
				var e = oForm.elements[i];
				if (e.type == "checkbox")
				{
					if ((e.name != oSelect) && (e.name != "status") && (e.checked))
					{
						num += 1;
					}
				}
			}
			
			if (num == 0)
			{
				eval(oSelect+"_inner").style.display = "none";
			}
		}
	}
	num = 0;
}

/**
 * Object.HTMLEncode("1 = 1")
 * @Params 输入 字符串
 * @Return 字符串
 */
function HTMLEncode(text)
{
	if ( typeof( text ) != "string" )
		text = text.toString() ;

	text = text.replace(/&/g, "&amp;") ;
	text = text.replace(/"/g, "&quot;") ;
	text = text.replace(/</g, "&lt;") ;
	text = text.replace(/>/g, "&gt;") ;
	text = text.replace(/'/g, "&#39;") ;
	text = text.replace(/\\n/g, "\n") ;
	text = text.replace(/\\r/g, "\r") ;

	return text ;
}

/**
 * Object.IIf("1 = 1","on","off")
 * @Params 必选项。字符串匹配条件 
 * @Params 必选项。条件为真返回
 * @Params 必选项。条件为假返回
 * @Return 字符串
 */
function IIf(strParameter,blTrue,blFalse)
{
	this.blTrue = blTrue?blTrue:true;
	this.blFalse = blFalse?blFalse:false;
	
	if (strParameter)
	{
		return (blTrue);
	}else{
		return (blFalse);
	}
}

/*
 * 格式化货币样式
 * @params 类似VBSCRIPT里的FormatCurrency
 * @params 输入货币值
 */
function formatCurrency(num)
{
	num = num.toString().replace(/\$|\,/g,'');

	if(isNaN(num))

	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();

	if(cents<10)
	{
		cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		{
			num = num.substring(0,num.length-(4*i+3))+','+
			num.substring(num.length-(4*i+3));
		}
	
	}

	return (((sign)?'':'-') + num);
}

function formatUrlForReload(_url,_params)
{
	if (_url.toString().indexOf("?") == -1)
	{
		return (_url + "?" + _params);
	}else{
		return (_url + "&" + _params);
	}
}

/*
 * 通过XMLHTTP判断当前用户是否登录
 * @params 返回为0将自动注销
 * @remark
 * 
 */
function IsLogin()
{
	if (!_private_Login_Status)
	{
		var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")

		xmlhttp.onreadystatechange = getreadystatechange;
		xmlhttp.open("GET","servlet/modules/member/process.asp?action=isign",false)
		xmlhttp.send()

		function getreadystatechange()
		{
			if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
			{
				if (xmlhttp.responseText == 0)
				{
					_private_Login_Status = false;
					top.location = "servlet/modules/member/process.asp?action=signout";
				}
			}else{
				_private_Login_Status = true;
			}
		}

		delete(xmlhttp);
	}

	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
	xmlhttp.onreadystatechange = getreadystatechangebyversion;
	xmlhttp.open("GET","servlet/modules/configuration/version.asp",false)
	xmlhttp.send()

	function getreadystatechangebyversion()
	{
		if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
		{
			var _param = xmlhttp.responseText.toString().split("|");
			top.frames["main"].frames["frmtoolbar"].CurrentVersion.innerHTML = _param[0]?_param[0]:"未知";
			top.frames["main"].frames["frmtoolbar"].CurrentVersionLastRelease.innerHTML = _param[1]?_param[1]:"未知";
		}
	}
}

/*
 * 获取系统所运行的根目录参数类
 * @params 根据系统条件分析: scripting,servlet 三个特殊地址
 * @params 获取系统跟目录地址路径;
 * @remark
 * 
 */
function object_root()
{
	this.parameter;
	this.path;

	// <summary>
	// 获取系统所运行的根目录地址
	// </summary>
	this.InitializeRootVirtualPath = function()
	{
		var thisUrl = window.location.href.toString();
		var arrUrlParams = this.parameter.split(",");

		for (var i = 0;i <= arrUrlParams.length ; i++ )
		{
			if (thisUrl.indexOf(arrUrlParams[i]) > 0)
			{
				thisUrl = thisUrl.substring(0,thisUrl.indexOf(arrUrlParams[i]));
				break;
			}

			if (i == arrUrlParams.length)
			{
				thisUrl = thisUrl.substring(0,thisUrl.lastIndexOf("/")+1);

				if (thisUrl.length = 0)
				{
					thisUrl = thisUrl.substring(0,thisUrl.lastIndexOf("\\")+1);
				}
				break;
			}
		}
		
		this.path = thisUrl;
	}
}

var root = new object_root();
root.parameter = "frame.html,redirect.html,cache,images,scripting,servlet,stylesheet";
root.InitializeRootVirtualPath()