﻿function commonOnLoad(){
    if (BrowserDetect.browser != "Explorer") window.onresize=doResize;

    setDivSizes();
}


function commonOnResize(){
    setDivSizes();
}

function setDivSizes(){
    sizeSectionHeaderDiv();
    sizeSectionMenuDiv();
}

function doResize(){
    setDivSizes();
}

function sizeSectionHeaderDiv() {
	var w = windowWidth();
	var sectionHeader = document.getElementById("sectionHeader");

	sectionHeader.style.width = w - 150 + "px"; 
}


function sizeSectionMenuDiv() {
    var h;
	var winH = windowHeight();
	var bodyDiv = document.getElementById("bodyContainer");
	var menuDiv = document.getElementById("mainMenuEnd");

	if (bodyDiv==null){ bodyDiv=document.getElementById("bodyContainerNonRestricted"); }
	if (bodyDiv==null){ bodyDiv=document.getElementById("bodyContainerJudges"); }

    if (winH>bodyDiv.offsetHeight){h=winH}else{h=bodyDiv.offsetHeight};
	
	menuDiv.style.height = h - menuDiv.offsetTop + "px"; 
}

function setHomePageTableHeight() {
    var h;
	var winH = windowHeight();
	var w = windowWidth();	
	var bodyDiv = document.getElementById("homePageImage");
    
    bodyDiv.style.left =(w - bodyDiv.offsetWidth)/2 + "px";
    bodyDiv.style.top =(winH - bodyDiv.offsetHeight)/2 + "px";
}

function openWinImg(myimage) {
 html = "<HTML><HEAD><TITLE>Photo</TITLE>" +
  "</HEAD><BODY LEFTMARGIN=0 " 
  + "MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0><CENTER>" 
  + "<IMG SRC='" + myimage + "' BORDER=0 NAME=image " 
  + "onload='window.resizeTo(document.image.width + 40,document.image.height + 40)'>"
  + "</CENTER>" 
  + "</BODY></HTML>";
  
 
 popup=
 window.open
  ('','image',
  'width=500,height=300,toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=1');
 popup.document.open();
 popup.document.write(html);
 popup.document.focus();
 popup.document.close()
 }
 
 
 
 function openMovie(movie) {
 
 //popup=
 window.open
  (movie,'image',
  'width=720,height=480,toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=1');
 //popup.document.open();
 //popup.document.write(html);
 //popup.document.focus();
 //popup.document.close()
 }
 
 function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}


 function windowWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  
  return myWidth;
}

function windowHeight(){
  myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
 
  return myHeight;
}















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();