var ns4 = (document.layers)? true:false;
var ie4 = (document.all)? true:false;

function addEvent(elemento,nomevento,funcion,captura) {
  if (elemento.attachEvent) {
    elemento.attachEvent('on'+nomevento,funcion);
    return true;
  }
  else if (elemento.addEventListener) {
    elemento.addEventListener(nomevento,funcion,captura);
    return true;
  }
  else
    return false;
}

function Cambio_Clase(nested, Clase) {
  nested.className = Clase;
}

function WindowStatus(Descripcion){
  window.status = Descripcion;
  return true;
}

function AddWindowStatus(Descripcion){
  window.status = window.defaultStatus +' - '+ Descripcion;
  return true;
}

function PreloadImages() {
  for(var i=0; i < ArrayImages.length; i++) {
    var img = new Image();
    img.src = ArrayImages[i];
  }
}

function VerificarUnCampo(Campo, Condicion, Verifica, Mensaje) {
  if (Condicion=='==') {
    if (Campo.value==Verifica) {window.alert(Mensaje); Campo.focus(); return true;}
  }
  else {
    if (Condicion=='<>') {
      if (Campo.value!=Verifica) {window.alert(Mensaje); Campo.focus(); Campo.select(); return true;}
    }
  }
}

function VerificarEntero(Campo, Minimo, Maximo, Mensaje) {
  if (Minimo!=Maximo)
    var regEnteros = new RegExp("^(([-])?([0-9])+)$", "");
  else
    var regEnteros = new RegExp("^((([-])?([0-9])+)?)$", "");
  if (Campo.value.search(regEnteros)){
    window.alert(Mensaje); Campo.focus(); Campo.select(); return true;}
  if (Minimo!=Maximo) {
    if (Campo.value<Minimo) {
      window.alert(Mensaje + ' - Debe ser Mayor o igual a ' + Minimo);
      Campo.focus(); Campo.select(); return true;
    }
    if (Campo.value>Maximo) {
      window.alert(Mensaje + ' - Debe ser Menor o igual a ' + Maximo);
      Campo.focus(); Campo.select(); return true;
    }
  }
}

function VerificarReal(Campo, Minimo, Maximo, Mensaje) {
  var regReal = new RegExp("^(([-])?([0-9])+([.]?[0-9]+)?)$", "");
  if (Campo.value.search(regReal)){
    window.alert(Mensaje); Campo.focus(); Campo.select(); return true;}
  if (Minimo!=Maximo) {
    if (Campo.value<Minimo) {
      window.alert(Mensaje + ' - Debe ser Mayor o igual a ' + Minimo);
      Campo.focus(); Campo.select(); return true;
    }
    if (Campo.value>Maximo) {
      window.alert(Mensaje + ' - Debe ser Menor o igual a ' + Maximo);
      Campo.focus(); Campo.select(); return true;
    }
  }
}

function VerificarRadio(Campo, Mensaje) {
  chequeado = false;
  if (Campo.length) {
    ii = 0;
    while ((ii < Campo.length) && (!chequeado)) {if (Campo[ii].checked) chequeado = true; ii++;}
    if (!(chequeado)) {window.alert(Mensaje); Campo[0].focus(); return true;}
  } else {
    if (!Campo.checked) {window.alert(Mensaje); Campo.focus(); return true;}
  }
}

function VerificarEMail(Campo, Mensaje) {
  var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/;
  if(Campo.value && !RegExp.test(Campo.value))
    {window.alert(Mensaje); Campo.focus(); Campo.select(); return true;}
}

function VerificarURL(Campo, Mensaje) {
  var RegExp = /^((ftp|http|https):\/\/){0,1}(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
  if(Campo.value && !RegExp.test(Campo.value))
    {window.alert(Mensaje); Campo.focus(); Campo.select(); return true;}
}

function VerificarPassword(Campo) {
  var RegExp = /^(([a-z]|[A-Z]|[0-9]){6,100})?$/;
  if(Campo.value && !RegExp.test(Campo.value))
    {window.alert('La clave debe tener 4 o más caracteres alfanuméricos (sin espacios en blanco)'); Campo.focus(); Campo.select(); return true;}
}

function AbrirSitio(Pagina,Identificador,PagX,PagY){
  PosX=(screen.availWidth-PagX)/2;
  PosY=((screen.availHeight-PagY)/2)-15;
  if (PosX < 10) PosX=0;
  if (PosY < 10) PosY=0;
  var choose=window.open(Pagina,Identificador,
    'scrollbars=no,resizable=no,width='+PagX+',height='+PagY+',left='+PosX+',top='+PosY+','+
    'status=no,location=no,toolbar=no, menubar=no,screenY=0,screenX=0');
}



