//=========================================================================== // script/Doc__js.php //=========================================================================== /**/ //add chkBackspace() to keydown event. //........................................................................... if( typeof document.addEventListener != "undefined" ) { document.addEventListener( "keydown", chkBackspace, false ); } else { if( typeof document.attachEvent != "undefined" ) { document.attachEvent( "onkeydown", chkBackspace ); } else { if( document.onkeydown != null ) { var prv = document.onkeydown; document.onkeydown = function( e ) { prv( e ); chkBackspace( e ); } } else { document.onkeydown = chkBackspace; } } } //=========================================================================== /** Supress backspace browser default. */ function chkBackspace( e ) /* Called by all keydown actions. */ { e = ( e ) ? e : window.event; var t = ( e.target ) ? e.target : ( e.srcElement ) ? e.srcElement : null; if( t && t.tagName && ( t.type && /(password)|(text)|(file)/.test(t.type.toLowerCase()) && t.readOnly == false ) || t.tagName.toLowerCase() == "textarea" && t.readOnly == false ) { return true; } //allow. var k = ( e.keyCode ) ? e.keyCode : ( e.which ) ? e.which : null; if( k == 8 ) { if( e.preventDefault ) { e.preventDefault(); } return false; //supress. } return true; //allow. } //=========================================================================== /** * UTF-8 encodes special characters for URL argument. Returns empty string * when given NULL. */ function encodeURL( arg ) /* Known Issue: converts "*" to "**". */ { if( typeof( arg ) !== "string" && arg !== null ) { throw new TypeError( "Invalid Parameter" ); } if( arg !== null ) { arg = arg.replace( new RegExp( "\#", "g" ), "%23" ); arg = arg.replace( new RegExp( "\&", "g" ), "%26" ); arg = arg.replace( new RegExp( "\\+", "g" ), "%2B" ); arg = arg.replace( new RegExp( "\\?", "g" ), "%3F" ); } return ( arg !== null ) ? arg : ""; } //=========================================================================== /** Returns value of given argument in given URL. */ function getArg( url, arg ) /**/ { arg += "="; var val = null; start = url.indexOf( arg ); if( url.indexOf( arg ) == -1 ) { url += "&" +arg +val; } else { start = url.indexOf( arg ) +arg.length; stop = url.indexOf( "&", start ); if( stop == -1 ) { stop = url.length; } val = url.substring( start, stop ); } return val; } //=========================================================================== /** Replaces URL argument value and returns modified URL. */ function rplArg( url, arg, val ) /**/ { arg += "="; start = url.indexOf( arg ); if( url.indexOf( arg ) == -1 ) { url += "&" +arg +val; } else { start = url.indexOf( arg ) +arg.length; stop = url.indexOf( "&", start ); if( stop == -1 ) { stop = url.length; } url = url.replace ( new RegExp( arg +url.substring( start, stop ), "i" ) , arg +val ); } return url; } //=========================================================================== /** * Reformats form-data array into seperated string and prevents array submit. * Default seperation: "," (comma). */ function arrToStr( form, arrayName, seperator ) /* Called by other functions. */ { var str = ""; if ( seperator == null || seperator == "" ) { seperator = ","; } for (var i=0; i < form.elements.length; i++) { if ( form.elements[i].name == arrayName +"[]" && form.elements[i].checked ) { if ( str != "" ) { str = str + seperator; } str = str + form.elements[i].value; form.elements[i].checked = false; //removes variable from submit. } } return str; } //=========================================================================== /** Checks for any selected checkboxes in from. */ function hasSelected( form ) /* Called by other functions. */ { var is = false; for (var i=0; i < form.elements.length; i++) { if ( form.elements[i].type == "checkbox" ) { if ( form.elements[i].checked ) { is = true; } } } return is; } //=========================================================================== /** Toggels all form checkboxes. */ function toggelAll( form ) /* Called by check-all control in studentList. */ { for (var i=0; i < form.elements.length; i++) { if ( form.elements[i].type == "checkbox" ) { if ( ! form.elements[i].checked ) { form.elements[i].checked = true; } else { form.elements[i].checked = false; } } } } //=========================================================================== /** Fires cross-browser-compatible onclick-event from given element. */ function fireOnclick( element, isIE ) /* Called by other functions. */ { if( isIE ) { element.fireEvent( "onclick" ); } //submit. else { var tEvent = window.document.createEvent( "MouseEvent" ); tEvent.initEvent( "click", false, true ); element.dispatchEvent( tEvent ); } } //=========================================================================== /** ... */ function addOption( element, text, value ) /**/ { t = document.createElement( "OPTION" ); t.text = text; t.value = value; element.options.add( t ); } //=========================================================================== /** ... */ function selOption( element, value ) /**/ { r = false; for(i=1; i < element.options.length; i++) { if( element.options[i].value == value ) { element.selectedIndex = i; r = true; break; } }return r; } //=========================================================================== /** ... */ function clrOption( element )/**/ { for(var i=element.options.length-1; i >= 0; i--) { element.remove( i ); } } //=========================================================================== /** Trims whitespace from beginning and ending of string. */ String.prototype.trim = function()/**/ { return this.replace( /^\s+|\s+$/g, "" ); } //=========================================================================== //=========================================================================== // END script/Doc__js.php //=========================================================================== //=========================================================================== // script/Form__js.php //=========================================================================== /**/ //=========================================================================== // Form (abstract class) //=========================================================================== /** Constructor -- UI behavior. */ function Form( id ) { /* FireFox Bug: .focus() non-functioning. */ this.UNA = "Unknown event: "; //action error. this.UNS = "Unknown id: "; //source error. this.isIE = false; //event flag. this.form = document.getElementById( id ); this.parent = this; //inherited reference. //=========================================================================== /** Performs execution. Calls action-event methods. */ Form.prototype.run = function( event, data ) /**/ { var r = true; var action; var source; if( window.event ) { event = window.event; this.isIE = true; } if( this.isIE ) { action = event.type; source = ( event.srcElement != null ) ? event.srcElement.id : null; } else if( event ) { action = event.type; source = ( event.target != null ) ? event.target.id : null; } switch ( action ) { case "load": r = this.onLoad( source, data ); break; case "focus": r = this.onFocus( source, data ); break; case "blur": r = this.onBlur( source, data ); break; case "click": r = this.onClick( source, data ); break; case "change": r = this.onChange( source, data ); break; case "keypress": var key = ( this.isIE ) ? event.keyCode : event.which; r = this.onKeypress( source, data, key ); break; default: alert( this.UNA+action ); //alert! } return r; } //=========================================================================== /** OnLoad action-event. */ Form.prototype.onLoad = function( source, data )/**/ { return true; } //do-nothing. //=========================================================================== /** OnFocus action-event. */ Form.prototype.onFocus = function( source, data ) /**/ { var r = true; switch( source ) { //case this.???.id: break; default: alert( this.UNS+source ); //alert! } return r; } //=========================================================================== /** OnFocus action-event. */ Form.prototype.onBlur = function( source, data ) /**/ { var r = true; switch( source ) { //case this.???.id: break; default: alert( this.UNS+source ); //alert! } return r; } //=========================================================================== /** OnClick action-event. */ Form.prototype.onClick = function( source, data ) /**/ { var r = true; switch( source ) { //case this.???.id: break; default: alert( this.UNS+source ); //alert! } return r; } //=========================================================================== /** OnChange action-event. */ Form.prototype.onChange = function( source, data ) /**/ { var r = true; switch( source ) { //case this.???.id: break; default: alert( this.UNS+source ); //alert! } return r; } //=========================================================================== /** OnKeypress action-event. */ Form.prototype.onKeypress = function( source, data, key ) /**/ { var r = true; switch( key ) { case 13: r = this.keyEnter( source, data ); break; //enter-key. default: //do-nothing. } return r; } //=========================================================================== /** Enter-key event. */ Form.prototype.keyEnter = function( source, data ) /**/ { var r = false; //FALSE suppresses form-auto-submit. switch( source ) { //case this.???.id: break; default: alert( this.UNS+source ); //alert! } return r; } //=========================================================================== } // END Form //=========================================================================== //=========================================================================== // DateGroup //=========================================================================== /** ... */ function DateGroup() { /* defines methods only. */ this.parent = this; //inherited reference. //=========================================================================== /** ... */ DateGroup.prototype.init = function( cur, y, m, d ) /**/ { this.MONTH = new Array ( "Jan", "Feb", "Mar", "Apr", "May", "Jun" , "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ); this.cur = ( cur ) ? cur : null; this.y = ( y ) ? document.getElementById( y ) : null; this.m = ( m ) ? document.getElementById( m ) : null; this.d = ( d ) ? document.getElementById( d ) : null; this.setMin(); this.setMax(); this.setSel(); if( ! this.sel ) { this.setY(); this.setM(); this.setD(); } } //=========================================================================== /** ... */ DateGroup.prototype.isSel = function()/**/ { return ( this.hasY() && this.hasM() && this.hasD() ) ? true : false; } //=========================================================================== /** ... */ DateGroup.prototype.hasY = function()/**/ { return ( this.y.selectedIndex > 0 ) ? true : false; } //=========================================================================== /** ... */ DateGroup.prototype.getY = function( i )/**/ { return ( i != undefined ) ? this.y.options[i].value : this.y.value; } //=========================================================================== /** ... */ DateGroup.prototype.hasM = function()/**/ { return ( this.m.selectedIndex > 0 ) ? true : false; } //=========================================================================== /** ... */ DateGroup.prototype.getM = function( i )/**/ { return ( i != undefined ) ? this.m.options[i].value -1 : this.m.value -1; } //=========================================================================== /** ... */ DateGroup.prototype.hasD = function()/**/ { return ( this.d.selectedIndex > 0 ) ? true : false; } //=========================================================================== /** ... */ DateGroup.prototype.getD = function( i )/**/ { return ( i != undefined ) ? this.d.options[i].value : this.d.value; } //=========================================================================== /** ... */ DateGroup.prototype.setSel = function() /**/ { if( this.isSel() ) { //set one month ahead then set to last day of preceeding month. last = new Date( this.getY(), this.getM() +1, 0 ); this.sel = ( this.getD() > last.getDate() ) ? new Date( this.getY(), this.getM(), 1 ) //prevents day overflow. : new Date( this.getY(), this.getM(), this.getD() ); }else { this.sel = null; } } //=========================================================================== /** ... */ DateGroup.prototype.setMin = function()/**/ { this.min = ( this.cur ) ? new Date( this.cur.getFullYear() , this.cur.getMonth(), this.cur.getDate() ) : null; } //=========================================================================== /** ... */ DateGroup.prototype.setMax = function() /**/ { if( this.min ) { //set one month ahead then set to last day of preceeding month. last = new Date( this.min.getFullYear() +1, this.min.getMonth() +1, 0 ); this.max = ( this.min.getDate() > last.getDate() ) //handles day overflow. ? new Date( this.min.getFullYear() +1, this.min.getMonth() +1 , this.min.getDate() ) : new Date( this.min.getFullYear() +1, this.min.getMonth() , this.min.getDate() ); }else { this.max = null; } } //=========================================================================== /** ... */ DateGroup.prototype.edit = function( src ) /**/ { i = -1; switch( src ) { case this.y.id: i = this.y.selectedIndex; break; case this.m.id: i = this.m.selectedIndex; break; case this.d.id: i = this.d.selectedIndex; break; } if( i < 1 ) { this.clear( this.d ); this.d.selectedIndex = 0; this.m.selectedIndex = 0; this.y.selectedIndex = 0; } else { if( ! this.hasY() ) { this.y.selectedIndex++; } if( ! this.hasM() ) { this.m.selectedIndex++; } if( src != this.d.id ) { this.setD(); } if( ! this.hasD() ) { this.d.selectedIndex++; } //selected date. this.setSel(); //verify date. this.chk( src ); } } //=========================================================================== /** ... */ DateGroup.prototype.chk = function( src ) /**/ { //below minimum. if( this.sel.getTime() < this.min.getTime() ) { switch( src ) { //year. case this.y.id: if( this.sel.getMonth() == this.min.getMonth() ) { //edit day. selOption( this.d, this.min.getDate() ); this.edit( this.d.id ); } else { //edit month. selOption( this.m, this.min.getMonth() + 1 ); this.edit( this.m.id ); } break; //month. case this.m.id: if( this.sel.getMonth() == this.min.getMonth() ) { //edit year. if( selOption( this.y, this.min.getFullYear() +1 ) ) { this.edit( this.y.id ); } else { //edit day. selOption( this.d, this.min.getDate() ); this.edit( this.d.id ); } } else { //edit year. if( selOption( this.y, this.min.getFullYear() +1 ) ) { this.edit( this.y.id ); } else { //edit month. selOption( this.m, this.min.getMonth() + 1 ); this.edit( this.m.id ); } } break; default: //do-nothing. } } //above maximum. if( this.sel.getTime() > this.max.getTime() ) { switch( src ) { //year. case this.y.id: if( this.sel.getMonth() == this.max.getMonth() ) { //edit day. selOption( this.d, this.max.getDate() ); this.edit( this.d.id ); } else { //edit month. selOption( this.m, this.max.getMonth() + 1 ); this.edit( this.m.id ); } break; //month. case this.m.id: if( this.sel.getMonth() == this.max.getMonth() ) { //edit year. if( selOption( this.y, this.max.getFullYear() -1 ) ) { this.edit( this.y.id ); } else { //edit day. selOption( this.d, this.max.getDate() ); this.edit( this.d.id ); } } else { //edit year. if( selOption( this.y, this.max.getFullYear() -1 ) ) { this.edit( this.y.id ); } else { //edit month. selOption( this.m, this.max.getMonth() + 1 ); this.edit( this.m.id ); } } break; default: //do-nothing. } } } //=========================================================================== /** ... */ DateGroup.prototype.setY = function() /**/ { prv = this.getY(); this.clear( this.y ); if( this.min && this.max ) { for(i=this.min.getFullYear(); i <= this.max.getFullYear(); i++) { addOption( this.y, i, i ); } } //select year. if( this.sel ) { selOption( this.y, this.sel.getFullYear() ); } else { selOption( this.y, prv ); } } //=========================================================================== /** ... */ DateGroup.prototype.setM = function() /**/ { prv = this.getM()+1; this.clear( this.m ); if( this.min ) { for(i=0; i < this.MONTH.length; i++) { addOption( this.m, this.MONTH[i], i+1 ); } } //select month. if( this.sel ) { selOption( this.m, this.sel.getMonth() +1 ); } else { selOption( this.m, prv ); } } //=========================================================================== /** ... */ DateGroup.prototype.setD = function() /**/ { prv = this.getD(); this.clear( this.d ); if( this.min && this.hasY() && this.hasM() ) { first = ( this.getY() == this.min.getFullYear() && this.getM() == this.min.getMonth() ) ? this.min.getDate() //minimum day. : 1; //set one month ahead then set to last day of preceeding month. last = new Date( this.getY(), this.getM() +1, 0 ); limit = ( this.getY() == this.max.getFullYear() && this.getM() == this.max.getMonth() ) ? this.max.getDate() : last.getDate(); for(i=first; i <= limit; i++) { addOption( this.d, i, i ); } } //select day. if( this.sel ) { selOption( this.d, this.sel.getDate() ); } else { selOption( this.d, prv ); } } //=========================================================================== /** ... */ DateGroup.prototype.clear = function( element )/**/ { for(var i=element.options.length-1; i > 0; i--) { element.remove( i ); } } //=========================================================================== } // END DateGroup //=========================================================================== //=========================================================================== // END script/Form__js.php //=========================================================================== //=========================================================================== // script/Nav__js.php //=========================================================================== /**/ //=========================================================================== /** Receives selector id, desired state (true/false), & toggles indicator. */ function navSelect( id, state ) /* offset background-image is visible/invisible by toggling repeat value. */ { var x = document.getElementById( id ); if( state ) { x.style.backgroundRepeat = "repeat-x"; } else { x.style.backgroundRepeat = "no-repeat"; } } //=========================================================================== // END script/Nav__js.php //===========================================================================