$(document).ready(function()
{
	 
});


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function ventana(URL,nombre,ancho,alto) {
	x = (screen.width - ancho)/2
	y = (screen.height - alto)/2
	eval("page = window.open(URL, nombre, 'toolbar=0,scrollbars=no,location=0,statusbar=0,menubar=0,resizable=1,width="+ancho+",height="+alto+",left=" + x + ",top = " + y + "');");
}

function NuevoAjax(){
        var xmlhttp=false;
        try{
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
                try{
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }catch(E){
                        xmlhttp = false;
                }
        }

        if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
                xmlhttp = new XMLHttpRequest();
        }
        return xmlhttp;
}

function getAjax (url, div){
        var contenedor = document.getElementById(div);
        ajax=NuevoAjax(); 
        //peticionamos los datos, le damos la url enviada desde el link
        ajax.open("GET", url, true); 
		ajax.onreadystatechange=function(){
                if(ajax.readyState==1){

            contenedor.innerHTML = "<div align='center'style='float: right; width: 225px; margin: 60px 0;'><img src='images/loading.gif' width='30' height='30' /><br />Cargando...</div>";

            }else if(ajax.readyState==4){
                        if(ajax.status==200){
                                //mostramos los datos dentro del contenedor
                                contenedor.innerHTML = ajax.responseText
								agregar_accion();
                        }else if(ajax.status==404){
                                contenedor.innerHTML = "La página no existe";
                        }else{
                                //mostramos el posible error
                                contenedor.innerHTML = "Error:".ajax.status; 
                        }
                }
        }
        ajax.send(null);
}

function agregar_accion(){
	$("a.zoom").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0, 
		'overlayShow':	true
	});	
}


function paginado_ajax (formulario,div) {
	
	var div =  $("#" + formulario + " input[name=ajax_div]").val();
	var pagina = parseInt($("#" + formulario + " input[name=ajax_pagina]").val());
	var ultima = $("#" + formulario + " input[name=ajax_ultpagina]").val();
	
	var ajaxFormOptions = { 
			target:        div/*,
			beforeSubmit:  showRequest,
			success:       showResponse*/
	}; 

	$("#" + formulario).ajaxForm( ajaxFormOptions );

	$("#" + formulario + " .ajax_orden").unbind().click(function(e) {
		$("#" + formulario + " input[name=ajax_orden]").val($(this).val());
		$("#" + formulario).submit();
	});	

	$("#" + formulario + " .ajax_tipoorden").unbind().click(function(e) {
		$("#" + formulario + " input[name=ajax_tipoorden]").val($(this).val());
		$("#" + formulario).submit();
	});	
	
	$("#" + formulario + " .ajax_termino").unbind().click(function(e) {
		$("#" + formulario + " input[name=ajax_termino]").val($(this).val());
		$("#" + formulario).submit();
	});	
	
	
	$("#" + formulario + " .ajaxpag_pri").unbind().click(function(e) {
		$("#" + formulario + " input[name=ajax_pagina]").val("1");
		$("#" + formulario).submit();
	});
	
	$("#" + formulario + " .ajaxpag_ant").unbind().click(function(e) {
		$("#" + formulario + " input[name=ajax_pagina]").val(pagina-1);
		$("#" + formulario).submit();
	});
	
	$("#" + formulario + " .ajaxpag_sig").unbind().click(function(e) {
		$("#" + formulario + " input[name=ajax_pagina]").val(pagina+1);
		$("#" + formulario).submit();
	});
	
	$("#" + formulario + " .ajaxpag_ult").unbind().click(function(e) {
		$("#" + formulario + " input[name=ajax_pagina]").val(ultima);
		$("#" + formulario).submit();
	});
	
	$("#" + formulario + " .ajaxselect_pagina").unbind().change(function(e) {
		$("#" + formulario + " input[name=ajax_pagina]").val($(this).val());
		$("#" + formulario).submit();
	});

}



function dame_calendario(){
	$.ajax({
		url: "bloque_calendario.asp",
		type: 'POST',
		dataType: 'text',
		error: function(){
			return false;
		},
		success: function(data){
			$("#calendario").html(data);
			$("#hoy a").attr("style","background-color:none;");
			$('.eventocal').each(function(){
				$(this).qtip(
				{
					 content: $(this).siblings("span").html(),
					 position: {
							corner: {
									 tooltip: 'bottomMiddle',
									 target: 'topMiddle'
							}
					 },
					 hide: {
							fixed: true
					 },
					 style: {
							name: 'cream',
							border: {
								 width: 0, 
								 radius: 4 
							}, 
							tip: true
					 }
				});
			});
			 
			$("#leyenda").qtip({
				 content: $(this).attr("title"),
				 position: {
						corner: {
							 tooltip: 'topRight',
							 target: 'bottomMiddle'
						}
				 },
				 hide: {
						fixed: true
				 },
				 style: {
						name: 'cream',
						border: {
							 width: 0, 
							 radius: 4 
						}, 
						tip: true
				 }
			});

		}
	});	
}
function cambia_calendario(fecha){
	
	$.ajax({
		url: "bloque_calendario.asp?date="+ fecha,
		type: 'POST',
		dataType: 'text',
		error: function(){
			return false;
		},
		success: function(data){
		
			$("#calendario").html(data);
			 $('.eventocal').each(function()
			 {
					$(this).qtip(
					{
						 content: $(this).siblings("span").html(),
						 position: {
								corner: {
									 tooltip: 'bottomMiddle',
									 target: 'topMiddle'
								}
						 },
						 hide: {
								fixed: true
						 },
						 style: {
								name: 'cream',
								border: {
									 width: 0, 
									 radius: 4 
								}, 
								tip: true
						 }
					});
	
			 });

				$("#leyenda").qtip(
				{
					 content: $(this).attr("title"),
					 position: {
							corner: {
							 tooltip: 'topRight',
							 target: 'bottomMiddle'
							}
					 },
					 hide: {
							fixed: true
					 },
					 style: {
							name: 'cream',
							border: {
								 width: 0, 
								 radius: 4 
							}, 
							tip: true
					 }
				});

		}
	});	
}

function clicable (selector, blank){ // Hace clicable un elemento contenedor de un enlace
	$(selector).each(function(){
		if ($(this).find("a").length == 1){
			$(this).css('cursor','pointer');
			$(this).unbind();		
			$(this).click(function(){
				if(blank){
					href=$(this).find("a").attr("href");
					var ventana = window.open(href);
					ventana.focus();
				} else {
					window.location=$(this).find("a").attr("href");
				}
				return false;
			});
		}
	});
}
