3
* Returns the value of the selected option in the list with the given identifier.
5
* @param listId the list identifier.
7
function getListValue( listId )
9
var list = document.getElementById( listId );
10
var value = list.options[ list.selectedIndex ].value;
16
* Hides the document element with the given identifier.
18
* @param elementId the element identifier.
20
function hideById( elementId )
22
document.getElementById( elementId ).style.display = "none";
26
* Shows the document element with the given identifier.
28
* @param elementId the element identifier.
30
function showById( elementId )
32
document.getElementById( elementId ).style.display = "block";
36
* Returns true if the element with the given identifier has text, false if not.
38
* @param inputId the identifier of the input element.
40
function hasText( inputId )
42
return document.getElementById( inputId ).value != "";
46
* Returns true if the element with the given identifier is checked, false if not
47
* or if it does not exist.
49
* @param checkboxId the identifier of the checkbox element.
51
function isChecked( checkboxId )
53
var checkBox = document.getElementById( checkboxId );
57
return checkBox.checked;
64
* Checks the checkbox with the given identifier if the checkbox exists.
66
function check( checkBoxId )
68
var checkBox = document.getElementById( checkBoxId );
72
checkBox.checked = true;
77
* Unchecks the checkbox with the given identifier if the checkbox exists.
79
function uncheck( checkBoxId )
81
var checkBox = document.getElementById( checkBoxId );
85
checkBox.checked = false;
90
* Enables the element with the given identifier if the element exists.
92
function enable( elementId )
94
var element = document.getElementById( elementId );
98
element.disabled = false;
103
* Disables the element with the given identifier if the element exists.
105
function disable( elementId )
107
var element = document.getElementById( elementId );
111
element.disabled = true;
116
* Returns true if the element with the given identifier has selected elements
117
* associated with it, false if not.
119
* @param listId the identifier of the list element.
121
function hasElements( listId )
123
return document.getElementById( listId ).options.length > 0;
127
* Returns true if the element with the given identifier exists, false if not.
129
* @param elementId the identifier of the element.
131
function isNotNull( elementId )
133
return document.getElementById( elementId ) != null ? true : false;
137
* HTML encodes the given string.
139
* @param str the input string.
140
* @return the HTML encoded string.
142
function htmlEncode( str )
144
str = str.replace( /\ /g, "%20" );
145
str = str.replace( /\!/g, "%21" );
146
str = str.replace( /\"/g, "%22" );
147
str = str.replace( /\#/g, "%23" );
148
str = str.replace( /\$/g, "%24" );
149
str = str.replace( /\&/g, "%26" );
150
str = str.replace( /\'/g, "%27" );
151
str = str.replace( /\(/g, "%28" );
152
str = str.replace( /\)/g, "%29" );
153
str = str.replace( /\*/g, "%2a" );
154
str = str.replace( /\+/g, "%2b" );
155
str = str.replace( /\,/g, "%2c" );
156
str = str.replace( /\-/g, "%2d" );
157
str = str.replace( /\./g, "%2e" );
158
str = str.replace( /\//g, "%2f" );
159
str = str.replace( /\:/g, "%3a" );
160
str = str.replace( /\;/g, "%3b" );
161
str = str.replace( /\</g, "%3c" );
162
str = str.replace( /\=/g, "%3d" );
163
str = str.replace( /\>/g, "%3e" );
164
str = str.replace( /\?/g, "%3f" );
165
str = str.replace( /\@/g, "%40" );
171
* Gets the value for the element with the given name from the DOM object.
173
* @param parentElement the DOM object.
174
* @param childElementName the name of the element.
176
function getElementValue( parentElement, childElementName )
178
var textNode = parentElement.getElementsByTagName( childElementName )[0].firstChild;
180
return textNode ? textNode.nodeValue : null;
184
* Gets the value from the given DOM element.
186
* @param rootElement the DOM object.
188
function getRootElementValue( rootElement )
190
var textNode = rootElement.firstChild;
192
return textNode ? textNode.nodeValue : null;
196
* Gets the value of the attribute with the given name from the given DOM element.
198
* @param rootElement the DOM object.
199
* @param attributeName the name of the attribute.
201
function getRootElementAttribute( rootElement, attributeName )
203
return rootElement.getAttribute( attributeName );
207
* Sets a value on the given element.
209
* @param fieldId the identifier of the element.
210
* @param value the value to set.
212
function setFieldValue( fieldId, value )
214
document.getElementById( fieldId ).innerHTML = value;
218
* Gets a value from the given element.
220
* @param fieldId the identifier of the element.
221
* @return a value corresponding to the given identifier.
223
function getFieldValue( fieldId )
225
return document.getElementById( fieldId ).value;
229
* Sets a message in the "message" span and makes the span visible.
231
* @param message the message.
233
function setMessage( message )
235
document.getElementById( 'message' ).innerHTML = message;
236
document.getElementById( 'message' ).style.display = 'block';
240
* Makes the "message" span invisible.
242
function hideMessage()
244
document.getElementById( 'message' ).style.display = 'none';
247
function setInfo( message )
249
document.getElementById( 'info' ).innerHTML = message;
250
document.getElementById( 'info' ).style.display = 'block';
255
document.getElementById( 'info' ).style.display = 'block';
259
* Makes the "detailsArea" span visible.
261
function showDetails()
263
$( '#detailsArea' ).show( "fast" ); //jquery specific
265
//document.getElementById( 'detailsArea' ).style.display = 'block';
269
* Makes the "detailsArea" span invisible.
271
function hideDetails()
273
$( '#detailsArea' ).hide( "fast" ); //jquery specific
275
//document.getElementById( 'detailsArea' ).style.display = 'none';
279
* Makes the "warningArea" span visible.
281
function showWarning()
283
$( '#warningArea' ).show( "fast" ); //jquery specific
285
//document.getElementById( 'warningArea' ).style.display = 'block';
289
* Makes the "warningArea" span invisible.
291
function hideWarning()
293
$( '#warningArea' ).hide( "fast" ); //jquery specific
295
//document.getElementById( 'warningArea' ).style.display = 'none';
299
* Convenience method for getting a document element.
301
* @param id id of the element to get.
303
function byId( elementId )
305
return document.getElementById( elementId );
309
* Toggles visibility for an element.
311
* @param id the identifier of the element.
312
* @param display boolean indicator.
314
function toggleByIdAndFlag( id, display )
316
var node = byId( id );
323
node.style.display = ( display ? 'block' : 'none' );
327
* Toggles visibility for an element.
329
* @param id the identifier of the element.
331
function toggleById( id )
333
var node = byId( id );
340
var display = node.style.display;
342
node.style.display = ( display == 'none' || display == '' ? 'block' : 'none' );
346
* Show div at center of screen.
348
function showDivCenter( id )
350
var div = document.getElementById(id);
352
var width = div.style.width;
353
var height = div.style.height;
355
var x = (document.documentElement.clientHeight / 2) - new Number(height.replace('px',''))/2;
356
var y = (document.documentElement.clientWidth / 2) - new Number(width.replace('px',''))/2;
358
div.style.display = 'block';
359
div.style.top = x +"px";
360
div.style.left = y +"px";
364
* Toggles visibility of document element.
366
function showHideDiv( elementId )
368
if ( document.getElementById( elementId ).style.display == "none" )
370
document.getElementById( elementId ).style.display = "block";
374
document.getElementById( elementId ).style.display = "none";
379
* Adds a div with 50 % opacity on the document.
381
function showDivEffect()
383
var width = document.documentElement.clientWidth;
384
var height = document.documentElement.clientHeight;
385
var divEffect = document.createElement( 'div' );
387
divEffect.id = "divEffect";
388
divEffect.style.position = "fixed";
389
divEffect.style.top = 0;
390
divEffect.style.width = width + "px";
391
divEffect.style.height = height + "px";
392
divEffect.style.background = "#000000";
393
divEffect.style.opacity = 0.5;
395
document.body.appendChild( divEffect );
399
* Removes the opacity div from the document.
401
function deleteDivEffect()
403
var divEffect = document.getElementById( 'divEffect' );
405
document.body.removeChild(divEffect);
409
* Returns a query string with all selected element values in the select with
410
* the specified identifier.
412
function getParamString( elementId )
414
var list = document.getElementById( elementId );
418
for ( var i = 0; i < list.options.length; i++ )
420
params += elementId + "=" + list.options[i].value + "&";
427
* Creates an option and adds it to the list.
429
* @param list the list.
430
* @param optionValue the option value.
431
* @param optionText the option text.
433
function addOptionToList( list, optionValue, optionText )
435
var option = document.createElement( "option" );
436
option.value = optionValue;
437
option.text = optionText;
438
list.add( option, null );