/* mostrar y ocultar div */

function abrir_div(id,n) { 
	i=0;
	while(i < n){
		if(id == 'bt'+i){
			document.getElementById(id).className='abrir';
		}else{
			document.getElementById("bt"+i).className='cerrar';
		}
		i++;
	}
} 

/* cambiar titulo */

function toTitleCase(str) {
    return str.substr(0,1).toUpperCase() + str.substr(1);
}      
            
function formatTitle(title) {
     return 'Hecop centro de negocios' + (title != '/' ? ' / ' + toTitleCase(title.substr(1, title.length - 2).replace(/\//g, ' / ')) : '');
}

/* Cambiar contenido */
             
function getTransport() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
        	return new ActiveXObject('Msxml2.XMLHTTP');
            } catch(e) {
            return new ActiveXObject('Microsoft.XMLHTTP');
    	}
    }
}

function updateContent(html) {
                var content = document.getElementById('contenido');
                content.innerHTML = html;
                
                while (html.match(/(<script[^>]+javascript[^>]+>\s*(\/\/*<!\[CDATA\[)?(<!--)?\s*)/i)) {
                    html = html.substr(html.indexOf(RegExp.$1) + RegExp.$1.length);
                    if (!html.match(/((\/\/ *\]\]>)?(-->)?\s*<\/script>)/)) break;
                    block = html.substr(0, html.indexOf(RegExp.$1));
                    html = html.substring(block.length + RegExp.$1.length);
                    eval(block);
                }
}
            
function updateChange(xhr) {	
    if (xhr.readyState != 4) {
		document.getElementById('contenido').innerHTML='<div align="center"><img src="imagenes/ajax-loader.gif" width="220" height="19" /></div>';
	}else{
        if (xhr.status == 200) {
            updateContent(xhr.responseText);           
        } else {
            alert('Error: ' + xhr.status + '!');
        }
    }
}

/* contenido slogan */


function updateContentSlogan(html) {
                var content = document.getElementById('slogan');
                content.innerHTML = html;
                
                while (html.match(/(<script[^>]+javascript[^>]+>\s*(\/\/*<!\[CDATA\[)?(<!--)?\s*)/i)) {
                    html = html.substr(html.indexOf(RegExp.$1) + RegExp.$1.length);
                    if (!html.match(/((\/\/ *\]\]>)?(-->)?\s*<\/script>)/)) break;
                    block = html.substr(0, html.indexOf(RegExp.$1));
                    html = html.substring(block.length + RegExp.$1.length);
                    eval(block);
                }
}
            
function updateChangeSlogan(xhr) {	
    if (xhr.readyState == 4) {
        if (xhr.status == 200) {
            updateContentSlogan(xhr.responseText);           
        } else {
            alert('Error: ' + xhr.status + '!');
        }
    }
}

/* evento */

function handleChange(event) {
	
	var parameters = '';
    for (var p in event.parameters) {
        parameters += '&' + p + '=' + event.parameters[p];
    }
	var xhr = getTransport();
	xhr.onreadystatechange = function() {
		updateChange(xhr);
	}
   xhr.open('get', 'datasource.php?dir=' + event.path + parameters, true);
    xhr.send('');
    SWFAddress.setTitle(formatTitle(event.path)); 
	
	var xhrSlogan = getTransport();
	xhrSlogan.onreadystatechange = function() {
		updateChangeSlogan(xhrSlogan);
	}
	xhrSlogan.open('get', 'dataslogan.php?dir=' + event.path + parameters, true);
    xhrSlogan.send('');
}
SWFAddress.addEventListener(SWFAddressEvent.CHANGE, handleChange);           
