﻿// JScript File M Berrueta



function pageWidth() 
{
	return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;
}
	
	
function pageHeight() 
{
	return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;
}
		

function posLeft() 
{
	return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;
}
		
function posTop()
{
	return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;
}
			
function viewWait(){			

var p = 'px';

var h = pageHeight();
var w = pageWidth();
var t = posTop();
var l = posLeft();

var ModalDiv = document.getElementById('ModalDiv');			
	ModalDiv.style.height=  '2000'+p;
	ModalDiv.style.width=   '2000'+p;	
    ModalDiv.style.display = 'block';

var WaitDiv = document.getElementById('WaitDiv');			

	WaitDiv.style.top=     (t+ h/2 ) +p;
	WaitDiv.style.left=    (l+ w/2 ) +p;
    WaitDiv.style.display = 'block';

}





function ValidarKeyUp(control, validador){

var txt = document.getElementById(control);
var valid = document.getElementById(validador);

  
    if ( txt.value.length == 0 )
    {    
     valid.innerHTML = '*';
    }
    else
    {
      valid.innerHTML = '';
    }  
   
}

function ValidarDDL (control , validador){

var ddl = document.getElementById(control);
var valid = document.getElementById(validador);

    if ( ddl.value == 0 )
    {    
     valid.innerHTML = '*';
    }
    else
    {
      valid.innerHTML = '';
    }  


}

function ValidarPerderFoco (control, validador){

var control = document.getElementById(control);
var valid = document.getElementById(validador);
   
    if ( ( control.value.length == 0 ) )
    {    
            valid.innerHTML = '*';
    }
        else
    {
    valid.innerHTML = '';
    }
}





function ValidarForm(BotonOcultar){
    var flag = true;
    var btn = document.getElementById(BotonOcultar);
    listaValid = new Array();
		
		if (document.all)//si es IE
		{
		//Esta separado porque IE no reconoce getElementByName
		//Lo guarda en un atributo
		listaTMP = new Array();	
		listaTMP = document.getElementsByTagName('label');
		   
		        for(i = 0; i < listaTMP.length; i++)
		        {	        	 
		            if ( listaTMP[i].attributes) 
		            {
		        	    for( var x = 0; x < listaTMP[i].attributes.length; x++ ) {
						    if( listaTMP[i].attributes[x].nodeName.toLowerCase() == 'name' )
				 	    {
					 	    var y = document.getElementById(listaTMP[i].id);
		    
				            if( y.innerHTML == '*' )
				            {
					            flag = false;
				            }
					    }
				    }
		        }
		     }
		}
        else
        {
			listaValid = document.getElementsByName('reqFieldValidator');
			 for (i = 0; i < listaValid.length; i++)
			{
			    if( listaValid[i].innerHTML == '*' )
			    {
			        flag = false;
			    }
			}   
        }

	//Si todos estan OK
    if(flag) {
      btn.style.display = 'inline';
      return true;
    }
    else
    {
      btn.style.display = 'none';
      return false; 
    }
        	
}

 
 
function resetear(BotonOcultar){

listaValid = new Array();
listaValid = document.getElementsByName('reqFieldValidator');

		for (i = 0; i < listaValid.length; i++)
		{
		    listaValid[i].innerHTML == '*'	;		
		}		
}


function permitirSoloNumero(evento){

var	tecla = (document.all) ? evento.keyCode : evento.which; //para compatibilidad
   
   if ( ( tecla == 8 ) || ( tecla == 9 ) || ( tecla == 0 ))//backspace o tab H, o tab V
      return true;
       
 
   if (( tecla > 47 ) && (tecla< 58 ) ){ //numero entre 0 y 9
   return true;
   }
   else
   {
   return false;
   }
   
   
}

function permitirSoloTelefono (evento){

var	tecla = (document.all) ? evento.keyCode : evento.which; //para compatibilidad
   
   if ( ( tecla == 8 ) || ( tecla == 9 ) || ( tecla == 0 )|| ( tecla == 45 )|| ( tecla == 40 )|| ( tecla == 41 ))//backspace, tab H, tab V,-,(,)
      return true;
       
 
   if (( tecla > 47 ) && (tecla< 58 ) ){ //numero entre 0 y 9
   return true;
   }
   else
   {
   return false;
   }
   
   
}




function mostrarCalendar (calendar){

var calendar = document.getElementById(calendar); 
calendar.style.display = 'inline'; 
//calendar.style.left = posX+'px' ; 
//calendar.style.top = posY+'px' ; 


}


 function validarEmail(control, validador) {
 
    var control = document.getElementById(control);
    var valid = document.getElementById(validador);
   
    if ( /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(control.value) )
        {    
                valid.innerHTML = '';
                return true;
        }
            else
        {
                valid.innerHTML = '*';
                return false;
        }
    
    
 }
 
 
 
 //NO ANDAAAAAA
function validarFormLoad(BotonOcultar){
    var formInvalido = true;
    var btn = document.getElementById(BotonOcultar);
    listaValid = new Array();
		
		//trae todo los validadores
			if (document.all)//si es IE
			{
			//Esta separado porque IE no reconoce getElementByName
			//Lo guarda en un atributo
			listaTMP = new Array();	
			listaTMP = document.getElementsByTagName('label');
			   
			        for(i = 0; i < listaTMP.length; i++)
			        {	        	 
			            if ( listaTMP[i].attributes) 
			            {
			        	    for( var x = 0; x < listaTMP[i].attributes.length; x++ ) {
							    if( listaTMP[i].attributes[x].nodeName.toLowerCase() == 'name' )
						 	    {
							 	    var y = document.getElementById(listaTMP[i].id);
				    				listaValid.push(y)
							    }
						    }
				        }
				     }
			}
	        else
	        {
				listaValid = document.getElementsByName('reqFieldValidator');
	        }
        
        
      //por cada validador  
      for (i = 0; i < listaValid.length; i++)
		{
			//trae el txt o ddl asociado al validador
			var txt = document.getElementById(listaValid[i].htmlFor)
			var	esInvalido = true;
		    
		    //si lo trajo
		    if (txt)
		    {
		    	if(txt.value.length){
		    		//si es un txtbox
		    		esInvalido = (txt.value.length==0);
		    	}
		    	else
		    	{
		    		//si es un ddl
		    		esInvalido = (txt.value==0);	    	
		    	}
		    }
		    
		    if(esInvalido)
	    		{
	    			listaValid[i].innerHTML == '*';
	    		}
	    		else
	    		{
	    			listaValid[i].innerHTML == '';
	    		}
			}   
			
			   

	//Si todos estan OK
    if(formInvalido) {
      btn.style.display = 'inline';
      return true;
    }
    else
    {
      btn.style.display = 'none';
      return false; 
    }
        	
}
