﻿
var m_intMinPageWidth	= 1005;
var m_intMinPageHeight	= 550;
var mapisvisible = true;
var prevTab = "";
var currTab = "";
var expanded = "";
var sideTabSelected = "";
var blnResizing = false;
var argsQueryString = {};
var btnShareThis = null;
dojo.addOnLoad(OnLoad);

var MapIt = {};
MapIt.hide = function(layerID){
    l = dojo.byId(layerID);
    if(l) l.style.visibility="hidden";
}
MapIt.show = function(layerID){
    l = dojo.byId(layerID);
    if(l) l.style.visibility="visible";
}

function OnLoad()
{
    BrowserDetect.init();
    if(BrowserDetect.browser =="Explorer" && BrowserDetect.version=="6") 
        window.setTimeout('alert("We have found that Internet Explorer version 6 does not perform as well\\nas newer browser versions. We recommend you upgrade to Internet Explorer\\nversion 7 or use Firefox for an improved user experience.")',800);
    
    GACTInit();
    showLayer("BusyIndicator");
    
	top.tabstripLeft.OnClientTabSelected = OnTabSelectedHandler;
	top.tabstripRight.OnClientTabSelected = OnTabSelectedHandler;
	sidetabLeft.OnClientTabSelected = OnSideTabSelectedHandler;
	sidetabRight.OnClientTabSelected = OnSideTabSelectedHandler;
	hideRadTab('DemoDetails');
	
	initBAO();
	
	argsQueryString.PropID = getQueryStringVariable("PropID");
    argsQueryString.PropX = getQueryStringVariable("PropX");
    argsQueryString.PropY = getQueryStringVariable("PropY");
    argsQueryString.secure = getQueryStringVariable("Secure");
    dojo.subscribe("mapLoadedEvent", "onMapLoad");
	
	//window.setTimeout('GACTInit();',10);
	window.setTimeout('ResizeMain();', 50);
	window.setTimeout('initMap();',150);
	window.setTimeout('setResize();', 250);
    
    var units = document.getElementById('bbusSearchForm_siteUnits').value;
    setUnits(1, units);
    
    window.setTimeout('document.getElementById("lblFooter").focus();document.getElementById("lblFooter").blur();',100);
}
function onMapLoad()
{
    
	dojo.unsubscribe("mapLoadedEvent");
    
    loadAddThis();
    var setTab = getQueryStringVariable("TabID");
    if(setTab!=null) selectRadTab(setTab);
    
    if(argsQueryString.PropID!=null) gotoPropertyDetails(argsQueryString.PropID, argsQueryString.PropX, argsQueryString.PropY);
    
}


//var resizeTimer=setTimeout(resizeHandler,1);
function resizeHandler(){
    window.onresize = function() {
        OnResize();
        window.onresize = function() {;};
        clearTimeout(resizeTimer);
        resizeTimer=setTimeout(resizeHandler,1);
    }
}

function setResize()
{

    window.onresize = OnResize;
}

function OnResize()
{
    DoResizing();
    
}
function DoResizing()
{
    ResizeMain();
    // resize controls inside panes
	
	
    window.setTimeout('ResizeMap();',10);
    
}
function ResizeMain()
{
    resizePanes();
    
	resizeLeftPaneControls();
	resizeRightPaneControls();
}
function resizePanes()
{
	// calculate the width of the page
	var intPageWidth  = GetViewportWidth();
	var intPageHeight = GetViewportHeight();
    
	if (intPageWidth  < m_intMinPageWidth)	intPageWidth  = m_intMinPageWidth;
	if (intPageHeight < m_intMinPageHeight)	intPageHeight = m_intMinPageHeight;

	var divResize = document.getElementById('divResize');
	if (divResize)
	{
		divResize.style.width  = intPageWidth + "px";
		divResize.style.height = intPageHeight + "px";
	}

	var intMaxPaneWidth = intPageWidth;
    var paneLeftMargin = document.getElementById('paneLeftMargin');
    var paneRightMargin = document.getElementById('paneRightMargin');
    if (paneLeftMargin)
	{    intMaxPaneWidth = intMaxPaneWidth - paneLeftMargin.offsetWidth - paneLeftMargin.offsetWidth;
	}
	var paneMiddle = document.getElementById('paneMiddle');
	if (paneMiddle)
	{    intMaxPaneWidth = intMaxPaneWidth - paneMiddle.offsetWidth;
	} 
	

	var paneHeader = document.getElementById('paneHeader');
    var paneHeight = intPageHeight;// - 40;
    if (paneHeader)
	{    paneHeight = paneHeight - paneHeader.offsetHeight;
	}
	var paneTopMargin = document.getElementById('paneTopMargin');
	if (paneTopMargin)
	{   paneHeight = paneHeight - paneTopMargin.offsetHeight - paneTopMargin.offsetHeight;
	}
	var paneFooter = document.getElementById('divFooter');
	if (paneFooter)
	{   paneHeight = paneHeight - paneFooter.offsetHeight;
	}

	// resize the right pane
	var paneLeft  = document.getElementById('paneLeft');
	var paneLeftBody  = document.getElementById('paneLeftBody');
	var paneRight = document.getElementById('paneRight');
	var paneRightBody = document.getElementById('paneRightBody');
	var paneMiddle  = document.getElementById('paneMiddle');
    if (paneLeft && paneRight)
	{
		var curLeftTab = tabstripLeft.SelectedTab.Value;
	    var arrPanesText = document.getElementById("panesText").value.split(",");
        var arrPanesWidth = document.getElementById("panesWidth").value.split(",");
        var plWidth = 360;
        for (var ap in arrPanesText)
        {
            if(curLeftTab == arrPanesText[ap])
                plWidth = arrPanesWidth[ap];
        }
        
        var intMaxRightPaneWidth = intMaxPaneWidth - plWidth;
        if (paneMiddle.offsetWidth == 0) intMaxRightPaneWidth -= paneMiddle.clientWidth;
	
	    tabstripLeft.DomElement.style.width=plWidth + "px";
        tabstripRight.DomElement.style.width=intMaxRightPaneWidth + "px";
	    sidetabLeft.DomElement.style.display = "";
	    sidetabRight.DomElement.style.display = "";
	    sidetabLeft.DomElement.style.width=plWidth + "px";
        sidetabRight.DomElement.style.width=intMaxRightPaneWidth + "px";
            
	    if (paneLeft.style.display == 'none')
		{
			paneRight.style.width = (intMaxPaneWidth) + "px";
			tabstripRight.DomElement.className = tabstripRight.DomElement.className + " FloatRight";
			
	        hideSideTabs(sidetabRight); 
		}
		else if (paneRight.style.display == 'none')
		{
			paneLeft.style.width = (intMaxPaneWidth) + "px";
			paneLeftBody.style.width = (intMaxPaneWidth) + "px";
			sidetabRight.DomElement.className = tabstripRight.DomElement.className + " FloatRight";
			
			hideSideTabs(sidetabLeft); 
		}
		else
		{
		    paneRight.style.width = (intMaxPaneWidth - plWidth) + "px";
			paneLeft.style.width  = plWidth + "px";
			paneLeftBody.style.width = plWidth + "px";
	        tabstripRight.DomElement.className = tabstripRight.DomElement.className.replace(" FloatRight","");
			sidetabRight.DomElement.className = tabstripRight.DomElement.className.replace(" FloatRight","");
			hideSideTabs(sidetabLeft); 
			hideSideTabs(sidetabRight); 
		}

        paneLeft.style.height  = paneHeight + "px";
		paneRight.style.height = paneHeight + "px";
		paneMiddle.style.height = paneHeight + "px";
		paneLeftMargin.style.height = paneHeight + "px";
		paneRightMargin.style.height = paneHeight + "px";
		var tabStripLeft = document.getElementById('tabstripLeft');
		var tabStripRight = document.getElementById('tabstripRight');
		paneLeftBody.style.height = (paneHeight - tabStripLeft.offsetHeight) + "px";
		paneRightBody.style.height = (paneHeight - tabStripRight.offsetHeight) + "px";
		paneLeftBody.style.height = (paneLeftBody.style.pixelHeight + paneLeftBody.clientHeight - paneLeftBody.offsetHeight) + "px";
		paneRightBody.style.height = (paneRightBody.style.pixelHeight + paneRightBody.clientHeight - paneRightBody.offsetHeight) + "px";
		var multipageLeft = document.getElementById('multipageLeft');
		var multipageRight = document.getElementById('multipageRight');
		multipageLeft.style.height = paneLeftBody.clientHeight + "px";
		multipageRight.style.height = paneRightBody.clientHeight + "px";
		
	}

	paneLeft.style.visibility	= 'visible';
	paneRight.style.visibility	= 'visible';

	var divFooter = document.getElementById('divFooter');
	divFooter.style.width		= intPageWidth;
	divFooter.style.visibility	= 'visible';
}

	function GetViewportWidth()
	{
		// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
		if (typeof window.innerWidth != 'undefined')
			return window.innerWidth;

		// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
		else if ((typeof document.documentElement != 'undefined') && 
				 (typeof document.documentElement.clientWidth != 'undefined') && 
				 (document.documentElement.clientWidth != 0))
			return document.documentElement.clientWidth;

		// older versions of IE
		else
			return document.getElementsByTagName('body')[0].clientWidth;
	}
	
	function GetViewportHeight()
	{
		// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
		if (typeof window.innerHeight != 'undefined')
			return window.innerHeight;

		// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
		else if ((typeof document.documentElement != 'undefined') && 
				 (typeof document.documentElement.clientHeight != 'undefined') && 
				 (document.documentElement.clientHeight != 0))
			return document.documentElement.clientHeight;

		// older versions of IE
		else
		{
			return document.getElementsByTagName('body')[0].clientHeight;
		}
	}

function ResizeMap()
{
    var mapDiv = document.getElementById('divMap');
    if (mapDiv)
    {    
        mapDiv.style.width = "100%";
    } 
    var jsMapDiv = document.getElementById('jsMap');
    if (jsMapDiv)
    {    
        jsMapDiv.style.height = "100%";
        jsMapDiv.style.width = "100%";
    } 
    if (jsMap)
    {	if (jsMap.loaded)
        {
            blnResizing = true;
            jsMap.resize();
        }
    }
    
}

function RepositionMap()
{
    if (jsMap)
    {	if (jsMap.loaded)
        {
            jsMap.reposition();
        }
    }
}
function closeRadWindow()
{
	var winManager = top.GetRadWindowManager();
	if (!winManager)	return;
	
	var activeWindow = winManager.GetActiveWindow();
	if (!activeWindow)	return;

	activeWindow.Close();
}



function resizeRightPaneControls()
{
	resizePaneControls("right");
}
function resizeLeftPaneControls()
{
	resizePaneControls("left");
}
function resizePaneControls(side)
{
    var arrPanesSide = document.getElementById("panesSide").value.split(",");
	var arrPanesResize = document.getElementById("panesResize").value.split(",");
	for (var ap in arrPanesSide)
	{
	    if(arrPanesSide[ap]==side)
	        eval(arrPanesResize[ap]);
	}
}

function ResizeInPane(strPaneId, strToResizeId, intMinWidth, intMinHeight, intTop, intFooterHeight)
{
	// get the container DIV
	var divPane	= document.getElementById(strPaneId);
	// get the item DIV
	var divToResize	= document.getElementById(strToResizeId);

	if (!divPane)		return (null);
	if (!divToResize)	return (null);

	// get the size of the container DIV
	var intPaneWidth  = divPane.clientWidth;
	var intPaneHeight = divPane.clientHeight;
	if (!intPaneWidth) intPaneWidth = divPane.offsetWidth;
	if (!intPaneHeight) intPaneHeight = divPane.offsetHeight;
	if (!intPaneWidth && divPane.style.width && (divPane.style.width.length > 0))
		intPaneWidth  = parseInt(divPane.style.width,10);
	if (!intPaneHeight && divPane.style.height && (divPane.style.height.length > 0))
		intPaneHeight = parseInt(divPane.style.height,10);

	//if (intTop > 150)	intTop = 150;
    //if (intTop < 0)
	///{
	    intTop = 0;
	    var tempdiv = divToResize;
        if (tempdiv.offsetParent) 
        {
            do 
            {
			    intTop += tempdiv.offsetTop;
			    tempdiv = tempdiv.offsetParent;
			} while (tempdiv.id != divPane.id);

        }
	//}
	    var tempdiv = divToResize;
        if (tempdiv.offsetParent) 
        {
            do 
            {
			    intPaneWidth -= tempdiv.offsetLeft;
			    tempdiv = tempdiv.offsetParent;
			} while (tempdiv.id != divPane.id);

        }
        
	// resize the area
	if (intPaneWidth  < intMinWidth)	intPaneWidth  = intMinWidth;
	if (intPaneHeight < intMinHeight)	intPaneHeight = intMinHeight;

    var newheight = intPaneHeight - intTop - intFooterHeight;
    newheight = (newheight < 0)? 0 : newheight;

	var arrSize = new Array(intPaneWidth, newheight );
    //alert(divToResize.id + ': ' + arrSize[0] + ' x ' + arrSize[1]);
	if (divToResize)
	{
		divToResize.style.width  = arrSize[0] + "px";
		divToResize.style.height = arrSize[1] + "px";
		divToResize.style.display = '';
	}
	
	return (arrSize);	
}

function OnTabSelectedHandler(sender, eventArgs)
{
	currTab = eventArgs.Tab.Value;
	if(eventArgs.PreviousTab!=null)prevTab = eventArgs.PreviousTab.Value;
	else prevTab = currTab;
	var arrPanesText = document.getElementById("panesText").value.split(",");
	var arrPanesClick = document.getElementById("panesClick").value.split(",");
	for (var ap in arrPanesText)
	{
	    if(currTab == arrPanesText[ap])
	        eval(arrPanesClick[ap]);
	}
	
}

function expandRightPane()
{
	window.onresize = null;
	
	// to expand the right plane, we need to collapse the left pane
	hidePane('paneLeft'); 
	hidePane('paneMiddle'); 
	
	hideSideTabs(sidetabRight); 
	showSideTabs(sidetabLeft,tabstripLeft,"left"); 

	expandPaneControls("right")
	expanded = "right";
	
	resizePanes();	
	ResizeMain();
	RepositionMap();
	ResizeMap();
	
	window.setTimeout('setResize()',100);
}

function expandLeftPane()
{
	window.onresize = null;
	
	// to expand the left plane, we need to collapse the right pane
	hidePane('paneMiddle');
	hidePane('paneRight');
	
	hideSideTabs(sidetabLeft); 
	showSideTabs(sidetabRight,tabstripRight,"right"); 

	expandPaneControls("left")
	expanded = "left";
	
	resizePanes();	
	ResizeMain();
	
	window.setTimeout('setResize()',100);
}
function expandPaneControls(side)
{
    var arrPanesSide = document.getElementById("panesSide").value.split(",");
	var arrPanesExpand = document.getElementById("panesExpand").value.split(",");
	for (var ap in arrPanesSide)
	{
	    if(arrPanesSide[ap]==side)
	        eval(arrPanesExpand[ap]);
	}
}
function collapsePaneControls()
{
    var arrPanesCollapse = document.getElementById("panesCollapse").value.split(",");
	for (var ap in arrPanesCollapse)
	{
	    eval(arrPanesCollapse[ap]);
	}
}


function restorePanes()
{
	window.onresize = null;
	
	showPane('paneRight');
	showPane('paneMiddle');
	showPane('paneLeft');

    collapsePaneControls();
	expanded = "";
	
	//OnResize();
	//Resize Twice to ensure that no white space appears in the scrollbar area
	resizePanes();	
	ResizeMain();
	
	if(mapisvisible)
	{
   	    RepositionMap();
	    ResizeMap();
	}
	
	mapisvisible=true;

	window.setTimeout('setResize()',200);
	
}

function hidePane(pane)
{
	var paneToHide = top.document.getElementById(pane);
	
	if (paneToHide)
		paneToHide.style.display = 'none';  
}

function showPane(pane)
{
	var paneToShow = top.document.getElementById(pane);
	
	if (paneToShow)
		paneToShow.style.display = '';  
}

function swapDIV(strId, strShowState)
{
	divCollapse	= document.getElementById(strId + '_Collapse');
	divExpand	= document.getElementById(strId + '_Expand');

	if (divCollapse && divExpand)
	{
		if (!strShowState)
			strShowState = (divCollapse.style.display == 'none') ? 'collapse' : 'expand';

		divExpand.style.display	  = (strShowState == 'collapse') ? 'none' : '';
		divCollapse.style.display = (strShowState == 'expand')	 ? 'none' : '';
	}
}


function getRadTab(strTabValue)
{
	var tab = tabstripLeft.FindTabByValue(strTabValue);
	if (!tab)
		tab = tabstripRight.FindTabByValue(strTabValue);


	return tab;
}
function hideRadTab(strTabValue)
{
	var tab = getRadTab(strTabValue);

	if (tab)
	{
	    tab.Disable;
		tab.DomElement.style.display="none";
	}
}
function showRadTab(strTabValue)
{
	var tab = getRadTab(strTabValue);

	if (tab)
	{
	    tab.Enable;
		tab.DomElement.style.display="block";
	}
}
function selectRadTab(strTabValue)
{
	var tab = getRadTab(strTabValue);

	if (tab)
	{
		tab.Enable();
		tab.Select();
	}
}
function unselectRadTab(strTabValue)
{
	var tab = getRadTab(strTabValue);

	if (tab)
	{
		tab.UnSelect();
	}
}

function enableRadTab(strTabValue)
{
	var tab = getRadTab(strTabValue);

	if (tab)
		tab.Enable();
}

function disableRadTab(strTabValue)
{
	var tab = getRadTab(strTabValue);

	if (tab)
		tab.Disable();
}

function OnSideTabSelectedHandler(sender, eventArgs)
{
    restorePanes();
    if(currTab!="")
    {
        var tab = getRadTab(currTab);
        tab.UnSelect();
        tab.Select();
    }
    selectRadTab(eventArgs.Tab.Value);
    
}
function showSideTabs(sideTabs,tabstrip,side)
{
    var arrPanesText = document.getElementById("panesText").value.split(",");
	var arrPanesSide = document.getElementById("panesSide").value.split(",");
	var striptab;
	var sidetab;
	for (var ap in arrPanesText)
	{
	    if(side == arrPanesSide[ap])
	    {
	        striptab = tabstrip.FindTabByValue(arrPanesText[ap]);
	        sidetab = sideTabs.FindTabByValue(arrPanesText[ap]);
	        if(striptab && sidetab)
	        {
	            sidetab.UnSelect();
	            if(striptab.Enabled) sidetab.Enable();
	            else    sidetab.Disable();
	        }
	    }
	}
	sideTabs.DomElement.style.display = "";
    
}

function hideSideTabs(sideTab)
{
    sideTab.DomElement.style.display = "none";
}

function showLoginLink()
{
	// swap the "login" link for the "logout" link
	var lnkLogin	= top.document.getElementById('lnkLogin');
	var lnkLogout	= top.document.getElementById('lnkLogout');
	
	if (lnkLogin && lnkLogout)
	{
		lnkLogout.style.display  = 'none';
		lnkLogin.style.display = '';
	}
}

function showLogoutLink()
{
	// swap the "login" link for the "logout" link
	var lnkLogin	= top.document.getElementById('lnkLogin');
	var lnkLogout	= top.document.getElementById('lnkLogout');
	
	if (lnkLogin && lnkLogout)
	{
		lnkLogin.style.display  = 'none';
		lnkLogout.style.display = '';
	}
}
function doNothing()
{   return;
}

function getQueryStringVariable(variable) { 
  var query = window.location.search.substring(1); 
  var vars = query.split("&"); 
  for (var i=0;i<vars.length;i++) { 
    var pair = vars[i].split("="); 
    if (pair[0] == variable) { 
      return unescape(pair[1]); 
    } 
  } 
  return null;
} 

function loadAddThis()
{
     if (dojo.isIE){
        loadAddThisScript("js/addthis/addthis_widget.js#domready=1", "js");
        loadAddThisScript("js/addthis/menu64.js", "js");
        loadAddThisScript("js/addthis/widget50.css", "css");
    }
    else
        loadAddThisScript("http://s7.addthis.com/js/250/addthis_widget.js#domready=1", "js");
    


    window.setTimeout("addthis.button('', {}, {});",1000);
     
}

function loadAddThisScript(url, type)
{
    var attribute="src";
    var tag = "script";
    var texttype="text/javascript"
    if(type== "css")
    {
        attribute="href";
        tag = "link";
        texttype="text/css";
    }
    var allsuspects=document.getElementsByTagName(tag);
    for (var i=allsuspects.length; i>=0; i--)
    { 
     //search backwards within nodelist for matching elements to remove
      if (allsuspects[i] && allsuspects[i].getAttribute(attribute)!=null && allsuspects[i].getAttribute(attribute).indexOf(url)!=-1)
       allsuspects[i].parentNode.removeChild(allsuspects[i]); //remove element by calling parentNode.removeChild()
    }
    var fileref=document.createElement(tag);
    fileref.setAttribute("type",texttype);
    if(type=="css")fileref.setAttribute("rel","stylesheet");
    fileref.setAttribute(attribute, url);
    if (typeof fileref!="undefined")
        document.getElementsByTagName("head")[0].appendChild(fileref);
     
}


function setContent(elemName, content)
{
    var divElement = document.getElementById(elemName);
    divElement.innerHTML = content;
    
}

function formatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function setAltRows(elId)
{
    var el = document.getElementById(elId);
    var trElements = el.getElementsByTagName('tr');
    var alt = false;
    if (trElements.length == 0)
    {
        return;
    }
    for(i=0;i<trElements.length;i++)
    {
        if (alt) trElements[i].className = "alt";
        alt = !alt;
    }
}
function setTableWidth(elId)
{
    var el = document.getElementById(elId);
    var trElements = el.getElementsByTagName('TABLE');
    if (trElements.length == 0)
    {
        return;
    }
    for(i=0;i<trElements.length;i++)
    {
        var tEl = trElements[i];
        trElements[i].width = trElements[i].offsetParent.clientWidth;
    }
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

