
/********* FUNCIONES GENERALES ***********/

function getFecha(){
    var dayNames = new Array("Domingo", "Lunes","Martes","Miercoles","Jueves","Viernes","Sabado");
    var monthNames = new Array( "Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
    var now = new Date();

    thisYear = now.getYear();
    if(thisYear < 1900) {thisYear += 1900}; // corrections if Y2K display problem
    document.write(dayNames[now.getDay()] + ", " + now.getDate() + " de " + monthNames[now.getMonth()] + " de " + thisYear);        
}

/****/

function validateEmail(strEmail) 
{ 

	 var at="@";
	 var dot="."; 
	 var lat=strEmail.indexOf(at);
	 var lstr=strEmail.length;

	 ldot=strEmail.indexOf(dot);

	 if (strEmail.indexOf(at)==-1) {
	     return false;
     }

	if (strEmail.indexOf(at)==-1 || strEmail.indexOf(at)==0 || strEmail.indexOf(at)==lstr){
		return false;
	} 

	if (strEmail.indexOf(dot)==-1 || strEmail.indexOf(dot)==0 || strEmail.indexOf(dot)==lstr){
		return false;
	} 

	if (strEmail.indexOf(at,(lat+1))!=-1){
	   return false;
	} 

	if (strEmail.substring(lat-1,lat)==dot || strEmail.substring(lat+1,lat+2)==dot){ 
       return false;
	} 

	if (strEmail.indexOf(dot,(lat+2))==-1){ 
		return false; 
	}

	if (strEmail.indexOf(" ")!=-1){ 
		return false;
	 }
	
	return true;

}

/********* FUNCIONES DE COMPORTAMIENTO ***********/

function limita(area_texto,max)
{
    if(area_texto.value.length>=max){
        area_texto.value=area_texto.value.substring(0,max-1);
    }
}

function swapImage(element,source) { 
    var img;
    img = document.getElementById(element)
    img.src=source;
}

function trim(TRIM_VALUE){
    if(TRIM_VALUE.length < 1){
       return"";
    }
    TRIM_VALUE = rtrim(TRIM_VALUE);
    TRIM_VALUE = ltrim(TRIM_VALUE);
    if(TRIM_VALUE==""){
        return "";
    }
    else{
        return TRIM_VALUE;
    }
} //End Function

function rtrim(VALUE){
    var w_space = String.fromCharCode(32);
    var v_length = VALUE.length;
    var strTemp = "";
    if(v_length < 0){
        return"";
    }
    var iTemp = v_length -1;

    while(iTemp > -1){
        if(VALUE.charAt(iTemp) == w_space){}
        else{
            strTemp = VALUE.substring(0,iTemp +1);
        break;
        }
        iTemp = iTemp-1;
    }
    
    return strTemp;
}

function ltrim(VALUE){
    var w_space = String.fromCharCode(32);
    if(v_length < 1){
        return"";
    }
    var v_length = VALUE.length;
    var strTemp = "";
    var iTemp = 0;

    while(iTemp < v_length){
        if(VALUE.charAt(iTemp) == w_space){}
        else{
            strTemp = VALUE.substring(iTemp,v_length);
            break;
        }
        iTemp = iTemp + 1;
    }
    
    return strTemp;
}

/****/

function openWindow(url,nombre,caracteristicas) {
  window.open(url,nombre,caracteristicas);
}


/********* FUNCIONES ESPECIALES ***********/

function resizeElements() {

    if (document.getElementById) {
        
        /*ASIGNAR ALTO DE CONTENIDO*/
        var windowHeight=getWindowHeight();        
        
        if (windowHeight>0) {
        
            var contentElement=document.getElementById('bloque_central');
            var contentLeft=document.getElementById('bloque_left');
            var contentRight=document.getElementById('bloque_right');
                       
            var headerHeight=document.getElementById('page_header').offsetHeight;
            var footerHeight=document.getElementById('page_footer').offsetHeight;
            var contentHeight=document.getElementById('bloque_central').offsetHeight;
                         
            if ((windowHeight-(headerHeight + footerHeight + contentHeight))>=0) {
                contentElement.style.height= windowHeight - headerHeight - footerHeight + 'px';
            } 
            
            /*AJSUTAR alto de sombreados laterales*/
            var contentLeftHeight=document.getElementById('bloque_left_menu').offsetHeight;
            var contentRightHeight=document.getElementById('bloque_right_publicidad').offsetHeight;
            
            var patternLeft=document.getElementById('bloque_left_pattern');
            var patternRight=document.getElementById('bloque_right_pattern');
            
            patternLeft.style.height= contentElement.offsetHeight - contentLeftHeight + 'px';
            patternRight.style.height= contentElement.offsetHeight - contentRightHeight + '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;

}

/****/

activateMenu = function (nav) {

    //currentStyle restricts the Javascript to IE only
	if (document.all && document.getElementById(nav).currentStyle) {  
        var navroot = document.getElementById(nav);
        
        //Get all the list items within the menu 
        var lis=navroot.getElementsByTagName("LI");  
        for (i=0; i<lis.length; i++) {
        
           // If the LI has another menu level 
            if(lis[i].lastChild.tagName=="UL"){
            
                // assign the function to the LI 
             	lis[i].onmouseover=function() {	
                
                   // display the inner menu 
                   this.lastChild.style.display="block";
                   this.lastChild.style.overflow="visible";
                   
                }
                lis[i].onmouseout=function() {                       
                   this.lastChild.style.display="none";
                }
            }
        }
    }
}

/********* EVENTOS GENERALES ***********/

window.onload = function() {  
  activateMenu('nav'); 
  resizeElements();  
}

/****/

window.onresize = function() {
  resizeElements();  
}
