﻿/*----------------- InviteByAddressBook.ascx  begin -------------------*/

function ValidAddressBookAccount(sender, args)
{
    args.IsValid = IsValidEmail(args.Value);
    SetValidStatus(sender, args);
}
function ValidAddressBookPassword(sender, args)
{
    ValidRequiredField(sender, args);
}

function ToggleSeletedAddressBookItem()
{
    var rdos = $($("#ulAddressProvider").find("input[type='radio']"));
    var lis = $($("#ulAddressProvider").find("li"));
    lis.each(function(index, domEle)
    {
        var formBox = $(domEle).find(".formBox");
        if (rdos[index].checked)
        {
            $(formBox).show();
        }
        else
        {
            var txtAccount = $($(domEle).find("input[type='text']"));
            var txtPwd = $($(domEle).find("input[type='password']"));
            if (txtAccount.val().length > 0 || txtPwd.val().length > 0)
            {
                $(formBox).show();
            }
            else
            {
                $(formBox).hide();
            }
        }
    });
}

function selectAllAddressBookItems(strContainerId)
{
    $($("#" + strContainerId).find("input[type='checkbox']")).each(function(index, item) { $(item).attr("checked", true); });

    $($("#" + strContainerId).find("label")).each(function(index, item) {
           $(this).addClass("rfdCheckboxChecked");
       });

       $("#" + strContainerId + "_Select").hide();
       $("#" + strContainerId + "_UnSelect").show();

       $("#" + strContainerId + "_imgAdd").hide();
       $("#" + strContainerId + "_imgAll").show(); 
 }

 function unSelectAllAddressBookItems(strContainerId) {
     $($("#" + strContainerId).find("input[type='checkbox']")).each(function(index, item) { $(item).attr("checked", false); });

     $($("#" + strContainerId).find("label")).each(function(index, item) {
         $(this).removeClass("rfdCheckboxChecked");
     });
     $("#" + strContainerId + "_Select").show();
     $("#" + strContainerId + "_UnSelect").hide();

     $("#" + strContainerId + "_imgAdd").show();
     $("#" + strContainerId + "_imgAll").hide(); 
 }

/*----------------- InviteByAddressBook.ascx  end -------------------*/


/*----------------- InviteByMail.ascx  begin -------------------*/

function ValidRecipientEmailAccount(sender, args)
{
    var parent = $(sender).closest(".inviteItem");
    args.IsValid = IsValidEmail(args.Value);
    if (args.IsValid)
    {
        $(parent.find("span.imgHook")).show();
        $(parent.find("span.errMsg").get(1)).hide();
    }
    else
    {
        $(parent.find("span.imgHook")).hide();
        $(parent.find("span.errMsg").get(1)).show();
    }
}

function ValidRecipientEmailAccounts()
{
    var isValid = true; 
    var $inviteItems = $("#divRecipients div.inviteItem");
    $inviteItems.each(function()
    {
        var tmpValid = true;
        var hasValue = false;
        var $this = $(this);
        var $Name = $($this.find("input._name"));
        var $Email = $($this.find("input._mail"));
        var $spanName = $($this.find("span._first"));
        var $spanMail = $($this.find("span._sencond"));
        var $imgHook = $($this.find("span.imgHook"));

        $spanName.hide();
        $spanMail.hide();
        $imgHook.hide();

        var strName = $Name.val();
        var strMail = $Email.val();
        if (strName.length > 0 || strMail.length > 0)
        {
            hasValue = true;
            if (strName.length < 1)
            {
                tmpValid = false;
                $spanName.show();
            }

            if (strMail.length < 1 || !IsValidEmail(strMail))
            {
                tmpValid = false;
                $spanMail.show();
            }
        }
        if (!tmpValid)
        {
            isValid = false;
        }
        else if (hasValue)
        {
            $imgHook.show();
        }
    });
    return isValid;
}

function SetInvitorName()
{
    $(".__spanInviter").each(function()
    {
        $(this).html($(".__inviter").val());
    });
}

function RenderInviteFriends()
{
    var $recipient = $(".yourInvitation .__recipient");
    if ($recipient)
    {
        var strNames = "";
        var $recipientNames = $(".inviteByMail ._name");
        $recipientNames.each(function()
        {
            var $this = $(this);
            if ($this.val().length > 0)
            {
                strNames = strNames + $this.val() + "_,_";
            }
        });
        if (strNames.length > 0)
        {
            strNames = strNames.substr(0, strNames.length - 3);
            strNames = strNames.replace(/_,_/g, ", ");
        }
        $recipient.html(strNames);
    }
}

/*----------------- InviteByMail.ascx  end -------------------*/
