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;
	}

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

	return elemento_input;
}

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

function eliminar_contenido(elemento)
{
	if(elemento.hasChildNodes) 	
		while(elemento.childNodes.length >= 1 ) 
			elemento.removeChild(elemento.childNodes[0]);		
}

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

function crear_estilo_css(texto_css, es_archivo)
{
	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);

	return temp;
}

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;
}



//Alinea al centro el contenido
//La position debe ser absolute o fixed
function valign_center(contenedor,contenido,position)
{
    if (position != "absolute")
    {
	position = "fixed";
    }
    var altura_contenido = contenido.clientHeight;
    var centro_contenedor = contenedor.clientHeight / 2;
    contenido.style.position = position;
    contenido.style.top = centro_contenedor - altura_contenido/2;
}



//Alinea al centro el contenido
//La position debe ser absolute o fixed
function valign_center(contenedor,contenido, position)
{

    var altura_contenido = contenido.clientHeight;
    var centro_contenedor = contenedor.clientHeight / 2;
    contenido.style.position = "absolute";
    var numero_altura = centro_contenedor - altura_contenido/2;
    contenido.style.top = numero_altura + "px";
}
