// JavaScript Document
function IsDigit(e)
{
	var key = window.event ? e.keyCode : e.which;
	var keychar = String.fromCharCode(key);
	reg = /[0-9]/;
	return (reg.test(keychar) || e.keyCode == 8)
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function NuevoAjax(){
var xmlhttp=false; 
	try { 
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
	} 
	catch (e) { 
		try { 
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch (E) { 
			xmlhttp = false; 
		} 
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { 
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function aleatorio(inferior,superior){ 
		numPosibilidades = superior - inferior 
		aleat = Math.random() * numPosibilidades 
		aleat = Math.round(aleat) 
		return parseInt(inferior) + aleat 
}


function correcto(o,m){
o.innerHTML="<span class=\"correcto_msj\">"+(m==null?"&nbsp;":m)+"</span>";o.className="correcto";
de("Vproceso").style.visibility = "hidden";
}
function correcto1(o,m){o.innerHTML="<span class=\"correcto_msj\">"+(m==null?"&nbsp;":m)+"</span>";o.className="correcto1";
de("Vproceso").style.visibility = "hidden";
}

function incorrecto(o,m,obj){
o.innerHTML="<span class=\"incorrecto_msj\">&nbsp;</span>";o.className="incorrecto";
valor = "img" + o.id;
//alert(valor+ "--- TOP: " + findPosY(de(valor)) + " LEFT: " + findPosX(de(valor)))
if (o.id == "tipo_documento_editStatus"){
	de("Vproceso").style.top = findPosY(de(valor)) + -45 +"px";
	de("Vproceso").style.left = findPosX(de(valor)) + -40 +"px";
}else{
	de("Vproceso").style.top = findPosY(de(valor)) + -35 +"px";
	de("Vproceso").style.left = findPosX(de(valor)) + -50 +"px";
}
de("Vproceso").style.visibility = "visible";
de("contenidocapa").innerHTML = "&nbsp;&nbsp;" + m;
obj.focus();
}

function de(n){return document.getElementById(n);}

function checkdate(fecha){
// for all other strange errors

var err=0
f1=fecha;
//alert(f1)
var n1 = f1.indexOf("/",0);
//alert (n1);
var n2 = f1.lastIndexOf("/");
//alert (n2);
var ultimo =f1.length
if (ultimo == 0) return true
//alert (ultimo);

if ( (n1 < 1) || (n1>2) || (n2<3) || (n2>5) || (n2+1>=ultimo)) {
//alert ("DEBE INTRODUCIR LA FECHA CORRECTAMENTE. (dd/mm/yyyy)");
//fecha.focus();
return false;
}


var d = Math.abs(f1.substring(0, n1))// day
var c = f1.substring(n1,n1+1)// '/'
var b = Math.abs(f1.substring(n1+1, n2))// month
var e = f1.substring(n2,n2+1)// '/'

var f = Math.abs(f1.substring(n2+1, ultimo))// year

//alert (d+"-"+b+"-"+f+" "+c+e);

// test basico de error
if (b<1 || b>12) err = 1
if (c != '/') err = 1
if (d<1 || d>31) err = 1
if (e != '/') err = 1
if (f<1900 || f>2099) err = 1
//test avanzado de error
// meses de 30 days
if (b==4 || b==6 || b==9 || b==11){
if (d==31) err=1
}
// february, leap year
if (b==2){
// feb
var g=parseInt(f/4)
if (isNaN(g)) {
err=1
}
if (d>29) err=1
if (d==29 && ((f/4)!=parseInt(f/4))) err=1
}
if (err==1){
//alert ("DEBE INTRODUCIR LA FECHA CORRECTAMENTE. (dd/mm/yyyy)");
//fecha.focus();
return false
}
else{
//alert('ĄCorrecto!');
return true;
}
}
