/* 
       +-------------------------------------------------------------------------- +
       | 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;
		   case 2: entrar();  break;
		   case 3: validaEmail(val_01, val_02); 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();
		 
		 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 #81A840';
		 }
		 
		 if (document.getElementById(idobj).getAttribute('type')!='button'&&
			 document.getElementById(idobj).getAttribute('type')!='submit'&&
			 document.getElementById(idobj).getAttribute('type')!='reset'){
		     if (document.getElementById(idobj).getAttribute('type')=='text'||document.getElementById(idobj).getAttribute('type')=='password'||document.getElementById(idobj).getAttribute('type')=='file')
				 document.getElementById(idobj).style.backgroundImage="";
				 document.getElementById(idobj).style.backgroundColor = '#FFFFFF';
				 document.getElementById(idobj).style.border = '1px solid #FE7000';
			 }			
		   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';
		      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 fondo(modo,elemento,color){ //#E2E2E2
	if(modo=='1')
		document.getElementById(elemento).style.backgroundColor = color;
	else
		document.getElementById(elemento).style.backgroundColor = color;
}

function validaMonto (id, monto){
		 if (Number (str_replace(',','.',str_replace('.','',document.getElementById(id).value))) < monto){
			 alert('El monto debe ser Mayor ķ Igual a: '+numFormat(monto,2));
			 foco(id);
			 return false;
		 }else{
		     return true;	 
		 }
}

function show(id, modo){
	     obj=document.getElementById(id).style;
	     switch (modo){
		                case 1: obj.display="none"; break;
						case 2: obj.display="";     break;
		 }
	
}

function borrar(id, id_capa, op, url){
	     band=true;
		 if (confirm("Esta seguro de eliminar este registro ??")){
			 ir_url (url+'&id='+id, id_capa)
			 //inicio('index.php?op='+op);
		 }else{
		     band=false;	 
		 }
		 
		 return band;
}

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!\nEjemplo: mi_email@gmail.com');
					 band=false;
				 }
			 }else{
				  foco(id);
				  alert('Falta el dominio del email!\nEjemplo: mi_email@gmail.com');
				  band=false;
			 }
		 }else{
			    foco(id);
				alert('El email es incorrecto!\nEjemplo: mi_email@gmail.com');
				band=false;      
		 }
		  				  
		 return band;  
}
 
function changeimg(opcion, id, strImg) {
		 if (opcion='over')
	         document.getElementById(id).src = strImg;
		 else	 
		     document.getElementById(id).src = strImg; 
}

function changeimg2(opcion, id, strImg) {
	     
		 //alert(parent.document.getElementById(id).value);
		 if (opcion='over')
	         parent.document.getElementById(id).src = strImg;
		 else	 
		     parent.document.getElementById(id).src = strImg; 
}


function precargaImagenes(){ 
         var i;
         var imagenes = new Array("img/botones_top2.jpg", "img/botones_top1.jpg", "img/menu1.jpg", "img/menu2.jpg", "img/menu3.jpg", "img/menu4.jpg", "img/menu5.jpg", 
								  "img/loaddder.gif", "img/botones_top.jpg", "img/nosotros.jpg", "img/pag_solucion.jpg", "img/pag_empleos.jpg", "img/pag_revista.jpg",
								  "img/pag_lamparas.jpg", "img/pag_seguros.jpg", "img/pag_rey.jpg", "img/top_tablas.jpg", "img/menu.jpg", "img/colores_1.jpg",
								  "img/colores_2.jpg", "img/colores_3.jpg", "img/colores_plan_1.jpg", "img/colores_plan_2.jpg", "img/colores_plan_3.jpg",
								  "img/ascesoria.jpg", "img/hosting.jpg", "img/desarrollo_w.jpg", "img/mantenimi.jpg", "img/img_publi2.jpg");
         var lista_imagenes = new Array(); 

		 for(i=0; i<imagenes.length; i++){
		     lista_imagenes[i]     = new Image();
		     lista_imagenes[i].src = imagenes[i];		
		}		 
}



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