jQuery(document).ready(function() {
    jQuery(this).find(".dommeCheck").change(function() {
        if (jQuery(this).val() != '') {
            validateDomme(this);
        }
    });
    jQuery(this).find("#fds_im").click(function() {
        im_win('/fdsim.php?member_id=<?=$logged_member_id?>', 310, 460, 'fds_im');
    });
    jQuery(this).everyTime(300000, 'mail_hotlist_check', function() {
        jQuery.getJSON('/api/new.php?member_id=' + jQuery('div.member_id:first').text() + '&SID=' + jQuery.cookie('PHPSESSID') + '&item=mail', function(response) {
            if (response.status == 'OK' && response.data) {
                jQuery("#mail_notify").remove();
                jQuery("#my_mail").after('<li id="mail_notify"><a href="/my_mail.php"><img src="/images/animatedenvelope_25x20.gif" alt="new mail!" /></a></li>');
            }
        });
        jQuery.getJSON('/api/new.php?member_id=' + jQuery('div.member_id:first').text() + '&SID=' + jQuery.cookie('PHPSESSID') + '&item=hotlist', function(response) {
            if (response.status == 'OK' && response.data) {
                jQuery("#mail_notify").remove();
                jQuery("#my_mail").after('<li id="mail_notify"><a href="/my_mail.php"><img src="/images/friends_animated_25x20.gif" alt="hotlisted!" /></a></li>');
            }
        });
        }, true);

});

// Author: Kit Peters
// Date: 27 April 2009
/**
 * Validate the member ID passed in the given element as a Domme or not.
 *
 * @param element Element containing the member ID
 */
function validateDomme(element) {
    var notDommeMsg = ((jQuery("#notDommeMsg") && jQuery("#notDommeMsg").val()) ? jQuery("#notDommeMsg").val() : "is not a Domme Lady of the Society");
    var dommeMsg = ((jQuery("#dommeMsg") && jQuery("#dommeMsg").val()) ? jQuery("#dommeMsg").val() : "will surely be pleased that you have chosen to support the Society in Her name.");
    if (jQuery("#myid") && jQuery("#myid").val() == jQuery(element).val()) { // maybe somebody will try to be sneaky and give themselves 1000 points...
        alert("You cannot refer yourself");
        $(element).val('');
        return;
    } 
    checkMember(jQuery(element).val(), function(response) {
        if (response.status == "ERROR") {
            alert(response.data);
            jQuery(element).val('');
        } else {
            if (isDomme(response.data.iama)) {
                alert(response.data.display_name + ' ' + dommeMsg);
            } else {
                alert(response.data.display_name + ' ' + notDommeMsg);
                jQuery(element).val('');
            }
        }
        });
}

function isDomme(iama) {
    return (iama == 1 || iama == 2 || iama == 5 || iama == 6);
}

function checkMember(member_id, callback) {
    jQuery.getJSON("/api/check.php?member_id=" + member_id + '&SID=' + jQuery.cookie('PHPSESSID'), callback);
}

function im_win(url, win_width, win_height, win_name) {
    win_opt = "top=25,left=25,height="+win_height+",width="+win_width+",scrollbars=no,status=no,menubars=no,toolbars=no,resizable=no,location=no";		
    newwindow = window.open(url,win_name,win_opt);
    if (!newwindow.opener) newwindow.opener = self;

    if (window.focus) {newwindow.focus()}
    return true;
}


