Subversion Repositories DevTools

Rev

Rev 6617 | 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;
6651 dpurdie 80
 
81
        // Process elements just loaded
82
        if(typeof vixPostPageLoad == 'function'){
83
            vixPostPageLoad(ajaxdivname);
84
        }
119 ghuddy 85
    }
86
}
87
 
88
 
89
//stateComboChangeHandler will fire when the state has changed, i.e. data is received back
90
// This is non-blocking (asynchronous)
91
function stateComboChangeHandler()
92
{
93
	//Expected response data: text|-|value|-|selected|+|text2|-|value2|-|selected2
94
 
95
    //readyState of 4 or 'complete' represents that data has been returned
96
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){
97
        //Gather the results from the callback
98
        var str = xmlHttp.responseText;
99
		var combo = ajaxdivname ;
100
		var lastOption = combo.options.length
101
 
102
        //Remove current Combo options
6613 dpurdie 103
		for (i=0; i<lastOption; i++) {
119 ghuddy 104
			combo.options[0] = null;//The combo box re-organizes itself therefore remove the first element
105
		}
106
 
107
		//Populate combowith new items
108
		var optionArray = str.split('|+|');
109
 
6613 dpurdie 110
		for (i in optionArray) {
119 ghuddy 111
			//alert(optionArray[i]);
112
			var opt = optionArray[i].split('|-|');
113
			combo.options[i] = new Option( opt[0], opt[1], opt[2] );
114
		}
115
    }
116
}
117
 
118
// XMLHttp send GET request
119
function xmlHttp_Get(xmlhttp, url) {
120
    xmlhttp.open('GET', url, true);
121
    xmlhttp.send(null);
122
}
123
 
3959 dpurdie 124
// XMLHttp send GET request but wait for return;
125
function xmlHttp_Get_Synch(xmlhttp, url) {
126
    xmlhttp.open('GET', url, false);
127
    xmlhttp.send(null);
128
}
129
 
119 ghuddy 130
function GetXmlHttpObject(handler) {
131
    var objXmlHttp = null;    //Holds the local xmlHTTP object instance
132
 
3959 dpurdie 133
    if (typeof(handler) != "function") {
134
      alert('Internal: GetXmlHttpObject called without a handler');
135
      return;
136
    }
137
        //Depending on the browser, try to create the xmlHttp object
119 ghuddy 138
    if (is_ie){
139
        //The object to create depends on version of IE
140
        //If it isn't ie5, then default to the Msxml2.XMLHTTP object
141
        var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';
142
 
143
        //Attempt to create the object
144
        try{
145
            objXmlHttp = new ActiveXObject(strObjName);
146
            objXmlHttp.onreadystatechange = handler;
147
        }
148
        catch(e){
149
        //Object creation errored
150
            alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled');
151
            return;
152
        }
153
    }
154
    else if (is_opera){
155
        //Opera has some issues with xmlHttp object functionality
156
        alert('Opera detected. The page may not behave as expected.');
157
        return;
158
    }
159
    else{
160
        // Mozilla | Netscape | Safari
161
        objXmlHttp = new XMLHttpRequest();
162
        objXmlHttp.onload = handler;
163
        objXmlHttp.onerror = handler;
164
    }
165
 
166
    //Return the instantiated object
167
    return objXmlHttp;
168
}
169
 
170
//-->