// JavaScript Document
function validateAcepto() {
    arguments.IsValid = testAcepto();
}

function testAcepto() {
    var a = document.getElementById('ctl00_CPH_cbAcepto');
    if (a.checked) {
        $('#spanCondUso').hide();
        return true;
    }
    else {
        $('#spanCondUso').show();
        return false;
    }
}

function validatePass() {
    arguments.IsValid = testPass();
}

function testPass() {
    var p = document.getElementById('ctl00_CPH_txtPass');

    if (p.value.length < 8) {
        $('#ctl00_CPH_spanErrorPass1').show();
        return false;
    }
    else {
        $('#ctl00_CPH_spanErrorPass1').hide();
        return true;
    }
}
function validateConfirmPass() {
    arguments.IsValid = testConfirmPass();
}

function testConfirmPass() {
    var cp = document.getElementById('ctl00_CPH_txtConfirmPass');
    var p = document.getElementById('ctl00_CPH_txtPass');
    if (p.value != cp.value) {
        $('#ctl00_CPH_spanErrorPass').show();
        return false;
    }
    else {
        $('#ctl00_CPH_spanErrorPass').hide();
        return true;
    }
}


function validateMail(source, arguments) {
    arguments.IsValid = testMail();
}

function testMail() {
    //alert($('#ctl00_CPH_txtEmail').value);
    var emailReg = "^(([a-zA-Z0-9_-])+\.)*([a-zA-Z0-9_-])+@(([a-zA-Z0-9_-])+\.)+([a-zA-Z0-9]){2,4}$";
    var regex = new RegExp(emailReg);
    var r = regex.test(document.getElementById('ctl00_CPH_txtEmail').value);
    if (r) {
        //$('#spanValidoMail').show();
        $('#ctl00_CPH_spanErrorMail').hide();
        return true;
    }
    else {
        //$('#spanValidoMail').hide();
        $('#ctl00_CPH_spanErrorMail').show();
        return false;
    }
}

// JavaScript Document
function desplegarLi() {
	var liContainers = $('.main_menu ul');
	liContainers.hide();
	$('.main_menu .des, .main_menu .open').click(function() {
		var capa = $(this).parent().next('ul')
		if ((capa).is(':visible')) {
			capa.slideToggle(105);
			$('#busprox select, #mundoMain #navPaises select').css({visibility:'visible'});
		}
		else {
			liContainers.hide();
			capa.slideToggle(105);
			    if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
				$('#busprox select, #mundoMain #navPaises select').css({visibility:'hidden'}); // Esto oculta los select que se muestran sobre elementos flotantes en IE6.
			}
		};
		return false;
	});
	$('*').click(function() {
		liContainers.hide();
		muestraSelects();
	 })
};
function desplegarTab() {
	var tabContainers = $('.fondobusca .int > div, .esq_redond .inner > div');
	tabContainers.hide().filter(':first').show();
	$('.busca_menu li:first').addClass('active').addClass('primera')
	$('.busca_menu a[href*=#]').click(function() {
		tabContainers.filter(':visible').toggle();
		$(this.hash).toggle();
		$('.busca_menu li').removeClass('active');
		$('.busca_menu li').removeClass('primera');
		var padre = $(this).parent().parent();
		padre.addClass('active');
		if ((this.hash) == ('#busrapida') || (this.hash) == ('#restaurante') || (this.hash) == ('#significativo')) { padre.addClass('primera') };
		return false;
	});
	$(".buscador").removeClass('none');
};

function selectTab(tab) {
	var tabContainers = $('.fondobusca .int > div, .esq_redond .inner > div');
	tabContainers.filter(':visible').toggle();
	$(tab).toggle();
	$('.busca_menu li').removeClass('active');
	$('.busca_menu li').removeClass('primera');
	//$('.busca_menu a[href*=' + tab + ']').parent().parent().addClass('active');
	var padre = $('.busca_menu a[href*=' + tab + ']').parent().parent();
	padre.addClass('active');
	if ((tab) == ('#busrapida') || (tab) == ('#restaurante') || (tab) == ('#significativo')) { padre.addClass('primera') };
	return false;
}

/*function desplegarMapa() {
	//$('#mapa').hide()
	//$('.mapav').hide()
	$('.mapao').click(function() {
		if (document.getElementById('ctl00_CPH_imgbtnMostrarMapa').style.visibility == 'hidden') return;

		if (document.getElementById('frame_mapa').src != document.getElementById('ctl00_CPH_hfMappy').value) {
			document.getElementById('frame_mapa').src = document.getElementById('ctl00_CPH_hfMappy').value;
			document.getElementById('frame_mapa').style.visibility = 'visible';
			$('#ctl00_CPH_imgCargando').show();
		}

		$('#mapa').slideToggle(500)
		$('.mapav').toggle()
		$('.mapao').toggle()
		return false;
	});
	$('.mapav').click(function() {
		$('#mapa').slideToggle(500)
		$('.mapav').toggle()
		$('.mapao').toggle()
		return false;
	});

	$('.mapao').toggle()
	//document.getElementById('mapao').style.display = 'block'; //backup method for if toggle doesn't work
};
*/
/*function desplegarCupones() {
	$('.table_cupones dd ').hide().filter('.actual').show();
	$('dd.actual').prev().css("border", "none");
	$('dd.actual').prev().find('a').css("background-image", "url(img/menos.gif)");
	$('.table_cupones dt a').click(function() {
		var capa = $(this).parent().next()
		if ((capa).hasClass('actual'))
			return false;
		else {
			if ((capa).is(':visible')) {
				capa.slideToggle(115);
				$(this).css("background-image", "url(img/mas.gif)");
				$(this).parent().css("border-bottom", "solid 1px #fff");
			}
			else {
				if ((capa).parent().not('.actual') != null) {
					$('.table_cupones dd').hide().filter('.actual').show();
					$('.table_cupones dt a').css("background-image", "url(img/mas.gif)");
					$('.table_cupones dt').css("border-bottom", "solid 1px #fff");
					$('dd.actual').prev().css("border", "none");
					$('dd.actual').prev().find('a').css("background-image", "url(img/menos.gif)");
					capa.slideToggle(115);
					$(this).css("background-image", "url(img/menos.gif)");
					$(this).parent().css("border", "none");
					$(this).parent().next('dd').css("border-bottom", "solid 1px #fff");
				}
			};
			return false
		};
	});
};*/
function desplagarNext() {
	$('.prestamos').hide()//despliega amarillas resultados
	$('.disclai div').hide()// despliega disclaimer cupones
	//$('.legal div').hide()// despliega legal resultados
	$('.localidad a').click(function() {
		$(this).parent().next().slideToggle(150)
		$(this).parents('.datos').toggleClass("desplegado")
		return false;
	});
	$('.disclai .over a.desplegar').click(function() {
		$(this).parent().next().slideToggle(150)
		$(this).toggleClass('bgc')
		return false;
	});
	$('.legal p a').click(function() {
		$(this).parent().next().slideToggle(150)
		return false;
	});
};
function desplegarContactoEmpresas() {
	//$('#mas_contacto').hide();
	$('.lista_empresas .opciones a').click(function() {
		$('#mas_contacto').slideToggle(150);
		if (document.getElementById('OcultarContactos').style.display == 'none') {
			document.getElementById('OcultarContactos').style.display = 'block';
			document.getElementById('VerContactos').style.display = 'none';
		}
		else {
			document.getElementById('OcultarContactos').style.display = 'none';
			document.getElementById('VerContactos').style.display = 'block';
			var sPath = window.location.pathname;
			var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
			window.location = sPage + "#contactos"
		}
		return false;
	});
};
/*function desplegarmapaEmpresas() {
	//$('#mapa_info').hide();
	$('#info').click(function() {
	if ($('#mapa_ampliar').is(':visible')) {
		$('#mapa_ampliar').fadeOut(450);
	}
	if ($('#mapa_itinerario').is(':visible')) {
		$('#mapa_itinerario').fadeOut(450);
	}
	if ($('#mapa_vista3d').is(':visible')) {
		$('#mapa_vista3d').fadeOut(450);
	}
	if ($('#mapa_info').is(':visible')) {
			$('#mapa_info').fadeOut(450);
			$('#mapa_cover').fadeOut(450);
		} else {
			$('#mapa_info').fadeIn(450);
			$('#mapa_cover').fadeIn(450);
		};
		return false;
	});
	$('#mapa_info p:first a').click(function() {
	$('#mapa_info').fadeOut(450);
	$('#mapa_cover').fadeOut(450);
		return false;
	});
};*/
/*
function desplegarAmpliarEmpresas() {
	//$('#mapa_ampliar').hide();
	$('#ampliar').click(function() {
		if ($('#mapa_info').is(':visible')) {
			$('#mapa_info').fadeOut(450);
		}
		if ($('#mapa_itinerario').is(':visible')) {
			$('#mapa_itinerario').fadeOut(450);
		}
		if ($('#mapa_vista3d').is(':visible')) {
			$('#mapa_vista3d').fadeOut(450);
		}
		if ($('#mapa_ampliar').is(':visible')) {
			$('#mapa_ampliar').fadeOut(450);
			$('#mapa_cover').fadeOut(450);
		} else {
			$('#mapa_ampliar').fadeIn(450);
			$('#mapa_cover').fadeIn(450);
		};
		return false;
	});
	$('#mapa_ampliar p:first a').click(function() {
	$('#mapa_ampliar').fadeOut(450);
	$('#mapa_cover').fadeOut(450);
		return false;
	});
};
*/
/*
function desplegarItinerarioEmpresas() {
	//$('#mapa_itinerario').hide();
	$('#itinerario').click(function() {
		if ($('#mapa_info').is(':visible')) {
			$('#mapa_info').fadeOut(450);
		}
		if ($('#mapa_ampliar').is(':visible')) {
			$('#mapa_ampliar').fadeOut(450);
		}
		if ($('#mapa_vista3d').is(':visible')) {
			$('#mapa_vista3d').fadeOut(450);
		}
		if ($('#mapa_itinerario').is(':visible')) {
			$('#mapa_itinerario').fadeOut(450);
			$('#mapa_cover').fadeOut(450);
		} else {
		$('#mapa_itinerario').fadeIn(450);
		$('#mapa_cover').fadeIn(450);
		};
		return false;
	});
	$('#mapa_itinerario p:first a').click(function() {
	$('#mapa_itinerario').fadeOut(450);
	$('#mapa_cover').fadeOut(450);
		return false;
	});
};
*/
/*
function desplegarVista3dEmpresas() {
	//$('#mapa_vista3d').hide();
	$('#vista3d').click(function() {
		if ($('#mapa_info').is(':visible')) {
			$('#mapa_info').fadeOut(450);
		}
		if ($('#mapa_ampliar').is(':visible')) {
			$('#mapa_ampliar').fadeOut(450);
		}
		if ($('#mapa_itinerario').is(':visible')) {
			$('#mapa_itinerario').fadeOut(450);
		}
		if ($('#mapa_vista3d').is(':visible')) {
			$('#mapa_vista3d').fadeOut(450);
			$('#mapa_cover').fadeOut(450);
		} else {
		$('#mapa_vista3d').fadeIn(450);
		$('#mapa_cover').fadeIn(450);
		};
		return false;
	});
	$('#mapa_vista3d p:first a').click(function() {
	$('#mapa_vista3d').fadeOut(450);
	$('#mapa_cover').fadeOut(450);
		return false;
	});
};
*/
function opacidad() {
	$('.sideright .botones input, .sideright .botones img, .galeria img').hover(
      function() {
      	$(this).fadeTo("fast", 0.7);
      },
      function() {
      	$(this).fadeTo("fast", 1.0);
      }
    );
};
function desplegarActvidades() {
	var tabContainers = $('.carga');
	//tabContainers.hide();
	$('.enlace a[href*=#], .botones > a[href*=#],').click(function() {
		$('.enlace a[href*=#]').removeClass('resalte')
		if ($(this.hash).is(':visible')) {
			tabContainers.filter(this.hash).slideToggle(400);

		}
		else {
			tabContainers.slideUp(200);
			$(this).show("normal", function() {
				$(this.hash).slideDown(400);
			});
			$(this).toggleClass('resalte');
		}
		var varOffset = $(this).offset();
		var varCargaOffset = $(this.hash).offset();
		var nuevaPos = (varOffset.left + ($(this).width() / 2) - 9 - varCargaOffset.left);
		$('.pestana').css('left',nuevaPos + 'px');

		return false;
	});

	$('.pestana a[href*=#],').click(function() {
		$('.enlace a[href*=#]').removeClass('resalte')
		if ($(this.hash).is(':visible')) {
			tabContainers.filter(this.hash).slideToggle(400);
		}
		else {
			tabContainers.slideUp(200);
			$(this).show("normal", function() {
				$(this.hash).slideDown(400);
			});
			$(this).toggleClass('resalte');
		}
		return false;
	});
	$('.contenedor_mg .enlace a[href*=#fotomapa]').click();
};
$(document).ready(function() {

    //try {
        desplegarLi();
        desplegarTab();
        //desplegarMapa();
        //	desplegarCupones();
        desplagarNext();
        desplegarContactoEmpresas();
        opacidad();
        //desplegarmapaEmpresas();
        //desplegarAmpliarEmpresas();
        //desplegarItinerarioEmpresas();
        //desplegarVista3dEmpresas();
        desplegarActvidades();

        if (document.getElementById('TabMenu') != null) {
            DoTabSelection();
        }

        /* This is a select visual bug correction for IE6 */
        if (jQuery.browser.msie == true && jQuery.browser.version < 7) {
            $(".thickbox").click(function() {
                $("select").css({ visibility: "hidden" });
            });
            if ($("#TB_window") !== true)
                $("select").css({ visibility: "visible" });
        }

    //} catch (err) { alert('error:' + err.description) };

});

function muestraSelects() {
	$("select").css({visibility:"visible"});
}