<!--
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_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_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];}
}
//-->

// ******************************************************************************** //

var over = false;

var constanteNumerica;

var rutaControladorContacto = "/site/Portals/0/Scripts/plugin_share/ControladorContacto.ashx";

function fn_onLoad()
{
	$("tr#trFilaResultado").hide();
} // Fin de la función fn_onLoad.

function fn_btnMouseOver() {
    over = true;
    
    window.clearInterval(constanteNumerica);
    
    $("div#divCompartir").fadeIn();
}

function fn_btnMouseOut() {
    over = false;
    
    //alert("fn_btnMouseOut");
    
    constanteNumerica = self.setInterval("fn_validarFadeOut()", 2);
    //fn_validarFadeOut();
}

function fn_divMouseOver() {
    over = true;
    
    window.clearInterval(constanteNumerica);
    
    $("div#divCompartir").fadeIn();
}

function fn_divMouseOut() {
    over = false;
    
    //alert("fn_divMouseOut");
    
    constanteNumerica = self.setInterval("fn_validarFadeOut()", 2);
    //fn_validarFadeOut();
}

function fn_validarFadeOut() {
    //alert("fn_validarFadeOut");
    
    window.clearInterval(constanteNumerica);
    
    //alert("fn_validarFadeOut" + "." + "over" + " = " + over);
    
    if (over) {
        return;
    }
    else {
        //alert($("div#divCompartir"));

        //$("div#divCompartir").fadeOut();
        $("div#divCompartir").hide();
    }
} // Fin de la función fn_validarFadeOut.

function fn_SharePrint() {
    window.print();
} // Fin de la función fn_SharePrint.

function fn_enviarDatos() {
    var para = $("textarea#taDestinatarios").val();
    var de = $("input#txtCorreoRemitente").val();
    var nota = $("textarea#taNota").val();

    var hayErrores = false;

    var mensajeValidacion = "Por favor verifique:" + "<br />";

    if (para == null || para == "" || para == undefined) {
        hayErrores = true;
        mensajeValidacion += "<br />" + "&nbsp;" + "- Debe indicar el destinatario.";
    } // Fin del if.
    else {
        if (para.indexOf(",") != -1) {
            var listaDestinatarios = para.split(",");

            var i = 0;

            var hayUnDestinatarioMalo = false;

            var correoActual = "";

            for (i = 0; i < listaDestinatarios.length; i++) {
                correoActual = listaDestinatarios[i];

                if (!fn_correoElectronicoEsValido(correoActual)) {
                    hayUnDestinatarioMalo = true;
                    break;
                } // Fin del if.
            } // Fin del for.

            if (hayUnDestinatarioMalo) {
                hayErrores = true;
                mensajeValidacion += "<br />" + "&nbsp;" + "- Debe indicar correctamente todos los destinatarios.";
            } // Fin del if.
        } // Fin del if.
		else
		{
			if(!fn_correoElectronicoEsValido(para))
			{
				hayErrores = true;
				mensajeValidacion += "<br />" + "&nbsp;" + "- Debe indicar correctamente el destinatario.";
			} // Fin del if.
		} // Fin del else.
    } // Fin del else.

    if (de == null || de == "" || de == undefined) {
        hayErrores = true;
        mensajeValidacion += "<br />" + "&nbsp;" + "- Debe indicar el remitente.";
    } // Fin del if.
    else {
        if (!fn_correoElectronicoEsValido(de)) {
            hayErrores = true;
            mensajeValidacion += "<br />" + "&nbsp;" + "- Debe indicar correctamente el remitente.";
        } // Fin del if.
    } // Fin del else.

    if (nota == null || nota == "" || nota == undefined) {
        nota = "No hay comentarios asociados.";
    } // Fin del if.

    if (hayErrores) {
        $("p#lblMensajesValidacion").html(mensajeValidacion);

        $("tr#trFilaValidacion").fadeIn();

        return;
    } // Fin del if.
    else {
        var variables = "";
        variables += "accion" + "=" + "contactar";
        variables += "&";
        variables += "para" + "=" + para;
        variables += "&";
        variables += "de" + "=" + de;
        variables += "&";
        variables += "nota" + "=" + nota;

        var href = encodeURIComponent(window.location.href);

        variables += "&";
        variables += "href" + "=" + href;
		
		$("tr#trFilaPrecarga").fadeIn();
		
        $.ajax
        (
            {
                type: "POST",
                url: rutaControladorContacto,
                data: variables,
                success: function(xmlResultado) {
                    $(xmlResultado).find("mensaje").each
                    (
                        function() {
                            var ds = $(this).attr("ds");
                            //alert("ds" + " = " + ds);
							
							$("tr#trFilaPrecarga").fadeOut();
							
                            if (ds == "OK") {
                                //alert("Tu mensaje ha sido enviado exitosamente.");
								
								$("tr#trFilaResultado").fadeIn();
								$("label#lblResultado").html("Tu mensaje ha sido enviado exitosamente.");
                                
                                fn_limpiarCampos();
                            } // Fin del if.
                            else {
                                //alert(ds);
								
								$("tr#trFilaResultado").fadeIn();
								$("label#lblResultado").html(ds);
                            } // Fin del else.
                        }
                    );
                }
            }
        );
    } // Fin del else.
} // Fin de la función fn_enviarDatos.

function fn_limpiarCampos() {
    $("textarea#taDestinatarios").val("");
    $("input#txtCorreoRemitente").val("");
    $("textarea#taNota").val("");
} // Fin de la función fn_limpiarCampos.

function fn_fadeOutValidacion() {
    $("tr#trFilaValidacion").fadeOut();
} // Fin de la función fn_fadeOutValidacion.

function fn_cambiarColorFondo(id, color) {
    document.getElementById(id).style.background = color;
} // Fin de la función fn_cambiarColorFondo.

$(document).ready
(
    function() {
        // Select all the a tag with name equal to modal
        $('a[name=modal]').click
        (
            function(e) {
                // Cancel the link behavior
                e.preventDefault();
                
                // Get the A tag
                var id = $(this).attr('href');
                
                // Get the screen height and width
                var maskHeight = $(document).height();
                var maskWidth = $(window).width();
                
                // Set heigth and width to mask to fill up the whole screen
                $('#divMascara').css({ 'width': maskWidth, 'height': maskHeight });
                
                // Transition effect
                $('#divMascara').fadeIn(1000);
                $('#divMascara').fadeTo("slow", 0.8);
                
                // Get the window height and width
                var winH = $(window).height();
                var winW = $(window).width();
                
                // Set the popup window to center
                $(id).css('top', winH / 2 - $(id).height() / 2);
                $(id).css('left', winW / 2 - $(id).width() / 2);
                
                // Transition effect
                //$(id).fadeIn(2);
                $(id).fadeIn();
            }
        );
        
        // If close button is clicked
        $(".window .close").click
        (
            function(e) {
                // Cancel the link behavior
                e.preventDefault();
                
                $('#divMascara').hide();
                $('.window').hide();
            }
        );
        
        // If close button is clicked
        $("input#btnCancelar").click
        (
            function(e) {
                // Cancel the link behavior
                e.preventDefault();
                
                $('#divMascara').hide();
                $('.window').hide();
            }
        );
        
        // If mask is clicked
        $('#divMascara').click
        (
            function() {
                $(this).hide();
                $('.window').hide();
            }
        );
    }
);

function fn_ShareFacebook() {
    var href = encodeURIComponent(window.location.href + "?" + new Date().getTime());
    //var href = encodeURIComponent("http://www.google.com/");
    
    var titulo = encodeURIComponent(document.title);
    //alert("titulo" + " = " + titulo);
    
    var direccionShare = "http://www.facebook.com/sharer.php?u=" + href + "&" + "t" + "=" + titulo;
    
    window.open(direccionShare);
} // Fin de la función fn_ShareFacebook.

function fn_ShareTwitter() {
    var href = encodeURIComponent(window.location.href);
    //var href = encodeURIComponent("http://www.google.com/");
    
    var titulo = encodeURIComponent(document.title);
    //alert("titulo" + " = " + titulo);
    
    var direccionShare = "http://twitter.com/share?url=" + href + "&" + "text" + "=" + titulo;
	
	window.open(direccionShare);
} // Fin de la función fn_ShareTwitter.

function fn_ShareLinkedIn() {
    var href = encodeURIComponent(window.location.href);
    //var href = encodeURIComponent("http://www.google.com/");
    
    var titulo = encodeURIComponent(document.title);
    //alert("titulo" + " = " + titulo);
    
    var direccionShare = "http://www.linkedin.com/shareArticle" + "?" + "mini" + "=" + "true" + "&" + "url" + "=" + href + "&" + "title" + "=" + titulo;
    
    window.open(direccionShare);
} // Fin de la función fn_ShareLinkedIn.

// ******************************************************************************** //
