// JavaScript Document

function OpenWindow(url, w, h)
{
	var l = parseInt((screen.width - w)/2);
	var t = parseInt((screen.height - h)/2);
	var n = parseInt(Math.random() * 1000);
	var nw = window.open(url, "NewWindow" + n, "width=" + w + "px,height=" + h + "px,left=" + l + "px,top=" + t + "px");
}

function OpenWindowWScroll(url, w, h)
{
	var l = parseInt((screen.width - w)/2);
	var t = parseInt((screen.height - h)/2);
	var n = parseInt(Math.random() * 1000);
	var nw = window.open(url, "NewWindow" + n, "width=" + w + "px,height=" + h + "px,left=" + l + "px,top=" + t + "px,scrollbars=1");
}


function openCopy()
{
	
}

function openAviso()
{
	OpenWindowWScroll('legal.asp', 800, 600);
}

function openImage(i)
{
	OpenWindow('imagePreview.asp?width=550&height=550&path=' + i, 600, 600);	
}

/* poner foco en el primer campo del formulario */

function setFocusToChild(n)
{
	var setFocus = false;
	for (var x=0; x<n.childNodes.length; x++)
	{
		var nTemp = n.childNodes[x];
		if (!setFocus)
		{
			if (nTemp.nodeName == "INPUT" && nTemp.type == "text" && !setFocus)
			{
				nTemp.focus();
				nTemp.selectionStart = 0;
				nTemp.selectionEnd = nTemp.value.length;
				setFocus = true;
			}
			else if (nTemp.nodeName == "SELECT" && !setFocus) 
			{
				nTemp.focus();
				setFocus = true;
			}else {
				if (setFocusToChild(nTemp))
				{
					setFocus = true;
				}
			}
		}
	}
	return setFocus;
}

window.onload = function()
{
	var f = document.getElementsByTagName("form");
	if (f.length >= 1)
	{
		var f1 = f[0];
		var setFocus = false;
		for (var x=0; x<f1.childNodes.length; x++)
		{
			var nTemp = f1.childNodes[x];
			if (!setFocus)
			{
				if (nTemp.nodeName == "INPUT" && nTemp.type != "hidden" && !setFocus)
				{
					nTemp.focus();
					nTemp.selectionStart = 0;
					nTemp.selectionEnd = nTemp.textLength;
					setFocus = true;
				} else {
					if (setFocusToChild(nTemp))
					{
						setFocus = true;
					}
				}
			}
		}
	}
}