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;
}

/* 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);

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//					
// form autoclear
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//	
// used in: login; review submission;			
				$('fieldset.review label span, fieldset.form label.contact span').click(function(){
					if($(this).parent().parent().find('label input').attr('value') == ""){
						$(this).parent().find('span').fadeIn('fast');
					}															
					$(this).fadeOut('fast',function(){
						$(this).parent().find('input').focus();
					});																	
				});
				$('fieldset.review label input, fieldset.review label textarea, fieldset.form label.contact textarea, fieldset.form label.contact input').focusin(function(){
						$(this).parent().find('span').fadeOut('fast');
				});
				$('fieldset.review label input, fieldset.review label textarea, fieldset.form label.contact textarea, fieldset.form label.contact input').focusout(function(){
					if($(this).attr('value') == ""){
						$(this).parent().find('span').fadeIn('fast');
					}
				});	
				
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() {
    setupDefaultTextReset($('div.reviewForm textarea.comment'), 'Comment');
    setupDefaultTextReset($('div.reviewForm input.commentorName'), 'Your Name');
    setupDefaultTextReset($('div.reviewForm 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 reviewForm reviewForm2" id="replyform">' +
          '<fieldset class="review">' +
          '<label class="textarea460" for="tbBlogCommentComment"><textarea id="tbBlogCommentComment" name="tbBlogCommentComment" class="comment" rows="5" >Comment</textarea></label>' +
          '<label class="field220" for="tbBlogCommentName"><input id="tbBlogCommentName" name="tbBlogCommentName" type="text" class="commentorName" value="Your Name"/></label>' +
          '<label class="field220r" for="tbBlogCommentEmail"><input id="tbBlogCommentEmail" name="tbBlogCommentEmail" type="text" class="commentorEmail" value="Your Email"/></label>' +
          '<div class="clearer"></div>' +
          '<p class="error blog-reply-error" style="display:none"></p>' +
          '<div class="clearer"></div>' +
          '<a href="#" class="blog-reply-send b-elastic-r"><span>Send</span></a>' +
          '<a href="javascript:void(0)" class="b-elastic-r blog-reply-cancel"><span>Cancel</span></a>' +
          '<div class="clearer"></div>' +
          '<p class="blog-reply-wait">submitting..</p>' +
          '<div class="clearer"></div>' +
        '</fieldset></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).parent().find('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 ~~~~~*/
		
