jQuery.noConflict();
var miFecha = new Date();
var mesActual = miFecha.getMonth()+1;

// Apenas termina de cargar la pagina ******************************************************************************************************
jQuery(document).ready(function(){
  // Para darle el enfoque a la caja de login -----------------------------------------------------------
	if(jQuery("#buscar_txt").length > 0) {
		jQuery("#buscar_txt").focus();
	}
  // Para el efecto CARRUSEL de las noticias ------------------------------------------------------------
  	if(jQuery("#cont_noticias_carrusel").length > 0) {
  		jQuery("#cont_noticias_carrusel").bxSlider({
			alignment: "horizontal",
			infiniteLoop: true,
			pause: 5000,
			auto: true,
			auto_direction: "next",
			auto_hover: false,
			auto_controls: true,
			controls: false,
			pager: true,
			start_text: 'Iniciar',
			stop_text: 'Parar',
			speed: 300,
			wrapper_class: "cont_noticias"
		});
		//ancho = jQuery(".cont_noticias .bxslider_container").width()-164; //164
		//jQuery(".cont_noticias #cont_noticias_carrusel .item .descripcion").css({'width':ancho});
	}
  // Para el efecto CARRUSEL de los eventos ------------------------------------------------------------
  	if(jQuery("#cont_eventos_carrusel").length > 0) {
  		jQuery("#cont_eventos_carrusel").bxSlider({
			alignment: "horizontal",
			pause: 5000,
			auto: true,
			auto_direction: "prev",
			auto_hover: false,
			auto_controls: true,
			controls: false,
			pager: true,
			start_text: 'Iniciar',
			stop_text: 'Parar',
			speed: 300,
			wrapper_class: "cont_eventos"
		});
		//ancho = jQuery(".cont_eventos .bxslider_container").width()-164; //164
		//jQuery(".cont_eventos #cont_eventos_carrusel .item .descripcion").css({'width':ancho});
	}
  // Para el efecto CARRUSEL de las obras ------------------------------------------------------------
  	if(jQuery("#cont_obras_carrusel").length > 0) {
		jQuery('#cont_obras_carrusel').infiniteCarousel({
			transitionSpeed: 1200,
			displayTime: 6000,
			inView:1,
			advance:1,
			imagePath: '../img/carrusel/',
			easeLeft: 'easeOutElastic',
			easeRight:'easeOutQuart',
			textholderHeight : .25,
			padding:'0px',
			autoHideCaptions: true,
			prevNextInternal: true 
		});
	}
  // Para el efecto CARRUSEL de: biblioteca, grifo, parque, terminal collasuyo ------------------------
  	if(jQuery("#cont_interior").length > 0) {
		jQuery('#cont_interior').infiniteCarousel({	
			transitionSpeed: 1200,
			displayTime: 6000,
			inView:1,
			advance:1,
			imagePath: '../img/carrusel/',
			textholderHeight : .06,
			padding:'0px',
			autoHideCaptions: false,
			prevNextInternal: false,
			displayThumbnails:false,
			enableKeyboardNav:false
		});
	}
  // Para el thumbnail del detalle de una obra --------------------------------------------------------
  	if(jQuery("#cont_img_antes").length > 0) { // Imagenes antes de iniciar la obra
		jQuery(".img_antes_peque").hover(
			function(){
				elemento = jQuery(this);
				id_thumb = elemento.attr('id').split('_')[1];
				jQuery(".img_antes_peque").each(function(i){
					id_img = jQuery(this).attr('id').split('_')[1];
					if(id_thumb==id_img){ jQuery('#img_antes_'+id_img).show(); }
					else{ jQuery('#img_antes_'+id_img).hide(); }
					if(elemento.attr('id')==jQuery(this).attr('id')){
						jQuery(this).children("a").children(".img_peque").addClass("img_peque_hover");
					}else{
						jQuery(this).children("a").children(".img_peque").removeClass("img_peque_hover");
					}
				});
			},
			function(){ }
		);
	}
	if(jQuery("#cont_img_durante").length > 0) { // Imagenes en plena obra
		jQuery(".img_durante_peque").hover(
			function(){
				elemento = jQuery(this);
				id_thumb = elemento.attr('id').split('_')[1];
				jQuery(".img_durante_peque").each(function(i){
					id_img = jQuery(this).attr('id').split('_')[1];
					if(id_thumb==id_img){ jQuery('#img_durante_'+id_img).show(); }
					else{ jQuery('#img_durante_'+id_img).hide(); }
					if(elemento.attr('id')==jQuery(this).attr('id')){
						jQuery(this).children("a").children(".img_peque").addClass("img_peque_hover");
					}else{
						jQuery(this).children("a").children(".img_peque").removeClass("img_peque_hover");
					}
				});
			},
			function(){ }
		);
	}
	if(jQuery("#cont_img_despues").length > 0) { // Imagenes culminada la obra
		jQuery(".img_despues_peque").hover(
			function(){
				elemento = jQuery(this);
				id_thumb = elemento.attr('id').split('_')[1];
				jQuery(".img_despues_peque").each(function(i){
					id_img = jQuery(this).attr('id').split('_')[1];
					if(id_thumb==id_img){ jQuery('#img_despues_'+id_img).show(); }
					else{ jQuery('#img_despues_'+id_img).hide(); }
					if(elemento.attr('id')==jQuery(this).attr('id')){
						jQuery(this).children("a").children(".img_peque").addClass("img_peque_hover");
					}else{
						jQuery(this).children("a").children(".img_peque").removeClass("img_peque_hover");
					}
				});
			},
			function(){ }
		);
	}
  // Para el cambio de color de fondo de la seccion enlaces ------------------------------------------
	if(jQuery(".interior_modulo_contenido .cont_submenu .submenu .enlaces").length > 0) {
		var obj_li = jQuery('.interior_modulo_contenido .cont_submenu .submenu .enlaces li');
		obj_li.click(function(){ 
			var obj_a = jQuery(this).children("a");
			if(obj_a.length > 0) {
				href = obj_a.attr("href");
				document.location.href = href;
			}
		});
		obj_li.hover(
			function(){ 
				if(jQuery(this).hasClass('enlace_activo')==false){
					jQuery(this).addClass('enlace_sobre'); 
				}
			},
			function(){
				if(jQuery(this).hasClass('enlace_activo')==false){
					jQuery(this).removeClass('enlace_sobre');
				}
			}
		);
	}
  // Para el cambio de color de fondo de la seccion videos ------------------------------------------
	if(jQuery(".interior_modulo_contenido .cont_videos .videos .listado").length > 0) {
		var obj_li = jQuery('.interior_modulo_contenido .cont_videos .videos .listado li');
		obj_li.click(function(){ 
			var obj_a = jQuery(this).children("a");
			if(obj_a.length > 0) {
				href = obj_a.attr("href");
				gal_videos_det.document.location.href = href;
			}
			jQuery('.interior_modulo_contenido .cont_videos .videos .listado li').each(function(i){
				jQuery(this).removeClass("enlace_video_activo");
				jQuery(this).removeClass("enlace_video_sobre");
			});
			jQuery(this).addClass('enlace_video_activo');
		});
		obj_li.hover(
			function(){ 
				if(jQuery(this).hasClass('enlace_video_activo')==false){
					jQuery(this).addClass('enlace_video_sobre'); 
				}
			},
			function(){
				if(jQuery(this).hasClass('enlace_video_activo')==false){
					jQuery(this).removeClass('enlace_video_sobre');
				}
			}
		);
	}
  // Para el cambio de color de fondo de los listados ------------------------------------------------
	if(jQuery(".cont_listado_tabla").length > 0) {
		jQuery('.cont_listado_tabla').tableHover({rowClass:'sobre', clickClass:'elegido'});
	}
  // Para el cambio de borde de las imagenes del detalle ---------------------------------------------
	if(jQuery(".cont_detalle_img").length > 0) {
		var obj_img = jQuery('.cont_detalle_img img.img_peque');
		obj_img.hover(
			function(){ jQuery(this).addClass('img_peque_hover'); },
			function(){ jQuery(this).removeClass('img_peque_hover'); }
		);
	}
  // Para el cambio de borde de las imagenes de la galeria -------------------------------------------
	if(jQuery(".cont_detalle_gal").length > 0) {
		var obj_img = jQuery('.cont_detalle_gal img.img_peque');
		obj_img.hover(
			function(){ jQuery(this).addClass('img_peque_hover'); },
			function(){ jQuery(this).removeClass('img_peque_hover'); }
		);
	}
});

// Para enviar el FORMULARIO DE ENCUESTA
function fncEnviarEncuesta(frm,obj){
	var marcado = false;
	jQuery("#"+frm.id+" input:radio").each(function() {
		if ( jQuery(this).is(':checked') ) {
			marcado = true;
		}
	});
	if(marcado==true){
		if(confirm("Esta seguro de su respuesta?")){
			jQuery.ajax({type: "POST",
				url: frm.action,
				data: jQuery("#"+frm.id).serialize(),
				dataType: "html",
				success: function(datos){
					if(datos=="bien"){
						alert("Su encuesta fue registrada con exito.");
					}else{
						if(datos=="voto"){
							msg = "Usted ya realizo esta encuesta.";
						}else{
							msg = "Ocurrio un error en el registro de su votacion";	
						}
						alert(msg);
						frm.reset();
					}
				},
				error: function(XMLHttpRequest, textStatus, errorThrown){
					alert ("error: "+textStatus);
				}
			});
		}
	}else{
		alert("Elija una respuesta para continuar");
	}
}

// validar formulario de contacto ***************************************************************************
function fncValidarContacto(frm){
	var nombre = trim(frm.nombre.value);
	var email = trim(frm.email.value);
	var asunto = trim(frm.asunto.value);
	var mensaje = trim(frm.mensaje.value);
	var codseguridad = trim(frm.codseguridad.value);
	var msg = "OCURRIERON LOS SIGUIENTES ERRORES:\n\n";
	if(nombre==""){ alert(msg+="- No ingreso su NOMBRE."); frm.nombre.value=''; frm.nombre.focus(); return false; }
	if(email==""){ alert(msg+="- No ingreso su EMAIL."); frm.email.value=''; frm.email.focus(); return false; }
	else{
		if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)==false){
			alert(msg+="- El CORREO ELECTRONICO no es correcto.");
			frm.email.value=""; frm.email.focus(); return false;
		}	
	}
	if(asunto==""){ alert(msg+="- No eligio el ASUNTO."); frm.asunto.focus(); return false; }
	if(mensaje==""){ alert(msg+="- No ingreso el COMENTARIO."); frm.mensaje.value=''; frm.mensaje.focus(); return false; }
	if(codseguridad==""){ alert(msg+="- No ingreso el CODIGO DE SEGURIDAD."); frm.codseguridad.value=''; frm.codseguridad.focus(); return false; }
	else{
		jQuery.ajax({type: "POST",
			url: "../web/contacto_captcha_validar.php",
			data: "codseguridad="+codseguridad,
			dataType: "html",
			success: function(datos){
				if(datos=="si"){
					if(confirm("Esta seguro de los datos a enviar?")){ frm.submit(); }
				}else{ alert(msg+="- El codigo de seguridad ingresado es incorrecto."); frm.codseguridad.select(); return false; }
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				alert ("error: "+textStatus);
			}
		});	
	}
	return false;
}
// Para enviar el contacto
function fncEnviarMensaje(frm){
	jQuery('#objCargador').show("slow");
	jQuery.ajax({type: "POST",
		url: frm.action,
		data: jQuery("#"+frm.name).serialize(),
		dataType: "html",
		success: function(datos){
			jQuery('#objCargador').hide("slow");
			alert(datos);
			id_producto = trim(frm.id_producto.value);
			document.location.href = "producto.php?id="+id_producto;
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			alert ("error: "+textStatus);
		}
	});
}

// Para cambiar el CSS de un objeto *************************************************************************
function color(el,tt){
    if(jQuery(el).hasClass('tabla_texto_3')==true){
        jQuery(el).removeClass(); jQuery(el).addClass('tabla_texto_');
    }else{
        jQuery(el).removeClass(); jQuery(el).addClass('tabla_texto_3');
    }
}

// Para validar el formulario de busqueda *******************************************************************
function fncValidarBuscar(frm){
	var busc_criterio = trim(frm.busc_criterio.value);
	var msg = "OCURRIERON LOS SIGUIENTES ERRORES:\n\n";
	if(busc_criterio==""){ alert(msg+="- No ingreso el CRITERIO DE BUSQUEDA."); frm.busc_criterio.value=''; frm.busc_criterio.focus(); return false; }
	return true;
}

// Para cargar Pagina **************************************************************************************
function cargarPagina(url,params,objDiv){ //_objDiv -> Id del objeto
	jQuery(objDiv).innerHTML = "<div style='padding-top:20px;'><img src='../img/loading.gif' border='0' /></div>";
	jQuery.ajax({type: "POST",
		url: url,
		data: params, //jQuery("#frm_prueba").serialize(),
		dataType: "html",
		success: function(datos){
			jQuery(objDiv).hide().html(datos).fadeIn("slow");
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			alert ("error: "+textStatus);
		}
	});
}
function fncCargarPaginaAgenda(url,params,mes,objDiv){
	jQuery(objDiv).innerHTML = "<div style='padding-top:20px;'><img src='../img/loading.gif' border='0' /></div>";
	jQuery.ajax({type: "POST",
		url: url,
		data: params, //jQuery("#frm_prueba").serialize(),
		dataType: "html",
		success: function(datos){
			jQuery(objDiv).hide().html(datos).fadeIn("slow");
			if(mes!=mesActual){
				mesActual=mes;
				fncCargarMesesAgenda('tresCalendarios.php',params,'#cont_calendarios');
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			alert ("error: "+textStatus);
		}
	});
}
function fncCargarMesesAgenda(url,params,objDiv){ //_objDiv -> Id del objeto
	jQuery(objDiv).innerHTML = "<div style='padding-top:20px;'><img src='../img/loading.gif' border='0' /></div>";
	jQuery.ajax({type: "POST",
		url: url,
		data: params, //jQuery("#frm_prueba").serialize(),
		dataType: "html",
		success: function(datos){
			jQuery(objDiv).hide().html(datos).fadeIn("slow");
			cargarPagina("nombre_mes.php",params,'#cont_mes_actual');
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			alert ("error: "+textStatus);
		}
	});
}
