function iPrint(target) { 
	try {
		var DocumentContainer = target;
		//alert(DocumentContainer);
		var WindowObject = window.open('', 'TrackHistoryData', 'width=800,height=600,top=250,left=345,toolbars=no,scrollbars=yes,status=no,resizable=yes');
		WindowObject.document.write(DocumentContainer.innerHTML);
		
		//alert (DocumentContainer.innerHTML);
		WindowObject.document.close();
		WindowObject.focus();
		WindowObject.print();
		//WindowObject.close();
	} catch(epas) {
		alert (epas.message);
	}
}
function autofitIframe(id) {
	if (!window.opera && !document.mimeType && document.all && document.getElementById) {
		parent.document.getElementById(id).style.height = this.document.body.parentNode.clientHeight + "px";
	} else {
		if (document.getElementById) {
			parent.document.getElementById(id).style.height = this.document.body.scrollHeight + "px";
		}
	}
}
function seleccionarTodos(estado) {
	var allchks = document.frm.chkItem;
	for (i = 0; i < allchks.length; i++) {
		allchks[i].checked = estado;
	}
}
function enviar(accion, formName) {
//alert(document.getElementById(formName));
	try {
		document.getElementById(formName).action = accion;
		document.getElementById(formName).submit();
	} catch(epas) {
		alert (epas.message);
	}
}
function showBusquedaAvanzada(funcionalidad) {
	options = "scroll:yes; resizeable:no; help:no; center: yes;status: no;dialogWidth: 1010px;dialogHeight: 700px;";
	if (parent) {
		parent.window.showModalDialog("/VehiculosWeb/buscadorAvanzado.do?en=" + funcionalidad, window, options);
		//showPopWin('/VehiculosWeb/buscadorAvanzado.do?en='+funcionalidad, 850, 700, null);
	} else {
		window.showModalDialog("/VehiculosWeb/buscadorAvanzado.do?en=" + funcionalidad, window, options);
	}
}
function showErrores(funcionalidad) {
	options = "scroll:yes; resizeable:no; help:no; center: yes;status: no;dialogWidth: 1010px;dialogHeight: 700px;";
	if (parent) {
		//parent.window.showModalDialog('/VehiculosWeb/buscadorAvanzado.do?en='+funcionalidad, window, options);
		//showPopWin('/VehiculosWeb/buscadorAvanzado.do?en='+funcionalidad, 850, 700, null);
		//windows.open
	} else {
		window.showModalDialog("/VehiculosWeb/buscadorAvanzado.do?en=" + funcionalidad, window, options);
	}
}
function enviarModal(url) {
		var xWin = window.dialogArguments;
		window.close();
		
		xWin.location.replace(url);
}
function erroresValidaciones(error) {
	if (error == "") {
		return true;
	} else {
		MensajeValidaciones(error);
	}
}
function ChequearSeleccionados() {
	for (var i = 0; i < document.forms[0].elements.length; i++) {
		var elemento = document.forms[0].elements[i];
		if (elemento.type == "checkbox") {
			if (elemento.checked) {
				return true;
			}
		}
	}
	alert("No hay ninguna casilla de verificación seleccionada");
	return false;
}
function ChequearCantSeleccionados(entidad){
	var cont=0;
	
	for (var i = 0; i < document.forms[0].elements.length; i++) {
		var elemento = document.forms[0].elements[i];
		if (elemento.type == "checkbox") {
			if (elemento.checked) {
				cont=cont+1;
			}
		}
	}
	if (cont>1){
		alert("No se puede asociar mas de una "+ entidad);
		return false;
	}else {return true;}

}

function abrirVentana(url,name,atributos) {
  window.open(url,name,atributos);
}

function cambiarFila(check,fila) {
	if (document.getElementById(check).checked){
		document.getElementById(fila).className = "marcar";
	}else{
		document.getElementById(fila).className = "odd";
	}
}

function pararEvento(evento) {
	if (window.event) window.event.cancelBubble = true;
	if (evento.stopPropagation) evento.stopPropagation();
}

function textareaLimit(field, maxlimit,countfield) {
	if (field.value.length > maxlimit){
		field.value = field.value.substring(0, maxlimit);
	}else {
	//	countfield.value = maxlimit - field.value.length;
	}
}

function shortText(text,maxCaracter){
	var result = text;
	if (text.length >= maxCaracter)
		result = text.substring(0,maxCaracter) + '...';
	document.write(result);
}

function OcultarMostrarFilas(Fila,Imagen) {
 	 var elementos = document.getElementsByName(Fila);
     for (i = 0; i< elementos.length; i++) {
         if(navigator.appName.indexOf("Microsoft") > -1){
			 if (elementos[i].style.display == "none"){
			 	var visible = 'block';
				document.getElementById(Imagen).src = "/VehiculosWeb/general/imagenes/iconos/contraer.jpg";
			 }else{
				var visible = 'none';
				document.getElementById(Imagen).src = "/VehiculosWeb/general/imagenes/iconos/expandir.jpg";
			 }
         } else {
             if (elementos[i].style.display == "none"){
			 	var visible = 'table-row';
				document.getElementById(Imagen).src = "/VehiculosWeb/general/imagenes/iconos/contraer.jpg";
			 }else{
				var visible = 'none';
				document.getElementById(Imagen).src = "/VehiculosWeb/general/imagenes/iconos/expandir.jpg";
			 }
         }
 		 elementos[i].style.display = visible;
	}
 }
 
 function toggle(id) {
    obj = document.getElementById(id);
    if (obj.style.display == "") {
        obj.style.display = "none"
    }
    else {
        obj.style.display = ""
    }
}


document.onkeydown = fn_keyhandler;
		function tabOrEnter(objeto){
			retorno=13;
			if(objeto){
				if(objeto.type=="text" || objeto.type=="label" || objeto.type=="password" || objeto.type=="comboBox" || objeto.type!="textarea"){
					retorno=9;
				}
				if(objeto.style){
					if(objeto.style.keyEnter){
						retorno=0;
					}
				}
			}
			
			return retorno;
		}
		
		function fn_keyhandler() 
		 {
		 	var e = window.event;

			var targ;
			var form;
			k = window.event.keyCode;
			
			if (e.target) 
				targ = e.target;
			else 
				if (e.srcElement){
					targ = e.srcElement;
					form = e.srcElement.form;
				}
		 	 if (window.event) {
		     	if(window.event.keyCode==13){
		     		e.keyCode=tabOrEnter(targ);
					if(e.keyCode!=13 && e.keyCode!=0){
						
						if(targ){
							if(!targ.onClick || targ.keyEnter){
								window.event.keyCode=9;				
							}
						}
					}
		     		
		     	}
		         
		     }
		    return true;
		 } 
 
 
