/***************************************
 *@ 功能说明:基础类(中信组件库)
 *@ 作者:组件库小组成员
 *@ 版本:1.0.20030723 
 *@ 版权:中信信息发展有限公司（2003）
***************************************/
// added by jdh at 20040212
//var _client_property_sql={};
//异常处理
function processException(e){
	switch (typeof(e)){
		case "string":{
			if (e!="abort"){
				if (e)
					alert(e);
				else
					alert(constErrUnknown);
			}
			break;
		}

		case "object":{
			alert(e.description+"\n"+constErrType+":"+(e.number & 0xFFFF));
			break;
		}
	}
}

//去掉两端空格

function trimStr(str){
	str=getValidStr(str);
	if (!str) return "";
	for(var i=str.length-1; i>=0; i--){
		if (str.charCodeAt(i, 10)!=32) break;
	}
	// modified by steve_gu at 2004-02-23,修正只去除后面空格的BUG
	for (var j=0; j <= str.length - 1; j++) {
		if (str.charCodeAt(j) != 32) {
			break;
		}
	}
	return str.substr(j, i+1-j);
}

//是否为有效字符""
function getValidStr(str) {
	str+="";
	if (str=="undefined" || str=="null")
		return "";
	else
		return str;
}

//编码
function encode(strIn)
{
	var intLen=strIn.length;
	var strOut="";
	var strTemp;

	for(var i=0; i<intLen; i++)
	{
		strTemp=strIn.charCodeAt(i);
		if (strTemp>255)
		{
			tmp = strTemp.toString(16);
			for(var j=tmp.length; j<4; j++) tmp = "0"+tmp;
			strOut = strOut+"^"+tmp;
		}
		else
		{
			if (strTemp < 48 || (strTemp > 57 && strTemp < 65) || (strTemp > 90 && strTemp < 97) || strTemp > 122)
			{				
				tmp = strTemp.toString(16);
				for(var j=tmp.length; j<2; j++) tmp = "0"+tmp;
				strOut = strOut+"~"+tmp;
			}
			else
			{
				strOut=strOut+strIn.charAt(i);
			}
		}
	}
	return (strOut);
}

//解码
function decode(strIn)
{
	var intLen = strIn.length;
	var strOut = "";
	var strTemp;

	for(var i=0; i<intLen; i++)
	{
		strTemp = strIn.charAt(i);
		switch (strTemp)
		{
			case "~":{
				strTemp = strIn.substring(i+1, i+3);
				strTemp = parseInt(strTemp, 16);
				strTemp = String.fromCharCode(strTemp);
				strOut = strOut+strTemp;
				i += 2;
				break;
			}
			case "^":{
				strTemp = strIn.substring(i+1, i+5);
				strTemp = parseInt(strTemp,16);				
				strTemp = String.fromCharCode(strTemp);
				strOut = strOut+strTemp;
				i += 4;
				break;
			}
			default:{
				strOut = strOut+strTemp;
				break;
			}
		}

	}
	return (strOut);
}

//效验并编码
function getEncodeStr(str) {
	return encode(getValidStr(str));
}

//效验并解码
function getDecodeStr(str) {
	return ((str)?decode(getValidStr(str)):"");
}

//比较两个文本是否相等(不区分大小写)，返回true或false
function compareText(str1, str2){
	str1=getValidStr(str1);
	str2=getValidStr(str2);
	if (str1==str2) return true;
	if (str1=="" || str2=="") return false;
	return (str1.toLowerCase()==str2.toLowerCase());
}

//
function isTrue(value){
	return (value==true || (typeof(value)=="number" && value!=0) ||
		compareText(value, "true") || compareText(value, "T") ||
		compareText(value, "yes") || compareText(value, "on"));
}

function getStringValue(value){
	if (typeof(value)=="string" || typeof(value)=="object")
		return "\""+getValidStr(value)+"\"";
	else if (typeof(value)=="date")
		return "\""+(new Date(value))+"\"";
	else if (getValidStr(value)=="")
		return "\"\"";
	else
		return value;
}

function getInt(value){
	var result=parseInt(value);
	if (isNaN(result)) result=0;
	return result;
}

function getFloat(value){
	var result=parseFloat(value);
	if (isNaN(result)) result=0;
	return result;
}

function formatFloat(value, decimalLength){
	var text=getValidStr(Math.round(getFloat(value)*Math.pow(10, decimalLength)));
	var len=text.length;
	return text.substr(0, len-decimalLength)+"."+text.substr(len-decimalLength, decimalLength);
}

function formatDateTime(date, mode,separator){
	
	function getDateString(date){
		var years=date.getFullYear();
		var months=date.getMonth()+1;
		var days=date.getDate();
		
		if (months<10) months="0"+months;
		if (days<10) days="0"+days;
		if (separator == null) {
			return years+ "-" + months+"-"+days;
		}
		else {
			return years+ separator + months+separator+days;
		}
	}
	
	function getTimeString(date){
		var hours=date.getHours();
		var minutes=date.getMinutes();
		//var seconds=date.getSeconds();
		
		if (hours<10) hours="0"+hours;
		if (minutes<10) minutes="0"+minutes;
		//if (seconds<10) seconds="0"+seconds;
		
		return hours+":"+minutes;
	}
	
	if (typeof(date)=="object" && !isNaN(date)){
		if (!mode) mode="datetime";
		switch (mode){
			case "date":{
				return getDateString(date);
				break;
			}
			case "time":{
				return getTimeString(date);
				break;
			}
			case "datetime":{
				return getDateString(date)+" "+getTimeString(date);
				break;
			}
			default:{
				return getDateString(date)+" "+getTimeString(date);
				break;
			}
		}
	}
	else
		return "";
}

function getTypedValue(value, dataType){
	var result="";
	switch (dataType){
		case "float":{
			result=parseFloat(value);
			break;
		}
		case "int":{
			result=Math.round(parseFloat(value));
			break;
		}
		case "date":;
		case "datetime":;
		case "time":{
			result=new Date(value);
			break;
		}
		case "bool":{
			result=isTrue(value);
			break;
		}
		default:{
			result=getValidStr(value);
			break;
		}
	}
	return result;
}

var _client_property_sql=null;
function setClientProperty(name, value){
//	Response.Write("<INPUT TYPE=hidden id=\"_client_property_"+name+"\" value=\""+getEncodeStr(value)+"\">\n");
	_client_property_sql=document.createElement("<INPUT TYPE=hidden >");
	_client_property_sql.id="_client_property_"+name;
//	_client_property_sql.value=getEncodeStr(value);
	_client_property_sql.value=value;
//id=\"_client_property_"+name+"\" value=\""+getEncodeStr(value)+"\"
	document.body.appendChild(_client_property_sql);
}

function getClientProperty(name){
	var value;
	eval("value=getDecodeStr(_client_property_"+name+".value);");
	return value;
}



/*
 * ===========================WebFXCookie class===============================
 */
function WebFXCookie() {
	if (document.cookie.length) { this.cookies = ' ' + document.cookie; }
}

WebFXCookie.prototype.setCookie = function (key, value) {
	document.cookie = key + "=" + escape(value);
}

WebFXCookie.prototype.getCookie = function (key) {
	if (this.cookies) {
		var start = this.cookies.indexOf(' ' + key + '=');
		if (start == -1) { return null; }
		var end = this.cookies.indexOf(";", start);
		if (end == -1) { end = this.cookies.length; }
		end -= start;
		var cookie = this.cookies.substr(start,end);
		return unescape(cookie.substr(cookie.indexOf('=') + 1, cookie.length - cookie.indexOf('=') + 1));
	}
	else { return null; }
}


// added by steve_gu at 2003-12-30
// Cookie 操作类

// The constructor function: creates a cookie object for the specified
// document, with a specified name and optional attributes.
// Arguments:
//   document: The Document object that the cookie is stored for. Required.
//   name:     A string that specifies a name for the cookie. Required.
//   hours:    An optional number that specifies the number of hours from now
//             that the cookie should expire.
//   path:     An optional string that specifies the cookie path attribute.
//   domain:   An optional string that specifies the cookie domain attribute.
//   secure:   An optional Boolean value that, if true, requests a secure cookie.
//
function Cookie(document, name, hours, path, domain, secure)
{
    // All the predefined properties of this object begin with '$'
    // to distinguish them from other properties which are the values to
    // be stored in the cookie.
    this.$document = document;
    this.$name = name;
    if (hours)
        this.$expiration = new Date((new Date()).getTime() + hours*3600000);
    else this.$expiration = null;
    if (path) this.$path = path; else this.$path = null;
    if (domain) this.$domain = domain; else this.$domain = null;
    if (secure) this.$secure = true; else this.$secure = false;
}

// This function is the store() method of the Cookie object.
Cookie.prototype.store = function () {
    // First, loop through the properties of the Cookie object and
    // put together the value of the cookie. Since cookies use the
    // equals sign and semicolons as separators, we'll use colons
    // and ampersands for the individual state variables we store 
    // within a single cookie value. Note that we escape the value
    // of each state variable, in case it contains punctuation or other
    // illegal characters.
    var cookieval = "";
    for(var prop in this) {
        // Ignore properties with names that begin with '$' and also methods.
        if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function')) 
            continue;
        if (cookieval != "") cookieval += '&';
        cookieval += prop + ':' + escape(this[prop]);
    }

    // Now that we have the value of the cookie, put together the 
    // complete cookie string, which includes the name and the various
    // attributes specified when the Cookie object was created.
    var cookie = this.$name + '=' + cookieval;
    if (this.$expiration)
        cookie += '; expires=' + this.$expiration.toGMTString();
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    if (this.$secure) cookie += '; secure';

    // Now store the cookie by setting the magic Document.cookie property.
    this.$document.cookie = cookie;
}

// This function is the load() method of the Cookie object.
Cookie.prototype.load = function() { 
    // First, get a list of all cookies that pertain to this document.
    // We do this by reading the magic Document.cookie property.
    var allcookies = this.$document.cookie;
    if (allcookies == "") return false;

    // Now extract just the named cookie from that list.
    var start = allcookies.indexOf(this.$name + '=');
    if (start == -1) return false;   // Cookie not defined for this page.
    start += this.$name.length + 1;  // Skip name and equals sign.
    var end = allcookies.indexOf(';', start);
    if (end == -1) end = allcookies.length;
    var cookieval = allcookies.substring(start, end);

    // Now that we've extracted the value of the named cookie, we've
    // got to break that value down into individual state variable 
    // names and values. The name/value pairs are separated from each
    // other by ampersands, and the individual names and values are
    // separated from each other by colons. We use the split method
    // to parse everything.
    var a = cookieval.split('&');    // Break it into array of name/value pairs.
    for(var i=0; i < a.length; i++)  // Break each pair into an array.
        a[i] = a[i].split(':');

    // Now that we've parsed the cookie value, set all the names and values
    // of the state variables in this Cookie object. Note that we unescape()
    // the property value, because we called escape() when we stored it.
    for(var i = 0; i < a.length; i++) {
        this[a[i][0]] = unescape(a[i][1]);
    }

    // We're done, so return the success code.
    return true;
}

// This function is the remove() method of the Cookie object.
Cookie.prototype.remove = function() {
    var cookie;
    cookie = this.$name + '=';
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';

    this.$document.cookie = cookie;
}

/**
 * JavaScript的一些基本工具包
 * 版权：中信信息发展有限公司（2005）
 * @author 孙进，组件库小组成员
 * @version 1.0.20050220
 */

//扩展了Object的一些方法

/****************************************************************************|
*===========================Object class======================================|
*****************************************************************************/ 

/**
 * 返回对象的一个克隆对象
 * @return
 */
Object.prototype.Clone = function() {
	function CloneModel() { }
	CloneModel.prototype = this;
	var objClone = new CloneModel();
	for (v in objClone) { 
		switch (typeof objClone[v]) {
		case "function":
			//如果是方法，不需要进行clone
			break;
		case "object":
		   //如果是对象，采用Clone重新得到，这样做的目的在于能够进行深度Clone
		   //因为JavaScript是一个Object Based的语言，不然内部对象是指向原来的引用
			objClone[v] = objClone[v].Clone();
			break;
		default:
		   //其余数据类型情况下全部重新赋值
		   //这样做的目的就是保证数值在内存中的存放是在新对象的空间中
		   //而不仅仅指向Parent Object的一个refrence
			objClone[v] = objClone[v];
			break;
		}   
	}
	return objClone;
}

//扩展了Array的一些方法

/****************************************************************************|
*===========================Array class======================================|
*****************************************************************************/ 

/**
 * 返回数组中某元素的第一个索引
 * @param o 数组中某元素
 * @return 该元素在数组中的第一个索引或者-1
 */
Array.prototype.indexOf = function(o) {
	for (var i = 0; i < this.length; i++) {
	   if (this[i] == o) { return i; }
	}
    return -1;
};

/**
 * 返回数组中某元素的最后一个索引
 * @param o 数组中某元素
 * @return 该元素在数组中的最后一个索引或者-1
 */
Array.prototype.lastIndexOf = function(o) {
	for (var i = this.length - 1; i >= 0; i--) {
		if (this[i] == o) { return i; }
	}
    return -1;
};

/**
 * 返回数组中是否包含某元素
 * @param o 数组中某元素
 * @return 是否包含 true false
 */
Array.prototype.contains = function(o) {
	return this.indexOf(o) != -1;
};

/**
 * 在数组中某索引或者尾部添加某元素，
 * @param o 某元素
 * @param i 数组中某索引，或者为null
 */
Array.prototype.add = function(o, i) {
	if (i != null && i != -1) { this.splice(i, 0, o); }
	else { this.push(o); }
};

/**
 * 在数组中某索引或者尾部添加某新的数组，
 * @param o 新的数组
 * @param i 数组中某索引，或者为null
 */
Array.prototype.addAll = function(o, i) {
	if (o instanceof Array) {
		for (var j = 0; j < o.length; j++) {
			this.add(o[j], i);
		}
	}
};

/**
 * 在数组中删除某元素，
 * @param o 数组中某元素
 */
Array.prototype.remove = function(o) {
	var i = this.indexOf(o);
	if (i != -1) { this.splice(i, 1); }
};

/**
 * 在数组中删除某数组，
 * @param o 某数组
 */
Array.prototype.removeAll = function(o) {
	if (o instanceof Array) {
		for (var j = 0; j < o.length; j++) {
			this.remove(o[j]);
		}
	}
};

/**
 * 返回数组的副本
 * @return 数组的副本
 */
Array.prototype.copy = function() {
    return this.concat();
};

//扩展了Date的一些方法

/****************************************************************************|
*=============================Date class=====================================|
*****************************************************************************/ 

/**
 * 返回日在年中为第几周
 */

Date.prototype.getWeek = function () {
 var date = new Date(this.getFullYear(), 0, 1);
 var week = date.getDay();
 week = (week == 0 ? 7 : week);
 var days = Math.floor(((this.valueOf()- date.valueOf()) / 86400000)) + 1;
 return ((days + 6 - this.getDay() - 7 + week)/7);
}
//扩展了String的一些方法

/****************************************************************************|
*===========================String class=====================================|
*****************************************************************************/ 

/**
 * 按词典顺序比较两个字符串。比较的基础是字符串中每个字符的 Unicode 值
 * @param another 要比较的 String
 * @return 若参数字符串等于该字符串，则返回 0 ；若该字符串按词典顺序小于参数字符串则返回值小于 0 ；若该字符串按词典顺序大于参数字符串则返回值大于 0
 */
String.prototype.compareTo = function (another) {
	if (another == null) { another = ""; }
	another = String(another);
	var length = Math.max(this.length, another.length);
	for (var i = 0; i < length; i++) {
		if (isNaN(this.charCodeAt(i))) {
			return -1;
		} else if (isNaN(another.charCodeAt(i))) {
			return 1;
		} else {
			var compare = this.charCodeAt(i) - another.charCodeAt(i);
			if (compare != 0) { return compare; }
			continue;
		}
	}
	return 0;
}

/**
 * 测试该字符串是否以指定的字符串作后缀
 * @param suffix 后缀
 * @return 若参数表示的字符序列是该对象字符序列的后缀则返回 true ，否则返回 false
 */
String.prototype.endsWith = function (suffix) {
	if (suffix == null) { suffix = ""; }
	suffix = String(suffix);
	return this.lastIndexOf(suffix) == this.length - suffix.length;
}

/**
 * 测试该字符串是否是以指定的前缀开头
 * @param prefix 前缀
 * @param offset 在字符串中查找的起始点
 * @return 若参数表示的字符序列是该对象开始于索引 offset 处的子字符串前缀则返回 true ，否则返回 false
 */
String.prototype.startsWith = function (prefix, offset) {
	if (prefix == null) { prefix = ""; }
	prefix = String(prefix);
	var index = 0;
	if (offset != null) {
		offset = parseInt(offset);
		index = isNaN(offset) ? 0 : offset;
	}
	return this.indexOf(prefix) == index;
}

/**
 * 删除该字符串两端的空格
 * @return 头尾两端的空格都被删掉的字符串
 */
String.prototype.trim = function() {
    return this.replace(/(^\s+)|\s+$/g, "");
};

/**
 * 字符串是否为合法的Email
 * @return
 */
String.prototype.isEmail = function() {
    return /^[\w-]+@[\w-]+(\.(\w)+)*(\.(\w){2,3})$/i.test(this);
};

/**
 * 字符串是否为合法的Url
 * @return
 */
String.prototype.isUrl = function() {
    return /^(http|https|ftp):\/{2}[^\s:\/]+(:\d{0,5})?(\/[^\s\?]*)?(\?([^\s=&]*=?[^\s=&]*)*(&([^\s=&]*=?[^\s=&]*)*)*)?(#[^\s#]*)?$/i.test(this);
};

/**
 * 字符串是否为合法的颜色值
 * @return
 */
String.prototype.isColor = function() {
	var colors = ["black", "white", "red", "yellow", "lime", "aqua", "blue", "fuchsia", "gray", "silver", "maroon", "olive", "green", "teal", "navy", "purple", "transparent"];
    return (colors.indexOf(this.toLowerCase()) != -1 || /^#[abcdef\d]{6}$/i.test(this));
};

//扩展了Function的一些方法

/****************************************************************************|
*===========================Function class===================================|
*****************************************************************************/ 

Function.READ = "r";
Function.WRITE = "w";
Function.READ_WRITE = "rw";

/**
 * 生成属性的getter或者setter方法
 * @param sName 属性名
 * @param nReadWrite 属性的读写标记 
 */
Function.prototype.addProperty = function(sName, nReadWrite) {
    var nReadWrite = nReadWrite || Function.READ_WRITE;
    var capitalized = sName.charAt(0).toUpperCase() + sName.substr(1);
    if (nReadWrite & Function.READ) { this.prototype["get"+capitalized] = new Function("", "return this._" + sName + ";"); }
    if (nReadWrite & Function.WRITE) { this.prototype["set"+capitalized] = new Function(sName, "this._" + sName + " = " + sName + ";"); }
};

/****************************************************************************|
*===========================CoralObject class===================================|
*****************************************************************************/  
function CoralObject() {
    this._hashCode = CoralObject._hashCodePrefix + Math.round(Math.random() * 1000) + CoralObject._hashCodePrefix + CoralObject._hashCodeCounter++;
}

CoralObject._hashCodeCounter = 1;
CoralObject._hashCodePrefix = "hc";

CoralObject.toHashCode = function(o) {
    if (o._hashCode != null) { return o._hashCode; }
    return o._hashCode = CoralObject._hashCodePrefix + Math.round(Math.random() * 1000) + CoralObject._hashCodePrefix + CoralObject._hashCodeCounter++;
};

var _p = CoralObject.prototype;
_p._className = "CoralObject";
_p._disposed = false;
_p._id = null;

CoralObject.prototype.getDisposed = function() {
    return this._disposed;
};

CoralObject.prototype.getId = function() {
    return this._id;
};

CoralObject.prototype.setId = function(v) {
    this._id = v;
};

CoralObject.prototype.getUserData = function() {
    return this._userData;
};

CoralObject.prototype.setUserData = function(v) {
    this._userData = v;
};

_p.toHashCode = function() {
    return CoralObject.toHashCode(this);
};

_p.dispose = function() {
    this._disposed = true;
    delete this._userData;
};

_p.toString = function() {
    if (this._className) { return "[object " + this._className + "]"; }
    return "[object Object]";
};

_p.getProperty = function(sPropertyName) {
    var getterName = "get" + sPropertyName.charAt(0).toUpperCase() + sPropertyName.substr(1);
    if (typeof this[getterName] == "function") { return this[getterName](); }
    throw new Error("No such property, " + sPropertyName);
};

_p.setProperty = function(sPropertyName, oValue) {
    var setterName = "set" + sPropertyName.charAt(0).toUpperCase() + sPropertyName.substr(1);
    if (typeof this[setterName] == "function") { this[setterName](oValue); }
    throw new Error("No such property, " + sPropertyName);
};

_p.setAttribute = function(sName, sValue, oXmlResourceParser) {
    var v;
    if (sValue == "true") { v = true; }
    else if (sValue == "false"){ v=false; }
    else if (parseFloat(sValue) == sValue) { v=parseFloat(sValue); }
    else { v = sValue; }
    this.setProperty(sName, v);
};

_p.getAttribute = function(sName) {
    return String(this.getProperty(sName));
};

_p.addXmlNode = function(oNode, oXmlResourceParser) {
    if (oNode.nodeType == 1) { oXmlResourceParser.fromNode(oNode); }
};

/****************************************************************************|
*===========================BrowserChecker class==========================|
*****************************************************************************/  

function BrowserChecker() {
    if (BrowserChecker._singleton) { return BrowserChecker._singleton; }
    var ua = navigator.userAgent;
    this._ie = /msie/i.test(ua);
    this._moz = navigator.product == "Gecko";
    if (this._moz) {
        /rv\:([^\);]+)(\)|;)/.test(ua);
        this._version = RegExp.$1;
        this._ie55 = false;
        this._ie6 = false;
    } else {
        /MSIE([^\);]+)(\)|;)/.test(ua);
        this._version = RegExp.$1;
        this._ie55 = /msie 5\.5/i.test(ua);
        this._ie6 = /msie 6/i.test(ua);
    }
    BrowserChecker._singleton = this;
}

BrowserChecker.prototype = new CoralObject;

BrowserChecker.prototype.getIe = function() {
    return this._ie;
};

BrowserChecker.prototype.getIe55 = function() {
    return this._ie55;
};

BrowserChecker.prototype.getIe6 = function() {
    return this._ie6;
};

BrowserChecker.prototype.getMoz = function() {
    return this._moz;
};

BrowserChecker.prototype.getVersion = function() {
    return this._version;
};

var _com_br = new BrowserChecker;
BrowserChecker.ie = _com_br.getIe();
BrowserChecker.ie55 = _com_br.getIe55();
BrowserChecker.ie6 = _com_br.getIe6();
BrowserChecker.moz = _com_br.getMoz();
BrowserChecker.version = _com_br.getVersion();
_com_br = null;

/****************************************************************************|
*===========================XmlHttp class=================================|
*****************************************************************************/  
function XmlHttp() {
	if (window.XMLHttpRequest) { return new XMLHttpRequest(); }
	else if (window.ActiveXObject) { return new ActiveXObject(XmlHttp._activeXName); }
}

XmlHttp.create = function() {
	return new XmlHttp();
};

/****************************************************************************|
*===========================XmlDocument class=============================|
*****************************************************************************/  
function XmlDocument() {
	if (document.implementation && document.implementation.createDocument) {
        var doc = document.implementation.createDocument("", "", null);
        doc.addEventListener("load", function(e) { this.readyState = 4; }, false);
        doc.readyState = 4;
        return doc;
	}
	else if (window.ActiveXObject) {
        return new ActiveXObject(XmlDocument._activeXName);
    }
}

XmlDocument.create = function() {
	return new XmlDocument();
};

XmlDocument._getActiveXName = XmlHttp._getActiveXName = function(sType) {
	var servers = ["Microsoft", "MSXML2", "MSXML", "MSXML3"];
	var o;
	for (var i = 0; i < servers.length; i++) {
		try {
            o = new ActiveXObject(servers[i] + "." + sType);
            return servers[i] + "." + sType;
		}
		catch(ex) {
		};
	}
	throw new Error("Could not find an installed XML parser");
};

if (window.ActiveXObject) {
	XmlHttp._activeXName = XmlHttp._getActiveXName("XmlHttp");
	XmlDocument._activeXName = XmlDocument._getActiveXName("DomDocument");
}

/**************************************以下方法下拉框中使用*********************************/
function calendar(){
	var today=new Date()
	this.todayDay=today.getDate();
	this.todayMonth=today.getMonth();
	this.todayYear=today.getFullYear();
	this.thisHour = today.getHours();
	this.thisMinute = today.getMinutes();
	this.thisSecond = today.getSeconds();
	this.activeCellIndex=0;
}
var _dropdownFrame = null;
var constDownLoadingData = "正在加载数据,请稍候";
function getElementEventName(element, eventName){
	var result="";
	result=element.id+"_"+eventName;
	return result;
}

function isUserEventDefined(function_name){
	if (function_name=="") return false;
	var result;
	eval("result=(typeof("+function_name+")!=\"undefined\");");
	return result;
}

function fireUserEvent(function_name, param){
	var result;
	var paramstr="";
	for(i=0; i<param.length; i++) {
		if (i==0) paramstr="param["+i+"]";
		else paramstr=paramstr+",param["+i+"]";
	}
	if (isUserEventDefined(function_name)) eval("result="+function_name+"("+paramstr+");");
	return result;
}

function getStatusLabel(text) {
	if (typeof(_status_label)=="undefined"){
		window.document.body.insertAdjacentHTML("beforeEnd", "<DIV id=_status_label name= nowrap style=\"position: absolute; visibility: hidden;"+
			" padding-left: 12px; padding-right: 12px; height: 22px; font-size: 9pt; background-color: #ffffcc; border: 1 solid silver; padding-top:3; z-index: 10000;  filter:alpha(opacity=80)\"></DIV>");
	}
	_status_label.innerHTML=text;
}

function showStatusLabel(parent_window, text, control){
	getStatusLabel(text);
	if (control){
		var pos=getAbsPosition(control);
		locateStatusLabel(pos[0]+(control.offsetWidth-_status_label.offsetWidth)/2+1, pos[1]+control.offsetHeight+1);
	}
	else{
		parent_window._status_label.style.posLeft=(document.body.clientWidth - _status_label.offsetWidth) / 2;
		parent_window._status_label.style.posTop=(document.body.clientHeight - _status_label.offsetHeight) / 2;
		parent_window.document.onmousemove=null;
	}
	parent_window._status_label.style.visibility="visible";
}

function hideStatusLabel(parent_window){
	if (!parent_window.closed && parent_window._status_label){
		parent_window.document.onmousemove=null;
		parent_window._status_label.style.visibility="hidden";
	}
}

function getAbsPosition(obj, offsetObj){
	var _offsetObj=(offsetObj)?offsetObj:window.document.body;
	var x=obj.offsetLeft;
	var y=obj.offsetTop;
	var tmpObj=obj.offsetParent;
	while ((tmpObj!=_offsetObj) && tmpObj){
		x+=tmpObj.offsetLeft+tmpObj.clientLeft-tmpObj.scrollLeft;
		y+=tmpObj.offsetTop+tmpObj.clientTop-tmpObj.scrollTop;
		tmpObj=tmpObj.offsetParent;
	}
	return ([x, y]);
}

function locateStatusLabel(x, y){
	if (x==0 && y==0) return;

	var posX=window.document.body.clientWidth + window.document.body.scrollLeft - _status_label.offsetWidth;
	var posY=window.document.body.clientHeight + window.document.body.scrollTop - _status_label.offsetHeight;
	posX=(x<posX)?x:posX;
	posY=(y<posY)?y:posY;

	_status_label.style.posLeft=posX -1;
	_status_label.style.posTop=posY -1;
}



/****************************************************************************|
*=============================Calendar class=================================|
*****************************************************************************/ 
//实现简单功能，待补充

function Calendar() {
	this.date = new Date();
}

Calendar.YEAR = 1;
Calendar.MONTH = 2;
Calendar.DATE = 3;
Calendar.HOUR = 4;
Calendar.MINUTE = 5;
Calendar.SECOND = 6;

Calendar.prototype.setDate = function (newDate) {
	if(newDate instanceof Date) {
		this.date = newDate;
	} 
	return this;
}

Calendar.prototype.getDate = function () {
	return this.date;
}

Calendar.prototype.set = function(type,value) {
	switch (type){
		case Calendar.YEAR:
			this.date.setYear(value);
		break;
		case Calendar.MONTH:
			this.date.setMonth(value-1);
		break;
		case Calendar.DATE:
			this.date.setDate(value);
		break;
		case Calendar.HOUR:
			this.date.setHours(value);
		break;
		case Calendar.MINUTE:
			this.date.setMinutes(value);
		break;
		case Calendar.SECOND:
			this.date.setSeconds(value);
		break;
	}
	return this;
}

Calendar.prototype.get = function(type) {
	var tmpValue;
	switch (type){
		case Calendar.YEAR:
			tmpValue = this.date.getFullYear();
		break;
		case Calendar.MONTH:
			tmpValue = this.date.getMonth()+1;
		break;
		case Calendar.DATE:
			tmpValue = this.date.getDate();
		break;
		case Calendar.HOUR:
			tmpValue = this.date.getHours();
		break;
		case Calendar.MINUTE:
			tmpValue = this.date.getMinutes();
		break;
		case Calendar.SECOND:
			tmpValue = this.date.getSeconds();
		break;
	}
	return tmpValue;
}

Calendar.prototype.parse = function (newDate) {
	var tmpDate = newDate.replace(/-/g,"/");
	this.date = new Date(tmpDate);
	return this;
}

Calendar.prototype.add = function (type,value){
	var newDate;
	switch (type){
		case Calendar.DATE:
			newDate = new Date(this.date.getFullYear(),this.date.getMonth(),this.date.getDate()+value,this.date.getHours(),this.date.getMinutes(),this.date.getSeconds());
		break;
		case Calendar.MONTH:
			newDate = new Date(this.date.getFullYear(),this.date.getMonth()+value,this.date.getDate(),this.date.getHours(),this.date.getMinutes(),this.date.getSeconds());
		break;
		case Calendar.Year:
			newDate = new Date(this.date.getFullYear()+value,this.date.getMonth(),this.date.getDate(),this.date.getHours(),this.date.getMinutes(),this.date.getSeconds());
		break;
		case Calendar.HOUR:
			newDate = new Date(this.date.getFullYear(),this.date.getMonth(),this.date.getDate(),this.date.getHours()+value,this.date.getMinutes(),this.date.getSeconds());
		break;
		case Calendar.MINUTE:
			newDate = new Date(this.date.getFullYear(),this.date.getMonth(),this.date.getDate(),this.date.getHours(),this.date.getMinutes()+value,this.date.getSeconds());
		break;
		case Calendar.SECOND:
			newDate = new Date(this.date.getFullYear(),this.date.getMonth(),this.date.getDate(),this.date.getHours(),this.date.getMinutes(),this.date.getSeconds()+value);
		break;
	}
	this.setDate(newDate);
	return this;
}

Calendar.prototype.toLocalString = function (){
	var tmpMonth = this.date.getMonth()+1;
	var tmpDate = this.date.getDate();
	var tmpHour = this.date.getHours();
	var tmpMinute = this.date.getMinutes();
	return this.date.getFullYear()+"-"+(tmpMonth<10?"0"+tmpMonth:tmpMonth)+"-"+(tmpDate<10?"0"+tmpDate:tmpDate)+" "+(tmpHour<10?"0"+tmpHour:tmpHour)+":"+(tmpMinute<10?"0"+tmpMinute:tmpMinute);
}

Calendar.prototype.getTime = function() {
	return this.date.getTime();
}

