function posicionar_modelo(ID)
{
	xajax_poner_modelo_virtual_en(ID);
}

function previzualizar_modelo(Cual)
{
  var posicion=document.getElementById('CBUbicacionV').value;
  switch(Cual)
  {
	case "1":location.href="panel.php?MVV=1&posMVV="+posicion;
	         break;
	case "2":location.href="panel.php?MVV=2&posMVV="+posicion;
	         break;
	case "3":location.href="panel.php?MVV=3&posMVV="+posicion;
	         break;
  }
}




function dar_formato_mensaje(cuerpo)
{
	var pie='\n-------------------------------------------------------';
	var encabezado='Errores encontrados:\n';
	encabezado+='-------------------------------------------------------\n';
	return encabezado+cuerpo+pie;
}

function tiene_letras(texto){
   var letras="abcdefghyjklmnñopqrstuvwxyz";
   texto = texto.toLowerCase();
   for(i=0; i<texto.length; i++){
      if (letras.indexOf(texto.charAt(i),0)!=-1){
         return 1;
      }
   }
   return 0;
} 


function validar_campo(forma,campo,tipo,obligatorio,contenido)
{
  var validado="";
  
  if(tipo=="texto")
  {
	if(obligatorio==true) 
	{
       	if(document.forms[forma].elements[campo].value.length>0)
		{  		   
		  if(contenido=='N')	
     	  {
		     if (!isNaN(document.forms[forma].elements[campo].value) )
		     {  validado="";  }	
			 else{ validado="*El dato "+document.forms[forma].elements[campo].title+" debe ser numerico.\n";	}
	      }	  
	      if(contenido=='A')	
	      {
		     if(tiene_letras(document.forms[forma].elements[campo].value)==1)
		     {  validado=""; }
			 else{ validado="*El dato "+document.forms[forma].elements[campo].title+" debe ser alfabetico.\n"; }
	      }	
		  if(contenido=='email')
		  {
			 if(validar_correo(document.forms[forma].elements[campo].value))  
			 {  validado=""; }
			 else { validado="*El dato "+document.forms[forma].elements[campo].title+" no es un formato valido.\n"; }
			 
		  }
		 
		  if(contenido=='AN')
		  {
			  if(verificar_caracteres(document.forms[forma].elements[campo].value))
			  { validado=""; }
			 else { validado="*El dato "+document.forms[forma].elements[campo].title+" contiene caracteres no validos.\n Solo se permiten A-Z, a-z, 0-9 y _ \n"; }
		  }
		  
		}
		else
		{  
		  validado="*Falta introducir el dato obligatorio: "+document.forms[forma].elements[campo].title+".\n";
	    }
		
	}
	else
	{
		  if(contenido=='N')	
     	  {
		     if (!isNaN(document.forms[forma].elements[campo].value) )
		     {  validado="";  }	
			 else{ validado="*El dato "+document.forms[forma].elements[campo].title+" debe ser numerico.\n";	}
	      }	  
	      if(contenido=='A')	
	      {
		     if(tiene_letras(document.forms[forma].elements[campo].value)==1)
		     {  validado=""; }
			 else{ validado="*El dato "+document.forms[forma].elements[campo].title+" debe ser alfabetico.\n"; }
	      }		 
		    if(contenido=='email')
		  {
			 if(validar_correo(document.forms[forma].elements[campo].value))  
			 {  validado=""; }
			 else { validado="*El dato "+document.forms[forma].elements[campo].title+" no es un formato valido.\n"; }
			 
		  }
		    if(contenido=='AN')
		  {
			  if(verificar_caracteres(document.forms[forma].elements[campo].value))
			  { validado=""; }
			 else { validado="*El dato "+document.forms[forma].elements[campo].title+" contiene caracteres no validos.\n Solo se permiten A-Z, a-z, 0-9 y _ \n"; }
			  
		  }
    }	
  }
  
  if(tipo=="checkbox")
  {
    if(document.forms[forma].elements[campo].checked==true) 
	{		
	 if(contenido=='DATE')
	 {
		
		if(document.forms[forma].elements['ERFI'].value.length>0)
		{
		   if(ValidaFecha(document.forms[forma].elements['ERFI'].value)=='')
		   {
		 validado+="*Dato no valido de: "+document.forms[forma].elements['ERFI'].title+".\n";
           }
		}
		else
		{
		 validado+="*Falta introducir el dato obligatorio: "+document.forms[forma].elements['ERFI'].title+".\n";
		}
		
		if(document.forms[forma].elements['ERFF'].value.length>0)
		{
		   if(ValidaFecha(document.forms[forma].elements['ERFF'].value)=='')
		   {
		 validado+="*Dato no valido de: "+document.forms[forma].elements['ERFF'].title+".\n";
           }
		}
		else
		{
		 validado+="*Falta introducir el dato obligatorio: "+document.forms[forma].elements['ERFF'].title+".\n";
		}
		
		
	}
	}
  }

  if(tipo=="combobox")
  {
	if(obligatorio==true) 
	{
		if(!isNaN(document.forms[forma].elements[campo].value))
		{												 
		   if(document.forms[forma].elements[campo].value==-1)
		   {
	     	 validado+="*Falta seleccionar la opcion de: "+document.forms[forma].elements[campo].title+".\n";
           }
		}
		else
		{
		   if(document.forms[forma].elements[campo].value=='')
		   {
	     	 validado+="*Falta seleccionar la opcion de: "+document.forms[forma].elements[campo].title+".\n";
           }
		}
	}
  }
  
  if(tipo=="fecha")
  {
    if(obligatorio==true) 
	{
        if(document.forms[forma].elements[campo].value.length>0)
		{
		   if(ValidaFecha(document.forms[forma].elements[campo].value)=='')
		   {
		 validado+="*Dato no valido de: "+document.forms[forma].elements[campo].title+".\n";
           }
		}
		else
		{  
		  validado="*Falta introducir el dato obligatorio: "+document.forms[forma].elements[campo].title+".\n";
	    }
	}
	else
	{
		if(document.forms[forma].elements[campo].value.length>0)
		{
		   if(ValidaFecha(document.forms[forma].elements[campo].value)=='')
		   {
		 validado+="*Dato no valido de: "+document.forms[forma].elements[campo].title+".\n";
           }
		}		
	}
  }  
return validado;
}

function seleccion_fila(src,clase) { 
	src.className=clase; 
} 


function marcar_fila(De)
{

 De.onmouseover = function() {  
 }
 De.onmouseout = function() {  
 }
 De.className='filaMarcada';
}

function activar_casilla()
{

if (document.forms.length > 0) {
var field = document.forms[0];
for (i = 0; i < field.length; i++) {
if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
document.forms[0].elements[i].focus();
break;
         }
      }
   }

}

function Ajustar_frame_datos()
{
  var dimension = window.getSize();	
  document.getElementById('Datos').width=(screen.availWidth)-40;
  document.getElementById('Datos').height=dimension.y-50;
}

function Ajustar_frame_datos_modulo()
{
  var dimension = window.getSize();	
  document.getElementById('Datos').width=(screen.availWidth)-40;
  document.getElementById('Datos').height=dimension.y-79;
}

function verificar_caracteres(cadena)
{
   var valido=true;
   var letras="./'+*%$#!º&()?¡¿=-,[]{}|´^\\`";
   for(i=0; i<cadena.length; i++){
      if (letras.indexOf(cadena.charAt(i),0)!=-1){
         valido=false;
      }
   }
   return valido;
}

function validar_correo(Correo)
{
     var valido=false;
	 var s = Correo;
     var filter=/^[A-Za-z][A-Za-z0-9_.]*@[A-Za-z0-9_-]+\.[A-Za-z0-9_.]+[A-za-z]$/;
     if (filter.test(s))			 
	 {
       valido=true;
     }      
	 return valido;
}

function validar_url(ruta)
{
 var valido=false;
 var filter=/^w{3}.$/;
 //[a-zA-Z0-9].([a-zA-Z]){2,3}(.([a-zA-Z])(2,3)?
     if(filter.test(ruta))			 
	 {
       valido=true;
     }      
	 return valido;
}

function Maximizar_ventana()
{

window.moveTo(0,0);
if (document.all) {
top.window.resizeTo(screen.availWidth,screen.availHeight);
}
else if (document.layers||document.getElementById) {
if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
top.window.outerHeight = screen.availHeight;
top.window.outerWidth = screen.availWidth;
}
}

}


function comparar_pass(forma,campo1,campo2)
{
  var validado="";

    if(document.forms[forma].elements[campo1].value!=document.forms[forma].elements[campo2].value)
	{
	  validado="*La contrase\361a de confirmacion no corresponde a la inicial.\n";	
	}
  return validado;	
}


function ValidaFecha(caja)
		{ 
		   if (caja.value!='')
		   {  
		      borrar = caja;
		      if ((caja.substr(2,1) == "/") && (caja.substr(5,1) == "/"))
		      {      
        		 for (i=0; i<10; i++)
			     {	
        		    if (((caja.substr(i,1)<"0") || (caja.substr(i,1)>"9")) && (i != 2) && (i != 5))
					{
        		       borrar = '';
		               break;  
					}  
		         }
	    		 if (borrar)
			     { 
	    		    a = caja.substr(6,4);
				    m = caja.substr(3,2);
				    d = caja.substr(0,2);
				    if((a < 1900) || (a > 2100) || (m < 1) || (m > 12) || (d < 1) || (d > 31))
				       borrar = '';
				    else
				    {
				       if((a%4 != 0) && (m == 2) && (d > 28))	   
				          borrar = ''; // Año no viciesto y es febrero y el dia es mayor a 28
					   else	
					   {
		        		  if ((((m == 4) || (m == 6) || (m == 9) || (m==11)) && (d>30)) || ((m==2) && (d>29)))
					         borrar = '';	      				  	 
					   }  // else
				    } // fin else
		         } // if (error)
		      } // if ((caja.substr(2,1) == \"/\") && (caja.substr(5,1) == \"/\"))			    			
			  else
			     borrar = '';
		     return borrar;
		   } // if (caja)   
		} // FUNCION
