function findPosX(varobj){
  var obj = document.getElementById(varobj);
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
		
	return curleft;
	
  }

function findPosY(varobj){
  var obj = document.getElementById(varobj);
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
  
function mostrarCapaAdv2(varid,varVal,varPos,varX,varY){
	var idcapa = document.getElementById(varid);
	
	idcapa.style.top=varY;
	idcapa.style.left=varX;
	
	
	idcapa.style.visibility=varVal;
	idcapa.style.position=varPos;
}
function mostrarCapa(varid){
	var idcapa = document.getElementById(varid);
	
	idcapa.style.visibility='visible';
}

function mostrarCapaAdv(varid,varVal,varPos){
	var idcapa = document.getElementById(varid);
	
	idcapa.style.visibility=varVal;
	idcapa.style.position=varPos;
}

var ns6=document.getElementById&&!document.all
var ie=document.all

function changeto(e,highlightcolor){
source=ie? event.srcElement : e.target
if (source.tagName=="TR"||source.tagName=="TABLE")
return
while(source.tagName!="TD"&&source.tagName!="HTML")
source=ns6? source.parentNode : source.parentElement
if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
source.style.backgroundColor=highlightcolor
}

function contains_ns6(master, slave) { //check if slave is contained by master
while (slave.parentNode)
if ((slave = slave.parentNode) == master)
return true;
return false;
}

function changeback(e,originalcolor){
if
(ie&&(event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")||source.tagName=="TR"||source.tagName=="TABLE")
return
else if (ns6&&(contains_ns6(source, e.relatedTarget)||source.id=="ignore"))
return
if (ie&&event.toElement!=source||ns6&&e.relatedTarget!=source)
source.style.backgroundColor=originalcolor
}

function PaginaInicio(oHomePage,url) {
    oHomePage.style.behavior='url(#default#homepage)';
	oHomePage.setHomePage(url);
}

function openWindow(url,name,w,h,sc){
	args = openWindow.arguments;
	var ancho_interface=10;
	var alto_interface=29;
	var tamx=screen.width;
	var tamy=screen.height;
	var posx=(tamx-(parseInt(w)+ancho_interface))/2;
	var posy=(tamy -(parseInt(h)+alto_interface))/2;
		
	var parameters = 'width='+w+',height='+h+',top='+posy+',left='+posx+',scrollbars='+sc+args[5];
	window.open(url,name,parameters);
}

function salir() {
	if (confirm('La siguiente acción terminará la sesión actual.\n¿Desea continuar?')){
	document.location='borrarsesiones.asp';
	}
}

function replaceTo(str,to,by) {
var out = "", flag = 0;
for (i = 0; i < str.length; i++) {
if (str.charAt(i) != to) {
out += str.charAt(i);
flag = 0;
}
else {
if(flag == 0) {
out += by;
flag = 1;
      }
   }
}
return out;
}

function EsVacio(val) {
    return ((val == null) || (val.length == 0));
}

function EsNumerico(val) {
    num = parseFloat(val);
    if (val!=''+num) return false;
    return true;
}

function EsFecha(val) {
    var dia = parseInt(val.substr(0,2),10);
    var mes = parseInt(val.substr(3,2),10);
    var anyo = parseInt(val.substr(6,4),10);
  
    if(val.length!=10) return false;
    d = new Date(val)
    if (isNaN( d.valueOf() )) return false;
    sArray = val.split("/")
    if (sArray.length > 3) return false;
    if( (sArray[0].length!=2) || (sArray[1].length!=2) || (sArray[2].length!=4) ) return false;
    if( (anyo<0) || (anyo>9999) ) return false;
    if((mes>12) || (mes<1)) return false;
    if((mes==4)||(mes==6)||(mes==9)||(mes==11)) {
        if((dia>30) || (dia<1)) return false;
    }
    if((mes==1)||(mes==3)||(mes==5)||(mes==7)||(mes==8)||(mes==10)||(mes==12)) {
            if((dia>31) || (dia<1)) return false;
    }
    if((mes==2) && (!EsBisiesto(anyo))) {
            if((dia>28) || (dia<1)) return false;
    } else if((mes==2) && (EsBisiesto(anyo))) {
            if((dia>29) || (dia<1)) return false;
    }
    return true;
}

function EsBisiesto(val) {
    return ((val % 4 == 0) && ((!(val % 100 == 0)) || (val % 400 == 0)));
}

function imprimir(){
	print();	
}

function FormatoDosDecimales(varNum){
	var Coma = varNum.indexOf('.');
	
	if (Coma==-1){
		return varNum + '.00';
	} else {
		varNum = varNum + '00';
		return varNum.substring(0,Coma+3);
	}
}

function openCalendar(varX,varY,varCampo,varFecha){
	args = openCalendar.arguments;
	window.open('calendario/calendario.asp?Campo='+varCampo+'&Fecha='+varFecha+'&nolimit='+args[4],'calendar','left='+varX+',top='+varY+',height=140,width=145');
}

function openCalendar2(varX,varY,varCampo,varFecha){
	args = openCalendar2.arguments;
	window.open('../calendario/calendario.asp?Campo='+varCampo+'&Fecha='+varFecha+'&nolimit='+args[4],'calendar','left='+varX+',top='+varY+',height=140,width=145');
}

function redimImagen(IdImagen) {
	var TBLImagenes = IdImagen.split("|");
	var id;
	
	
	
	for (i=0;i<(TBLImagenes.length);i++){
	
		id = document.getElementById(TBLImagenes[i]);
		
		if (id.width==28&&id.height==30){
			//Id.src = "/pics/articulos/sin_imagen.jpg";
		}		
		
		if (id.width>=90 && id.width<=120){
		  id.width = id.width / 1.25;
		}
		
		if (id.width>120 && id.width<=150){
		  id.width = id.width / 1.50;
		}
		
		if (id.width>150 && id.width<=201){
		  id.width = id.width / 2;
		}
		
		if (id.width>201 && id.width<=250){
		  id.width = id.width / 2.50;
		}
		
		if (id.width>250 && id.width<=300){
		  id.width = id.width / 3;
		}
		
		if (id.width>300 && id.width<=350){
		  id.width = id.width / 3.50;
		}
		
		if (id.width>350 && id.width<=450){
		  id.width = id.width / 4;
		}
	}
}

function ChequeoLetras(chequeo)
{
  var digitos = "0123456789";
  for (i = 0;  i < chequeo.length;  i++)
  {
    ch = chequeo.charAt(i);
    for (j = 0;  j < digitos.length;  j++)
      if (ch == digitos.charAt(j))
        break;
    if (j == digitos.length)
    { return (true); }
   }
  return (false);
}
function valora(valor)
{this.valor=valor}

function Calcula(valor){

var val = new valora(11);

val[1] = new valora(1);
val[2] = new valora(2);
val[3] = new valora(4);
val[4] = new valora(8);
val[5] = new valora(5);
val[6] = new valora(10);
val[7] = new valora(9);
val[8] = new valora(7);
val[9] = new valora(3);
val[10] = new valora(6);
var Total=0;
  for (i = 0;  i < valor.length;  i++)
  {
    Total += valor.charAt(i)*val[i+1].valor;
   }
	Total = 11-(Total % 11)
	if (Total==10) {Total=1}
	if (Total==11) {Total=0}
  return Total;
}


function CalcularCC(CB,CS,CC,CD)
{
if ((CB.value=='0000')&&(CS.value='0000')&&(CC.value='0000000000')&&(CD.value='00')){
	alert("La cuenta introducida no es valida.");
	return false;
	}

  if (CB.value.length != 4)
  {
    alert("Escriba el valor para el campo \"C.Banco\" con cuatro digitos.");
    CB.focus();
    return (false);
  }
  if (CS.value.length != 4)
  {
    alert("Escriba el valor para el campo \"C.Sucursal\" con cuatro digitos.");
    CS.focus();
    return (false);
  }
  if (CD.value.length != 2)
  {
    alert("Escriba el valor para el campo \"C.Control\" con dos digitos.");
    CD.focus();
    return (false);
  }
  if (CC.value.length != 10)
  {
    alert("Escriba el valor para el campo \"C.Corriente\" con diez digitos.");
    CC.focus();
    return (false);
  }

  if (ChequeoLetras(CB.value))
  {
    alert("Escriba solo numeros (0-9) el campo \"C.Banco\" .");
    CB.focus();
    return (false);
  }
  if (ChequeoLetras(CS.value))
  {
    alert("Escriba solo numeros (0-9) el campo \"C.Sucursal\" .");
    CS.focus();
    return (false);
  }
  if (ChequeoLetras(CD.value))
  {
    alert("Escriba solo numeros (0-9) el campo \"C.Control\" .");
    CD.focus();
    return (false);
  }
  if (ChequeoLetras(CC.value))
  {
    alert("Escriba solo numeros (0-9) el campo \"C.Corriente\" .");
    CC.focus();
    return (false);
  }
  
  redun =Calcula("00"+CB.value+CS.value);
  redun =""+Calcula("00"+CB.value+CS.value)+Calcula(CC.value);
	if (redun!=CD.value)
		{
		alert("La cuenta introducida no es valida.");
		return false;
		}
	else
		{
		return true;
		}
  return false;
}

function EsEmail(val) {
    arroba = val.lastIndexOf('@');

    if ( arroba < 1 )
        return false;
    else {
    punto = val.indexOf('.', arroba);
      if ( punto < arroba + 2 ||
         punto > val.length - 2 ) {
         return false;
      }
   }
   return true;
}

function sobre(src,Color) {
   
   // if (!src.contains(event.fromElement)) {
	  //src.style.cursor = 'hand';
	  src.style.backgroundColor = Color;
	  //src.style.color = '#ffffff';
	//}
}

function fuera(src,Color) {
	//if (!src.contains(event.toElement)) {
	  //src.style.cursor = 'default';
	  src.style.backgroundColor = Color;
	//}
}

function sobreADV(idsrc,Color,Cursor) {
	  var src = document.getElementById(idsrc);
	  
	  src.style.cursor = Cursor;
	  src.style.backgroundColor = Color;
}

function fueraADV(idsrc,Color,Cursor) {
	var src = document.getElementById(idsrc);
	
	src.style.cursor = Cursor;
	src.style.backgroundColor = Color;
}

function dameSoloFechaMysql(fecha){
	var tblF = fecha.value.split('/');
	var SubFecha = new Date(tblF[2],tblF[1]-1,tblF[0]);
	var mes = '0' + (SubFecha.getMonth()+1);
	var dia = '0' + SubFecha.getDate();
	fecha.value = SubFecha.getYear()+'-'+mes.substr(mes.length-2,mes.length)+'-'+dia.substr(dia.length-2,dia.length);
	return fecha.value;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}