/* 
<!--
    + -------------------------------------------------- +
    | Desarrollado por: Websarrollo, C.A.                |
    |                   J-29744628-1                     |
    |                   info@websarrollo.com             |
    |                   0414-428.42.30 / 0416-730.10.61  |
    + -------------------------------------------------- +
 -->*/
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;
		   case 4: valida_ci_rif(val_01,val_02); break;
		   case 5: evia_login(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();
		 
		 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 #CDA244';
		 }
		 
		 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 = '#D9F0FF';
				 document.getElementById(idobj).style.border = '1px solid #00006E';
			 }			*/
		   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 fondo(modo,elemento,color){ //#E2E2E2
	if(modo=='1')
		document.getElementById(elemento).style.backgroundColor = color;
	else
		document.getElementById(elemento).style.backgroundColor = color;
}

function borderMenu(id, color){
		document.getElementById(id).style.border = 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!\n\nEjemplo: mi_email@websarrollo.com');
					 band=false;
				 }
			 }else{
				  foco(id);
				  alert('Falta el dominio del email!\n\nEjemplo: mi_email@websarrollo.com');
				  band=false;
			 }
		 }else{
			    foco(id);
				alert('El email es incorrecto!\n\nEjemplo: mi_email@websarrollo.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 expandit(curobj){
		if(document.getElementById(curobj)){
		  folder=document.getElementById(curobj).style;
		  }else{
			if(ns6==1||(agtbrw.indexOf('opera')!=-1)){
				folder=curobj.nextSibling.nextSibling.style;
			}else{
				folder=document.all[curobj.sourceIndex+1].style;
			}
		   }
		if (folder.display=="none"){
			folder.display="";
		}else{
			folder.display="none";}
}

function confirma(msj){
         if (confirm(msj)) 
		     return true;
		 else
		     return false;	
}
function popup(url, ancho, largo, aux) {
		 x   = ((screen.width/2)-largo);		 
		 y   = ((screen.height/2)/2);
		 day = new Date();
         id  = day.getTime();
		 
         eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=0,scrollbars="+aux+",location=0,statusbar=0,menubar=0,resizable=0,width="+ancho+",height="+largo+",left = "+x+",top = "+y+"');");
}

function valida_campos(id_01, id_02){
	     band=true;
	     if (document.getElementById(id_01).value!=document.getElementById(id_02).value){
			 alert('Los valores deben coincidir.');
			 document.getElementById(id_01).value=document.getElementById(id_02).value='';
			 foco(id_01);
			 band=false;
		 }
		 return band;
}


function valida_muchos_id(){
	     var inputFields = document.getElementsByTagName('INPUT'); 
	     var inputs = new Array();
		 var band = true;
	     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' && inputFields[i].getAttribute('type')!='radio' && inputFields[i].getAttribute('type')!='hidden'){
					inputs[inputs.length] = inputFields[i];
				}
	     }
	
	     for (i=0;i<inputs.length;i++){ 
		      if (inputs[i].value=="" && inputs[i].getAttribute('todos')!='no'){
				  alert('Debe completar los datos para continuar con la compra.');
				  band=false;
				  return band;
			  } 
		 }         

         return band;
}

function hidden_photo(id, curobj){
		 if (document.getElementById(curobj)){
			 folder = document.getElementById(curobj).style;
		 }else{
			 if (ns6==1||(agtbrw.indexOf('opera')!=-1)){
				 folder=curobj.nextSibling.nextSibling.style;
			 }else{
				 folder=document.all[curobj.sourceIndex+1].style;
			 }
		 }
		
		 if (document.getElementById(id).value=='no' && folder.display=="none")
			 folder.display="";
		 
		 if (document.getElementById(id).value!='no')
			 folder.display="none";
}

function cerrar_ventana(){
	     document.getElementById('ventana').style.display="none";
}


function ventana(obj_pos){
   var x=findPos(document.getElementById(obj_pos))[0]+25;
   var y=findPos(document.getElementById(obj_pos))[1]+20;
   document.getElementById("ventana").style.top=y+'px';
   document.getElementById("ventana").style.left=x+'px';
   document.getElementById('ventana').style.display="";
}

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];
}

function evia_login(formu){
	     if (valida()) document.getElementById(formu).submit();
}

function oculta_div(){
         var div    = document.getElementsByTagName('DIV');	
	     var inputs = new Array();
         
		 for (i=0; i < div.length; i++)
			  if (div[i].getAttribute('div_requerido') == 'si' && div[i].getAttribute('div_requerido') != 'null')
			      inputs[inputs.length] = div[i];	
				
	     for (i=0; i < inputs.length; i++)
			  inputs[i].style.display="none"; 
}

function valor(id){
         return document.getElementById(id).value;	
}

/* 
<!--
    + -------------------------------------------------- +
    | Desarrollado por: Websarrollo, C.A.                |
    |                   J-29744628-1                     |
    |                   info@websarrollo.com             |
    |                   0414-428.42.30 / 0416-730.10.61  |
    + -------------------------------------------------- +
 -->*/
