//http://rafael.adm.br/css_browser_selector/
var css_browser_selector = function() {var ua=navigator.userAgent.toLowerCase(),is=function(t){return ua.indexOf(t) != -1;},h=document.getElementsByTagName('html')[0],b=(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?'gecko ff2':is('firefox/3')?'gecko ff3':is('gecko/')?'gecko':is('opera/9')?'opera opera9':/opera\s(\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('chrome')?'chrome webkit safari':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';var c=b+os+' js'; h.className += h.className?' '+c:c;}();

function UpdateMessageBox(header, details)
{
    FindById('MessageHeader').innerHTML = header;
    FindById('MessageInfo').innerHTML = details;
}
function GoToUrl(url)
{
    document.location.href = url;
}

function ChangeText(mode, imageSuffix, txtControlId)
{
    if(imageSuffix == null) imageSuffix = "Image";
    if(txtControlId == null) txtControlId = "BodyText";

    FindById(txtControlId).className = mode + "SizedText PaddedBottom";
    FindById('Small' + imageSuffix).src = "/_images/g_SmallA_Unselected.gif";
    FindById('Medium' + imageSuffix).src = "/_images/g_MediumA_Unselected.gif";
    FindById('Large' + imageSuffix).src = "/_images/g_LargeA_Unselected.gif";
    
    FindById(mode + imageSuffix).src = "/_images/g_" + mode + "A_Selected.gif";
    PageMethods.ChangeTextSize(mode);
}

function AddOnResize(func)
{
    oldOnResize = window.onresize; 
    if (typeof window.onresize != 'function') 
    {     
        window.onresize = function() 
        {
            func();  
        } 
    }
    else 
    {     
        window.onresize = function() 
        {         
            oldOnResize();  
            func();
        }
    } 
}
AddOnResize(function()
{
    if(FindById('grayArea') && FindById('grayArea').style.display == "inline")
    {
        ResizeOverlay('MessageDIV');
    }
});

if(!Array.indexOf)
{
    Array.prototype.indexOf = function(obj){
        for(var i=0; i<this.length; i++){
            if(this[i]==obj){
                return i;
            }
        }
        return -1;
    }
}
function FindById(id)
{
    var obj = document.getElementById(id);
    if(obj == null)
        obj = document.getElementById("ctl00_" + id);
    if(obj == null)
        obj = document.getElementById("ctl00_ContentPlaceHolder1_" + id);
    return obj;
}

function Reset(arg)
{
    if(confirm("Are you sure you want to reset form?"))
    {
        document.location.href = arg;
    }
}
function popAtMouse(width, height, url)
{
    var topPos = event.screenY - (height/2);
	var leftPos = event.screenX - (width/2);
	
	var settings = 'width=' + width + ',height=' + height + ',location=no,directories=no,menubar=no,toolbar=no,' +
	    'status=no,scrollbars=no,resizable=no,dependent=no,top=' + topPos + ',left=' + leftPos;

    calWindow=open(url, 'calendarWin', settings);
    if (calWindow.opener == null) 	calWindow.opener = self;
}
function popCentered(width, height, url)
{
    var topPos = (screen.availHeight)/2 - (height/2);
    var leftPos = (screen.availWidth)/2 - (width/2);
    var settings = 'width=' + width + ',height=' + height + ',location=no,directories=no,menubar=no,toolbar=no,' +
        'status=no,scrollbars=yes,resizable=yes,dependent=yes,top=' + topPos + ',left=' + leftPos;
    calWindow=open(url,'win2',settings);
    if (calWindow.opener == null) calWindow.opener = self;
}

function BackToIndex()
{
    if(confirm('Are you sure you want to cancel?'))
    {
        document.location.href = "Index.aspx";
    }
}
function ClearRows(tbl, start)
{
    row = tbl.rows[start];
    while(row)
    {
        row = tbl.deleteRow(start);
        row = tbl.rows[start];
    }
}
var timeout = false;
function SelectTab(tabID, index)
{
    if(timeout)
    {
        var tabStrip = eo_GetObject(tabID);
        var totalCount = tabStrip.getTopGroup().getItemCount();
        if (totalCount == 0)
            return;
        if(totalCount <= index)
            index = 0;
        tabStrip.setSelectedIndex(index);
    }
    else
    {
        timeout = true;
        setTimeout("SelectTab('" + tabID + "', " + index + ")", 50);
    }
}
function DisplayScreen(mode, grayBoxID, boxID)
{
    var backScreen = document.getElementById(grayBoxID);
    var box = document.getElementById(boxID);
    
    if (mode)
    {
        box.style.display = "inline";
        backScreen.style.display = "inline";
    }
    else 
    
    {
        box.style.display = "none";
        backScreen.style.display = "none";
        return;
    }
    
    backScreen.style.width = screen.availWidth + "px";
    backScreen.style.height = document.body.clientHeight + "px";
    
    var top = (screen.availHeight / 2 - parseInt(box.offsetHeight, 10) /2) + document.documentElement.scrollTop - 50;
    var left = screen.availWidth / 2 - parseInt(box.style.width, 10) /2;
    
    box.style.top = top + "px";
    box.style.left = left + "px";
}
function flipWith(eventCB, otherID)
{
    eventCB.checked = true;
    FindById(otherID).checked = false; 
}
function DisplayTable(id)
{
    FindById("ctl01_WeeklyTable").style.display = "none";
    FindById("ctl01_MonthlyTable").style.display = "none";
    FindById("ctl01_YearlyTable").style.display = "none";
    
    FindById("ctl01_" + id + "Table").style.display = "inline";
}
function checkTime(obj, period)
{
    var error = false; 
    if(obj.value != "")
    {
        obj.className = "";    
        if(obj.value.length > 5){ error = true; }
        else
        {
            if(obj.value.length <= 2)
                obj.value = obj.value + ":00";
                
            if(obj.value.indexOf(":") == -1)
            {
                if(obj.value.length == 3){ obj.value = "0" + obj.value; }
                obj.value = obj.value.substring(0, 2) + ":" + obj.value.substring(2, 4);
            }
            else if(obj.value.length == 4)
                obj.value = "0" + obj.value;
            
            var hour = parseInt(obj.value.substring(0, 2));
            if(hour >= 12)
            {
                if(hour%12 != 0){ obj.value = hour%12 + obj.value.substring(2, 5); }
                period.selectedIndex = 1;
            }
        }
        if(obj.value.length == 4) obj.value = "0" + obj.value;
        
        if(error)
        {
            obj.value = "";
            alert("Please enter a valid time.");
        }
    }
    else error = true;
    return !error;
}
function toggleOverlay(objId, show)
{
    var mode1 = "inline", mode2 = "none";
    if(show)
    {
        mode1 = "none";
        mode2 = "inline";
        ResizeOverlay(objId);
    }

    FindById('grayArea').style.display = mode2;
    if (show) FindById('grayArea').focus();
    FindById(objId).style.display = mode2;
    
    if(typeof toggleDropDowns == 'function') 
        toggleDropDowns(mode1);
}
function ResizeOverlay(objId)
{
    var top = (screen.availHeight / 2 - 500 /2) + document.documentElement.scrollTop;
    var left = screen.availWidth / 2 - 500 /2;
    
    FindById('grayArea').style.height = document.documentElement.scrollHeight + "px";
    FindById('grayArea').style.width = document.documentElement.clientWidth + "px";

    FindById(objId).style.top = top + "px";
    FindById(objId).style.left = left + "px";
}
function AjaxFailure(response) { }