Ajax EncapsulationCode
VaR waitelement;
VaR scrollx, scrolly =-1;
Function Ajax (){
/// Create an object
VaR XMLHTTP;
Try
{
If (window. activexobject ){
/* Do not delete the following comments, which are not comments */
/* @ Cc_on @*/
/* @ If (@ _ jscript_version> = 5)
Try {
XMLHTTP = new activexobject ("msxml2.xmlhttp ");
} Catch (e ){
Try {
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
} Catch (e ){
XMLHTTP = false;
}
}
@ End @*/
} Else {
XMLHTTP = new XMLHttpRequest ();
}
If (! XMLHTTP & typeof XMLHttpRequest! = 'Undefined '){
XMLHTTP = new XMLHttpRequest ();
}
}
Catch (E)
{
Alert (E. Message );
}
If (! XMLHTTP)
{
Alert ("your browser does not support XMLHTTP objects, so some features cannot be used. We recommend that you use a later version of the browser !! ");
Return;
}
/// Function topic
This. getdata = function (URL, Data, dodata)
{
VaR verbs = data;
// Alert (data );
XMLHTTP. Open ("Post", URL, true );
XMLHTTP. onreadystatechange = function (){
If (XMLHTTP. readystate = 4 ){
Waitelement. style. Visibility = 'hiden ';
Dodata (XMLHTTP );
}
Else {
Createwaitelement ();
Waitelement. style. Visibility = 'visable ';
Movewaitelement ();
}
}
XMLHTTP. setRequestHeader ("Content-Length", verbs. Length );
XMLHTTP. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ");
XMLHTTP. Send (verbs );
}
/////
This. geturldata = function (URL, Data, dodata)
{
XMLHTTP. Open ("get", URL, true );
XMLHTTP. onreadystatechange = function (){
If (XMLHTTP. readystate = 4 & XMLHTTP. Status = 200 ){
Dodata (XMLHTTP );
}
Else
{
Waitelement. style. Visibility = 'visable ';
}
}
XMLHTTP. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ");
XMLHTTP. Send (null );
}
This. getformdata = function (DEMO)
{
// Alert (DEMO );
}
/// Function topic
}
If (window. addeventlistener ){
Window. addeventlistener ('scroll ', movewaitelement, false );
Window. addeventlistener ('resize', movewaitelement, false );
}
Else if (window. attachevent ){
Window. attachevent ('onscroll ', movewaitelement );
Window. attachevent ('onresize', movewaitelement );
}
Function movewaitelement (){
VaR scrollyt, scrollxt;
If (! Waitelement)
Createwaitelement ();
If (typeof (window. pageyoffset) = "Number "){
Scrollyt = Window. pageyoffset;
Scrollxt = Window. pagexoffset;
}
Else if (document. Body & document.doc umentelement. scrolltop ){
Scrollyt = document.doc umentelement. scrolltop;
Scrollxt = Document. Body. scrollleft;
}
Else if (document. Body & typeof (document. Body. scrolltop) = "Number "){
Scrollyt = Document. Body. scrolltop;
Scrollxt = Document. Body. scrollleft;
}
If (scrollx! = Scrollxt | scrolly! = Scrollyt ){
Scrollx = scrollxt;
Scrolly = scrollyt;
VaR width = Document. Body. clientwidth;
Waitelement. style. Top = scrollyt + "PX ";
Waitelement. style. Right =-scrollxt + "PX ";
}
}
Function createwaitelement (){
VaR ELEM = Document. getelementbyid ('_ ajax_loading ');
If (! ELEM ){
ELEM = Document. createelement ("Div ");
ELEM. ID = '_ ajax_loading ';
ELEM. style. Position = 'absolute ';
ELEM. style. Height = 17;
ELEM. style. paddingleft = "3px ";
ELEM. style. paddingright = "3px ";
ELEM. style. fontsize = "11px ";
ELEM. style. fontfamily = 'arial, verdana, tahoma ';
ELEM. style. Border = "#000000 1px solid ";
ELEM. style. backgroundcolor = "red ";
ELEM. style. color = "# ffffff ";
ELEM. innerhtml = 'loading ...';
ELEM. style. Visibility = 'hiden ';
Document. Body. insertbefore (ELEM, document. Body. firstchild );
}
Waitelement = ELEM;
}