Several nice functions in js $ ()
The Code is as follows:
Function map (a, f) {f ();}
Function getRand (a, B)
{
If ()
{
B = B? B: 0;
Return Math. floor (Math. random () * a + B );
} Else
{
A = new Date ();
Return d. getTime ();
}
}
Function $ (a) {document. write ();}
Function $ ()
{
Var elements = new Array ();
For (var I = 0; I <arguments. length; I ++)
{
Var element = arguments [I];
If (typeof element = 'string ')
Element = document. getElementById (element );
If (arguments. length = 1)
Return element;
Elements. push (element );
}
Return elements;
}
Function fGetCookie (name)
{
Var cookieValue = "";
Var search = name + "= ";
If (document. cookie. length> 0)
{
Offset = document. cookie. indexOf (search );
If (offset! =-1)
{
Offset + = search. length;
End = document. cookie. indexOf (";", offset );
If (end =-1) end = document. cookie. length;
CookieValue = unescape (document. cookie. substring (offset, end ));
}
}
Return cookieValue;
}
Function J_get (name)
{
Var js_get parameters self.20.doc ument. location. href;
Var start = js_get.indexOf (name + '= ');
If (start =-1) return '';
Var len = start + name. length + 1;
Var end = js_get.indexOf ('&', len );
If (end =-1) end = js_get.length;
Return unescape (js_get.substring (len, end ));
}
Function writeCookie (name, value, hours)
{
Var expire = "";
Var domain = "; domain = jb51.net; path = /";
If (hours! = "")
{
Expire = new Date (). getTime () + hours * 60*60*1000 );
Expire = "; expires =" + expire. toGMTString ();
}
Document. cookie = name + "=" + escape (value) + domain;
}
Function createXMLHttp ()
{
Var ret = null;
Try {
Ret = new ActiveXObject ('msxml2. xmlhttp ');
}
Catch (e ){
Try {
Ret = new ActiveXObject ('Microsoft. xmlhttp ');
}
Catch (ee ){
Ret = null;
}
}
If (! Ret & typeof XMLHttpRequest! = 'Undefined ')
Ret = new XMLHttpRequest ();
Return ret;
}
Function loadXmlToElement (fragment_url, element_id, mode, de)
{
Var element =$ $ (element_id );
Var xmlhttp = createXMLHttp ();
Var str;
Xmlhttp. open ("GET", fragment_url );
Xmlhttp. onreadystatechange = function ()
{
If (xmlhttp. readyState = 4 & xmlhttp. status = 200)
{
If (! Mode)
{
Str = xmlhttp. responseXML. getElementsByTagName ("data") [0]. childNodes [0]. nodeValue;
If (! Element. innerHTML)
{
Try {
Str = xmlhttp. responseXML. firstChild. childNodes [1]. nodeValue;
} Catch (e ){}
}
} Else if (mode = 'txt ')
{
Str = xmlhttp. responseText;
}
If (de) str = unescape (str );
Element. innerHTML = str;
}
}
Xmlhttp. send (null );
}
Var oJson = new Object ();
Var fJson =
{
"Data": {}, // [0, y, yes, null]: Default, [-1, n, no]: Do not run flush (),
"File": {}, // Add a js Code file
"Str" :{}, // Add JS Code
"Set": function (element, vars)
{
For (key in vars)
{
This [key] [element] = vars [key];
}
},
"GetSrc": function (element)
{
Var rs = '';
If (this ['data'] [element])
{
If (this ['data'] [element] = 'n' | this ['data'] [element] = '-1' | this ['data'] [element] = 'no ')
{
Rs + = '& gJsonData = n ';
}
}
If (this ['str'] [element])
{
Rs + = '& gJsonDoStr =' + escape (this ['str'] [element]);
}
If (this ['file'] [element])
{
Rs + = '& gJsonDoFile =' + escape (this ['file'] [element]);
}
Return rs;
},
"Main": function (url, element, un)
{
Un = un? Un: 0;
Eval ("oJson. "+ element +" = new fJson. _ Json ('"+ url +"', '"+ element +"', '"+ un + "')");
},
"_ Json": function (url, element, un)
{
Var a = document. getElementById ("script _" + element)
If (! A)
{
A = document. createElement ("script ");
A. setAttribute ("id", "script _" + element );
}
A. un = un;
A. data = '';
A. src = url + (url. indexOf ('? ') =-1 )? '? ':' & ') + 'Gjson =' + element + fJson. getSrc (element );
If (navigator. appVersion. indexOf ("MSIE") =-1)
{
Document. getElementById (element). insertBefore (a, null );
} Else
{
Document. body. insertAdjacentElement ("BeforeBegin", );
}
Return;
},
"Flush": function (element)
{
Document. getElementById (element). innerHTML = (oJson [element]. un )? Unescape (oJson [element]. data): oJson [element]. data;
// OJson [element] = null;
}
}
/* Application */
Function subPageSelect (B, e, d, a) // B Start e end d default a action
{
Var shtml ='';For (var I = B; I <= e; I ++){Shtml + =''+ I +'';}Shtml + ='';
Return shtml;
}
Function err (a, B, c)
{
If (B)
{
If (c)
{
A. src = 'HTTP: // www.jb51.net/space/imgs/all/thu_woman.gif ';
} Else
{
A. src = 'HTTP: // v.jb51.net: 88/img/user_no_photo.gif ';
}
} Else
{
A. src = 'HTTP: // v.jb51.net: 88/img/flv_no_photo.gif ';
}
}
Function img_onerr ()
{
Err ();
}
Function gowin ()
{
Document. location =;
}
Function CopyInBoard (hahaUrl, note)
{
Note = note? Note: 'The website has been copied successfully! ';
Window. clipboardData. setData ('text', hahahaurl)
Alert (note );
}
Function fDoMask (a, f, s, c, p, color) // a element f refreshes the call function s style c content p transparency
{
A =$ $ ();
P = p? P: 75;
S ='
'+ (C? C: 'loading data... ') + (f? '[Refresh]': '') +'
';
Color = color? Color: '# ffff ';
If (a. innerHTML! = "")
{
// Window. onunload = fCheckStatus;
Var objBrother = a. childNodes [0];
Var B = document. createElement ('div ');
B. setAttribute ('id', 'maskp ');
B. style. textAlign = "center ";
B. style. position = "absolute ";
B. style. filter = "alpha (opacity =" + p + ")";
B. style. opacity = (p/100 );
B. style. Required opacity = (p/100 );
B. style. KhtmlOpacity = (p/100 );
B. style. width = a ['offsetwidth'] + 'px ';
B. style. height = a ['offsetheight'] + 'px ';
B. style. margin = "0px ";
B. style. backgroundColor = color;
A. insertBefore (B, objBrother)
B. innerHTML = s;
}
}
Function switchDisplay (obj1, obj2)
{
Try
{
Obj1 =$ $(obj1 );
Obj2 =$ $(obj2 );
If (obj1.style. display = '')
{
Obj1.style. display = 'none ';
Obj2.style. display = '';
}
Else
{
Obj1.style. display = '';
Obj2.style. display = 'none ';
}
} Catch (ex)
{
}
}
Function getFlashPlayer (vars, playUrl, id, w, h)
{
PlayUrl = playUrl? PlayUrl: 'http: // www.jb51.net/flashapp/56 ';
Id = id? Id: 'siteflvplayer ';
W = w? W: '000000 ';
H = h? H: '000000 ';
AC_FL_RunContent ('codebase', 'HTTP: // response); // end AC code
}
Function f_js_playObject (a, h, s, player)
{
H = 'www .jb51.net ';//#..
Player = player? Player: '/flashApp/v_player_site_fp7_5.swf ';
Player = 'HTTP: // '+ h + player;
S = s? S: 'width = "100%" height = "100% "';
Var _ into = "";
_ Into + ='
';
_ Into + ='
Double-click the player screen or click "full screen" to cancel or restore the full screen.
';
_ Into + ='
';
_ Into + ='';
_ Into + ='';
_ Into + ='';
_ Into + ='';
_ Into + ='';
_ Into + ='';
_ Into + ='';
_ Into + ='';
_ Into + ='';
_ Into + ='
';
_ Into + ='
';
_ Into + =' ';
_ Into + ='
If the video cannot be played normally, click here for details.
';
_ Into + ='
The video cannot be played normally due to the following conditions. Please download the Flash8.0 player. Click here to download
1. If the page is opened, only the sound and no video are displayed.
2. The player cannot be loaded. "Red X" appears"
3. the player can be loaded, but the system prompts that the version is too low!
If the video cannot be played in the above circumstances, please report it to us! Http://bbs.jb51.net/data/841/841800.html? Sid = 11212 "target =" _ blank "> click this report
[Disable details]
';
Document. getElementById ('js _ playobject'). innerHTML = _;
FcheckZoom ();
}
Function zoomMovie (){
Var objId = 'videoplayer ';
Var videoObject = document. all? Document. all [objId]: document. getElementById (objId );
Var maskForIe = document. all? Document. all ['maskforie']: document. getElementById ('maskforie ');
Var videoPlayBack = document. all? Document. all ['flvplayback']: document. getElementById ('flvplayback ');
Var playerInfo = document. all? Document. all ['playerinfo']: document. getElementById ('playerinfo ');
Var searchBox = document. all? Document. all ['nav _ search_form ']: document. getElementById ('nav _ search_form ');
Var isMaxmized =/. * maxmized. */I. test (videoObject. className );
If (isMaxmized ){
VideoObject. className = 'normalsize ';
VideoObject. style. position = '';
VideoPlayBack. firstChild. BGCOLOR = 'ffffff ';
PlayerInfo. style. display = 'none ';
MaskForIe. style. display = 'none ';
SearchBox. style. display = '';
} Else {
Window. scrollTo (0, 0 );
VideoObject. className = 'maxmized ';
VideoObject. style. position = 'absolute ';
If (navigator. appName. lastIndexOf ('Explorer ')! =-1 ){
VideoObject. style. left = (document. body. parentNode. The scrollWidth-600)/2;
VideoObject. style. top = '30 ';
PlayerInfo. style. display = '';
MaskForIe. style. display = '';
}
VideoPlayBack. firstChild. BGCOLOR = '000000 ';
}
VideoObject. onclick = function () {zoomMovie ()}
}
Function FcheckZoom ()
{
Var a = J_get ('fs ');
If (a = 1)
{
ZoomMovie ();
}
}
/* Menu */
Var isOverMainMenu = false;
Var isOverSortMenu = false;
Function showMenu (id ){
Var a = document. getElementById ("MainMenu"). getElementsByTagName ("");
For (var I = 0; I a [I]. onmouseover = function (){
If (this. className! = "Active") this. className = "hover ";
ShowSortMenu (this. id );
IsOverMainMenu = true;
}
A [I]. onmouseout = function (){
If (this. className! = "Active") this. className = "";
SetTimeout ("showSortMenu (" + id + "')", 400 );
IsOverMainMenu = false;
}
If (a [I]. id = id ){
A [I]. className = "active ";
ShowSortMenu (id );
} Else {
A [I]. className = "";
}
}
}
Function showSortMenu (id ){
Var a = document. getElementById ("SortMenu ");
A. onmouseover = function (){
IsOverSortMenu = true;
}
A. onmouseout = function (){
IsOverSortMenu = false;
}
If (! IsOverSortMenu &&! IsOverMainMenu ){
Var B = document. getElementById ("SortMenu"). getElementsByTagName ("ul ");
For (var I = 0; I If (B [I]. id = "SortMenu _" + id ){
B [I]. className = "active ";
} Else {
B [I]. className = "";
}
}
}
}
/*******************************/
Var gLoginId = fGetCookie ("member_id"); // logon user ID
Var gLoginHost = fGetCookie ("host"); // logon host Name
Var gLoginPass = fGetCookie ("pass_hex"); // pass
Var gLoginMember = fGetCookie ("member_login"); // member_login
Var gNewMail = fGetCookie ("newmail"); // new email
Var gKeepMail = fGetCookie ("keepmail"); // whether to check the email id
Var gLoginUser = gLoginId. substring (0, gLoginId. indexOf ("@"); // login Username
Var gIsLogin = (gLoginHost! = "" & GLoginUser! = "" & GLoginPass! = "" & GLoginMember! = "")? True: false; // whether the user has logged on
Var basedir = 'HTTP: // v.jb51.net: 88/photo /';
Var userDir = fCaculateUrl (gLoginUser );
Function fIsLogin ()
{
Return (fGetCookie ("host ")! = "" & FGetCookie ("member_id ")! = "" & FGetCookie ("pass_hex ")! = "" & FGetCookie ("member_login ")! = "")? True: false;
}
Function fCaculateUrl (userName)
{
Var level1 = 0;
Var level2 = 0;
Var k = userName. length;
// Var arr = new Array ();
For (var I = 0; I {
Level1 + = userName. charCodeAt (I) * I;
Level2 + = userName. charCodeAt (I) * (2 * I + 1 );
}
Level1 = level1. % 100;
Level2 = level2 % 100;
Return level1 + '/' + level2;
}
Document. domain = "jb51.net ";
Window. focus ();