/*
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);

$(document).ready(function() {
    //contact form
    setupDefaultTextReset($('div.footerForm #tbMessage'), 'Message');
    setupDefaultTextReset($('div.footerForm #tbName'), 'Your Name');
    setupDefaultTextReset($('div.footerForm #tbEmail'), 'Your Email');
    $('div.footerForm a.buttonSend').click(function() {
        //validation
        $('div.error').html('');
        $('div.error').css('display', 'none');
        if (trim($('div.footerForm #tbMessage').val()) == '' ||
            $('div.footerForm #tbMessage').val() == 'Message') {
            $('div.footerForm div.error').append('Please enter your message<br />');
        }
        if (trim($('div.footerForm #tbName').val()) == '' ||
            $('div.footerForm #tbName').val() == 'Your Name') {
            $('div.footerForm div.error').append('Please enter your name<br />');
        }
        if (trim($('div.footerForm #tbEmail').val()) == '' ||
            $('div.footerForm #tbEmail').val() == 'Your Email') {
            $('div.footerForm div.error').append('Please enter your email<br />');
        }
        else if (!isValidEmail($('div.footerForm #tbEmail').val())) {
            $('div.footerForm div.error').append('Please enter a valid email<br />');
        }

        if ($('div.footerForm div.error').html() != '') {
            //error
            $('div.footerForm div.error').css('display', 'block');
        }
        else {
            //send contact
            $('div.footerForm div.wait').css('display', 'block');
            $.post("/handlers/ContactHandler.ashx", { message: $('div.footerForm #tbMessage').val(), name: $('div.footerForm #tbName').val(), email: $('div.footerForm #tbEmail').val()/*, captcha: $('div.footerForm #tbCaptcha').val(), hash: $('label.obfuscate span.spanHash').html()*/ }, function(data) {
                $('div.footerForm div.wait').css('display', 'none');

                if (data.indexOf('Error:invalid captcha') != -1) {
                    $('div.footerForm div.error').css('display', 'block');
                    $('div.footerForm div.error').html('Incorrect number of fingers');
                }
                else if (data.indexOf('Error:') != -1) {
                    $('div.footerForm div.error').css('display', 'block');
                    $('div.footerForm div.error').html('An error had occured. Please try again later.');
                }
                else if (data.indexOf('Success') != -1) {
                    $('div.footerForm div.success').css('display', 'block');
                    $('div.footerForm div.footerForm label.obfuscate').css('display', 'none');
                    $('div.footerForm div.footerForm a.buttonSend').css('display', 'none');
                }
            });
        }

        return false;
    });

    //silo contact form
    setupDefaultTextReset($('div.bgGrey300Inner #tbSCName'), 'Your Name');
    setupDefaultTextReset($('div.bgGrey300Inner #tbSCEmail'), 'Your Email');
    setupDefaultTextReset($('div.bgGrey300Inner #tbSCPhone'), 'Your Phone');
    setupDefaultTextReset($('div.bgGrey300Inner #tbSCMessage'), 'Your Message');
    $('div.bgGrey300Inner a#aSend').click(function() {
        //validation
        $('div.footerShell').hide();
        $('div.bgGrey300Inner div.error').html('');
        $('div.bgGrey300Inner div.error').css('display', 'none');
        if (trim($('div.bgGrey300Inner #tbSCName').val()) == '' ||
            $('div.bgGrey300Inner #tbSCName').val() == 'Your Name') {
            $('div.bgGrey300Inner div.error').append('Please enter your name<br />');
        }
        if (trim($('div.bgGrey300Inner #tbSCEmail').val()) == '' ||
            $('div.bgGrey300Inner #tbSCEmail').val() == 'Your Email') {
            $('div.bgGrey300Inner div.error').append('Please enter your email<br />');
        }
        else if (!isValidEmail($('div.bgGrey300Inner #tbSCEmail').val())) {
            $('div.bgGrey300Inner div.error').append('Please enter a valid email<br />');
        }
        if (trim($('div.bgGrey300Inner #tbSCPhone').val()) == '' ||
            $('div.bgGrey300Inner #tbSCPhone').val() == 'Your Phone') {
            $('div.bgGrey300Inner div.error').append('Please enter your phone number<br />');
        }
        if (trim($('div.bgGrey300Inner #tbSCMessage').val()) == '' ||
            $('div.bgGrey300Inner #tbSCMessage').val() == 'Your Message') {
            $('div.bgGrey300Inner div.error').append('Please enter your message<br />');
        }

        if ($('div.bgGrey300Inner div.error').html() != '') {
            //error
            $('div.bgGrey300Inner div.error').css('display', 'block');
        }
        else {
            //send contact
            $('div.bgGrey300Inner div.wait').css('display', 'block');
            $.post("/handlers/SiloContactHandler.ashx", { siloname: $('div.bgGrey300Inner #hdSiloName').val(), message: $('div.bgGrey300Inner #tbSCMessage').val(), name: $('div.bgGrey300Inner #tbSCName').val(), email: $('div.bgGrey300Inner #tbSCEmail').val(), phone: $('div.bgGrey300Inner #tbSCPhone').val() }, function(data) {
                $('div.bgGrey300Inner div.wait').css('display', 'none');

                if (data.indexOf('Error:invalid captcha') != -1) {
                    $('div.bgGrey300Inner div.error').css('display', 'block');
                    $('div.bgGrey300Inner div.error').html('Incorrect number of fingers');
                }
                else if (data.indexOf('Error:') != -1) {
                    $('div.bgGrey300Inner div.error').css('display', 'block');
                    $('div.bgGrey300Inner div.error').html('An error had occured. Please try again later.');
                }
                else if (data.indexOf('Success') != -1) {
                    $('div.bgGrey300Inner div.success').css('display', 'block');
                    $('div.bgGrey300Inner label.obfuscate').css('display', 'none');
                    $('div.bgGrey300Inner a#aSend').css('display', 'none');
                }
            });
        }
        $('div.footerShell').show();

        return false;
    });
});
function centerMov() {
    var winH = ($(window).height());
    var winW = ($('.lightBox').width());
    $('.bgBlue320').css('position', 'absolute').css('top', (winH / 2) - ($('.bgBlue320').height() / 2) + "px").css('left', (winW / 2) - ($('.bgBlue320').width() / 2) + "px");
    $('html, body').css('top', $(".bgBlue320").offset().top);
}
function setupDefaultTextReset(obj, message) {
    obj.click(function() {
        if (obj.val() == message)
            obj.val('');
    });
    obj.blur(function() {
        if (obj.val() == '')
            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 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 PostBackOnReturn(event, postbackMethod) {
    if (event) {
        if (event.keyCode == 13) {
            __doPostBack(postbackMethod, '');
        }
    }
}
String.prototype.startsWith = function(str) { return (this.match("^" + str) == str); }