/*
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

function ClearInput(value, id) {
    var input = document.getElementById(id);
    if (value == input.value) {
        input.value = '';
    }
    else {
        input.value = input.value;
    }
}
function ClearInput2(id){
    obj = MM_findObj(id);
    if(!obj) return;
    obj.value = '';
}
function PostBackOnReturn(event, postbackMethod) {
    if (event) {
        if (event.keyCode == 13) {
            __doPostBack(postbackMethod, '');
        }
    }
}
function setRegion(region) {
    setCookie("RegionInfo",region + "^false",100,"/");
}
function setCookie(name, value, expires, path, domain, secure) {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime(today.getTime());

    /*
    if the expires variable is set, make the correct
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
    */
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));

    document.cookie = name + "=" + value +
    ((expires) ? ";expires=" + expires_date.toGMTString() : "") +
    ((path) ? ";path=" + path : "") +
    ((domain) ? ";domain=" + domain : "") +
    ((secure) ? ";secure" : "");
}
function openWindow(url) {
    window.open(url, 'printorder', 'width=750,height=650,scrollbars=yes,menubar=yes');
}

/*~~~~~~~~~~ gallery lightbox ~~~~~~~~~~*/
var _galleryImageCurrent = 1;
$(document).ready(function() {
    var pageTotal = $('#thumbPanel > a').size();
    //lightbox
    $('#imagePanel').find('div').hide();
    $('#imagePanel').find('div:first-child').show();
    $('#thumbPanel a').click(function() {
        $('#imagePanel').find('div').hide();
        var thisID = $(this).attr('id');
        currentID = thisID.substring(1);
        $('#i' + currentID).show();
        _galleryImageCurrent = currentID;
        updatePage();
        return false;
    });
    $('#fNext').click(function() {
        if (_galleryImageCurrent < pageTotal) {
            _galleryImageCurrent++;
        } else if (_galleryImageCurrent == pageTotal) {
            _galleryImageCurrent = 1;
        }
        $('#imagePanel').find('div').hide();
        $('#i' + _galleryImageCurrent).show();
        updatePage();
        return false;
    });
    $('#fBack').click(function() {
        if (_galleryImageCurrent > 1) {
            _galleryImageCurrent--;
        } else if (_galleryImageCurrent == 1) {
            _galleryImageCurrent = pageTotal;
        }
        $('#imagePanel').find('div').hide();
        $('#i' + _galleryImageCurrent).show();
        updatePage();
        return false;
    });
    updatePage();
});
function updatePage() {
    $('#pageCurr').text(_galleryImageCurrent);
    $('#pageTotal').text($('#imagePanel div').length);
}
function popGallery(index) {
    _galleryImageCurrent = index;
    _buildLightbox();
    $('#imagePanel').find('div').hide();
    $('#i' + _galleryImageCurrent).show();
    updatePage();
}
function _buildLightbox() {
    $('body').append('<div id="galleryOverlay"></div>');
    var sH = $('body').height();
    var sW = $('body').width();
    $("#galleryOverlay").css('height', sH + 'px').css('display', 'block');
    if ($.browser.msie) {
        if ($.browser.version <= 6) {
            $('#galleryOverlay').bgiframe(); // js to fix select boxes in IE 6		
        }
    }
    $('#lightboxContent').fadeIn();
    $('#lightboxContent').css('left', (sW / 2) - ($('#lightboxContent').width() / 2));
    $('html, body').animate({ scrollTop: $("#lightboxContent").offset().top - 10 }, 1000);
    $('#galleryOverlay').click(function() {
        _destroyLightbox()
    });
    $('#lightboxClose').click(function() {
        _destroyLightbox()
    });
};
// ------------------------------------------------------------------------------------
function _destroyLightbox() {
    $('#galleryOverlay').fadeOut(function() {
        $('#galleryOverlay').remove();
    });
    $('#lightboxContent').fadeOut();
    lightboxStatus = false;
};
$(window).resize(function() {
    var sH = $('body').height();
    var sW = $('body').width();
    $("#galleryOverlay").css('height', sH + 'px').css('display', 'block');
    if ($.browser.msie) {
        if ($.browser.version <= 6) {
            $('#galleryOverlay').bgiframe(); // js to fix select boxes in IE 6		
        }
    }
    $('#lightboxContent').css('left', (sW / 2) - ($('#lightboxContent').width() / 2));
});
