// Form class/object v0.1.2 (peppered/AK)

function Form(id) {
	this.elementId = id;
	this.element = null;
	if (document.getElementById(id))
		this.element = document.getElementById(id);
}


// FormField child object

Form.prototype.FormField = function(id) {

	this.elementId = id;
	this.element = null;
	if (document.getElementById(id))
		this.element = document.getElementById(id);
	this.element.formObject = this; // for referencing in element events
}

Form.prototype.FormField.prototype.setDefaultValue = function(sValue) {
	var sDefaultTxt = sValue;
	this.element.value = sDefaultTxt;
	this.element.onfocus = function(){
		if (this.value == sDefaultTxt)
			this.value = '';
	};
	this.element.onblur = function(){
		if (this.value == '')
			this.value = sDefaultTxt;
	};
}

// enableImgHover (imgbutton fields)
Form.prototype.FormField.prototype.enableImgHover = function() {
	var sImg = this.element.src;
	var sExt = sImg.substring(sImg.length-3);
	var sHoverImg = sImg.substring(0, sImg.length-4) + '_over' + '.' + sExt;
	
	this.img = sImg;
	this.hoverImg = sHoverImg;
	
	var agt=navigator.userAgent.toLowerCase();
	// Note: On IE5, these return 4
	var is_major = parseInt(navigator.appVersion);
	var is_minor = parseFloat(navigator.appVersion);
	var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var ie_alphaImg = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1 || agt.indexOf("msie 6.") != -1));
	
	if (sExt == 'png' && is_ie && ie_alphaImg) {
		this.element.onmouseover = function() {
			//this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + sHoverImg + "',sizingMethod='image')";
			this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=0)";
			this.parentNode.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + sHoverImg + "',sizingMethod='image')";
		};
		this.element.onmouseout = function(){
			//this.runtimeStyle.filter = '';
			this.parentNode.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + sImg + "',sizingMethod='image')";;
		};
		return;
	}

	this.element.onmouseover = this.element.onfocus = function(){this.src = this.formObject.hoverImg};
	this.element.onmouseout = this.element.onblur = function(){this.src = this.formObject.img};
}

