function stopRKey(evt) {
var evt  = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text")) { return false; }
}
document.onkeypress = stopRKey;



function showhideelement(menuelement, clickaction) {

    if (!clickaction) {
        if (document.getElementById(menuelement).style.display == '') {
           document.getElementById(menuelement).style.display = 'none';
        } else {
           document.getElementById(menuelement).style.display = '';
        }
    } else {
        if (clickaction == 'show') {
           document.getElementById(menuelement).style.display = '';
        } else {
           document.getElementById(menuelement).style.display = 'none';
        }
    }
}

function confirmar_accion(mensaje)
{
  var agree=confirm(mensaje);
  if (agree)
    return true ;
  else
    return false ;
}

function formato_moneda(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;
    return (mnt == Math.floor(mnt)) ? mnt + '.00'
              : ( (mnt*10 == Math.floor(mnt*10)) ?
                       mnt + '0' : mnt);
}


function color_menu(theElement, theAction) {
         if (theAction) {
             document.getElementById(theElement).className = 'body_menub_01b';
         } else {
             document.getElementById(theElement).className = 'body_menub_01';
         }
}


function class_name(theElement, CName, theAction) {
         if (theAction) {
             document.getElementById(theElement).className = CName + 'b';
         } else {
             document.getElementById(theElement).CLASSnAME = CName + 'a';
         }
}

function class_change(theElement, CName) {

             document.getElementById(theElement).className = CName;

}



function val_exist(celda, mensaje) {
  if (celda.value == '') {
    alert(mensaje);
    celda.focus();
    return false;
  } else {
    return true;
  }
}



function openNewWindow(Wurl,Wame, Wheight, Wwidth, Wextra)
{
  if (Wextra) { Wextra = "," + Wextra; }
  winLeft = (screen.width-Wwidth)/2;
  winTop = (screen.height-(Wheight+110))/2;
//  myWin= open();

  window.open(Wurl,Wame,"width=" + Wwidth +",height=" + Wwidth + ",left=" + winLeft + ",top=" + winTop + Wextra );
}

function NewWindow(mypage,myname,w,h,extra){
  var win= null;
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl;
	  settings += ','+extra;
  win=window.open(mypage,myname,settings);
  if(parseInt(navigator.appVersion) >= 4){win.focus();}
}




function validar_correo(str) {
	return ((str.indexOf("@") != -1) && (str.indexOf(".") != -1));
}


function validar_alfa(checkStrx, tipo, mensaje, fin) {

    if (fin == 'si') {checkStr = checkStrx;} else { checkStr = checkStrx.value; }

    var checkOK;

    if (tipo == 1) { checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; }
    if (tipo == 2) { checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "; }
    if (tipo == 3) { checkOK = "0123456789"; }
    if (tipo == 4) { checkOK = "0123456789-"; }
    if (tipo == 5) { checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 αινσϊόρΑΙΝΣΪάΡ"; }
    if (tipo == 6) { checkOK = "-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 αινσϊόρΑΙΝΣΪάΡ"; }
    if (tipo == 7) { checkOK = "-.,ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 αινσϊόρΑΙΝΣΪάΡ"; }
    if (tipo == 8) { checkOK = "(;:)/_-.,ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 αινσϊόρΑΙΝΣΪάΡ"; }
    if (tipo == 9) { checkOK = "0123456789/"; }
    if (tipo == 'username') { checkOK = "abcdefghijklmnopqrstuvwxyz0123456789"; }
    if (tipo == 'passwd') { checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; }
    if (tipo == 'sql') { checkOK = "() ,%\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; }
    if (tipo == 'general') { checkOK = "-.,ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 αινσϊόρΑΙΝΣΪάΡ&%"; }


    var allValid = true;
    for (i = 0;  i < checkStr.length;  i++)
    {
      ch = checkStr.charAt(i);
      for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
      break;
      if (j == checkOK.length) { allValid = false; break; }
    }

    if (!allValid) { alert(mensaje); checkStrx.focus(); return ('bad'); }


}
