Subversion Repositories DevTools

Rev

Rev 6616 | Rev 6651 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
119 ghuddy 1
<!--
2
 
3
var xmlHttp;
4
var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0;
5
var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0;
6
var is_opera = ((navigator.userAgent.indexOf("Opera6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0;
7
//netscape, safari, mozilla behave the same???
8
var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0;
9
var ajaxdivname;
10
 
6613 dpurdie 11
//
12
//	Load/Hide/Show an Ajax expander
13
//	BaseId - Base for IDs to process
14
//			 IMG_BaseId - image to to toggle
15
//             TGL_BaseId - element to show/hide if found else use BaseId
16
//             BaseId - Div to load Ajax into
17
//	url - Url used to load subcontrol
18
function ToggleLoadControl(baseId, url)
19
{
20
  var img, dmode;
21
  var imgel = MM_findObj("IMG_" + baseId);
22
  var shel =  MM_findObj("TGL_" + baseId);
23
  var divel = MM_findObj(baseId);
24
  if ( !shel ) {
25
      shel = divel;
26
  }
27
  var showing = imgel.getAttribute("data-show");
28
  if(showing == 1) {
29
      img = "images/bt_minus.gif";
30
      dmode = '';
31
      showing = 2
32
  } else if(showing == 2) {
33
      img = "images/bt_plus.gif";
34
      dmode = 'none';
35
      showing = 1;
6616 dpurdie 36
  } else if (url == null) {
37
      img = "images/bt_plus.gif";
38
      dmode = 'none';
39
      showing = 1;
6613 dpurdie 40
  } else {
41
      img = "images/bt_minus.gif";
42
      dmode = '';
43
      showing = 2;
119 ghuddy 44
 
6613 dpurdie 45
      // Set div name for ajax loading
46
      ajaxdivname = baseId;
119 ghuddy 47
 
6613 dpurdie 48
      //Create the xmlHttp object to use in the request
49
      //stateChangeHandler will fire when the state has changed, i.e. data is received back
50
      // This is non-blocking (asynchronous)
51
      xmlHttp = GetXmlHttpObject(stateChangeHandler);
52
 
53
      //Send the xmlHttp get to the specified url
54
      xmlHttp_Get(xmlHttp, url);
55
  }
6616 dpurdie 56
 
6613 dpurdie 57
  // Update image and attributes
58
  imgel.src = img;
59
  shel.style.display = dmode;
60
  imgel.setAttribute("data-show", showing);
61
}
62
 
119 ghuddy 63
//stateChangeHandler will fire when the state has changed, i.e. data is received back
64
// This is non-blocking (asynchronous)
65
function stateChangeHandler()
66
{
6617 dpurdie 67
    var str;
119 ghuddy 68
    //readyState of 4 or 'complete' represents that data has been returned
69
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){
6617 dpurdie 70
        if ( xmlHttp.status != 200 ) {
71
            // Generate an error message
72
            str = "Ajax Load Error [" + xmlHttp.status + ']: ' + xmlHttp.statusText + '<br>Url:' + xmlHttp.responseURL;
73
        } else {
74
            //Gather the results from the callback
75
            str = xmlHttp.responseText;
76
        }
119 ghuddy 77
 
78
        //Populate the innerHTML of the div with the results
79
		MM_findObj( ajaxdivname ).innerHTML = str;
80
    }
81
}
82
 
83
 
84
//stateComboChangeHandler will fire when the state has changed, i.e. data is received back
85
// This is non-blocking (asynchronous)
86
function stateComboChangeHandler()
87
{
88
	//Expected response data: text|-|value|-|selected|+|text2|-|value2|-|selected2
89
 
90
    //readyState of 4 or 'complete' represents that data has been returned
91
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){
92
        //Gather the results from the callback
93
        var str = xmlHttp.responseText;
94
		var combo = ajaxdivname ;
95
		var lastOption = combo.options.length
96
 
97
        //Remove current Combo options
6613 dpurdie 98
		for (i=0; i<lastOption; i++) {
119 ghuddy 99
			combo.options[0] = null;//The combo box re-organizes itself therefore remove the first element
100
		}
101
 
102
		//Populate combowith new items
103
		var optionArray = str.split('|+|');
104
 
6613 dpurdie 105
		for (i in optionArray) {
119 ghuddy 106
			//alert(optionArray[i]);
107
			var opt = optionArray[i].split('|-|');
108
			combo.options[i] = new Option( opt[0], opt[1], opt[2] );
109
		}
110
    }
111
}
112
 
113
// XMLHttp send GET request
114
function xmlHttp_Get(xmlhttp, url) {
115
    xmlhttp.open('GET', url, true);
116
    xmlhttp.send(null);
117
}
118
 
3959 dpurdie 119
// XMLHttp send GET request but wait for return;
120
function xmlHttp_Get_Synch(xmlhttp, url) {
121
    xmlhttp.open('GET', url, false);
122
    xmlhttp.send(null);
123
}
124
 
119 ghuddy 125
function GetXmlHttpObject(handler) {
126
    var objXmlHttp = null;    //Holds the local xmlHTTP object instance
127
 
3959 dpurdie 128
    if (typeof(handler) != "function") {
129
      alert('Internal: GetXmlHttpObject called without a handler');
130
      return;
131
    }
132
        //Depending on the browser, try to create the xmlHttp object
119 ghuddy 133
    if (is_ie){
134
        //The object to create depends on version of IE
135
        //If it isn't ie5, then default to the Msxml2.XMLHTTP object
136
        var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';
137
 
138
        //Attempt to create the object
139
        try{
140
            objXmlHttp = new ActiveXObject(strObjName);
141
            objXmlHttp.onreadystatechange = handler;
142
        }
143
        catch(e){
144
        //Object creation errored
145
            alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled');
146
            return;
147
        }
148
    }
149
    else if (is_opera){
150
        //Opera has some issues with xmlHttp object functionality
151
        alert('Opera detected. The page may not behave as expected.');
152
        return;
153
    }
154
    else{
155
        // Mozilla | Netscape | Safari
156
        objXmlHttp = new XMLHttpRequest();
157
        objXmlHttp.onload = handler;
158
        objXmlHttp.onerror = handler;
159
    }
160
 
161
    //Return the instantiated object
162
    return objXmlHttp;
163
}
164
 
165
//-->