function DOM_siguiente(v_elemento)
{
	var siguiente=v_elemento.nextSibling;

	while(siguiente && siguiente.nodeType!=1)
	{
		siguiente=siguiente.nextSibling;
	};

	return siguiente;
}

function DOM_anterior(v_elemento)
{
	var anterior=v_elemento.previousSibling;
	
	while(anterior && anterior.nodeType!=1)
	{
		anterior=anterior.previousSibling;
	};

	return anterior;
}

function montar_elemento(tipo, clases, contenido, padre, id)
{
	var temporal=document.createElement(tipo);
	
	if(clases) temporal.className=clases;
	if(contenido) temporal.innerHTML=contenido;
	if(id) temporal.id=id;
	if(padre) padre.appendChild(temporal);

	return temporal;
}

function montar_imagen(src, title, clases, padre, id)
{
	var temporal=document.createElement('img');

	if(title)
	{
		temporal.title=title;
		temporal.alt=title;
	}
	
	if(clases) temporal.className=clases;
	if(src) temporal.src=src;
	if(id) temporal.id=id;
	if(padre) padre.appendChild(temporal);

	return temporal;
}

function montar_enlace(href, clases, contenido, padre, id, title)
{
	var temporal=document.createElement('a');
	if(title)
	{
		temporal.title=title;
		temporal.alt=title;
	}

	if(href) temporal.href=href;
	if(clases) temporal.className=clases;
	if(contenido) temporal.innerHTML=contenido;
	if(id) temporal.id=id;
	if(padre) padre.appendChild(temporal);

	return temporal;
}

function montar_input(tipo, nombre, valor, clase, id, padre)
{
	var elemento_input=null;

	switch(tipo)
	{
		case 'text':
			elemento_input=document.createElement('input');
			elemento_input.type='text';
			if(clase) elemento_input.className=clase;
			if(id) elemento_input.id=id;
			if(valor) elemento_input.value=valor;
		break;

		case 'textarea':
			elemento_input=document.createElement('textarea');
			if(clase) elemento_input.className=clase;
			if(id) elemento_input.id=id;
			if(valor) elemento_input.value=valor;
		break;

		case 'button':
			elemento_input=document.createElement('input');
			elemento_input.type='button';
			if(clase) elemento_input.className=clase;
			if(id) elemento_input.id=id;
			if(valor) elemento_input.value=valor;
		break;

		case 'submit':
			elemento_input=document.createElement('input');
			elemento_input.type='submit';
			if(clase) elemento_input.className=clase;
			if(id) elemento_input.id=id;
			if(valor) elemento_input.value=valor;
		break;

		case 'hidden':
			elemento_input=document.createElement('input');
			elemento_input.type='hidden';
			if(id) elemento_input.id=id;
			if(valor) elemento_input.value=valor;
		break;

		case 'select':
			elemento_input=document.createElement('select');
			if(id) elemento_input.id=id;
			if(valor) elemento_input.value=valor;
		break;
	}

	if(nombre) elemento_input.name=nombre;
	if(padre) padre.appendChild(elemento_input);

	return elemento_input;
}

function insertar_opcion(valor, texto, select, marcado)
{
	var opcion = document.createElement('option'); 
	opcion.value=valor;
	opcion.text=texto;
	opcion.innerText=texto;

	if(marcado) opcion.selected=true;

	select.appendChild(opcion);
}

function eliminar_contenido(elemento)
{
	while(elemento.hasChildNodes()) elemento.removeChild(elemento.childNodes[0]);

/*
Esta solución aún no está completamente cerrada... Con todo parece ser que 
bastaría con eliminar el nodo padre.
//	salir=confirm('salir?');

	if(elemento.hasChildNodes())
	{
		while(elemento.childNodes.length >= 1) // && !salir)
		{
			eliminar_contenido(elemento.childNodes[0]);
		}
	}
	else
	{
		elemento.parentNode.removeChild(elemento);
	}
*/
}

function eliminar_elemento(elemento)
{
	eliminar_contenido(elemento);
	elemento.parentNode.removeChild(elemento);
}

function crear_estilo_css(texto_css, es_archivo, v_id)
{
	if(!es_archivo)
	{
		var temp=document.createElement('style');
		temp.type="text/css";

		if(temp.styleSheet)
		{
			temp.styleSheet.cssText=texto_css;
		}
		else
		{
			temp.appendChild(document.createTextNode(texto_css));
		}
	}
	else
	{
		var temp=document.createElement('link');
		temp.rel='stylesheet';
		temp.type='text/css';
		temp.href=texto_css;
	}

	document.getElementsByTagName('head')[0].appendChild(temp);

	if(v_id) temp.id=v_id;

	return temp;
}

function detener_propagacion(evento)
{
	if(!evento)	//Para Explorer: Si no hay evento se maneja con window.Event.
	{
		var evento=window.event;
		evento.cancelBubble=true;	//También para para explorer....
		evento.returnValue=false;
	}

	if(evento.stopPropagation) 	//Y ahora para fireFox...
	{
		evento.stopPropagation();
		evento.preventDefault();
	}
}

function asociar_calendario(input, boton)
{
	boton.onclick=function()
	{
		new Selector_fecha_vf(input, boton);
	}
}


function getElementsByClassName(v_elemento, v_clase)
{
	var resultado=new Array();

	if(v_elemento.className && v_elemento.className.search(v_clase)!=-1)
	{
		resultado.push(v_elemento);
	}

	if(v_elemento.hasChildNodes())
	{
		var i;
		var l=v_elemento.childNodes.length;
		for(i=0; i<l; i++)
		{
			var encontrados=getElementsByClassName(v_elemento.childNodes[i], v_clase);
			if(encontrados instanceof Array && encontrados.length)
			{	
				resultado=resultado.concat(encontrados);
			}
		}
	}

	return resultado;
}

function obtener_dimensiones_chrome()
{
	var alto;
	var ancho;

	if(window.innerWidth) 
	{
		ancho=window.innerWidth;
		alto=window.innerHeight;
	} 
	else if(document.documentElement && document.documentElement.clientWidth) 
	{
		ancho=document.documentElement.clientWidth;
		alto=document.documentElement.clientHeight;
	} 
	else if(document.body) 
	{
		ancho=document.body.clientWidth;
		alto=document.body.clientHeight;
	}

	var resultado=Array(ancho, alto);

	return resultado;
}


