var req;
var req2;
var target;
var isIE;

function resetContenido() { 
	document.forms['busquedaBean'].detalleO.value = "buscar en ofertas";
	document.forms['busquedaBean'].detalleA.value = "buscar en anunciantes";
}
function resetAll() {
	document.forms['busquedaBean'].detalleO.value = "buscar en ofertas";
	document.forms['busquedaBean'].detalleA.value = "buscar en anunciantes";
	document.forms['busquedaBean'].zona.value = "";
	document.forms['busquedaBean'].distrito.value = "";
	document.forms['busquedaBean'].sector.value = "";
	document.forms['busquedaBean'].subSector.value = "";
	
}
function borrarContenido() {
	var textoO = document.forms['busquedaBean'].detalleO.value;
	var textoA = document.forms['busquedaBean'].detalleA.value;
	if(textoO == "buscar en ofertas"){
		document.forms['busquedaBean'].detalleO.value = "";
	}
	if(textoA == "buscar en anunciantes") {
		document.forms['busquedaBean'].detalleA.value = "";
	}
}
function borrarContenidoUsuario() {
	var texto = document.forms['logearBean'].usuarioP.value;
	if (texto == "nombre de usuario") {
		document.forms['logearBean'].usuarioP.value = "";
	}
}
function borrarContenidoClave() {
	document.forms['logearBean'].claveP.value = "";
}
function xstooltip_findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	} else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function xstooltip_findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y)
		curtop += obj.y;
	return curtop;
}
function xstooltip_show(tooltipId, parentId, posX, posY) {
	it = document.getElementById(tooltipId);
	if ((it.style.top == '' || it.style.top == 0)
			&& (it.style.left == '' || it.style.left == 0)) {
		// need to fixate default size (MSIE problem)
		it.style.width = it.offsetWidth + 'px';
		it.style.height = it.offsetHeight + 'px';

		img = document.getElementById(parentId);
		// if tooltip is too wide, shift left to be within parent
		// if (posX + it.offsetWidth > img.offsetWidth) posX = img.offsetWidth -
		// it.offsetWidth;
		// if (posX < 0 ) posX = 0;

		x = xstooltip_findPosX(img) + posX;
		y = xstooltip_findPosY(img) + posY;

		it.style.top = y + 'px';
		it.style.left = x + 'px';
	}

	it.style.display = 'block';
}
function reposicionarTextosAnunciantes() {
	it = document.getElementById(idCapa);
	tamanoReal = parseInt(it.style.height.substring(0, it.style.height.length
			- 2));
	tamano = tamanoReal + alto;
	it.style.height = tamano + 'px';
}
function capaResize(idCapa, alto) {
	it = document.getElementById(idCapa);
	tamanoReal = parseInt(it.style.height.substring(0, it.style.height.length
			- 2));
	tamano = tamanoReal + alto;
	it.style.height = tamano + 'px';
}

function xstooltip_show_hide(tooltipId, divToHide) {
	it = document.getElementById(tooltipId);
	it2 = document.getElementById(divToHide);

	/*
	 * if ((it.style.top == '' || it.style.top == 0) && (it.style.left == '' ||
	 * it.style.left == 0)) { // need to fixate default size (MSIE problem)
	 * it.style.width = it.offsetWidth + 'px'; it.style.height = it.offsetHeight +
	 * 'px';
	 * 
	 * img = document.getElementById(parentId); // if tooltip is too wide, shift
	 * left to be within parent if (posX + it.offsetWidth > img.offsetWidth)
	 * posX = img.offsetWidth - it.offsetWidth; if (posX < 0 ) posX = 0;
	 * 
	 * x = xstooltip_findPosX(img) + posX; y = xstooltip_findPosY(img) + posY;
	 * 
	 * 
	 * it.style.top = y + 'px'; it.style.left = x + 'px'; }
	 */

	// it.style.visibility = 'visible';
	// it2.style.visibility = 'hidden';
	it.style.display = 'block';
	it2.style.display = 'none';
}

function xstooltip_show_hide2(tooltipId, divToHide1, divToHide2) {
	it = document.getElementById(tooltipId);
	it2 = document.getElementById(divToHide1);
	it3 = document.getElementById(divToHide2);

	/*
	 * if ((it.style.top == '' || it.style.top == 0) && (it.style.left == '' ||
	 * it.style.left == 0)) { // need to fixate default size (MSIE problem)
	 * it.style.width = it.offsetWidth + 'px'; it.style.height = it.offsetHeight +
	 * 'px';
	 * 
	 * img = document.getElementById(parentId); // if tooltip is too wide, shift
	 * left to be within parent if (posX + it.offsetWidth > img.offsetWidth)
	 * posX = img.offsetWidth - it.offsetWidth; if (posX < 0 ) posX = 0;
	 * 
	 * x = xstooltip_findPosX(img) + posX; y = xstooltip_findPosY(img) + posY;
	 * 
	 * 
	 * it.style.top = y + 'px'; it.style.left = x + 'px'; }
	 */

	// it.style.visibility = 'visible';
	// it2.style.visibility = 'hidden';
	it.style.display = 'block';
	it2.style.display = 'none';
	it3.style.display = 'none';
}

function xstooltip_hide(id) {
	it = document.getElementById(id);
	it.style.display = 'none';
}
function cambiarExplicacionOferta(idNuevo) {
	for (i = 1; i <= 5; i++) {
		var capa = document.getElementById("incluir_oferta_0" + i);
		capa.style.display = "none";
	}
	var capa = document.getElementById("incluir_oferta_0" + idNuevo);
	capa.style.display = "block";

}
function cambiarDescuentoOferta(idNuevo) {
	for (i = 1; i <= 5; i++) {
		var capa = document.getElementById("formulario_descuento0" + i);
		capa.style.display = "none";
	}
	var capa = document.getElementById("formulario_descuento0" + idNuevo);
	capa.style.display = "block";

}
function logear() {
	document.forms['logearBean'].action = '/Logear.do';
	document.forms['logearBean'].submit();
	return false;
}
var capa;
var capaPresentada = false;
var fondo;
addEvent(window, "scroll", centrarFondo);
addEvent(window, "resize", centrarFondo);
var gHideSelects = false;

function VerFormularioModal(idCapa) {
	// if it's IE, we hide the dropdown because in IE 6 and below, the select dropdown is always on top
	// we just dont bother checking if it's IE 6 and below, we apply it to all IE
	if (window.navigator.appVersion.indexOf("MSIE") > -1)
	{
		gHideSelects = true;
	}
	
	fondo = document.getElementById("popupMaskMio");
	capa = document.getElementById(idCapa);
	capa.style.position = "absolute";
	capa.style.display = "block";
	fondo.style.display = "block";
	capaPresentada = true;
	centrarCapas();
	
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
}

/**
* Hides all drop down form select boxes on the screen so they do not appear above the mask layer.
* IE has a problem with wanted select form tags to always be the topmost z-index or layer
* Thanks for the code Scott!
*/
function hideSelectBoxes() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
				document.forms[i].elements[e].style.visibility="hidden";
			}
		}
	}
}

function OcultarFormularioModal(idCapa) {
	fondo = document.getElementById("popupMaskMio");
	capa = document.getElementById(idCapa);
	capa.style.position = "absolute";
	capa.style.display = "none";
	fondo.style.display = "none";
	capaPresentada = false;
	
	if (gHideSelects == true)
	{
		displaySelectBoxes();
		gHideSelects = false;
	}
}

/**
* Makes all drop down form select boxes on the screen visible so they do not reappear after the dialog is closed.
* IE has a problem with wanted select form tags to always be the topmost z-index or layer
*/
function displaySelectBoxes() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
			document.forms[i].elements[e].style.visibility="visible";
			}
		}
	}
}

function centrarCapas() {
	if (capaPresentada == true) {
		var fullHeight = getViewportHeight();
		var fullWidth = getViewportWidth();
		width = capa.offsetWidth;
		height = capa.offsetHeight;
		var scLeft, scTop;
		if (self.pageYOffset) {
			scLeft = self.pageXOffset;
			scTop = self.pageYOffset;
		} else if (document.documentElement
				&& document.documentElement.scrollTop) {
			scLeft = document.documentElement.scrollLeft;
			scTop = document.documentElement.scrollTop;
		} else if (document.body) {
			scLeft = document.body.scrollLeft;
			scTop = document.body.scrollTop;
		}
		fondo.style.height = fullHeight + "px";
		fondo.style.width = fullWidth + "px";
		fondo.style.top = scTop + "px";
		fondo.style.left = scLeft + "px";
		var titleBarHeight = 0;
		var topMargin = scTop + ((fullHeight - (height + titleBarHeight)) / 2);
		if (topMargin < 0) {
			topMargin = 0;
		}
		capa.style.top = "100px";
		capa.style.left = (scLeft + ((fullWidth - width) / 2)) + "px";
	}
}
function centrarFondo() {
	if (capaPresentada == true) {
		var fullHeight = getViewportHeight();
		var fullWidth = getViewportWidth();
		width = capa.offsetWidth;
		height = capa.offsetHeight;
		var scLeft, scTop;
		if (self.pageYOffset) {
			scLeft = self.pageXOffset;
			scTop = self.pageYOffset;
		} else if (document.documentElement
				&& document.documentElement.scrollTop) {
			scLeft = document.documentElement.scrollLeft;
			scTop = document.documentElement.scrollTop;
		} else if (document.body) {
			scLeft = document.body.scrollLeft;
			scTop = document.body.scrollTop;
		}
		fondo.style.height = fullHeight + "px";
		fondo.style.width = fullWidth + "px";
		fondo.style.top = scTop + "px";
		fondo.style.left = scLeft + "px";
		var titleBarHeight = 0;
		var topMargin = scTop + ((fullHeight - (height + titleBarHeight)) / 2);
		if (topMargin < 0) {
			topMargin = 0;
		}
		// capa.style.top = topMargin + "px";
		capa.style.left = (scLeft + ((fullWidth - width) / 2)) + "px";
	}
}

function getViewportHeight() {
	if (window.innerHeight != window.undefined)
		return window.innerHeight;
	if (document.compatMode == 'CSS1Compat')
		return document.documentElement.clientHeight;
	if (document.body)
		return document.body.clientHeight;
	return window.undefined;
}

function getViewportWidth() {
	if (window.innerWidth != window.undefined)
		return window.innerWidth;
	if (document.compatMode == 'CSS1Compat')
		return document.documentElement.clientWidth;
	if (document.body)
		return document.body.clientWidth;
	return window.undefined;
}
function addEvent(obj, evType, fn) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, false);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on" + evType, fn);
		return r;
	} else {
		return false;
	}
}
function resetAltaDirecciones() {
	document.getElementById('direccion_id3').value = "";
	document.getElementById('direccion2_id3').value = "";
	document.getElementById('cp_id3').value = "";
	document.getElementById('telefono_id3').value = "";
	document.getElementById('direccionCorreo_id3').value = "";
	document.getElementById('direccionWeb_id3').value = "";
	document.getElementById('zona_id3').value = "";
	loadOptions('/DistritosAJAX.do?', "", 'distrito_id3');
	document.getElementById('distrito_id3').value = "";
}
var cambio = false;
var direccionAntigua = "";
function notificarCambio(cambioAux) {
	cambio = cambioAux;
}
function cambiarDireccionAntigua(direccion) {
	direccionAntigua = direccion;
}

/*
function calcularCreditos() {
	var fechaIni = document.getElementById("fechaIni");
	var fechaFin = document.getElementById("fechaFin");
	var fecha1 = new fecha(fechaIni.value);
	var fecha2 = new fecha(fechaFin.value);
	var miFecha1 = new Date(fecha1.anio, fecha1.mes, fecha1.dia);
	var miFecha2 = new Date(fecha2.anio, fecha2.mes, fecha2.dia);
	var diferencia = miFecha2.getTime() - miFecha1.getTime();
	var dias = Math.floor(diferencia / (1000 * 60 * 60 * 24)) + 1;
	var creditosCalculados = document.getElementById("creditosCalculados");
	var creditos = document.getElementById("creditos");
	creditosDisponibles = parseInt(creditos.innerHTML);
	creditosCalculados.innerHTML = dias;
	restaCreditos = creditosDisponibles - dias;
	if (restaCreditos >= 0) {
		var errorCreditos = document.getElementById("errorCreditos");
		errorCreditos.className = '';
		var creditosSuma = document.getElementById("creditosSuma");
		creditosSuma.className = '';
		creditosSuma.innerHTML = restaCreditos;
	} else {
		var errorCreditos = document.getElementById("errorCreditos");
		errorCreditos.className = 'registroerror';
		var creditosSuma = document.getElementById("creditosSuma");
		creditosSuma.className = 'registroerror';
		creditosSuma.innerHTML = "insuficientes";
	}

}
*/
function fecha(cadena) {
	var separador = "/";
	if (cadena.indexOf(separador) != -1) {
		var posi1 = 0;
		var posi2 = cadena.indexOf(separador, posi1 + 1);
		var posi3 = cadena.indexOf(separador, posi2 + 1);
		this.dia = cadena.substring(posi1, posi2);
		this.mes = cadena.substring(posi2 + 1, posi3);
		this.anio = cadena.substring(posi3 + 1, cadena.length);
	} else {
		this.dia = 0
		this.mes = 0
		this.anio = 0
	}
}
function cambiarTipoDescuento(tipoDescuento) {
	var descuento1Activo = document
			.getElementById("formulario_descuento01_activo");
	var descuento1Inactivo = document
			.getElementById("formulario_descuento01_inactivo");
	var descuento2Activo = document
			.getElementById("formulario_descuento02_activo");
	var descuento2Inactivo = document
			.getElementById("formulario_descuento02_inactivo");
	if (tipoDescuento == 1) {
		descuento1Activo.style.display = "block";
		descuento1Inactivo.style.display = "none";
		descuento2Activo.style.display = "none";
		descuento2Inactivo.style.display = "block";
	} else {
		descuento1Activo.style.display = "none";
		descuento1Inactivo.style.display = "block";
		descuento2Activo.style.display = "block";
		descuento2Inactivo.style.display = "none";
	}
}

var fechaFija;// finFechaPublicacion
var fechaValida;

function completarFechas(inicioFechaPublicacion, finFechaPublicacion,
		inicioFechaValidez, finFechaValidez, creditosDisponibles, 
		tipoVenta, esCuponable, creditosToDeductOfertaAbierta) {
	
	// 2008-06-25 anio-mes-dia
	var fechaFijaArr;
	// año-mes-día, el mes es de 0 a 11
	fechaFijaArr = inicioFechaValidez.split('/');
	document.getElementById('inicioFechaValidez').innerHTML = fechaFijaArr[0]
			+ "/" + fechaFijaArr[1] + "/" + fechaFijaArr[2];
	fechaFijaArr = finFechaValidez.split('/');
	document.getElementById('finFechaValidez').value = fechaFijaArr[0] + "/"
			+ fechaFijaArr[1] + "/" + fechaFijaArr[2];
	fechaFijaArr = inicioFechaPublicacion.split('/');
	document.getElementById('inicioFechaPublicacion').innerHTML = fechaFijaArr[0]
			+ "/" + fechaFijaArr[1] + "/" + fechaFijaArr[2];

	fechaFijaArr = finFechaPublicacion.split('/');
	document.getElementById('finFechaPublicacion').value = fechaFijaArr[0]
			+ "/" + fechaFijaArr[1] + "/" + fechaFijaArr[2];
	fechaFija = new Date(fechaFijaArr[2], fechaFijaArr[1] - 1, fechaFijaArr[0]);
	fechaValida = 1;

	if (tipoVenta == 0 || tipoVenta == 2) {
		if (esCuponable == "true") {
			document.getElementById("creditos_necesarios_div").innerHTML = "1 por cup&oacute;n bajado";
			document.getElementById("formulario_modal_infotexto_ampliar").innerHTML = "<b>con tus créditos actuales se pueden bajar hasta <span class='dark_green'>" +
					creditosDisponibles +" cupones</span></b>";
		} else {
			document.getElementById("creditos_necesarios_div").innerHTML = creditosToDeductOfertaAbierta + " al d&iacute;a";
			
			var daysAvailable;
			if (creditosToDeductOfertaAbierta > 1) {
				daysAvailable = parseInt((creditosDisponibles/creditosToDeductOfertaAbierta));
			} else {
				daysAvailable = "-";
			}
			
			document.getElementById("formulario_modal_infotexto_ampliar").innerHTML = "<b>con tus créditos actuales se podría ver la oferta <span class='dark_green'>por " +
			  daysAvailable + " días</span></b>";
		}
	} else {
		document.getElementById("creditos_necesarios_div").innerHTML = "1 por click";
		document.getElementById("formulario_modal_infotexto_ampliar").innerHTML = "<b>con tus créditos actuales te pueden llegar hasta <span class='dark_green'>" +
		            creditosDisponibles + " nuevos clientes</span></b>";
	}
	
	document.getElementById("creditos_restantes_div").innerHTML = creditosDisponibles;

	document.getElementById("creditos_negativo_div").style.display = "none";
	document.getElementById("error_creditos_negativo").style.display = "none";
	//document.getElementById("creditos_positivo_div").style.display = "";
	document.getElementById("creditos_positivo_div").style.display = "none";
	
}

/*
function calcularCreditosOferta() {
	var finFechaPublicacion = document.getElementById('finFechaPublicacion').value;
	var fechaFijaArr;
	fechaFijaArr = finFechaPublicacion.split('/');
	var fechaIngresadaDate = new Date(fechaFijaArr[2], fechaFijaArr[1] - 1,
			fechaFijaArr[0]);
	var undia = 1000 * 60 * 60 * 24;
	var diferenciaEnDias = Math.ceil((fechaIngresadaDate.getTime() - fechaFija
			.getTime())
			/ undia);
	document.getElementById("creditos_necesarios_div").innerHTML = diferenciaEnDias;
	document.getElementById("creditos_restantes_div").innerHTML = document
			.getElementById("creditos_disponibles_div").innerHTML
			- diferenciaEnDias;
	document.getElementById("creditos_restantes_div2").innerHTML = document
			.getElementById("creditos_disponibles_div").innerHTML
			- diferenciaEnDias;

	document.getElementById("error_creditos_negativo").style.display = "none";

	if (document.getElementById("creditos_restantes_div").innerHTML == "NaN"
			|| diferenciaEnDias < 0) {
		document.getElementById("creditos_necesarios_div").innerHTML = 0;
		document.getElementById("creditos_restantes_div").innerHTML = document
				.getElementById("creditos_disponibles_div").innerHTML;
		document.getElementById("creditos_restantes_div2").innerHTML = document
				.getElementById("creditos_disponibles_div").innerHTML;
		if (diferenciaEnDias < 0) {
			fechaValida = 0;
		}
	} else {
		if ((document.getElementById("creditos_disponibles_div").innerHTML - diferenciaEnDias) < 0) {
			//document.getElementById("creditos_negativo_div").style.display = "";
			document.getElementById("creditos_negativo_div").style.display = "none";
			document.getElementById("creditos_positivo_div").style.display = "none";
			fechaValida = 0;
		} else {
			document.getElementById("creditos_negativo_div").style.display = "none";
			//document.getElementById("creditos_positivo_div").style.display = "";
			document.getElementById("creditos_positivo_div").style.display = "none";
			fechaValida = 1;
		}
	}
}
*/

/*
function calcularCreditosOferta() {
	alert('calcularCreditosOferta');
	
}
*/

function submitCambiarFechasOferta() {
	//calcularCreditosOferta();
	document.forms['cambiarFechasOfertaBean'].submit();
	return false;
}

function submitAmpliarDescargasOferta() {		
	document.forms['ampliarDescargasOfertaBean'].submit();
	return false;
}

function submitCambiarLinkDirectoBean() {		
	document.forms['cambiarLinkDirectoBean'].submit();
	return false;
}

function cerrarPromocion() {
	var codigoPromocion = document.getElementById("codigoPromocion");
	codigoPromocion.disabled = true;
}
function abrirPromocion() {
	var codigoPromocion = document.getElementById("codigoPromocion");
	codigoPromocion.disabled = false;
}
function borrarContenidoPromocion() {
	var codigoPromocion = document.getElementById("codigoPromocion");
	codigoPromocion.value = "";
}
function cerrarCupon() {
	var esLimitado = document.getElementById("esLimitado");
	var esConBarras = document.getElementById("esConBarras");
	var limiteDescargas = document.getElementById("limiteDescargas");
	var codigoBarras = document.getElementById("codigoBarras");
	esLimitado.disabled = true;
	esConBarras.disabled = true;
	esLimitado.checked=false;
	esConBarras.checked=false;
	limiteDescargas.disabled = true;
	codigoBarras.disabled = true;
	limiteDescargas.value = "";
	codigoBarras.value = "";
	
	limite=false;
	barras=false;
}
function abrirCupon() {
	var esLimitado = document.getElementById("esLimitado");
	var esConBarras = document.getElementById("esConBarras");
	var limiteDescargas = document.getElementById("limiteDescargas");
	var codigoBarras = document.getElementById("codigoBarras");
	esLimitado.disabled = false;
	esConBarras.disabled = false;
	
	//limiteDescargas.disabled = false;
	//codigoBarras.disabled = false;
	//limiteDescargas.value = "";
	//codigoBarras.value = "";
}

function abrirCuponSeguras() {
	var esLimitadoSeguras = document.getElementById("esLimitado");
	var esCantidadSeguros = document.getElementById("esCantidadSeguros");
	
	var limiteDescargasSeguras = document.getElementById("limiteDescargas");	
	if (!esLimitadoSeguras){						
	   limiteDescargasSeguras.value=""; 
	}
	
	var limiteCuponSegXPersona = document.getElementById("limiteCuponSegXPersona");
	if (!esCantidadSeguros){				
		limiteCuponSegXPersona.value=""; 
	}
}

var limite = false;
function abrirLimite() {
	var esLimitado = document.getElementById("esLimitado");
	var limiteDescargas = document.getElementById("limiteDescargas");
	
	if (!limite) {
		limiteDescargas.disabled = false;
		limite = true;
	} else {
		limiteDescargas.disabled = true;
		limiteDescargas.value="";
		limite = false;
	}
}

var limiteSeguras = false;
function abrirLimiteSeguras() {	
	var esLimitado = document.getElementById("esLimitado");
	var limiteDescargas = document.getElementById("limiteDescargas");
	
	if (!limiteSeguras) {
		limiteDescargas.disabled = false;
		limiteSeguras = true;
	} else {		
		limiteDescargas.disabled = true;
		limiteDescargas.value="";
		limiteSeguras = false;
	}
}

//
var conTitulo = false;
function abrirTitulo() {	
   var tieneTitulo = document.getElementById("tieneTitulo");
   var titulo = document.getElementById("titulo");
	
   if (!conTitulo) {
      titulo.disabled = false;
	  conTitulo = true;
   } else {		
      titulo.disabled = true;
	  titulo.value="";
	  conTitulo = false;
   }
}

var cantidadSeguros = false;
function abrirCantidadSeguros() {	
	var esLimitado = document.getElementById("esCantidadSeguros");
	var limiteDescargas = document.getElementById("limiteCantidadSeguros");
	
	if (!cantidadSeguros) {
		limiteDescargas.disabled = false;
		cantidadSeguros = true;
	} else {		
		limiteDescargas.disabled = true;
		limiteDescargas.value="";
		cantidadSeguros = false;
	}
}

var barras = false;
function abrirCodigoBarras() {
	var esConBarras = document.getElementById("esConBarras");
	var codigoBarras = document.getElementById("codigoBarras");
	
	if (!barras) {
		codigoBarras.disabled = false;
		barras = true;
	} else {
		codigoBarras.disabled = true;
		codigoBarras.value = "";
		barras = false;
	}
}
function addfav() {
	title = "oportunista.com - solo ofertas, nada más";
	url = "http://www.oportunista.com";
	if (window.sidebar) {
		window.sidebar.addPanel(title, url, "");
	} else if (window.opera && window.print) {
		var mbm = document.createElement('a');
		mbm.setAttribute('rel', 'sidebar');
		mbm.setAttribute('href', url);
		mbm.setAttribute('title', title);
		mbm.click();
	} else if (document.all) {
		window.external.AddFavorite(url, title);

	}
}
function EnviarInvitaciones() {
	document.forms['mandarInvitacionesBean'].submit();
}
function SumarInvitaciones() {
	/*
	 * numInvitaciones =
	 * parseInt(document.forms['mandarInvitacionesBean'].tamanoInvitaciones.value);
	 * var texto=""; for(i=0;i<numInvitaciones;i++){
	 * texto+=document.forms['mandarInvitacionesBean'].elements[2*i].value+"#"+document.forms['mandarInvitacionesBean'].elements[(2*i)+1].value+"#"; }
	 * document.forms['mandarInvitacionesBean'].textoInvitaciones.value=texto;
	 */
	document.forms['mandarInvitacionesBean'].action = "/SumarInvitaciones.do";
	document.forms['mandarInvitacionesBean'].submit();
}
function RestarInvitaciones() {
	numInvitaciones = parseInt(document.forms['mandarInvitacionesBean'].tamanoInvitaciones.value);
	if (numInvitaciones > 1) {
		document.forms['mandarInvitacionesBean'].action = "/RestarInvitaciones.do";
		document.forms['mandarInvitacionesBean'].submit();
	}
}
function ColocarInvitaciones() {
	var texto = document.forms['mandarInvitacionesBean'].textoInvitaciones.value;
	if (texto.length != 0) {
		invitaciones = texto.split("#");
		for (var i = 0; i < invitaciones.length; i++) {
			document.forms['mandarInvitacionesBean'].elements[i].value = invitaciones[i];
		}

	}
}
function ColocarInvitacionesError() {
	var texto = document.forms['mandarInvitacionesBean'].textoInvitaciones.value;
	alert(texto);
	if (texto.length != 0) {
		invitaciones = texto.split("#");
		for (var i = 0; i < invitaciones.length; i++) {
			document.forms['mandarInvitacionesBean'].elements[i].value = invitaciones[i];
			var elemento;
			if (invitaciones[i].length == 0) {
				if (i % 2 == 0) {
					elemento = document.getElementById("nombre" + (i / 2));
				} else {
					elemento = document.getElementById("email" + ((i / 2) + 1));
				}
				elemento.className = "formulariotextbox_error";
			}
		}

	}
}
function VerOfertas() {
	document.forms['busquedaBean'].action = "/VerOfertas.do";
	document.forms['busquedaBean'].submit();
}

function VerAnunciantes() {
	document.forms['busquedaBean'].action = "/VerAnunciantes.do";
	document.forms['busquedaBean'].submit();
}
function envioIntro(oEvent) {
	if ((oEvent.keyCode && oEvent.keyCode == 13)
			|| (oEvent.which && oEvent.which == 13)) {
		document.forms['logearBean'].submit();
	}
}
function envioIntro2(oEvent) {
	if ((oEvent.keyCode && oEvent.keyCode == 13)
			|| (oEvent.which && oEvent.which == 13)) {
		buscarDetalle('1');
	}
}
function envioIntro3(oEvent) {
	if ((oEvent.keyCode && oEvent.keyCode == 13)
			|| (oEvent.which && oEvent.which == 13)) {
		buscarDetalle('2');
	}
}
function colocarDatosInvitacion(invitacion, idUsuario, idOferta){	
	var tituloOferta = document.getElementById("ofertaTitulo"+invitacion);
	var descripcionOferta = document.getElementById("ofertaDescripcion"+invitacion);
	var tituloInvitacion = document.getElementById("tituloInvitacion");
	var descripcionInvitacion = document.getElementById("descripcionInvitacion");
	tituloInvitacion.innerHTML = tituloOferta.innerHTML;
	var descripcion = descripcionOferta.innerHTML;
	if(descripcion.length >200){
		descripcionInvitacion.innerHTML = descripcionOferta.innerHTML.substring(0,200)+"...";
	}else{
		descripcionInvitacion.innerHTML = descripcionOferta.innerHTML;
	}
	document.forms['invitarAmigosBean'].tituloInvitacion.value = tituloInvitacion.innerHTML;
	document.forms['invitarAmigosBean'].descripcionInvitacion.value = descripcionInvitacion.innerHTML;	
	document.forms['invitarAmigosBean'].indice.value = invitacion;
	document.forms['invitarAmigosBean'].idUsuario.value = idUsuario;
	document.forms['invitarAmigosBean'].idOferta.value = idOferta;
}

function colocarDatosInvitacionAnt(invitacion){	
	var tituloOferta = document.getElementById("ofertaTitulo"+invitacion);
	var descripcionOferta = document.getElementById("ofertaDescripcion"+invitacion);
	var tituloInvitacion = document.getElementById("tituloInvitacion");
	var descripcionInvitacion = document.getElementById("descripcionInvitacion");
	tituloInvitacion.innerHTML = tituloOferta.innerHTML;
	var descripcion = descripcionOferta.innerHTML;
	if(descripcion.length >200){
		descripcionInvitacion.innerHTML = descripcionOferta.innerHTML.substring(0,200)+"...";
	}else{
		descripcionInvitacion.innerHTML = descripcionOferta.innerHTML;
	}
	document.forms['invitarAmigosBean'].tituloInvitacion.value = tituloInvitacion.innerHTML;
	document.forms['invitarAmigosBean'].descripcionInvitacion.value = descripcionInvitacion.innerHTML;
	document.forms['invitarAmigosBean'].indice.value = invitacion;
}
function colocarDatosInvitacionAnunciante(idAnunciante){
	var nombreEmpresa = document.getElementById("nombreEmpresaAnunciante");
	var descripcionAnunciante = document.getElementById("descripcionAnunciante");
	var tituloInvitacion = document.getElementById("tituloInvitacion");
	var descripcionInvitacion = document.getElementById("descripcionInvitacion");
	tituloInvitacion.innerHTML = nombreEmpresa.innerHTML;
	descripcionInvitacion.innerHTML = descripcionAnunciante.innerHTML;
	var descripcion = descripcionAnunciante.innerHTML;
	if(descripcion.length >200){
		descripcionInvitacion.innerHTML = descripcionAnunciante.innerHTML.substring(0,200)+"...";
	}else{
		descripcionInvitacion.innerHTML = descripcionAnunciante.innerHTML;
	}
	document.forms['invitarAmigosBean'].tituloInvitacion.value = tituloInvitacion.innerHTML;
	document.forms['invitarAmigosBean'].descripcionInvitacion.value = descripcionInvitacion.innerHTML;
	document.forms['invitarAmigosBean'].indice.value = "0";
	document.forms['invitarAmigosBean'].idUsuario.value = idAnunciante;
	document.forms['invitarAmigosBean'].idOferta.value = 0;
	
}

function colocarDatosInvitacionAnuncianteAnt(){	
	var nombreEmpresa = document.getElementById("nombreEmpresaAnunciante");
	var descripcionAnunciante = document.getElementById("descripcionAnunciante");
	var tituloInvitacion = document.getElementById("tituloInvitacion");
	var descripcionInvitacion = document.getElementById("descripcionInvitacion");
	tituloInvitacion.innerHTML = nombreEmpresa.innerHTML;
	descripcionInvitacion.innerHTML = descripcionAnunciante.innerHTML;
	var descripcion = descripcionAnunciante.innerHTML;
	if(descripcion.length >200){
		descripcionInvitacion.innerHTML = descripcionAnunciante.innerHTML.substring(0,200)+"...";
	}else{
		descripcionInvitacion.innerHTML = descripcionAnunciante.innerHTML;
	}
	document.forms['invitarAmigosBean'].tituloInvitacion.value = tituloInvitacion.innerHTML;
	document.forms['invitarAmigosBean'].descripcionInvitacion.value = descripcionInvitacion.innerHTML;
	document.forms['invitarAmigosBean'].indice.value = "0";
}
function colocarDatosOportunista(){	
	var tituloInvitacion = document.getElementById("tituloInvitacion");
	var descripcionInvitacion = document.getElementById("descripcionInvitacion");
	tituloInvitacion.innerHTML = "oportunista.com";
	descripcionInvitacion.innerHTML = "La nueva plataforma para conseguir todas las ofertas " +
			"especiales en tu zona o localidad - todo en abierto, sin registro ni pagos.";
	var imagenOferta = "<div align= 'left' style='float:left;'>"
         + "<br/><a href='http://www.oportunista.com/"
		 + "?utm_source=Recomendacion_del_sitio" 
		 + "&amp;utm_medium=Email" 
		 + "&amp;utm_term=Oportunista"
		 + "&amp;utm_content=Imagen_de_oportunista"
		 + "&amp;utm_campaign=Recomienda_oportunista"
         + "'>"
         + "<img src='http://www.oportunista.com/imagenes/header/oportunista_smiley.gif' width='80px' height='80px' border='0' /></a></div>";
		
	var descripcionConFoto  = imagenOferta
	                        + "<div>"
                            + "<table border='0' cellpadding='0' cellspacing='0'>" ;
                            + "<tr><td>&nbsp;&nbsp;&nbsp;</td><td><span class='asterisco'>"
		                    + "oportunista.com </span></td></tr>"
                            + "</table>"
                            + "<br/>";
                                                        
        descripcionConFoto+= "<table border='0' cellpadding='0' cellspacing='0' width='50%'>"
              		       + "<tr><td>&nbsp;&nbsp;&nbsp;</td><td>"   
              		       + "Oportunista es el sitio donde podrás ahorrar en restaurantes, spas, hoteles, actividades, compras etc., "
	                       + "gracias a los <b>cupones descuento</b> y ofertas que encontrarás en esta web. Es el primer sitio web de <b>cupones descuento</b> " 
	                       + "donde los propios anunciantes ponen sus ofertas y tú las puedes canjear <b>SIN intermediarios</b> y <b>SIN registros</b>. "
	                       + "Entérate de las mejores ofertas y <a href='http://www.oportunista.com/"
	              		   + "?utm_source=Recomendacion_del_sitio" 
	            		   + "&amp;utm_medium=Email" 
	            		   + "&amp;utm_term=Oportunista"
	            		   + "&amp;utm_content=Link_de_oportunista"
	            		   + "&amp;utm_campaign=Recomienda_oportunista"
	                       + "'><b>¡Sé oportunista!</b></a> "
              		       + "</td></tr>"	              		
              		       + "<tr><td>&nbsp;&nbsp;&nbsp;</td><td>&nbsp;</td></tr>"
              			   + "<tr><td>&nbsp;&nbsp;&nbsp;</td><td>&nbsp;</td></tr>"						
              			   + "<tr><td>&nbsp;&nbsp;&nbsp;</td><td>&nbsp;</td></tr>"
              			   + "</table></div>";
        
        descripcionConFoto+= "<div><table border='0' cellpadding='0' cellspacing='0'><tr><td>--------------------------------------------------------------------------------------------------------</td></tr></table></div>"
		                   + "<br/>";
    		               + "<div id='sitemap-header-right' style='color: #5E4530;'>" 
		                   + "Oportunista es el sitio donde podrás ahorrar en restaurantes, spas, hoteles, actividades, compras etc., "
		                   + "gracias a los <b>cupones descuento</b> y ofertas que encontrarás en esta web. Es el primer sitio web de <b>cupones descuento</b> " 
		                   + "donde los propios anunciantes ponen sus ofertas y tú las puedes canjear <b>SIN intermediarios</b> y <b>SIN registros</b>. "
		                   + "Entérate de las mejores ofertas y <b>¡Sé oportunista!</b> ";
	                       + "</div>";
	                       
	document.forms['invitarAmigosBean'].tituloInvitacion.value = tituloInvitacion.innerHTML;
	document.forms['invitarAmigosBean'].descripcionInvitacion.value = descripcionInvitacion.innerHTML;
	document.forms['invitarAmigosBean'].indice.value = "0";
	document.forms['invitarAmigosBean'].descripcionConFoto.value = descripcionConFoto; 
}

function colocarDatosVaguada(){	
	var tituloInvitacion = document.getElementById("tituloInvitacion");
	var descripcionInvitacion = document.getElementById("descripcionInvitacion");
	tituloInvitacion.innerHTML = "Cupones de La Vaguada en Oportunista.com";
	descripcionInvitacion.innerHTML = "Todos los cupones de La Vaguada a tu disposición online - totalmente gratis. "
                                    + "Baja los cupones de tiendas y restaurantes, imprímelos y ahorra en tu "
                                    + "próxima visita a La Vaguada. ";
                                    
	var imagenOferta = "<div align= 'left' style='float:left;'>"
         + "<br/><a href='http://www.oportunista.com/"
		 + "?utm_source=Recomendacion_del_sitio" 
		 + "&amp;utm_medium=Email" 
		 + "&amp;utm_term=Oportunista"
		 + "&amp;utm_content=Imagen_de_oportunista"
		 + "&amp;utm_campaign=Recomienda_oportunista"
         + "'>"
         + "<img src='http://www.oportunista.com/imagenes/header/oportunista_smiley.gif' width='80px' height='80px' border='0' /></a></div>";
		
	var descripcionConFoto  = imagenOferta
	                        + "<div>"
                            + "<table border='0' cellpadding='0' cellspacing='0'>" ;
                            + "<tr><td>&nbsp;&nbsp;&nbsp;</td><td><span class='asterisco'>"
		                    + "oportunista.com </span></td></tr>"
                            + "</table>"
                            + "<br/>";
                                                        
        descripcionConFoto+= "<table border='0' cellpadding='0' cellspacing='0' width='50%'>"
              		       + "<tr><td>&nbsp;&nbsp;&nbsp;</td><td>"                 		       
              		       + "Todos los cupones de La Vaguada a tu disposición online - totalmente gratis."
                           + "Baja los cupones de tiendas y restaurantes, imprímelos y ahorra en tu "
                           + "próxima visita a La Vaguada. "
              		       + "</td></tr>"	              		
              		       + "<tr><td>&nbsp;&nbsp;&nbsp;</td><td>&nbsp;</td></tr>"
              			   + "<tr><td>&nbsp;&nbsp;&nbsp;</td><td>&nbsp;</td></tr>"						
              			   + "<tr><td>&nbsp;&nbsp;&nbsp;</td><td>&nbsp;</td></tr>"
              			   + "</table></div>";
        
        descripcionConFoto+= "<div><table border='0' cellpadding='0' cellspacing='0'><tr><td>--------------------------------------------------------------------------------------------------------</td></tr></table></div>"
		                   + "<br/>";
    		               + "<div id='sitemap-header-right' style='color: #5E4530;'>" 
    		               + "Todos los cupones de La Vaguada a tu disposición online - totalmente gratis."
                           + "Baja los cupones de tiendas y restaurantes, imprímelos y ahorra en tu "
                           + "próxima visita a La Vaguada. "
	                       + "</div>";
	                       
	document.forms['invitarAmigosBean'].tituloInvitacion.value = tituloInvitacion.innerHTML;
	document.forms['invitarAmigosBean'].descripcionInvitacion.value = descripcionInvitacion.innerHTML;
	document.forms['invitarAmigosBean'].indice.value = "0";
	document.forms['invitarAmigosBean'].descripcionConFoto.value = descripcionConFoto; 
}

function irAncla(nombre)
{	top.location.hash = nombre
}


function callAviso()
{
	document.location.href="/AvisoBusquedaIni.do?email=" + document.getElementById("email_banner").value;
	document.getElementById("email_banner").value = "escribe tu email";
}

function callMapa(event, server)
{
	if (event.keyCode == 13){
	   verMapaAux('mapa');
	   verPausaOfertas('activar');
	   pintarOfertasEnDireccion(server);
	}
}

function verMapaAux(vista) {	
	if(vista == "todasOfertas"){		
		document.getElementById('ver_' + vista ).style.display = "block";
		document.getElementById('ver_mapa').style.display = "none";		
	}else{
		document.getElementById('ver_' + vista).style.display = "block";
		document.getElementById('ver_todasOfertas').style.display = "none";		
	}
}

function verPausaOfertas(vista) {   
   if(vista == "desactivar"){			  
	  document.getElementById('ver_cargaOfertas').style.display = "none";		
	  document.getElementById('ver_cargaOfertas_mensaje').style.display = "block";
   }else{
	   document.getElementById('ver_cargaOfertas').style.display  = "block";
	   document.getElementById('ver_cargaOfertas_mensaje').style.display = "none";
   }
}


function verPausaOfertasZona(vista) { 	
   if(vista == "desactivar"){			  
      document.getElementById('ver_cargaOfertas').style.display = "none";				  
   }else{
      document.getElementById('ver_cargaOfertas').style.display  = "block";		   
   }
}

function callHelpTipEmailAviso()
{
	if (document.getElementById("helptip_email_aviso").value == 'pon tu email') {
		document.getElementById("helptip_email_aviso").value = '';
	}
	
	document.location.href="/AvisoBusquedaIni.do?email=" + document.getElementById("helptip_email_aviso").value;
	document.getElementById("helptip_email_aviso").value = "pon tu email";
}


function borrarContenidoEmail(from) {
	var texto;
	
	if (from == "bannerEmail") {
	  texto = document.getElementById("email_banner").value;
	  if(texto == "escribe tu email"){
		document.getElementById("email_banner").value = "";
	  }
	} else if (from == "helptipEmail") {
	  texto = document.getElementById("helptip_email_aviso").value;
	  if(texto == "pon tu email"){
		document.getElementById("helptip_email_aviso").value = "";
	  }
	}
}

function borrarContenidoEmailCentroComercialCatalan(from) {
	var texto;
	
	if (from == "bannerEmail") {
	  texto = document.getElementById("email_banner").value;
	  if(texto == "posa el teu email"){
		document.getElementById("email_banner").value = "";
	  }
	} else if (from == "helptipEmail") {
	  texto = document.getElementById("helptip_email_aviso").value;
	  if(texto == "posa el teu email"){
		document.getElementById("helptip_email_aviso").value = "";
	  }
	}
}

function borrarContenidoCajaTexto(from) {
	var texto;
	
	if (from == "direccionMaps") {
	  texto = document.getElementById("maps_banner").value;

	  if(texto == "ej: Paseo de Born 4, Mallorca"){
		document.getElementById("maps_banner").value = "";
	  }
	}if (from == "movilEnvio") {
	   texto = document.getElementById("movilEnvio").value;

       if(texto == "ej:555665566"){
	      document.getElementById("movilEnvio").value = "";
	   }
	}if (from == "emailEnvioBulk") {
	   texto = document.getElementById("emailEnvioBulk").value;

	   if(texto == "ej:tu_nombre@oportunista.com"){
	      document.getElementById("emailEnvioBulk").value = "";
	   }
	}if (from == "panelMapaDireccion") {
       texto = document.getElementById("maps_banner").value;

	   if(texto == "escribe una dirección ..."){
	      document.getElementById("maps_banner").value = "";
	   }
	}if (from == "panelMapaCadena") {
	   texto = document.getElementById("maps_buscar").value;

	   if(texto == "buscar palabra clave en ofertas ..."){
		  document.getElementById("maps_buscar").value = "";
	   }
	}	
}

function limpiarTxtBuscar(){
	  document.getElementById("txtbuscar").value = "";
	
} 

function determineKeyPressed(event, from) {
	if (event.keyCode == 13)
	{
		if (from == "bannerEmail") {
			callAviso();
		} else if (from == "direccionMaps") {
			callMapa();
		} else if (from == "helptipEmail") {
			callHelpTipEmailAviso();
		}
		
	}
}


function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function cambiarTildes2(str) {
	
	// Note: When modifying this function, make sure to modify the corresponding function in Utils.java in both Oportunista and envios projects
	
	str = str.replace(/&aacute;/g,"a");
	str = str.replace(/&eacute;/g,"e");
	str = str.replace(/&iacute;/g,"i");
	str = str.replace(/&oacute;/g,"o");
	str = str.replace(/&uacute;/g,"u");
	str = str.replace(/&Aacute;/g,"A");
	str = str.replace(/&Eacute;/g,"E");
	str = str.replace(/&Iacute;/g,"I");
	str = str.replace(/&Oacute;/g,"O");
	str = str.replace(/&Uacute;/g,"U");
	
	str = str.replace(/&agrave;/g,"a");
	str = str.replace(/&egrave;/g,"e");
	str = str.replace(/&igrave;/g,"i");
	str = str.replace(/&ograve;/g,"o");
	str = str.replace(/&ugrave;/g,"u");
	str = str.replace(/&Agrave;/g,"A");
	str = str.replace(/&Egrave;/g,"E");
	str = str.replace(/&Igrave;/g,"I");
	str = str.replace(/&Ograve;/g,"O");
	str = str.replace(/&Ugrave;/g,"U");
	
	str = str.replace(/&auml;/g,"a");
	str = str.replace(/&euml;/g,"e");
	str = str.replace(/&iuml;/g,"i");
	str = str.replace(/&ouml;/g,"o");
	str = str.replace(/&uuml;/g,"u");
	str = str.replace(/&Auml;/g,"A");
	str = str.replace(/&Euml;/g,"E");
	str = str.replace(/&Iuml;/g,"I");
	str = str.replace(/&Ouml;/g,"O");
	str = str.replace(/&Uuml;/g,"U");
	
	str = str.replace(/&ccedil;/g,"c");
	str = str.replace(/&Ccedil;/g,"C");
	
	str = str.replace(/&ntilde;/g,"n");
	str = str.replace(/&Ntilde;/g,"N");
	
	str = str.replace(/&#039;/g,"\'");
	
	return str;
}

function cambiarTildes3(str) {

	// Note: When modifying this function, make sure to modify the corresponding function in Utils.java in both Oportunista and envios projects

	str = str.replace(/á/g,"a");
	str = str.replace(/é/g,"e");
	str = str.replace(/í/g,"i");
	str = str.replace(/ó/g,"o");
	str = str.replace(/ú/g,"u");
	str = str.replace(/Á/g,"A");
	str = str.replace(/É/g,"E");
	str = str.replace(/Í/g,"I");
	str = str.replace(/Ó/g,"O");
	str = str.replace(/Ú/g,"U");
	
	str = str.replace(/à/g,"a");
	str = str.replace(/è/g,"e");
	str = str.replace(/ì/g,"i");
	str = str.replace(/ò/g,"o");
	str = str.replace(/ù/g,"u");
	str = str.replace(/À/g,"A");
	str = str.replace(/È/g,"E");
	str = str.replace(/Ì/g,"I");
	str = str.replace(/Ò/g,"O");
	str = str.replace(/Ù/g,"U");
	
	str = str.replace(/ä/g,"a");
	str = str.replace(/ë/g,"e");
	str = str.replace(/ï/g,"i");
	str = str.replace(/ö/g,"o");
	str = str.replace(/ü/g,"u");
	str = str.replace(/Ä/g,"A");
	str = str.replace(/Ë/g,"E");
	str = str.replace(/Ï/g,"I");
	str = str.replace(/Ö/g,"O");
	str = str.replace(/Ü/g,"U");
	
	str = str.replace(/ç/g,"c");
	str = str.replace(/Ç/g,"C");
	
	str = str.replace(/ñ/g,"n");
	str = str.replace(/Ñ/g,"N");
	
	return str;
}



function formatForSeoUrl(str)
{
	// Note: When modifying this function, make sure to modify the corresponding function in Utils.java in both Oportunista and envios projects
	
    // check if str is null to prevent exception
	if (str == null) {
		return str;
	}
	
	// convert all to lower-case characters
	str = str.toLowerCase();
	
	// trim the string
	str = trim(str);
	
	// remove all accents and tildes
	str = cambiarTildes2(str);
	str = cambiarTildes3(str);
	
	// change symbol with spaces before and after to just the symbol
	str = str.split(" - ").join('-');
	str = str.split("- ").join('-');
	str = str.split(" & ").join('-');
	str = str.split(" / ").join('-');
	str = str.split("\' ").join('-');
	str = str.split(". ").join('.');
	
	// change spaces,.,' to dash
	str = str.split('.').join('-');
	str = str.split('/').join('-');
	str = str.split('\'').join('-');
	str = str.split('_').join('-');
	str = str.split(' ').join('-');
	
	// we just hardcode some rules because we cannot make the regular expression rule work in javascript
	str = str.split("(").join('');
	str = str.split(")").join('');
	
	return str;
}

function composeBuscarUrlOfertas() {
	var urlString = "/ofertas-descuentos";
	
	if ( (document.forms['busquedaBean'].subSector.value != null) && (document.forms['busquedaBean'].subSector.value.length > 0) ) {
		urlString = urlString + "/ss_" + formatForSeoUrl(document.forms['busquedaBean'].subSector.value);
	} else if ( (document.forms['busquedaBean'].sector.value != null) && (document.forms['busquedaBean'].sector.value.length > 0) ) {
		urlString = urlString + "/s_" + formatForSeoUrl(document.forms['busquedaBean'].sector.value);
	}

	if ( (document.forms['busquedaBean'].distrito.value != null) && (document.forms['busquedaBean'].distrito.value.length > 0) && (document.forms['busquedaBean'].distrito.value != "--") ) {
		urlString = urlString + "/d_" + formatForSeoUrl(document.forms['busquedaBean'].zona.value) + '_' + formatForSeoUrl(document.forms['busquedaBean'].distrito.value);
	} else if ( (document.forms['busquedaBean'].zona.value != null) && (document.forms['busquedaBean'].zona.value.length > 0) ) {
		urlString = urlString + "/z_" + formatForSeoUrl(document.forms['busquedaBean'].zona.value);
	}

	// NOTE: The clean url is hardcoded here as there's no way we can rewrite the url because we have to use
	// <c:url> passing the choices the user selected in the buscadores (e.g. comer y beber, restaurante, madrid) 
	// which are all determined via client side and so there's no way we can pass a client side parameter
	// to a server side <c:url> unless the buscadores design is changed
	document.forms['busquedaBean'].action = urlString;
	document.forms['busquedaBean'].submit();
}

function composeBuscarUrlOfertasMapa(zona) {	
	var urlString = "/ofertas-descuentos";
	urlString = urlString + "/z_" + formatForSeoUrl(zona);
	

	// NOTE: The clean url is hardcoded here as there's no way we can rewrite the url because we have to use
	// <c:url> passing the choices the user selected in the buscadores (e.g. comer y beber, restaurante, madrid) 
	// which are all determined via client side and so there's no way we can pass a client side parameter
	// to a server side <c:url> unless the buscadores design is changed
	//document.forms['busquedaBean'].pintaMapa.value = '1';	
	//document.forms['busquedaBean'].paginaReset.value='ok';
	document.forms['busquedaBean'].action = urlString;
	document.forms['busquedaBean'].submit();
}

function composeBuscarUrlAnunciantes() {
	var urlString = "";
	
	if ( (document.forms['busquedaBean'].subSector.value != null) && (document.forms['busquedaBean'].subSector.value.length > 0) ) {
		urlString = urlString + "/ss_" + formatForSeoUrl(document.forms['busquedaBean'].subSector.value);
	} else if ( (document.forms['busquedaBean'].sector.value != null) && (document.forms['busquedaBean'].sector.value.length > 0) ) {
		urlString = urlString + "/s_" + formatForSeoUrl(document.forms['busquedaBean'].sector.value);
	}

	if ( (document.forms['busquedaBean'].distrito.value != null) && (document.forms['busquedaBean'].distrito.value.length > 0) && (document.forms['busquedaBean'].distrito.value != "--") ) {
		urlString = urlString + "/d_" + formatForSeoUrl(document.forms['busquedaBean'].zona.value) + '_' + formatForSeoUrl(document.forms['busquedaBean'].distrito.value);
	} else if ( (document.forms['busquedaBean'].zona.value != null) && (document.forms['busquedaBean'].zona.value.length > 0) ) {
		urlString = urlString + "/z_" + formatForSeoUrl(document.forms['busquedaBean'].zona.value);
	}
	
	if (urlString == "") {
		urlString = "/VerAnunciantes.do";
	}

	// NOTE: The clean url is hardcoded here as there's no way we can rewrite the url because we have to use
	// <c:url> passing the choices the user selected in the buscadores (e.g. comer y beber, restaurante, madrid) 
	// which are all determined via client side and so there's no way we can pass a client side parameter
	// to a server side <c:url> unless the buscadores design is changed
	document.forms['busquedaBean'].action = urlString;
	document.forms['busquedaBean'].submit();
}

function buildVerTodosUrl(zonaParam, distritoParam) {
	document.forms['busquedaBean'].action="/VerAnunciantes.do?distritoparam=" + formatForSeoUrl(zonaParam)+ '_' + formatForSeoUrl(distritoParam) + "&searchtipo=0";
	document.forms['busquedaBean'].submit();
}

function buscarDetalle(tipoBusqueda) {
	if (tipoBusqueda == 1) {
	  document.forms['busquedaBean'].action='/VerOfertas.do?paginaReset=ok&btnBusqueda=ok';
	  document.forms['busquedaBean'].submit();
	  
	} else if (tipoBusqueda == 2) {
	  document.forms['busquedaBean'].action='/VerAnunciantes.do?btnBusqueda=ok';
	  document.forms['busquedaBean'].submit();
	  
	}		
}

function mostrar_telefono(telefono, tipoPanel){	
	document.forms['sumarLinksAnuncianteBean'].panel.value = tipoPanel;
	document.forms['sumarLinksAnuncianteBean'].telefonoAnunciante.value = telefono;
	document.forms['sumarLinksAnuncianteBean'].submit();	
}

function cambiar_panel(tipoPanel){	
	document.forms['sumarLinksAnuncianteBean'].panel.value = tipoPanel;	
}

function sumar_links(){		
	document.forms['sumarLinksAnuncianteBean'].submit();	
}

function colocarDatosCuponDesdeOferta(idUsuario, idOferta){
	document.forms['enviarCuponBean'].idUsuarioAvisos.value = idUsuario;
	document.forms['enviarCuponBean'].idOfertaAvisos.value  = idOferta;
}

function colocarDatosCuponDesdeListadoVaguada(idUsuario, idOferta){	
	document.forms['busquedaCentroComercialVaguadaBean'].idOfertaAvisos.value  = idOferta;
	document.forms['busquedaCentroComercialVaguadaBean'].idUsuarioAvisos.value = idUsuario;
}

function colocarDatosCuponDesdeListado(idUsuario, idOferta){	
	document.forms['busquedaCentroComercialBean'].idOfertaAvisos.value  = idOferta;
	document.forms['busquedaCentroComercialBean'].idUsuarioAvisos.value = idUsuario;
}

var estadoBoton1 = false;

function pulsar(){
	
		document.boton1.src='/imagenes/lilla/botones/1_lilla_moda_activo.gif';
		estadoBoton1 =  true; 
}

function outVaguada(botonActual, botonPresionado){
	
	if (botonActual != botonPresionado){
	   if(botonActual == 'boton1')	
	      document.boton1.src='/imagenes/vaguada/1_va_tiendas_inactivo.gif';
	   if(botonActual == 'boton2')	
		  document.boton2.src='/imagenes/vaguada/2_va_rest_inactivo.gif';
	   if(botonActual == 'boton3')	
	      document.boton3.src='/imagenes/vaguada/3_va_todos_inactivo.gif';
	}
}

function overVaguada(botonActual, botonPresionado){

	if (botonActual != botonPresionado){
	   if(botonActual == 'boton1')	
	      document.boton1.src='/imagenes/vaguada/1_va_tiendas_rollover.gif'
	   if(botonActual == 'boton2')	
	      document.boton2.src='/imagenes/vaguada/2_va_rest_rollover.gif'
	   if(botonActual == 'boton3')	
	      document.boton3.src='/imagenes/vaguada/3_va_todos_rollover.gif';
	}
}

function colocarDatosComercialRestringidoVaguada(sector, subsector, cadena, boton){
	document.forms['busquedaCentroComercialVaguadaBean'].idAnunciante.value = 6683;
	document.forms['busquedaCentroComercialVaguadaBean'].sector.value = sector;
	document.forms['busquedaCentroComercialVaguadaBean'].subSector.value = subsector;
	document.forms['busquedaCentroComercialVaguadaBean'].detalleO.value = cadena;
	document.forms['busquedaCentroComercialVaguadaBean'].botonPulsado.value = boton;
	document.forms['busquedaCentroComercialVaguadaBean'].submit();		
}

function colocarDatosComercialRestringido2Vaguada(sector, subsector){
	document.forms['busquedaCentroComercialVaguadaBean'].idAnunciante.value = 6683;
	document.forms['busquedaCentroComercialVaguadaBean'].sector.value = sector;
	document.forms['busquedaCentroComercialVaguadaBean'].subSector.value = subsector;
	document.forms['busquedaCentroComercialVaguadaBean'].submit();	
}

function out(botonActual, botonPresionado){
	
	if (botonActual != botonPresionado){
	   if(botonActual == 'boton1')	
	      document.boton1.src='/imagenes/lilla/botones/1_lilla_moda_inactivo.gif';
	   if(botonActual == 'boton2')	
		  document.boton2.src='/imagenes/lilla/botones/2_lilla_llar_inactivo.gif';
	   if(botonActual == 'boton3')	
	      document.boton3.src='/imagenes/lilla/botones/3_lilla_perfume_inactivo.gif';
	   if(botonActual == 'boton4')	
		  document.boton4.src='/imagenes/lilla/botones/4_lilla_imatge_inactivo.gif';
	   if(botonActual == 'boton5')	
		  document.boton5.src='/imagenes/lilla/botones/5_lilla_alimento_inactivo.gif';
	   if(botonActual == 'boton6')	
		  document.boton6.src='/imagenes/lilla/botones/6_lilla_restaura_inactivo.gif';
	   if(botonActual == 'boton7')	
		  document.boton7.src='/imagenes/lilla/botones/7_lilla_serveis_inactivo.gif';
	   if(botonActual == 'boton9')	
		  document.boton9.src='/imagenes/lilla/botones/9_lilla_totes_inactivo.gif';
	}
}

function over(botonActual, botonPresionado){

	if (botonActual != botonPresionado){
	   if(botonActual == 'boton1')	
	      document.boton1.src='/imagenes/lilla/botones/1_lilla_moda_rollover.gif'
	   if(botonActual == 'boton2')	
	      document.boton2.src='/imagenes/lilla/botones/2_lilla_llar_rollover.gif'
	   if(botonActual == 'boton3')	
	      document.boton3.src='/imagenes/lilla/botones/3_lilla_perfume_rollover.gif';
	   if(botonActual == 'boton4')	
	   	  document.boton4.src='/imagenes/lilla/botones/4_lilla_imatge_rollover.gif';
	   if(botonActual == 'boton5')	
	   	  document.boton5.src='/imagenes/lilla/botones/5_lilla_alimento_rollover.gif';
	   if(botonActual == 'boton6')	
	   	  document.boton6.src='/imagenes/lilla/botones/6_lilla_restaura_rollover.gif';
	   if(botonActual == 'boton7')	
	   	  document.boton7.src='/imagenes/lilla/botones/7_lilla_serveis_rollover.gif';
	   if(botonActual == 'boton9')	
	   	  document.boton9.src='/imagenes/lilla/botones/9_lilla_totes_rollover.gif';
	}
}
	

function colocarDatosComercialRestringido(sector, subsector, cadena, boton){
	document.forms['busquedaCentroComercialBean'].idAnunciante.value = 6607;
	document.forms['busquedaCentroComercialBean'].sector.value = sector;
	document.forms['busquedaCentroComercialBean'].subSector.value = subsector;
	document.forms['busquedaCentroComercialBean'].detalleO.value = cadena;
	document.forms['busquedaCentroComercialBean'].botonPulsado.value = boton;
	document.forms['busquedaCentroComercialBean'].submit();		
}

function colocarDatosComercialRestringido2(sector, subsector){
	document.forms['busquedaCentroComercialBean'].idAnunciante.value = 6607;
	document.forms['busquedaCentroComercialBean'].sector.value = sector;
	document.forms['busquedaCentroComercialBean'].subSector.value = subsector;
	document.forms['busquedaCentroComercialBean'].submit();	
}

function colocarDatosEnviarCupon(idOferta){	
	
	var email='emailEnvio_'+idOferta;
	
	var valorEmail=document.getElementById(email).value;
	
	var codigoConfirmacion=document.getElementById('codigoConfirmacion_'+idOferta).value;
	
	document.forms['enviarCuponBean'].emailEnvio.value=valorEmail;
	
	document.forms['enviarCuponBean'].codigoConfirmacion.value=codigoConfirmacion;
	
	document.forms['enviarCuponBean'].esRecibirAvisos.value = document.getElementById("enviarAvisos").checked;
	
	var recibirCuponImg = document.getElementById("recibirCuponImg_"+idOferta);
	recibirCuponImg.disabled = true;
	
	document.forms['enviarCuponBean'].submit();
}
function colocarDatosEnviarCuponCentroComercialVaguada(){	
	
	var codigoConfirmacion=document.getElementById('codigoConfirmacionTxt').value;
	
	var valorEmail=document.getElementById('emailEnvioTxt').value;
	
	document.forms['busquedaCentroComercialVaguadaBean'].codigoConfirmacion.value=codigoConfirmacion;
	document.forms['busquedaCentroComercialVaguadaBean'].esRecibirAvisos.value = document.getElementById('enviarAvisos').checked;
	document.forms['busquedaCentroComercialVaguadaBean'].esPoliticas.value = document.getElementById('politicas').checked;	
	document.forms['busquedaCentroComercialVaguadaBean'].accion.value = 'enviarCupon';
	document.forms['busquedaCentroComercialVaguadaBean'].emailEnvio.value=valorEmail;	
	document.forms['busquedaCentroComercialVaguadaBean'].submit();
}


function colocarDatosEnviarCuponCentroComercial(){	
	
	var codigoConfirmacion=document.getElementById('codigoConfirmacionTxt').value;
	
	var valorEmail=document.getElementById('emailEnvioTxt').value;
	
	document.forms['busquedaCentroComercialBean'].codigoConfirmacion.value=codigoConfirmacion;
	document.forms['busquedaCentroComercialBean'].esRecibirAvisos.value = document.getElementById('enviarAvisos').checked;
	document.forms['busquedaCentroComercialBean'].esPoliticas.value = document.getElementById('politicas').checked;	
	document.forms['busquedaCentroComercialBean'].accion.value = 'enviarCupon';
	document.forms['busquedaCentroComercialBean'].emailEnvio.value=valorEmail;	
	document.forms['busquedaCentroComercialBean'].reset.value='no';
	document.forms['busquedaCentroComercialBean'].submit();
}

function colocarDatosEnviarCuponSeguro(idOferta){	
	
	var idDireccionSeleccionada=0;
	
	idDireccionSeleccionada=document.getElementById('idDireccionEnviado').value;
	
	var combo=document.getElementById("idDireccionDisponibleSeguro_"+idOferta);
	
	var arrValor=combo.options[combo.selectedIndex].value.split(":");
	
	document.forms['validarCuponSeguroBean'].idDireccionEnviado.value = arrValor[0];
		
	var email='emailEnvioSeguro_'+idOferta;
	
	var valorEmail=document.getElementById(email).value;
	
	document.forms['validarCuponSeguroBean'].emailEnvio.value=valorEmail;
	
	document.forms['validarCuponSeguroBean'].submit();
	
	var recibirCuponImg = document.getElementById("recibirCuponImgSeguro_"+idOferta);
	
	recibirCuponImg.disabled = true;
}

function asignarEmailError(nombreEmail,nombreBean,idOferta){
	document.getElementById(nombreEmail+idOferta).value= document.forms[nombreBean].emailEnvio.value;
}
function asignarDireccionEnviadaSeguro(idOferta){
	
	var combo=document.getElementById("idDireccionDisponibleSeguro_"+idOferta);
	
	var idEnviado=document.forms['validarCuponSeguroBean'].idDireccionEnviado.value;
	
	for(i=0; i< combo.options.length; i++){
		
		var arrValor=combo.options[i].value.split(":");
		
		if(arrValor[0]==idEnviado){
			
			combo.selectedIndex=i;
			
		}
		
	} 
		 
	
}
function asignarDireccionEnviada(idOferta){
	
	var combo=document.getElementById("idDireccionDisponible_"+idOferta);
	
	var idEnviado=document.forms['enviarCuponBean'].idDireccionEnviado.value;
	
	for(i=0; i< combo.options.length; i++){
		
		var arrValor=combo.options[i].value.split(":");
		
		if(arrValor[0]==idEnviado){
			
			combo.selectedIndex=i;
			
		}
		
	} 
		 
	
}
function colocarDatosClienteSeguro(){   
   document.forms['registroClienteBean'].envios.value = document.getElementById("enviarAvisosClientesSeguros").checked;	
   document.forms['registroClienteBean'].submit();
}

/*
function colocarDatosEnviarCupon(idUsuario, idOferta){	
	document.forms['enviarCuponBean'].idUsuarioAvisos.value = idUsuario;
	document.forms['enviarCuponBean'].idOfertaAvisos.value  = idOferta;
	document.forms['enviarCuponBean'].esRecibirAvisos.value = document.getElementById("enviarAvisos").checked;
	
	var recibirCuponImg = document.getElementById("recibirCuponImg");
	recibirCuponImg.disabled = true;
	
	document.forms['enviarCuponBean'].submit();
}

*/
function colocarDatosSmsDesdeOferta(idUsuario, idOferta){		
   document.forms['enviarSmsBean'].idUsuarioAvisos.value = idUsuario;
   document.forms['enviarSmsBean'].idOfertaAvisos.value  = idOferta;
}

function colocarDatosSmsBulkDesdeOferta(idUsuario, idOferta){		
   document.forms['enviarSmsBulkBean'].idUsuarioAvisos.value = idUsuario;
   document.forms['enviarSmsBulkBean'].idOfertaAvisos.value  = idOferta;
}


function colocarDatosEnviarSms(){
	/*
	document.forms['enviarSmsBean'].esRecibirAvisos.value = document.getElementById("enviarAvisoSms").checked;
	
	var meApuntoImg = document.getElementById("meApuntoImg");
	meApuntoImg.disabled = true;
	
	document.forms['enviarSmsBean'].submit();
	*/
}

function colocarDatosCuponSeguro(idUsuario, idOferta){
	document.forms['validarCuponSeguroBean'].idUsuarioAvisos.value = idUsuario;
	document.forms['validarCuponSeguroBean'].idOfertaAvisos.value  = idOferta;
}

function seleccionarChecks(identificador, valor, tipo){
	
	if (valor == 1 && tipo == 0){
		if (document.getElementById('ComeryBeber').checked){		   
		   document.getElementById('1-1').checked = true;
		   document.getElementById('1-2').checked = true;
		   document.getElementById('1-4').checked = true;
		   document.getElementById('1-5').checked = true;
		   document.getElementById('1-6').checked = true;
		   document.getElementById('1-7').checked = true;
		}else{
			document.getElementById('1-1').checked = false;
			document.getElementById('1-2').checked = false;
			document.getElementById('1-4').checked = false;
			document.getElementById('1-5').checked = false;
			document.getElementById('1-6').checked = false;
			document.getElementById('1-7').checked = false;
		}		
	}
	
	if (valor == 2 && tipo == 0){
		if (document.getElementById('SaludyBelleza').checked){		   
		   document.getElementById('2-8').checked = true;
		   document.getElementById('2-9').checked = true;
		   document.getElementById('2-10').checked = true;
		   document.getElementById('2-11').checked = true;
		   document.getElementById('2-12').checked = true;
		   document.getElementById('2-44').checked = true;
		}else{
		   document.getElementById('2-8').checked = false;
		   document.getElementById('2-9').checked = false;
		   document.getElementById('2-10').checked = false;
		   document.getElementById('2-11').checked = false;
		   document.getElementById('2-12').checked = false;
		   document.getElementById('2-44').checked = false;
		}		
	}
	
	if (valor == 3 && tipo == 0){
		if (document.getElementById('Tiendas').checked){		   
		   document.getElementById('3-13').checked = true;
		   document.getElementById('3-14').checked = true;
		   document.getElementById('3-15').checked = true;
		   document.getElementById('3-16').checked = true;
		   document.getElementById('3-17').checked = true;
		   document.getElementById('3-18').checked = true;
		   document.getElementById('3-19').checked = true;
		   document.getElementById('3-20').checked = true;
		   document.getElementById('3-42').checked = true;
		}else{
			document.getElementById('3-13').checked = false;
			document.getElementById('3-14').checked = false;
			document.getElementById('3-15').checked = false;
			document.getElementById('3-16').checked = false;
			document.getElementById('3-17').checked = false;
			document.getElementById('3-18').checked = false;
			document.getElementById('3-19').checked = false;
			document.getElementById('3-20').checked = false;
			document.getElementById('3-42').checked = false;
		}		
	}
	
	if (valor == 4 && tipo == 0){
		if (document.getElementById('Servicios').checked){		   
		   document.getElementById('4-21').checked = true;
		   document.getElementById('4-22').checked = true;
		   document.getElementById('4-23').checked = true;
		   document.getElementById('4-39').checked = true;
		   document.getElementById('4-24').checked = true;
		}else{
			document.getElementById('4-21').checked = false;
			document.getElementById('4-22').checked = false;
			document.getElementById('4-23').checked = false;
			document.getElementById('4-39').checked = false;
			document.getElementById('4-24').checked = false;
		}		
	}
	
	if (valor == 5 && tipo == 0){
		if (document.getElementById('OcioyDeporte').checked){		   
		   document.getElementById('5-25').checked = true;
		   document.getElementById('5-26').checked = true;
		   document.getElementById('5-27').checked = true;
		   document.getElementById('5-28').checked = true;
		   document.getElementById('5-29').checked = true;
		   document.getElementById('5-30').checked = true;		   
		}else{
		   document.getElementById('5-25').checked = false;
		   document.getElementById('5-26').checked = false;
		   document.getElementById('5-27').checked = false;
		   document.getElementById('5-28').checked = false;
		   document.getElementById('5-29').checked = false;
		   document.getElementById('5-30').checked = false;	
		}		
	}
	
	if (valor == 6 && tipo == 0){
		if (document.getElementById('ViajesyAlojamiento').checked){		   
		   document.getElementById('6-31').checked = true;
		   document.getElementById('6-32').checked = true;
		   document.getElementById('6-33').checked = true;
		   document.getElementById('6-34').checked = true;
		   document.getElementById('6-43').checked = true;
		}else{
		   document.getElementById('6-31').checked = false;
		   document.getElementById('6-32').checked = false;
		   document.getElementById('6-33').checked = false;
		   document.getElementById('6-34').checked = false;
		   document.getElementById('6-43').checked = false;
		}		
	}
	
	if (valor == 7 && tipo == 0){
		if (document.getElementById('Supermercados').checked){		   
		   document.getElementById('7-40').checked = true;		   
		}else{
		   document.getElementById('7-40').checked = false;
		}		
	}
	
	marcarSectores();
    		   
	var opciones = "";

	if (document.getElementById('1-1').checked){
		opciones = opciones + document.getElementById('ComeryBeber').value + '-' + document.getElementById('1-1').value + ',';
	}
	if (document.getElementById('1-2').checked){
		opciones = opciones + document.getElementById('ComeryBeber').value + '-' + document.getElementById('1-2').value + ',';
	}
	if (document.getElementById('1-4').checked){
		opciones = opciones + document.getElementById('ComeryBeber').value + '-' + document.getElementById('1-4').value + ',';
	}
	if (document.getElementById('1-5').checked){
		opciones = opciones + document.getElementById('ComeryBeber').value + '-' + document.getElementById('1-5').value + ',';
	}
	if (document.getElementById('1-6').checked){
		opciones = opciones + document.getElementById('ComeryBeber').value + '-' + document.getElementById('1-6').value + ',';
	}
	if (document.getElementById('1-7').checked){
		opciones = opciones + document.getElementById('ComeryBeber').value + '-' + document.getElementById('1-7').value + ',';
	}
	if (document.getElementById('2-8').checked){
		opciones = opciones + document.getElementById('SaludyBelleza').value + '-' + document.getElementById('2-8').value + ',';
	}
	if (document.getElementById('2-9').checked){
		opciones = opciones + document.getElementById('SaludyBelleza').value + '-' + document.getElementById('2-9').value + ',';
	}
	if (document.getElementById('2-10').checked){
		opciones = opciones + document.getElementById('SaludyBelleza').value + '-' + document.getElementById('2-10').value + ',';
	}
	if (document.getElementById('2-11').checked){
		opciones = opciones + document.getElementById('SaludyBelleza').value + '-' + document.getElementById('2-11').value + ',';
	}
	if (document.getElementById('2-12').checked){
		opciones = opciones + document.getElementById('SaludyBelleza').value + '-' + document.getElementById('2-12').value + ',';
	}
	if (document.getElementById('2-44').checked){
		opciones = opciones + document.getElementById('SaludyBelleza').value + '-' + document.getElementById('2-44').value + ',';
	}
	if (document.getElementById('3-13').checked){
		opciones = opciones + document.getElementById('Tiendas').value + '-' + document.getElementById('3-13').value + ',';
	}
	if (document.getElementById('3-14').checked){
		opciones = opciones + document.getElementById('Tiendas').value + '-' + document.getElementById('3-14').value + ',';
	}
	if (document.getElementById('3-15').checked){
		opciones = opciones + document.getElementById('Tiendas').value + '-' + document.getElementById('3-15').value + ',';
	}
	if (document.getElementById('3-16').checked){
		opciones = opciones + document.getElementById('Tiendas').value + '-' + document.getElementById('3-16').value + ',';
	}
	if (document.getElementById('3-17').checked){
		opciones = opciones + document.getElementById('Tiendas').value + '-' + document.getElementById('3-17').value + ',';
	}
	if (document.getElementById('3-18').checked){
		opciones = opciones + document.getElementById('Tiendas').value + '-' + document.getElementById('3-18').value + ',';
	}
	if (document.getElementById('3-19').checked){
		opciones = opciones + document.getElementById('Tiendas').value + '-' + document.getElementById('3-19').value + ',';
	}
	if (document.getElementById('3-20').checked){
		opciones = opciones + document.getElementById('Tiendas').value + '-' + document.getElementById('3-20').value + ',';
	}
	if (document.getElementById('3-42').checked){
		opciones = opciones + document.getElementById('Tiendas').value + '-' + document.getElementById('3-42').value + ',';
	}
	if (document.getElementById('4-21').checked){
		opciones = opciones + document.getElementById('Servicios').value + '-' + document.getElementById('4-21').value + ',';
	}
	if (document.getElementById('4-22').checked){
		opciones = opciones + document.getElementById('Servicios').value + '-' + document.getElementById('4-22').value + ',';
	}
	if (document.getElementById('4-23').checked){
		opciones = opciones + document.getElementById('Servicios').value + '-' + document.getElementById('4-23').value + ',';
	}
	if (document.getElementById('4-39').checked){
		opciones = opciones + document.getElementById('Servicios').value + '-' + document.getElementById('4-39').value + ',';
	}
	if (document.getElementById('4-24').checked){
		opciones = opciones + document.getElementById('Servicios').value + '-' + document.getElementById('4-24').value + ',';
	}
	if (document.getElementById('5-25').checked){
		opciones = opciones + document.getElementById('OcioyDeporte').value + '-' + document.getElementById('5-25').value + ',';
	}
	if (document.getElementById('5-26').checked){
		opciones = opciones + document.getElementById('OcioyDeporte').value + '-' + document.getElementById('5-26').value + ',';
	}
	if (document.getElementById('5-27').checked){
		opciones = opciones + document.getElementById('OcioyDeporte').value + '-' + document.getElementById('5-27').value + ',';
	}
	if (document.getElementById('5-28').checked){
		opciones = opciones + document.getElementById('OcioyDeporte').value + '-' + document.getElementById('5-28').value + ',';
	}
	if (document.getElementById('5-29').checked){
		opciones = opciones + document.getElementById('OcioyDeporte').value + '-' + document.getElementById('5-29').value + ',';
	}
	if (document.getElementById('5-30').checked){
		opciones = opciones + document.getElementById('OcioyDeporte').value + '-' + document.getElementById('5-30').value + ',';
	}
	
	if (document.getElementById('6-31').checked){
		opciones = opciones + document.getElementById('ViajesyAlojamiento').value + '-' + document.getElementById('6-31').value + ',';		
	}
	if (document.getElementById('6-32').checked){
		opciones = opciones + document.getElementById('ViajesyAlojamiento').value + '-' + document.getElementById('6-32').value + ',';		
	}
	if (document.getElementById('6-33').checked){
		opciones = opciones + document.getElementById('ViajesyAlojamiento').value + '-' + document.getElementById('6-33').value + ',';		
	}
	if (document.getElementById('6-34').checked){
		opciones = opciones + document.getElementById('ViajesyAlojamiento').value + '-' + document.getElementById('6-34').value + ',';		
	}
	if (document.getElementById('6-43').checked){
		opciones = opciones + document.getElementById('ViajesyAlojamiento').value + '-' + document.getElementById('6-43').value + ',';		
	}
	if (document.getElementById('7-40').checked){
		opciones = opciones + document.getElementById('Supermercados').value + '-' + document.getElementById('7-40').value + ',';		
	}
	  
	//Quita la ultima coma
	if (opciones.length > 0){
		opciones = opciones.substring(0,opciones.length-1);
	}
	
	document.forms['avisoBusquedaBean'].listaSubSector.value = opciones;		
}

function marcarSectores(){
	//Desactiva un sector si hay subsector no seleccionado	
	if (!document.getElementById('1-1').checked ||
	    !document.getElementById('1-2').checked ||
	    !document.getElementById('1-4').checked ||
	    !document.getElementById('1-5').checked ||
	    !document.getElementById('1-6').checked){
		
		document.getElementById('ComeryBeber').checked = false;		
	}	
    if (document.getElementById('1-1').checked &&
    	document.getElementById('1-2').checked &&
    	document.getElementById('1-4').checked &&
    	document.getElementById('1-5').checked &&
    	document.getElementById('1-6').checked){
    		
    	document.getElementById('ComeryBeber').checked = true;
    }
    
    if (!document.getElementById('2-8').checked ||
		!document.getElementById('2-9').checked ||
		!document.getElementById('2-10').checked ||
		!document.getElementById('2-11').checked){
    	
    	document.getElementById('SaludyBelleza').checked = false;
    }    
    if (document.getElementById('2-8').checked &&
    	document.getElementById('2-9').checked &&
    	document.getElementById('2-10').checked &&
    	document.getElementById('2-11').checked) {
        	
        document.getElementById('SaludyBelleza').checked = true;
    }
	
    if (!document.getElementById('3-13').checked ||
		!document.getElementById('3-14').checked ||
		!document.getElementById('3-15').checked || 
		!document.getElementById('3-16').checked || 
		!document.getElementById('3-17').checked ||
		!document.getElementById('3-18').checked ||
		!document.getElementById('3-19').checked){
		   
		document.getElementById('Tiendas').checked = false;
	}
    if (document.getElementById('3-13').checked &&
    	document.getElementById('3-14').checked &&
    	document.getElementById('3-15').checked && 
    	document.getElementById('3-16').checked && 
    	document.getElementById('3-17').checked &&
    	document.getElementById('3-18').checked &&
    	document.getElementById('3-19').checked){
    		   
    	document.getElementById('Tiendas').checked = true;
    }
    
    if(!document.getElementById('4-21').checked ||
	   !document.getElementById('4-22').checked ||
	   !document.getElementById('4-23').checked ||
	   !document.getElementById('4-39').checked){
		   
	   document.getElementById('Servicios').checked = false;
    }
    if(document.getElementById('4-21').checked &&
       document.getElementById('4-22').checked &&
       document.getElementById('4-23').checked &&
       document.getElementById('4-39').checked){
    			   
       document.getElementById('Servicios').checked = true;    			   
    }
    
    if(!document.getElementById('5-25').checked ||
	   !document.getElementById('5-26').checked ||
	   !document.getElementById('5-27').checked ||
	   !document.getElementById('5-28').checked ||
	   !document.getElementById('5-29').checked ||
	   !document.getElementById('5-30').checked){
    
	   document.getElementById('OcioyDeporte').checked = false;
    }
    if(document.getElementById('5-25').checked &&
       document.getElementById('5-26').checked &&
       document.getElementById('5-27').checked &&
       document.getElementById('5-28').checked &&
       document.getElementById('5-29').checked &&
       document.getElementById('5-30').checked){
    	    
       document.getElementById('OcioyDeporte').checked = true;
    }
    
    if(!document.getElementById('6-31').checked ||
	   !document.getElementById('6-32').checked ||
	   !document.getElementById('6-33').checked) {
    
	   document.getElementById('ViajesyAlojamiento').checked = false;
    }
    if(document.getElementById('6-31').checked &&
       document.getElementById('6-32').checked &&
       document.getElementById('6-33').checked) {
    	    
       document.getElementById('ViajesyAlojamiento').checked = true;
    }
    
    if(!document.getElementById('7-40').checked) {	  
       document.getElementById('Supermercados').checked = false;
    }
    
    if(document.getElementById('7-40').checked) {	    
       document.getElementById('Supermercados').checked = true;
    }

}

function marcarSubSectores(lista){     
   var subsectores;	
   var cajacheck;
   subsectores = lista.split(',');   
   for (var i = 0; i < subsectores.length; i++) {		   
	   cadena = subsectores[i];	   
	   cajacheck = document.getElementById(cadena);
	   cajacheck.checked = true;	   
   }   
   marcarSectores();
}

function sumar_linksOferta(){		
	document.forms['sumarLinksOfertaBean'].submit();	
}

function continuePublishingOffer(noError) {
	return noError;
}

function abrirPie() {
	document.forms['oferta01Bean'].esCuponable[0].disabled = false;
	document.forms['oferta01Bean'].esCuponable[1].disabled = false;
}

function cerrarPie() {
	document.forms['oferta01Bean'].esCuponable[0].disabled = true;
	document.forms['oferta01Bean'].esCuponable[1].disabled = true;
}

function VerFormularioModal2(idCapa) {	
	fondo = document.getElementById("popupMaskMio");
	capa = document.getElementById(idCapa);
	capa.style.position = "absolute";
	capa.style.display = "block";
	fondo.style.display = "block";
	capaPresentada = true;
	centrarCapas();
}

function cerrarAlgunosDirecciones() {

	for (i=0; i<document.forms['oferta04Bean'].ofertaValidIn.length; i++) {
		document.forms['oferta04Bean'].ofertaValidIn[i].disabled = true;
		document.forms['oferta04Bean'].ofertaValidIn[i].checked = false;
	}
	
}

function abrirAlgunosDirecciones() {

	for (i=0; i<document.forms['oferta04Bean'].ofertaValidIn.length; i++) {
		document.forms['oferta04Bean'].ofertaValidIn[i].disabled = false;
	}

}

function checkDistritosOfZona(zonaId, thisCheckBox) {
    var zonaStr = zonaId + '_';
    
	for (i=0; i<document.forms['oferta04Bean'].ofertaValidIn.length; i++) {
	  if (document.forms['oferta04Bean'].ofertaValidIn[i].value.indexOf(zonaStr) == 0) {
		  document.forms['oferta04Bean'].ofertaValidIn[i].checked = thisCheckBox.checked;
	  }
	}
    
}

function checkAllZonas(zonaId, thisCheckBox) {
   for (i=607; i<=664; i++) {
      if (i != 608 && i != 656 && i != 661){
	     var id = 'bannerValidIn_'+i;	   
	    
	     if(thisCheckBox.checked)
	        document.getElementById(id).checked = true;
		 else
		    document.getElementById(id).checked = false;
	  }
   }    
}

function almacenarAllZonas() {
   
   var cadena = '';
	 
   for (i=607; i<=664; i++) {
      if (i != 608 && i != 656 && i != 661){
	     var id = 'bannerValidIn_'+i;	   
		    
		 if(document.getElementById(id).checked){
		    
		    cadena  = cadena + document.getElementById(id).value + "-";		    	 
		 }     
	  }
   }
   document.forms['imagenbannerMBean'].bannerValidInCadena.value = cadena;
   
}

function checkUncheckParentDireccion(thisCheckBox) {
	var safeToUnCheck = new Boolean(true);
	var zona = thisCheckBox.value.substring(0,thisCheckBox.value.indexOf("_"));
	
	for (i=0; i<document.forms['oferta04Bean'].ofertaValidIn.length; i++) {
	  if (document.forms['oferta04Bean'].ofertaValidIn[i].value == zona ) {
		  
		  if (thisCheckBox.checked == true) {
		    document.forms['oferta04Bean'].ofertaValidIn[i].checked = thisCheckBox.checked;
		  } else {
			// if it will uncheck, see first if we could safely uncheck the parent (if there are no other sub which still has a check mark)
			for (j=0; j<document.forms['oferta04Bean'].ofertaValidIn.length; j++) {
				if ((document.forms['oferta04Bean'].ofertaValidIn[j].value.indexOf(zona + "_") != -1) && (document.forms['oferta04Bean'].ofertaValidIn[j].checked == true)) {
					safeToUnCheck = false;
				}
			}
			
			if (safeToUnCheck) {
				document.forms['oferta04Bean'].ofertaValidIn[i].checked = thisCheckBox.checked;
			}
			
		  }
	  }
	}

}




function initialize(listaLocalizacionesStr) {
	  
	  
	  var listaLocalizaciones = new Array();
	  var registro = new Array();
	  
	  
	  
	  listaLocalizaciones = listaLocalizacionesStr.split('@');
	  
	  
	  var map = new GMap2(document.getElementById("map_canvas")); 
	  map.setCenter(new GLatLng(40.544265,-3.624887), 10);
	  
	  // Add 10 markers to the map at random locations 
	  var bounds = map.getBounds(); 
	  var southWest = bounds.getSouthWest(); 
	  var northEast = bounds.getNorthEast(); 
	  var lngSpan = northEast.lng() - southWest.lng(); 
	  var latSpan = northEast.lat() - southWest.lat();
	  	  
	  //alert("Antes del For " + listaLocalizaciones.length);
	  for (var i = 0; i < listaLocalizaciones.length - 1; i++) { 
		  registro = registro = listaLocalizaciones[i].split('|');
		  alert(i + " : " + registro[2] +  "/" + registro[3] );
		  var point = new GLatLng(parseFloat(registro[2]), parseFloat(registro[3]));
		  map.addOverlay(new GMarker(point));
    }
	  
	  
	}


function mapaParticular() {
	  
	if (GBrowserIsCompatible()) { 
      var map = new GMap2(document.getElementById("map_canvas"));         
      map.setCenter(new GLatLng(40.544265,-3.624887), 15);
      map.addOverlay(new GMarker(new GLatLng(40.544265,-3.624887))); 
  } 
}

function mapa() {
	var map = null;
	var geocoder = null;
	var direccion;
	
  if (GBrowserIsCompatible()) { 
    var map = new GMap2(document.getElementById("map_canvas"));        
              
    geocoder = new GClientGeocoder();
    direccion = document.getElementById('maps_banner').value      
    
    if (geocoder) {              	  
        geocoder.getLatLng(
      		  direccion,
          function(point) {              
            if (!point) {
              alert(direccion + " no localizada");
            } else {            	  
              map.setCenter(point, 16);
              alert(point);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(direccion);                
            }
          }
        );
    }      
  }
}



function cordenadasMapa(lista) {
	
	var map = null;
	var geocoder = null;
	var direccion;
	var coordenadas ="";
	var id;
	var laDireccion;
	var listaDireccionesAux = new Array();
	var registro = new Array();
	
	listaDireccionesAux = lista.split('$');	
	for (var i = 0; i < listaDireccionesAux.length - 1; i++) {	
		
		registro = listaDireccionesAux[i].split('@');		
		 		
	    if (GBrowserIsCompatible()) { 	                
         geocoder = new GClientGeocoder();
         direccion = registro[1];                 
         if (geocoder) {        	  
            geocoder.getLatLng(direccion,
              function(point) {              
                 if (!point) {
              	   
                    coordenadas = coordenadas + registro[0] + "," + point.lat() + ", 0"  + "@";                      
                 } else {                          	   
              	   coordenadas = coordenadas + registro[0] + "," + point.lat() + "," + point.lng() + "@";
              	   
                 }
              }
            );
         }      
      }
	    
	    
	}	
	
	document.getElementById('puntos').value = coordenadas;
	
} 




//Lo Uso en carga direcciones
function mapaParticularDireccion(id, direccion) {
	
	alert("DIRECCION:: " + id + " DIRECCION " + direccion);
	
	
	var map = null;
	var geocoder = null;
	//var direccion;
	
  if (GBrowserIsCompatible()) { 
    var map = new GMap2(document.getElementById("map_canvas"));        
    //map.setCenter(new GLatLng(40.544265,-3.624887), 16);          
    geocoder = new GClientGeocoder();
    //direccion = document.getElementById('maps_banner').value      
    
    if (geocoder) {              	  
        geocoder.getLatLng(
      		  direccion,
          function(point) {              
            if (!point) {
              alert(direccion + " no localizada");
            } else {            	  
              map.setCenter(point, 16);
              //alert(point);
              
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(direccion);
              alert("UPDATE otrasdirecciones SET latitud = " + point.lat() + " , longitud = " + point.lng() + " WHERE idDireccion = " + id + ";");
            }
          }
        );
    }      
  }
}

function cordenadasMapa2(lista) {
	 
	var geocoder = null;
	var direccion;
	var coordenadas ="";
	var id;
	var laDireccion;
	var listaDireccionesAux = new Array();
	var registro = new Array();
	var str;
	 	
	listaDireccionesAux = lista.split('$');	
	
	if (GBrowserIsCompatible()) {   
	      geocoder = new GClientGeocoder();
		  //direccion = registro[1];                 
		  if (geocoder) { 
			 //alert("Dentro del geocoder"); 
	
	         for (var i = 0; i < listaDireccionesAux.length - 1; i++) {	
		         //alert("VALOR DE I:::. " + i);
		         
		         registro = listaDireccionesAux[i].split('@');		
		         //alert("ANTES DE CALCULAR COORDENADA"); 		
	             id = registro[0];
               direccion = registro[1];
               //alert("ANTES DE IR A LA FUNCION");
               //alert(obtenerCoordenadas(direccion , geocoder, id));
               
               str = obtenerCoordenadas(direccion , geocoder, id);
	         }	
		 }
	}	
} 

///// FUNCIONES DE GOOGLE MAPS QUE SE OCUPAN HASTA EL MOMENTO ///////////////////

//Funciones para acceder al Servidor.
function inicialiazarRequest(url) {
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req2 = new XMLHttpRequest();        
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        req2 = new ActiveXObject("Microsoft.XMLHTTP");        
    }
}

function procesarRequest() {
   if (req.readyState == 4) {
      if (req.status == 200) {
        var coordenadas = req.responseXML.getElementsByTagName("coordenadas")[0].childNodes[0].nodeValue;
        var lat_lon = coordenadas.split(",");
        document.getElementById("latitud").value = lat_lon[0];
        document.getElementById("longitud").value = lat_lon[1];
      }
   }
}

//Lo uso en perfilUsuario y en Direcciones en el Mapa de la Direccion principañ
function mapaAnunciante(latitud, longitud) {		
  if (GBrowserIsCompatible()) { 
	  
	var baseIcon = new GIcon();
    baseIcon.iconSize=new GSize(32,32);
    baseIcon.shadowSize=new GSize(56,32);
    baseIcon.iconAnchor=new GPoint(16,32);
    baseIcon.infoWindowAnchor=new GPoint(16,0);
         	                  
    var logoOporRojo = new GIcon(baseIcon, "http://www.oportunista.com/imagenes/web/pin_oportunista_rojo.png", null, "http://www.oportunista.com/imagenes/web/shadow-pin_oportunista.png");
        
	  
    var map = new GMap2(document.getElementById("map_canvas_anun"));        
    map.setCenter(new GLatLng(latitud, longitud), 15);
    var marker = new GMarker(new GLatLng(latitud, longitud), logoOporRojo);
    map.addOverlay(marker);   
  }
}

//Permite posicionar las direcciones en Editar Direcciones
function mapaDireccionCambiarUbicacion(id, latitud, longitud) {
   
   if (GBrowserIsCompatible()) { 
      var map = new GMap2(document.getElementById("map_canvas2"));        
	  map.setCenter(new GLatLng(latitud, longitud), 15);
	  var marker = new GMarker(new GLatLng(latitud, longitud), {draggable: true}); 
	  map.addOverlay(marker);  
	 
	  map.addControl(new GLargeMapControl()); 
	  
	  
	  GEvent.addListener(marker, "dragstart", function() {map.closeInfoWindow();});
      GEvent.addListener(marker, "dragend",
              function() {
                  
                  latitud = marker.getLatLng().lat();
                  longitud = marker.getLatLng().lng();
                                    
                  var url = "OtrasDireccionesPrincipal.do?accion1=actualizar&" + "id=" + id + "&latitud=" + escape(latitud) + "&longitud=" + escape(longitud);
                  
                  inicialiazarRequest(url);
                  
                  req.onreadystatechange = procesarRequest;
                  req.open("GET", url, true);
                  req.send(null);
              });
   }
}

//Muestra la direccion de un mapa sin coordenadas para su confirmacion
function mapaFijarDirPrimeraVez(id, direccion) {	
	var map = null;
	var geocoder = null;
	//var direccion;
	
  if (GBrowserIsCompatible()) { 
    var map = new GMap2(document.getElementById("map_canvas2"));
    
    map.addControl(new GLargeMapControl()); 
    
              
    geocoder = new GClientGeocoder();
    //direccion = document.getElementById('maps_banner').value      
    
    if (geocoder) {              	  
        geocoder.getLatLng(
      		  direccion,
          function(point) {              
            if (!point) {
              alert(direccion + " no localizada");
            } else {            	  
              map.setCenter(point, 16);              
              var marker = new GMarker(point, {draggable: true});
              map.addOverlay(marker);
              
              //Si encuentra alguna direccion la salva
              latitud = marker.getLatLng().lat();
              longitud = marker.getLatLng().lng();
                                
              var url = "OtrasDireccionesPrincipal.do?accion1=actualizar&" + "id=" + id + "&latitud=" + escape(latitud) + "&longitud=" + escape(longitud);
              
              inicialiazarRequest(url);
              
              req.onreadystatechange = procesarRequest;
              req.open("GET", url, true);
              req.send(null);
              //Fin de salvada              
              GEvent.addListener(marker, "dragstart", function() {map.closeInfoWindow();});
              GEvent.addListener(marker, "dragend",
                      function() {
                          
                          latitud = marker.getLatLng().lat();
                          longitud = marker.getLatLng().lng();
                                            
                          var url = "OtrasDireccionesPrincipal.do?accion1=actualizar&" + "id=" + id + "&latitud=" + escape(latitud) + "&longitud=" + escape(longitud);
                          
                          inicialiazarRequest(url);
                          
                          req.onreadystatechange = procesarRequest;
                          req.open("GET", url, true);
                          req.send(null);
                      });                              
            }
          }
        );
    }      
  }
	
}


//Calcula la posición sugerida cuando se ingresa un nuevo perfil
function calculaCoordenadas(direccion) {

	
	var map = null;
	var geocoder = null;
	//var direccion;
	
  if (GBrowserIsCompatible()) { 
	  
    var map = new GMap2(document.getElementById("map_canvas"));        
            
    geocoder = new GClientGeocoder();
          
    
    if (geocoder) {        	
        geocoder.getLatLng(
      		  direccion,
          function(point) {       			
            if (!point) {
              alert(direccion + " no localizada");
              //latitud = 0;
              //longitud = 0;
              //document.getElementById("latitud").value = 0;
              //document.getElementById("longitud").value = 0;
            } else { 
              alert(direccion + " localizada"); 	
              map.setCenter(point, 16);
            //alert(direccion + " localizada"); 
              //alert(point);
              //latitud = point.lat();
              //longitud = point.lng();
              
              //document.getElementById("latitud").value = point.lat();
              //document.getElementById("longitud").value = point.lng();
              
              
              //alert(latitud + ", " longitud);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(direccion);                
            }
          }
        );
    }      
  }
}

function displayAlternateBanner() {
	
	// this will randomize number from 0-1, change this to another number
	// if you want to randomize more numbers
	var randomnumber=Math.floor(Math.random()*3);
	
	var alternateBannerHref = document.getElementById("alternateBannerHref");
	var alternateBannerImg = document.getElementById("alternateBannerImg");
	
	if (randomnumber == 0) {
		alternateBannerHref.href = "http://www.tarifas24.es";
		alternateBannerImg.src = "/imagenes/banners/banner_tarifas.gif";
	} else if (randomnumber == 1) {
		alternateBannerHref.href = "http://www.retospadel.com";
		alternateBannerImg.src = "/imagenes/banners/retos_padel.gif";
	}  else if (randomnumber == 2) {
		alternateBannerHref.href = "http://www.agentesdelanoche.com";
		alternateBannerImg.src = "/imagenes/banners/bannerADN.gif";
	}
	
}
//***********************************************
function recuperaOfertasZonaPorDireccion() {
    if (req.readyState == 4) {
      if (req.status == 200) {
    	//Recupera valores en formato JSON 
 	     ofertasJSon = eval('(' + req2.responseText +')');     	 
      }
    }
}

//***********************************************
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TODO LO REFERENTE A MAPA POR ZONA EN WELCOME ANTIGUO
//var host = "http://www.oportunista.com/";
//var host = "http://localhost:8080/";
var host = "";
var ofertasJSon = null;

//Usado en la Welcome para pintar TODAS las ofertas, aun que ahora se usa la funcion pintarOfertasEnDireccion()
//la cual solo pinta 200 ofertas de acuerdo a la direccion introducida.
function pintarOfertas() {	
   var so = new SWFObject("http://www.oportunista.com/imagenes/web/swf/loader_oportunista_ok.swf", "sotester", "620", "50", "9");	
   so.write("flashespera");

   if (ofertasJSon == null){	   
      var url = host + "OfertasEnMapa.do";     
      inicialiazarRequest(url);
      req2.onreadystatechange = pintarOfertasRequest;
  
      req2.open("GET", url, true);
      req2.send(null);
   }else{
      pintarOfertasSinJSonRequest();
   }	   
}

function pintarOfertasRequest() {
   //Si se ejecuta correctamente	 
   if (req2.readyState == 4) {  		 
      if (req2.status == 200) {  	    	  
	     //Recupera valores en formato JSON 
	     ofertasJSon = eval('(' + req2.responseText +')');   	         
	     pintarOfertasSinJSonRequest();               
	  }
   }
}


function pintarOfertasSinJSonRequest() {   	 
	         
 //Variables locales
 var map = null;
 var geocoder = null;
 var direccion;
	     	
 //Si el browser es compatible con Google Maps
 if (GBrowserIsCompatible()) {
	        	 
    var baseIcon = new GIcon();
	  baseIcon.iconSize=new GSize(32,32);
	  baseIcon.shadowSize=new GSize(56,32);
	  baseIcon.iconAnchor=new GPoint(16,32);
	  baseIcon.infoWindowAnchor=new GPoint(16,0);
	                	            
	  var logoOpor = new GIcon(baseIcon, "http://www.oportunista.com/imagenes/web/pin_oportunista.png", null, "http://www.oportunista.com/imagenes/web/shadow-pin_oportunista.png");
	             
	  //Crear marcas 
	  function crearMarca(point,html) {
	     var marker = new GMarker(point, logoOpor);
	     GEvent.addListener(marker, "mouseover", function() {
	    	 
	    	 marker.openInfoWindowHtml(html);
	        
	     });    	         	   
	     GEvent.addListener(marker, "click", function() {
	    	 marker.openInfoWindowHtml(html);    
	     });
	     return marker;
	  }     	         	    	        	     	        	
	        	     	        	    	        	  	        	
	  var map = new GMap2(document.getElementById("map_canvas"));        
	                   
	  geocoder = new GClientGeocoder();
	  direccion = document.getElementById('maps_banner').value + " ,España";     
	         
	  if (geocoder) {              	  
	     geocoder.getLatLng(
	        direccion,
	        function(point) {              
	           if (!point) {
	        	  verPausaOfertas("desactivar"); 
	              alert(direccion + " no localizada");
	           } else {            	   	               	                             	                            	                            	              	    
	              //Usado en ventana standar   	              	      
	              function pretty(foto1Url,nombreEmpresa, msgTipoOferta,titulo,direccion, zona, localidad, nombre_singular, nombreEmpresaFormatted, idUsuario, idDireccion, nombre_seo_url    ) {
	               	  return '<form name="myform" method="POST" action="' + host + nombre_seo_url + '/' + nombreEmpresaFormatted + '_o' + idUsuario + '">'
	              	             + '<input type="hidden" name="demapa" value="' + idDireccion + '"/> '
	              	             + '<table width="250" border="0" cellpadding="0" cellspacing="0">'    	              	             
	              	             + ' <tr>'
	              	             + '    <td colspan="3" width="100%"><b>' + nombre_singular + '</b>: ' + nombreEmpresa + '</td>'
	              	             + '    <td>&nbsp;</td>'
	              	             + ' </tr>'	              	             
	              	             + '<tr><td colspan="4" width="100%">&nbsp;</td></tr>'	              	             
	              	             + '<tr>'       		                               		                         
		                         + '  <td rowspan="6">'  
		                         + '     <img src="http://www.oportunista.com' + foto1Url +  '" width=115 height=80>'
		                         + '  </td>'
		                         + '  <td rowspan="6">&nbsp;&nbsp;&nbsp;</td>'
		                         + '  <td rowspan="5" class="estyleTable">'         		                              
		                         + '     <b>' + msgTipoOferta + '</b>: ' + titulo     		                         		                         
		                         + '  </td>'                        		                  
		                         + '</tr>'  
		                         + '<tr><td>&nbsp;</td></tr>'
		                         + '<tr><td>&nbsp;</td></tr> '
		                         + '<tr><td>&nbsp;</td></tr>'
		                         + '<tr><td>&nbsp;</td></tr> '
		                         + '<tr><td>'
		                         + '     <input type="submit" name="boton" value="+ info" class="botonMsjOferta"/> '
		                         + '</td></tr> '
		                         + '<tr><td colspan="4" width="100%">&nbsp;</td></tr>'
		                         + '<tr><td colspan="4">' + direccion + '</td></tr>'    		                         
		                         + '</table>'                        		                      		                                                                                                                                                    
                           + '</form> ';    	              	                    	    	  
	              }
	                
	              verPausaOfertas("desactivar"); 
	              for(var i = 0; i <  ofertasJSon.length; i++) {                        		
	                 var oferta1 = new GLatLng(ofertasJSon[i].latitud, ofertasJSon[i].longitud); 
	                 var html = pretty(ofertasJSon[i].foto1Url, ofertasJSon[i].nombreEmpresa, ofertasJSon[i].msgTipoOferta, ofertasJSon[i].titulo, ofertasJSon[i].direccion, ofertasJSon[i].zona, ofertasJSon[i].localidad, ofertasJSon[i].nombre_singular, ofertasJSon[i].nombreEmpresaFormatted, ofertasJSon[i].idUsuario, ofertasJSon[i].idDireccion, ofertasJSon[i].nombre_seo_url);    	                           
	                 var marker1 = crearMarca(oferta1,html);    	                           
	                 map.addOverlay(marker1);    	                                                   		                        	                        	
	              }
	              	              
	              map.setCenter(point, 16);                        
	              var marker = new GMarker(point);
	              map.addOverlay(marker);
	           }
	        }
	     );
	  }
    map.setUIToDefault();
 }                  		
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TODO LO REFERENTE A MAPA POR ZONA EN PERFIL USUARIO
function pintarOfertasZona(server) {
   host = server;   
   var so = new SWFObject("http://www.oportunista.com/imagenes/web/swf/loader_oportunista_ok_zona.swf", "sotester", "620", "50", "9");	
   so.write("flashespera");

   var valorTab = document.getElementById("clickTabMapa").value;
   
   var latitudDir = document.getElementById('maps_latitud').value;
   var longitudDir = document.getElementById('maps_longitud').value;
   
   if(valorTab == 0){	
	  verPausaOfertasZona("activar");  
      if (ofertasJSon == null){	      
         var url = host + "OfertasEnMapa.do?latitud='"+latitudDir+"'&longitud='"+longitudDir+"'";     
	     inicialiazarRequest(url);
	     req2.onreadystatechange = pintarOfertasZonaRequest;
	    
	     req2.open("GET", url, true);
	     req2.send(null);
      }else{    	  
         pintarOfertasZonaSinJSonRequest();
      } 
   }
}

function pintarOfertasZonaRequest() {   
   //Si se ejecuta correctamente	 
   if (req2.readyState == 4) {  		 
      if (req2.status == 200) {  	    	  
	     //Recupera valores en formato JSON 
		 ofertasJSon = eval('(' + req2.responseText +')'); 
		 pintarOfertasZonaSinJSonRequest();		 	                    
	  }
   }
}

function pintarOfertasZonaSinJSonRequest() {	 
 //Variables locales
 var map = null;
 var geocoder = null;
 var direccion;
 var latitudDir;
 var longitudDir;
		     	
 //Si el browser es compatible con Google Maps
 if (GBrowserIsCompatible()) {		        	 
    var baseIcon = new GIcon();
    baseIcon.iconSize=new GSize(32,32);
    baseIcon.shadowSize=new GSize(56,32);
    baseIcon.iconAnchor=new GPoint(16,32);
    baseIcon.infoWindowAnchor=new GPoint(16,0);
		                	            
    var logoOpor = new GIcon(baseIcon, "http://www.oportunista.com/imagenes/web/pin_oportunista.png", null, "http://www.oportunista.com/imagenes/web/shadow-pin_oportunista.png");
	var logoOporRojo = new GIcon(baseIcon, "http://www.oportunista.com/imagenes/web/pin_oportunista_rojo.png", null, "http://www.oportunista.com/imagenes/web/shadow-pin_oportunista.png");
		             
    //Crear marcas 
	  function crearMarca(point,html, tipo, id) {
		  var marker;
		  if(tipo == '1') 
	         marker = new GMarker(point, logoOpor);
		  else
			  marker = new GMarker(point, logoOporRojo);  
		 GEvent.addListener(marker, "mouseover", function() {
			 
	    	 $.get("/RegistrarPerfilOpo.do?tipo=3&ids="+id);
		    marker.openInfoWindowHtml(html);
		 });    	         	   
		 GEvent.addListener(marker, "click", function() {
			 
	    	 $.get("/RegistrarPerfilOpo.do?tipo=3&ids="+id);
		     marker.openInfoWindowHtml(html);    
		 });
		 return marker;
   }     	         	    	        	     	        	
		        	     	        	    	        	 
   var map = new GMap2(document.getElementById("map_canvas"));        
   var latitudDir = document.getElementById('maps_latitud').value;
   var longitudDir = document.getElementById('maps_longitud').value;
   var idUsuarioDir = document.getElementById('maps_idUsuario').value;
   
		            
   function pretty(foto1Url,nombreEmpresa, msgTipoOferta,titulo,direccion, zona, localidad, nombre_singular, nombreEmpresaFormatted, idUsuario, idDireccion, nombre_seo_url    ) {	   
	 	return '<form name="myform" method="POST" action="' + host + nombre_seo_url + '/' + nombreEmpresaFormatted + '_o' + idUsuario + '">'
	         + '<input type="hidden" name="demapa" value="' + idDireccion + '"/> '
	         + '<table width="250" border="0" cellpadding="0" cellspacing="0">'    	              	             
	         + ' <tr>'
	         + '    <td colspan="3" width="100%"><b>' + nombre_singular + '</b>: ' + nombreEmpresa + '</td>'
	         + '    <td>&nbsp;</td>'
	         + ' </tr>'	              	             
	         + '<tr><td colspan="4" width="100%">&nbsp;</td></tr>'	              	             
	         + '<tr>'       		                               		                         
	         + '  <td rowspan="6">'  
	         + '     <img src="http://www.oportunista.com' + foto1Url +  '" width=115 height=80>'
	         + '  </td>'
	         + '  <td rowspan="6">&nbsp;&nbsp;&nbsp;</td>'
	         + '  <td rowspan="5" class="estyleTable">'         		                              
	         + '     <b>' + msgTipoOferta + '</b>: ' + titulo     		                         		                         
	         + '  </td>'                        		                  
	         + '</tr>'  
	         + '<tr><td>&nbsp;</td></tr>'
	         + '<tr><td>&nbsp;</td></tr> '
	         + '<tr><td>&nbsp;</td></tr>'
	         + '<tr><td>&nbsp;</td></tr> '
	         + '<tr><td>'
	         + '     <input type="submit" onclick= "document.getElementById("clickTabMapa").value =0;" name="boton" value="+ info" class="botonMsjOferta"/> '
	         + '</td></tr> '
	         + '<tr><td colspan="4" width="100%">&nbsp;</td></tr>'
	         + '<tr><td colspan="4">' + direccion + '</td></tr>'    		                         
	         + '</table>'                        		                      		                                                                                                                                                    
	         + '</form> ';    	              	                    	    	  
	 }           	           	              	    	                      
     verPausaOfertasZona("desactivar");      	           	              	    	                       
	 for(var i = 0; i <  ofertasJSon.length; i++) {                        		
	    var oferta1 = new GLatLng(ofertasJSon[i].latitud, ofertasJSon[i].longitud); 
	    var html = pretty(ofertasJSon[i].foto1Url, ofertasJSon[i].nombreEmpresa, ofertasJSon[i].msgTipoOferta, ofertasJSon[i].titulo, ofertasJSon[i].direccion, ofertasJSon[i].zona, ofertasJSon[i].localidad, ofertasJSon[i].nombre_singular, ofertasJSon[i].nombreEmpresaFormatted, ofertasJSon[i].idUsuario, ofertasJSon[i].idDireccion, ofertasJSon[i].nombre_seo_url);
	    var marker1;
	    //Marca a todos los anunciantes seleccionados iguales
	    if(idUsuarioDir == ofertasJSon[i].idUsuario)
	       marker1 = crearMarca(oferta1,html, 0, ofertasJSon[i].idOferta);
	    else
	       marker1 = crearMarca(oferta1,html, 1, ofertasJSon[i].idOferta);
	    map.addOverlay(marker1);    	                                                   		                        	                        	
	 }  	                        
	      			        
	 map.setCenter(new GLatLng(latitudDir, longitudDir), 15);   
	 		        		     		            
	 map.setUIToDefault();
   }                 		
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//TODO LO REFERENTE AL MAPA DE ANUNCIANTES

var anunciantesJSon;

//Usado en la Welcome
function pintarAnunciantes() {	 
 var url = "AnunciantesEnMapa.do";     
 inicialiazarRequest(url);     
 req2.onreadystatechange = pintarAnunciantesRequest;
 req2.open("GET", url, true);
 req2.send(null);
}
	 			    
function pintarAnunciantesRequest() {
 //Si se ejecuta correctamente	 
 if (req2.readyState == 4) {
    if (req2.status == 200) {
	 	    	  
	 	 //Recupera valores en formato JSON 
	 	 var anunciantesJSon = eval('(' + req2.responseText +')'); 
	 	         
	 	 //Variables locales
	 	 var map = null;
	 	 var geocoder = null;
	 	 var direccion;
	 	     	
	 	 //Si el browser es compatible con Google Maps
	 	 if (GBrowserIsCompatible()) {
	 	        	 
	 	    var baseIcon = new GIcon();
	 	    baseIcon.iconSize=new GSize(32,32);
	 	    baseIcon.shadowSize=new GSize(56,32);
	 	    baseIcon.iconAnchor=new GPoint(16,32);
	 	    baseIcon.infoWindowAnchor=new GPoint(16,0);
	 	                	            
	 	    var logoOpor = new GIcon(baseIcon, "http://www.oportunista.com/imagenes/web/pin_oportunista.png", null, "http://www.oportunista.com/imagenes/web/shadow-pin_oportunista.png");
	 	             
	 	    //Crear marcas 
	 	    function crearMarca(point,html) {
	 	       var marker = new GMarker(point, logoOpor);
	 	       GEvent.addListener(marker, "mouseover", function() {
	 	          marker.openInfoWindowHtml(html);
	 	       });    	         	   
	 	       GEvent.addListener(marker, "click", function() {
	 	          marker.openInfoWindowHtml(html);    
	 	       });
	 	       return marker;
	 	    }     	         	    	        	     	        	
	 	        	     	        	    	        	 
	 	    var map = new GMap2(document.getElementById("map_canvas"));        
	 	                   
	 	    geocoder = new GClientGeocoder();
	 	    direccion = document.getElementById('maps_banner').value      
	 	         
	 	    if (geocoder) {              	  
	 	       geocoder.getLatLng(
	 	       	  direccion,
	 	          function(point) {              
	 	             if (!point) {
	 	                alert(direccion + " no localizada");
	 	             } else {            	  
	 	                map.setCenter(point, 16);                        
	 	                var marker = new GMarker(point);
	 	                map.addOverlay(marker);
	 	                            	                            	              	     	 	                
	 	              	function pretty(foto1Url,nombreEmpresa, direccion) {
	 	              	   return '<form name="myform" method="POST" action="' + host + '">'	              	             
		              	             + '<table width="250" border="0" cellpadding="0" cellspacing="0">'    	              	             
		              	             + ' <tr>'
		              	             + '    <td colspan="3" width="100%"><b>Empresa</b>: ' + nombreEmpresa + '</td>'
		              	             + '    <td>&nbsp;</td>'
		              	             + ' </tr>'	              	             
		              	             + '<tr><td colspan="4" width="100%">&nbsp;</td></tr>'	              	             
		              	             + '<tr>'       		                               		                         
			                         + '  <td rowspan="6">'  
			                         + '     <img src="http://www.oportunista.com' + foto1Url +  '" width=115 height=80>'
			                         + '  </td>'
			                         + '  <td rowspan="6">&nbsp;&nbsp;&nbsp;</td>'
			                         + '  <td rowspan="5" class="estyleTable">'         		                              
			                         + '     &nbsp; '     		                         		                         
			                         + '  </td>'                        		                  
			                         + '</tr>'  
			                         + '<tr><td>&nbsp;</td></tr>'
			                         + '<tr><td>&nbsp;</td></tr> '
			                         + '<tr><td>&nbsp;</td></tr>'
			                         + '<tr><td>&nbsp;</td></tr> '
			                         + '<tr><td>'
			                         + '     <input type="submit" name="boton" value="+ info" class="botonMsjOferta"/> '
			                         + '</td></tr> '
			                         + '<tr><td colspan="4" width="100%">&nbsp;</td></tr>'
			                         + '<tr><td colspan="4">' + direccion + '</td></tr>'    		                         
			                         + '</table>'                        		                      		                                                                                                                                                    
	                             + '</form> ';    	              	                    	    	  
	 	              	}
	 	              	           	              	    	                       
	 	                for(var i = 0; i <  anunciantesJSon.length; i++) {                        		
	 	                   var anunciante = new GLatLng(anunciantesJSon[i].latitud, anunciantesJSon[i].longitud); 
	 	                   var html = pretty(anunciantesJSon[i].foto1Url, anunciantesJSon[i].nombreEmpresa, anunciantesJSon[i].direccion);    	                           
	 	                   var marker1 = crearMarca(anunciante,html);    	                           
	 	                   map.addOverlay(marker1);    	                                                   		                        	                        	
	 	                }
	 	             }
	 	          }
	 	       );
	 	    }
	 	    map.setUIToDefault();
	 	 }                 
	  }
   } 
}

function initializeInvitarAmigos(idUsuario, idOferta) {
	document.forms['invitarAmigosBean'].indice.value = "0";
	document.forms['invitarAmigosBean'].idUsuario.value = idUsuario;
	document.forms['invitarAmigosBean'].idOferta.value = idOferta;
	
	return true;
}
////******************************************************************
//NUEVO PARA WELCOME
//Usado en la Welcome, pinta las 200 ofertas más cercanas a una dirección introducida
var mapWelcome = null;
function pintarOfertasEnDireccion(server) {   	 
    
     //Asigna servidor	
	 host = server;	 
	 
	 //Variables locales	 
	 var geocoder = null;
	 var direccion;
	 var latitudDir = 0;
	 var longitudDir = 0;
		     	
	 //Si el browser es compatible con Google Maps
	 if (GBrowserIsCompatible()) {
		        	 	            	     	        	    	        	  	        
		  mapWelcome = new GMap2(document.getElementById("map_canvas"));                      
		  geocoder = new GClientGeocoder();
		  direccion = document.getElementById('maps_banner').value + " ,España";     		  
		  
		  if (geocoder) {              	  
		     geocoder.getLatLng(
		        direccion,
		        function(point) {              
		           if (!point) {
		        	  verPausaOfertas("desactivar");  
		              alert(direccion + " no localizada");
		           } else {            	   	               	                             	                            	                            	              	    
		              			        	   		        	      		        	   		        	 
		        	  latitudDir = point.lat();
		        	  longitudDir = point.lng();
		        	  
		        	  pintarOfertasEnDireccionEncontradas(latitudDir, longitudDir);  
	 	             
	 	              mapWelcome.setCenter(point, 16);                        
	 	              var marker = new GMarker(point);
	 	              mapWelcome.addOverlay(marker);	 	             
		           }
		        }
		     );
		  }		  	    
	 }                  		
}
	
function pintarOfertasEnDireccionEncontradas(latitudDir, longitudDir) {	   
   var so = new SWFObject("http://www.oportunista.com/imagenes/web/swf/loader_oportunista_ok_zona.swf", "sotester", "620", "50", "9");	
   so.write("flashespera");
   
   mapWelcome = new GMap2(document.getElementById("map_canvas"));
    
   var url = host + "OfertasEnMapa.do?latitud='"+latitudDir+"'&longitud='"+longitudDir+"'";
   inicialiazarRequest(url);
   req2.onreadystatechange = pintarOfertasEnDireccionEncontradasRequest;

   req2.open("GET", url, true);
   req2.send(null);
}


function pintarOfertasEnDireccionEncontradasRequest() {	
   //Si se ejecuta correctamente	 
   if (req2.readyState == 4) {  		 
      if (req2.status == 200) {  	    	  
	     //Recupera valores en formato JSON 
		 ofertasJSon = eval('(' + req2.responseText +')');   	         
		 ofertasEnDireccionEncontradas();               
	  }
   }
}

function ofertasEnDireccionEncontradas() {  
	 //Variables locales	 
	 var geocoder = null;
	 var direccion;
		     	
	 //Si el browser es compatible con Google Maps
	 if (GBrowserIsCompatible()) {
		        	 
	    var baseIcon = new GIcon();
		  baseIcon.iconSize=new GSize(32,32);
		  baseIcon.shadowSize=new GSize(56,32);
		  baseIcon.iconAnchor=new GPoint(16,32);
		  baseIcon.infoWindowAnchor=new GPoint(16,0);
		                	            
		  var logoOpor = new GIcon(baseIcon, "http://www.oportunista.com/imagenes/web/pin_oportunista.png", null, "http://www.oportunista.com/imagenes/web/shadow-pin_oportunista.png");
		             
		  //Crear marcas 
		  function crearMarca(point,html, id) {
		     var marker = new GMarker(point, logoOpor);
		     GEvent.addListener(marker, "mouseover", function() {
		    	 $.get("/RegistrarPerfilOpo.do?tipo=3&ids="+id);
		    	 marker.openInfoWindowHtml(html);
		        
		     });    	         	   
		     GEvent.addListener(marker, "click", function() {
		        marker.openInfoWindowHtml(html);
		        $.get("/RegistrarPerfilOpo.do?tipo=3&ids="+id);
		     });
		     return marker;
		  }     	         	    	        	     	        	
		        	     	        	    	        	  	        	
		  geocoder = new GClientGeocoder();
		  direccion = document.getElementById('maps_banner').value + " ,España";     
		         
		  if (geocoder) {              	  
		     geocoder.getLatLng(
		        direccion,
		        function(point) {              
		           if (!point) {
		        	  verPausaOfertas("desactivar"); 
		              alert(direccion + " no localizada");
		           } else {            	   	               	                             	                            	                            	              	    
		              //Usado en ventana standar   	              	      
		              function pretty(foto1Url,nombreEmpresa, msgTipoOferta,titulo,direccion, zona, localidad, nombre_singular, nombreEmpresaFormatted, idUsuario, idDireccion, nombre_seo_url    ) {
		               	  return '<form name="myform" method="POST" action="' + host + nombre_seo_url + '/' + nombreEmpresaFormatted + '_o' + idUsuario + '">'
		              	             + '<input type="hidden" name="demapa" value="' + idDireccion + '"/> '
		              	             + '<table width="250" border="0" cellpadding="0" cellspacing="0">'    	              	             
		              	             + ' <tr>'
		              	             + '    <td colspan="3" width="100%"><b>' + nombre_singular + '</b>: ' + nombreEmpresa + '</td>'
		              	             + '    <td>&nbsp;</td>'
		              	             + ' </tr>'	              	             
		              	             + '<tr><td colspan="4" width="100%">&nbsp;</td></tr>'	              	             
		              	             + '<tr>'       		                               		                         
			                         + '  <td rowspan="6">'  
			                         + '     <img src="http://www.oportunista.com' + foto1Url +  '" width=115 height=80>'
			                         + '  </td>'
			                         + '  <td rowspan="6">&nbsp;&nbsp;&nbsp;</td>'
			                         + '  <td rowspan="5" class="estyleTable">'         		                              
			                         + '     <b>' + msgTipoOferta + '</b>: ' + titulo     		                         		                         
			                         + '  </td>'                        		                  
			                         + '</tr>'  
			                         + '<tr><td>&nbsp;</td></tr>'
			                         + '<tr><td>&nbsp;</td></tr> '
			                         + '<tr><td>&nbsp;</td></tr>'
			                         + '<tr><td>&nbsp;</td></tr> '
			                         + '<tr><td>'
			                         + '     <input type="submit" name="boton" value="+ info" class="botonMsjOferta"/> '
			                         + '</td></tr> '
			                         + '<tr><td colspan="4" width="100%">&nbsp;</td></tr>'
			                         + '<tr><td colspan="4">' + direccion + '</td></tr>'    		                         
			                         + '</table>'                        		                      		                                                                                                                                                    
	                           + '</form> ';    	              	                    	    	  
		              }
		                
		              verPausaOfertas("desactivar"); 
		              for(var i = 0; i <  ofertasJSon.length; i++) {                        		
		                 var oferta1 = new GLatLng(ofertasJSon[i].latitud, ofertasJSon[i].longitud); 
		                 var html = pretty(ofertasJSon[i].foto1Url, ofertasJSon[i].nombreEmpresa, ofertasJSon[i].msgTipoOferta, ofertasJSon[i].titulo, ofertasJSon[i].direccion, ofertasJSon[i].zona, ofertasJSon[i].localidad, ofertasJSon[i].nombre_singular, ofertasJSon[i].nombreEmpresaFormatted, ofertasJSon[i].idUsuario, ofertasJSon[i].idDireccion, ofertasJSon[i].nombre_seo_url);    	                           
		                 var marker1 = crearMarca(oferta1,html,ofertasJSon[i].idOferta);    	                           
		                 mapWelcome.addOverlay(marker1);    	                                                   		                        	                        	
		              }
		              		              
		              mapWelcome.setCenter(point, 16);                        
		              var marker = new GMarker(point);
		              mapWelcome.addOverlay(marker);
		           }
		        }
		     );
		  }
		  mapWelcome.setUIToDefault();
	 }                  		
}

function enviarAvisosBulk() {
	if(document.getElementById("enviarAvisoSmsBulk").checked){
	
		document.forms['enviarSmsBulkBean'].esRecibirAvisosBulk.value = "1";	
	}else{
		document.forms['enviarSmsBulkBean'].esRecibirAvisosBulk.value = "0";		
	}
}

function direccionAPosicionar(direccion){
	document.getElementById("direccionPosicionar").innerHTML = "<b>dirección a ubicar: </b>" + direccion;
	
}

function cambiarZonaDireccionOfertas(comboDir, idOferta){
	
	/*var dirId = "direccionOfertas" + idOferta;
	
	var dirDetails = comboDir.options[comboDir.selectedIndex].value;
	
	document.forms['enviarCuponBean'].idDireccionEnviado.value = dirDetails;
	
	document.getElementById(dirId).innerHTML = dirDetails[1];*/
	
}

function cambiarDireccionOfertas(comboDir, direccionId){
	
	var dirId = "direccionOfertas" + direccionId; 
	var dirDetails = comboDir.options[comboDir.selectedIndex].value.split(":");
	
	document.forms['enviarCuponBean'].idDireccionEnviado.value = dirDetails[0];
	
	document.getElementById(dirId).innerHTML = dirDetails[1];
	
}

function cambiarDireccionOfertas2(idcomboDir, direccionId){
	
	var comboDir=document.getElementById(idcomboDir);
	alert('1');
	var dirId = "direccionOfertas" + direccionId; 
	var dirDetails = comboDir.options[comboDir.selectedIndex].value.split(":");
	
	document.forms['enviarCuponBean'].idDireccionEnviado.value = dirDetails[0];
	alert(dirDetails[1]);
	document.getElementById(dirId).innerHTML = dirDetails[1];
	
}


function cambiarDireccionOfertasSeguro(comboDir, direccionId){
	
	var dirId = "direccionOfertas" + direccionId; 
	var dirDetails = comboDir.options[comboDir.selectedIndex].value.split(":");
	
	document.forms['validarCuponSeguroBean'].idDireccionEnviado.value = dirDetails[0];

}

function stopSubmit(){
	return false;
}

function cambiarDireccionOfertasSms(comboDir, direccionId){
	
	var dirId = "direccionOfertasSms" + direccionId; 
	var dirDetails = comboDir.options[comboDir.selectedIndex].value.split(":");
	//document.forms['enviarCuponBean'].idDireccionEnviado.value = dirDetails[0];
	document.getElementById("idDireccionEnviadoSms").value = dirDetails[0];
	document.getElementById(dirId).innerHTML = dirDetails[1];
}

function checkCreditos(anuncianteCreditos,whereItCameFrom,idOferta, dePago) {
	if (dePago != 2){
	  if (anuncianteCreditos < 4) {
		// display a popup
		VerFormularioModal('noCreditos');	
		return false;
	  }
	}
    
	if (whereItCameFrom == 1) { // it came from IncluirOferta
	  document.location.href = '/Oferta1Ini.do';
	} else if (whereItCameFrom == 2) { // it came from RepetirOferta
	  document.location.href = '/Oferta2RepIni.do?idOferta=' + idOferta;	
	} else if (whereItCameFrom == 3) { // it came from Hazlo ahora (in the ofertas tab, when there is currently no active offer)
	  document.location.href = '/Oferta1Ini.do';
	}
	
	return true;
}

function verificaCookies(){
	
	var cookieEnabled=(navigator.cookieEnabled)? true : false
			
			//if not IE4+ nor NS6+
			if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ 
			document.cookie="testcookie"
			cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? true : false
			}
			
			if(!cookieEnabled)
				document.getElementById("sincookies").style.display='block';
				
	
}


function composeBuscarUrlOfertasCentroComercial() {
	
	document.forms['busquedaCentroComercialBean'].submit();
}

function borrarContenidoCentroComercial() {
	alert("EN borrarContenidoCentroComercial ");
	var textoO = document.forms['busquedaBean'].detalleO.value;
	if(textoO == "buscar en ofertas"){
		document.forms['busquedaBean'].detalleO.value = "";
	}
}	
function buscarCadenaCentroComercial(valor){
	
	document.forms['busquedaCentroComercialBean'].submit();
}

function colocarDatosErrorEmailLilla(email){
	
	var email = document.getElementById("emailEnvioTxt");
	email.innerHTML = email;	
}

function asignarEmailErrorLilla(email){
	document.getElementById("emailEnvioTxt").value= document.forms['busquedaCentroComercialBean'].emailEnvio.value;
}

function asignarEmailErrorVaguada(email){
	document.getElementById("emailEnvioTxt").value= document.forms['busquedaCentroComercialVaguadaBean'].emailEnvio.value;
}

function asignarLinkAOferta(link, idOferta) {		
	document.forms['cambiarLinkDirectoBean'].linkDirecto.value = link;
	document.forms['cambiarLinkDirectoBean'].idOfertaLinkDirectoBean.value = idOferta;
}


/*mapa intermedio en los resultados*/

function pintarOfertasEnDireccionIntermedio(server) {   	 
    
    //Asigna servidor	
	 host = server;	 
	 
	 //Variables locales	 
	 var geocoder = null;
	 var direccion;
	 var latitudDir = 0;
	 var longitudDir = 0;
		     	
	 //Si el browser es compatible con Google Maps
	 if (GBrowserIsCompatible()) {
		        	 	            	     	        	    	        	  	        
		  mapWelcome = new GMap2(document.getElementById("map_canvasintermedio"));                      
		  geocoder = new GClientGeocoder();
		  direccion = document.getElementById('maps_bannerintermedio').value + " ,España";     		  
		  
		  if (geocoder) {              	  
		     geocoder.getLatLng(
		        direccion,
		        function(point) {              
		           if (!point) {
		        	  //verPausaOfertas("desactivar");  
		              alert(direccion + " no localizada");
		           } else {            	   	               	                             	                            	                            	              	    
		              			        	   		        	      		        	   		        	 
		        	  latitudDir = point.lat();
		        	  longitudDir = point.lng();
		        	  
		        	  pintarOfertasEnDireccionEncontradasIntermedio(latitudDir, longitudDir);  
	 	             
	 	              mapWelcome.setCenter(point, 16);                        
	 	              var marker = new GMarker(point);
	 	              mapWelcome.addOverlay(marker);	 	             
		           }
		        }
		     );
		  }		  	    
	 }                  		
}
	
function pintarOfertasEnDireccionEncontradasIntermedio(latitudDir, longitudDir) {	   
 //var so = new SWFObject("http://www.oportunista.com/imagenes/web/swf/loader_oportunista_ok_zona.swf", "sotester", "620", "50", "9");	
  //so.write("flashesperaIntermedio");
  
  mapWelcome = new GMap2(document.getElementById("map_canvasintermedio"));
   
  var url = host + "OfertasEnMapa.do?latitud='"+latitudDir+"'&longitud='"+longitudDir+"'";
  inicialiazarRequest(url);
  req2.onreadystatechange = pintarOfertasEnDireccionEncontradasRequestIntermedio;

  req2.open("GET", url, true);
  req2.send(null);
}


function pintarOfertasEnDireccionEncontradasRequestIntermedio() {	
  //Si se ejecuta correctamente	 
  if (req2.readyState == 4) {  		 
     if (req2.status == 200) {  	    	  
	     //Recupera valores en formato JSON 
		 ofertasJSon = eval('(' + req2.responseText +')');   	         
		 ofertasEnDireccionEncontradasIntermedio();               
	  }
  }
}

function ofertasEnDireccionEncontradasIntermedio() {  
	 //Variables locales	 
	 var geocoder = null;
	 var direccion;
		     	
	 //Si el browser es compatible con Google Maps
	 if (GBrowserIsCompatible()) {
		        	 
	    var baseIcon = new GIcon();
		  baseIcon.iconSize=new GSize(32,32);
		  baseIcon.shadowSize=new GSize(56,32);
		  baseIcon.iconAnchor=new GPoint(16,32);
		  baseIcon.infoWindowAnchor=new GPoint(16,0);
		                	            
		  var logoOpor = new GIcon(baseIcon, "http://www.oportunista.com/imagenes/web/pin_oportunista.png", null, "http://www.oportunista.com/imagenes/web/shadow-pin_oportunista.png");
		             
		  //Crear marcas 
		  function crearMarca(point,html, id) {
		     var marker = new GMarker(point, logoOpor);
		     GEvent.addListener(marker, "mouseover", function() {
		    	 $.get("/RegistrarPerfilOpo.do?tipo=3&ids="+id);
		    	 marker.openInfoWindowHtml(html);
		        
		     });    	         	   
		     GEvent.addListener(marker, "click", function() {
		        marker.openInfoWindowHtml(html);
		        $.get("/RegistrarPerfilOpo.do?tipo=3&ids="+id);
		     });
		     return marker;
		  }     	         	    	        	     	        	
		        	     	        	    	        	  	        	
		  geocoder = new GClientGeocoder();
		  direccion = document.getElementById('maps_bannerintermedio').value ;     
		         
		  if (geocoder) {              	  
		     geocoder.getLatLng(
		        direccion,
		        function(point) {              
		           if (!point) {
		        	  verPausaOfertas("desactivar"); 
		              alert(direccion + " no localizada");
		           } else {            	   	               	                             	                            	                            	              	    
		              //Usado en ventana standar   	              	      
		              function pretty(foto1Url,nombreEmpresa, msgTipoOferta,titulo,direccion, zona, localidad, nombre_singular, nombreEmpresaFormatted, idUsuario, idDireccion, nombre_seo_url    ) {
		               	  return '<form name="myform" method="POST" action="' + host + nombre_seo_url + '/' + nombreEmpresaFormatted + '_o' + idUsuario + '">'
		              	             + '<input type="hidden" name="demapa" value="' + idDireccion + '"/> '
		              	             + '<table width="250" border="0" cellpadding="0" cellspacing="0">'    	              	             
		              	             + ' <tr>'
		              	             + '    <td colspan="3" width="100%"><b>' + nombre_singular + '</b>: ' + nombreEmpresa + '</td>'
		              	             + '    <td>&nbsp;</td>'
		              	             + ' </tr>'	              	             
		              	             + '<tr><td colspan="4" width="100%">&nbsp;</td></tr>'	              	             
		              	             + '<tr>'       		                               		                         
			                         + '  <td rowspan="6">'  
			                         + '     <img src="http://www.oportunista.com' + foto1Url +  '" width=115 height=80>'
			                         + '  </td>'
			                         + '  <td rowspan="6">&nbsp;&nbsp;&nbsp;</td>'
			                         + '  <td rowspan="5" class="estyleTable">'         		                              
			                         + '     <b>' + msgTipoOferta + '</b>: ' + titulo     		                         		                         
			                         + '  </td>'                        		                  
			                         + '</tr>'  
			                         + '<tr><td>&nbsp;</td></tr>'
			                         + '<tr><td>&nbsp;</td></tr> '
			                         + '<tr><td>&nbsp;</td></tr>'
			                         + '<tr><td>&nbsp;</td></tr> '
			                         + '<tr><td>'
			                         + '     <input type="submit" name="boton" value="+ info" class="botonMsjOferta"/> '
			                         + '</td></tr> '
			                         + '<tr><td colspan="4" width="100%">&nbsp;</td></tr>'
			                         + '<tr><td colspan="4">' + direccion + '</td></tr>'    		                         
			                         + '</table>'                        		                      		                                                                                                                                                    
	                           + '</form> ';    	              	                    	    	  
		              }
		                
		              verPausaOfertas("desactivar"); 
		              for(var i = 0; i <  ofertasJSon.length; i++) {                        		
		                 var oferta1 = new GLatLng(ofertasJSon[i].latitud, ofertasJSon[i].longitud); 
		                 var html = pretty(ofertasJSon[i].foto1Url, ofertasJSon[i].nombreEmpresa, ofertasJSon[i].msgTipoOferta, ofertasJSon[i].titulo, ofertasJSon[i].direccion, ofertasJSon[i].zona, ofertasJSon[i].localidad, ofertasJSon[i].nombre_singular, ofertasJSon[i].nombreEmpresaFormatted, ofertasJSon[i].idUsuario, ofertasJSon[i].idDireccion, ofertasJSon[i].nombre_seo_url);    	                           
		                 var marker1 = crearMarca(oferta1,html,ofertasJSon[i].idOferta);    	                           
		                 mapWelcome.addOverlay(marker1);    	                                                   		                        	                        	
		              }
		              		              
		              mapWelcome.setCenter(point, 16);
		              //mapWelcome.setZoom(document.getElementById('hzoom').value);
		              var zom=1*document.getElementById('hzoom').value;
		              mapWelcome.setZoom(zom);
		              var marker = new GMarker(point);
		              mapWelcome.addOverlay(marker);
		           }
		        }
		     );
		  }
		  mapWelcome.setUIToDefault();
		  
	 }                  		
}
/*fin del mapas intermedio*/
function pasarintermedio(){
	
	baninter=document.getElementById('txtbuscar').value;
	document.getElementById('maps_bannerintermedio').value=baninter;
	
}

function colocarDatosBusquedaTxtPanelMapa(){	
	if (document.getElementById('maps_buscar').value != "buscar palabra clave en ofertas ..."){
	   document.forms['busquedaBean'].detalleO.value=document.getElementById('maps_buscar').value;
	}else{
	   document.forms['busquedaBean'].detalleO.value="";
	}
	document.forms['busquedaBean'].action='/VerOfertas.do?paginaReset=ok&btnBusqueda=ok';
	document.forms['busquedaBean'].submit();
	
}

function colocarDatosBusquedaTxtPanelMapaEvento(event)
{
	if (event.keyCode == 13){
		document.forms['busquedaBean'].detalleO.value=document.getElementById('maps_buscar').value;
		document.forms['busquedaBean'].action='/VerOfertas.do?paginaReset=ok&btnBusqueda=ok';
		document.forms['busquedaBean'].submit();
	}
}

function seleccionarOfertas(){
   
   var x=document.getElementsByName("chkOferta");
   var listaOfertas = "";
   
   for (i=0; i<x.length; i++) {
	   //alert(x[i].value + " " +x[i].checked);
	   if(x[i].checked){
		   listaOfertas = listaOfertas + x[i].value + ",";  
	   }
   }   
   if (listaOfertas == ""){
	   alert("Debes seleccionar al menos una oferta..." );	     
   }else{
	  listaOfertas = listaOfertas.substring(0,listaOfertas.length - 1); 
      document.forms['bKEEnvio1Bean'].listaOfertas.value = listaOfertas;
      document.forms['bKEEnvio1Bean'].action='/BKEEnviosRep.do';
	  document.forms['bKEEnvio1Bean'].submit();
   }
}
         
function seleccionarOfertasNew(){
	
    var x=document.getElementsByName("chkOferta");
	var listaOfertas = "";
	   
	for (i=0; i<x.length; i++) {
	   if(x[i].checked){
	      listaOfertas = listaOfertas + x[i].value + ",";  
	   }
	}   
	if (listaOfertas == ""){
	   document.forms['bKEEnvio1Bean'].listaOfertas.value = listaOfertas;	
	}else {
       listaOfertas = listaOfertas.substring(0,listaOfertas.length - 1); 
       document.forms['bKEEnvio1Bean'].listaOfertas.value = listaOfertas;
	}
   document.forms['bKEEnvio1Bean'].action='/BKEEnviosRep.do';
   document.forms['bKEEnvio1Bean'].submit();
}

function abrirProvincia(valor) {	
   var zona = document.getElementById("zonaForm_id");
		
   if (valor == 0) {
      zona.disabled = true;      
   } else {		
	  zona.disabled = false;	  	  
   }
}


