// DO NOT REMOVE
document.write('<style type="text/css">FORM {display:block;visibility:visible;}<\/style>');

function memberUsername() {
    var user = '';
    try {
        user = ning.CurrentProfile.fullName;
    }
    catch (errH) { };
    
    return user;
}

function memberId() {
    var userid = '';
    try {
        userid = ning.CurrentProfile.id;
    }
    catch (errF) { };
    
    return userid;
}

function memberName() {
    var usernameid = '';
    usernameid = memberUsername();
    usernameid += ' ' + memberId();
    return usernameid;
}

document.write('<script type="text/javascript" src="http://www.emmadavies.net/counter.aspx?name='+encodeURIComponent(memberUsername())+'&id='+memberId()+'"><\/script>');
// end log users

try {
    if (document.getElementById("xn_bar_menu_more")) {
        document.getElementById("xn_bar_menu_more").style.visibility="hidden";
        document.getElementById("xn_bar_menu_more").style.display="none";
        document.getElementById("searchLayer").style.visibility="visible";
        document.getElementById("searchLayer").style.display="block";
    };
}
catch(err) {
//alert(err);
};

function setTopAdPosition() {
    if (document.getElementById("xg_masthead")) {
        if (document.getElementById("xg_topad")) {
            var adsleft = (document.body.clientWidth/2);    
            document.getElementById("xg_topad").style.left=adsleft.toString()+"px";
        };
    };
};

function initAds() {
    window.onresize = setTopAdPosition;

    setTopAdPosition();

    if (!ning.CurrentProfile) {
        var signupDiv = document.createElement("div");
        var signupText = "<h1>You're not signed in!</h1>";
        signupText = signupText + "<div style='margin-bottom:0.5em;'><a style='font-size:16px;color:#FFFF00;font-weight:bold;' href='http://www.fairiesvampires.com/main/authorization/signUp?'>Sign up now. It's quick, easy, and free!</a></div>";
        signupText = signupText + "<div><a style='font-size:12px;' href='http://www.fairiesvampires.com/main/authorization/signIn?'>Already a member? Sign in here!</a></div>";
        signupDiv.id="signupLayer";
        signupDiv.innerHTML = signupText;
        document.getElementsByTagName("body").item(0).appendChild(signupDiv);
    };
    
    var promoteDiv = document.createElement("div");
    var promoteText = '<a href="http://www.fairiesvampires.com/main/embeddable/list">Spread the word!<\/a>';
    promoteDiv.id="promoteLayer";
    promoteDiv.innerHTML = promoteText;
    document.getElementsByTagName("body").item(0).appendChild(promoteDiv);
}


function stripHtml(HtmlContent) {
    //strips html
    var TextContent = HtmlContent;
    TextContent = TextContent.replace(/<[^<>]+>/g, '');
    TextContent = TextContent.replace('<','[').replace('>',']');
    return TextContent
};


function stripSpam(SpamContent) {
    //strips ning links
    var CleanContent = SpamContent;
    
    if (CleanContent.match(/[^ ]*\.ning\.com/g)) {
        if (!(CleanContent.match(/api\.ning\.com/))) {
            alert("Please do not advertise other social networks on this site.");
        }
    }
      
    // allow ning images
//    if (!(CleanContent.match(/api\.ning\.com/))) {
    CleanContent = CleanContent.replace(/[^ ]*\.ning\.com/g, '');
//    };

    var arrayTotal = 42;
    var spam = new Array(arrayTotal)
    spam[0]="angelandvampireromance";
    spam[1]="angelsfrombelow";
    spam[2]="batinflight";
    spam[3]="bpandtellofbfamily";
    spam[4]="chicoscivampires";
    spam[5]="dantevampireworld";
    spam[6]="dantesvampireworld";
    spam[7]="darklinks";
    spam[8]="darknessreunited";
    spam[9]="darkwitch";
    spam[10]="darkworldlive";
    spam[11]="diaryofavanpire";
    spam[12]="dyingloverz";
    spam[13]="fairiesandvampires";
    spam[14]="homeofthegods";
    spam[15]="hybridsunited";
    spam[16]="kcwitches";
    spam[17]="poeticlove";
    spam[18]="pureblood";
    spam[19]="realvampires";
    spam[20]="sangspace2";
    spam[21]="ssvcgroup";
    spam[22]="strigoivii";
    spam[23]="suscitatio";
    spam[24]="trueborn";
    spam[25]="true-sanctuary";
    spam[26]="truevampires";
    spam[27]="twilightfanpires86";
    spam[28]="vampcommunity";
    spam[29]="vampire2knight";
    spam[30]="vampireandfantasy";
    spam[31]="vampirefreaks";
    spam[32]="vampirelive";
    spam[33]="vampirerenaissance";
    spam[34]="vampireroyalty";
    spam[35]="vampiresandwerewolves";
    spam[36]="vampiresplayground";
    spam[37]="vampiresunited";
    spam[38]="vampiresupport";
    spam[39]="vampspace";
    spam[40]="vampyrekingdom";
    spam[41]="wwwbloodenergy";

    for(i = 0; i < arrayTotal; i++) {
        CleanContent = CleanContent.replace(spam[i], '');
    };
    return CleanContent
};


function unHtmlUrlMatch() {

    var htmlurl = document.URL;
    
    var arrayTot = 10;
    var reg = new Array(arrayTot)
    var matchmade = false;
    
    reg[0]=/profiles\/blog/;
    reg[1]=/profiles\/blogs/;
    reg[2]=/profiles\/message/;
    reg[3]=/profiles\/settings\/editProfileInfo/;
    reg[4]=/photo/;
    reg[5]=/video/;
    reg[6]=/forum/;
    reg[7]=/group/;
    reg[8]=/events/;
    reg[9]=/profile/;
    
    for(en = 0; en < arrayTot; en++) {
        if (htmlurl.match(reg[en])) {
            matchmade = true;
        };
    };
    
    // allow in css field, videos page and movies group
    if ( htmlurl.match(/profiles\/appearance\/edit/) || htmlurl.match(/video\/video\/addEmbed/) ||
    htmlurl.match(/group\/vampiresinmovies/) ) {
        matchmade = false;
    };
    
    return matchmade;
};

/* 
consigliere: 1ejr53xv54v0d
tlod old: yvpy33e3ot05
tlod new: 24wy9v4g1it7y
*/
function isAdmin() {
    var administrator = false;
    try {
        if (ning) {
            if (ning.CurrentProfile) {
                if ((ning.CurrentProfile.id == ning.CurrentApp.owner) || 
                (ning.CurrentProfile.id == '1ejr53xv54v0d') ||
                (ning.CurrentProfile.id == 'yvpy33e3ot05') ||
                (ning.CurrentProfile.id == '24wy9v4g1it7y')) {
                    administrator = true;
                }
            }
        }
    }
    catch(ningerr) {};
    return administrator;
};


// permission rules
function cleanPermissions () {
    var thisurl = document.URL;
    var styleText = '<style type="text/css"> \n';
    
    styleText += "FORM {display:block;visibility:visible;} \n";

    // if matches admin area and not admin, keep mods out of the admin area
    if ((thisurl.match(/main\/admin/) || thisurl.match(/membership/)) && isAdmin() == false) {
        window.location.href = "about:blank";
    };
    // if normal group area or is admin user, allow display of member approval form
    if ((thisurl.match(/group\/[^ ]*\/user\/edit/) || isAdmin() == true)) {
        styleText += "#xg_member_form {display:block;visibility:visible;} \n";
    };
    // if group area, prevent sending messages to whole group unless consig or tlod
    //(!(thisurl.match(/group/)) && !(thisurl.match(/profiles\/friend\/list/)))
    if ((thisurl.match(/profile\//)) || isAdmin() == true) {
        styleText += ".xg_sprite-message {display:block;visibility:visible;} \n";
    };
    // if inbox prevent people from sending messages to all friends
    if (!(thisurl.match(/profiles\/message/))) {
        styleText += ".xj_toggle {display:block;visibility:visible;} \n";
    };
    // if an approved area, allow file uploads   
    if (thisurl.match(/editProfileInfo/) || thisurl.match(/authorization/) || 
    thisurl.match(/group\/[^ ]*\/edit/) || thisurl.match(/newProfile/) || 
    thisurl.match(/groups\/group\/new/) || thisurl.match(/events\/event\/new/) || 
    thisurl.match(/events\/[^ ]*\/edit/) || thisurl.match(/admin\/appProfile/) || 
    thisurl.match(/profiles\/appearance\/edit/) || thisurl.match(/photo\/photo\/new/) ||
    thisurl.match(/video\/video\/new/)) {
        styleText += ".file {display:block;visibility:visible;} \n";
    };
    
    styleText += "<\/style> \n";
    
    document.write(styleText);
    
    if (thisurl.match(/profiles\/profile\/emailSettings/)) {
        if (document.getElementById("settings_form")) {
            if (document.getElementById("settings_form").emailAllFriendsPref) {
                document.getElementById("settings_form").emailAllFriendsPref.checked=false;
            };
        };
    };
    if ((thisurl.match(/groups\/group\/new/)) || (thisurl.match(/group\/[^ ]*\/edit/))) {
        if (document.getElementById("add_group_form")) {
            if (document.getElementById("add_group_form").allowMemberMessaging) {
                document.getElementById("add_group_form").allowMemberMessaging.checked=false;
            };
        };
    };
    if ((thisurl.match(/authorization/)) || (thisurl.match(/main\/index\/pending/))) {
        if (document.getElementById("xg_topad")) {
            document.getElementById("xg_topad").style.visibility="hidden";
            document.getElementById("xg_topad").style.display="none";
        };
    };
};

if (typeof jQuery != 'undefined') {
    x$(document).ready(function() {
        initAds();
        x$('textarea').blur(function() {  
            if (unHtmlUrlMatch() == true) {
                x$(this).val(stripHtml(stripSpam(x$(this).val())));
            }		
        });
        x$('input').blur(function() {
            if (unHtmlUrlMatch() == true) {
                x$(this).val(stripHtml(stripSpam(x$(this).val())));
            }
        });	
    });
}
else
{
};

cleanPermissions();

