if( data.value ) {
input.setAttribute( 'value', data.value );
}
input.setAttribute( 'name', data.name );
input.setAttribute( 'type', 'text' );
if( data.size ) {
input.setAttribute( 'size', data.size );
}
if( data.disabled ) {
input.setAttribute( 'disabled', 'disabled' );
}
if( data.readonly ) {
input.setAttribute( 'readonly', 'readonly' );
}
if( data.maxlength ) {
input.setAttribute( 'maxlength', data.maxlength );
}
if( data.event ) {
input.addEventListener( 'keyup', data.event, false );
}
break;
case 'hidden':
var node = document.createElement( 'input' );
node.setAttribute( 'type', 'hidden' );
node.setAttribute( 'value', data.value );
node.setAttribute( 'name', data.name );
break;
case 'header':
node = document.createElement( 'h5' );
node.appendChild( document.createTextNode( data.label ) );
break;
case 'div':
node = document.createElement( 'div' );
break;
case 'submit':
node = document.createElement( 'span' );
childContainder = node.appendChild(document.createElement( 'input' ));
childContainder.setAttribute( 'type', 'submit' );
if( data.label ) {
childContainder.setAttribute( 'value', data.label );
}
childContainder.setAttribute( 'name', data.name || 'submit' );
if( data.disabled ) {
childContainder.setAttribute( 'disabled', 'disabled' );
}
break;
case 'button':
node = document.createElement( 'span' );
childContainder = node.appendChild(document.createElement( 'input' ));
childContainder.setAttribute( 'type', 'button' );
if( data.label ) {
childContainder.setAttribute( 'value', data.label );
}
childContainder.setAttribute( 'name', data.name );
if( data.disabled ) {
childContainder.setAttribute( 'disabled', 'disabled' );
}
if( data.event ) {
childContainder.addEventListener( 'click', data.event, false );
}
break;
case 'textarea':
node = document.createElement( 'div' );
if( data.label ) {
label = node.appendChild( document.createElement( 'label' ) );
label.appendChild( document.createTextNode( data.label ) );
label.setAttribute( 'for', id );
}
node.appendChild( document.createElement( 'br' ) );
textarea = node.appendChild( document.createElement( 'textarea' ) );
textarea.setAttribute( 'name', data.name );
if( data.cols ) {
textarea.setAttribute( 'cols', data.cols );
}
if( data.rows ) {
textarea.setAttribute( 'rows', data.rows );
}
if( data.disabled ) {
textarea.setAttribute( 'disabled', 'disabled' );
}
if( data.readonly ) {
textarea.setAttribute( 'readonly', 'readonly' );
}
break;  
}  
if( childContainder == null ) {
childContainder = node;
}
if( data.tooltip ) {
QuickForm.element.generateTooltip( label || node , data );
}  
if( data.extra ) {
childContainder.extra = extra;
}
childContainder.setAttribute( 'id', data.id || id );  
return [ node, childContainder ];
}  
QuickForm.element.generateTooltip = function QuickFormElementGenerateTooltip( node, data ) {
var tooltipButtonContainer = node.appendChild( document.createElement( 'span' ) );
tooltipButtonContainer.className = 'tooltipButtonContainer';
var tooltipButton = tooltipButtonContainer.appendChild( document.createElement( 'span' ) );
tooltipButton.className = 'tooltipButton';
tooltipButton.appendChild( document.createTextNode( '?' ) );
var tooltip = document.createElement( 'div' );
tooltip.className = 'quickformtooltip';
tooltip.appendChild( document.createTextNode( data.tooltip ) );
tooltipButton.tooltip = tooltip;
tooltipButton.showing = false;
tooltipButton.interval = null;
tooltipButton.addEventListener( 'mouseover', QuickForm.element.generateTooltip.display, false );
tooltipButton.addEventListener( 'mouseout', QuickForm.element.generateTooltip.fade, false );  
}
QuickForm.element.generateTooltip.display = function QuickFormElementGenerateTooltipDisplay(e) {
window.clearInterval( e.target.interval );
e.target.tooltip.style.setProperty( '-moz-opacity', 1, null);
e.target.tooltip.style.setProperty( 'opacity', 1, null);
e.target.tooltip.style. = (e.pageX - e.layerX + 24) + "px";
e.target.tooltip.style.top = (e.pageY - e.layerY + 12) + "px";
document.body.appendChild( e.target.tooltip );
e.target.showing = true;
}  
QuickForm.element.generateTooltip.fade = function QuickFormElementGenerateTooltipFade( e ) {
e.target.opacity = 1.2;
e.target.interval = window.setInterval(function(e){
e.target.tooltip.style.setProperty( '-moz-opacity', e.target.opacity, null);
e.target.tooltip.style.setProperty( 'opacity', e.target.opacity, null);
e.target.opacity -= 0.1;
if( e.target.opacity <= 0 ) {
window.clearInterval( e.target.interval );
document.body.removeChild( e.target.tooltip );e.target.showing = false;
}
},50,e);
}  
/*
- returns an array containing the values of elements with the given name, that has it's
- checked property set to true. (i.e. a checkbox or a radiobutton is checked).
- Type is optional and can specify if either radio or checkbox (for the event
- that both checkboxes and radiobuttons have the same name.
- /
HTMLFormElement.prototype.getChecked = function( name, type ) {
var elements = this.elements[name];
var return_array = [];
for( var i = 0; i < elements.length; ++i ) {
if( elements[i].checked ) {
if( type != null && elements[i].type != type ) {
continue;
}
return_array.push( elements[i].value );
}
}
return return_array;
}  
/*
- returns an array containing the values of elements with the given name, that has non-empty strings
- type is "text" or given.
- /
HTMLFormElement.prototype.getTexts = function( name, type ) {
type == type || 'text';
var elements = this.elements[name];
var return_array = [];
for( var i = 0; i < elements.length; ++i ) {
if( elements[i].type == type && elements[i].value != '' ) {
return_array.push( elements[i].value );
}
}
return return_array;
}
/**
- Will escape a string to be used in a RegExp
- /
RegExp.escape = function( text, space_fix ) {  
if ( !arguments.callee.sRE ) {
arguments.callee.sRE = /(\/|\.|\*|\+|\?|\||\(|\)|\[|\]|\{|\}|\\|\$|\^)/g;
}  
text = text.replace( arguments.callee.sRE , '\\$1' );  
// Special Mediawiki escape, underscore/space is the same, often at lest:  
if( space_fix ) {
text = text.replace( / |_/g, '[_ ]' );
}  
return text;  
}  
// Sprintf implementation based on perl similar
function sprintf {
if( arguments.length == 0 ) {
throw "Not enough arguments for sprintf";
}
var result = "";
var format = arguments[0];  
var index = 1;
var current_index = 1;
var flags = {};
var in_operator = false;
var relative = false;
var precision = false;
var fixed = false;
var vector = false;
var vector_delimiter = '.';  
for( var i = 0; i < format.length; ++i ) {
var current_char = format.charAt(i);
if( in_operator ) {
switch( current_char ) {
case 'i':
current_char = 'd';
break;
case 'F':
current_char = 'f';
break;
case '%':
case 'c':
case 's':
case 'd':
case 'u':
case 'o':
case 'x':
case 'e':
case 'f':
case 'g':
case 'X':
case 'E':
case 'G':
case 'b':
var value = arguments[current_index];
if( vector ) {
r = value.toString.split( '' );
result += value.toString.split('').map( function( value ) {
return sprintf.format( current_char, value.charCodeAt, flags );
}).join( vector_delimiter );
} else {
result += sprintf.format( current_char, value, flags );
}
if( !fixed ) {
++index;
}
current_index = index;
flags = {};
relative = false;
in_operator = false;
precision = false;
fixed = false;
vector = false;
vector_delimiter = '.';
break;
case 'v':
vector = true;
break;
case ' ':
case '0':
case '-':
case '+':
case '#':
flags[current_char] = true;
break;
case '*':
relative = true;
break;
case '.':
precision = true;
break;
}
if( /\d/.test( current_char ) ) {
var num = parseInt( format.substr( i ) );
var len = num.toString.length;
i += len - 1;
var next = format.charAt( i + 1 );
if( next == '$' ) {
if( num <= 0 || num >= arguments.length ) {
throw "out of bound";
}
if( relative ) {
if( precision ) {
flags['precision'] = arguments[num];
precision = false;
} else if( format.charAt( i + 2 ) == 'v' ) {
vector_delimiter = arguments[num];
}else {
flags['width'] = arguments[num];
}
relative = false;
} else {
fixed = true;
current_index = num;
}
++i;