// <script language="javascript" id="focusRollover">
<!--

// ********************** MANAGE THE EVENT ONKEYPRESS WHEN KEY IS 13 **********************


//first, tell the browsers to react to the event
if( document.captureEvents && Event.KEYUP ) {
  //remove this part if you do not need Netscape 4 to work
  document.captureEvents( Event.KEYUP );
}

var _arObjectId13Allowed = new Array();
var _bALL13Allowed = false;


/* this next line tells the browser to detect a keyup
event over the whole document and when it detects it,
it should run the event handler function 'alertkey' */
//now create the event handler function to process the event
function alertkeypress(e) {

	if( !e ) {
	//if the browser did not pass the event information to the
	//function, we will have to obtain it from the event register
	if( window.event ) {
		//Internet Explorer
		e = window.event;
	} else {
		//total failure, we have no way of referencing the event
		return;
		}
	} //!e

	var oSrcElement;
	if (e.target) oSrcElement = e.target;
	else if (e.srcElement) oSrcElement = e.srcElement;


	if( typeof( e.keyCode ) == 'number'  ) {
		//DOM
		e = e.keyCode;
	} else if( typeof( e.which ) == 'number' ) {
		//NS 4 compatible
		e = e.which;
	} else if( typeof( e.charCode ) == 'number'  ) {
		//also NS 6+, Mozilla 0.9+
		e = e.charCode;
	} else {
		//total failure, we have no way of obtaining the key code
		return;
	}
	//Manage the keycode 13
	if (!_bALL13Allowed)
		if (e == 13) {
			var a = _arObjectId13Allowed;
			if ((a) && (oSrcElement)) {
				for (var i=0; i<a.length; i++) if (a[i] == oSrcElement.id) break;
				if (i == a.length) return false;
				else return true;
			}
			else
				return false;
		} //(e == 13)
} //alertkeypress

// *******************************************************************


	if (window.attachEvent) {
			window.attachEvent("onload", function() { applyFocusRollover("INPUT", "TEXTAREA"); });
			//window.attachEvent("onload", autoFocus);
	}

	function autoFocus() {
		for (var i= 0; i < document.forms[0].elements.length; i++) {
			var o = document.forms[0].elements[i];
			var valid = true;
			if (o.type) if (o.type!='text' && o.type!='password') valid = false;
			// for now, do not set focus on dropdowns
			//if (o.type) if (o.type.indexOf('select')==-1 && o.type!='text' && o.type!='password') valid = false;
			
			if (valid) {
				if (o.focus && (!o.disabled)) o.focus();
				return;
			}
		}	// end for
	}


	// TODO: not working quite well. It overwrites default onfocus action if set on control
	function applyFocusRollover() {
	//return false;
		for (var j= 0; j<applyFocusRollover.arguments.length; j++) {
			var tag = applyFocusRollover.arguments[j];
			var o = document.getElementsByTagName(tag);
			for (var i=0; i<o.length; i++) {
				var apply = true;
				if (tag.toUpperCase() == 'INPUT') 
					if (o[i].type!='text' && o[i].type!='password') apply = false;
				
				if (apply) {
					if (o[i].onfocus) o[i].onfocus = rolloverFocus;
					if (o[i].onblur) o[i].onblur = rolloverBlur;
				} // end if (apply)
			}	// end for i
		} // end for j
	}
	
	function rolloverFocus() { this.className="formField1Focus"; }
	function rolloverBlur() {  
		this.className	= "formField1";
		this.onfocus	= rolloverFocus;
	}

	function CheckAll(pChecked, pItemName) {
		var f = document.forms[0];
		var i = 0;
		for (i=0; i<f.elements.length; i++)
			if ((f.elements[i].type == 'checkbox') && (f.elements[i].name.indexOf(pItemName) > -1)) {
				f.elements[i].checked = pChecked;
				f.elements[i].fireEvent("onclick");
				}
		} //CheckAll

	function changeRowColor(c, bNormalStyle) {
		var ch = c;
		while (c.tagName!="TR")
		{c = c.parentElement;}
		c.className = (ch.checked)?"GridItemStyleSelected":((bNormalStyle)?"GridItemStyle":"GridAlternatingItemStyle");	
		} //changeRowColor

	function btnEliminar_onClick(pItemName) {
		var f = document.forms[0];
		var i = 0;
		var bAnySelected = false;
		for (i=0; i<f.elements.length; i++)
			if (f.elements[i].name.indexOf(pItemName) > -1)
				if (f.elements[i].checked) {
					bAnySelected = true;
					break;
					}
		if (bAnySelected) {
			if (confirm("Está seguro que desea eliminar los registros seleccionados?\n(Se eliminarán también los datos relacionados)"))
				return true;
			}
		else
			alert("Seleccione al menos un registro de la lista");

		return false;
		} //btnEliminar_onClick

	function getFormElementBySimilarId(pItemId, f, pItemType) {
		if (!f) var f = document.forms[0];
		return (getBasicElementBySimilarId(f.elements, pItemId, pItemType));
		} //getFormElementBySimilarId

	function getAnyElementBySimilarId(pItemId, tagName) {
		var a = (tagName?document.getElementsByTagName(tagName):document.all);
		return (getBasicElementBySimilarId(a, pItemId));
		} //getAnyElementBySimilarId

	function getBasicElementBySimilarId(a, pItemId, pItemType) {
		for (var i=0; i<a.length; i++)
			if (a[i].id.indexOf(pItemId) > -1) {
				if (pItemType) {
					if ((a[i].type) && (pItemType == a[i].type)) return (a[i]);
					}
				else return (a[i]);
				}
		return null;
		} //getBasicElementBySimilarId

	function getFormArrayByName(pItemName) {
		var a = document.forms[0].elements;
		var r = new Array();
		for (var i=0; i<a.length; i++)
			if (a[i].name.indexOf(pItemName) > -1)
				r[r.length] = a[i];
		return r;
		} //getFormArrayByName

	function WinPopupOpen(pURL) {
		var h = 400, w = 1000;	// popup-window height, width ...
		var l = 0, t = 0;		//			...	left and top
		l = 0;		// align right
		var features =  'left='+l+',top='+t+','+
					'width='+w+',height='+h+','+
					'copyhistory=0,location=0,menubar=0,directories=0,'+
					'resizable=0,scrollbars=1,status=0,toolbar=0,hotkeys=0,titlebar=0';
					
		var WinPopup = window.open(pURL,"WinPopup",features);
		WinPopup.focus();
		
		} // WinPopupOpen
		
	function CleanInputItem(pControlID1, pControlID2) {
		var arItem = new Array(pControlID1, pControlID2);
		for (var i=0; i<arItem.length; i++) {
			var pControlID = arItem[i];
			if (pControlID) {
				pControlID = document.getElementById(pControlID);
				SetValueToTextbox(pControlID, "");
				}
			}		
	} //CleanInputItem

	function SeleccionarPopupItem(pDataValue, pDataText, pDataValueControlID, pDataTextControlID, fCode) {
	
		if (!opener) return false;
		var f = opener.document.forms[0];
		if (!f) return false;
	
		var oDataValueControl = getFormElementBySimilarId(pDataValueControlID, f);
		if (oDataValueControl) oDataValueControl.value = pDataValue;
		var oDataTextControl = getFormElementBySimilarId(pDataTextControlID,f);
		SetValueToTextbox(oDataTextControl, pDataText);
		
		window.close();
		opener.focus();
		oDataTextControl.focus();
	} //SeleccionarPopupItem
		
	function SetValueToTextbox(oTextbox, pValue) {
		if (oTextbox) {
			var vOtherData = (pValue != oTextbox.value);
			oTextbox.value = pValue;
			if ((vOtherData) && (oTextbox.onchange != null))
				if ((typeof(oTextbox.onchange) == "object") || (typeof(oTextbox.onchange) == "function"))
					oTextbox.onchange();
		} //if
	} //SetValueToTextbox
	
//-->
//</script>
