function dom(elm) { return document.getElementById(elm); }
function dov(elm) { if (!dom(elm)) alert('Error en tiempo de ejecucion! No existe el elemento ' + elm); return dom(elm).value; }
function doc(elm) { return dom(elm).checked; }
function replace(texto, s1, s2) { return texto.split(s1).join(s2); }
function cerrar(elm) { dom(elm).parentNode.removeChild(dom(elm)); }
var emfilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var telfilter = /^([689]{1})+([0-9]{8})+$/;
var cpfilter = /^([0-9]{5})+$/;
var depfilter = /^([RCTS]{1})+$/;

function xmlobj()
	{
	if (window.XMLHttpRequest) return new XMLHttpRequest(); else if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP"); else { alert('No se pudo crear el objeto XML'); return false; }
	}

var iWidth = '';
onload = function() { var iWidth = window.innerWidth?window.innerWidth:document.body.offsetWidth; }
onresize = function() { var w = window.innerWidth?window.innerWidth:document.body.offsetWidth; if (w == iWidth) return; iWidth = w; if(dom('pr_tabla')) { cerrar('pr_tabla'); presentacion(); } }

var presentacion = function ()
	{
	/*
	Control de presentación
	2009 - Gustavo Durán
	2009 - Grupo Lehmberg
	*/
	if (dom('pr_tabla') == undefined) var tbl = pr_creaTabla(); else var tbl = dom('pr_tabla');	
	if (tbl == undefined) return;
	// Restablecer color de fondo
	for (r=0; r<4; r++) for (c=0; c<30; c++) tbl.rows[r].cells[c].style.backgroundColor = '#336';
	// Colorear celdas del lado izquierdo de la tabla
	for (r=0; r<4; r++) { rnd = 8 * Math.random(); for (c=0; c<18 + rnd; c++) tbl.rows[r].cells[c].style.backgroundColor = '#366'; tbl.rows[r].cells[c].style.backgroundColor = '#588'; tbl.rows[r].cells[c+1].style.backgroundColor = '#8BB'; tbl.rows[r].cells[c+3].style.backgroundColor = '#AFF'; }
	}

var pr_creaTabla = function ()
	{
	/*
	Generador de cuadrados en cabecera
	2009 - Gustavo Durán
	2009 - Grupo Lehmberg
	*/
	// Alto máximo desde el borde superior de la página
	var h = dom('lh_head').offsetHeight - 10;
	// Ancho máximo, calculado
	var w = window.innerWidth?window.innerWidth:document.body.offsetWidth;
	w = (w<780)?780:w;
	// Si es Firefox, quitar el ancho de una columna
	if (navigator.userAgent.indexOf('MSIE') == -1) w -= h/4;
	// Elemento contenedor
	var cont = dom('lh_head');
	// Calcular dimensiones de los cuadrados (para 5 filas)
	var sq = h/4;
	// Calcular cantidad de columnas
	var col = Math.floor(w/sq);
	
	// Crear tabla
	var tbl = document.createElement('table');
	tbl.id = 'pr_tabla';
	tbl.style.position = 'absolute'; 
	tbl.style.left = 0;
	tbl.style.top = 0;
	tbl.style.zIndex = 10;
	tbl.style.backgroundColor = '#FFF';
	tbl.style.width = w + 'px';
	cont.appendChild(tbl);
	// Dibujar filas y columnas
	for (r=0; r<4; r++) { row = tbl.insertRow(r); for (c=0; c<col; c++) { cell = row.insertCell(c); cell.id = 'r' + r + 'c' + c; cell.innerHTML = ' '; cell.style.width = sq + 'px'; cell.style.height = sq + 'px'; cell.style.backgroundColor = '#336'; } }
	return tbl;
	}

function envia()
	{
	var frm = document.forms.contacta;
	if (!depfilter.test(frm.dept.value)) { alert('Elija un departamento'); return false; }
	if (frm.nombre.value == '' || frm.nombre.value == 'Introduzca su nombre') { alert('Introduzca su nombre'); return false; }
	if (!emfilter.test(frm.mail.value )) { alert('Introduzca una dirección de correo electrónico'); return false; }
	if (frm.tel.value != '' && !telfilter.test(frm.tel.value )) { alert('Introduzca un teléfono correcto'); return false; }
	if (frm.mensaje.value == '' || frm.mensaje.value == 'Escriba su consulta') { alert('Escriba el mensaje'); return false; }
	return true;
	}

function limpiar() { var frm = document.forms.contacta; frm.nombre.value = ''; frm.mail.value = ''; frm.tel.value = ''; frm.mensaje.value = ''; return false; }

function ch_dept()
	{
	if (!dom('dept')) return;
	if (dov('dept') == 'R') dom('pan_rrhh').style.display = 'block';
	else dom('pan_rrhh').style.display = 'none';
	}

var RecaptchaOptions = { theme : 'white', lang : 'es' };
