function MM_reloadPage(init) {  //reloads the window if Nav4 resized 
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) { 
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }} 
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload(); 
} 
MM_reloadPage(true); 

function cerrar() { 
var ventana = window.self; 
ventana.opener = window.self; 
ventana.close(); 
} 

function ayuda(xpagina) { 
w = screen.availWidth - 10;
h = screen.availHeight - 30;
params = "resizable = 0,left=0,top=0,scrollbars = 1,screenX=0,screenY=0";
params = params + ",width="+w;
params = params + ",height="+h;

var msg = "http://www.invima.gov.co/version1/ayudas/tutorialfinal/"+xpagina; 
vayuda = window.open(msg,"ayuda",params);
vayuda.focus;
return true;
}

var message="Sistema de tramites en linea";

///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("alert(message);return false")

document.onkeydown = mykeyhandler;
function mykeyhandler(e) {
if(!e)e = window.event;
var key = (typeof e.which == 'number')?e.which:e.keyCode;

if (e.altKey) 
  if(key==37 || key==39){
     alert("Función no permitida")
     return false;
  }
if (e.ctrlKey) 
  if(key==78 || key==85){
     alert("Función no permitida")
     return false;
  }

  if (key == 27) {
     window.event.cancelBubble = true;
     window.event.returnValue = false;
     return false;
  }

  if (key == 116 || key == 122 || key == 114 || key == 117) {
     window.event.cancelBubble = true;
     window.event.keyCode = 8; 
     window.event.returnValue = false;
     return false;
  }
}

function mykeyhandler8(e) {
if(!e)e = window.event;
var key = (typeof e.which == 'number')?e.which:e.keyCode;

if (e.altKey)
  if(key==37 || key==39){
     alert("Función no permitida")
     return false;
  }
if (e.ctrlKey)
  if(key==78 || key==85){
     alert("Función no permitida")
     return false;
  }

  if (key == 27) {
     window.event.cancelBubble = true;
     window.event.returnValue = false;
     return false;
  }

  if (key == 8) {
     window.event.cancelBubble = true;
     window.event.keyCode = 8; 
     window.event.returnValue = false;
     return false;
  }

  if (key == 116 || key == 122 || key == 114 || key == 117) {
     window.event.cancelBubble = true;
     window.event.keyCode = 8; 
     window.event.returnValue = false;
     return false;
  }
}

function printPage2() {
var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 
document.forms[0].imprimir.visible = false;
  if (pr) // NS4, IE5
    window.print()
  else if (da && !mac) // IE4 (Windows)
    vbPrintPage()
  else // other browsers
    alert("No soportado por este navegador");
  document.forms[0].imprimir.visible = true;
  return true;
}

function fvalidar_fecha(aniof,mesf,diaf) {
var anio1 = parseInt(aniof,10);
var mes1 = parseInt(mesf,10);
var dia1 = parseInt(diaf,10);
var numeros = "0123456789";
var ffecha = parseInt((anio1 * 365)+(mes1 * 30)+dia1,10);
	if (isNaN(aniof) || aniof == "" ) { 
		return "Ingrese año valido"; 
	} 
	if (isNaN(mesf) || mesf == "" ) { 
		return "Ingrese mes valido"; 
	} 
	if (isNaN(diaf) || diaf == "" ) { 
		return "Ingrese dia valido"; 
	} 

        longitud = diaf.length;
        for (t1=0;t1<longitud;t1++) {
          c = diaf.substring(t1,t1+1);
  	      if (numeros.indexOf(c,0) < 0 ) { 
      	    return "El dia no debe contener caracteres diferentes a <0 - 9>"; 
      	  } 
        }
        longitud = mesf.length;
        for (t1=0;t1<longitud;t1++) {
          c = mesf.substring(t1,t1+1);
  	      if (numeros.indexOf(c,0) < 0 ) { 
      	    return "El mes no debe contener caracteres diferentes a <0 - 9>"; 
      	  } 
        }
        longitud = aniof.length;
        for (t1=0;t1<longitud;t1++) {
          c = aniof.substring(t1,t1+1);
  	      if (numeros.indexOf(c,0) < 0 ) { 
      	    return "El año no debe contener caracteres diferentes a <0 - 9>"; 
      	  } 
        }
 if (aniof.length < 4 ){
		 return "El año debe llevar 4 digitos";
}
if (mes1 < 1 || mes1 > 12 ){
		 return "Mes no corresponde";
}
if (dia1 < 1 || dia1 > 31 ){
		 return "Dia no corresponde";
}
if (mes1 == 4 || mes1 == 6 || mes1 == 9 || mes1 == 11 ){
if (dia1 > 30 )
		 return "Dia no corresponde";
}
if (mes1 == 2){
if ((anio1 % 4) > 0) {
  if (dia1 > 28 )
		 return "Dia no corresponde";
}
else
  if (dia1 > 29 )
		 return "Dia no corresponde";
}
return "";
}

function fdifer_fecha(fechaf,dhoy,revisar) {
var aniox = parseInt(dhoy.substring(0,4),10);
var mesx = parseInt(dhoy.substring(5,7),10);
var diax = parseInt(dhoy.substring(8),10);
var anio1 = parseInt(fechaf.substring(0,4),10);
var mes1 = parseInt(fechaf.substring(5,7),10);
var dia1 = parseInt(fechaf.substring(8),10);

var fhoy = parseInt((aniox * 365)+(mesx * 30)+diax,10);
var ffecha = parseInt((anio1 * 365)+(mes1 * 30)+dia1,10);
if (revisar == "A") {
if (ffecha > fhoy){
		 return "La fecha no puede superar el dia de hoy";
		 }
     }
if (revisar == "D") {
if (ffecha < fhoy){
		 return "La fecha no puede ser inferior al dia de hoy";
		 }
     }
if (revisar == "M") {
if (ffecha < (fhoy - 30)){
		 return "La fecha no puede ser inferior al ultimo mes (maximo 30 dias atras)";
		 }
     }
return "";
}

