var MSG_BOX = "";

function msg(Mensaje) {
	alert(MSG_BOX);
	if (MSG_BOX) {
		try {
			MSG_BOX.innerHTML = Mensaje;
		} catch (e) {
			if (Mensaje) alert(Mensaje);
		}
	} else alert(Mensaje);
}

function urlencode(str) 
{
    var result = "";
    for (i = 0; i < str.length; i++) {
        if (str.charAt(i) == " ") result += "+";
        else result += str.charAt(i);
    }
    return escape(result);
}

function onLoadInit()
{
	fixTables();
	// Dejo lo de abajo comentado por si hay que abrir otro banner en otro momento
	//if (SECCION == "home")
       showMainBanner();
}


function urldecode(str) 
{    
    var result = str.replace(/\+/g, " ");
    return unescape(result);
}

function isEmail(elemento)
{
	var valor = elemento.value;
	var filtro=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if (filtro.test(valor))
		return true;
	else
		return false;
}

function calcularAlto(){
	var content = document.getElementById('cuerpo'); // tabla que tiene todo el contenido
	var altoContent = content.offsetHeight;
	
	var contenido = document.getElementById('medio'); //tabla del medio
	var altoContenido = contenido.offsetHeight;
	
	//calculo el alto de la tabla de relleno
	var altoRelleno = altoContent - altoContenido;

	var tdRelleno = document.getElementById('relleno');
	tdRelleno.height = altoRelleno+20;
}



function showMainBanner()
{

        if($('overlay')){
            $('overlay').show();
            var my_div = document.createElement("div");
            document.body.appendChild(my_div);
            my_div.id = my_div.name = 'div_banner';
            new Ajax.Updater(my_div, RUTA+"_banners/freeway_2010.html");
            centrarBanner($('div_banner'));
            setTimeout(oasfechar, 50000);
   }
}

function closebanner (){
	$('overlay').hide();
	$('div_banner').hide();
}
function oasfechar()
{
	var objList = $$('object');  
	for(var i=0; i<objList.length; i++){
		objList[i].show();
	}
	$('overlay').hide();
	$('div_banner').hide();
}


function centrarBanner(element)
{
	element.style.position = 'absolute';
	element.style.zIndex   = 999999999;
	
	var top_1 = getWindowHeight()/2 - 450/2;
	if (top_1 <= 150) top_1 = 150;
	element.style.top = top_1;
	element.style.left = getWindowWidth()/2 - 500/2;
	
	var scrollY = 0;
	if ( document.documentElement && document.documentElement.scrollTop ){
	    scrollY = document.documentElement.scrollTop;
	}else if ( document.body && document.body.scrollTop ){
	    scrollY = document.body.scrollTop;
	}else if ( window.pageYOffset ){
	    scrollY = window.pageYOffset;
	}else if ( window.scrollY ){
	    scrollY = window.scrollY;
	}
	
	if (scrollY > 0) document.body.scrollTo(); 	
}

// Alto de la Pagina
function getWindowHeight() {

	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

// Ancho de la Pagina
function getWindowWidth() {

	var windowWidth = 0;
	if (typeof(window.innerWidth) == 'number') {
		windowWidth = window.innerWidth;
	}
	else {
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			if (document.body && document.body.clientWidth) {
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}
