(function() {	// strings

	// What Browser is That ?
	//~ var isIE = document.all;
	var isNS6 = document.getElementById && !document.all;
	var isOpera = navigator.userAgent.indexOf('Opera') > -1;
	var isIE = navigator.userAgent.indexOf('MSIE') > 1 && !isOpera;
	var isIE7 = (isIE && document.all && !window.opera && window.XMLHttpRequest) ? true : false;
	var isMoz = navigator.userAgent.indexOf('Mozilla/5.') == 0 && !isOpera;
	var isFireFox = navigator.userAgent.indexOf('Firefox') > -1;
	var isChrome = navigator.userAgent.indexOf('Chrome') > -1;
	var isSafari = navigator.userAgent.indexOf('Safari') > -1;
	var isIPhone = navigator.userAgent.toLowerCase().indexOf('iphone') > -1;
	var isIPad = navigator.userAgent.toLowerCase().indexOf('ipad') > -1;
	var arrayDaysOfWeek = Array( 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' );
	//~ alert( navigator.userAgent.toLowerCase());

	var navto = function( sUrl ){window.location=sUrl;}

	var StopPropagation = function ( evt ) {

		evt = (evt) ? evt : ((window.event) ? window.event : '');

		if (evt) {
			if ( evt.preventDefault ) evt.preventDefault();
			if (isIE) {
				evt.cancelBubble = true;
				evt.returnValue = false;
			}
			if( evt.stopPropagation ) evt.stopPropagation();
		}
	}

	var DocumentBody = function() {
		return ( (document.compatMode && document.compatMode!="BackCompat" )
			? document.documentElement
			: document.body );
	}

	var ApplyHTMLAttributes = function( el, j ) {

		if ( j ) {

			if ( j.id ) el.id = j.id;

			if ( j.title ) el.title = j.title;
			if ( j.className ) el.className = j.className;
			if ( j.alt ) el.alt = j.alt;
			if ( j.src ) el.src = j.src;
			if ( j.innerHTML ) el.innerHTML = j.innerHTML;
			if ( j.href ) el.href = j.href;

			if ( j.textAlign ) el.style.textAlign = j.textAlign;
			if ( j.verticalAlign ) el.style.verticalAlign = j.verticalAlign;
			if ( j.color ) el.style.color = j.color;
			if ( j.backgroundColor ) el.style.backgroundColor = j.backgroundColor;
			if ( j.fontSize ) el.style.fontSize = j.fontSize;
			if ( j.fontStyle ) el.style.fontStyle = j.fontStyle;
			if ( j.fontWeight ) el.style.fontWeight = j.fontWeight;
			if ( j.overflow ) el.style.overflow = j.overflow;
			if ( j.overflowX ) el.style.overflowX = j.overflowX;
			if ( j.overflowY ) el.style.overflowY = j.overflowY;

			if ( j.display ) el.style.display = j.display;
			if ( j.position ) el.style.position = j.position;
			if ( j.zIndex ) el.style.zIndex = j.zIndex;
			if ( /string/i.test( typeof( j.top ))) el.style.top = j.top;
			if ( /string/i.test( typeof( j.left ))) el.style.left = j.left;
			if ( /string/i.test( typeof( j.bottom ))) el.style.bottom = j.bottom;
			if ( /string/i.test( typeof( j.right ))) el.style.right = j.right;
			if ( /string/i.test( typeof( j.width ))) el.style.width = j.width;
			if ( /string/i.test( typeof( j.height ))) el.style.height = j.height;

			if ( j.border ) el.style.border = j.border;
			if ( j.borderTop ) el.style.borderTop = j.borderTop;
			if ( j.margin ) el.style.margin = j.margin;
			if ( j.padding ) el.style.padding = j.padding;
			if ( /number|string/i.test( typeof( j.cellPadding )) ) el.cellPadding = j.cellPadding;
			if ( /number|string/i.test( typeof( j.cellSpacing )) ) el.cellSpacing = j.cellSpacing;
			if ( /number|string/i.test( typeof( j.colSpan )) ) el.colSpan = j.colSpan;
			if ( /number|string/i.test( typeof( j.rowSpan )) ) el.rowSpan = j.rowSpan;

			if ( j.cursor ) el.style.cursor = j.cursor;
			if ( /function/i.test( typeof( j.onclick )) ) el.onclick = j.onclick;
			if ( /function/i.test( typeof( j.onblur )) ) el.onblur = j.onblur;
			if ( /function/i.test( typeof( j.onmouseover )) ) el.onmouseover = j.onmouseover;
			if ( /function/i.test( typeof( j.onmouseout )) ) el.onmouseout = j.onmouseout;
			if ( /function/i.test( typeof( j.oncontextmenu )) ) el.oncontextmenu = j.oncontextmenu;


			if ( j.cssFloat ) {
				if (isIE)
					el.style.styleFloat = j.cssFloat;
				else
					el.style.cssFloat = j.cssFloat;
			}

			// Input Elements
			if ( j.type ) el.type = j.type;
			if ( j.size ) el.size = j.size;
			if ( j.name ) el.name = j.name;
			if ( /number|string/i.test( typeof( j.maxlength )) ) el.maxLength = j.maxlength;
			if ( /number|string/i.test( typeof( j.maxLength )) ) el.maxLength = j.maxLength;
			if ( ! /undefined/i.test(j.value) ) el.value = j.value;

			if ( /select/i.test( el.tagName ) ) {

				if (j.options) {

					for ( var i = 0; i < j.options.length; i ++ ) {
						var o = htmlElement({tagName:'option'});
						if ( /string/i.test( typeof(j.options[i].value))) {
							o.value = j.options[i].value;
							o.text = j.options[i].text;
						} else {
							o.value = j.options[i];
							o.text = j.options[i];
						}
						(isIE ? el.add(o) : el.add(o,null));
						if ( j.value && j.value == o.value ) {
							o.defaultSelected = true;
							o.selected = true;
						}
					}
				}
			} else if ( /textarea/i.test( el.tagName ) ) {

				if ( /number|string/i.test( typeof( j.rows )) ) el.rows = j.rows;
			}
		}
	}

	var addCell = function( row, value, j ) {
		var c = row.insertCell(-1);
		if (typeof(value) == 'object')
			c.appendChild(value);
		else
			c.innerHTML = value;

		ApplyHTMLAttributes( c, j );
		return (c);
	}

	var htmlElement = function( j ) {

		if (j) {

			var el = document.createElement(( j.tagName ? j.tagName : 'span' ));
			ApplyHTMLAttributes( el, j );
			return (el);
		} else {

			return (document.createElement('span'));
		}
	}

	window.logbook = {


		add : function( evt, el ) {

			var j = {
				parent : el,
				Date : htmlElement({ tagName: 'input', type: 'text', size: '10'}),
				Description : htmlElement({ tagName: 'input', type: 'text', size: '60'}),
				Providor : htmlElement({ tagName: 'input', type: 'text', size: '60'}),
				Type : htmlElement({ tagName: 'input', type: 'text', size: '60'}),
				Topics : htmlElement({ tagName: 'input', type: 'text', size: '60'}),
				Accredited : htmlElement({ tagName: 'input', type: 'checkbox', size: '10'}),
				AccreditationID : htmlElement({ tagName: 'input', type: 'text', size: '60'}),
				Group : htmlElement({ tagName: 'select', options : ['1','2','3'] }),
				CPDCredits : htmlElement({ tagName: 'input', type: 'text', size: '10'}),
				CancelButton : htmlElement({ tagName: 'button', innerHTML: 'Cancel' }),
				UpdateButton : htmlElement({ tagName: 'button', innerHTML: 'Update' })
			}

			j.CancelButton.j = j;
			j.UpdateButton.j = j;

			j.CancelButton.onclick = function(evt) {

				StopPropagation(evt);
				this.j.parent.removeChild(this.j.d);
			}
			j.UpdateButton.onclick = function(evt) {

				StopPropagation(evt);

				alert( 'I\'m Just a good Idea' );
				this.j.parent.removeChild(this.j.d);

				navto(window.location);
			}

			var t = htmlElement({ tagName: 'table', cellPadding: '4' });
			var r = t.insertRow(-1);
				addCell(r, 'Date' );
				addCell(r, j.Date );
			var r = t.insertRow(-1);
				addCell(r, 'Description' );
				addCell(r, j.Description );
			var r = t.insertRow(-1);
				addCell(r, 'Providor' );
				addCell(r, j.Providor );
			var r = t.insertRow(-1);
				addCell(r, 'Type' );
				addCell(r, j.Type );
			var r = t.insertRow(-1);
				addCell(r, 'Topics' );
				addCell(r, j.Topics );
			var r = t.insertRow(-1);
				addCell(r, 'Accredited' );
				addCell(r, j.Accredited );
			var r = t.insertRow(-1);
				addCell(r, 'Accreditation ID' );
				addCell(r, j.AccreditationID );
			var r = t.insertRow(-1);
				addCell(r, 'Group' );
				addCell(r, j.Group );
			var r = t.insertRow(-1);
				addCell(r, 'CPD Credits' );
				addCell(r, j.CPDCredits );
			var r = t.insertRow(-1);
				var c = addCell(r, j.UpdateButton, { colSpan: '2', textAlign: 'right' } );
				c.appendChild(j.CancelButton);

			var d = htmlElement({ tagName: 'div', position: 'absolute',
				backgroundColor: 'white',
				border: '1px solid black',
				bottom: '0', right: '0'
				});

				d.appendChild(t);

			j.parent.style.position = 'relative';
			j.parent.appendChild(d);

			j.d = d;
		}
	}
}) ()

