
function LTrim (Cadena)
{
	while (Cadena.length > 0 && (Cadena.substring (0, 1) == " " || Cadena.substring (0, 1) == "\t"))
		Cadena = Cadena.substring (1);
	return (Cadena);
}


function RTrim (Cadena)
{
	var i = Cadena.length;
	
	while (i > 0 && (Cadena.substring (i - 1, i) == " " || Cadena.substring (i - 1, i) == "\t"))
	{	Cadena = Cadena.substring (0, i - 1);
		i--;
	}
	return (Cadena);
}
	

function Trim (Cadena)
{
	if (typeof Cadena == 'undefined') return (''); else	return (LTrim (RTrim (Cadena)));
}

function EmailCorrecto (Email)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	Email = Trim (Email);

	return (filter.test (Trim (Email)));
}

function Suscribir ()
{
	var Email = Trim (document.Boletin.Email.value);
	
	if (Email)
	{	if (EmailCorrecto (Email))
		{	
			window.location.href='default.asp';
		} else alert ('El email indicado ' + Email + ' no es correcto.');
	}
}

var whitespace = "\\t\\n\\r ";	

	// Check whether string s is empty.
function isEmpty(s)
	{
	   return ((s == null) || (s.length == 0))
	}

function isWhitespace (s)
		
	{   var i;

	    if (isEmpty(s)) return true;
	    for (i = 0; i < s.length; i++)
	    {   
	        var c = s.charAt(i);
	        if (whitespace.indexOf(c) == -1) return false;
	    }
	    return true;
	}

function EnviarMensajePresupuestoRenting(){
	var msg="Informacion introducida incorrecta:\n\n";
	var ok=true;
	if (document.contactar.Autorizo.checked == true)
	{	if (isWhitespace (document.contactar.Nombre.value))
		{
			ok=false;
			msg+="Nombre y Apellidos en Blanco\n";
		}
		if (isWhitespace (document.contactar.Telefono.value))
		{
			ok=false;
			msg+="Teléfono en Blanco\n";
		}
		if (isWhitespace (document.contactar.Poblacion.value))
		{
			ok=false;
			msg+="Población en Blanco\n";
		}
		if (isWhitespace (document.contactar.Provincia.value))
		{
			ok=false;
			msg+="Provincia en Blanco\n";
		}
		if (isWhitespace (document.contactar.Fax.value))
		{
			ok=false;
			msg+="Fax en Blanco\n";
		}
}
	else
	{
		ok=false;
		msg+="Debe Autorizar el tratamiento de sus datos personales\n";
	}
	if (!ok) 
	{
		alert (msg);
		return ok;
	}
	else
	{	
		window.location.href='informacionRentingPresupuesto.asp';
	}	
}

function EnviarMensajeContactar(pag)
{
	var msg="Informacion introducida incorrecta:\n\n";
	var ok=true;
	if (document.contactar.Autorizo.checked == true)
	{	if (isWhitespace (document.contactar.Nombre.value))
		{
			ok=false;
			msg+="Nombre y Apellidos en Blanco\n";
		}
		if (isWhitespace (document.contactar.Telefono.value))
		{
			ok=false;
			msg+="Teléfono en Blanco\n";
		}
		if ((pag != 'llamarAhora.asp') && (pag != 'informacionRentingPresupuesto.asp')){
			if (! (isWhitespace (document.contactar.Email.value)))
			{	
				mail=document.contactar.Email.value;
				arroba = mail.indexOf("@");
				if (arroba == -1)
				{
					ok=false;
					msg+="Formato de la direccion de correo incorrecto\n";
				}
			
			}
			else
			{
					ok=false;
					msg+="Email en Blanco\n";
			}
		}
	}
	else
	{
		ok=false;
		msg+="Debe Autorizar el tratamiento de sus datos personales\n";
	}
	if (!ok) 
	{
		alert (msg);
		return ok;
	}
	else
	{	
		window.location.href=pag;
	}
}

function EnviarMensajeEntrada(pag)
{
	var msg="Informacion introducida incorrecta:\n\n";
	var ok=true;
	if (document.contactar.Autorizo.checked == true)
	{	if (isWhitespace (document.contactar.PersonaContacto.value))
		{
			ok=false;
			msg+="Persona de Contacto en Blanco\n";
		}
		if (isWhitespace (document.contactar.Telefono.value))
		{
			ok=false;
			msg+="Teléfono en Blanco\n";
		}
		if (! (isWhitespace (document.contactar.Email.value)))
		{	
			mail=document.contactar.Email.value;
			arroba = mail.indexOf("@");
			if (arroba == -1)
			{
				ok=false;
				msg+="Formato de la direccion de correo incorrecto\n";
			}
		
		}
		else
		{
				ok=false;
				msg+="Email en Blanco\n";
		}
	}
	else
	{
		ok=false;
		msg+="Debe Autorizar el tratamiento de sus datos personales\n";
	}
	if (!ok) 
	{
		alert (msg);
		return ok;
	}
	else
	{	
		window.location.href=pag;
	}
}


function AvisoLegal ()
{
	window.open ('avisolegal.asp','','width=550,height=400,resizable=yes,scrollbars=yes')	
}

function Mensaje (msg)
{
	alert(msg);
}

function autorizacionDatos()
{
	window.open ('proteccion.htm','','width=300,height=530,resizable=yes,scrollbars=auto')	
}


function createItem(HiddValue,toLst,conTodos)
{
	HiddValue = HiddValue.replace(/ /g,'');
	k=0;
	if (conTodos == true) {
	toLst.options[k]=new Option ('-Todos-', '', false, true);
	k++;
	}
	for (i=0 ; i < document.hiddenObjects.elements.length ;i++)
	{
		if (document.hiddenObjects.elements[i].type == 'hidden')
		{

			if (document.hiddenObjects.elements[i].name == "HNcom"+HiddValue)
			{
				oText=document.hiddenObjects.elements[i].value;
				oValue=document.hiddenObjects.elements[i+1].value;
				toLst.options[k]=new Option (oText, oValue, false, true);
				k++;
			}
		}
	}
	toLst.selectedIndex=0;
	return true;
}

function deleteAllItems(Lst)
{
	var longitud = Lst.options.length;

	longitud=longitud-1;
	for ( k = longitud ; k >= 0  ; k-- )
	{
		Lst.options[k] = null;
	}
	return true;
}				

function changeItems(Lst, Hidd, conTodos)
{
	deleteAllItems(Lst);
	createItem(Hidd,Lst, conTodos);
	return true;
}


function changeAllItems()
{
	a= changeItems(document.ocasion.select2, 'Hname'+document.ocasion.select2.options[document.ocasion.select2.selectedIndex].value);
	return a&b;
}

function aparece(nombre,variable){
	if (document.getElementById("celdaOpc_"+nombre).innerHTML == ""){
		subirTodos();
		document.getElementById("celdaOpc_"+nombre).innerHTML = variable;
	}
	else{
		document.getElementById("celdaOpc_"+nombre).innerHTML = "";
	}
	
}
function subirTodos(){
	var i;
	for (i=1; i<=numcombos; i++){
		document.getElementById("celdaOpc_CRI"+i).innerHTML = "";
	}
	
}

function cambia(nombre){
	if (document.getElementById("iBox_"+nombre).value == "X"){
		document.getElementById("iBox_"+nombre).value = "";
	}
	else{
		document.getElementById("iBox_"+nombre).value = "X";
	}

}

function ordenar(formulario,orden,sentido,num_pag,orden_ant){

	if (orden == orden_ant) {
		if (sentido == 'ASC') {
			sentido = 'DESC';
		} else {
			sentido = 'ASC';		
		}
	} else {
		sentido = 'ASC'
	}
	document.getElementById(formulario).orden.value=orden;
	document.getElementById(formulario).pagina.value= 1;
	document.getElementById(formulario).sentido.value=sentido;
	document.getElementById(formulario).submit();
}

function detalle(formulario,VehiculoId)
{
	document.getElementById(formulario).vehiculoID.value = VehiculoId;
	document.getElementById(formulario).submit();
}


function cambioPagina(formulario, nuevaPagina){
	document.getElementById(formulario).pagina.value= nuevaPagina;
	document.getElementById(formulario).submit();
}

function cambiaColor (fila) {
	var tr = document.getElementById('fila'+fila);
	tr.style.background='#dbdbdb';
	tr.style.color='#003399';
}

function restableceColor (fila) {
	var tr = document.getElementById('fila'+fila);
	tr.style.background='#EbEbEb';
	tr.style.color='#000000';
}

function InformacionRenting(formulario){
	window.open("blanco.html","InfRenting","width=465,height=390,resizable=no,menubar=no,scrollbars=no,status=no,toolbar=no");
	document.getElementById(formulario).submit();
}

function InformacionRentingGenerico(formulario){
	window.open("blanco.html","InfRentingG","width=465,height=390,resizable=no,menubar=no,scrollbars=no,status=no,toolbar=no");
	document.getElementById(formulario).submit();
}

function InformacionRentingPresupuesto(formulario){
	window.open("blanco.html","InfRentingP","width=465,height=500,resizable=no,menubar=no,scrollbars=no,status=no,toolbar=no");
	document.getElementById(formulario).submit();
}

function InformacionRentingAtencion(formulario){
	window.open("blanco.html","InfRentingA","width=465,height=500,resizable=no,menubar=no,scrollbars=no,status=no,toolbar=no");
	document.getElementById(formulario).submit();
}


function InformacionCuentas(formulario){
	window.open("blanco.html","InfCuentas","width=465,height=390,resizable=no,menubar=no,scrollbars=no,status=no,toolbar=no");
	document.getElementById(formulario).submit();
}

function InformacionFAQ(formulario){
	window.open("blanco.html","InfFAQ","width=465,height=390,resizable=no,menubar=no,scrollbars=no,status=no,toolbar=no");
	document.getElementById(formulario).submit();
}

function InformacionAnticipo(formulario){
	window.open("blanco.html","InfAnticipo","width=465,height=390,resizable=no,menubar=no,scrollbars=no,status=no,toolbar=no");
	document.getElementById(formulario).submit();
}
function InformacionLeasing(formulario){
	window.open("blanco.html","InfLeasing","width=465,height=390,resizable=no,menubar=no,scrollbars=no,status=no,toolbar=no");
	document.getElementById(formulario).submit();
}
function InformacionFactoring(formulario){
	window.open("blanco.html","InfFactoring","width=465,height=390,resizable=no,menubar=no,scrollbars=no,status=no,toolbar=no");
	document.getElementById(formulario).submit();
}
function InformacionAvales(formulario){
	window.open("blanco.html","InfAvales","width=465,height=390,resizable=no,menubar=no,scrollbars=no,status=no,toolbar=no");
	document.getElementById(formulario).submit();
}
function InformacionSegurosCredito(formulario){
	window.open("blanco.html","InfSegurosCredito","width=465,height=390,resizable=no,menubar=no,scrollbars=no,status=no,toolbar=no");
	document.getElementById(formulario).submit();
}
function InformacionDpp(formulario){
	window.open("blanco.html","InfDpp","width=465,height=390,resizable=no,menubar=no,scrollbars=no,status=no,toolbar=no");
	document.getElementById(formulario).submit();
}

function InformacionInf(formulario){
	window.open("blanco.html","InfInformacion","width=465,height=390,resizable=no,menubar=no,scrollbars=no,status=no,toolbar=no");
	document.getElementById(formulario).submit();
}

function InformacionAgentes(formulario){
	window.open("blanco.html","InfAgentes","width=465,height=390,resizable=no,menubar=no,scrollbars=no,status=no,toolbar=no");
	document.getElementById(formulario).submit();
}

function llamarAhora(formulario){
	window.open("blanco.html","LlamarAhora","width=465,height=390,resizable=no,menubar=no,scrollbars=no,status=no,toolbar=no");
	document.getElementById(formulario).submit();
}

function eliminarVehiculo(VehiculoID){
	self.event.cancelBubble = true;
	if (confirm("¿Esta seguro de Eliminar este vehiculo?")){
	document.frmConsulta.vehiculoID.value = VehiculoID
	document.frmConsulta.accion.value ="eliminar";			
	document.frmConsulta.submit();
	}
}

function borrarImagen(VehiculoID,FotoID) {
	
	self.event.cancelBubble = true;
	if (confirm("¿Esta seguro de Borrar esta imagen?")){
	document.frmConsulta.vehiculoID.value = VehiculoID
	document.frmConsulta.FotoID.value = FotoID
	document.frmConsulta.accion.value ="BorrarImagen";			
	document.frmConsulta.submit();
	}
}

function anyadirImagen(formulario){
	window.open("blanco.html","ImagenNueva","width=465,height=290,resizable=no,menubar=no,scrollbars=no,status=no,toolbar=no");
	document.getElementById(formulario).submit();
}

function refrescarVehiculo(){
	document.frmConsulta.accion.value = "";
	document.frmConsulta.submit();
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function altaClienteDto()
{
	window.open ('informacionAltaCliente.htm','','width=600,height=350,resizable=yes,scrollbars=auto')	
}

function numCheck(argvalue) {

  if (argvalue.length == 0)
    return false;

  for (var n = 0; n < argvalue.length; n++)
    if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9")
      return false;

  return true;

}


function formatoAnyo(argvalue) {
  var numOfDecimal = 0;
  var resultado = true;
  if (argvalue.indexOf(" / ") == -1) {
	resultado = false;
  }
  if (!numCheck(argvalue.substring(0,4))){
	resultado = false;

  }
  if (!numCheck(argvalue.substring(7,9))){
	resultado = false;
	
  }
  if (argvalue.length != 9 ){
	  resultado = false;
  }
  return resultado;
}
