function AgregarTblIngreso(contacto){
	if(document.getElementById('filaBorra')){
		eliminarFila('tbl_detalle','filaBorra');
	}//end if
	var tbl = document.getElementById('tbl_detalle');
	var lastRow = tbl.rows.length;

	secElemento = lastRow -	1;

	var row = tbl.insertRow(lastRow);	     
	clave = "rowPro"+secElemento; 
	row.id = clave;
	claveScript = "'"+clave+"'";
	if (((lastRow+1) % 2) == 0){
	 var claseTD = "celdaCons2";
	}else{
	 var claseTD = "";             
	}//end if
	
	//Contenido de los td	          
	var cell_0 = row.insertCell(0);
	
	cell_0.innerHTML = '<input name="txt_desdet[]" type="text" class="Texto02d" id="txt_desdet[]" size="17"  readonly="" style="border-width:0px;text-align:center" value="'+document.getElementById('txt_desproducto').value+'"/>';
	cell_0.className = claseTD;
	cell_0.align = "center";
	   
	/*--- ---*/
	var cell_1 = row.insertCell(1);	   
	cell_1.innerHTML = '<input name="txt_cantdet[]" type="text" class="Texto02d" id="txt_cantdet[]" size="12" readonly="" style="border-width:0px;text-align:center" value="'+document.getElementById('txt_cantidad').value+'"/>';
	cell_1.className = claseTD;
	cell_1.align = "center";
	
	/*--- ---*/
	var cell_2 = row.insertCell(2);	   
	cell_2.innerHTML = '<input name="txt_tamdet[]" type="text" class="Texto02d" id="txt_tamdet[]" size="12" readonly="" style="border-width:0px;text-align:center" value="'
						+document.getElementById('txt_tamano1').value
						+' x '
						+document.getElementById('txt_tamano2').value
						+'"/>';
	cell_2.className = claseTD;
	cell_2.align = "center";
	
	/*--- ---*/
	var cell_3 = row.insertCell(3);	   
	cell_3.innerHTML = '<input name="txt_matdet[]" type="text" class="Texto02d" id="txt_matdet[]" size="15" readonly="" style="border-width:0px;text-align:center" value="'+document.getElementById('txt_material').value+'"/>';
	cell_3.className = claseTD;
	cell_3.align = "center";
	
	/*--- ---*/
	var cell_4 = row.insertCell(4);	   
	cell_4.innerHTML = '<input name="txt_otrasdet[]" type="text" class="Texto02d" id="txt_otrasdet[]" size="30" readonly="" style="border-width:0px;text-align:center" value="'+document.getElementById('txt_caracteristicas').value+'"/>';
	cell_4.className=claseTD;
	cell_4.align = "center";
	
	/*--- ---*/
	var cell_5 = row.insertCell(5);	   
	cell_5.innerHTML = '<a href="javascript:eliminarFila(\'tbl_detalle\','+ claveScript +')" class="menurojo">Eliminar</a>';
	cell_5.bgColor = "#FFFFFF";
	cell_5.className=claseTD;
	cell_5.align = "center";	
	  
	vaciarDet();
}//end AgregarTblIngreso


//================================================================================================================================//

function validarFila(idTabla,idBoton){		
	var tbl = document.getElementById(idTabla);
    var lastRow = tbl.rows.length;	
	var vacio = 0;
	var elemento;
	if(document.getElementById('txt_desproducto') && document.getElementById('txt_desproducto').value==''){
		alert('Ingrese descripcion del producto');
		document.getElementById('txt_desproducto').focus();
		return false;
	}//end if
	if(document.getElementById('txt_cantidad') && document.getElementById('txt_cantidad').value==''){
		alert('Ingrese cantidad');
		document.getElementById('txt_cantidad').focus();
		return false;
	}//end if
	if(document.getElementById('txt_tamano1') && document.getElementById('txt_tamano1').value==''){
		alert('Ingrese tamano 1');
		document.getElementById('txt_tamano1').focus();
		return false;
	}//end if
	if(document.getElementById('txt_tamano2') && document.getElementById('txt_tamano2').value==''){
		alert('Ingrese tamano 2');
		document.getElementById('txt_tamano2').focus();
		return false;
	}//end if
	if(document.getElementById('txt_material') && document.getElementById('txt_material').value==''){
		alert('Ingrese material');
		document.getElementById('txt_material').focus();
		return false;
	}//end if
	/*if(document.getElementById('txt_caracteristicas') && document.getElementById('txt_caracteristicas').value==''){
		alert('Ingrese caracteristicas');
		document.getElementById('txt_caracteristicas').focus();
		return false;
	}//end if*/
	if (idBoton == 'btn_mas'){		
		switch(idTabla){
			case 'tbl_detalle':
				AgregarTblIngreso(0);
				break;			
		}//end switch		
    }// end if
	
	if(idBoton == 'btn_grabar'){
	   if(vacio == 1){
			alert("Complete datos de fila");	
			fila.childNodes[1].childNodes[0].focus();
			return false;
		}//end if
	}// end if	
	
	if (idBoton == 'btn_enviar'){		
		switch(idTabla){
			case 'tbl_detalle': 
				AgregarTblIngreso(0);
				document.getElementById('frm_servicio').submit();
				break;			
		}//end switch		
    }// end if
}//end validarFila

//==================================================================================================================================

function eliminarFila(idTabla,controlx){		
	var tbl = document.getElementById(idTabla);		
	for (i=0;i<tbl.childNodes.length;i++) {
		var n = tbl.childNodes.item(i);			
		for (j=0;j<n.childNodes.length;j++){
			var m = n.childNodes[j];
			if (m.id==controlx){
			   n.removeChild(n.childNodes[j]);
			   return;
			}//end if
		}//end for
   }//end for
}//end eliminarFila

function ocultarFilaE(idCampoOculto,idFila){	
	document.getElementById(idCampoOculto).value = "del";	
	row = document.getElementById(idFila);
	row.style.display='none';	
}//end ocultarFila2
 

function vaciarDet(){
	if(document.getElementById('txt_desproducto')){
		document.getElementById('txt_desproducto').value='';
	}//end if
	if(document.getElementById('txt_cantidad')){
		document.getElementById('txt_cantidad').value='';
	}//end if
	if(document.getElementById('txt_tamano1')){
		document.getElementById('txt_tamano1').value='';
	}//end if
	if(document.getElementById('txt_tamano2')){
		document.getElementById('txt_tamano2').value='';
	}//end if
	if(document.getElementById('txt_material')){
		document.getElementById('txt_material').value='';
	}//end if
	if(document.getElementById('txt_caracteristicas')){
		document.getElementById('txt_caracteristicas').value='';
	}//end if
}
	



