Subversion Repositories DevTools

Rev

Rev 5506 | Rev 6616 | 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;
36
  } else {
37
      img = "images/bt_minus.gif";
38
      dmode = '';
39
      showing = 2;
119 ghuddy 40
 
6613 dpurdie 41
      // Set div name for ajax loading
42
      ajaxdivname = baseId;
119 ghuddy 43
 
6613 dpurdie 44
      //Create the xmlHttp object to use in the request
45
      //stateChangeHandler will fire when the state has changed, i.e. data is received back
46
      // This is non-blocking (asynchronous)
47
      xmlHttp = GetXmlHttpObject(stateChangeHandler);
48
 
49
      //Send the xmlHttp get to the specified url
50
      xmlHttp_Get(xmlHttp, url);
51
  }
52
  // Update image and attributes
53
  imgel.src = img;
54
  shel.style.display = dmode;
55
  imgel.setAttribute("data-show", showing);
56
}
57
 
119 ghuddy 58
//stateChangeHandler will fire when the state has changed, i.e. data is received back
59
// This is non-blocking (asynchronous)
60
function stateChangeHandler()
61
{
62
 
63
    //readyState of 4 or 'complete' represents that data has been returned
64
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){
65
        //Gather the results from the callback
66
        var str = xmlHttp.responseText;
67
 
68
        //Populate the innerHTML of the div with the results
69
		MM_findObj( ajaxdivname ).innerHTML = str;
70
    }
71
}
72
 
73
 
74
//stateComboChangeHandler will fire when the state has changed, i.e. data is received back
75
// This is non-blocking (asynchronous)
76
function stateComboChangeHandler()
77
{
78
	//Expected response data: text|-|value|-|selected|+|text2|-|value2|-|selected2
79
 
80
    //readyState of 4 or 'complete' represents that data has been returned
81
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){
82
        //Gather the results from the callback
83
        var str = xmlHttp.responseText;
84
		var combo = ajaxdivname ;
85
		var lastOption = combo.options.length
86
 
87
        //Remove current Combo options
6613 dpurdie 88
		for (i=0; i<lastOption; i++) {
119 ghuddy 89
			combo.options[0] = null;//The combo box re-organizes itself therefore remove the first element
90
		}
91
 
92
		//Populate combowith new items
93
		var optionArray = str.split('|+|');
94
 
6613 dpurdie 95
		for (i in optionArray) {
119 ghuddy 96
			//alert(optionArray[i]);
97
			var opt = optionArray[i].split('|-|');
98
			combo.options[i] = new Option( opt[0], opt[1], opt[2] );
99
		}
100
    }
101
}
102
 
103
// XMLHttp send GET request
104
function xmlHttp_Get(xmlhttp, url) {
105
    xmlhttp.open('GET', url, true);
106
    xmlhttp.send(null);
107
}
108
 
3959 dpurdie 109
// XMLHttp send GET request but wait for return;
110
function xmlHttp_Get_Synch(xmlhttp, url) {
111
    xmlhttp.open('GET', url, false);
112
    xmlhttp.send(null);
113
}
114
 
119 ghuddy 115
function GetXmlHttpObject(handler) {
116
    var objXmlHttp = null;    //Holds the local xmlHTTP object instance
117
 
3959 dpurdie 118
    if (typeof(handler) != "function") {
119
      alert('Internal: GetXmlHttpObject called without a handler');
120
      return;
121
    }
122
        //Depending on the browser, try to create the xmlHttp object
119 ghuddy 123
    if (is_ie){
124
        //The object to create depends on version of IE
125
        //If it isn't ie5, then default to the Msxml2.XMLHTTP object
126
        var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';
127
 
128
        //Attempt to create the object
129
        try{
130
            objXmlHttp = new ActiveXObject(strObjName);
131
            objXmlHttp.onreadystatechange = handler;
132
        }
133
        catch(e){
134
        //Object creation errored
135
            alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled');
136
            return;
137
        }
138
    }
139
    else if (is_opera){
140
        //Opera has some issues with xmlHttp object functionality
141
        alert('Opera detected. The page may not behave as expected.');
142
        return;
143
    }
144
    else{
145
        // Mozilla | Netscape | Safari
146
        objXmlHttp = new XMLHttpRequest();
147
        objXmlHttp.onload = handler;
148
        objXmlHttp.onerror = handler;
149
    }
150
 
151
    //Return the instantiated object
152
    return objXmlHttp;
153
}
154
 
155
//-->