Manager.addMethods({
	'Form': new Module('Form', 'this module handles all scripts for html forms.')
});

USN.Form.zeroInputField = function(elementID) {
	if ($(elementID)) {
		if (!Object.isUndefined(document.observe)) {
			this.defaultText = true;
			document.observe("dom:loaded", this.setZeroInputFieldObserver.bind(this, elementID));
		}
		else { 
			Event.observe(window, 'load', this.setZeroInputFieldObserver.bind(this, elementID));
		}
	}
}

USN.Form.setZeroInputFieldObserver = function(elementID) {
	var element = $(elementID);
	if (element) {
		Event.observe(element, 'click', this._zeroInputFieldController.bindAsEventListener(this));
	}
}

USN.Form._zeroInputFieldController = function(event){
	if (this.defaultText) {
		this.defaultText = false;
		var input = event.element();
		input.value = "";
	}
}


//Old window functions. Legacy-code is a bitch!
var newwindow = "";

function openWindow(url,width,height) {
 // derived from PPK, http://www.quirksmode.org/js/croswin.html
 if (!newwindow.closed && newwindow.location) {
 //alert('newwindow is closed or already has a location');
 newwindow.location.href = url;
 }
 else {
 params = (arguments[3])?','+arguemnts[3]:',resizable=yes,scrollbars=no,status=no,toolbar=no';
 var windowOptionsString = [
 'height=',
 height,
 ',width=',
 width,
 params
 ];
 var windowOptionsString = windowOptionsString.join('');
 newwindow=window.open(url,'window',windowOptionsString);
 if (!newwindow.opener) newwindow.opener = self;
 }
 if (window.focus) {newwindow.focus();}
 if (this != window) {
 return false;
 }
}
function openWindowTMP(url,width,height) {
 // derived from PPK, http://www.quirksmode.org/js/croswin.html
 if (!newwindow.closed && newwindow.location) {
 //alert('newwindow is closed or already has a location');
 newwindow.location.href = url;
 }
 else {
 params = (arguments[3])?','+arguemnts[3]:',resizable=yes,scrollbars=no,status=no,toolbar=no';
 var windowOptionsString = [
 'height=',
 height,
 ',width=',
 width,
 params
 ];
 var windowOptionsString = windowOptionsString.join('');
 newwindow=window.open(url,'window',windowOptionsString);
 if (!newwindow.opener) newwindow.opener = self;
 }
 if (window.focus) {newwindow.focus();}
 if (this != window) {
 return false;
 }
}
