/*
Version:	VDCS Common & Instantiation Library 1.0.0416
*/

var VDCS=new Object();
var dcs=new Object();


function put(strer) { document.write(strer); }
function isNull(strer) { return (strer==null) ? true : false; }
function isEmpty(strer) { return (strer==null || strer=="") ? true : false; }
function isArray(o) { var re=false; if (isObject(o)) { try { if (o.length>-1) re=true; } catch(e) { }; }; return re; }
function isObject(strer) { return (typeof(strer)=="object" && strer) ? true : false; }
function getType(strer) { return typeof(strer).toString; }

function toTrim(strer) { return strer.replace(/(^\s*)|(\s*$)/g,""); }
String.prototype.toTrim=function() { return this.replace(/(^\s*)|(\s*$)/g,""); }
function toLength(strer) { return strer.replace(/[^\x00-\xff]/g,"aa").length; }
function toReplace(str1,str2,str3) { return str1.replace(str2,str3); }
function toDisp(str1,str2,str3) { return str1.replace("{$"+str2+"}",str3); }

function isInte(strer) { return /^[0-9]*[1-9][0-9]*$/.exec(strer) ? true : false; }	//判断是否是正整数
function isInt(strer) { return dcs.common.isNumber(strer); }
function isNum(strer) { return dcs.common.isNumber(strer,1); }

function toInt(strer) { return dcs.common.isNumber(strer) ? strer : 0; }
function toNum(strer) { return dcs.common.isNumber(strer,1) ? strer : 0; }

function inStr(strer) { return strer.indexOf(strer); }
function inPart(strer,strVar,strSymbol) { if (isEmpty(strSymbol)) strSymbol=","; return (strSymbol+strer.toString()+strSymbol).indexOf(strSymbol+strVar.toString()+strSymbol)+1; }

function $(strer) { return dcs.browser.getElementById(strer); }
function doLayerShow(strer) { var o=isObject(strer) ? strer : $(strer); if (o) o.style.display=""; }
function doLayerHide(strer) { var o=isObject(strer) ? strer : $(strer); if (o) o.style.display="none"; }



dcs.config=new Object();
dcs.config._data=new Array();
dcs.config._data=new Array();
dcs.config._data["dir"]				= "/";
dcs.config._data["url"]				= "/";
dcs.config._data["dir.common"]			= "common/";
dcs.config._data["dir.common.smiley"]		= "images/smiley/";
dcs.config._data["dir.common.script"]		= "common/script/";
dcs.config._data["dir.common.editor"]		= "common/script/editor/";
dcs.config._data["dir.account"]			= "account/";
dcs.config._data["dir.passport"]		= "passport/";
dcs.config._data["dir.images"]			= "images/";
dcs.config._data["dir.upload"]			= "upload/";
dcs.config._data["dir.xml"]			= "xml/";
dcs.config._data["dir.skin.base"]		= "skin/";
dcs.config._data["dir.skin"]			= "skin/default/";

dcs.config.getValue=function(strKey) { return this._data[strKey]; }
dcs.config.setValue=function(strKey,strValue) { this._data[strKey]=strValue; }

dcs.config.setPath=function(strDir,strURL,strSKIN)
{
	if (!isEmpty(strDir)) this._data["dir"]=strDir;
	if (!isEmpty(strURL)) this._data["url"]=strURL;
	if (!isEmpty(strSKIN)) this._data["dir.skin"]=(strSKIN=="_base") ? this._data["dir.skin.base"] : strSKIN;
}
dcs.config.setDir=function(strKey,strValue) { this._data["dir."+strKey]=strValue; }
dcs.config.getDir=function(strKey) { return this._data["dir."+strKey]; }
dcs.config.setFile=function(strKey,strValue) { this._data["url.file."+strKey]=strValue; }
dcs.config.getURL=function(strKey,strFile)
{
	var re="";
	var tmpBase=this._data["url"];
	if (isEmpty(strKey)) re=tmpBase;
	else
	{
		re=this._data["dir."+strKey];
		if (re.substring(0,1)!="/" && re.indexOf("://")==-1) re=tmpBase+re;
	}
	if (!isEmpty(strFile)) re+=this._data["url.file."+strFile];
	return re;
}



//########################################
//########################################
dcs.init=new Object();
dcs.init._Queues=new Array();

dcs.init.isRes=function(strer) { return isEmpty(this._Queues[strer]); }

dcs.init.loadResource=function(strType,strer)
{
	if (!isEmpty(this._Queues[strType+":"+strer])) return true;
	this._Queues[strType+":"+strer]=new Date().getTime();
	var _xmlHttp=dcs.browser.getXMLHttpObject();
	var tmpContent,tmpStatus=-1;
	try { _xmlHttp.open("GET",dcs.config.getURL("common.script")+strer,false); _xmlHttp.send(""); tmpStatus=_xmlHttp.status; if(_xmlHttp.readyState==4 && (tmpStatus==200 || tmpStatus==0)) tmpContent=_xmlHttp.responseText; } catch(e) {  }
	if (!isEmpty(tmpContent)) { eval(tmpContent); return true; }// else { var tmpMessage="VDCS Error: dcs.init."+strType+"\ncouldn't load resource ["+strer+"]."; if (_xmlHttp) tmpMessage+="\n\nHTTP-STATUS: "+tmpStatus+""; alert(tmpMessage); return false; }	//eval("(function(){"+tmpContent+"})();");
}

dcs.init.loadRes=function(strer) { this.loadResource("loadRes","resource/VDCS.res."+strer+".js"); }
dcs.init.loadUtil=function(strer) { this.loadResource("loadUtil","resource/VDCS.util."+strer+".js"); }
dcs.init.loadLib=function(strer) { this.loadResource("loadLib","resource/VDCS.lib."+strer+".js"); }

dcs.init.loadURL=function(strer)
{
	var _xmlHttp=dcs.browser.getXMLHttpObject();
	var tmpContent,tmpStatus=-1;
	if (strer.indexOf("://")>0) strer=dcs.config.getURL("common","url.proxy")+"?url="+strer+"&contenttype=js";
	try { _xmlHttp.open("GET",strer,false); _xmlHttp.send(""); if(_xmlHttp.readyState==4) { tmpStatus=_xmlHttp.status; if (tmpStatus==200 || tmpStatus==0) tmpContent=_xmlHttp.responseText; } } catch(e) {  }
	if (!isEmpty(tmpContent)) { eval(tmpContent); return true; }// else { var tmpMessage="VDCS Error: dcs.init.loadURL\ncouldn't load URL ["+strer+"]."; if (_xmlHttp) tmpMessage+="\n\nHTTP-STATUS: "+tmpStatus+""; alert(tmpMessage); return false; }
}

dcs.init.loadStyle=function() { if (dcs.browser.isIE) put("<link rel=\"stylesheet\" rev=\"stylesheet\" type=\"text/css\" href=\""+dcs.config.getURL("common.script")+"resource/browse.ie.css"+"\" charset=\"utf-8\" />"); }




//########################################
//########################################
dcs.browser=new Object();
dcs.browser.userAgent		= navigator.userAgent.toLowerCase();
dcs.browser.appVersion		= navigator.appVersion;

dcs.browser.doInit=function()
{
	this.isIE=(this.userAgent.indexOf("msie")!=-1);
	this.isIE5=false; this.isGecko=false; this.isNS=false; this.isMozilla=false; this.isFirefox=false; this.isOpera=false;
	if (this.isIE)
	{
		this.MajorVer=this.appVersion.match(/MSIE (.)/)[1];
		this.MinorVer=this.appVersion.match(/MSIE .\.(.)/)[1];
		this.isIE5=(this.MajorVer>5 || this.MinorVer>=5);
		this.type=(this.isIE5) ? "ie5" : "ie"; this.typeName="ie";
		//this.typeName=/msie/.test(navigator.userAgent.toLowerCase()) ? 'ie' : 'gecko';
	}
	else
	{
		this.isGecko=true;	
		this.type="gecko"; this.typeName="gecko";
		this.MajorVer=0; this.MinorVer=0;
		this.isNS=this.userAgent.indexOf("netscape")!=-1;
		if(this.isNS) this.type="ns";
		this.isMozilla=(typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument!='undefined');
		this.isFirefox=(navigator.userAgent.toLowerCase().indexOf("firefox")!=-1);
		this.isOpera=(navigator.userAgent.toLowerCase().indexOf("opera")!=-1);
	}
}
dcs.browser.doInit();

dcs.browser.getTypeName=function() { return this.typeName; }

dcs.browser.getObject=function(strname) { return this.getElementById(strname); }
dcs.browser.getElementById=function(strname)
{
	if (this.isIE5 || this.isMozilla || this.isFirefox) return document.getElementById(strname);
	if (this.isIE) return document.all(strname);
	if (this.isNS) return document.layers[strname];
}
dcs.browser.getElementsByName=function(strname)
{
	if (this.isIE5 || this.isMozilla || this.isFirefox) return document.getElementsByName(strname);
	if (this.isIE) return document.all(strname);
	if (this.isNS) return document.layers[strname];
}

dcs.browser.doRefresh=function() { return window.document.location.reload(); }
dcs.browser.goBack=function() { return history.back(); }

dcs.browser.getDomain=function() { return window.document.domain; }
dcs.browser.getURLs=function() { return window.document.URL; }
dcs.browser.getTitle=function() { return window.document.title; }
dcs.browser.getReferer=function() { return window.document.referrer; }

dcs.browser.getXMLHttpObject=function()
{
	var reObject=null;
	if (window.ActiveXObject)						// IE
	{
		var tmpObjectAry=new Array("Msxml2.XMLHTTP","Msxml.XMLHTTP","Microsoft.XMLHTTP");
		for (var i=0;i<tmpObjectAry.length;i++)
		{
			try  { reObject=new ActiveXObject(tmpObjectAry[i]); } catch(e) { reObject=null; }
			if (reObject!=null) break;
		}
	}
	else if(window.XMLHttpRequest) { reObject=new XMLHttpRequest(); }	// Mozilla, Safari,... (navigator.appName == "opear")
	return reObject;
}





//########################################
//########################################
dcs.common=new Object();
dcs.common.NEWLINE			= "";
dcs.common.VALUE_UNKNOWN		= "[unknown]";
dcs.common.VALUE_EMPTY_REPLACER		= "NaN";
dcs.common.VALUE_EMPTY_REPLACERS	= "<font class=\"gray\">NaN</font>";

dcs.common.toReplace=function(str1,str2,str3) { return str1.replace(str2,str3); }
dcs.common.toDisp=function(str1,str2,str3) { return str1.replace("{$"+str2+"}",str3); }

dcs.common.isNumber=function(strer,strt,strv)
{
	var tmpVar="0123456789";
	if (strt==1) tmpVar="0123456789.";
	var tmpAry=new Array(1);
	if (strv==null || strv=="") { tmpAry[0]=false; tmpAry[1]=true; } else { tmpAry[0]=0; tmpAry[1]=strer; }
	if (strer==null || strer=="") return tmpAry[0];
	for (var i=0;i<strer.length;i++) { if (tmpVar.indexOf(strer.charAt(i))==-1) return tmpAry[0]; }
	return tmpAry[1];
}





//########################################
//########################################
dcs.queues=new Object();
dcs.queues._Queues=new Array();

dcs.queues.addItem=function(strer) { this._Queues[this._Queues.length]=strer; }

dcs.queues.isItem=function(strer)
{
	var re=false;
	for (var i=0;i<this._Queues.length;i++) { if (this._Queues[i]==strer) { re=true; break; } }
	return re;
}





//########################################
//########################################
dcs.form=new Object();

dcs.form.getObject=function(strName,strType)
{
	var reObject=null;
	switch (strType)
	{
		case "parent":
			var tmpObject=this.getElement(strName);
			if (isObject(tmpObject)) reObject=dcs.browser.isIE ? tmpObject.parentElement : tmpObject.parentNode;
			break;
	}
	return reObject;
}

dcs.form.getElement=function(strName,strType)
{
	if (strType==1) { dcs.init.loadLib("form"); return dcs.form.getElements(strName); }
	var reElement=null;
	try
	{
		if (!isEmpty(strName))
		{
			var tmpTarget="";
			if (strName.indexOf(":")!=-1) { tmpTarget=strName.substring(0,strName.indexOf(":")); strName=strName.substring(strName.indexOf(":")+1); }
			var tmpForm;
			if (tmpTarget=="parent")
			{
				if (strName.indexOf(".")==-1) { reElement=window.parent.document.getElementById(strName); }
				else { if (isObject(tmpForm=window.parent.document.forms[strName.substring(0,strName.indexOf("."))])) reElement=tmpForm.elements[strName.substring(strName.indexOf(".")+1)]; }
			}
			else if (tmpTarget!="") { }
			else
			{
				if (strName.indexOf(".")==-1) { reElement=document.getElementById(strName); }
				else { if (isObject(tmpForm=document.forms[strName.substring(0,strName.indexOf("."))])) reElement=tmpForm.elements[strName.substring(strName.indexOf(".")+1)]; }
			}
		}
	}
	catch(e) { dbg.obj(e); }
	return reElement;
}

dcs.form.getValue=function(strName)
{
	var re="";
	var tmpElement=this.getElement(strName);
	if (isObject(tmpElement))
	{
		var tmpType=tmpElement.type;
		if (isEmpty(tmpType)) tmpType="";
		if (tmpElement.length || inPart("radio,checkbox",tmpType)>0)
		{
			if (tmpElement.length)
			{
				for(var i=0;i<tmpElement.length;i++)
				{
					if (isEmpty(tmpType)) tmpType=tmpElement[i].type;
					switch (tmpType)
					{
						case "radio":
							if (tmpElement[i].checked) re=tmpElement[i].value;
							break;
						case "checkbox":
							if (tmpElement[i].checked) re+=","+tmpElement[i].value;
							break;
					}
				}
				if (tmpType=="checkbox" && !isEmpty(re)) re=re.substring(2);
			}
			else
			{
				switch (tmpType)
				{
					case "radio":
						if (tmpElement.checked) re=tmpElement.value;
						break;
					case "checkbox":
						if (tmpElement.checked) re=tmpElement.value;
						break;
				}
			}
		}
		else { re=tmpElement.value; }
	}
	return re;
}

dcs.form.setValue=function(strName,strValue,strMode)
{
	var tmpElement=this.getElement(strName);
	if (isObject(tmpElement))
	{
		if (isEmpty(strValue)) strValue="";
		if (tmpElement.length)
		{
			var tmpType="";
			for(var i=0;i<tmpElement.length;i++)
			{
				if (isEmpty(tmpType)) tmpType=tmpElement[i].type;
				switch (tmpType)
				{
					case "radio":
						if (inPart(strValue,tmpElement[i].value)>0 || strMode==("__no"+(i+1))) tmpElement[i].checked=true;
						break;
					case "checkbox":
						if (inPart(strValue,tmpElement[i].value)>0 || strMode=="__all__") tmpElement[i].checked=true;
						break;
				}
			}
		}
		else
		{
			if (strMode=="append") tmpElement.value+=strValue;
			else tmpElement.value=strValue;
		}
	}
}

dcs.form.doOnceSubmit=function(strForm)
{
	var _objForm=strForm;
	if (!isObject(_objForm)) _objForm=document.forms[strForm];
	if (isObject(_objForm))
	{
		if (_objForm._smt) _objForm._smt.disabled=true;
		if (_objForm._sbt) _objForm._sbt.disabled=true;
		if (_objForm._rst) _objForm._rst.disabled=true;
	}
}

dcs.form.doSubmit=function(strForm)
{
	var _objForm=strForm;
	if (!isObject(_objForm)) _objForm=document.forms[strForm];
	if (isObject(_objForm)) _objForm.submit();
}

dcs.form.doQuickSubmit=function(strForm,strEvent)
{
	if (!strEvent) strEvent=event;
	if ((strEvent.keyCode==13 && strEvent.ctrlKey) || (strEvent.keyCode==83 && strEvent.altKey))
	{
		this.doOnceSubmit(strForm);
		this.doSubmit(strForm);
	}
}

dcs.form.toConvertInput=function(strer,strName)
{
	if (isEmpty(strName)) strName=this.SELECT_INPUT_NAME;
	var re="";
	var tmpAry=strer.split(",");
	for (var i=0;i<tmpAry.length;i++) { re+="<input type=\"hidden\" name=\""+strName+"\" value=\""+tmpAry[i]+"\">"; }
	return re;
}





//########################################
//########################################
dcs.pages=new Object();

dcs.pages.go=function(strer) { document.location.href=strer; }

dcs.pages.isClickReturn=function(strer,strt)
{
	var re="";
	switch (strt)
	{
		case 1: re="您确定"+strer+"吗？"; break;
		case 2: re="您确定要"+strer+"吗？\n\n执行该操作后将不可恢复！"; break;
		default : re=strer; break;
	}
	return window.confirm(re);
}

dcs.pages.doOpenWins=function(strurl,strname,strwidth,strheight,strscroll,strContent)
{
	var _left_size=0;
	var _top_size=0;
	if (strwidth==0 || strheight==0) { strwidth=screen.width-8; strheight=screen.height-55; }
	else { _left_size=(screen.width) ? (screen.width-strwidth)/2 : 0; _top_size=(screen.height) ? (screen.height-strheight)/2 : 0; }
	var _open_win=window.open(strurl,strname,'width='+strwidth+',height='+strheight+',left='+_left_size+',top='+_top_size+',toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars='+strscroll+',resizable=yes');
	if (!isEmpty(strContent)) { _open_win.document.write(strContent); /*_open_win.document.close();*/ }
	return _open_win;
}

dcs.pages.doOpenWin=function(strurl,strname,strwidth,strheight,strscroll)
{
	var _left_size=(screen.width) ? (screen.width-strwidth)/2 : 0;
	var _top_size=(screen.height) ? (screen.height-strheight)/2 : 0;
	var _open_win=window.open(strurl,strname,'width='+strwidth+',height='+strheight+',left='+_left_size+',top='+_top_size+',toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars='+strscroll+',resizable=no');
}

// onKeyPress="event.returnValue=dcs.pages.isInputInt(0);"
dcs.pages.isInputInt=function(strer)
{
	var tmpKeyCode=event.keyCode;
	var re=false;
	if (tmpKeyCode>=48 && tmpKeyCode<= 57) { re=true; }
	if (strer==1 && !re && tmpKeyCode==46) { re=true; }
	return re;
}

dcs.pages.doBlockSwitch=function(strBlock,strImages)
{
	var objBlock=$(strBlock);
	if (objBlock)
	{
		var tmpStatus=objBlock.style.display;
		objBlock.style.display=(tmpStatus=="none" ? "" : "none");
		if (isEmpty(strImages)) strImages=strBlock+"_icon";
		var objImages=$(strImages);
		if (objImages) objImages.src=objImages.src.replace((tmpStatus=="none" ? "open" : "close"),(tmpStatus=="none" ? "close" : "open"));
	}
	return false;
}




//########################################
//########################################
dcs.window=new Object();
dcs.window._QueuesOnLoad=new Array();

dcs.window.doTimeout=function(strer,strSpace) { window.setTimeout(strer,strSpace*1000); }
dcs.window.addTimeout=function(strer,strSpace) { window.setTimeout(strer,strSpace*1000); }

dcs.window.addOnLoad=function(strer) { this._QueuesOnLoad[this._QueuesOnLoad.length]=strer; }
dcs.window.doOnLoad=function() { for (var i=0;i<this._QueuesOnLoad.length;i++) { eval(this._QueuesOnLoad[i]); } }

dcs.window.getClipBoardData=function(strType)
{
	var re="";
	if (window.clipboardData)
	{
		if (isEmpty(strType)) strType="text";
		re=window.clipboardData.getData(strType);
	}
	return re;
}
dcs.window.setClipBoardData=function(strer) { if (window.clipboardData) window.clipboardData.setData(strer); }
dcs.window.doClipBoardClear=function() { if (window.clipboardData) window.clipboardData.clearData(); }

//window.onerror=function(a,b,c){return true;}
window.onload=function() { dcs.window.doOnLoad(); }




//########################################
//########################################
var dbg=new Object();

dbg.toString=function(o,l) { if (inPart("number,string,boolean",typeof(o))>0) return (l>0 && o.length>l) ? o.substr(0,l)+" ..." : o; else return "["+typeof(o)+"]"; }

dbg.obj=function(strObject,strMode,strRow)
{
	var _k,_v,_n=1,re="";
	if (isEmpty(strRow) || strRow==-1) strRow=20;
	try
	{
		for(_k in strObject)
		{
			if (_n>=strRow) { alert(re); re=""; _n=1; }
			if (strMode=="key") re+=_k+"\n"; else re+=_k+"="+(this.toString(strObject[_k],50))+"\n";
			_n++;
		}
		if (re!="") { alert(re); re=""; }
	}
	catch(e) { dbg.e(e); }
}

dbg.objString=function(strObject,strMode,strRow)
{
	var _k,_v,_n=1,re="";
	if (isEmpty(strRow) || strRow==-1) strRow=20;
	try
	{
		for(_k in strObject)
		{
			if (strMode=="key") re+=_k+"\n"; else re+=_k+"="+(this.toString(strObject[_k],50))+"\n";
			_n++;
		}
	}
	catch(e) { re=dbg.eString(e); }
	return re;
}

dbg.e=function(e) { alert(dbg.eString(e)); }

dbg.eString=function(e)
{
	var re="";
	for(var k in e) { re+=k+"="+e[k]+"\n"; }
	return re;
}

function doTestObject(strObject,strMode,strRow) { dbg.obj(strObject,strMode,strRow); }

