var exclude=1;
var agt=navigator.userAgent.toLowerCase();
var win=0;var mac=0;var lin=1;
if(agt.indexOf('win')!=-1){win=1;lin=0;}
if(agt.indexOf('mac')!=-1){mac=1;lin=0;}
var lnx=0;if(lin){lnx=1;}
var ice=0;
var ie=0;var ie4=0;var ie5=0;var ie6=0;var ie7=0;var com=0;var dcm;
var op5=0;var op6=0;var op7=0;
var ns4=0;var ns6=0;var ns7=0;var mz7=0;var kde=0;var saf=0;

if(typeof navigator.vendor!="undefined" && navigator.vendor=="KDE"){
	var thisKDE=agt;
	var splitKDE=thisKDE.split("konqueror/");
	var aKDE=splitKDE[1].split("; ");
	var KDEn=parseFloat(aKDE[0]);
	if(KDEn>=2.2){
		kde=1;
		ns6=1;
		exclude=0;
		}
	}
else if(agt.indexOf('webtv')!=-1){exclude=1;}
else if(typeof window.opera!="undefined"){
	exclude=0;
	if(/opera[\/ ][5]/.test(agt)){op5=1;}
	if(/opera[\/ ][6]/.test(agt)){op6=1;}
	if(/opera[\/ ][7-9]/.test(agt)){op7=1;}
	}
else if(typeof document.all!="undefined"&&!kde){
	exclude=0;
	ie=1;
	if(document.documentElement && typeof document.documentElement.style.maxHeight!="undefined"){
		ie7=1;
	}
	else if(typeof document.getElementById!="undefined"){
		ie5=1;
		if(agt.indexOf("msie 6")!=-1){
			ie6=1;
			dcm=document.compatMode;
			if(dcm!="BackCompat"){com=1;}
			}
		}
	else{ie4=1;}
	}
else if(typeof document.getElementById!="undefined"){
	exclude=0;
	if(agt.indexOf("netscape/6")!=-1||agt.indexOf("netscape6")!=-1){ns6=1;}
	else if(agt.indexOf("netscape/7")!=-1||agt.indexOf("netscape7")!=-1){ns6=1;ns7=1;}
	else if(agt.indexOf("gecko")!=-1){ns6=1;mz7=1;}
	if(agt.indexOf("safari")!=-1 || (typeof document.childNodes!="undefined" && typeof document.all=="undefined" && typeof navigator.taintEnabled=="undefined")){mz7=0;ns6=1;saf=1;}
	}
else if((agt.indexOf('mozilla')!=-1)&&(parseInt(navigator.appVersion)>=4)){
	exclude=0;
	ns4=1;
	if(typeof navigator.mimeTypes['*']=="undefined"){
		exclude=1;
		ns4=0;
		}
	}
if(agt.indexOf('escape')!=-1){exclude=1;ns4=0;}
if(typeof navigator.__ice_version!="undefined"){exclude=1;ie4=0;}

function getElementSafe(idIn)
{
	var retval;
	var id;
	id = idIn;
	
	if(document.getElementById){
		retval = document.getElementById(id);
	}
	else if(document.all){
		retval = document.all[id];
	}
	else if(document.layers)
	{
		retval = document.layers[id];
	}
	
	if (retval == null)
	{
		id = 'ctl00_MainContentPlaceHolder_' + idIn;
		if(document.getElementById){
			retval = document.getElementById(id);
		}
		else if(document.all){
			retval = document.all[id];
		}
		else if(document.layers)
		{
			retval = document.layers[id];
		}
	}
	
	return retval;
}

function returnObjById(id)
{
    if (document.getElementById)
        var returnVar = document.getElementById(id);
    else if (document.all)
        var returnVar = document.all[id];
    else if (document.layers)
        var returnVar = document.layers[id];
    return returnVar;
}

/* Gets the window position for IE and Firefox, at least */
function windowLeft() {return typeof window.screenLeft != 'undefined' ? window.screenLeft : typeof window.screenX != 'undefined' ?  window.screenX : 0;} 
function windowTop() {return typeof window.screenTop != 'undefined' ? window.screenTop : typeof window.screenY != 'undefined' ?  window.screenY : 0;} 

function popUp(url, width, height, menubar, name, top, left) 
{
	var strName;
	if(!top)
	{
		if(height)
		{
			top = (screen.height / 2 - height / 2);
			if(document.body.offsetHeight == height)
			{
				top += 50;
				if(Math.abs(windowTop() - top) < 50)
				{
					top += 50;
				}
			}
		}
		else
			top = 50;
	}
	if(!left)
	{
		if(width)
		{
			left = (screen.width / 2 - width / 2);
			if(document.body.offsetWidth == width)
			{
				left += 50;
				if(Math.abs(windowLeft() - left) < 50)
				{
					left += 50;
				}
			}
		}
		else
			left = 100;
	}
	if(name) strName = name; else strName = "popup"
	if(menubar)
	{
		var winObj = window.open(url,strName,'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=no,resizable=yes,copyhistory=yes,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height);
		winObj.focus();
	}
	else
	{
		var winObj = window.open(url,strName,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height);
		winObj.focus();
	}
}

function popUpWithScrollBars(url, width, height, menubar, name, top, left) 
{
	var strName;
	if(!top)
	{
		if(height)
		{
			top = (screen.height / 2 - height / 2);
			if(document.body.offsetHeight == height)
			{
				top += 50;
				if(Math.abs(windowTop() - top) < 50)
				{
					top += 50;
				}
			}
		}
		else
			top = 50;
	}
	if(!left)
	{
		if(width)
		{
			left = (screen.width / 2 - width / 2);
			if(document.body.offsetWidth == width)
			{
				left += 50;
				if(Math.abs(windowLeft() - left) < 50)
				{
					left += 50;
				}
			}
		}
		else
			left = 100;
	}
	if(name) strName = name; else strName = "popup"
	if(menubar)
	{
		var winObj = window.open(url,strName,'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height);
		winObj.focus();
	}
	else
	{
		var winObj = window.open(url,strName,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height);
		winObj.focus();
	}
}

function popUpDrilldown(url,name, width, height)
{
	if (width == null)
		width = 800;
	if (height == null)
		height = 600;
	popUp(url, width, height, false, name);
}
function popUpDrilldownWithScrolls(url,name, width, height)
{
	if (width == null)
		width = 800;
	if (height == null)
		height = 600;
	popUpWithScrollBars(url, width+20, height, false, name);
}

function popUpConfirmation(url,name)
{
	popUp(url, 360, 240, false, name);
}

function popUpLookup(url,hiddenName)
{
	var retVal = false;
	var returnId = "";
	returnId = window.showModalDialog(url,'','dialogHeight:400px;dialogWidth:500px');
	if(returnId != "" && returnId != undefined)
	{
		var hiddenField = document.getElementById(hiddenName);
		hiddenField.value = returnId;
		retVal = true;
	}
	return(retVal);
}

function resetDivHeight(divName, lessHeight)
{
	var divElement = getElementSafe(divName);
//	if(!divElement)
//		alert('could not find ' + divName);
	var divHeight = document.body.clientHeight - lessHeight;
	if(divHeight > 0)
		divElement.style.height = divHeight + 'px';
}

function resetDivWidth(divName, lessWidth)
{
	var divElement = getElementSafe(divName);
//	if(!divElement)
//		alert('could not find ' + divName);
	var divWidth = document.body.clientWidth - lessWidth;
	if(divWidth > 0)
		divElement.style.width = divWidth + 'px';
}

function resetDivAbsoluteHeight(divName, absHeight)
{
	var divElement = getElementSafe(divName);
//	if(!divElement)
//		alert('could not find ' + divName);
	if(absHeight > 0)
		divElement.style.height = absHeight + 'px';
}
function resetDivAbsoluteWidth(divName, absWidth)
{
	var divElement = getElementSafe(divName);
//	if(!divElement)
//		alert('could not find ' + divName);	
	if(absWidth > 0)
	{
		divElement.style.width = absWidth + 'px';
	}
}

function addEvent(obj, evType, fn)
{
    //alert('addEvent, obj = ' + obj + ', fn = ' + fn);
	if (obj.addEventListener)
	{
	  obj.addEventListener(evType, fn, false); 
	  return true; 
	}
	else if (obj.attachEvent)
	{ 
	  var r = obj.attachEvent("on"+evType, fn); 
	  return r; 
	}
	else
	{ 
	  return false; 
	} 
}

/* for Dev purposes */
function showWidth(control)
{
	alert(control.id + '\'s width = ' + control.offsetWidth);
}
function showHeight(control)
{
	alert(control.id + '\'s height  = ' + control.offsetHeight);
}

var pageHeaderHeight = 63;
var gutterCurveTopHeight = 30;
var searchBarAreaHeight = 33;
var listToolbarHeaderHeight = 38;
var listToolbarHeight = 34;
var listColumnHeight = 21;
var listPageTable = 21;
var gridFooterHeight = 20;
var listFooterHeight = 12;
var pageFooterHeight = 46;
var bottomMargin = 17; // offset by 7 for firefox

/* Fix IE Background Image Flicker */
if (ie) {
	try {
		document.execCommand("BackgroundImageCache", false, true);
	} catch(e) {}
}

var topBannerOffsetHeight = 56;
var pageToolbarOffsetHeight = 32;
var contentFooterOffsetHeight = 37;
var footerOffsetHeight = 31;

var offsetContentHeight = function() {
    var offset = topBannerOffsetHeight
                + pageToolbarOffsetHeight
                + getTotalFooterOffsetHeight(null);
    return offset;
}

function getTotalFooterOffsetHeight(customContentFooterClientId) {
    retVal = contentFooterOffsetHeight + footerOffsetHeight;
    
    var customContentFooter = getElementSafe(customContentFooterClientId);
    if(customContentFooter != null)
        retVal = customContentFooter.offsetHeight;
        
     return retVal;
}

function getContentWidthOffset() {
    var offset = 170    // left hand navigation, not including border
                + 6;     // right hand gutter, not including border
//    offset = 300;
    return offset;
}

var getElementIdsThatNeedWidthResizing = function()
{
    var widthArray = new Array();
    //widthArray[0] = 'contentWrapper';
    //widthArray[1] = 'ctl00_contentCell';
    //widthArray[0] = 'ctl00_MainContentPlaceHolder_pageToolbar_pageToolbarWrapper';
    return widthArray;
}
var getElementIdsThatNeedWidthResizingNoBorder = function()
{
    var widthArray = new Array();
    //widthArray[0] = 'ctl00_MainContentPlaceHolder_tab_tabStripTable';
    return widthArray;
}

var getContentWrapperIds = function()
{
    var contentWrapperArray = new Array();
    //contentWrapperArray[0] = 'contentWrapper';
    return contentWrapperArray;
}

function resizeContentWrapper()
{


    //resizeContentWrapperOveride();
    
	   // resizeGridToContentWidth();

}
var resizeContentWrapperOveride = function() {
    //resizeContentWrapperHelper();
}

function resizeContentWrapperHelper()
{
//    var myWidth = document.body.clientWidth;
//    if(typeof(document.documentElement) != "undefined")
//        myWidth = document.documentElement.clientWidth;
	                    
//	curWidth = document.documentElement.clientWidth;
//	curHeight = document.documentElement.clientHeight;
//	if (curWidth < 20)
//		curWidth = self.innerWidth;
//	if (curHeight < 20)
//		curHeight = self.innerHeight;
//		
//	var contentWrapperWidth = curHeight - offsetContentHeight();
//	var contentWrapperIds = getContentWrapperIds();
//    for(var x = 0; x < contentWrapperIds.length; x++)
//    {
//        resetDivAbsoluteHeight(contentWrapperIds[x], contentWrapperWidth);
//    }
	//resetDivAbsoluteWidth('contentWrapper', curWidth - getContentWidthOffset());
	
	//var mainTable = document.getElementById('mainTable');
	//mainTable.width = curWidth;
	//mainTable.style.width = curWidth + 'px';
	
//	var elementIdsThatNeedWidthResizing = getElementIdsThatNeedWidthResizing();
//	for(var i = 0; i < elementIdsThatNeedWidthResizing.length; i++)
//	{
//	    //resetDivAbsoluteWidth(elementIdsThatNeedWidthResizing[i], curWidth - getContentWidthOffset() + 4);
//	}
//	
//	var elementIdsThatNeedWidthResizingNoBorder = getElementIdsThatNeedWidthResizingNoBorder();
//	for(var i = 0; i < elementIdsThatNeedWidthResizingNoBorder.length; i++)
//	{
//	    //resetDivAbsoluteWidth(elementIdsThatNeedWidthResizingNoBorder[i], curWidth - getContentWidthOffset() + 6);
//	}
	
	//alert('about to set ctl00_contentCell to be ' + (curWidth - getContentWidthOffset()));
	//resetDivAbsoluteWidth('ctl00_contentCell', curWidth - getContentWidthOffset());
	//alert('now it is ' + document.getElementById('ctl00_contentCell').offsetWidth);
	
	//var contentWrapperDiv = getElementSafe('contentWrapper');
	//var contentCellTd = getElementSafe('ctl00_contentCell');
	

//    alert('A: contentWrapperDiv width=' + contentWrapperDiv.offsetWidth + ', contentCellTd width=' + contentCellTd.offsetWidth);
//	resetDivAbsoluteWidth('contentWrapper', myWidth - getContentWidthOffset());
//	alert('B: contentWrapperDiv width=' + contentWrapperDiv.offsetWidth + ', contentCellTd width=' + contentCellTd.offsetWidth);
//	resetDivAbsoluteWidth('contentCell', myWidth - getContentWidthOffset());
//	alert('C: contentWrapperDiv width=' + contentWrapperDiv.offsetWidth + ', contentCellTd width=' + contentCellTd.offsetWidth);
}

var ctrlPressed=0;
var altPressed=0;
var shiftPressed=0;
function mouseDown(e)
{
	if (parseInt(navigator.appVersion)>3)
	{
		if (navigator.appName=="Netscape") 
		{
			if(parseInt(navigator.appVersion) < 5)
			{
				var mString = (e.modifiers+32).toString(2).substring(3,6);
				shiftPressed = (mString.charAt(0)=="1");
				ctrlPressed = (mString.charAt(1)=="1");
				altPressed  = (mString.charAt(2)=="1");
			}
			else
			{
				shiftPressed = e.shiftKey;
				altPressed = e.altKey;
				ctrlPressed = e.ctrlKey;
			}
		}
		else
		{
			shiftPressed = event.shiftKey;
			altPressed  = event.altKey;
			ctrlPressed = event.ctrlKey;
		}
	}
	return true;
}

if (parseInt(navigator.appVersion)>3)
{
	document.onmousedown = mouseDown;
	if (navigator.appName=="Netscape") 
		document.captureEvents(Event.MOUSEDOWN);
}

function enterPressSubmit(buttonId)
{
	if (window.event && window.event.keyCode == 13)
	{
		var submitButton = document.getElementById(buttonId);
		if (submitButton)
			submitButton.click();
		else 
			alert('Javascript Error: "' + buttonId + '" button does not exist.  Form can not be submitted using the Enter key.')
		return false;
	}
	else
		return true;
}

function RefreshMicroStrategyIFrames()
{
    var iframes = document.getElementsByTagName('iframe');
    var len = iframes.length;
    for (var i=0; i<len; i++)
    {
        iframeId = iframes[i].id;
        var iframe = getElementSafe(iframeId);
        iframe.src = iframe.src;
    }
}

function StopEventBubble(e)
{
    if (!e) 
        var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) 
        e.stopPropagation();
}




var PCON_gridWrapperId = "";
function resizeGridToContentWidth(gridWrapper)
{

    //if(typeof(PCON_gridWrapperId) == undefined || PCON_gridWrapperId == null || PCON_gridWrapperId == "") return;

    //var gridWrapper = document.getElementById(PCON_gridWrapperId);
    //var contentDiv = document.getElementById("contentWrapper");
    
    //gridWrapper.style.width = (document.documentElement.clientWidth - getContentWidthOffset () - 25) + "px";

    //gridWrapper.style.height = (document.documentElement.clientHeight - offsetContentHeight() - 120) + "px";
    
}