function swapImage(img){
  var tStr = img.src;
  var newSrc = tStr.substring(0,tStr.length-4);
  var imgExt = tStr.substring(tStr.length-3,tStr.length);
  if(newSrc.indexOf('_off') == newSrc.length-4){
    newSrc = newSrc.substring(0,newSrc.length-4)+'_on.'+imgExt;
  }
  else{
    newSrc = newSrc.substring(0,newSrc.length-3)+'_off.'+imgExt;
  }
//  alert(newSrc);
  img.src = newSrc;
}

function openModal(page, refWindow, width, height) {
  xpos = (screen.width) ? (screen.width-width)/2 : 0;
  ypos = (screen.height) ? (screen.height-height)/2 : 0;

  var win;
  if(document.all){
    var param = 'dialogHeight='+height+'px; dialogWidth='+width+'px'+
               '; edge: Sunken; center: Yes; help: no; minimize: yes; maximize: yes; resizable: yes; status: no; scroll: yes; ';
    win = window.showModalDialog(page, refWindow, param);
  }
  else{
    var param = 'height='+height+',width='+width+',top='+ypos+',left='+xpos+
               ',resizable, modal=yes, menubar=no, status=no, toolbar=no, scrollbars=yes';
    win = window.open(page,refWindow,param)
  }
  return win;
}

function trim(s) {
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r')){
    s = s.substring(1,s.length);
  }

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r')){
    s = s.substring(0,s.length-1);
  }

  if(s.length > 0 && s.indexOf(" ") == 0) {
    var i = 0;
    while(s[i++] == ' ')
      if(i < s.length) s = s.substring(i, s.length);
  }

  return s;
}

function isAlpha(str) {
  if (str == "") {
      return false;
  }
  for (var i = 0; i < str.length; i++) {
      if ((str.charAt(i) < "a" || str.charAt(i) > "z") &&
         (str.charAt(i) < "A" || str.charAt(i) > "Z")) {
          return false; 
      }
  }
  return true;
}

function parseSqlDate(to_date) {
  var fecha = to_date;
  var day = fecha.getDate();
  var month = fecha.getMonth() + 1;
  var year = fecha.getYear();
  
  if(parseInt(year) < 2000) year += 1900;
  
  return (year + "/" + month + "/" + day);
}

var espC;
function scrollBottom(cuanto){
  espC = cuanto;
  espC++;

  if (espC <= 1) myTymer = setTimeout('scrollBottom(espC)',100);
  else scroll(1,10000);
}

function getkey(e) {
  if (window.event)
   return window.event.keyCode;
  else if (e)
   return e.which;
  else
   return null;
}

function _isNaN(e, goods) {
	var key, keychar;
	key = getkey(e);

	if (key == null) return true;
	
	// obtiene caracter desde el teclado
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	goods = goods.toLowerCase();
	
	// verifica caracteres aceptados
	if (goods.indexOf(keychar) != -1)
		return true;
	
	// teclas de control
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
	   return true;
	
	// else -> return false
	return false;
}

function numbersOnly(str) {
  var str2 = "";
  
  str = trim(str);

  for(var i = 0; i < str.length; i++) {
    if(!isNaN(str.charAt(i))) str2 += str.charAt(i);
  }
  
  return str2;
}

function lettersOnly(str) {
  var str2 = "";
  
  str = trim(str);

  for(var i = 0; i < str.length; i++) {
    if(isNaN(str.charAt(i))) str2 += str.charAt(i);
  }
  
  return str2;
}

function getRefWinOpener() {
  var refOpener = null;
  
  if(document.all) { 
    refOpener = window.dialogArguments;
  }
  else { 
    refOpener = top.opener;
  }
  return refOpener;
}

