/*
------------------------------------------------------------------------------
 Fecha de Modificación: 09/08/2011
 PPCR: 2011-00390
 Desarrollador: Leonardo Ruiz
 Descripción: Funcionalidad por Anexo I (planes variables)
--------------------------------------------------------------------------------
 Fecha de Modificación: 21/08/2007
 PPCR: desconocido
 Desarrollador: Fernando Osores
 Descripción: Se modifica la rutina JSMostrarError() para cambiar la descripción
 frente a un error. Antes se derivaba a un mail, ahora se muestra el número del 
 call center.
 -------------------------------------------------------------------------------
 Fecha de Modificación: 13/07/2007
 PPCR: 20060393-1
 Desarrollador: Fernando Osores
 Descripción: Se modifica la rutina valida_patente() para que no permita que las patentes
 con un espacio sean aceptadas. Adicionalmente se eliminó la ñ/Ñ como caracter válido
 para las patentes.
--------------------------------------------------------------------------------

 COPYRIGHT. THE HONGKONG AND SHANGHAI BANKING CORPORATION LIMITED 2007. 
 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: Cotiza.js

Fecha de Creación: desconocido

PPcR: desconocido

Desarrollador: desconocido

Descripción: Se incorpora al fuente el ammendment para cumplir con los requisitos de QA. 
El fuente es preexistente, se desconoce la fecha real de creación y el PPCR original.

--------------------------------------------------------------------------------
*/
var browser = navigator.appName;
var version = navigator.appVersion;
var pobjVentanaCalles;
// pagina de inicio de GoShell
var mvarURL_GOShell = "http://www.go-shell.com.ar/GoShell/insurance/Quoting.asp";


if(browser == 'Microsoft Internet Explorer')
	version = parseInt(version.substring(22));

if(browser == 'Netscape')
	version = parseInt(version);

NS4 = (document.layers) ? true : false;

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 valida_texto(texto, tipo, campo, area, mensaje)
{
	var solotexto = 'abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ ';
	var alfanum = 'abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ0123456789. ';
	var mail = 'abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ0123456789@._-';
	var telefono ='0123456789-';

	text=trim(texto);

	if(tipo=='T' || tipo=='t')
	{
	    for(i=0;i<texto.length;i++)
		{
			if(solotexto.indexOf(texto.charAt(i)) == -1)
			{
				alert(mensaje);
				ver(area,campo);
				return false;
			}
		}
	}

	if(tipo=='L' || tipo=='l')
	{
	    for(i=0;i<texto.length;i++)
		{
			if(telefono.indexOf(text.charAt(i)) == -1)
			{
				alert(mensaje);
				ver(area,campo);
				return false;
			}
		}
	}
	
	if(tipo=='A' || tipo=='a')
	{
		for(i=0;i<texto.length;i++)
		{
			if(alfanum.indexOf(texto.charAt(i)) == -1)
			{
				alert(mensaje);
				ver(area,campo);
				return false;
			}
		}
	}
  
	if(tipo=='E' || tipo=='e')
	{
		conta = 0;
		conta2=0;
		
		for(i=0;i<texto.length;i++)
		{
			if(mail.indexOf(texto.charAt(i)) == -1)
			{
				alert(mensaje);
				ver(area,campo);
				return false;
			}
			else
			{
				if(texto.charAt(i) == '@')
				{
					conta++;

					if(conta > 1)
					{
						alert(mensaje);
				        ver(area,campo);
						return false;
					}
				}
				if(texto.charAt(i) == '.')
				{
					conta2++;
				}
			}
		}

		if(conta==0 || conta2==0)
		{
			alert(mensaje);
			ver(area,campo);
			return false;
		}
		else
		{
			arroba=texto.split('@');
			punto=arroba[1].split('.');

			for(i=0;i<conta2;i++)
			{
				if (punto[i].length == 0)
				{
					alert(mensaje);
					ver(area,campo);
					return false;
				}
			}
		}

		if(texto.charAt(texto.length -1) == '.')
		{
			alert(mensaje);
			ver(area,campo);
			return false;		
		}
	}
    return true;
}

function ver(area,campo)
{
	if(browser == 'Microsoft Internet Explorer' && version == 4) 
	{
		area.focus();
		campo.focus();
	}

	if(browser == 'Microsoft Internet Explorer' && version >= 5) 
	{
		campo.focus();
		area.focus();
		campo.focus();
	}
}

function valida_fecha(dia,mes,anio,area,texto)
{
	var hoy = new Date();
	var dd = hoy.getDate();
	var mm = hoy.getMonth();
	var yy = hoy.getYear();
	var diaspormes= Array(31,29,31,30,31,30,31,31,30,31,30,31);
	var mes_texto= Array('enero','febrero','marzo','abril','mayo','junio','julio','agosto','septiembre','octubre','noviembre','diciembre');

	if(texto == 'inspección')
	{
		origend=document.DATOSVEHICULOS.SELITVLSDIA;
		origenm=document.DATOSVEHICULOS.SELITVLSMES;
		origena=document.DATOSVEHICULOS.SELITVLSANN;
	};

	if(texto == 'nacimiento')
	{
		origend=document.DATOSCONDUCTOR.NACIMDIA;
		origenm=document.DATOSCONDUCTOR.NACIMMES;
		origena=document.DATOSCONDUCTOR.NACIMANN;
	};
	
	mes=mes-0;
	mes--;
	dia=dia-0;
	anio=anio-0;

	if(mes == 1)
	{
		diaspormes[mes]=((anio % 4 == 0 &&  anio % 100 != 0) || (anio % 400 == 0)) ? 29:28;
	}
	
	if(dia > diaspormes[mes])
	{
		alert('En fecha de '+texto+'. \nel número máximo es de ' +diaspormes[mes]+' días \npara el mes de '+mes_texto[mes]+' en el año '+anio);
		ver(area,origend);
		return false;
	}

	if(anio > yy)
	{
		dd=(dd < 10)?'0'+dd:dd;mm++;mm=(mm < 10)?'0'+ mm:mm;mes++;
		alert('En fecha de '+texto+'. \nel año ingresado "'+anio+'" no puede ser superior a la fecha de hoy: '+dd+'/'+mm+'/'+yy);
		ver(area,origena);
		return false;
	}

	if(anio == yy && mes > mm)
	{
		dd=(dd < 10)?'0'+dd:dd;mm++;mm=(mm < 10)?'0'+ mm:mm;mes++;
		alert('En fecha de '+texto+'. \nel mes ingresado "'+mes+'" no puede ser superior a la fecha de hoy: '+dd+'/'+mm+'/'+yy);
		ver(area,origenm);
		return false;
	}

	if(anio == yy && mes == mm && dia > dd)
	{
		dd=(dd < 10)?'0'+dd:dd;mm++;mm=(mm < 10)?'0'+ mm:mm;mes++;
		alert('En fecha de '+texto+'. \nel día ingresado "'+dia+'" no puede ser superior a la fecha de hoy: '+dd+'/'+mm+'/'+yy);
		ver(area,origend);
		return false;
	}
	return true;
}

function valida_patente(pvarPatente, pvarRB0KM)
{
	//var iNumeros = 0;
	//var iLetras = 0;
	
	//13/07/2007 - Se modifica la cadena de caracteres válidos. PPCR 20060393-1
     // La letra ñ/Ñ no es una letra válida para patentes.
     // Modificación realizada por: F.J.O.
	//var letras = 'abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ';
	var letras = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

	if (pvarPatente.toUpperCase() == "A/D" && pvarRB0KM == "S")
		return true;

	//13/07/2007 - Se modifica la rutina para que los espacios (' ') no sean aceptados en la patente.
     // mediante un RegExp se eliminan los espacios ingresados por el usuario. Y continua normalmente 
	// la validación.
     // PPCR 20060393-1
	// Modificación realizada por: F.J.O.
     var rExp = / /gi;
     pvarPatente = pvarPatente.replace(rExp, "");
	
	if (pvarPatente.length != 6)
		return false;
		
	for (var iCounter = 0; iCounter < 3; iCounter ++)
	{
		if (letras.indexOf(pvarPatente.charAt(iCounter)) == -1)
			return false;
	}

	for (iCounter = 3; iCounter < 6; iCounter ++)
	{
		// OJO: isNaN devuelve FALSE si el caracter en cuestión es un espacio (' ').
		if (isNaN(pvarPatente.charAt(iCounter)))
			return false;
	}

	return true;
}


function FechaActual()
{
	var now = new Date();
	var mes = new String((now.getMonth() + 1));
	var dia = new String(now.getDate());
	
	if (mes.length < 2) 
	{
		mes = "0" + mes
	};
	
	if (dia.length < 2) 
	{
		dia = "0" + dia
	};
	
	diaHoy = now.getFullYear() + mes + dia;

	return diaHoy;
}

function BuscarCalles(pvarDOMICILIO, pSource, pobjCALLE, pobjCODPOS, pobjHIDDENCODPOS)
{
	var wvarOpenWindow = false;
	var opciones;
	
	alert('El nombre de la Calle, la Altura y/o el Código Postal son inválidos');

	opciones = "alwaysRaised=1,dependent=1,hotkeys=0,menubar=0,personalbar=0,scrollbars=0,";
	opciones += "status=0,toolbar=0,titlebar=0,location=0,resizable=0,fullscreen=no";
	opciones += "screenX=350,screenY=300,";
	opciones += "width=461,height=350";

	wvarOpenWindow = (typeof(pobjVentanaCalles) == 'undefined');
	
	if (!wvarOpenWindow)
		wvarOpenWindow = pobjVentanaCalles.closed;
			
	if (wvarOpenWindow)
		if (pSource != "GS")
			pobjVentanaCalles = window.open("../Cotizacion/BuscarCalles.asp?Calle=" + pvarDOMICILIO + "&SOURCE=" + pSource + "&OBJCALLE=" + pobjCALLE + "&OBJCODPOS=" + pobjCODPOS + "&OBJHIDDENCODPOS=" + pobjHIDDENCODPOS, "_blank", opciones, true);
		else
			pobjVentanaCalles = window.open("BuscarCalles.asp?Calle=" + pvarDOMICILIO + "&SOURCE=" + pSource + "&OBJCALLE=" + pobjCALLE + "&OBJCODPOS=" + pobjCODPOS + "&OBJHIDDENCODPOS=" + pobjHIDDENCODPOS, "_blank", opciones, true);

	pobjVentanaCalles.focus();
}

function CerrarVentanaCalles()
{
	if (typeof(pobjVentanaCalles) != 'undefined')
		if (! pobjVentanaCalles.closed)
			pobjVentanaCalles.close();
}

function Inicio_Shell()
{
	document.location.href= mvarURL_GOShell;
}

function CerrarVentana()
{
	if(navigator.appName=="Microsoft Internet Explorer") {
		window.close();
	} else {
		alert("Su navegador no permite cerrar esta ventana desde este botón de la aplicación. Hágalo mediante el botón cerrar de la ventana.")
	}

}

function JSMostrarError()
{
	var wvarError;

	wvarError = "<table width='100%' border='0' cellpadding='0' cellspacing='0' align='center'>";
	wvarError += "<tr>";
	wvarError += "<td class='textonormal' align=center>&nbsp;&nbsp;Estimado usuario, lamentamos informarle que por motivos de mantenimiento ";
	wvarError += "el cotizador no est&aacute; disponible en este momento. ";
	wvarError += "Si lo desea, puede comunicarse con nuestro centro de atención al cliente al 0810-999-2424 ";
	wvarError += ", o volver a intentarlo mas tarde. ";
	wvarError += "</td></tr><tr><td align='center' class='textonormal'>Atentamente. HSBC Seguros.</td>";
	wvarError += "</tr></table>";
	
	try
	{
		document.getElementById("DVError").innerHTML = wvarError;
		//document.getElementById("DVError").textContent = wvarError;		
	}
	catch (e)
	{
		;
	}
}

function fncIRDefault(pvarDireccion)
{
	document.forms[0].action=pvarDireccion;
	document.forms[0].submit();
}

function EvalNumber()
{

	var sCadena = event.srcElement.value;
	if (!((event.keyCode >= 96 && event.keyCode <= 105)
			|| (event.keyCode <= 40 && event.keyCode >= 35)
			|| (event.keyCode >= 48 && event.keyCode <= 57)
			|| event.keyCode == 45
			|| event.keyCode == 46
			|| event.keyCode == 8
			|| event.keyCode == 9
			|| event.keyCode == 13
			|| event.keyCode == 32)  || (event.altLeft || event.shiftLeft || event.ctrlLeft) || event.keyCode == 188
			)
	
	{
		event.returnValue = false;
	}
}

function OpenCCs(http,callcenters,hhlang,referer,pwd,rows,cc,un,id) 
{
     browserVer = parseInt(navigator.appVersion);
    if(browserVer>2 )
	if (callcenters) {	
		hWnd=window.open(http+'logincc2.htm?ReadForm&dni='+id+'&referer='+referer+'&pwd='+pwd+'&rows='+rows+'&hhlang='+hhlang+'&UN='+un+'&CC=&EN','','menu=no,screenX=0,screenY=0,left=0,top=0,width=272,height=380');
     } else {
		window.open(http+'login.htm?ReadForm&dni='+id+'&referer='+referer+'&pwd='+pwd+'&rows='+rows+'&hhlang='+hhlang+'&UN='+un+'&CC='+cc+'&EN','','hotkeys=no,menu=no,menubar=no,screenX=0,screenY=0,left=0,top=0,width=272,height=380');
     }
}
/********************************************************************************************/
function CambiarColor(idfila, vEsRC, vLunPar)
{
	//LR ANEXO I
	RestaurarColor();

	/*if(!vLunPar) vLunPar = 'S'
	
	if (vEsRC == 'S')
	{
		//es RC no es obligatorio el rastreo satelital 27/04/01
	  document.all.DISPO_RASTREO.value='N';
	} else {
		if (wvarRequiereDispRastreo == 'S' && document.all.POSEEDISP.value=='N')
		{				
			document.all.DISPO_RASTREO.value="S";
			alert('Debido al monto de la suma asegurada es condición para el otorgamiento de la cobertura que el vehículo cuente con el Dispositivo de Rastreo de Vehículos.\nHSBC Seguros instalará sin cargo un sistema de seguimiento satelital en su vehículo.');
		}
	}
	
	if (document.all.SELLUNETA.value=="S" && vLunPar == "N")
	{
		alert("La cobertura seleccionada no permite incluir el adicional de Lunetas y Parabrisas. \nSi desea incluir esta cobertura adicional deberá elegir entre aquellas coberturas que estén identificadas con la abreviatura LP.");
	}*/
	
	if (document.LISTAPLAN.COBERTURAS[idfila-1])
		if (document.LISTAPLAN.COBERTURAS[idfila-1].value.split("|")[1] == '01604')
	  {
	  	alert("Esta cobertura es válida únicamente para reparaciones realizadas en talleres autorizados por la Compañía")
	  }
	
	document.getElementById("Coberturas").rows[idfila].children[0].className = "Resaltar_filaL";
	document.getElementById("Coberturas").rows[idfila].children[1].className = "Resaltar_filaR";
	
	var col = "C0"+idfila;
	if (document.getElementById("Coberturas").rows[idfila].children[2].id == col)
	{
		document.getElementById("Coberturas").rows[idfila].children[2].className = "Resaltar_filaR";
		document.getElementById("Coberturas").rows[idfila].children[3].className = "Resaltar_filaC";
	}	else {
		document.getElementById("Coberturas").rows[idfila].children[2].className = "Resaltar_filaR";
	}	
}
/********************************************************************************************/
function RestaurarColor()
{
	
	iCounter = document.all.FilaDet.length;
	for (var i = 1; i <= iCounter; i += 2)
	{
		document.getElementById("Coberturas").rows[i].children[0].className = "Form_campname_ColorL";		
		document.getElementById("Coberturas").rows[i].children[1].className = "Form_campname_ColorR";
		
		var col = "C0"+i;
		if (document.getElementById("Coberturas").rows[i].children[2].id == col)
		{			
			document.getElementById("Coberturas").rows[i].children[2].className = "Form_campname_ColorR";
			document.getElementById("Coberturas").rows[i].children[3].className = "Form_campname_ColorC";
		}else
		{	
			document.getElementById("Coberturas").rows[i].children[2].className = "Form_campname_ColorR";
		}
	}		
	
//	iCounter = document.all.Coberturas.rows("FilaDet").length + 1;
	for (var i = 2; i <= iCounter; i += 2)
	{
		document.getElementById("Coberturas").rows[i].children[0].className = "Form_campname_bcoL";
		document.getElementById("Coberturas").rows[i].children[1].className = "Form_campname_bcoR";
			
				
		var col = "C0"+i;				
		if (document.getElementById("Coberturas").rows[i].children[2].id == col)
			{			
			document.getElementById("Coberturas").rows[i].children[2].className = "Form_campname_bcoR";
			document.getElementById("Coberturas").rows[i].children[3].className = "Form_campname_bcoC";
			}
		else
			{			
			document.getElementById("Coberturas").rows[i].children[2].className = "Form_campname_bcoR";
			}
	}
	
}
/********************************************************************************************/


