﻿function ShowRectagle()
{	                        
    $('AnunciosClub').style.height = document.documentElement.scrollHeight+'px';	                        
    $('AnunciosClub').style.display='block';       
    $('MessageArea').style.left=document.documentElement.clientWidth/2 +'px';    
    $('MessageArea').style.display='block';
}
function HideRectagle()
{
    $('AnunciosClub').style.display='none';
    $('MessageArea').style.display='none';		                
}

function ShowBankRectagle()
{	                        
    $('AnunciosBankWarning').style.height = document.documentElement.scrollHeight+'px';	                        
    $('AnunciosBankWarning').style.display='block';       
    $('MessageBankArea').style.left=document.documentElement.clientWidth/2 +'px';    
    $('MessageBankArea').style.display='block';
    window.setTimeout(CountDown, 1000);
}

function ShowUserLoginRectagle()
{	                        
    $('NoSusNumber').style.height = document.documentElement.scrollHeight+'px';	                        
    $('NoSusNumber').style.display='block';       
    $('NoSusNumberArea').style.left=document.documentElement.clientWidth/2 +'px';    
    $('NoSusNumberArea').style.display='block';
    window.setTimeout(CountDown, 1000);
}



// Función de abrir nueva ventana para imprimir
function OpenPrintWindow(intArticleUseID) {
    NewWindow = window.open("/servicios/imprimir/" + intArticleUseID, "Printing" + intArticleUseID, "height=640,width=600,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=no,top=0,left=0", false);
    if (NewWindow == null)
        alert("Un bloqueador de pop-ups está impidiendo que se abra la ventana que gestiona la impresión del articulo. Si desea imprimir este artículo, deshabilite esta utilidad al menos momentaneamente para este sitio");
}

// Ajax


function GetXMLHttpRequest() {
    if (window.XMLHttpRequest)
        return new XMLHttpRequest();
    else if (window.ActiveXObject)
        return new ActiveXObject("Microsoft.XMLHTTP");
}

function Prepare(str) {
    str = str.replace(/</g, "&lt;");
    str = str.replace(/>/g, "&gt;");
    str = str.replace(/&/g, "&amp;");
    return str;
}


// Efectos

function SetOpacity(LayerID, Opacity) {
    $(LayerID).style.filter = 'alpha(opacity=' + Opacity + ')';
    $(LayerID).style.opacity = Opacity / 10;
    $(LayerID).style.opacity = Opacity / 10;
    //$(LayerID).style.-moz-opacity = Opacity / 10;
    //$(LayerID).style.-khtml-opacity = Opacity / 10;
}


function ShowDisableler(DisabelerID, FrontLayerID) {
    $(DisabelerID).style.height = document.documentElement.scrollHeight + 'px';
    $(DisabelerID).style.display = 'block';
    ShowLayer(FrontLayerID);
}

function ShowLayer(LayerID) {
    $(LayerID).style.left = document.documentElement.clientWidth / 2 + 'px';
    $(LayerID).style.display = 'block';
}

function HideLayer(LayerID) {
    $(LayerID).style.display = 'none';
}


function HideDisableler(DisalbelerID, FrontLayerID) {
    HideLayer(DisalbelerID);
    HideLayer(FrontLayerID);
}


// Check del formulario por email

function CheckArticleEmailSending() {
    FromEmail = $F('SenderEmailAddress');
    FromName = $F('SenderName');
    ToEmailArray = $F('DestinationEmailAddress');
    Comments = $F('SenderComments');
    ToEmailArray = ToEmailArray.replace(/\s/g, "");
    ToEmailArray = ToEmailArray.replace(/;/g, ",");
    ToEmail = ToEmailArray.split(",");

    Filter4Email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

    if (!Filter4Email.test(FromEmail)) {
        alert("Su dirección de correo electrónico no es valida. Por favor, revísela.");
        $('SenderEmailAddress').focus();
        return false;
    }

    if (FromName.replace(/ /g, ",").length == 0) {
        alert("Por favor, indique su nombre.");
        $('SenderName').focus();
        return false;
    }

    if (ToEmail.length > 5) {
        alert("No se permiten más de 5 envíos simultaneos. Por favor, elimine direcciones de destino.");
        $('DestinationEmailAddress').focus();
        return false;

    }

    for (n = 0; n < ToEmail.length; n++) {
        if (!Filter4Email.test(ToEmail[n])) {
            alert("Al menos una de las direcciones de correo de destino no es válida. Por favor, reviselas.");
            $('DestinationEmailAddress').focus();
            return false;
        }
    }

    if (Comments.length > 1024) {
        alert("Comentario demasiado largo. Por favor, resúmalo.");
        $('SenderComments').focus();
        return false;
    }


    DoSend();


}

// Funciones de módulo de envio de artículo por email

function ShowSendForm() {
    ShowDisableler('SendFormDisabeler', 'SendFormContainer');
    window.scroll(0, 0);
}


function HideSendForm() {
    HideDisableler('SendFormDisabeler', 'SendFormContainer');
}

function DoSend() {
    HideLayer('SendFormContainer');
    ShowLayer('EmailSender');
    // Comienza el baile 

    SendHandle = GetXMLHttpRequest();

    if (SendHandle) {
        var FullURI = "" + window.location;
        var protocol = FullURI.substring(0, FullURI.indexOf("\/\/") + 2);
        FullURI = FullURI.substring(FullURI.indexOf("\/\/") + 2);
        var domain = FullURI.substring(0, FullURI.indexOf("\/"));
        SendHandle.onreadystatechange = ProcessSendFormAnwser;
        SendHandle.open("POST", protocol + domain + "/Users/SendArticle.aspx", true);
        var XmlMessage = GetEmailDocumentData(protocol + domain);
        SendHandle.setRequestHeader("Content-Type", "text/xml");
        SendHandle.send(XmlMessage);
    }
}

function SendDone() {
    HideLayer('EmailSender');
    ShowLayer('EmailSent');
    window.setTimeout(HideAllSendForm, 3000);
}

function HideAllSendForm() {
    HideDisableler('SendFormDisabeler', 'EmailSent');
}

function ErrorSending() {
    HideLayer('EmailSender')
    ShowLayer('EmailErrorSend');
}

function HideError() {
    HideLayer('SendFormDisabeler');
    HideLayer('EmailErrorSend');
}


function GetEmailDocumentData(DomainBase) {
    var xmlContent = "";
    xmlContent += "<Send>";
    xmlContent += "<Sender Name=\"" + Prepare($F('SenderName')) + "\" EmailAddress=\"" + Prepare($F('SenderEmailAddress')) + "\" \/>";
    xmlContent += "<Destination EmailAddress=\"" + Prepare($F('DestinationEmailAddress')) + "\" \/>";
    xmlContent += "<Content>" + Prepare($F('SenderComments')) + "</Content>";
    xmlContent += "<intArticleUseID>" + $F('intArticleUseID') + "</intArticleUseID>";
    xmlContent += "<OriginalHost>" + DomainBase + "</OriginalHost>";
    xmlContent += "<\/Send>";
    return xmlContent;
}

function ProcessSendFormAnwser() {
    var READY_STATE_COMPLETE = 4;
    if (SendHandle.readyState == READY_STATE_COMPLETE) {
        if (SendHandle.status == 200)
            SendDone();
        else
            ErrorSending();

    }

}

// Check del formulario de articulos por email

function CheckNewsEmailSending() {

    FromEmail = $F('SenderEmailAddress');
    FromName = $F('SenderName');
    ToEmailArray = $F('DestinationEmailAddress');
    Comments = $F('SenderComments');
    ToEmailArray = ToEmailArray.replace(/\s/g, "");
    ToEmailArray = ToEmailArray.replace(/;/g, ",");
    ToEmail = ToEmailArray.split(",");

    Filter4Email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

    if (!Filter4Email.test(FromEmail)) {
        alert("Su dirección de correo electrónico no es valida. Por favor, revísela.");
        $('SenderEmailAddress').focus();
        return false;
    }

    if (FromName.replace(/ /g, ",").length == 0) {
        alert("Por favor, indique su nombre.");
        $('SenderName').focus();
        return false;
    }

    if (ToEmail.length > 5) {
        alert("No se permiten más de 5 envíos simultaneos. Por favor, elimine direcciones de destino.");
        $('DestinationEmailAddress').focus();
        return false;

    }

    for (n = 0; n < ToEmail.length; n++) {
        if (!Filter4Email.test(ToEmail[n])) {
            alert("Al menos una de las direcciones de correo de destino no es válida. Por favor, reviselas.");
            $('DestinationEmailAddress').focus();
            return false;
        }
    }

    if (Comments.length > 1024) {
        alert("Comentario demasiado largo. Por favor, resúmalo.");
        $('SenderComments').focus();
        return false;
    }


    DoSendNews();


}


// Funciones de módulo de envio de artículo por email

function ShowSendForm() {
    ShowDisableler('SendFormDisabeler', 'SendFormContainer');
    window.scroll(0, 0);
}


function HideSendForm() {
    HideDisableler('SendFormDisabeler', 'SendFormContainer');
}

function DoSend() {
    HideLayer('SendFormContainer');
    ShowLayer('EmailSender');
    // Comienza el baile 

    SendHandle = GetXMLHttpRequest();

    if (SendHandle) {
        var FullURI = "" + window.location;
        var protocol = FullURI.substring(0, FullURI.indexOf("\/\/") + 2);
        FullURI = FullURI.substring(FullURI.indexOf("\/\/") + 2);
        var domain = FullURI.substring(0, FullURI.indexOf("\/"));
        SendHandle.onreadystatechange = ProcessSendFormAnwser;
        SendHandle.open("POST", protocol + domain + "/Users/SendArticle.aspx", true);
        var XmlMessage = GetEmailDocumentData(protocol + domain);
        SendHandle.setRequestHeader("Content-Type", "text/xml");
        SendHandle.send(XmlMessage);
    }
}

function DoSendNews() {
    HideLayer('SendFormContainer');
    ShowLayer('EmailSender');
    // Comienza el baile 

    SendHandle = GetXMLHttpRequest();

    if (SendHandle) {
        var FullURI = "" + window.location;
        var protocol = FullURI.substring(0, FullURI.indexOf("\/\/") + 2);
        FullURI = FullURI.substring(FullURI.indexOf("\/\/") + 2);
        var domain = FullURI.substring(0, FullURI.indexOf("\/"));
        SendHandle.onreadystatechange = ProcessSendFormAnwserNews;
        SendHandle.open("POST", protocol + domain + "/Users/SendNews.aspx", true);
        var XmlMessage = GetEmailDocumentData(protocol + domain);
        SendHandle.setRequestHeader("Content-Type", "text/xml");
        SendHandle.send(XmlMessage);
    }
}

function SendDone() {
    HideLayer('EmailSender');
    ShowLayer('EmailSent');
    window.setTimeout(HideAllSendForm, 3000);
}

function HideAllSendForm() {
    HideDisableler('SendFormDisabeler', 'EmailSent');
}

function ErrorSending() {
    HideLayer('EmailSender')
    ShowLayer('EmailErrorSend');
}

function HideError() {
    HideLayer('SendFormDisabeler');
    HideLayer('EmailErrorSend');
}

function HideErrorNews() {
    HideLayer('EmailErrorSend');
    ShowLayer('SendFormContainer');
}



function GetEmailDocumentData(DomainBase) {
    var xmlContent = "";
    xmlContent += "<Send>";
    xmlContent += "<Sender Name=\"" + Prepare($F('SenderName')) + "\" EmailAddress=\"" + Prepare($F('SenderEmailAddress')) + "\" \/>";
    xmlContent += "<Destination EmailAddress=\"" + Prepare($F('DestinationEmailAddress')) + "\" \/>";
    xmlContent += "<Content>" + Prepare($F('SenderComments')) + "</Content>";
    xmlContent += "<intArticleUseID>" + $F('intArticleUseID') + "</intArticleUseID>";
    xmlContent += "<OriginalHost>" + DomainBase + "</OriginalHost>";
    if (document.getElementById('nt'))
        xmlContent += "<nt>" + $F('nt') + "</nt>";
    xmlContent += "<\/Send>";
    return xmlContent;
}

function ProcessSendFormAnwser() {
    var READY_STATE_COMPLETE = 4;
    if (SendHandle.readyState == READY_STATE_COMPLETE) {
        if (SendHandle.status == 200)
            SendDone();
        else
            ErrorSending();

    }

}

function ProcessSendFormAnwserNews() {
    var READY_STATE_COMPLETE = 4;
    if (SendHandle.readyState == READY_STATE_COMPLETE) {
        if (SendHandle.status == 200) {
            HideLayer('EmailSender');
            ShowLayer('EmailSent');
        }

        else
            ErrorSending();

    }

}
    
    
