/* 
       +-------------------------------------------------------------------------- +
       | Desarrollado por: Gustavo Ocanto                                          | 
	   |         Telefono: 0414-4284230                                            | 
	   |	        Email: gustavoocanto@gmail.com , gustavo.ocanto@hotmail.com    |
	   + ------------------------------------------------------------------------- + 
	   |            Valencia Edo. Carabobo - Venezuela	              			   |
       + ------------------------------------------------------------------------- +
*/
function on_enter(evt,fun,tipo,val_01,val_02,val_03){
	var key = nav4 ? evt.which : evt.keyCode;	
	var t;
	if(key == 13||evt==13){ 
		switch (fun){
		   case 1: foco(val_01); break;		   
		} 		
	return false;
	}else{
		switch (tipo){
		   case 1 : return soloNum(evt);
		   case 2 : return soloLetras(evt);
		   case 3 : return val_caracter(evt);
		   case 99: t++;break;
		   default: return soloDecimal(evt,tipo);
		   //case 4: return soloDecimal(evt,val_01);
		   //default: return soloDecimal(evt,tipo);
		}  
	}
}

var nav4 = window.Event ? true : false;
function soloNum(evt){
	var key = nav4 ? evt.which : evt.keyCode;
	return (key <= 13 || (key >= 48 && key <= 57)|| key==45);
}
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>=133&&key<=235));
}
function soloLetras(evt){
	var key = nav4 ? evt.which : evt.keyCode;
	return (key==32||key <= 13 || (key >= 65 && key <= 90)||(key >= 97 && key <= 122) || key == 32 || (key >=160 && key <=164) || key ==130);
}

function soloDecimal(evt,id_campo){
	var key = nav4 ? evt.which : evt.keyCode;
	cadena=document.getElementById(id_campo).value;	
	if (checkForCharacters(cadena, ',') != -1 && key ==44 ||(cadena.length== 0 && key ==44 ||  key ==46 )||(checkForCharacters(cadena, '.') != -1 && key ==46)){ return false; }
	return (key <= 13 || (key >= 48 && key <= 57)|| key==46 || key==44);
}		
function checkForCharacters(inputString, checkString, startingIndex)
{
  if (!startingIndex) startingIndex = 0;
  return inputString.indexOf(checkString);
}

function inicio(url){
         location.href=url		
}

function foco(idobj){//#5
		 var inputFields = document.getElementsByTagName('INPUT'); 
		 var selectBoxes = document.getElementsByTagName('SELECT'); 
		 var textareas   = document.getElementsByTagName('TEXTAREA');
		 var inputs      = new Array();
         //agregamos los imputs 		 
		 for (i=0; i<inputFields.length; i++){ if (inputFields[i].getAttribute('type')!='button' && inputFields[i].getAttribute('type')!='submit' &&	inputFields[i].getAttribute('type')!='reset' && inputFields[i].getAttribute('type')!='checkbox'){ inputs[inputs.length] = inputFields[i]; }}
		 for (i=0; i<selectBoxes.length; i++){ inputs[inputs.length] = selectBoxes[i]; }
		 for (i=0; i<textareas.length;   i++){ inputs[inputs.length] = textareas[i];   }
		 for (i=0; i<inputs.length;      i++){ 
			  // document.getElementById(inputs[i].getAttribute('id')).style.backgroundImage="";
			  document.getElementById(inputs[i].getAttribute('id')).style.backgroundColor = '#FFFFFF';
			  document.getElementById(inputs[i].getAttribute('id')).style.border          = '1px solid #86A5D9';
		 }
		 // establecemos el estilo en el objeto que vviene por parametro
		 if (document.getElementById(idobj).getAttribute('type')!='button' && document.getElementById(idobj).getAttribute('type')!='submit' && document.getElementById(idobj).getAttribute('type')!='reset'){
			 //document.getElementById(idobj).style.backgroundImage="";
			 //document.getElementById(idobj).style.backgroundColor = '#E9EEF3';
			 document.getElementById(idobj).style.border = '1px solid #339900';
		 }			
		 document.getElementById(idobj).focus();
}	

function valida(){ // requerido=" label", opcional(tamanio="tamaņo")
	     var inputFields = document.getElementsByTagName('INPUT'); 
	     var selectBoxes = document.getElementsByTagName('SELECT'); 
	     var textareas = document.getElementsByTagName('TEXTAREA');
	     var inputs = new Array();
	     for (i=0;i<inputFields.length;i++){if(inputFields[i].getAttribute('requerido'))inputs[inputs.length] = inputFields[i];}
	     for (i=0;i<selectBoxes.length;i++){if(selectBoxes[i].getAttribute('requerido'))inputs[inputs.length] = selectBoxes[i];}
	     for (i=0;i<textareas.length;i++){if(textareas[i].getAttribute('requerido'))inputs[inputs.length] = textareas[i];}
	     for (i=0;i<inputs.length;i++){
		      msj=inputs[i].getAttribute('requerido')+' es requerido(a)!\n\n';
		      if (inputs[i].getAttribute('tamanio')){
			      tamanio=inputs[i].getAttribute('tamanio');
			      msj+='y debe contener al menos \''+ tamanio+'\' caracteres';
		      }else tamanio=1;
		      if (inputs[i].value.length<tamanio){	
		          foco(inputs[i].getAttribute('id'));
			      alert(msj);
			      return false;
		      }
	     }
	     return true;
}

function str_replace(inChar,outChar,conversionString){
         var convertedString = conversionString.split(inChar);
         convertedString = convertedString.join(outChar);
         return convertedString;
}

function sinFormato(number){
		 return str_replace(',','.',str_replace('.','',number));
}	 	   	     

function validaEmail(id){
		 valor  = document.getElementById(id).value;
		 correo = valor.indexOf('@');  
		 band=true;
		 if (correo != -1){
			 email = valor.split('@');
			 point = email[1].indexOf('.');
			 punto = email[1].split('.');
			 if (point != -1 && point!=''){
				 if (punto[1].length<2 || punto[1].length>5){
					 foco(id);
					 alert('El dominio de la direccion de email no es valido!\n\nEjemplo: mi_email@mi_dominio.com');
					 band=false;
				 }
			 }else{
				  foco(id);
				  alert('Falta el dominio del email!\n\nEjemplo: mi_email@mi_dominio.com');
				  band=false;
			 }
		 }else{
			    foco(id);
				alert('El email es incorrecto!\n\nEjemplo: mi_email@mi_dominio.com');
				band=false;      
		 }
		  				  
		 return band;  
}


/* 
       +-------------------------------------------------------------------------- +
       | Desarrollado por: Gustavo Ocanto                                          | 
	   |         Telefono: 0414-4284230                                            | 
	   |	        Email: gustavoocanto@gmail.com , gustavo.ocanto@hotmail.com    |
	   + ------------------------------------------------------------------------- + 
	   |            Valencia Edo. Carabobo - Venezuela	              			   |
       + ------------------------------------------------------------------------- +
*/
