atom_js
//SCRIPT_START
function AddNamespace(ns)
{
var nsParts = ns.split(".");
var root = window;
for(var i=0; i<nsParts.length; i++)
{
if(typeof root[nsParts[i]] == "undefined")
root[nsParts[i]] = new Object();
root = root[nsParts[i]];
}
}
AddNamespace("SysTool");
SysTool.isExist = function()
{
var strErrMsg = '';
var bExist = true;
var bDebug = typeof(arguments[arguments.length-1])!="boolean"?false:arguments[arguments.length-1]?true:false;
for( var i=0; i<arguments.length; i++ )
{
if( typeof(arguments[i])=='undefined' )
{
strErrMsg += "IsExist():The No."+i+" parameter is undefined./n";
bExist = false;
}
}
if( bDebug && !bExist )
alert(strErrMsg);
return bExist;
}
SysTool.isArray = function()
{
var strErrMsg = '';
var bArray = true;
var bDebug = typeof(arguments[arguments.length-1])!="boolean"?false:arguments[arguments.length-1]?true:false;
for( var i=0; i<arguments.length-(typeof(arguments[arguments.length-1])=="boolean"?1:0) ; i++ )
{
if( this.isExist(arguments[i]) )
{
if( arguments[i].constructor!=Array )
{
bArray = false;
strErrMsg += "IsArray():The No."+i+" parameter is not an Array./n";
}
}
else
{
bArray = false;
strErrMsg += "IsArray():The No."+i+" parameter is undefined./n";
}
}
if( bDebug && !bArray )
alert(strErrMsg);
return bArray;
}
SysTool.addProperty = function ( obj, arrProperty )
{
if( !this.isExist(obj,true) || !this.isArray(arrProperty,true))
return;
for( var i=0; i<arrProperty.length; i++ )
{
var dataParts = arrProperty[i].split("@");
if( !this.isArray(dataParts) || dataParts.length<2 )
break;
try
{
obj[dataParts[0]] = dataParts[1];
}
catch(e1)
{
alert("Exception: "+dataParts[0]+"="+dataParts[1]);
}
}
}
SysTool.getElementsByClassName = function( oElement, strCls )
{
var arrRet = new Array();
for( var i=0; i<oElement.childNodes.length;i++ )
if( oElement.childNodes[i].className==strCls )
arrRet[arrRet.length] = oElement.childNodes[i];
return arrRet.length?arrRet:null;
}
SysTool.matchTag = function( strChaos, tagName )
{
var reTag = eval('/<(///)?'+tagName+'.*?>/ig');
var nStack = 0;
while( (arrTest = reTag.exec(strChaos))!=null)
{
nStack += ((RegExp.$1)==''?1:-1);
if( !nStack )
break;
}
if( nStack != 0 )
return "Error: matchTag() cannot match tag:"+tagName;
var reTagStart = eval('/<'+tagName+'.*?>/i');
var arrTag = reTagStart.exec(strChaos);
return strChaos.substring(arrTag.index+arrTag[0].length,arrTest.index);
}
SysTool.SetDebugPrint = function(strFilePath)
{
if( !this.isExist(this.DP_aoFSO))
{
this.DP_strFilePath = this.isExist(strFilePath)?strFilePath:"c://Sys_Debug_print.txt";
try
{
this.DP_aoFSO = new ActiveXObject("Scripting.FileSystemObject");
this.DP_hDebugFile = this.DP_aoFSO.createTextFile(this.DP_strFilePath,"true");
}
catch(e1)
{
alert(e1);
}
}
}
SysTool.DebugPrint = function( strContent )
{
if( !this.isExist(this.DP_asFSO))
{
this.SetDebugPrint();
}
this.DP_hDebugFile.WriteLine(strContent);
}
//SCRIPT_END
function AddNamespace(ns)
{
var nsParts = ns.split(".");
var root = window;
for(var i=0; i<nsParts.length; i++)
{
if(typeof root[nsParts[i]] == "undefined")
root[nsParts[i]] = new Object();
root = root[nsParts[i]];
}
}
AddNamespace("SysTool");
SysTool.isExist = function()
{
var strErrMsg = '';
var bExist = true;
var bDebug = typeof(arguments[arguments.length-1])!="boolean"?false:arguments[arguments.length-1]?true:false;
for( var i=0; i<arguments.length; i++ )
{
if( typeof(arguments[i])=='undefined' )
{
strErrMsg += "IsExist():The No."+i+" parameter is undefined./n";
bExist = false;
}
}
if( bDebug && !bExist )
alert(strErrMsg);
return bExist;
}
SysTool.isArray = function()
{
var strErrMsg = '';
var bArray = true;
var bDebug = typeof(arguments[arguments.length-1])!="boolean"?false:arguments[arguments.length-1]?true:false;
for( var i=0; i<arguments.length-(typeof(arguments[arguments.length-1])=="boolean"?1:0) ; i++ )
{
if( this.isExist(arguments[i]) )
{
if( arguments[i].constructor!=Array )
{
bArray = false;
strErrMsg += "IsArray():The No."+i+" parameter is not an Array./n";
}
}
else
{
bArray = false;
strErrMsg += "IsArray():The No."+i+" parameter is undefined./n";
}
}
if( bDebug && !bArray )
alert(strErrMsg);
return bArray;
}
SysTool.addProperty = function ( obj, arrProperty )
{
if( !this.isExist(obj,true) || !this.isArray(arrProperty,true))
return;
for( var i=0; i<arrProperty.length; i++ )
{
var dataParts = arrProperty[i].split("@");
if( !this.isArray(dataParts) || dataParts.length<2 )
break;
try
{
obj[dataParts[0]] = dataParts[1];
}
catch(e1)
{
alert("Exception: "+dataParts[0]+"="+dataParts[1]);
}
}
}
SysTool.getElementsByClassName = function( oElement, strCls )
{
var arrRet = new Array();
for( var i=0; i<oElement.childNodes.length;i++ )
if( oElement.childNodes[i].className==strCls )
arrRet[arrRet.length] = oElement.childNodes[i];
return arrRet.length?arrRet:null;
}
SysTool.matchTag = function( strChaos, tagName )
{
var reTag = eval('/<(///)?'+tagName+'.*?>/ig');
var nStack = 0;
while( (arrTest = reTag.exec(strChaos))!=null)
{
nStack += ((RegExp.$1)==''?1:-1);
if( !nStack )
break;
}
if( nStack != 0 )
return "Error: matchTag() cannot match tag:"+tagName;
var reTagStart = eval('/<'+tagName+'.*?>/i');
var arrTag = reTagStart.exec(strChaos);
return strChaos.substring(arrTag.index+arrTag[0].length,arrTest.index);
}
SysTool.SetDebugPrint = function(strFilePath)
{
if( !this.isExist(this.DP_aoFSO))
{
this.DP_strFilePath = this.isExist(strFilePath)?strFilePath:"c://Sys_Debug_print.txt";
try
{
this.DP_aoFSO = new ActiveXObject("Scripting.FileSystemObject");
this.DP_hDebugFile = this.DP_aoFSO.createTextFile(this.DP_strFilePath,"true");
}
catch(e1)
{
alert(e1);
}
}
}
SysTool.DebugPrint = function( strContent )
{
if( !this.isExist(this.DP_asFSO))
{
this.SetDebugPrint();
}
this.DP_hDebugFile.WriteLine(strContent);
}
//SCRIPT_END