// JavaScript Document
window.onresize = setHeight('wrapper');
window.onmove = setHeight('wrapper');

function getWindowHeight() {
  var myHeight = 0;
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientHeight ) ) {
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
 return myHeight;
}

function getWindowWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth ) ) {
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
 return myWidth;
}

function positionInfo(el){
	var scrWidth = getWindowWidth();
	infoPos = scrWidth/2;
	infoPos = infoPos+53;
	//alert(infoPos);
	getElement(el).style.left = infoPos+'px';
}

function positionInfoIE7(el, adjust){
	if(BrowserDetect.browser=='Explorer' && BrowserDetect.version<='7'){
		//alert('Your using IE7 or below');
		var scrWidth = getWindowWidth();
		infoPos = scrWidth/2;
		infoPos = infoPos-adjust;
		//alert(infoPos);
		getElement(el).style.left = infoPos+'px';
	}
}

function setHeight(el){
		var bodyEl = getElement(el);
		var bodyHeight = bodyEl.offsetHeight;
		newHeight = getWindowHeight();
		
		//alert("Wrapper height: "+bodyHeight+"px\nWindow Height: "+newHeight+"px");
		
		if(bodyHeight < newHeight){
		 	bodyEl.style.height = newHeight+'px';
		}
}

function getElement(el){
	if(document.getElementById(el)){
		return document.getElementById(el);
	}
}

function getValue(el){
	return getElement(el).value;
}

function showHide(showThese, hideThese){
	var loopShows = showThese.split("-");
	var loopHides = hideThese.split("-");
	for(i=0;i<loopHides.length;i++){
		getElement(loopHides[i]).style.display='none';
	}
	for(i=0;i<loopShows.length;i++){
		getElement(loopShows[i]).style.display='';
	}
}

function styleTabs(activeTab,inactiveTabs){
	
	var loopActives = activeTab.split("-");
	var loopInactives = inactiveTabs.split("-");

	for(i=0;i<loopActives.length;i++){
		if(loopActives[i]=='sectorsTab'){
			//getElement(loopActives[i]).className = 'sectorsDown'
			getElement(loopActives[i]).style.width='220px';
			getElement(loopActives[i]).style.height='27px';
			getElement(loopActives[i]).style.display='block';
			getElement(loopActives[i]).style.styleFloat='left';
			getElement(loopActives[i]).style.padding='3px 0 0 10px';
			getElement(loopActives[i]).style.background='url(images/services_panel_title_short_bg.jpg)';
			getElement(loopActives[i]).style.backgroundPosition='-0 0';
			getElement(loopActives[i]).style.color='#132761';
		}else{
			//getElement(loopActives[i]).className = 'down'
			getElement(loopActives[i]).style.width='230px';
			getElement(loopActives[i]).style.height='27px';
			getElement(loopActives[i]).style.display='block';
			getElement(loopActives[i]).style.styleFloat='left';
			getElement(loopActives[i]).style.padding='3px 0 0 10px';
			getElement(loopActives[i]).style.background='url(images/services_panel_title_bg.jpg)';
			getElement(loopActives[i]).style.backgroundPosition='0 0';
			getElement(loopActives[i]).style.color='#132761';
		}
		
	}
	
	for(i=0;i<loopInactives.length;i++){
		if(loopInactives[i]=='sectorsTab'){
			//getElement(loopInactives[i]).className = 'sectors'
			getElement(loopInactives[i]).style.width='220px';
			getElement(loopInactives[i]).style.height='27px';
			getElement(loopInactives[i]).style.display='block';
			getElement(loopInactives[i]).style.styleFloat='left';
			getElement(loopInactives[i]).style.padding='3px 0 0 10px';
			getElement(loopInactives[i]).style.background='url(images/services_panel_title_short_bg.jpg)';
			getElement(loopInactives[i]).style.backgroundPosition='-230px 0';
			getElement(loopInactives[i]).style.color='#FFFFFF';
		}else{
			//getElement(loopInactives[i]).className = 'up'
			getElement(loopInactives[i]).style.width='230px';
			getElement(loopInactives[i]).style.height='27px';
			getElement(loopInactives[i]).style.display='block';
			getElement(loopInactives[i]).style.styleFloat='left';
			getElement(loopInactives[i]).style.padding='3px 0 0 10px';
			getElement(loopInactives[i]).style.background='url(images/services_panel_title_bg.jpg)';
			getElement(loopInactives[i]).style.backgroundPosition='-240px 0';
			getElement(loopInactives[i]).style.color='#FFFFFF';
		}
	}
	
}

function showPanel(activeTab, inactiveTabs, panelToShow, panelsToHide){
		styleTabs(activeTab,inactiveTabs);
		showHide(panelToShow,panelsToHide);	
}

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",
			versionSearch: "Version"
		},
		{
			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.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
