/*
--------------------------------------------------------------------------------
 Fecha de Modificación: 02/05/2007
 PPCR: 20050875-1
 Desarrollador: Daniel Armentano
 Descripción: Se agregan las validaciones y tratamiento de los campos:
 UIFCUIT/OCUPACODCLIE/Datos del Apoderado (datos de Persona y Domicilio y Ocupación)
 Estos datos son exigidos por la UIF para tratamiento e investigación de
 Lavado de Dinero
--------------------------------------------------------------------------------

 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: CotizaU.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";
var isNS = false;
var errorTxt = '';

if(browser == 'Microsoft Internet Explorer')
	version = parseInt(version.substring(22));

if(browser == 'Netscape')
{
	version = parseInt(version);
	isNS = true;
}

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 origend;
	var origenm;
	var origena;
	if(texto == 'inspección')
	{
		origend=document.DATOSVEHICULOS.SELITVLSDIA;
		origenm=document.DATOSVEHICULOS.SELITVLSMES;
		origena=document.DATOSVEHICULOS.SELITVLSANN;
	};

	if(texto == 'nacimiento')
	{
		origend=document.DATOSVEHICULOS.NACIMDIA;
		origenm=document.DATOSVEHICULOS.NACIMMES;
		origena=document.DATOSVEHICULOS.NACIMANN;
	};
	return(valida_fecha_g(dia,mes,anio,area,origend,origenm,origena,texto));
}

function valida_fecha_g(dia,mes,anio,area,origend,origenm,origena,texto)
{
	var hoy = new Date();
	var dd = hoy.getDate();
	var mm = hoy.getMonth();
	var yy = hoy.getFullYear();
	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');
	
	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, pvarRBOKM)
{
	var iNumeros = 0;
	var iLetras = 0;
	var letras = 'abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ';

	//17/04/2007 - Se quita esta validación a pedido de AP y LG.
	//if (pvarPatente.toUpperCase() == "A/D" && pvarRBOKM == "S")
	//	return true;


	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 ++)
	{
		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()
{
	window.close();
}

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 enviarnos sus datos y recibir&aacute; la cotizaci&oacute;n ";
	wvarError += "por <a href='Contacto.asp'>e-mail</a>, o volver a intentarlo m&aacute;s tarde. ";
	wvarError += "</td></tr><tr><td align='center' class='textonormal'>Atentamente. HSBC Seguros.</td>";
	wvarError += "</tr></table>";
	try
	{
		errorTxt = 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');
     }
}


