SoFunction
Updated on 2025-04-13

Common functions for js 2008-8-16 sorted


/*------------------------------------------------------------
Determine whether the input text is an ID number. If it is incorrect, it will be prompted
text------------------------------------------------------------------------------------------------------------------------------
Use example onBlur="isPid(this)"
------------------------------------------------------------*/
function isPid(text)
{
var pid=();
var temp="0123456789";
var temp1="0123456789xX";
if(pid!=""){
if(==15)
{
for(j=0; j<15; j++ )
{
var ch = (j);
if((ch)==-1)
{
alert("Please enter the correct ID number!");
();
break;
}
}
}
else if(==18)
{

for(j=0; j<-1; j++ )
{
var ch = (j);
if((ch)==-1)
{
alert("Please enter the correct ID number!");
();
break;
}
}
var ch1 = (-1);
if((ch1)==-1)
{
alert("Please enter the correct ID number!");
();
}
}
else{
alert("The ID number should be 15 or 18 digits!");
();
}}
}

/*------------------------------------------------------------
Determine whether the password inputs are consistent between the two times
text----------New password
name--------------Enter new password again
Use example checkPassword(,form1.newpass1)
------------------------------------------------------------*/
function checkPassword(text,text1)
{
var newpass=();
var newpass1=();
if(newpass!=newpass1){
alert("The new password is inconsistent when inputting the two times!");
();
return true;
}
}


/**//*------------------------------------------------------------
Determine whether there are illegal characters. If there are illegal characters, prompt
text------------Enter text
addtemp----characters that can be included in addition to English and numbers
name------------------------------------------------------------------------------------------------------------------------------
include----The characters that are not allowed in the prompt
Use example onBlur="compareTwoDate(this,'@_','mail','%*$')"
------------------------------------------------------------*/
function isChar(text,addtemp,name,include)
{
var temp="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"+addtemp;
for(j=0; j<; j++ )
{
var ch = ().charAt(j);
if((ch)==-1)
{
alert(name+" is not allowed to include characters such as '"+include+"'!");
();
break;
}
}
}
/**//*------------------------------------------------------------
Determine whether the entered email is an email. If it contains illegal characters, it will be prompted.
text---------Email entered
Use example onBlur="isEmail(this)"
------------------------------------------------------------*/
function isEmail(text)
{
var email=();
var m=("@");
var n=(".");
if(email!="")
{
if(m<1||m>-3)
{
alert("Please enter the correct email format!");
();
return true;
}
else if(n<m+2||n>-2)
{
alert("Please enter the correct email format!");
();
return true;
}
}
}
/**//*------------------------------------------------------------
Determine whether the input text is empty. If it is empty, it will prompt
text------------Enter text
Use example onBlur="isNull(this,'name')"
------------------------------------------------------------*/
function isNull(text,name)
{
if(()==null||()=="")
{
alert(name+"can't be empty!");
();
return true;
}
}

//Allow to be framed
function enableFrame(){
if ( == ){
alert("This operation is prohibited by the administrator");
("stop");
}
}

//No framed
function disableFrame(obj){
if( != ){
(obj);
}
}


//Hide or expand according to the ID control layer
function show_hide(obj){
if($(obj). == "none"){
$(obj). = "";
}else{
$(obj). = "none";
}
}

/*****Screen*******************/
//Calling method:
//
//().width
var WinPage = {
getPageWidth: function()
{
return || || 0;
},

getPageHeight: function()
{
return || || 0;
},

getBodyWidth: function()
{
return || || 0;
},

getBodyHeight: function()
{
return || || 0;
},

getBodyLeft: function()
{
return || || || 0;
},

getBodyTop: function()
{
return || || || 0;
},

getBody: function()
{
return {
width : (),
height : (),
left : (),
top : ()
};
},

getScreenWidth: function()
{
return ;
},

getScreenHeight: function()
{
return ;
}
};

//Test browser type//
var Browser = new Object();

= ();
= /msie/.test();
= /gecko/.test();

/****************/

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
var JsLoader = {
load: function(sUrl, fCallback)
{
var _script = ("script");
_script.setAttribute("type", "text/javascript");
_script.setAttribute("src", sUrl);
("head")[0].appendChild(_script);

if ()
{
_script.onreadystatechange = function()
{
if (=="loaded" || =="complete")
{
fCallback();
}
};
}
else if ()
{
_script.onload = function()
{
fCallback();
};
}
else
{
fCallback();
}
}
};

//Implement a StringBuffer
// var sb = new StringBuffer();
//("<table border='1'>");
//("<tr><td>A</td><td>B</td></tr>");
//("</table>")
//(());
function StringBuffer() {
this._strings_ = new Array;
}

= function(str) {
this._strings_.push(str);
}

= function() {
return this._strings_.join("");
}

= function() {
this._strings_ = new Array;
}