top.s_checked = '/images/check.gif';
top.s_nochecked = '/images/no_check.gif';
top.s_empty = '/images/spacer.gif';


function checkForm2()
{
	var Form;

	if (arguments[0] instanceof Object)
	{
		Form = arguments[0];
	}
	else
	{
		Form = document.getElementById(arguments[0]?arguments[0]:'mainform');
	}
	
	

	if (Form != null)
	{
		var tElement = Form.getElementsByTagName("INPUT");
		for (var i=0; i<tElement.length; i++)
		{
			if (tElement[i].type == "text" || tElement[i].type == "password")
			{
				if ((tElement[i].getAttribute('req') != null) && (tElement[i].getAttribute('req') != '') && (tElement[i].value == '' && tElement[i].getAttribute('maynull') != '1'))
				{
					alert(tElement[i].getAttribute('req'));
					tElement[i].focus();
					return false;
				}
				if ((tElement[i].getAttribute('req') != null) && (tElement[i].getAttribute('req') != '') && (tElement[i].type == 'checkbox') && !tElement[i].checked)
				{
					alert(tElement[i].getAttribute('req'));

					
					tElement[i].focus();
					return false;
				}
				if ((tElement[i].getAttribute('equal') != null) && (tElement[i].getAttribute('equal') != ''))
				{
					var t = tElement[i].getAttribute('equal');
					eval("var tt = Form." + t);
					if ((tt != null) && ((tt.value != tElement[i].value) && !(tElement[i].getAttribute('maynull') == '1' && tElement[i].value=='' && tt.value=='')))
					{
						alert(tElement[i].getAttribute('equaltext'));
						tt.focus();
						return false;
					}
				}
				
				if ((tElement[i].getAttribute('minlength') != null) && (tElement[i].getAttribute('minlength') != '') && (tElement[i].value.length < tElement[i].getAttribute('minlength'))&& !(tElement[i].getAttribute('maynull') == '1' && tElement[i].value=='' && tt.value==''))
				{
					
					alert(tElement[i].getAttribute('mintext'));
					tElement[i].focus();
					return false;
				}

				var regexp = /email/;
				if (tElement[i].name.match(regexp))
				{
					if (!checkEmail(tElement[i].value))
					{
						alert('Email?');
						tElement[i].focus();
						return false;
					}
				}


			}
			else
			{
				if ((tElement[i].getAttribute('req') != null))
				{
					var selected = false;
					var all_group = document.getElementsByName(tElement[i].name);
					for (var j=0; j<all_group.length; j++)
						if (all_group[j].checked)
							selected = true;
					
					if (!selected)
					{
						var v;
						if (tElement[i].required && tElement != 'undefined')
							v = 'Required field';
						else
							v = tElement[i].getAttribute('req'); 
						alert(v);
						tElement[i].focus();
						return false;
					}
				}
			}
		}

		tElement = Form.getElementsByTagName("SELECT");
		for (var i=0; i<tElement.length; i++)
		{
			if ((tElement[i].getAttribute('req') != null) && (tElement[i].getAttribute('req') != '') && (tElement[i].value == ''))
			{
				alert(tElement[i].getAttribute('req'));
				tElement[i].focus();
				return false;
			}
		}


		tElement = Form.getElementsByTagName("TEXTAREA");
		for (var i=0; i<tElement.length; i++)
		{
			if ((tElement[i].getAttribute('req') != null) && (tElement[i].getAttribute('req') != '') && (tElement[i].value == ''))
			{
				alert(tElement[i].getAttribute('req'));
				tElement[i].focus();
				return false;
			}
		}
		return true;
	}
	else
	{
		return false;
	}
}


function getBounds(tElement)
{
	var left = tElement.offsetLeft,
		top = tElement.offsetTop,
		parent;
	for (parent = tElement.offsetParent; parent; parent = parent.offsetParent)
	{
		left += parent.offsetLeft;
		top += parent.offsetTop;
	}
	return {left: left, top: top, width: tElement.offsetWidth, height: tElement.offsetHeight};
}

function setPosition()
{
	var scrollTop = document.body.scrollTop,
		tElement = arguments[0],
		tBounds = arguments[1],
		w = tElement.clientWidth,
		h = tElement.clientHeight,
		winW = document.body.clientWidth,
		winH = document.body.clientHeight,
		vPX = 0,
		tHeightNotSet = true;
	
	if ((w + tBounds.left > winW) && (winW - w + tBounds.left > w))
		tElement.style.left = tBounds.left - w + tBounds.width;
	else
		tElement.style.left = tBounds.left;

	if (h + tBounds.top > winH + scrollTop)
	{
		if (h - tBounds.top > 0)
			if (h + tBounds.top - winH - scrollTop > h - tBounds.top)
				tHeightNotSet = false;
	}
	
	if ((tBounds.top + h > winH + scrollTop) && tHeightNotSet)
		if (tBounds.top - h - scrollTop > 0)
			tHeightNotSet = false;
	
	if ((winH - tBounds.top + scrollTop - h - tBounds.height < 0) && (tBounds.top - scrollTop - h > winH - tBounds.top + scrollTop - h - tBounds.height))
		tHeightNotSet = false;

	if (tHeightNotSet)
		tElement.style.top = tBounds.top + tBounds.height + vPX
	else
		tElement.style.top = tBounds.top - h - vPX;
}

function process_zebra()
{
	var tTab = document.getElementsByTagName('TABLE');
	for (var i=0; i<tTab.length; i++)
	{
		if (tTab[i].getAttribute('zebra') == 1 || tTab[i].getAttribute('zebra') == 2)
		{
			tTab[i].className = 'zebra' + (tTab[i].getAttribute('zebra') == 2?'1':'');
			var tCou = 0;
			if (tTab[i].childNodes[0].tagName != 'TBODY')
				var tTbody = tTab[i].childNodes[1];
			else
				var tTbody = tTab[i].childNodes[0]
			if (!tTab[i].getAttribute('skip'))
				var start = 1;
			else
				var start = tTab[i].getAttribute('skip');
			for (var ii=start; ii<tTbody.childNodes.length; ii++)
				if (tTbody.childNodes[ii].tagName == 'TR' && tTbody.childNodes[ii].getAttribute('no_zebra') != '1')
				{
					tCou++;
					tTbody.childNodes[ii].className = (tCou % 2 == 1?'row_odd':'row_even');
				}
		}
	}
}
