

var hide = 0; 
var id = 0;

function menuSwitch(id) {
	i = 1; 
	hide = 1;
	for(m=0;m<arr_submenus.length;m++) {
	    
	    el = document.getElementById(arr_submenus[m]);
	    
	    if(id == arr_submenus[m]) {
			
			el.style.visibility = "visible";
			menu_showed = id;
		} else {
	    
			el.style.visibility = "hidden";
		}
	}
}
	
function menuEnd() {
	clearTimeout(id);
	hide = 0; 
	id = setTimeout(menu_hide, 100);
}
	
function menu_hide() {

	if (hide == 0) {
	  i = 1;
	  for(m=0;m<arr_submenus.length;m++) {
	  
	  	  e = document.getElementById(arr_submenus[m]);
	  	  e.style.visibility = "hidden";
	  }
	}
}



function changeElementContent(element_id,content) {

	var element = document.getElementById(element_id);
	element.innerHTML = content;
	return false;
}


function changeVideo(url,width,height) {

	if(!width) var width = 425;
	if(!height) var height = 350;
	
	var ytc = document.getElementById('youTubeContainer');
	
	var src = '<object style="width:'+width+'px;height:'+height+'px;" data="'+url;
	src += '><param name="movie" value="'+url;
	src += '"></param><param name="wmode" value="transparent"></param><embed src="'+url;
	src += '" type="application/x-shockwave-flash" wmode="transparent" width="'+width+'" height="'+height+'"></embed></object>';
    
	ytc.innerHTML = src;
	
	return false;
}

function showHideById(id) {
	
	var element = document.getElementById(id);
	
	if(element.style.display== 'none' || element.style.display == 'hidden') {
		element.style.display = 'block';
	} else {
		element.style.display = 'none';
	}
	return false;
}

function showMenu() {
	document.getElementById('menu').style.display = 'block';
	if (!document.all)
	{
		document.getElementById('menu').style.display = "";
	}
	document.getElementById('menu_hidden').style.display = 'none';
	setCookie('menu', 'yes', 365*24*3600);
}

function hideMenu() {
	document.getElementById('menu').style.display = 'none';
	document.getElementById('menu_hidden').style.display = 'block';
	if (!document.all)
	{
		document.getElementById('menu_hidden').style.display = "table-row";
	}	
	setCookie('menu', 'no', 365*24*3600);	
}

function showSubMenu(id) {
	sub = document.getElementById(id)
	if (sub != null) { 
		if (sub.style.display != 'block') {
			sub.style.display = 'block';
		} else {
			sub.style.display = 'none';
		}
	}
}

/**
 * Set cookie 
 */
function setCookie(name, value, sec_to_expire) {
  
  if(!sec_to_expire) {
  	var expire_date = 0;
  } else {
  	expire_date = new Date(new Date().getTime()+sec_to_expire*1000).toGMTString();
  }

  if (value != null && value != "") {
    document.cookie=name + "=" + escape(value) + "; expires=" + expire_date + '; path=/';
  }
}

function setCookieArray(name, array, sec_to_expire) {

  if(!sec_to_expire) {
     var sec_to_expire = 24*3600;
  }

  var expire_date = new Date(new Date().getTime()+sec_to_expire*1000).toGMTString();
  
  sCookie = '';
  for (var key in array) {
  	if(key.length > 0 && array[key].length > 0) {
	  	sCookie +=  key + ',' + array[key] + ',';
	}
  }
  
  sCookie = sCookie.substr(0, sCookie.length - 1);

  document.cookie= name + "=" + sCookie + "; expires=" + expire_date + '; path=/';
}

function getCookieArray(name) {

	start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && (name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;

	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	array = document.cookie.substring( len, end ).split(',');
	
	rArray = new Array();
	for (var i = 0; i < array.length; i += 2) {
		rArray[array[i]] = array[i + 1];
	}
	
	return rArray;
}

function eraseCookie(name) {

	var date = new Date();
	date.setTime(date.getTime()+(-1*24*60*60*1000)); //expire date set to yesterday
	var expires = "; expires="+date.toGMTString();
	document.cookie = name+"=''"+expires+"; path=/";
}

function addToCookieArray(name, key, value, sec_to_expire) {
	array = getCookieArray(name);
	if (!array) {
		array = new Array();
	}
	array[key] = value;

	setCookieArray(name, array, sec_to_expire);
}

function deleteFromCookieArray(name, element) {
	array = getCookieArray(name);
	array[element] = '';
	setCookieArray(name, array);
}


/**
 * Clock
 */
function runClock(){
	var oDate=new Date();
	var sSwitch="am";
	var iHours=oDate.getHours();
	/*
	if(iHours>11){
		sSwitch="pm";
	}
	if(iHours>12){
		iHours-=12;
		sSwitch="pm";
	}*/
	
	var sMinutes=oDate.getMinutes() + "";
	if(sMinutes.length==1){
		sMinutes="0" + sMinutes;
	}
	var sSeconds=oDate.getSeconds() + "";
	if(sSeconds.length==1){
		sSeconds="0" + sSeconds;
	}
	document.getElementById('timecell').innerHTML=iHours + ":" + sMinutes + ":" + sSeconds + "&nbsp;" ;
}

/**
 * Show popup
 */
function showPopUp(target, name, width, height) {
	strOptions = 'width=' + width + ',height=' + height + ',toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no';

	var popupWindow = window.open(target, name, strOptions);
	if(popupWindow) {
	
		popupWindow.focus();
		return popupWindow;
		
	} else {
		return false;
	}
}

function getUrlParam (paraName) {
	thisURL = document.location.search.slice(1);

	arrayURL = thisURL.split('&');

	for (i = 0; i < arrayURL.length; i++) {
		if (arrayURL[i].slice(0, arrayURL[i].indexOf('=')) == paraName) {
			return unescape(arrayURL[i].slice(arrayURL[i].indexOf('=') + 1));
		}
	}

	return '';
} 

function addTableBehavior() {	
	
	var l = document.getElementById('t1').getElementsByTagName('td');
	var last;
	for (i = 0; i < l.length; i++) {
		switch (l[i].className) {
			case 'o':
			case 'oo':
			case 'oi':
			case 'oback':
			case 'olay':
				l[i].onmouseover = function () {
				
			        this.parentNode.style.backgroundColor="#f1f1f1"; 
			        if(this.firstChild)
			        {
						this.style.cursor="pointer"; 
						this.style.color="white"; 

						this.style.backgroundColor="#005689"; 
					}
				}
				l[i].onmouseout = function () {
				
				    this.parentNode.style.backgroundColor="#ffffff";
				    if(this.firstChild)
					{
						this.style.color=""; 
						this.style.backgroundColor=""; 
				    }
				}
				break;
			case 'selections': 						
				l[i].onmouseover = function () {this.parentNode.style.backgroundColor="#f1f1f1";}
				l[i].onmouseout = function () {this.parentNode.style.backgroundColor="#ffffff";}
			default:
				break;			
		}
	}
	return true;
}

function setAllOddsTableFontSize() {
	
	if (screen.width <= 1024) {
		var table = document.getElementById('AllOddsTable');
	    var l = table.getElementsByTagName('tr');
	   	for (i = 0; i < l.length; i++) {
		   	if(l[i].className == 'eventTableRow') {
		   		
		   		x = l[i].getElementsByTagName('td');
		   		for (j = 0; j < x.length; j++) {
		   			if(x[j].firstChild.nodeValue >= 10000) {
		   				x[j].style.fontSize = '8px';
		   			} else {
		   				x[j].style.fontSize = '9px';
		   			}
		   		}
		   	}
	   	}
   	}		
}



function setMaxTotals(nof_trad_str,nof_ex_str) {

	var nof_trad = parseInt(nof_trad_str);
    var nof_ex = parseInt(nof_ex_str);

	arr = new Array();
	var tr = document.getElementById('e_totals');
	var tds = tr.getElementsByTagName('td');
	
	var ahref = tds[1].getElementsByTagName('a');
	
	for(var i=1;i<=nof_trad;i++) {
	
		ahref = tds[i].getElementsByTagName('a');

		if(ahref[0] && ahref[0].firstChild.nodeValue>0) arr.push(parseFloat(ahref[0].firstChild.nodeValue));
		else  arr.push(0);
	}
	
	var max = Math.max.apply(null, arr);

	for(var i=1;i<=nof_trad;i++) {
		ahref = tds[i].getElementsByTagName('a');
		if(ahref[0]) {
			if(parseFloat(ahref[0].firstChild.nodeValue) == max) tds[i].className = 'e_totals_best_acc';
		}
	}
	
	var arr = new Array();
	
	for(var i=nof_trad;i<=nof_trad+nof_ex;i++) {
		ahref = tds[i].getElementsByTagName('a');
		if(ahref[0] && ahref[0].firstChild.nodeValue>0) arr.push(parseFloat(ahref[0].firstChild.nodeValue));
		else  arr.push(0);
	}

	var max = Math.max.apply(null, arr);
	
	for(var i=nof_trad;i<=nof_trad+nof_ex;i++) {
		ahref = tds[i].getElementsByTagName('a');
		if(ahref[0]) {
			if(parseFloat(ahref[0].firstChild.nodeValue) == max) tds[i].className = 'e_totals_best_acc';
		}
	}
	
}

function mod(n, m)
{
	while (n >= m)
	{
		n = n-m;
	}
	return(n);
}

function dec2frac(dec)
{

	var decString = dec.toString();
	var dslength = decString.length - 1;
	var div = 1;
 
 	for (i=0; i<dslength; i++)
 	{
  		dec = dec * 10;
  		div = div * 10;
  	}

    dec = Math.round(dec);
	div = Math.round(div);

 	for (i=2; i <= dec; i++) {
		while ((mod(dec,i) == 0) && (mod(div,i) == 0))
		{
	    	dec = dec/i;
			div = div/i;
		}
	}
	
	dec = Math.round(dec);
	div = Math.round(div);

	return dec + (div !=1 ? "/" + div : "" );
}

function getBrowserWindowInnerSizes() {
	
	var h = w = 0;
	if (typeof(window.innerWidth) == 'number') {
		w = window.innerWidth;
		h = window.innerHeight;
	} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	} else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}
	
	sizes = new Array(w,h);
	return sizes;
}

document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
		var classes = elem[i].className;
		if (myclass.test(classes)) retnode.push(elem[i]);
	}
	return retnode;
};

/* for google maps */
function createMarker(point,html) {

    var marker = new GMarker(point);
    GEvent.addListener(marker, "click", function() {
       marker.openInfoWindowHtml(html);
    });
    return marker;
}
