// Source:en.wikipedia.org/wiki/User:AzaToth/morebits.js
// but as it is at the moment the only required file for all modules
// of twinkle, it's here.
// Shold perhaps be moved into a "twinklebase.js" file.
var twinkleConfigExists = false;  
if( userIsInGroup( 'sysop' ) || twUserIsWhitelisted ) {
twinkleConfigExists = true;
}
function twUserIsWhitelisted {
return userIsInGroup( 'autoconfirmed' );
}  
Cookies = {
/*
- Creates an cookie with the name and value pair. expiry is optional or null and defaults
- to browser standard (in seconds), path is optional and defaults to "/"
- throws error if the cookie already exists.
- /
create: function( name, value, max_age, path ) {
if( Cookies.exists( name ) ) {
throw "cookie " + name + " already exists";
}
Cookies.set( name, value, max_age, path );
},
/*
- Sets an cookie with the name and value pair, overwrites any previous cookie of that name.
- expiry is optional or null and defaults to browser standard (in seconds),
- path is optional and defaults to /
- /
set: function( name, value, max_age, path ) {
var cookie = name + "=" + encodeURIComponent( value );
if( max_age ) {
cookie += "; max-age=" + max_age;
}
cookie += "; path=" + path || "/";
document.cookie = cookie;
},
/*
- Retuns the cookie with the name "name", return null if no cookie found.
- /
read: function( name ) {
var cookies = document.cookie.split(";");
for( var i = 0; i < cookies.length; ++i ) {
var current = cookies[i];
current = current.trim;
if( current.indexOf( name + "=" ) == 0 ) {
return decodeURIComponent( current.substring( name.length + 1 ) );
}
}
return null;
},
/*
- Returns true if a cookie exists, false otherwise
- /
exists: function( name ) {
var re = new RegExp( ";\\s*" + name + "=" );
return re.test( document.cookie );
},
/*
- Deletes the cookie named "name"
- /
remove: function( name ) {
Cookies.set( name, '', -1 );
}
}  
/**
- Quickform is a class for creation of simple and standard forms without much
- specific coding.
- /  
QuickForm = function QuickForm( event, eventType ) {  
this.root = new QuickForm.element( { type: 'form', event: event, eventType:eventType } );  
var cssNode = document.createElement('style');
cssNode.type = 'text/css';
cssNode.rel = 'stylesheet';
cssNode.appendChild( document.createTextNode("")); // Safari bugfix
document.getElementsByTagName("head")[0].appendChild(cssNode);
var styles = cssNode.sheet ? cssNode.sheet : cssNode.stylesSheet;
styles.insertRule("form.quickform { width: 96%; margin:auto; padding: .5em; vertical-align: middle}", 0);
styles.insertRule("form.quickform * { font-family: sans-serif; vertical-align: middle}", 0);
styles.insertRule("form.quickform select { width: 30em; : solid gray; font-size: 1.1em}", 0);
styles.insertRule("form.quickform h5 { -top: solid gray;}", 0);
styles.insertRule("form.quickform textarea { width: 100%; height: 6em }", 0);
styles.insertRule("form.quickform .tooltipButtonContainer { position: relative; width: 100%; }", 0);
styles.insertRule("form.quickform .tooltipButton { padding: .2em; color: blue; font-weight: bold; cursor:help;}", 0);
styles.insertRule(".quickformtooltip { z-index: 200; position: absolute; padding: .1em; : dotted red; background-color: Linen; font: caption; font-size: 10pt; max-width: }", 0);
}  
QuickForm.prototype.render = function QuickFormRender {
return this.root.render;
}
QuickForm.prototype.append = function QuickFormAppend( data ) {
return this.root.append( data );
}  
QuickForm.element = function QuickFormElement( data ) {
this.data = data;
this.childs = [];
this.id = QuickForm.element.id++;
}  
QuickForm.element.id = 0;  
QuickForm.element.prototype.append = function QuickFormElementAppend( data ) {
if( data instanceof QuickForm.element ) {
var child = data;
} else {
var child = new QuickForm.element( data );
}
this.childs.push( child );
return child;
}  
QuickForm.element.prototype.render = function QuickFormElementRender {
var currentNode = this.compute( this.data );  
for( var i = 0; i < this.childs.length; ++i ) {
currentNode[1].appendChild( this.childs[i].render );
}
return currentNode[0];
}  
QuickForm.element.prototype.compute = function QuickFormElementCompute( data ) {
var node;
var childContainder = null;
var label;
var id = 'node_' + this.id;
if( data.adminonly && !userIsInGroup( 'sysop' ) ) {
// hell hack alpha
data.type = hidden;
}
switch( data.type ) {
case 'form':
node = document.createElement( 'form' );
node.setAttribute( 'name', 'id' );
node.className = "quickform";
node.setAttribute( 'action', 'javascript:void(0);');
if( data.event ) {
node.addEventListener( data.eventType || 'submit', data.event , false );
}
break;
case 'select':
node = document.createElement( 'div' );  
node.setAttribute( 'id', 'div_' + id );
if( data.label ) {
label = node.appendChild( document.createElement( 'label' ) );
label.setAttribute( 'for', id );
label.appendChild( document.createTextNode( data.label ) );
}
var select = node.appendChild( document.createElement( 'select' ) );
if( data.event ) {
select.addEventListener( 'change', data.event, false );
}
if( data.multiple ) {
select.setAttribute( 'multiple', 'multiple' );
}
if( data.size ) {
select.setAttribute( 'size', data.size );
}
select.setAttribute( 'name', data.name );  
if( data.list ) {
for( var i = 0; i < data.list.length; ++i ) {  
var current = data.list[i];  
if( current.list ) {
current.type = 'optgroup';
} else {
current.type = 'option';
}  
var res = this.compute( current );
select.appendChild( res[0] );
}
}
childContainder = select;
break;
case 'option':
node = document.createElement( 'option' );
node.setAttribute( 'value', data.value );
if( data.selected ) {
node.setAttribute( 'selected', 'selected' );
}
if( data.disabled ) {
node.setAttribute( 'disabled', 'disabled' );
}
node.setAttribute( 'label', data.label );
node.appendChild( document.createTextNode( data.label ) );
break;
case 'optgroup':
node = document.createElement( 'optgroup' );
node.setAttribute( 'label', data.label );  
if( data.list ) {
for( var i = 0; i < data.list.length; ++i ) {  
var current = data.list[i];  
current.type = 'option'; //must be options here  
var res = this.compute( current );
node.appendChild( res[0] );
}
}
break;
case 'field':
node = document.createElement( 'fieldset' );
label = node.appendChild( document.createElement( 'legend' ) );
label.appendChild( document.createTextNode( data.label ) );
if( data.name ) {
node.setAttribute( 'name', data.name );
}
break;
case 'checkbox':
case 'radio':
node = document.createElement( 'div' );
if( data.list ) {
for( var i = 0; i < data.list.length; ++i ) {
var cur_id = id + '_' + i;
var current = data.list[i];
cur_node = node.appendChild( document.createElement( 'div' ) );
var input = cur_node.appendChild( document.createElement( 'input' ) );
input.setAttribute( 'value', current.value );
input.setAttribute( 'name', current.name || data.name );
input.setAttribute( 'type', data.type );
input.setAttribute( 'id', cur_id );
if( current.checked ) {
input.setAttribute( 'checked', 'checked' );
}
if( current.disabled ) {
input.setAttribute( 'disabled', 'disabled' );
}
if( data.event ) {
input.addEventListener( 'change', data.event, false );
} else if ( current.event ) {
input.addEventListener( 'change', current.event, true );
}
var label = cur_node.appendChild( document.createElement( 'label' ) );
label.appendChild( document.createTextNode( current.label ) );
label.setAttribute( 'for', cur_id );
if( current.tooltip ) {
QuickForm.element.generateTooltip( label, current );
}
}
}
break;
case 'input':
node = document.createElement( 'div' );  
if( data.label ) {
label = node.appendChild( document.createElement( 'label' ) );
label.appendChild( document.createTextNode( data.label ) );
label.setAttribute( 'for', id );
}  
var input = node.appendChild( document.createElement( 'input' ) );
if( data.value ) {
input.setAttribute( 'value', data.value );
}
input.setAttribute( 'name', data.name );
input.setAttribute( 'type', 'text' );
if( data.size ) {