function check(c){
  var msg = ''
  var focus = false
  
  for (cta=0; cta<c.length; cta++){
    chk = c[cta].split('|')
    
    if(chk[1] == '='){
      if(trim(document.getElementById(chk[0]).value) == chk[2]){
        if(focus==false){
          document.getElementById(chk[0]).focus()
          focus=true
        }
        
        msg += chk[3] + '\r\n'
      }
    }else if(chk[1] == '<>'){
      if(trim(document.getElementById(chk[0]).value) != chk[2]){
        if(focus==false){
          document.getElementById(chk[0]).focus()
          focus=true
        }
                
        msg += chk[3] + '\r\n'
      }
    }else if(chk[1] == "<"){
      if(parseFloat(chk[0]) < parseFloat(chk[2])){
        msg += chk[3] + '\r\n'
      }
    }else if(chk[1] == ">"){
      if(parseFloat(chk[0]) > parseFloat(chk[2])){
        msg += chk[3] + '\r\n'
      }
    }else if(chk[1] == 'd'){
      if(isDate(document.getElementById(chk[0]).value) == false){
        if(focus==false){
          document.getElementById(chk[0]).focus()
          focus=true
        }
                
        msg += chk[3] + '\r\n'
      }
    }
  }
  
  if(msg != ''){
    alert(msg)
    return false
  }else{
    return true
  }

  return true
}

function isDate(sDate) {
  var dArr = sDate.split("/");
  var d = new Date(dArr[1] + "/" + dArr[0] + "/" + dArr[2]);
  return d.getMonth() + 1 == dArr[1] && d.getDate() == dArr[0] && d.getFullYear() == dArr[2];
}

validNum = new RegExp("[^0-9]")
validCodigo = new RegExp("[^a-zA-Z0-9_-]")
validPrecio = new RegExp("[^0-9,]")

function CheckChar(Tipo){
  if(event.keyCode==13){
    return true
  }
  
  if(Tipo=='Decimal' || Tipo=='DecimalNegativo'){
    if(event.keyCode==46){
      event.keyCode = 44
    }
  }
  
  var x = event.keyCode
  
  if(Tipo=='Codigo'){
    if(validCodigo.test(String.fromCharCode(x))==true){
      event.returnValue=false
    }
  }else if(Tipo=='Entero'){
    if(validNum.test(String.fromCharCode(x))==true){
      event.returnValue=false
    }
  }else if(Tipo=='EnteroNegativo'){
    if(x==45&&document.getElementById(window.event.srcElement.name).value.length==0){
    }else if(validNum.test(String.fromCharCode(x))==true){
      event.returnValue=false
    }
  }else if(Tipo=='Decimal'){
    if(validPrecio.test(String.fromCharCode(x))==true){
      event.returnValue=false
    }else{
      if(String.fromCharCode(x)==','){
        if(document.getElementById(window.event.srcElement.name).value.indexOf(',')!=-1){
          event.returnValue=false
        }
      }
    }
  }else if(Tipo=='DecimalNegativo'){
    if(x==45&&document.getElementById(window.event.srcElement.name).value.length==0){
    }else if(validPrecio.test(String.fromCharCode(x))==true){
      event.returnValue=false
    }else{
      if(String.fromCharCode(x)==','){
        if(document.getElementById(window.event.srcElement.name).value.indexOf(',')!=-1){
          event.returnValue=false
        }
      }
    }
  }
}

function windowopen(theurl,winname,features,mywidth,myheight,iscenter){
  if(iscenter==true){
    var myleft = (screen.width-mywidth) / 2
    var mytop = (screen.height-myheight) / 2
    
    features=features+',left='+myleft+',top='+mytop;
  }
  
  window.open(theurl,winname,'width='+mywidth+',height='+myheight+features);
}


function trim(cadena){ 
  for(i=0; i<cadena.length; ){
    if(cadena.charAt(i)==" ")
      cadena=cadena.substring(i+1, cadena.length);
    else
      break;
  }
  
  for(i=cadena.length-1; i>=0; i=cadena.length-1){
    if(cadena.charAt(i)==" ")
      cadena=cadena.substring(0,i);
    else
      break;
  }
  
  return cadena;
}

function ajaxobj() {
  try {
    _ajaxobj = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      _ajaxobj = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      _ajaxobj = false;
    }
  }
  
  if (!_ajaxobj && typeof XMLHttpRequest!='undefined') {
    _ajaxobj = new XMLHttpRequest();
  }
    
  return _ajaxobj;
}

function mOvr(src) {
if (!src.contains(event.fromElement)) {
src.style.cursor = 'hand';
src.bgColor = '#FFF5E5';
}
}

function mOut(src,color) {
if (!src.contains(event.toElement)) {
src.style.cursor = 'default';
src.bgColor = color;
}
}

function MM_preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

