/* ======================================================================
DESC: Funciones Globales JavaScript
PLATFORMS:  Alls
Author: Jesus Perez Lorenzo
Date Created: 8/7/2001
Version: 1.0 
USAGE NOTES: 
====================================================================== */

/*  Strings for locales  */
var debugMode=false;
var msg1=" el valor no es correcto ";
/******************************************************************
   debug(str)
        To trace functions when debugMode is true
*******************************************************************/
function debug(str) {
    if ( debugMode == true ) {
        alert(str);
    }     
}
/******************************************************************
   setStatusBar(str)
        Assign str to Status Bar in the Window
*******************************************************************/
function setStatusBar(str) {
        window.status=str;
        return true;
}

/******************************************************************
   emptyField(textObj)
        Check to see if text field is empty
*******************************************************************/
function emptyField(textObj) {
 if (textObj.value.length == 0) return true;
        for (var i=0; i<textObj.value.length; i++) { 	
 	         var ch = textObj.value.charAt(i);
 	         if (ch != ' ' && ch !='\t' ) return false;
        }
        return true;
}
/******************************************************************
   get_value(type,elem)
        Get Element value from differents types
*******************************************************************/
function get_value(type,elem){
    var i, j, k;
    if(type == "text"){
	// return the "value" of a input field of type "text". It is
	// supposed to work with textarea too (not in 2.0b3 though)
	return (elem.value == "") ? elem.defaultValue : elem.value;
    } else if(type == "select"){
	//  return the "value" of the selected option in a "select" 
	//  (doens't work with "multiple")
    	j  = elem.length;
	k  = -1;
	var opts = elem.options;
	for(i = 0; i < j; i++){
	    if(opts[i].selected){
          k=i ; break;
//		    return opts[i].value;
	    } else if(opts[i].defaultSelected){
		   k = i;
	    }
	}
	return (k >= 0) ?  ("" + opts[k].value) : null;
//    return elem.options[elem.selectedIndex].value;
    } else if(type == "radio"){
	// return the "value" of a radio group
	j = elem.length;
	k = -1;
	for(i = 0; i < j; i++){
	    if(elem[i].status){
          k=i ; break;
	    } else if(elem[i].defaultStatus){
		k = i;
	    }
	}
	return (k >= 0) ? elem[k].value : null;
    } else {
	return null;
    }
}
/******************************************************************
   StringClip(full,i_cadena)
   To eliminate trailing spaces, full will eliminate begining spaces
   if string "i_cadena" is "null" the return value will be " "   
*******************************************************************/
function StringClip(full,i_cadena)
{ 
   var ipos=0;
	var lpos=0;
	var cadena=i_cadena+"";
	if (!cadena || cadena == " " )
	    return " "
	lpos=cadena.length;
	if (lpos <= 1 ) 
	    return cadena;
	if (cadena == "null") 
	    return " ";
//  debug("->"+cadena+"<- "+lpos);
   for (var i=lpos-1; i > 1 ; i--) {
//      debug("-->"+i+"<--")
      if (cadena.substring(i,i+1) != " " ) break;
	} 
//  debug("--"+ipos+"--"+i+"--"+lpos+"--")
	if ( i > 0 )
	    lpos=i+1;
	    
	if ( full == true ) {
      for (var j=1 ; j<cadena.length ; j++ ) {
	    if (cadena.substring(j-1,j) != " " )  break;	        
	   }  
    	if ( j > 0 )
	       ipos=j-1;
   }
//	debug("Cadena: "+cadena.substring(ipos,lpos)+"<-->"+i+"logg="+cadena.length);   
	return cadena.substring(ipos,lpos)
}
/******************************************************************
   isNroThis(obj)
*******************************************************************/
function isNroThis(obj) {
  nro=parseInt(obj.value)
  if ( nro+1 > 0 ) 
      return true
  else {
      alert(msg1);
      obj.focus();
      return false
  }    
}    
