/*************************************** ****************************************
* Joneajax obtains DOM objects, Ajax operations, and reads and writes cookies.
* @ Author Roddy <minguiluo@gmail.com>
* @ Site http://www.cnblogs.com/luomingui/
* @ Version 1.0.0
**************************************** ***************************************/
VaR lf = {};
Lf. Version = '1. 0.0 ';
// Global functions
Function $ (objname ){
Return document. getelementbyid (objname );
}
Function $ name (objname ){
Return document. getelementsbyname (objname );
}
Function $ tag (objname ){
Return document. getelementsbytagname (objname );
}
// Ad SWF flashwrite ('sw/2009/homegrobuy.swf ', '123', '70', 'navigation',' # ffff', 'menunum = 0 ', 'Transparent ');
Function flashwrite (URL, W, H, ID, BG, vars, Win ){
VaR flashstr =
"<Div align = \" center \ "> <object classid = 'clsid: d27cdb6e-ae6d-11cf-96b8-444553540000 'codebase = 'HTTP: // adjust width = '"+ W +" 'height =' "+ H +" 'id = '"+ ID +" 'align = 'middle'> "+
"<Param name = 'allowScriptAccess' value = 'alway'/>" +
"<Param name = 'movie 'value ='" + URL + "'/>" +
"<Param name = 'flashvars' value = '" + vars + "'/>" +
"<Param name = 'wmode' value = '" + win + "'/>" +
"<Param name = 'menu 'value = 'false'/>" +
"<Param name = 'quality' value = 'high'/>" +
"<Param name = 'bgcolor' value = '" + bg + "'/>" +
"<Embed src = '" + URL + "'flashvars ='" + vars + "'wmode = '" + win + "'menu = 'false' Quality = 'high' bgcolor = '"+ bg +" 'width =' "+ W +" 'height = '"+ H +" 'name =' "+ ID +" 'align = 'Middle 'allowscriptaccess = 'allowes' type = 'application/X-Shockwave-flash' pluginspage = 'HTTP: // www.macromedia.com/go/getflashplayer'/> "+
"</Object> </div> ";
Document. Write (flashstr );
}
// Imgwrite ('images/pic04.jpg ', '000000', '90', 'HTTP: // www.lfang.com/wzzt/2009/lgzt /');
Function imgwrite (URL, W, H, linkurl ){
VaR flashstr = "";
If (linkurl = "")
Flashstr = " ";
Else
Flashstr = "<a href = \" "+ linkurl +" \ ">" + " "+" </a> ";
Document. Write (flashstr );
}
// Ajax operation
Lf. Ajax = {
Getxmlhttp: function (){
VaR http_request;
If (window. XMLHttpRequest ){
Http_request = new XMLHttpRequest ();
If (http_request.overridemimetype ){
Http_request.overridemimetype ("text/XML ");
}
}
Else if (window. activexobject ){
Try {
Http_request = new activexobject ("msxml2.xmlhttp ");
} Catch (e ){
Try {
Http_request = new activexobject ("Microsoft. XMLHTTP ");
} Catch (e ){}
}
}
If (! Http_request ){
Window. Alert ("can't create XMLHTTPRequest object .");
Return NULL;
}
Return http_request;
},
Loadajaxtab: function (URL) {// Div
Try {
VaR xhttp = lf. Ajax. getxmlhttp ();
Xhttp. Open ("get", URL, false );
Xhttp. Send (null );
If (xhttp. readystate = 0) Return "0 initializing ......";
If (xhttp. readystate = 1) Return "1 initializing ......";
If (xhttp. readystate = 2) Return "2 initializing ......";
If (xhttp. readystate = 3) Return "3 initializing ......";
If (xhttp. readystate = 4 & (xhttp. Status = 200 )){
VaR restext = xhttp. responsetext;
If (restext! = "") Return restext;
}
} Catch (e ){
Return E;
}
},
Datasubmit: function (URL, urlparameter, method) {// Ajax post submits data
Try {
If (Method = "") {method = "Post ";}
VaR xhttp = lf. Ajax. getxmlhttp ();
Xhttp. Open (method, URL + urlparameter, false );
Xhttp. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ");
Xhttp. Send (null );
If (xhttp. readystate = 0) Return "0 initializing ......";
If (xhttp. readystate = 1) Return "1 initializing ......";
If (xhttp. readystate = 2) Return "2 initializing ......";
If (xhttp. readystate = 3) Return "3 initializing ......";
If (xhttp. readystate = 4 & xhttp. Status = 200) return xhttp. responsetext;
} Catch (e ){
Return E;
}
}
};
// Tool
Lf. util = {
Setcookie: function (name, value) {// write cookies
VaR days = 30;
VaR exp = new date ();
Exp. settime (exp. gettime () + days x 24x60*60*1000 );
Document. Cookie = Name + "=" + escape (value) + "; expires =" + exp. togmtstring ();
},
Getcookie: function (name) {// read cookies
VaR arr, Reg = new Regexp ("(^ |)" + name + "= ([^;] *) (; | $ )");
If (ARR = Document. Cookie. Match (REG) return Unescape (ARR [2]);
Else return NULL;
},
Delcookie: function (name) {// Delete cookies
VaR exp = new date ();
Exp. settime (exp. gettime ()-1 );
VaR cval = getcookie (name );
If (cval! = NULL) document. Cookie = Name + "=" + cval + "; expires =" + exp. togmtstring ();
},
Escape: function (HTML) {// filter HTML
Html = html. Replace (/&/g, "& amp ;");
Html = html. Replace (/</g, "& lt ;");
Html = html. Replace (/>/g, "& gt ;");
Html = html. Replace (/\ xa0/g, "& nbsp ;");
Html = html. Replace (/\ x20/g ,"");
Return HTML;
}
};