/********************************************/
/******* SHOW HIDDEN ELEMENT**********/
/********************************************/
function show(item)
{
	var contenedor=document.getElementById(item)
		
	if(contenedor.style.display=='none')
	{
		contenedor.style.display='block'
	}
	else
	{
		contenedor.style.display='none'
	}
	
	resizeElements();
	
}
/********************************************/
/******* BUSCAR CONTROL TIPO INPUT **********/
/********************************************/
function findControl(ControlName)
{       
    var ret=null;
    var aControls = document.getElementsByTagName("input");
    if (aControls)
    {       
        for (var i=0; i< aControls.length ; i++)
        {
            if (aControls[i].id.lastIndexOf(ControlName) == 
                aControls[i].id.length - ControlName.length && 
                aControls[i].id.length != ControlName.length && 
                aControls[i].id.lastIndexOf(ControlName)  > 0 )
            {
                ret =aControls[i];
                break;
            }
        }
    }
    return ret;
} 
/********************************************/
/******* INTERCAMBIO DE IMAGENES ************/
/********************************************/
function swapImage(element,source) { 
    var img;
    img = document.getElementById(element);
    img.src=source;
}
/********************************************/
/******* RESIZE ELEMENTOS *******************/
/********************************************/
function resizeElements() {
    
    if (document.getElementById) {
        
        /*ASIGNAR ALTO DE CONTENIDO*/
        var windowHeight=getWindowHeight();        
        
        if (windowHeight>0) {
        
            var contentElement=document.getElementById('body_center');
            var contentLeft=document.getElementById('body_left');
            var contentRight=document.getElementById('body_right');
                                   
            var headerHeight=document.getElementById('page_header').offsetHeight;
            var footerHeight=document.getElementById('page_footer').offsetHeight;            
            var contentHeight=document.getElementById('body_center').offsetHeight;
                                   
            /*                         
            alert ("window " + windowHeight + " Pie " + footerHeight + " Cabecera " + headerHeight + " Contenido " + contentHeight);
            
            if ((windowHeight-(headerHeight + footerHeight + contentHeight))>=0) {
                contentElement.style.height= windowHeight - headerHeight - footerHeight + 'px';
            } 
            */
            
            /*AJSUTAR alto laterales*/            
            var contentLeftHeight=document.getElementById('body_left').offsetHeight ;
            var contentRightHeight=document.getElementById('body_right').offsetHeight;
                                   
            if (contentLeftHeight < contentHeight){
                contentLeft.style.height= contentHeight + 'px';
                contentRight.style.height= contentHeight + 'px';                   
            }
            
            /*alert ("Contenido " + contentHeight + " Left " + contentLeftHeight);*/
            
            if (contentLeftHeight > 410 && contentLeftHeight > contentHeight){                
                contentRight.style.height= contentLeftHeight + 'px';                   
            }            
                                                
        }               
    }
}

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;

}
/********************************************/
/******* HANDLER SUMARIO ERRORES ************/
/********************************************/
function ShowSummaryErrors()
{
    if (!Page_IsValid)
    {    
        var s = "";
        var i;
        for (i=0; i<Page_Validators.length; i++) {
            if (!Page_Validators[i].isvalid && 
                 typeof(Page_Validators[i].errormessage) == "string") {
                s += "<li>" + Page_Validators[i].errormessage + "</li>";
            }
        }
        if (s != "")
        {
            document.getElementById('errores').innerHTML = s;
            document.getElementById('error').style.display = 'block';
            resizeElements();
        }
    }
}
/********************************************/
/******* CONTROL SECCIONES ******************/
/********************************************/
function showHideDiv(id)
{    
    var status = document.getElementById(id).style.display;
    
    if (status=='none' || status=='')
    {
        document.getElementById(id).style.display = 'block';
    }
    else
    {
        document.getElementById(id).style.display = 'none';
    }
}
/********************************************/
/******* EVENTOS WINDOW *********************/
/********************************************/
window.onload = function() {   
  resizeElements();  
}

window.onresize = function() {
  resizeElements();  
}