
/********* 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 openWindow(url,nombre,caracteristicas) {
  window.open(url,nombre,caracteristicas);
}
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 fCompartir(estado) {        

    if (estado==true){
        document.getElementById('compartir_bungalow').style.visibility="visible";    
    }else{
        document.getElementById('compartir_bungalow').style.visibility="hidden";    
    }
}

function fCalcularCompartir() {        
 
    var f = document.getElementById('formulario');
    var adultos = radioValue(f.npersonas);
    var ninos = radioValue(f.ninos);
                
    if (adultos==3){                   
        document.getElementById('compartir_bungalow').style.visibility="hidden";
        document.getElementById('nino').style.visibility="hidden";
        f.ninos[0].style.visibility = "hidden"; 
        f.ninos[1].style.visibility = "hidden";      
        f.ninos[2].style.visibility = "hidden";      
        f.ninos[3].style.visibility = "hidden";     
        f.ninos[4].style.visibility = "hidden";      
        f.ninos[5].style.visibility = "hidden";         
    }

    if (adultos==2){                           
        document.getElementById('nino').style.visibility="visible";  
        f.ninos[0].style.visibility = "visible";      
        f.ninos[1].style.visibility = "visible";      
        f.ninos[2].style.visibility = "visible";      
        f.ninos[3].style.visibility = "hidden";     
        f.ninos[4].style.visibility = "hidden";      
        f.ninos[5].style.visibility = "hidden";              
    }    
    
    if (adultos==1){                           
        document.getElementById('nino').style.visibility="visible";  
        f.ninos[0].style.visibility = "visible";     
        f.ninos[1].style.visibility = "visible";      
        f.ninos[2].style.visibility = "visible";      
        f.ninos[3].style.visibility = "visible";     
        f.ninos[4].style.visibility = "visible";      
        f.ninos[5].style.visibility = "visible";             
    }      
    
    if (adultos==2 && ninos>1){                
        document.getElementById('compartir_bungalow').style.visibility="hidden";        
    }    
    
    if (adultos==2 && ninos<2){                
        document.getElementById('compartir_bungalow').style.visibility="visible";
        document.getElementById('nino').style.visibility="visible";
    }        
    
    if (adultos==1 && ninos>1){        
        document.getElementById('compartir_bungalow').style.visibility="hidden";    
        document.getElementById('nino').style.visibility="visible";
    }
    
    if (adultos==1 && ninos<2){        
        document.getElementById('compartir_bungalow').style.visibility="visible";    
        document.getElementById('nino').style.visibility="visible";
    }    
    
    resizeElements();  
        
}


/********* FUNCIONES ESPECIALES ***********/

function radioValue(radioButton)
{
    for (x = 0; x <= radioButton.length; x++)
    {
        if (radioButton[x].checked == true) return radioButton[x].value;
    }
         // if it didn't find anything, return the .value  (behaviour of single radio btn)
        return radioButton.value;
}

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 headerHeight=document.getElementById('page_header').offsetHeight;
            var footerHeight=document.getElementById('page_footer').offsetHeight;            
            var contentHeight=document.getElementById('bloque_central').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('bloque_left').offsetHeight;
            if (contentLeftHeight < contentHeight){
                contentLeft.style.height= contentHeight + '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;

}

/********* EVENTOS GENERALES ***********/

window.onload = function() {   
  resizeElements();  
}

window.onresize = function() {
  resizeElements();  
}