
/*
CSS Browser Selector v0.3.5 (Feb 05, 2010)
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: 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.documentElement,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 MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
//popUp that div start
var amID = "blank";
function showMe(containerId){
	if(amID != "blank"){
		hideMe(amID);
	}
	amID = containerId;
	showContainer(containerId);
}
function showContainer(containerId){
	obj = MM_findObj(containerId);
	if (!obj) return;
	obj.style.display = 'block';
}
function hideMe(containerId){
	obj2 = MM_findObj(containerId)
	if (!obj2) return;
	obj2.style.display = 'none';
}
//popUp that div end
//clearing input fields start
function ClearInput(value, id){
var input = document.getElementById(id);
	if(value == input.value){
		input.value = '';
	}
	else{
		input.value = input.value;
	}
}
//clearing input fields end
function fileInputCopy(){
	obj = MM_findObj("realFile");
	obj2 = MM_findObj("fakeFile");
	obj2.value = obj.value;
}
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 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'), '');
}
function setupDefaultTextReset(obj, message) {
    obj.click(function() {
        if (obj.val() == message)
            obj.val('');
    });
    obj.blur(function() {
        if (obj.val() == '')
            obj.val(message);
    });
}
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 trim(this); }
/*~~~~~ start blog ~~~~~*/
$(document).ready(function() {
    $('.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;">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 ~~~~~*/
