/*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);

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }
String.prototype.startsWith = function(str) { return (this.match("^" + str) == str); }
function setupDefaultTextReset(obj, message) {
    obj.click(function() {
        if (obj.val() == message)
            obj.val('');
    });
    obj.blur(function() {
        if (obj.val() == '')
            obj.val(message);
    });
}
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 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('answer' + amID);
		$('#question' + amID).removeClass('active');
	}
	if(amID != containerId){
		amID = containerId;
		showContainer('answer' + containerId);
		$('#question' + containerId).addClass('active');
	}
	else
		amID = "blank";
}
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

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 resetText(obj, text, isClick) {
    if (obj.val() == text && isClick)
        obj.val('');
    else if (obj.val() == '' && !isClick)
        obj.val(text);
}
/*start blog*/
$(document).ready(function() {
    $('.blog-reply').click(function() {
        $(this).parent().next('.blog-reply-comment').html(
        '<div class="form commentForm">' +
          '<a href="javascript:void(0)" class="blog-reply-cancel">cancel</a>' +
          '<div class="clearer"></div>' +
          '<p class="blog-reply-error"></p>' +
          '<label for="tbBlogCommentName">Your Name *</label><input id="tbBlogCommentName" name="tbBlogCommentName" type="text" class="inputText" /><div class="clearer"></div>' +
          '<label for="tbBlogCommentEmail">Your Email *</label><input id="tbBlogCommentEmail" name="tbBlogCommentEmail" type="text" class="inputText" /><div class="clearer"></div>' +
          '<label for="tbBlogCommentComment">Comment *</label><textarea id="tbBlogCommentComment" name="tbBlogCommentComment"></textarea><div class="clearer"></div>' +
          '<a href="javascript:void(0)" class="medBlueButton"><span class="leftEdge"></span><span class="middlePortion">POST COMMENT</span><span class="rightEdge"></span></a>' +
          '<div class="clearer"></div>' +
        '</div>');

        $('.blog-reply-cancel').click(function() {
            $(this).parents('.blog-reply-comment').html('');
        });
		
        $('.medBlueButton').click(function() {
            var name = $(this).siblings('input[name=tbBlogCommentName]').val();
            var email = $(this).siblings('input[name=tbBlogCommentEmail]').val();
            var comment = $(this).siblings('textarea[name=tbBlogCommentComment]').val();

            //validation
            $(this).siblings('p.blog-reply-error').html('');
            var isValid = true;
            var errorMsg = '';
            if (name.trim() == '' || name.trim().toLowerCase() == 'your name') {
                isValid = false;
                errorMsg += 'Please enter your name<br />';
                $(this).siblings('input[name=tbBlogCommentName]').attr('class', 'inputText error');
            }
            if (email.trim() == '' || email.trim().toLowerCase() == 'your email (not displayed on the website)') {
                isValid = false;
                errorMsg += 'Please enter your email address<br />';
                $(this).siblings('input[name=tbBlogCommentEmail]').attr('class', 'inputText error');
            }
            else if (!isValidEmail(email)) {
                isValid = false;
                errorMsg += 'Please enter a valid email address<br />';
                $(this).siblings('input[name=tbBlogCommentEmail]').attr('class', 'inputText error');
            }
            if (comment.trim() == '' || comment.trim().toLowerCase() == 'your comment') {
                isValid = false;
                errorMsg += 'Please enter your comment<br />';
                $(this).siblings('textarea[name=tbBlogCommentComment]').attr('class', 'error');
            }
            if (!isValid) {
                $(this).siblings('p.blog-reply-error').html(errorMsg);
                return false;
            }

            var commentID = $(this).parents('.blog-reply-comment').parent().find('input[type="hidden"]').val();
            $(this).html('Submitting... Please Wait');
            $(this).attr('style', 'color:#31BEEE !important;');
            jQuery.post('/handlers/BlogCommentReply.ashx', { commentid: commentID, name: name, email: email, comment: comment }, function(data) {
                if (data.startsWith('Success')) {
                    if (data.startsWith("Success:posted")) {
                        $('#divBlogReplyComment-' + commentID).html('<p>Your reply has been posted.</p>');
                        /*var newCommentHTML = $('#ulBlogCommentReply-' + commentID).html() + '<li>' + comment + '<br /><cite>' + name + '</cite><small class="commentmetadata">' + data.split(':')[2] + '</small</li>';
                        $('#divBlogReplyComment-' + commentID).prev('p').after(newCommentHTML);*/
                    }
                    else {
                        $('#divBlogReplyComment-' + commentID).html('<p>Your reply is now submitted and pending approval.</p>');
                    }
                }
                else {
                    $('#divBlogReplyComment-' + commentID).html('An error had occurred. Please try again later.');
                }
            });
        });
    });
});
$(document).ready(function() {

    $('#blogNav > a.active').attr('rel', 'open').next().show();

    $('#blogNav > a').click(function() {
        if ($(this).attr('rel') == 'open')
            $(this).attr('rel', '').next().slideUp();
        else {
            $('#blogNav > a[rel="open"]').attr('rel', '').next().slideUp();
            $(this).attr('rel', 'open').next().slideDown();
        }
        return false;
    });
});
/*end blog*/
/*lightbox*/
function _createIFrame(width, height, src) {
    _buildLightbox();
    $('#lightboxContent').css('width', width);
    $('#lightboxContentWrap').css('top', ($(window).height() - height) / 2);
    $('#lightboxLoadTarget').html('<iframe src="' + src + '" border="0" frameborder="0" ALLOWTRANSPARENCY="true" scrolling="no" width="' + width + 'px" height="' + height + 'px" style="background:transparent;" />');
    $('html, body').animate({ scrollTop: 0 }, 'slow');
};
function _createIFrameParent(width, height, src) {
    _buildLightbox();
    $('#lightboxContent', parent.document.body).css('width', width);
    $('#lightboxContentWrap', window.parent.document).css('top', 100);
    
    $('#lightboxLoadTarget', parent.document.body).html('<iframe src="' + src + '" border="0" frameborder="0" ALLOWTRANSPARENCY="true" scrolling="no" width="' + width + 'px" height="' + height + 'px" style="background:transparent;" />');
    
    $('html, body', parent.document.body).animate({ scrollTop: 0 }, 'slow');
};

function _buildLightbox() {
    $('body').append('<div id="lightboxOverlay"></div>');
    $('body').append('<div id="lightboxContentWrap"><div id="lightboxContent"><a class="close" href="javascript:_destroyLightbox()">Close</a><div id="lightboxLoadTarget"></div></div></div>');
    $('#lightboxOverlay').click(function() {
        _destroyLightbox();
    });
    $('#lightboxContentWrap').click(function() {
        _destroyLightbox();
    });
};

function _destroyLightbox() {
    $('#lightboxOverlay').remove();
    $('#lightboxContentWrap').remove();
};


/***********************************************
* Drop Down Date select script- by JavaScriptKit.com
* This notice MUST stay intact for use
* Visit JavaScript Kit at http://www.javascriptkit.com/ for this script and more
* WARNING -------------------------------------------------------!-
* This javascript has been modified by *bdhacker* for real life use
* ishafiul@gmail.com
* http://bdhacker.wordpress.com
***********************************************/

var monthtext=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'];

function date_populate(dayfield, monthfield, yearfield){
    var today=new Date();
    var dayfield=document.getElementById(dayfield)
    var monthfield=document.getElementById(monthfield)
    var yearfield=document.getElementById(yearfield)
    for (var i=0; i<31; i++)
        dayfield.options[i]=new Option(i+1, i+1)
    dayfield.options[today.getDate()]=new Option(today.getDate(), today.getDate(), true, true) //select today's day
    for (var m=0; m<12; m++)
        monthfield.options[m]=new Option(monthtext[m], monthtext[m])
    monthfield.options[today.getMonth()]=new Option(monthtext[today.getMonth()], monthtext[today.getMonth
()], true, true) //select today's month
    var thisyear=today.getFullYear()
    for (var y=0; y<100; y++){
        yearfield.options[y]=new Option(thisyear, thisyear)
        thisyear-=1
    }
    yearfield.options[0]=new Option(today.getFullYear(), today.getFullYear(), true, true) //select today's year
}


