/*CSS Browser Selector v0.3.4 (Sep 29, 2009)Rafael Lima (http://rafael.adm.br)http://rafael.adm.br/css_browser_selectorLicense: 
http://creativecommons.org/licenses/by/2.5/Contributors: http://rafael.adm.br/css_browser_selector#contributors*/
function css_browser_selector(u) { var ua = u.toLowerCase(), is = function(t) { return ua.indexOf(t) > -1; }, g = 'gecko', w = 'webkit', s = 'safari', o = 'opera', h = document.getElementsByTagName('html')[0], b = [(!(/opera|webtv/i.test(ua)) && /msie\s(\d)/.test(ua)) ? ('ie ie' + RegExp.$1) : is('firefox/2') ? g + ' ff2' : is('firefox/3.5') ? g + ' ff3 ff3_5' : is('firefox/3') ? g + ' ff3' : is('gecko/') ? g : is('opera') ? o + (/version\/(\d+)/.test(ua) ? ' ' + o + RegExp.$1 : (/opera(\s|\/)(\d+)/.test(ua) ? ' ' + o + RegExp.$2 : '')) : is('konqueror') ? 'konqueror' : is('chrome') ? w + ' chrome' : is('iron') ? w + ' iron' : is('applewebkit/') ? w + ' ' + s + (/version\/(\d+)/.test(ua) ? ' ' + s + RegExp.$1 : '') : is('mozilla/') ? g : '', is('j2me') ? 'mobile' : is('iphone') ? 'iphone' : is('ipod') ? 'ipod' : is('mac') ? 'mac' : is('darwin') ? 'mac' : is('webtv') ? 'webtv' : is('win') ? 'win' : is('freebsd') ? 'freebsd' : (is('x11') || is('linux')) ? 'linux' : '', 'js']; c = b.join(' '); h.className += ' ' + c; return c; }; css_browser_selector(navigator.userAgent);
function setupDefaultTextReset(obj, message) {    
    obj.click(function() {
        if (obj.val() == message)
            obj.val('');
    });
    obj.blur(function() {
        if (obj.val() == '')
            obj.val(message);
    });
    if(obj.val() != message)
        obj.val(message);
}
function isValidEmail(email) {
    var regex = /([\w\d\-_]+)(\.[\w\d\-_]+)*@([\w\d\-_]+\.)([\w\d\-_]+\.)*([\w]{2,3})/;
    if (regex.test(email))
        return true;
    else
        return false;
}
function PostBackOnReturn(event, postbackMethod) {
    if (event) {
        if (event.keyCode == 13) {
            __doPostBack(postbackMethod, '');
        }
    }
}
String.prototype.startsWith = function(str) { return (this.match("^" + str) == str); }
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }

$(document).ready(function() {
    //nesletter subscribe
    $('div.keepUpToDate>a').click(function() {
        newsletterSubscribe();
        return false;
    });
    setupDefaultTextReset($("fieldset.search input"), "Search");
    $("fieldset.search input").keydown(function(event){
        if(event.keyCode == '13'){
            var searchHref = $(this).next().attr("href");
            searchHref = searchHref.replace(/javascript:/, '');
            eval(searchHref);
        }
    });
    setupDefaultTextReset($('div.keepUpToDate>input#tbEmail'), 'enter your email address');
    $('div.keepUpToDate>input#tbEmail').keydown(function(event) {
        if (event.keyCode == '13') {
            newsletterSubscribe();
            return false;
        }
    });
    
});
function newsletterSubscribe() {
    var email = $('div.keepUpToDate>input#tbEmail').val();
    $('div.keepUpToDate>span.error').html('');
    $('div.keepUpToDate>span.error').hide();

    if (email.trim() == '' ||
        email.trim() == 'enter your email address') {
        $('div.keepUpToDate>span.error').html('Please enter your email address');
    }
    else if (!isValidEmail(email)) {
        $('div.keepUpToDate>span.error').html('Please enter a valid email address');
    }
    if ($('div.keepUpToDate>span.error').html() != '') {
        $('div.keepUpToDate>span.error').fadeIn(500);
    }
    else {
        //send
        $('div.keepUpToDate span.wait').show();
        $.post("/handlers/NewsletterSubscriptionHandler.ashx", { email: email }, function(data) {
            $('div.keepUpToDate span.wait').hide();

            if (data.indexOf('Error:') != -1) {
                $('div.keepUpToDate>span.error').fadeIn(500);
                $('div.keepUpToDate>span.error').html('Unfortunately an error has occured saving your details, please try again or contact us');
            }
            else if (data.indexOf('Success') != -1) {
                $('div.keepUpToDate>span.success').fadeIn(500);
            }
        });
    }
}
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
    chars = chars || '\\s';
    return str.replace(new RegExp('^[" + chars + "]+', 'g'), '');
}
function rtrim(str, chars) {
    chars = chars || '\\s';
    return str.replace(new RegExp('[" + chars + "]+$', 'g'), '');
}
String.prototype.startsWith = function(str) { return (this.match("^" + str) == str); }
String.prototype.trim = function() { return trim(this); }
/*~~~~~ start blog ~~~~~*/
$(document).ready(function() {
    setupDefaultTextReset($('div.commentFormContainer textarea.comment'), 'Comment');
    setupDefaultTextReset($('div.commentFormContainer input.commentorName'), 'Your Name');
    setupDefaultTextReset($('div.commentFormContainer input.commentorEmail'), 'Your Email');
    $('.blog-reply').click(function() {
        $('.blog-reply-comment').html('');
        $(this).parents('div.comment').nextAll('.blog-reply-comment').eq(0).html(
        '<div class="commentFormContainer" id="replyform">' +
          '<div class="clearer"></div>' +
          '<textarea id="tbBlogCommentComment" name="tbBlogCommentComment" class="comment" rows="5" style="margin-top:5px;width:530px;">Comment</textarea>' +
          '<label for="tbBlogCommentName"><input id="tbBlogCommentName" name="tbBlogCommentName" type="text" class="commentorName" value="Your Name" /></label>' +
          '<label for="tbBlogCommentEmail"><input id="tbBlogCommentEmail" name="tbBlogCommentEmail" type="text" class="commentorEmail" value="Your Email" /></label>' +
          '<p class="error blog-reply-error" style="display:none"></p>' +
          '<a href="#" class="buttonSend blog-reply-send">Send</a>' +
          '<a href="javascript:void(0)" class="blog-reply-cancel">cancel</a>' +
          '<p class="blog-reply-wait">submitting..</p>' +
          '<div class="clearer"></div>' +
        '</div><div class="clearer"></div>');

        setupDefaultTextReset($('div.blog-reply-comment div.commentFormContainer textarea.comment'), 'Comment');
        setupDefaultTextReset($('div.blog-reply-comment div.commentFormContainer input.commentorName'), 'Your Name');
        setupDefaultTextReset($('div.blog-reply-comment div.commentFormContainer input.commentorEmail'), 'Your Email');

        window.location.hash = '#replyform';

        $('.blog-reply-cancel').click(function() {
            $(this).parents('.blog-reply-comment').html('');
        });
        $('.blog-reply-send').click(function() {
            var name = $(this).parent().find('label input[name=tbBlogCommentName]').val();
            var email = $(this).parent().find('label input[name=tbBlogCommentEmail]').val();
            var comment = $(this).siblings('textarea[name=tbBlogCommentComment]').val();

            //validation
            $(this).siblings('p.blog-reply-error').html('');
            $(this).siblings('p.blog-reply-error').css('display', 'none');
            var isValid = true;
            var errorMsg = '';
            if (comment.trim() == '' || comment.trim().toLowerCase() == 'comment') {
                isValid = false;
                errorMsg += 'Please enter your comment<br />';
            }
            if (name.trim() == '' || name.trim().toLowerCase() == 'your name') {
                isValid = false;
                errorMsg += 'Please enter your name<br />';
            }
            if (email.trim() == '' || email.trim().toLowerCase() == 'your email') {
                isValid = false;
                errorMsg += 'Please enter your email address<br />';
            }
            else if (!isValidEmail(email)) {
                isValid = false;
                errorMsg += 'Please enter a valid email address<br />';
            }
            if (!isValid) {
                $(this).siblings('p.blog-reply-error').html(errorMsg);
                $(this).siblings('p.blog-reply-error').css('display', 'block');
                return false;
            }

            var commentID = $(this).parents('.blog-reply-comment').next('input:hidden').val();
            $('p.blog-reply-wait').html('Submitting... Please Wait');
            $('p.blog-reply-wait').css('display', 'block');

            jQuery.post('/handlers/BlogCommentReply.ashx', { commentid: commentID, name: name, email: email, comment: comment }, function(data) {
                $('p.blog-reply-wait').css('display', 'none');
                if (data.startsWith('Success')) {
                    if (data.startsWith("Success:posted")) {
                        $('#divBlogReplyComment-' + commentID).html('<div class="reply"><p>' + comment + '<br /><span class="commentor">' + name + '</span></p></div>');
                    }
                    else {
                        $('#divBlogReplyComment-' + commentID).html('<div class="reply"><p>' + comment + '<br /><em>Your reply is now submitted and pending approval</em><br /><span class="commentor">' + name + '</span></p></div>');
                    }
                }
                else {
                    $('#divBlogReplyComment-' + commentID + ' div.commentFormContainer p.blog-reply-error').html('An error had occurred. Please try again later.');
                    $('#divBlogReplyComment-' + commentID + ' div.commentFormContainer p.blog-reply-error').css('display', 'block');
                }
            });
            return false;
        });
        return false;
    });
});
/*~~~~~ end blog ~~~~~*/
