
//***********************************//
// Desarrollada por Angel Soto       //
// angels0t0@hotmail.com             //
// Fecha:  18/03/2004                //
//***********************************//


function esbisiesto(ano){
   div4=((ano % 4)==0);
   div100=((ano % 100)==0);
   div400=((ano % 400)==0);
   aux=false;
   if (div4) aux=true;
   if (div100) aux=false;
   if (div400) aux=true;
     return(aux);
}

//********************************************************************************

function ConfirmaBorrar(Link, idc) {
    var is_confirmed = confirm(idc);
    if (is_confirmed) {
       Link.href += '&is_js_confirmed=1';
    }
    return is_confirmed;
}

//********************************************************************************
function ConfirmaBorrarCheck(id) {
   if (confirm('¿Confirma?')) {
      window.location.href = ".php?id=" + id;
   }
}

//********************************************************************************
function LimpiarFormulario() {
      window.fm.reset();
      return false;
}

//********************************************************************************
var win = null;
function NewWindow(mypage,myname,w,h,scroll) {
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
}


//********************************************************************************
function isBlanco(texto) {
   largo = texto.length
   for (i=0; i < largo ; i++ )
       if ( texto.charAt(i) !=" ")
          return false;
   return true
}


//********************************************************************************
function isValidEmail(texto)
   {
   var addressIsValid = false;
   var invalidPatterns = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
   var validPatterns = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
   if (window.RegExp)
      {
      if (!invalidPatterns.test(texto) && validPatterns.test(texto))
         {
         addressIsValid = true;
         }
      else
         {
         addressIsValid = false;
         }
      }
   else
      {
      if(texto.indexOf("@") >= 0)
      addressIsValid = true;
      }
   return addressIsValid;
   }


//**************************************************************
function isNumber(texto)
  {
   largo = texto.length
   if (largo == 0)
   return false;
   for (i=0; i < largo ; i++ )
       if (!isDigit(texto.charAt(i)))
       return false;
   return true
  }


//**************************************************************
function isDigit(caracter)
  {
  if ((caracter.charAt(0) >= "0") && (caracter.charAt(0) <= "9"))
     return  true
  return false
  }


//**************************************************************
function mOvr(src,clrOver)
  {
  if (!src.contains(event.fromElement))
     {
     src.style.cursor = 'hand';
     src.bgColor = clrOver;
     }
  }

function mOut(src,clrIn)
  {
  if (!src.contains(event.toElement))
     {
     src.style.cursor = 'default';
     src.bgColor = clrIn;
     }
  }

function mClk(src)
  {
  if (event.srcElement.tagName=='TD')
     {
     src.children.tags('A')[0].click();
     }
  }


//**************************************************************
function setPointer(theRow, thePointerColor)
{
    if (typeof(theRow.style) == 'undefined' || typeof(theRow.cells) == 'undefined') {
        return false;
    }

    var row_cells_cnt           = theRow.cells.length;
    for (var c = 0; c < row_cells_cnt; c++) {
        theRow.cells[c].bgColor = thePointerColor;
    }

    return true;
}

//**************************************************************

function ir(direccion)
  {
  if (direccion != -1) location=direccion
  }


//**************************************************************
function verifydigit(texto)
{
  largo = texto.length;
  for (i=0; i < largo ; i++ )
    {
   if ( texto.charAt(i) != "0" &&
        texto.charAt(i) != "1" && texto.charAt(i) != "2" &&
        texto.charAt(i) != "3" && texto.charAt(i) != "4" &&
        texto.charAt(i) != "5" && texto.charAt(i) != "6" &&
        texto.charAt(i) != "7" && texto.charAt(i)!= "8" &&
        texto.charAt(i) != "9" )
        {
          return false;
        }
    }
  return true;
}


//**************************************************************
function checkDigitsOnly(texto)
{
  largo = texto.length;
  for (i=0; i < largo ; i++ )
  {
      if ( texto.charAt(i) != "0" && texto.charAt(i) != "1" && texto.charAt(i) != "2"
      && texto.charAt(i) != "3" && texto.charAt(i) != "4" && texto.charAt(i) != "5"
      && texto.charAt(i) != "6" && texto.charAt(i) != "7" && texto.charAt(i) != "8"
      && texto.charAt(i) != "9" )
     {
      return false;
     }
  }
  return true;
}


//**************************************************************
function checkDigitsKOnly(texto)
{
  largo = texto.length;
  for (i=0; i < largo ; i++ )
  {
     if ( texto.charAt(i) != "0" && texto.charAt(i) != "1" && texto.charAt(i) != "2"
     && texto.charAt(i) != "3" && texto.charAt(i) != "4" && texto.charAt(i) != "5"
     && texto.charAt(i) != "6" && texto.charAt(i) != "7" && texto.charAt(i) != "8"
     && texto.charAt(i) != "9" && texto.charAt(i) !="k" && texto.charAt(i) != "K" )
    {
      return false;
    }
 }
 return true;
}


//**************************************************************
function testlargo(texto,largomin,largomax) {
    if ((texto.length < largomin) || (texto.length > largomax)){
    return false;
    }
   else {
 return true;
 }
}


//**************************************************************
function checkDV(rut,dig)
{
  var dvr = '0'
  suma = 0
  mul  = 2
  for (i= rut.length -1 ; i >= 0; i--)
  {
     suma = suma + rut.charAt(i) * mul
    if (mul == 7)
       mul = 2
    else
       mul++
  }
  res = suma % 11
  if (res==1)
   dvr = 'k'
  else if (res==0)
   dvr = '0'
  else
  {
    dvi = 11-res
    dvr = dvi + ""
  }
  if ( dvr != dig.toLowerCase() )
  { return false; }
 else
  { return true }
}


//**************************************************************
function verifica_password(cad) {
  cadextr="áéíóú´ñ!¡?¿ç{}[]û\/*+#$%&()=;:, \t" + "\"";
  cad = cad.toLowerCase();
  if (cad.length < 6) return false;
  for (var i=0; i < cad.length;i++) {
      var letra=cad.substring(i,i+1)
      if (cadextr.indexOf(letra) > 0)
      return false;
   }
  return true;
}

//**************************************************************
// formatea el mes a mm, ejemplo: 4 lo deja en 04
function ValidarMes(inputmes) {
  mes   = inputmes.value;
  largo = mes.length;
  if (!isNumber(mes) ) {
//     alert(mes);
     inputmes.value = "";
     return false;
   } else {
     if (mes < 13 && mes > 0) {
//       alert(largo);
         if (mes < 10 && largo == 1) {
            inputmes.value = "0" + mes ;
         }
                 return true;
   } else {
     inputmes.value = ""; return false;}
   }
}

function mostrar(idCapa) {
	var ie4
	ie4 = (document.all)? true:false 
	
	document.getElementById(idCapa).style.visibility="visible";
	document.getElementById(idCapa).style.display='';

}

function ocultar(idCapa) {
	var ie4
	ie4 = (document.all)? true:false 
	
	document.getElementById(idCapa).style.visibility="hidden";
	document.getElementById(idCapa).style.display='none';
	
}

function change_promocion(opcion_value, id_hidde) {
	if (opcion_value == id_hidde) {
		mostrar ("div_promocion_otro");
	} else {
		ocultar("div_promocion_otro");
	}
}