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 crearXMLHttpRequest()
{
  var xmlHttp=null;
  if (window.ActiveXObject)
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  else
    if (window.XMLHttpRequest)
      xmlHttp = new XMLHttpRequest();
  return xmlHttp;
}

function Cambio_Clase(nested, Clase) {
  nested.className = Clase;
}

function addClassName(objElement, strClass, blnMayAlreadyExist) {
  if ( objElement.className ) {
    var arrList = objElement.className.split(' ');
    if ( blnMayAlreadyExist ) {
      var strClassUpper = strClass.toUpperCase();
      for ( var i = 0; i < arrList.length; i++ ) {
        if ( arrList[i].toUpperCase() == strClassUpper ) {
          arrList.splice(i, 1);
          i--;
        }
      }
    }
    arrList[arrList.length] = strClass;
    objElement.className = arrList.join(' ');
  } else {
    objElement.className = strClass;
  }
}

function removeClassName(objElement, strClass) {
  if ( objElement.className ) {
    var arrList = objElement.className.split(' ');
    var strClassUpper = strClass.toUpperCase();
    for ( var i = 0; i < arrList.length; i++ ) {
      if ( arrList[i].toUpperCase() == strClassUpper ) {
        arrList.splice(i, 1);
        i--;
      }
    }
    objElement.className = arrList.join(' ');
  }
}

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 ResizeIframe(id,resizeIframeX,resizeIframeY) {
  var newheight;
  var newwidth;
  if(document.getElementById) {
    newwidth=document.getElementById(id).contentWindow.document.body.scrollWidth;
    if ((navigator.appName.match(/Netscape/))) {
      newheight=document.getElementById(id).contentWindow.document .body.offsetHeight;
      if (resizeIframeX) document.getElementById(id).style.width = (newwidth) + "px";
      if (resizeIframeY) document.getElementById(id).style.height = (newheight) + "px";
    } else {
      newheight=document.getElementById(id).contentWindow.document .body.scrollHeight;
      if (resizeIframeX) document.getElementById(id).style.width = (newwidth) + "px";
      if (resizeIframeY) document.getElementById(id).style.height = (newheight) + "px";
    }
  }
}

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 VerificarCheckBox(Campo, Mensaje) {
  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]){5,100})?$/;
  if(Campo.value && !RegExp.test(Campo.value))
    {window.alert('La clave debe tener 5 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');
}


