﻿function fbs_click_fb() {
    u = location.href;
    t = document.title;
    window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t));
    return false;
}

function fbs_click_digg() {
    u = location.href;
    t = document.title;
    window.open('http://digg.com/submit?phase=2&url=' + encodeURIComponent(u) + '&title=' + encodeURIComponent(t));
    return false;
}

function fbs_click_googleb() {
    u = location.href;
    t = document.title;
    window.open('http://www.google.com/bookmarks/mark?op=edit&bkmk=' + encodeURIComponent(u) + '&title=' + encodeURIComponent(t));
    return false;
}

function fbs_click_twitter() {
    u = location.href;
    t = document.title;
    window.open('http://twitter.com/home?status=Currently reading ' + encodeURIComponent(u) + '&title=' + encodeURIComponent(t));
    return false;
}

function fbs_click_technorati() {
    u = location.href;
    t = document.title;
    window.open('http://technorati.com/faves?sub=' + encodeURIComponent(t) + '&add=' + encodeURIComponent(u));
    return false;
}

function fbs_click_linkedin() {
    u = location.href;
    t = document.title;
    window.open('http://www.linkedin.com/shareArticle?mini=true&url=' + encodeURIComponent(t) + '&title=' + encodeURIComponent(u));
    return false;
}

function fbs_click_blinklist() {
    u = location.href;
    t = document.title;
    window.open('http://blinklist.com/index.php?Action=Blink/addblink.php&url=' + encodeURIComponent(u) + '&title=' + encodeURIComponent(t));
    return false;
}

function fbs_click_del() {
    u = location.href;
    t = document.title;
    window.open('http://del.icio.us/post?url=' + encodeURIComponent(u) + '&title=' + encodeURIComponent(t));
    return false;
}

function fbs_click_newsv() {
    u = location.href;
    t = document.title;
    window.open('http://www.newsvine.com/_tools/seed&save?popoff=0&u=' + encodeURIComponent(u) + '&h=' + encodeURIComponent(t));
    return false;
}

function fbs_click_redd() {
    u = location.href;
    t = document.title;
    window.open('http://reddit.com/submit?url=' + encodeURIComponent(u) + '&title=' + encodeURIComponent(t));
    return false;
}

function fbs_click_SUpon() {
    u = location.href;
    t = document.title; window.open('http://www.stumbleupon.com/submit?url=' + encodeURIComponent(u) + '&title=' + encodeURIComponent(t));
    return false;
}

function fbs_click_yahoo() {
    u = location.href;
    t = document.title; window.open('http://myweb2.search.yahoo.com/myresults/bookmarklet?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t));
    return false;
}

function fbs_click_livej() {
    u = location.href;
    window.open('http://www.livejournal.com/update.bml?subject=' + encodeURIComponent(u));
    return false;
}

function isValidEmail(email, required) {
    if (required == undefined) { 
        required = true;
    }
    if (email == null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length == 0) {
        if (required) {
            return false;
        }
        return true;
    }
    var re = /^.+\@.+\..{2,4}$/gi;
    if (!email.match(re)) {
        email.focus;
        return false;
    }
    return true;
}

function DynamicValidate(invalidUsernameMessage, emptyPassordMessage) {
    var emailaddress = document.getElementById("tbUsername");
    var password = document.getElementById("tbPassword");
    var isValid = false;
    // Email validation commented because Codehouse usernames no longer are email adresses
    if (invalidUsernameMessage != '' && !isValidEmail(emailaddress.value)) {
        emailaddress.style.color = "red";
        alert(invalidUsernameMessage);
        return false;
    }
    if (emptyPassordMessage != '' && password.value.length == 0) {
        alert(emptyPassordMessage);
        password.focus();
        return false;
    }
    else {
        isValid = true;
    }
    if (isValid == true) {
        var newID = "btnAction";
        document.getElementById(newID).click();
    }
    return isValid;
}

function DynamicValidateEx() {
    var emailaddress = document.getElementById("tbUsername");
    var password = document.getElementById("tbPassword");
    // Email validation commented because Codehouse usernames no longer are email adresses
    if (!isValidEmail(emailaddress.value)) {
        return false;
    }
    if (password.value.length == 0) {
        return false;
    }
    return true;
}

function DynamicCaptureEnterKey() {
    document.onkeydown = null;
    document.onkeydown = DynamicCaptureKeyBoardEvents;
    if (window.addEventListener) {
        window.addEventListener("keydown", DynamicCaptureKeyBoardEvents, false);
    }
}

function DynamicCaptureKeyBoardEvents(evt) {
    var keyCode = document.layers ? evt.which : document.all ? event.keyCode : document.getElementById ? evt.keyCode : 0;
    var srcID = document.all ? event.srcElement.id : evt.target.id;
    if (keyCode == 13) {
        if (DynamicValidateEx() == true) {
            var newID = "btnAction";
            document.getElementById(newID).click();
        }
        else {
            return false;
        }
    }
}