/*
--------------------------------------------------------------------------------
 Fecha de Modificación: 20/09/2011
 PPCR: 2011-00469
 Desarrollador: Martín Cabrera
 Descripción: Soporte a Firefox.-
--------------------------------------------------------------------------------
 COPYRIGHT. THE HONGKONG AND SHANGHAI BANKING CORPORATION LIMITED 2011. 
 ALL RIGHTS RESERVED
 
 This software is only to be used for the purpose for which it has been provided.
 No part of it is to be reproduced, disassembled, transmitted, stored in a 
 retrieval system or translated in any human or computer language in any way or
 for any other purposes whatsoever without the prior written consent of the Hong
 Kong and Shanghai Banking Corporation Limited. Infringement of copyright is a 
 serious civil and criminal offence, which can result in heavy fines and payment 
 of substantial damages.

Nombre del JavaScript: CotConductorU.js

Fecha de Creación: Desconocido

PPcR: Desconocido

Desarrollador: Desconocido

Descripción: Este archivo contiene funciones utilizadas por el modulo

--------------------------------------------------------------------------------
*/

function esCampoObligatorio (campo, descripcion)
{
	var text = trim(campo.value);
	
	if (text.length == 0)
	{
		//alert('Por favor complete la información necesaria. El campo ' + descripcion + ' es obligatorio.');
		campo.value = "";
		//campo.focus();
		
		return false;
	}
	return true;
}

function valida_texto(campo, descripcion, long_minima)
{
	var solotexto = 'abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ ';
	var bandera = 1;
	var auxChar = '';

	if (campo.value.length > 0)	
	{
	    	for(i=0;i<campo.value.length;i++)
		{
			if(solotexto.indexOf(campo.value.charAt(i)) == -1)
			{
				alert('El campo ' + descripcion + ' solo puede contener letras.');
				campo.value = "";
				campo.focus();
				return false;
			}
			if (bandera == 1)
			{
				if (auxChar == '')
				{
					auxChar = campo.value.charAt(i).toLowerCase();
				}
				else
				{
					if (auxChar != campo.value.charAt(i).toLowerCase())
					{
						bandera = 0;
					}
				}
			}
		}
		if (campo.value.length < long_minima)
		{
			//alert('El campo ' + descripcion + ' debe tener una longitud mínima de ' + long_minima + ' caracteres.');
			alert('El ' + descripcion + ' ingresado no es correcto, por favor, ingréselo nuevamente.');
			campo.value = "";
			campo.focus();
			return false;
		}
		if ((bandera == 1) && (campo.value.length > 1))
		{
			
			alert('El ' + descripcion + ' ingresado no es correcto, por favor, ingréselo nuevamente.');
			campo.value = "";
			campo.focus();
			return false;
		}
	}
	return true;
}

function valida_numeros(campo, descripcion, tipo, long_minima)
{
	var numeros ='0123456789';

	if (campo.value.length > 0)	
	{
	    	for(i=0;i<campo.value.length;i++)
		{
			if(numeros.indexOf(campo.value.charAt(i)) == -1)
			{
				alert('El número de ' + descripcion + ' solo puede contener números, por favor, ingréselo nuevamente.');
				campo.value = "";
				campo.focus();
				return false;
			}
		}
		if (tipo == 'documento')
		{
			if (campo.value.length < 7)
			{
				alert('El número de ' + descripcion + ' ingresado no es correcto, por favor, ingréselo nuevamente.');
				campo.value = "";
				campo.focus();
				return false;
			}
			numeros ='0';
			var bandera = 1;
		    	for(i=0;i<campo.value.length;i++)
			{
				if(numeros.indexOf(campo.value.charAt(i)) == -1)
				{
					bandera = 0;
					break;
				}
			}
			if (bandera == 1)
			{
				alert('El número de ' + descripcion + ' ingresado no es correcto, por favor, ingréselo nuevamente.');
				campo.value = "";
				campo.focus();
				return false;
			}
		}
		else
		{
			if (campo.value.length < long_minima)
			{
				//alert('El número de ' + descripcion + ' no puede tener menos de ' + long_minima + ' dígitos. Por favor, ingréselo nuevamente.');
				alert('El número de ' + descripcion + ' ingresado no es correcto, por favor, ingréselo nuevamente.');
				
				campo.value = "";
				campo.focus();
				return false;
			}
			numeros ='0';
			var bandera = 1;
		    	for(i=0;i<campo.value.length;i++)
			{
				if(numeros.indexOf(campo.value.charAt(i)) == -1)
				{
					bandera = 0;
					break;
				}
			}
			if (bandera == 1)
			{
				alert('El ' + descripcion + ' ingresado no es correcto, por favor, ingréselo nuevamente.');
				campo.value = "";
				campo.focus();
				return false;
			}
			
		}
	}
	return true;
}

function valida_email(campo, descripcion)
{
	var mail = 'abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ0123456789@._-';

	if (campo.value.length > 0)	
	{
	    	for(i=0;i<campo.value.length;i++)
		{
			if(mail.indexOf(campo.value.charAt(i)) == -1)
			{
				alert('El campo ' + descripcion + ' solo puede contener caracteres alfanuméricos.');
				campo.value = "";
				campo.focus();
				return false;
			}
		}
		
		conta = 0;
		conta2 = 0;
		
		for(i=0;i<campo.value.length;i++)
		{
			if(mail.indexOf(campo.value.charAt(i)) == -1)
			{
				alert('La dirección de email no es correcta, por favor, ingrésela nuevamente.');
				campo.value = "";
				campo.focus();
				return false;
			}
			else
			{
				if(campo.value.charAt(i) == '@')
				{
					conta++;

					if(conta > 1)
					{
						alert('La dirección de email no es correcta, por favor, ingrésela nuevamente.');
						campo.value = "";
						campo.focus();
						return false;
					}
				}
				if(campo.value.charAt(i) == '.')
				{
					conta2++;
				}
			}
		}

		if(conta==0 || conta2==0)
		{
			alert('La dirección de email no es correcta, por favor, ingrésela nuevamente.');
			campo.value = "";
			campo.focus();
			return false;
		}
		else
		{
			arroba=campo.value.split('@');
			punto=arroba[1].split('.');

			for(i=0;i<conta2;i++)
			{
				if (punto[i].length == 0)
				{
					alert('La dirección de email no es correcta, por favor, ingrésela nuevamente.');
					campo.value = "";
					campo.focus();
					return false;
				}
			}
		}

		if(campo.value.charAt(campo.value.length -1) == '.')
		{
			alert('La dirección de email no es correcta, por favor, ingrésela nuevamente.');
			campo.value = "";
			campo.focus();
			return false;				
		}
	}
	return true;
}

function trim(texto01) 
{
	while(texto01.substring(0,1) == ' ')
		texto01 = texto01.substring(1,texto01.length);

	while(texto01.substring(texto01.length-1,texto01.length) == ' ')
		texto01 =texto01.substring(0, texto01.length-1);   
	
	return texto01;
}

function getAniosEdad()
{
	var now = new Date();
	var Index;
	var Result = '';

	for (Index = now.getFullYear() - 21; Index >=  now.getFullYear() - 88; Index --)
	{
		Result += "<OPTION VALUE='" + String(Index) + "'>" + String(Index) + "</OPTION>"
	}

	return Result;
}

function GetEdadHijo(pEdad)
{
	var now = new Date();
	var NumDay = String(now.getDate());
	var NumMonth = String((now.getMonth() + 1));
	var Result;

	NumDay = (NumDay.length == 1)? "0" + NumDay: NumDay;
	NumMonth = (NumMonth.length == 1)? "0" + NumMonth: NumMonth;

	Result = NumDay + NumMonth + String(now.getFullYear() - pEdad); 

	return Result;
}

function cambia_Hijos(pSource)
{
	if (document.DATOSVEHICULOS.HIJOS1729.value == '1')
	{
		document.DATOSVEHICULOS.SELCONDADIC.disabled = false;
	}
	else 
	{
		document.DATOSVEHICULOS.SELCONDADIC.value = "0";
		document.DATOSVEHICULOS.SELCONDADIC.disabled = true;

		if (pSource == 'LBA')
			LimpiarTabla();
		else
			LimpiarTabla_Shell();
	}
}

function Validar_Conductor()
{
	if ((document.DATOSVEHICULOS.TIPODOC.value!="0" &&	document.DATOSVEHICULOS.TIPODOC.value!="")||
		document.DATOSVEHICULOS.NUMDOC.value != "" ||
		document.DATOSVEHICULOS.NOMBRES.value != "" ||
		document.DATOSVEHICULOS.APELLIDOS.value != "" ||
		document.DATOSVEHICULOS.EMAILP.value !="" ||
		document.DATOSVEHICULOS.EMAILL.value !="" ||
		document.DATOSVEHICULOS.ESCLIENTE[0].checked
		)
	{
		if (document.DATOSVEHICULOS.TIPODOC.value=="0" || document.DATOSVEHICULOS.TIPODOC.value=="")
		{
			alert('Debe informar su tipo de documento');
			document.DATOSVEHICULOS.TIPODOC.focus();
			return(false);
		}
		if (document.DATOSVEHICULOS.NUMDOC.value == "")
		{
			alert('Debe informar su número de documento');
			document.DATOSVEHICULOS.NUMDOC.focus();
			return(false);
		}
		if (isNaN(trim(document.DATOSVEHICULOS.NUMDOC.value)))
		{
			alert('Hay un caracter inválido en el Número de Documento');
			//ver(document.all.SPNNUMEDOCU, document.DATOSVEHICULOS.NUMDOC);
			document.DATOSVEHICULOS.NUMDOC.focus();
			return(false);
		}
		
		if ((document.DATOSVEHICULOS.TIPODOC.value==4 || document.DATOSVEHICULOS.TIPODOC.value==5) & !(verificaCuit(document.DATOSVEHICULOS.NUMDOC.value))){
			alert('Número de CUIT / CUIL inválido');
			document.DATOSVEHICULOS.NUMDOC.focus();
			return(false);
		}
		if (!(document.DATOSVEHICULOS.TIPODOC.value==4 || document.DATOSVEHICULOS.TIPODOC.value==5) & document.DATOSVEHICULOS.NUMDOC.value.length>8){
			alert('Número de Documento inválido');
			document.DATOSVEHICULOS.NUMDOC.focus();
			return(false);
		}
		if (document.DATOSVEHICULOS.NOMBRES.value == "")
		{
			alert('Debe informar su nombre');
			document.DATOSVEHICULOS.NOMBRES.focus();
			return(false);
		}
		if (document.DATOSVEHICULOS.APELLIDOS.value == "")
		{
			alert('Debe informar su apellido');
			document.DATOSVEHICULOS.APELLIDOS.focus();
			return(false);
		}
		if (document.DATOSVEHICULOS.TELEFONO.value =="")
		{
			alert('Debe ingresar su teléfono');
			document.DATOSVEHICULOS.TELEFONO.focus();
			return(false);			

		}
		else if (!valida_numeros(document.DATOSVEHICULOS.TELEFONO, 'Telefono','telefono')) //, document.DATOSVEHICULOS.TELEFONO, document.all.SPNTELEFONO, 'El teléfono es inválido'))
			return(false);
	}
	if (document.DATOSVEHICULOS.EMAILP.value !="")
	{
		//if (!valida_texto(document.DATOSVEHICULOS.EMAILP.value, 'E', document.DATOSVEHICULOS.EMAILP, document.all.SPNEMAILP, 'La dirección de email es inválida'))
		if (!valida_email(document.DATOSVEHICULOS.EMAILP, 'Email Personal')) //, document.DATOSVEHICULOS.EMAILP, document.all.SPNEMAILP, 'La dirección de email es inválida'))
			return(false);
	}
	else if (document.DATOSVEHICULOS.EMAILL.value !="")
	{
		//if (!valida_texto(document.DATOSVEHICULOS.EMAILL.value, 'E', document.DATOSVEHICULOS.EMAILL, document.all.SPNEMAILL, 'La dirección de email es inválida'))
		if (!valida_email(document.DATOSVEHICULOS.EMAILL, 'Email Laboral')) //, document.DATOSVEHICULOS.EMAILL, document.all.SPNEMAILL, 'La dirección de email es inválida'))
			return(false);
	}	
	if (document.DATOSVEHICULOS.NACIMDIA.value == '0')
	{
		alert('Falta ingresar el DIA en fecha de nacimiento');
		document.DATOSVEHICULOS.NACIMDIA.focus();
		return(false);
	}

	if (document.DATOSVEHICULOS.NACIMMES.value == '0')
	{
		alert('Falta ingresar el MES en fecha de nacimiento');
		document.DATOSVEHICULOS.NACIMMES.focus();
		return(false);
	}

	if (document.DATOSVEHICULOS.NACIMANN.value == '0')
	{
		alert('Falta ingresar el AÑO en fecha de nacimiento');
		document.DATOSVEHICULOS.NACIMANN.focus();
		return(false);
	}

	if (!valida_fecha(document.DATOSVEHICULOS.NACIMDIA.value, document.DATOSVEHICULOS.NACIMMES.value, document.DATOSVEHICULOS.NACIMANN.value, SPNNACIM, "nacimiento"))
		return(false);

	if (document.DATOSVEHICULOS.SEXO.value == '0')
	{
		alert('Falta ingresar el Sexo');
		document.DATOSVEHICULOS.SEXO.focus();
		return(false);
	}

	if (document.DATOSVEHICULOS.ESTADO.value == '0')
	{
		alert('Falta ingresar el Estado Civil');
		document.DATOSVEHICULOS.ESTADO.focus();
		return(false);
	}

	if (document.DATOSVEHICULOS.SELCONDADIC[0].checked)
	{
		if (!ValidarDatosHijos())
			return(false);
		document.DATOSVEHICULOS.CONDADIC.value = "1";
		document.DATOSVEHICULOS.HIJOS1729.value = "1";
	}
	else
	{
		document.DATOSVEHICULOS.CONDADIC.value = "0";
		document.DATOSVEHICULOS.HIJOS1729.value = "0";
	}
	document.DATOSVEHICULOS.FECHACOTI.value = FechaActual();
	return(true);
}

function cambia_CondAdic(pSource)
{
	if (document.DATOSVEHICULOS.SELCONDADIC[0].checked)
	{
		if (pSource == 'LBA')
		{
			if (document.getElementById('TRHAdic')==null)				
				AgregarHijo();
		}
		else
			AgregarHijo_Shell();
	}
	else
	{
		if (pSource == 'LBA')
			LimpiarTabla();
		else
			LimpiarTabla_Shell();
	}
}

function AgregarHijo()
{
	var wvarCantidad;

	if (document.getElementById("TRHAdic"))
		wvarCantidad = (typeof(document.all.TRHAdic.length) == "undefined")?1:document.all.TRHAdic.length;
	else
		wvarCantidad = 0;

	if (wvarCantidad <= 10)
	{
		// TITULO DE TABLA
		var wvarHTML = "";
		var rowIndex = document.getElementById("lastRow").rowIndex;
		var NewRow = document.getElementById("MainTable").insertRow(rowIndex);
		NewRow.id="TRHAdic";

		var NewTD = document.getElementById("MainTable").rows[NewRow.rowIndex].insertCell(-1);
		NewTD.colSpan=4;
		NewTD.className = getRowClass(rowIndex);
		NewTD.innerHTML = "<span class=\"" + getRowClass(rowIndex) + "\" id='fntDATOVEHI'><b>Hijo N° " + String(wvarCantidad + 1) + "</b></span></TD>";

		rowIndex++;
		NewRow = document.getElementById("MainTable").insertRow(rowIndex);

		// EDAD
		NewTD = document.getElementById("MainTable").rows[NewRow.rowIndex].insertCell(-1);
		NewTD.className = getRowClass(rowIndex);
		NewTD.innerHTML = "Edad";

		NewTD = document.getElementById("MainTable").rows[NewRow.rowIndex].insertCell(-1);
		NewTD.className = getRowClass(rowIndex);
		NewTD.colSpan=3;

		wvarHTML = "<select size='1' name='EDADHIJO' class='Form_campname_bcoL' onchange='JavaScript:VerificarDatosHijo(event)'>";
		wvarHTML += "<option selected value='0'>&nbsp;</option>";

		for (var iCounter = 17; iCounter < 30; iCounter ++)
		{
			wvarHTML +=	"<option value='" + GetEdadHijo(iCounter) + "|" + iCounter + "'>" + String(iCounter) + "</option>";
		}

		wvarHTML +=	"</select>"
		NewTD.innerHTML = wvarHTML;

		// SEXO
		rowIndex++;
		NewRow = document.getElementById("MainTable").insertRow(rowIndex);

		NewTD = document.getElementById("MainTable").rows[NewRow.rowIndex].insertCell(-1);
		NewTD.className = getRowClass(rowIndex);
		NewTD.innerHTML = "Sexo";

		NewTD = document.getElementById("MainTable").rows[NewRow.rowIndex].insertCell(-1);
		NewTD.className = getRowClass(rowIndex);
		NewTD.colSpan=3;

		wvarHTML = "<select size='1' name='SEXOHIJO' class='Form_campname_bcoL' onchange='JavaScript:VerificarDatosHijo(event)'>";
		wvarHTML += "<option VALUE='0'>Seleccionar...</option>";
		wvarHTML += "<option VALUE='F'>FEMENINO</option>";
		wvarHTML += "<option VALUE='M'>MASCULINO</option>";
		wvarHTML += "</select>";
		NewTD.innerHTML = wvarHTML;

		// ESTADO CIVIL
		rowIndex++;
		NewRow = document.getElementById("MainTable").insertRow(rowIndex);

		NewTD = document.getElementById("MainTable").rows[NewRow.rowIndex].insertCell(-1);
		NewTD.className = getRowClass(rowIndex);
		NewTD.innerHTML = "Estado Civil";

		NewTD = document.getElementById("MainTable").rows[NewRow.rowIndex].insertCell(-1);
		NewTD.className = getRowClass(rowIndex);
		NewTD.colSpan=3;

		wvarHTML = "<select size='1' name='ESTADOHIJO' class='Form_campname_bcoL' onchange='JavaScript:VerificarDatosHijo(event)'>";
		wvarHTML += "<option VALUE='0'>Seleccionar...</option>";
		wvarHTML += "<option VALUE='S'>SOLTERO/A</option>";
		wvarHTML += "<option VALUE='C'>CASADO/A</option>";
		wvarHTML += "<option VALUE='E'>SEPARADO/A</option>";
		wvarHTML += "<option VALUE='V'>VIUDO/A</option>";
		wvarHTML += "<option VALUE='D'>DIVORCIADO/A</option>";
		wvarHTML += "</select>";
		NewTD.innerHTML = wvarHTML;
	}
}

// ACA VALIDO QUE HAYA INGRESADO TODOS LOS DATOS DEL HIJO Y AGREGO 
// UN NUEVO HIJO
function VerificarDatosHijo(event)
{
	//-------------------------------------------------------------------------------//
	//LR 20/09/2011 esto es para soportar Firefox
	if(event.srcElement)
		var wvarObj = event.srcElement;
	else
		var wvarObj = event.target;
	//-------------------------------------------------------------------------------//
	
	var wvarIndex = wvarObj.parentNode.parentNode.rowIndex;

	//-----------------------------------------------------
	var wvarCantidad;

	var wvarObjeto = document.getElementById("TRHAdic")
	if (document.getElementById("TRHAdic"))
		wvarCantidad = (typeof(document.all.TRHAdic.length) == "undefined")?1:document.all.TRHAdic.length;
	else
		wvarCantidad = 0;
		
	//var wvarCantidad = (typeof(document.all.MainTable.rows("TRHAdic").length) == "undefined")?1:document.all.MainTable.rows("TRHAdic").length;
	//-----------------------------------------------------
	
	var lastRowIndex = document.all.lastRow.rowIndex;

	if (wvarObj.name == "EDADHIJO")
	{
		
		if (wvarObj.value != "0" &&
			document.getElementById("MainTable").rows[wvarIndex + 1].children[1].children[0].value != "0" && 
			document.getElementById("MainTable").rows[wvarIndex + 2].children[1].children[0].value != "0") 
		{
			if (wvarIndex + 3 == lastRowIndex)
				AgregarHijo();
			else
				document.all.MainTable.rows(wvarIndex + 4).children(1).children(0).focus();
		}
		else if (wvarObj.value == "0" &&
			document.all.MainTable.rows(wvarIndex + 1).children(1).children(0).value == "0" && 
			document.all.MainTable.rows(wvarIndex + 2).children(1).children(0).value == "0" &&
			wvarIndex + 3 != lastRowIndex)
		{
			document.all.MainTable.deleteRow(wvarIndex - 1);
			document.all.MainTable.deleteRow(wvarIndex - 1);
			document.all.MainTable.deleteRow(wvarIndex - 1);
			document.all.MainTable.deleteRow(wvarIndex - 1);
			
			for (var iCounter = 0; iCounter < wvarCantidad - 1; iCounter ++)
			{
				document.all.MainTable.rows("TRHAdic")(iCounter).cells(0).children(0).children(0).innerText = "Hijo N° " + String(iCounter + 1);
			}
		}
	}
	else if (wvarObj.name == "SEXOHIJO")
	{
		if (wvarObj.value != "0" &&
			document.getElementById("MainTable").rows[wvarIndex - 1].children[1].children[0].value != "0" && 
			document.getElementById("MainTable").rows[wvarIndex + 1].children[1].children[0].value != "0")
		{
			if (wvarIndex + 2 == lastRowIndex)
				AgregarHijo();
			else
				document.all.MainTable.rows(wvarIndex + 3).children(1).children(0).focus();
		}
		else if (wvarObj.value == "0" &&
			document.all.MainTable.rows(wvarIndex - 1).children(1).children(0).value == "0" && 
			document.all.MainTable.rows(wvarIndex + 1).children(1).children(0).value == "0" &&
			wvarIndex + 2 != lastRowIndex)
		{
			document.all.MainTable.deleteRow(wvarIndex - 2);
			document.all.MainTable.deleteRow(wvarIndex - 2);
			document.all.MainTable.deleteRow(wvarIndex - 2);
			document.all.MainTable.deleteRow(wvarIndex - 2);
			
			for (var iCounter = 0; iCounter < wvarCantidad - 1; iCounter ++)
			{
				document.all.MainTable.rows("TRHAdic")(iCounter).cells(0).children(0).children(0).innerText = "Hijo N° " + String(iCounter + 1);
			}
		}
	}
	else if (wvarObj.name == "ESTADOHIJO")
	{
		if (wvarObj.value != "0" &&
			document.getElementById("MainTable").rows[wvarIndex - 2].children[1].children[0].value != "0" && 
			document.getElementById("MainTable").rows[wvarIndex - 1].children[1].children[0].value != "0")
		{
			if (wvarIndex + 1 == lastRowIndex)
				AgregarHijo();
			else
				document.all.MainTable.rows(wvarIndex + 2).children(1).children(0).focus();
		}
		else if (wvarObj.value == "0" &&
			document.all.MainTable.rows(wvarIndex - 2).children(1).children(0).value == "0" && 
			document.all.MainTable.rows(wvarIndex - 1).children(1).children(0).value == "0" &&
			wvarIndex + 1 != lastRowIndex)
		{
			document.all.MainTable.deleteRow(wvarIndex - 3);
			document.all.MainTable.deleteRow(wvarIndex - 3);
			document.all.MainTable.deleteRow(wvarIndex - 3);
			document.all.MainTable.deleteRow(wvarIndex - 3);
			
			for (var iCounter = 0; iCounter < wvarCantidad - 1; iCounter ++)
			{
				document.all.MainTable.rows("TRHAdic")(iCounter).cells(0).children(0).children(0).innerText = "Hijo N° " + String(iCounter + 1);
			}
		}
	}
}

function LimpiarTabla()
{
	if (document.getElementById("TRHAdic")){
		try
		{
				var wvarCant = (typeof(document.all.TRHAdic.length) == "undefined")?0:document.all.TRHAdic.length - 1;
		}
		catch (e)
		{
			;
		}
	
		var wvarRowIndex;
	
		for (var iCounter = wvarCant; iCounter >= 0; iCounter --)
		{
				wvarRowIndex = (typeof(document.all.TRHAdic.length) == "undefined")?document.getElementById("TRHAdic").rowIndex: document.all.TRHAdic[iCounter].rowIndex;
				document.getElementById("MainTable").deleteRow(wvarRowIndex);
				document.getElementById("MainTable").deleteRow(wvarRowIndex);
				document.getElementById("MainTable").deleteRow(wvarRowIndex);
				document.getElementById("MainTable").deleteRow(wvarRowIndex);
		}
	}
}

function SeleccionarValores_Conductor(pSource, pNACIMDIA, pNACIMMES, pNACIMANN, pSEXO, pESTADO, pTIPODOC, pESCLIENTE, pINFO)
{
	if (pNACIMDIA != '')
		document.DATOSVEHICULOS.NACIMDIA.value = pNACIMDIA;

	if (pNACIMMES != '')
		document.DATOSVEHICULOS.NACIMMES.value = pNACIMMES;

	if (pNACIMANN != '')
		document.DATOSVEHICULOS.NACIMANN.value = pNACIMANN;

	pSEXO = (pSEXO == 'MASCULINO')?'M':(pSEXO == 'FEMENINO')?'F':pSEXO;

	if (pSEXO != '')	
		document.DATOSVEHICULOS.SEXO.value = pSEXO;

	if (pESTADO != '')	
		document.DATOSVEHICULOS.ESTADO.value = pESTADO;

	if (pTIPODOC != "0")
		document.DATOSVEHICULOS.TIPODOC.value = pTIPODOC;

	if (pESCLIENTE !="0")
		document.DATOSVEHICULOS.ESCLIENTE.value = pESCLIENTE;

	if (pESCLIENTE =="N")
	{
		checkPersonalData();
		if (pINFO != "0")
			document.DATOSVEHICULOS.SIINFO.value = pINFO;
	}

	/*	if (pINFO != "0")
		document.DATOSVEHICULOS.INFO.value = pINFO;
	
	if ((pINFO == "0" || pINFO== "") && (pTIPODOC!="0" && pTIPODOC!=""))
		document.DATOSVEHICULOS.INFO.value = 'S';
	*/
	
	cambia_Hijos(pSource);
	cambia_CondAdic(pSource);
	document.DATOSVEHICULOS.FECHACOTI.value = FechaActual();
}

function ValidarDatosHijos()
{
	if (typeof(document.all.EDADHIJO.tagName) != 'undefined')
	{
		// HAY UN SOLO HIJO
		if (trim(document.all.EDADHIJO.value) != '0' || trim(document.all.SEXOHIJO.value) != '0' || trim(document.all.ESTADOHIJO.value) != '0')
		{
			if (trim(document.all.EDADHIJO.value) == '0')
			{
				alert('Debe ingresar la Edad del Hijo');
				document.all.EDADHIJO.focus();
				return false;
			}

			if (trim(document.all.SEXOHIJO.value) == '0')
			{
				alert('Debe ingresar el Sexo del Hijo');
				document.all.SEXOHIJO.focus();
				return false;
			}

			if (document.all.ESTADOHIJO.value == '0')
			{
				alert('Falta ingresar el Estado Civil del hijo');
				document.all.ESTADOHIJO.focus();
				return false;
			}
		}
	}
	else
	{
		// HAY MAS DE UN HIJO 
		for (var iCounter = 0; iCounter < document.all.EDADHIJO.length; iCounter ++)
		{
			if (trim(document.all.EDADHIJO[iCounter].value) != '0' || trim(document.all.SEXOHIJO[iCounter].value) != '0' || trim(document.all.ESTADOHIJO[iCounter].value) != '0')
			{
				if (trim(document.all.EDADHIJO[iCounter].value) == '0')
				{
					alert('Debe ingresar la Edad del Hijo');
					document.all.EDADHIJO[iCounter].focus();
					return false;
				}

				if (trim(document.all.SEXOHIJO[iCounter].value) == '0')
				{
					alert('Debe ingresar el Sexo del Hijo');
					document.all.SEXOHIJO[iCounter].focus();
					return false;
				}

				if (document.all.ESTADOHIJO[iCounter].value == '0')
				{
					alert('Falta ingresar el Estado Civil del hijo');
					document.all.ESTADOHIJO[iCounter].focus();
					return false;
				}
			}
		}
	}

	return true;
}

function RedireccionaSeguroTradicional(pSource)
{
	alert("La cotización de AutoScoring no está disponible\npara la ubicación de domicilio ingresada.");

	if (pSource == 'LBA')
		document.DATOSVEHICULOS.action = "ContactoTradicional.asp";
	else 
		document.DATOSVEHICULOS.action = "ContactoTradicional_shell.asp";

	document.DATOSVEHICULOS.submit();
}


function verificaCuit(pvarCui){

var bol=0;
var i;
var j=9;
var ri;
var resto;
var Delta;
var verif=mfVector(pvarCui,10,1);
var ac=0;

if (pvarCui.length!=11){
	return false;
}
if (!IsNumber(pvarCui)){
	return false;
}

	for (i=1;i<=10;i++){
		ri= i % 6;
		if (ri==0){
			ri=6;
		}
		Delta=mfVector(pvarCui,j,1);
		ac=ac+((ri + 1) * Delta);
		j--;
	}
	
	resto=ac % 11
	
	if (resto==0){
		return resto==verif;
	}
	if (resto>=2 &&	resto<=11){
		return verif== 11-resto;
	}
	return false;
}

function mfVector(pvarValor,pvarPos,pvarLarg){
var ca=pvarValor.substr(pvarPos,pvarLarg)

	return ca
}

function IsNumber(theField)
{
  var checkOK = "0123456789";
  var checkStr = theField;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    return (false);
  }
  else
  {
    return (true);
  }
}

function checkPersonalData(pValor) 
{
	if (pValor=='N')
	{
		document.getElementById("rowPersonalData").style.display = "";
	}
	else
	{
		document.getElementById("rowPersonalData").style.display = "none";
	}
}
