/*****************************************************************
 (C) NetEnZo 2010
  www.netenzo.nl
*****************************************************************/



function popupWindow (url, caption, w, h, scrollbars) {
	var x = (screen.width) ? (screen.width - w) / 2 : 100;
	var y = (screen.height) ? (screen.height - h) / 2 : 100;
	var settings = "width="+w+",height="+h+",top="+y+",left="+x+",scrollbars="+scrollbars+",location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
	var win = window.open(url, caption, settings);
	var e = window.event;
	if (e) {
		if (!e.stopPropagation) {
			e.cancelBubble=true
		}
	}
}

// ------------------------------------------------------------------------


function addEvent (domNode, type, listener, useCapture)
{
	// Mozilla, Safari, Opera, Chrome, etc.
	if (domNode.addEventListener)
	{
		return domNode.addEventListener(type, listener, useCapture);
	}

	// Internet Explorer
	if (domNode.attachEvent)
	{
		return domNode.attachEvent('on' + type, function () { return listener.call(this, event); });
	}

	// older browsers
	var oldListener = domNode['on' + type];
	domNode['on' + type] = function (e)
	{
		e = e || window.event;
		if (oldListener) { oldListener.call(this, e); }
		return listener.call(this, e);
	};

} // function


// ------------------------------------------------------------------------


function initHintTextboxes () {

	var hintClass = 'blur';

	function onHintTextboxFocus () {
		var re = new RegExp('(^|\\s)' + hintClass + '(\\s|$)');
		var re2 = new RegExp('(^\\s+|\\s+$)');
		if (this.value === this.title && this.className && this.className.match(re)) {
			this.value = '';
			this.className = this.className ? this.className.replace(re, ' ').replace(re2, '') : '';
		}
	}

	function onHintTextboxBlur () {
		if (this.value === '' || this.value === this.title) {
			this.value = this.title;
			this.className = (this.className ? (this.className + ' ') : '') + hintClass;
		}
	}

	function initHintTextbox (el) {
		if (el.title && el.title.length > 0) {
			el.onfocus = onHintTextboxFocus;
			el.onblur  = onHintTextboxBlur;
			onHintTextboxBlur.apply(el);
			addEvent(el.form, 'submit', function () {
				onHintTextboxFocus.apply(el);
			}, true);
			addEvent(window, 'unload', function () {
				onHintTextboxFocus.apply(el);
			}, true);
		}
	}

	var inputs = document.getElementsByTagName('input');
	for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].type == 'text' || inputs[i].type == 'password') {
			initHintTextbox(inputs[i]);
		}
	}

	inputs = document.getElementsByTagName('textarea');
	for (var i = 0; i < inputs.length; i++) {
		initHintTextbox(inputs[i]);
	}

} // function

addEvent(window, 'load', initHintTextboxes, false);

