/*#############################################################
Name: Niceforms
Version: 1.0
Author: Lucian Slatineanu
URL: http://www.badboy.ro/

Feel free to use and modify but please provide credits.
#############################################################*/

// some changes by Miquel Antoni Coma  <macomarivas_at_aedgency_dot_com>

	var nForms = 
	{
		//Global Variables
		imagesPath	: "imgs/niceforms/",
		selectText	: "please select",
		niceforms	: document.getElementsByTagName('form'),
		isMac		: new RegExp('(^|)'+'Apple'+'(|$)'),
		ie			: ((navigator.userAgent.toLowerCase().indexOf("msie") != -1) && (navigator.userAgent.toLowerCase().indexOf("opera") == -1)),
		preloads	: [],
		
		//Theme Variables - edit these to match your theme
		srdw		: 21,	// selectRightSideWidth
		slsw		: 8,	// selectLeftSideWidth
		sah			: 21,	// selectAreaHeight
		saoo		: 2,	// selectAreaOptionsOverlap
		
		$			: function (e){return document.getElementById(e);},
		$$			: function (e){return document.getElementsByTagName(e);},
		$a			: function (e){return document.createElement(e);},
		
		input		: [],
		label		: [],
		textarea	: [],
		select		: [],
		radio		: [],
		radioLabel	: [],
		checkbox	: [],
		checkboxLab	: [],
		text		: [],
		hover		: [],
		button		: [],
		
		//----------------------------------------------------------------
		//Initialization function - if you have any other 'onload' functions, add them here
		init			: function ()
		{
			if(!document.getElementById) return false;
			
			nForms.preloadImages();
			nForms.getElements();
			nForms.separateElements();
			nForms.replaceRadios();
			nForms.replaceCheckboxes();
			nForms.replaceSelects();
			//if(!nForms.isMac.test(navigator.vendor)) {
				nForms.replaceTexts();
				nForms.replaceTextareas();
				nForms.buttonHovers();
			//}
		},
		
		//----------------------------------------------------------------
		//preloading required images
		preloadImages	: function ()
		{
			var n,imgs = ["button_left_dis.gif","button_right_dis.gif","button_left_xon.gif","button_right_xon.gif","input_left_xon.gif","input_right_xon.gif","txtarea_bl_xon.gif","txtarea_br_xon.gif","txtarea_cntr_xon.gif","txtarea_l_xon.gif","txtarea_tl_xon.gif","txtarea_tr_xon.gif"];
			
			n = imgs.length;
			nForms.preloads = new Array(n);
			while(n--)
			{
				nForms.preloads[n] = new Image();
				nForms.preloads[n].src = nForms.imagesPath + imgs[n];
			}
		},
		
		//----------------------------------------------------------------
		//getting all the required elements
		getElements		: function ()
		{
			var a,b,c,f,k,n,re = new RegExp('(^| )'+'niceform'+'( |$)'), els = ["input","label","textarea","select"];
			
			n = nForms.$$('form').length;
			while(n--)
			{
				if(!re.test(nForms.niceforms[n].className)) continue;
				
				a = document.forms[n];
				
				f = els.length;
				while(f--)
				{
					c = els[f];
					b = a.getElementsByTagName(c);
					k = b.length;
					while(k--)
						nForms[c].push(b[k])
				}
			}
		},
		
		//----------------------------------------------------------------
		//separating all the elements in their respective arrays
		separateElements	: function ()
		{
			var r = 0, c = 0, t = 0, rl = 0, cl = 0, tl = 0, b = 0;
			var a,b,f,n = nForms.input.length;
			while(n--)
			{
				a = nForms.input[n];
				switch(a.type)
				{
					case 'radio':
							nForms.radio[r++] = a;
							f = nForms.label.length;
							while(f--)
							{
								k = nForms.label[f];
								if(k.htmlFor == a.id)
								{
									if(a.checked)
										k.className = "chosen";
									nForms.radioLabel[rl++] = k;
								}
							}
							break;
					
					case 'checkbox':
							nForms.checkbox[c++] = a;
							f = nForms.label.length;
							while(f--)
							{
								k = nForms.label[f];
								if(k.htmlFor == a.id)
								{
									if(a.checked)
										k.className = "chosen";
									nForms.checkboxLab[cl++] = k;
								}
							}
							break;
					
					case 'password':
					case 'text':
							nForms.text[t++] = a;
							break;
					
					case 'button':
					case 'submit':
							nForms.button[b++] = a;
							break;
				}
			}
		},
		
		//----------------------------------------------------------------
		// Radios
		replaceRadios		: function ()
		{
			var a,radioArea,n = nForms.radio.length;
			while(n--)
			{
				a = nForms.radio[n];
				//move radios out of the way
				a.className = "outtaHere";
				//create div
				radioArea = nForms.$a('div');
				
				radioArea.className = a.checked && "radioAreaChecked" || "radioArea";
				
				radioArea.style.left = nForms.findPosX(a) + 'px';
				radioArea.style.top = nForms.findPosY(a) + 'px';
				radioArea.style.margin = "1px";
				radioArea.id = "myRadio" + n;
				//insert div
				a.parentNode.insertBefore(radioArea, a);
				//assign actions
				radioArea.onclick = new Function('nForms.rechangeRadios('+n+')');
				nForms.radioLabel[n].onclick = new Function('nForms.rechangeRadios('+n+')');
				//if(!nForms.ie){a.onfocus = new Function('nForms.focusRadios('+n+')');a.onblur = new Function('nForms.blurRadios('+n+')');}
				a.onclick = nForms.radioEvent;
			}
			return true;
		},
		
		//----------------------------------------------------------------
		focusRadios			: function (who)
		{
			var what = nForms.$('myRadio'+who).style;
			what.border = "1px dotted #333"; what.margin = "0";
			return false;
		},
		
		//----------------------------------------------------------------
		blurRadios			: function (who)
		{
			var what = nForms.$('myRadio'+who).style;
			what.border = "0"; what.margin = "1px";
			return false;
		},
		
		//----------------------------------------------------------------
		checkRadios			: function (who)
		{
			var what = nForms.$('myRadio'+who);
			var others = nForms.$$('div');
			var whoName = nForms.radio[who].name;
			
			var a,n = others.length;
			while(n--)
			{
				a = others[n];
				if((a.className == "radioAreaChecked") && (a.nextSibling.name == whoName))
					a.className = "radioArea";
			}
			what.className = "radioAreaChecked";
		},
		
		//----------------------------------------------------------------
		changeRadios		: function (who)
		{
			var n,b,a = nForms.radio[who];
			if(!a.checked) return;
			
			n = nForms.radio.length;
			while(n--)
			{
				b = nForms.radio[n];
				
				if(b.name == a.name)
				{
					b.checked = false;
					nForms.radioLabel[n].className = "";
				}
				
				a.checked = true;
				nForms.radioLabel[who].className = "chosen";
				nForms.checkRadios(who);
			}
			
			b = nForms.$(nForms.radio[who].id + "-inp");
			if(b) b.focus();
		},
		
		//----------------------------------------------------------------
		rechangeRadios		: function (who)
		{
			var n,b,a = nForms.radio[who];
			if(!a.checked)
			{
				n = nForms.radio.length;
				while(n--)
				{
					b = nForms.radio[n];
					if(b.name == a.name)
					{
						b.checked = false;
						nForms.radioLabel[n].className = "";
					}
				}
				a.checked = true;
				nForms.radioLabel[who].className = "chosen";
				nForms.checkRadios(who);
			}
		},
		
		//----------------------------------------------------------------
		radioEvent			: function (e)
		{
			e = e || window.event;
			if(e.type == "click")
			{
				var n = nForms.radio.length;
				while(n--)
					if(this == nForms.radio[n])
					{
						nForms.changeRadios(n);
						break;
					}
			}
		},
		
		//----------------------------------------------------------------
		// checkBoxs
		replaceCheckboxes	: function ()
		{
			var a, n = nForms.checkbox.length;
			while(n--)
			{
				a = nForms.checkbox[n];
				//move checkboxes out of the way
				a.className = "outtaHere";
				//create div
				var checkboxArea = nForms.$a('div');
				
				checkboxArea.className = a.checked && "checkboxAreaChecked" || "checkboxArea";
				
				checkboxArea.style.left = nForms.findPosX(a) + 'px';
				checkboxArea.style.top = nForms.findPosY(a) + 'px';
				checkboxArea.style.margin = "1px";
				checkboxArea.id = "myCheckbox" + n;
				//insert div
				a.parentNode.insertBefore(checkboxArea, a);
				//asign actions
				checkboxArea.onclick = new Function('nForms.rechangeCheckboxes('+n+')');
				if(!nForms.isMac.test(navigator.vendor)) {a.onclick = new Function('nForms.changeCheckboxes('+n+')');}
				else {a.onclick = new Function('nForms.rechangeCheckboxes('+n+')');}
				//if(!nForms.ie){a.onfocus = new Function('nForms.focusCheckboxes('+n+')');a.onblur = new Function('nForms.blurCheckboxes('+n+')');}
				a.onkeydown = nForms.checkEvent;
			}
			return true;
		},
		
		//----------------------------------------------------------------
		focusCheckboxes		: function (who)
		{
			var what = nForms.$('myCheckbox'+who).style;
			what.border = "1px dotted #333"; what.margin = "0";
			return false;
		},
		
		//----------------------------------------------------------------
		blurCheckboxes		: function (who)
		{
			var what = nForms.$('myCheckbox'+who).style;
			what.border = "0"; what.margin = "1px";
			return false;
		},
		
		//----------------------------------------------------------------
		checkCheckboxes		: function (who, action)
		{
			nForms.$('myCheckbox'+who).className = action && "checkboxAreaChecked" || "checkboxArea";
		},
		
		//----------------------------------------------------------------
		changeCheckboxes	: function (who)
		{
			var a = nForms.checkboxLab[who], b = a.className == "chosen";
			
			a.checked = b;
			a.className = b ? "" : "chosen";
			nForms.checkCheckboxes(who, !b);
		},
		
		//----------------------------------------------------------------
		rechangeCheckboxes	: function (who)
		{
			var a = nForms.checkboxLab[who], b = a.className != "chosen";
			
			a.className = b ? "chosen" : "";
			
			a.checked = b;
			nForms.checkCheckboxes(who, b);
		},
		
		//----------------------------------------------------------------
		checkEvent			: function (e)
		{
			e = e || window.event;
			if(e.keyCode == 32)
			{
				var n = nForms.checkbox.length;
				while(n--)
					if(this == nForms.checkbox[n])
						nForms.changeCheckboxes(n);
			} //check if space is pressed
		},
		
		//----------------------------------------------------------------
		// selects
		replaceSelects		: function ()
		{
			var w,a,n = nForms.select.length;
			var selectArea,left,right,center,button,text,selectWidth,optionsDiv
			
			while(n--)
			{
				a = nForms.select[n];
				//create and build div structure
				selectArea = nForms.$a('div');
				left = nForms.$a('div');
				right = nForms.$a('div');
				center = nForms.$a('div');
				button = nForms.$a('a');
				text = document.createTextNode(nForms.selectText);
				center.id = "mySelectText"+n;
				selectWidth = parseInt(a.className.replace(/width_/g, ""));
				center.style.width = selectWidth - 10 + 'px';
				selectArea.style.width = selectWidth + nForms.srdw + nForms.slsw + 'px';
				button.style.width = selectWidth + nForms.srdw + nForms.slsw + 'px';
				button.style.marginLeft = - selectWidth - nForms.slsw + 'px';
				button.href = "javascript:nForms.showOptions("+n+")";
				button.onmouseover = nForms.hideStatus;
				button.onkeydown = nForms.selectEvent;
				button.className = "selectButton"; //class used to check for mouseover
				selectArea.className = "selectArea";
				selectArea.id = "sarea"+n;
				left.className = "left";
				right.className = "right";
				center.className = "center";
				right.appendChild(button);
				center.appendChild(text);
				selectArea.appendChild(left);
				selectArea.appendChild(right);
				selectArea.appendChild(center);
				//hide the select field
				a.style.display='none'; 
				//insert select div
				a.parentNode.insertBefore(selectArea, a);
				//build & place options div
				optionsDiv = nForms.$a('div');
				optionsDiv.style.width = selectWidth + nForms.srdw - 3 + (4 * nForms.ie) + 'px';
				optionsDiv.className = "optionsDivInvisible";
				optionsDiv.id = "optionsDiv"+n;
				optionsDiv.onmouseout = nForms.hideOptions;
				
				
				//_debug($(selectArea).getPosition().y);
				w = nForms.getPosition(selectArea);
				optionsDiv.style.left = w.x + 'px';
				optionsDiv.style.top = w.y + nForms.sah - nForms.saoo + 'px';
				
				//optionsDiv.style.left = nForms.findPosX(selectArea) + 'px';
				//optionsDiv.style.top = nForms.findPosY(selectArea) + nForms.sah - nForms.saoo + 'px';
				//get select's options and add to options div
				w = 0;
				left = a.options.length;
				for(; w < left; w++)
				{
					right = nForms.$a('p');
					center = nForms.$a('a');
					center.href = "javascript:nForms.showOptions("+n+"); nForms.selectMe('"+a.id+"',"+w+","+n+");";
					center.onmouseover = nForms.hideStatus;
					center.appendChild( document.createTextNode(a.options[w].text) );
					right.appendChild(center);
					optionsDiv.appendChild(right);
					//check for pre-selected items
					if(a.options[w].selected) {nForms.selectMe(a.id,w,n,true);}
				}
				//insert options div
				nForms.$$("body")[0].appendChild(optionsDiv);
			}
		},
		
		//----------------------------------------------------------------
		showOptions		: function (g)
		{		
				var elem = nForms.$("optionsDiv"+g);
				
				// dependncia amb mootools! s'ha de estudiar el codi de mootools per mirar com ho fa ;)
				var a =   nForms.getPosition( nForms.$("sarea" + g) );
				elem.style.left = a.x + 'px';
				elem.style.top = a.y + nForms.sah - nForms.saoo + 3 + 'px';
				
				elem.className = elem.className=="optionsDivInvisible" && "optionsDivVisible" || "optionsDivInvisible";
		},
		
		//----------------------------------------------------------------
		hideOptions		: function (e) //hiding the options on mouseout
		{
			e = e || window.event;
			var reltg = e.relatedTarget || e.toElement, a = reltg.nodeName;
			if( ((a != 'A') && (a != 'DIV') && (a != 'xul:slider') && (a != 'xul:thumb') && (a != 'xul:scrollbarbutton')) || ((a == 'A') && (reltg.className=="selectButton") && (a != 'DIV')) )
				this.className = "optionsDivInvisible";
			
			e.cancelBubble = true;
			if(e.stopPropagation) e.stopPropagation();
		},
		
		//----------------------------------------------------------------
		selectMe		: function (selectFieldId,linkNo,selectNo,activa)
		{
			//feed selected option to the actual select field
			var f = nForms.$(selectFieldId);
			var n = f.options.length;
			while(n--)
				f.options[n].selected = n == linkNo && "selected" || "";
				
			//show selected option
			n = nForms.$("mySelectText"+selectNo);
			var newText = document.createTextNode(f.options[linkNo].text);
			n.replaceChild(newText, n.childNodes[0]);
			
			nForms.formFunctions(f,activa);
			//if(f.onchange && !activa) f.onchange();
		},
		
		//----------------------------------------------------------------
		selectEvent		: function (e)
		{
			e = (e || window.event).keyCode;
			switch(e)
			{
				case 40: //down
					var fieldId = this.parentNode.parentNode.id.replace(/sarea/g, "");
					var a = nForms.select[fieldId];
					var linkNo = 0,n = a.options.length;
					while(n--)
						if(a.options[n].selected)
						{
							linkNo = n;
							break;
						}
					++linkNo;
					if(linkNo >= a.options.length) {linkNo = 0;}
					nForms.selectMe(a.id, linkNo, fieldId);
					break;
				case 38: //up
					var fieldId = this.parentNode.parentNode.id.replace(/sarea/g, "");
					var a = nForms.select[fieldId];
					var linkNo = 0,n = a.options.length;;
					while(n--)
						if(a.options[n].selected)
						{
							linkNo = n;
							break;
						}
					--linkNo;
					if(linkNo < 0) {linkNo = a.options.length - 1;}
					nForms.selectMe(a.id, linkNo, fieldId);
					break;
				default:
					break;
			}
		},
		
		//----------------------------------------------------------------
		hideStatus		: function ()
		{
			window.status = "";
			return true;
		},
		
		//----------------------------------------------------------------
		// Texts - Inputs
		replaceTexts	: function ()
		{
			var a,o,txtLeft,txtRight, n = nForms.text.length;
			while(n--)
			{
				a = nForms.text[n];
				
				if(a.type == "password" && a.value != "")
				{
					o = nForms.$a('input');
					o.type = "text";
					o.value = a.value;
					o.size = a.size;
					o.style.width = a.style.width;
					o.alt = a.alt;
					a.value = "";
					
					o.style.display = "none";
					o.style.height = a.style.height;
					a.oText = o;
					o.oPass = a;
					o.className = "textinput";
					o.style.background = "url("+ nForms.imagesPath + a.alt + "input_bg.gif) repeat-x left top";
					
					a.parentNode.insertBefore(o,a);
					
					nForms.addEvent(o,"focus",
						function()
						{
							this.style.display = "none";
							this.oPass.style.display = "inline";
							this.parentNode.replaceChild(this.oPass,this);
							
							this.oPass.focus();
							this.oPass.select();
						}
					);
					
					nForms.addEvent(a,"blur",
						function()
						{
							if(this.value != "") return;
							
							this.style.display = "none";
							this.oText.style.display = "inline";
							this.parentNode.replaceChild(this.oText,this);
						}
					);
				}
				
				a.style.width = a.size * 10 + 'px';
				txtLeft = nForms.$a('img'); txtLeft.src = nForms.imagesPath + a.alt + "input_left.gif"; txtLeft.className = "inputCorner";
				txtRight = nForms.$a('img'); txtRight.src = nForms.imagesPath + a.alt + "input_right.gif"; txtRight.className = "inputCorner";
				a.parentNode.insertBefore(txtLeft, a);
				a.parentNode.insertBefore(txtRight, a.nextSibling);
				a.className = "textinput";
				
				a.style.background = "url(" + nForms.imagesPath + a.alt + "input_bg.gif) repeat-x left top";
				
				//create hovers
				nForms.addEvent(a,"focus",
					function()
					{
						var r = nForms.imagesPath + this.alt;
						this.className = "textinputHovered";
						this.previousSibling.src = r + "input_left_xon.gif";
						this.nextSibling.src = r + "input_right_xon.gif";
						this.style.backgroundPosition = "left bottom"; // for variation only
					}
				);
				
				nForms.addEvent(a,"blur",
					function()
					{
						var r = nForms.imagesPath + this.alt;
						if(this.oText && !nForms.ie)
						{
							this.oText.previousSibling.src = r + "input_left.gif";
							this.oText.nextSibling.src = r + "input_right.gif";
							return;
						}
						this.className = "textinput";
						this.previousSibling.src = r + "input_left.gif";
						this.nextSibling.src = r + "input_right.gif";
						this.style.backgroundPosition = "left top"; // for variation only
					}
				);
				
				a.disable = function(v)
				{
					var r = nForms.imagesPath + this.alt;
					this.disabled = v;
					//this.className = "textinputDisabled";
					v = v && "_dis" || "";
					this.style.backgroundImage = "url(" + r + "input_bg" + v + ".gif)";
					this.previousSibling.src = r + "input_left" + v + ".gif";
					this.nextSibling.src = r + "input_right" + v + ".gif";
				}
				
				if(a.value != "")
				{
					nForms.addEvent(a,"focus",nForms.textBlur);
					nForms.addEvent(a,"blur",nForms.textFocus);
				}
				
				if(a.oText)
				{
					a.parentNode.replaceChild(o,a);
					o.style.display = "inline";
					o.style.width = a.style.width;
				}
			}
		},
		
		//----------------------------------------------------------------
		textBlur			: function ()
		{
			if(!this.txt) this.txt = this.value; // save the default value of the field
			if(this.value == this.txt) this.value = ""; // blank field on enter
		},
		
		//----------------------------------------------------------------
		textFocus			: function ()
		{
			if(this.value == "") this.value = this.txt; // if blank field, restore the default value
		},
		
		//----------------------------------------------------------------
		// Textareas
		replaceTextareas	: function ()
		{
			var a,n = nForms.textarea.length;
			while(n--)
			{
				a = nForms.textarea[n];
				var where = a.parentNode;
				var where2 = a.previousSibling;
				a.style.width = a.cols * 10 + 'px';
				a.style.height = a.rows * 10 + 'px';
				//create divs
				var container = nForms.$a('div');
				container.className = "txtarea";
				//container.style.width = a.offsetWidth + 'px';
				//container.style.height = a.offsetHeight + 'px';
				
				container.style.width = a.cols * 10 + 20 + 'px';
				container.style.height = a.rows * 10 + 20 + 'px';
				var topRight = nForms.$a('div');
				topRight.className = "tr";
				
				var topLeft = nForms.$a('img');
				topLeft.className = "txt_corner";
				topLeft.src = nForms.imagesPath + "txtarea_tl.gif";
				
				var centerRight = nForms.$a('div');
				centerRight.className = "cntr";
				
				var centerLeft = nForms.$a('div');
				centerLeft.className = "cntr_l";
				//centerLeft.style.height = a.offsetHeight + 'px'
				centerLeft.style.height = a.rows * 10 + (nForms.ie && 12 || 10) + 'px'
				
				var bottomRight = nForms.$a('div');
				bottomRight.className = "br";
				var bottomLeft = nForms.$a('img');
				bottomLeft.className = "txt_corner";
				bottomLeft.src = nForms.imagesPath + "txtarea_bl.gif";
				//assemble divs
				container.appendChild(topRight);
				topRight.appendChild(topLeft);
				container.appendChild(centerRight);
				centerRight.appendChild(centerLeft);
				centerRight.appendChild(a);
				container.appendChild(bottomRight);
				bottomRight.appendChild(bottomLeft);
				//insert structure
				where.insertBefore(container, where2);
				//create hovers
				nForms.addEvent(a,"focus",
					function()
					{
						this.previousSibling.className = "cntr_l_xon";
						this.parentNode.className = "cntr_xon";
						this.parentNode.previousSibling.className = "tr_xon";
						this.parentNode.previousSibling.getElementsByTagName("img")[0].src = nForms.imagesPath + "txtarea_tl_xon.gif";
						this.parentNode.nextSibling.className = "br_xon";
						this.parentNode.nextSibling.getElementsByTagName("img")[0].src = nForms.imagesPath + "txtarea_bl_xon.gif";
					}
				);
				
				nForms.addEvent(a,"blur",
					function()
					{
						this.previousSibling.className = "cntr_l";
						this.parentNode.className = "cntr";
						this.parentNode.previousSibling.className = "tr";
						this.parentNode.previousSibling.getElementsByTagName("img")[0].src = nForms.imagesPath + "txtarea_tl.gif";
						this.parentNode.nextSibling.className = "br";
						this.parentNode.nextSibling.getElementsByTagName("img")[0].src = nForms.imagesPath + "txtarea_bl.gif";
					}
				);
			}
		},
		
		//----------------------------------------------------------------
		// button hovers
		buttonHovers	: function ()
		{
			var a,n = nForms.button.length;
			while(n--)
			{
				a = nForms.button[n];
				a.className = "buttonSubmit";
				var buttonLeft = nForms.$a('img');
				buttonLeft.src = nForms.imagesPath + "button_left.gif";
				buttonLeft.className = "buttonImg";
				a.parentNode.insertBefore(buttonLeft, a);
				var buttonRight = nForms.$a('img');
				buttonRight.src = nForms.imagesPath + "button_right.gif";
				buttonRight.className = "buttonImg";
				if(a.nextSibling) {a.parentNode.insertBefore(buttonRight, a.nextSibling);}
				else {a.parentNode.appendChild(buttonRight);}
				
				nForms.addEvent(a,"mouseover",
					function()
					{
						this.className += "Hovered";
						this.previousSibling.src = nForms.imagesPath + "button_left_xon.gif";
						this.nextSibling.src = nForms.imagesPath + "button_right_xon.gif";
					}
				);
				
				nForms.addEvent(a,"mouseout",
					function()
					{
						this.className = this.className.replace(/Hovered/g, "");
						this.previousSibling.src = nForms.imagesPath + "button_left.gif";
						this.nextSibling.src = nForms.imagesPath + "button_right.gif";
					}
				);
			}
		},
		
		//----------------------------------------------------------------
		//Useful functions
		findPosY		: function (o)
		{
			var p = 0;
			while (o.offsetParent) {p += o.offsetTop; o = o.offsetParent;}
			return p;
		},
		
		//----------------------------------------------------------------
		findPosX		: function (o)
		{
			var p = 0;
			while (o.offsetParent) {p += o.offsetLeft; o = o.offsetParent;}
			return p;
		},
		
		//----------------------------------------------------------------
		getPosition		: function (o)
		{
			var x = 0, y = 0;
			do {
				x += o.offsetLeft || 0;
				y += o.offsetTop || 0;
				o = o.offsetParent;
			} while (o);
			
			return {x:x,y:y};
		},
		
		//----------------------------------------------------------------
		addEvent		: function (o,type,fn)
		{
			if(o.attachEvent)
			{
				o["e"+type+fn]=fn;
				o[type+fn]=function()
				{
					o["e"+type+fn](window.event);
				}
				o.attachEvent("on"+type,o[type+fn]);
			}
			else
				o.addEventListener(type,fn,true);
		},
		
		//----------------------------------------------------------------
		delEvent		: function (o,type,fn)
		{
			if(o.detachEvent)
			{
				o.detachEvent("on"+type,o[type+fn]);
				o[type+fn]=null;
			}
			else
				o.removeEventListener(type,fn,true);
		},
		
		//----------------------------------------------------------------
		formFunctions	: function (o,activa)
		{
			if(activa) return;
			
			o.onchange && o.onchange();
			
			//if(o.onchange) o.onchange();
		}
		
	};

//window.onload = nForms.init;
window.addEvent('domready', nForms.init);
//addDOMLoadEvent(nForms.init); 