﻿function CloseSendFriend() {
    $(sendfriendDiv).setStyle('display', 'none');
}

//function DisplaySendFriend() {
//    $(sendfriendDiv).setStyle('display', 'block');
//    var coords = $('divSendToFriend').getCoordinates();
//    $(sendfriendDiv).setStyle('top', coords.top + 20);
//    $(sendfriendDiv).setStyle('right', coords.right - 150);
//    $(sendfriendDiv).setStyle('z-index', 5000);
//}

function DisplaySendFriendFix(Mydiv) {
    $(sendfriendDiv).setStyle('display', 'block');
    var coords = $(Mydiv).getCoordinates();
    $(sendfriendDiv).setStyle('top', coords.top + 20);
    $(sendfriendDiv).setStyle('left', coords.left);
    $(sendfriendDiv).setStyle('z-index', 5000);
}

function SubmitSendFriend() {
    if (echeck($('toEmail').value) == false) {
        displayAlert2('אנא הכנס אי-מייל חוקי', $('toEmail'));
        return false;
    }
    else if (echeck($('senderEmail').value) == false) {
        displayAlert2('אנא הכנס אי-מייל חוקי', $('senderEmail'));
        return false;
    }
    else if ($('senderName').value == '') {
        displayAlert2('הכנס שם', $('senderName'));
        return false;
    }
    else {
        var req = new Request.HTML({
            url: '/ajax/SendFriend.aspx?dicid=' + disctionaryID,
            update: $(sendfriendDiv),
            onRequest: function() { $(sendfriendDiv).empty().innerHTML = '<div style="padding-top:20px"><center><img src="/images/ajax_loaderHD.gif" ></center></div>'; }

        }).post($('frm_SendFriend'));
    }
}

function displayAlert2(message, elm) {
    alert(message);
    elm.focus();
}

function echeck(str) {

    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)
    if (str.indexOf(at) == -1) {
        return false
    }

    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {

        return false
    }

    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
        return false
    }

    if (str.indexOf(at, (lat + 1)) != -1) {
        return false
    }

    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
        return false
    }

    if (str.indexOf(dot, (lat + 2)) == -1) {
        return false
    }

    if (str.indexOf(" ") != -1) {
        return false
    }

    return true
}

function ShowLable(ControlName) {
    $(ControlName).style.display = "block";
}

function HideLable(ControlName) {
    $(ControlName).style.display = "none";
}

function AddRemoveFavoritesArticle(TopAnchor, LowerAnchor, item, key, status) {

    var req = new Request.HTML({
        method: 'get',
        url: '/ajax/MyWedding/AddRemoveFavorites.ashx?item=' + item + '&key=' + key + '&status=' + status,
        onRequest: function() {
            $(TopAnchor).empty().innerHTML = '<img src="/images/ajax_loaderHD.gif" width="28" height="26" align="bottom" />';
            $(LowerAnchor).empty().innerHTML = '<img src="/images/ajax_loaderHD.gif" width="28" height="26" align="bottom" />';
        },
        onComplete: function(response) {
            var ret = response.length > 0 ? response[0].data : "";
            if (ret == '1') {
                $(TopAnchor).onclick = new Function("AddRemoveFavoritesArticle('" + TopAnchor + "','" + LowerAnchor + "','" + item + "','" + key + "','False')");
                $(TopAnchor).empty().innerHTML = '<img src="/images/icon_fav_remov.gif" width="28" height="26" align="bottom" alt="" />';
                $('divTopToolTipFavorit').innerHTML = 'הסר מהמועדפים שלי';

                $(LowerAnchor).onclick = new Function("AddRemoveFavoritesArticle('" + TopAnchor + "','" + LowerAnchor + "','" + item + "','" + key + "','False')");
                $(LowerAnchor).empty().innerHTML = '<img src="/images/icon_fav_remov.gif" width="28" height="26" align="bottom" alt="" />';
                $('divLowerToolTipFavorit').innerHTML = 'הסר מהמועדפים שלי';
            }
            else if (ret == '0') {
                $(TopAnchor).onclick = new Function("AddRemoveFavoritesArticle('" + TopAnchor + "','" + LowerAnchor + "','" + item + "','" + key + "','True')");
                $(TopAnchor).empty().innerHTML = '<img src="/images/icon_fav_add.gif" width="28" height="26" align="bottom" alt="" />';
                $('divTopToolTipFavorit').innerHTML = 'הוסף למועדפים שלי';

                $(LowerAnchor).onclick = new Function("AddRemoveFavoritesArticle('" + TopAnchor + "','" + LowerAnchor + "','" + item + "','" + key + "','True')");
                $(LowerAnchor).empty().innerHTML = '<img src="/images/icon_fav_add.gif" width="28" height="26" align="bottom" alt="" />';
                $('divLowerToolTipFavorit').innerHTML = 'הוסף למועדפים שלי';
            }
        }
    }).send();
}



