function ocular_selects(){
	selec = document.getElementsByTagName('SELECT');	
	var gko = navigator.userAgent.toLowerCase();
	if (gko.indexOf('gecko')==-1)
		for(i=0;i<selec.length;i++)
			selec[i].style.visibility='hidden';//hacemos el setAttribute normalmente	
}

function mostrar_selects(){
	selec = document.getElementsByTagName('SELECT');	
	var gko = navigator.userAgent.toLowerCase();
	if (gko.indexOf('gecko')==-1)
		for(i=0;i<selec.length;i++)		
			selec[i].style.visibility='visible';//hacemos el setAttribute normalmente
}

function confirmarDel(ae,campo,id) {
	var conf=confirm('¿Seguro que desea eliminar est'+ae+' '+campo+'?');
	if (conf) { window.location = '?iddel='+id; }
}

function str_replace(busca, repla, orig){
	str 	= new String(orig);
	rExp	= "/"+busca+"/g";
	rExp	= eval(rExp);
	newS	= String(repla);
	str = new String(str.replace(rExp, newS));
	return str;
}

/**
* Validadores de entradas de datos
* soloNum(evt), moneda(evt,id_campo), val_caracter(evt), val_caract_email(evt), 
* val_numero_letra(evt), val_numero_letra(evt), val_dominio(evt), soloLetras(evt), 
* soloLetras(evt), soloDecimal(evt, id_campo)
* Permiten validar los datos de entrada por medio del keypress 
**/
var nav4 = window.Event ? true : false;
function soloCI(evt){
   var key = nav4 ? evt.which : evt.keyCode;
   return (key <= 13 || (key >= 48 && key <= 57) || (key==86) || (key==69) || (key==71) || (key==74));
}
function moneda(evt,id_campo){     
   str=document.getElementById(id_campo).value;	
   var key = nav4 ? evt.which : evt.keyCode;   
   if((key==46 || key==44) && str.match(',')==null){
   	   document.getElementById(id_campo).value+=',';	  
   }
   return (key <= 13 || (key >= 48 && key <= 57));
}
function val_caracter(evt){
   var key = nav4 ? evt.which : evt.keyCode;
   return (key==32|| key <= 13 || (key >= 65 && key <= 90)||(key >= 97 && key <= 122)|| (key >= 40 && key <= 57) || (key>=130&&key<=250)||key==95 ||key==241 ||key==209);
}
function val_caract_email(evt){
   var key = nav4 ? evt.which : evt.keyCode;
   return (key <= 13 || (key >= 64 && key <= 90)||(key >= 97 && key <= 122)|| (key >= 48 && key <= 57)||key==95||key==46);
}
function val_numero_letra(evt){
   var key = nav4 ? evt.which : evt.keyCode;
   return (key <= 13 || (key >= 65 && key <= 90)||(key >= 97 && key <= 122)|| (key >= 48 && key <= 57) ||key==241 ||key==209);
}

function val_dominio(evt){
   var key = nav4 ? evt.which : evt.keyCode;
   return (key <= 13 || (key >= 65 && key <= 90)||(key >= 97 && key <= 122)||(key >= 48 && key <= 57));
}

function soloLetras(evt){
   var key = nav4 ? evt.which : evt.keyCode;
   return (key==32||key <= 13 || (key >= 65 && key <= 90)||(key >= 97 && key <= 122)||(key>=193&&key<=250)||key==95 ||key==241 ||key==209);
}
function soloDecimal(evt, id_campo){
   var key = nav4 ? evt.which : evt.keyCode;
   cadena=document.getElementById(id_campo).value;
   document.getElementById(id_campo).value= str_replace('.', ',', cadena);
   if(key==46){
      key=44;
   }
   if ((checkForCharacters(cadena, ',') != -1 && key ==44)||(cadena.length== 0 && key ==44)){
      return false;

   }
   return (key <= 13 || (key >= 48 && key <= 57)|| key==45 || key==44);
}
/** Fin de validadores de entradas de datos **/

/** abre_popup(URL,titulo,ancho,alto)
* Es una funcion para crear popups con parámetros por defecto como lo son:
* scrollbars=yes, menubar=no, directories=no , channelmode=no, location=no
* y la ubica al centro de la ventana de windows
**/
function abre_popup(URL,titulo,ancho,alto){
   ventana_win=window.open(URL, titulo, "scrollbars=yes, menubar=no, directories=no , channelmode=no, location=no");
   ventana_win.resizeTo(ancho, alto);
   centrox=(screen.width/2)-(ancho/2);
   centroy=(screen.height/2)-(alto/2);
   ventana_win.moveTo(centrox, centroy);
}

/** Validacion de Email con expresiones regulares 
* 
**/
function validarEmail(valor){
  if(/^w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})+$/.test(valor))
    return (true);
  else
    return (false);
}

/** Permite validar URL con expresiones regulares**/
function validarURL(valor){
	//return valor.match(/^([a-zA-Z0-9][a-zA-Z0-9\-]{3,})\.([a-zA-Z0-9]{2,4}(\.[a-zA-Z0-9]{2})?)$/) == true;
  if(valor.match(/^([a-zA-Z0-9][a-zA-Z0-9\-]{3,})\.([a-zA-Z0-9]{2,4}(\.[a-zA-Z0-9]{2})?)$/)){	 
   return (true)
  } else {
    return (false);
  }
}

/**
* Para hacer un trim() parecido al de PHP
**/
function ltrim(s){
   return s.replace(/^\s+/, "");
}

function rtrim(s){
   return s.replace(/\s+$/, "");
}
/** trim(s)
* Elimina los espacios en blanco que se encuentran al principio o al final de la cadena
**/
function trim(s){
   return rtrim(ltrim(s));
}

/** findPos(obj)
* Devuelve la posicion X Y de un objeto en la pantalla
* sintaxtis 
* findPos(document.getElementById('id_objeto'))[0] = Objeto en la posicion X
* findPos(document.getElementById('id_objeto'))[1] = Objeto en la posicion Y
**/
function findPos(obj) {
   var curleft = curtop = 0;
   if (obj.offsetParent){
      curleft = obj.offsetLeft;
      curtop = obj.offsetTop;
      while (obj = obj.offsetParent) {
         curleft += obj.offsetLeft;
         curtop += obj.offsetTop;
      }
   }
   return [curleft, curtop];
}

/** setCheckedValue(formu,radioObjt, newValue)
* Permite colocar como Checked a un radiobutton
*
**/
function setCheckedValue(formu,radioObjt, newValue) {
	evaluado=eval("document."+formu+"."+radioObjt);
	for(i=0; i<evaluado.length; i++)		
		evaluado[i].checked = (evaluado[i].value == newValue.toString());	
}
/** checkbox_checked(nombre_checkbox,valor)
* Permite colocar como Checked a un checkbox enviandole el valor por defecto
**/
function checkbox_checked(nombre_checkbox,valor){
   calculo=valor.split("|");
   for(i=0; i<calculo.length; i++)
   		document.getElementById(nombre_checkbox+i).checked=(calculo[i]!=' ');	
}

/** select_selected(nomb_sel,valor)
* Permite colocar como selected a un select enviandole el valor por defecto
**/
function select_selected(nomb_sel,valor){
 select_tipo = document.getElementById(nomb_sel).getElementsByTagName('OPTION');  
   for (i=0; i<select_tipo.length; i++)
	    select_tipo[i].selected=(select_tipo[i].getAttribute('value')==valor.toString());   			
}

/** select_selected_multiple(nomb_sel,valor) es la version v2.0 
* de select_selected(nomb_sel,valor)
* Permite colocar como selected a un select a uno o varios de sus valores enviandole el o los valores por defecto
* mientras se encuentren separados por (,)
**/
function select_selected_multiple(nomb_sel,valor){
 	select_tipo = document.getElementById(nomb_sel).getElementsByTagName('OPTION');
 	valores=valor.split(",");
	if(valores!=valor){
		for (i=0; i<select_tipo.length; i++){
			select_tipo[i].selected=false;
			select_tipo[i].selected=(select_tipo[i].getAttribute('value')==valor.toString());
		}
	}
	else{
		for (i=0; i<select_tipo.length; i++){
			select_tipo[i].selected=false;
			for (j=0; j<valores.length; j++){					
				if(select_tipo[i].getAttribute('value')==valores[j].toString())
					select_tipo[i].selected='selected';			
			}
		}
	}
}

/** getPageSize()
* Devuelve el ancho y alto de la resolucion de pantalla y el de la pagina desde cualquier navegador
* sintaxis
* getPageSize()[0] = pageWidth 
* getPageSize()[1] = pageHeight
* getPageSize()[2] = windowWidth
* getPageSize()[3] = windowHeight
**/
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
