/*---------------------------------------------*/

//---------------------------
function fnSwDiv(div) {
	var div = document.getElementById(div);
	if(div.style.display == 'block')
		div.style.display = 'none';
	else
		div.style.display = 'block';
}
//---------------------------
function fnEnviarFormulario() {

	if(document.getElementById("txtNombre").value == ""){
		alert("Favor de ingresar un nombre de contacto");
		document.getElementById("txtNombre").focus();
		return;
	}else if(document.getElementById("txtTelefono").value == ""){
		alert("Favor de ingresar el numero de telefono");
		document.getElementById("txtTelefono").focus();
		return;
	}else if(document.getElementById("txtCorreo").value == ""){
		alert("Favor de ingresar un correo electronico");
		document.getElementById("txtCorreo").focus();
		return;
	}else if(document.getElementById("txtAreaComentarios").value == ""){
		alert("Favor de agregar los comentarios");
		document.getElementById("txtAreaComentarios").focus();
		return;
	}else if(!fnValidar()){
		return;
	}else if(!fnValidarTodo()){
		alert("Por lo menos agrege una fila para el contacto")
		return;
	}else{
		fnEnviarArreglo();
		document.getElementById("frmDatos").submit();
	}
}
//---------------------------
function fnEnviarArreglo() {
	var campo1 = document.getElementsByName("txtParte");
	var campo2 = document.getElementsByName("txtDescripcion");
	var campo3 = document.getElementsByName("txtCantidad");
	
	var datos_campo1 = "";
	for(i=0; i < campo1.length; i++)
		if(campo1[i].value != "")
		datos_campo1 += campo1[i].value + ":";
	document.getElementById("txtParteURL").value = datos_campo1;
		
	var datos_campo2 = "";		
	for(i=0; i < campo2.length; i++)
		if(campo2[i].value != "")
			datos_campo2 += campo2[i].value + ":";
	document.getElementById("txtDescripcionURL").value = datos_campo2;
	
	var datos_campo3 = "";
	for(i=0; i < campo3.length; i++)
		if(campo3[i].value != "")
			datos_campo3 += campo3[i].value + ":";
	document.getElementById("txtCantidadURL").value = datos_campo3;
}
//---------------------------
function fnValidar() {
	var campo1 = document.getElementsByName("txtParte");
	var campo2 = document.getElementsByName("txtDescripcion");
	var campo3 = document.getElementsByName("txtCantidad");

	cont = 0;
	for(i=0; i < 5; i++){

		if(campo1[i].value == "" && campo2[i].value != "" && campo3[i].value != ""){
			alert("Faltan campos de la fila")
			campo1[i].focus();
			return false;
			
		}else if(campo1[i].value != "" && campo2[i].value == "" && campo3[i].value != ""){
			alert("Faltan campos de la fila")
			campo2[i].focus();
			return false;
			
		}else if(campo1[i].value != "" && campo2[i].value != "" && campo3[i].value == ""){
			alert("Faltan campos de la fila")
			campo3[i].focus();
			return false;

		}else if(campo1[i].value != "" && campo2[i].value == "" && campo3[i].value == ""){
			alert("Faltan campos de la fila")
			campo2[i].focus();
			return false;
						
		}else if(campo1[i].value == "" && campo2[i].value != "" && campo3[i].value == ""){
			alert("Faltan campos de la fila")
			campo1[i].focus();
			return false;
						
		}else if(campo1[i].value == "" && campo2[i].value == "" && campo3[i].value != ""){
			alert("Faltan campos de la fila")
			campo1[i].focus();
			return false;
		}
		cont++;
	}
	if(cont == 5)return true;
}
//--------------------------------------------------------------------
function fnValidarTodo() {
	var campo1 = document.getElementsByName("txtParte");
	var campo2 = document.getElementsByName("txtDescripcion");
	var campo3 = document.getElementsByName("txtCantidad");	
	
	var cont = 0;

	for(i=0; i < campo1.length; i++)
		if(campo1[i].value == "")
			cont ++;

	for(i=0; i < campo2.length; i++)
		if(campo2[i].value == "")
			cont ++;
			
	for(i=0; i < campo3.length; i++)
		if(campo3[i].value == "")
			cont ++; 		

	return band = (cont == 15)? false : true ;
}
//--------------------------------------------------------------------