// Logica del cuadro de notificación para envíos de listados en subasta

var pics = new Array(4);
var cdro;
var timer;

 for(var i=0;i<pics.length;i++)
   pics[i] = new Image();
   
   pics[0].src = path + "/subasta/images/hd.gif";
   pics[1].src = path + "/subasta/images/ayb.gif";
   pics[2].src = path + "/asesorias/images/enviar.gif";
   pics[3].src = path + "/subasta/images/fd.gif";

function mostrarFranja(s){
    var c = document.getElementById("franja");
	var w = (s>324)?324:s;

	c.style.width = w + "px";
	
	if(w<324){
	 setTimeout("mostrarFranja(" + (w+80) + ")",300);
	}
	else{
	   document.getElementById("curva").src = f1.src;
	   var a = document.createElement("a");
	       a.setAttribute("href","javascript:mostrarCuadro();void(0);");
		   a.setAttribute("title","Clic aqui para que nos autorice el envio por email de listados de inmuebles en subasta cuando hayan.");
	   var imagen = document.createElement("img");
	       imagen.setAttribute("src",f2.src);
	   a.appendChild(imagen);	   
	   c.appendChild(a); 
	} 
}

function mostrarCuadro(){

	if(!cdro){
	       var ancho = 264;
	       var alto = 132;

	           if (window.screenX) { 
                   x = window.screenX + ((window.outerWidth - ancho) / 2);
                   y = window.screenY + ((window.outerHeight - alto) / 2);
               }  
			   else if (window.screenLeft) { 
                   var CSSCompat = (document.compatMode && document.compatMode != "BackCompat");
                       window.outerWidth = (CSSCompat)?document.body.parentElement.clientWidth:document.body.clientWidth;
                       window.outerHeight = (CSSCompat)?document.body.parentElement.clientHeight:document.body.clientHeight;
                       window.outerHeight -= 80;
                       x = parseInt(window.screenLeft+((window.outerWidth - ancho) / 2));
                       y = parseInt(window.screenTop + ((window.outerHeight - alto) / 2));
               } else {   
                   x = (screen.width - ancho) / 2;
                   y = (screen.height - alto) / 2;
                }
				
             cdro = new cuadro(x,y);
			 cdro.build();

	}
	else{
		document.getElementById("cuadro").style.visibility = "visible"
	}
}

function cuadro(x,y){
	 this.x = x;
	 this.y = y;
	 
	 this.build = function(){
		 var contenido = '<form id="datos">';
             contenido += '<img src="' + pics[0].src + '">';
             contenido += '<div>';
             contenido += '<a href="javascript:abrirDialogo();void(0);" title="Clic para obtener mas informacion"><img src="' + pics[1].src + '" style="float:right;margin-right:9px;margin-top:-8px;"></a>';
             contenido += '<label>Nombre/Apellido</label>';
             contenido += '<input name="nombre" type="text" value="" id="nbre">';
             contenido += '<label>E-mail</label>';
             contenido += '<input name="email" type="text" value="" id="em">';
             contenido += '<a href="javascript:enviar();void(0);" title="Clic para enviar sus datos."><img src="' + pics[2].src + '" style="float:right;margin-right:14px;margin-top:-15px;"></a>';
             contenido += '</div>';
             contenido += '<img src="' + pics[3].src + '">';
             contenido += '</form>';		

		  cd = document.createElement("div");
		  cd.setAttribute("id","cuadro");
		  cd.style.top = this.y;
		  cd.style.left = this.x;
		  cd.innerHTML = contenido;

		  document.getElementsByTagName("body")[0].appendChild(cd);
          cd.onmouseover = function(){if(timer)clearTimeout(timer);};
		  cd.onmouseout = function(){timer=setTimeout("cerrar()",1000);};
	 };
	 
	 
}

function cerrar(){
	 if(document.getElementById("cuadro"))document.getElementById("cuadro").style.visibility = "hidden";
}

function abrirDialogo(){
	alert("La informacion que usted nos suministra aqui estara protegida por nuestra politica de confidencialidad y privacidad de datos. Estos datos son necesarios para que le podamos enviar a usted la notificacion y un listado de propiedades en subasta, una vez tengamos disponibles. Gracias.");
}

function enviar(){
	var p1 = /^[a-zA-Z\s]{3,40}$/;
	var p2 = /^([\w]+)(\.[\w]+)*@([\w]+)(\.[a-z]{2,3})+$/;
	//Validar campos
	if(!p1.test(document.getElementById("nbre").value)){ //Validar campo nombre y apellido
		document.getElementById("nbre").focus();
		document.getElementById("nbre").select();
		alert("El campo 'Nombre/Apellido' debe ser diligenciado correctamente.");
	}
	else if(!p2.test(document.getElementById("em").value)){ //Validar campo email
	    document.getElementById("em").focus();
		document.getElementById("em").select();
		alert("El campo 'Email' debe ser diligenciado correctamente.");
	}
	else{ //Se envía

	   var form = document.getElementById("datos");
	    form.method = "post";
	    form.action = path + "/servlet/Contacto?codigo=6070";
	    form.submit(); 

	}
}
