// function create_xhr() {{{
var xhr;
/**
* Create XMLHttpRequest (XHR) object.
*
* @return object Return XHR object.
*/
function create_xhr() {
if (window.XMLHttpRequest)
{
xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
xhr = new ActiveXObject('Microsoft.XMLHTTP');
}
else
{
alert('Nelze vytvořit objekt');
}
}
// }}}
// function show_xhr_error() {{{
/**
* Display XHR error and error code, if creation failure.
*
* @return void
*/
function show_xhr_error()
{
alert('XMLHttp Chyba žádosti: '+"\n"+'Chyba: '+xhr.status+"\n"+'Vzkaz: '+xhr.text);
}
// }}}
// function create_th() {{{
/**
* Create TH element.
*
* @param mixed $content TH content.
* @return object Return TH object.
*/
function create_th(content)
{
var cell = document.createElement('th');
if (typeof content == 'object')
{
cell.appendChild(content);
}
else
{
var cellValue = document.createTextNode(content);
cell.appendChild(cellValue);
}
return cell;
}
// }}}
// function create_td() {{{
/**
* Create TD element.
*
* @param mixed $content TD content.
* @return object Return TD object.
*/
function create_td(content)
{
var cell = document.createElement('td');
if (typeof content == 'object')
{
cell.appendChild(content);
}
else
{
var cellValue = document.createTextNode(content);
cell.appendChild(cellValue);
}
return cell;
}
// }}}
// function getElementPosition() {{{
/**
* Get element position.
*
* @param {Object} obj DOM element.
* @return {Object} Returns object with element position.
*/
function getElementPosition(obj)
{
var curleft, curtop = 0;
if (isObject(obj)) {
if (obj.offsetParent){
curleft = obj.offsetLeft;
curtop = obj.offsetTop;
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
}
}
}
return {curleft:curleft, curtop:curtop};
}
// }}}
/**
* Get element size.
*
* @param {Object} obj DOM element.
* @return {Object} Returns the element dimension.
*/
function getElementSize(obj)
{
var width, height = 0;
if (isObject(obj)) {
width = obj.offsetWidth;
height = obj.offsetHeight;
}
return {width:width, height:height};
};
// function arch_odds() {{{
var parE;
/**
* Generate info about archive course.
*
* @param object $element Parent element.
* @param integer $course_id Course ID.
* @param string $table Table for courses.
*
* - 1 - table for 1x2 courses,
* - 2 - table for under/over courses,
* - 3 - table for asian handicap courses,
* - 4 - table for money line courses.
*
* @param string $type Course type.
*
* - k1 - K1 courses,
* - k0 - K0 courses,
* - k2 - K2 courses,
* - k10 - K10 courses,
* - k02 - K02 courses.
*
*/
function arch_odds(element, course_id, table, type)
{
parE = element;
create_xhr();
xhr.onreadystatechange = _arch_odds;
xhr.open('GET', '/gres/archive-odds.php?id='+course_id+'&table='+table+'&type='+type);
//xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
xhr.send(null);
}
function _arch_odds()
{
if (xhr.readyState == 4)
{
if (xhr.status == 200)
{
var xml = xhr.responseXML;
var nodata = xml.getElementsByTagName('nodata');
// some data, show it
if (nodata.length == 0)
{
// check if box for archive courses already generated and remove it
del_arch_info();
var elem = xml.getElementsByTagName('element'); // all element with archive courses
var div = document.createElement('div');
div.setAttribute('id', 'aodds-info');
div.setAttribute('title', 'Klikněte pro zavření');
// archive course closer
var closer = document.createElement('div');
if (navigator.userAgent.match(/MSIE/) && !navigator.userAgent.match(/MSIE 8/))
{
closer.setAttribute('className', 'a-closer');
}
else
{
closer.setAttribute('class', 'a-closer');
}
var strong = document.createElement('strong');
strong.appendChild(document.createTextNode('Archiv kursů'));
closer.appendChild(strong);
var link = document.createElement('a');
if (navigator.userAgent.match(/MSIE/) && !navigator.userAgent.match(/MSIE 8/))
{
link.onclick = new Function("env", "del_arch_info()");
div.onclick = new Function("env", "del_arch_info()");
}
else
{
link.setAttribute('onclick', 'del_arch_info()');
div.setAttribute('onclick', 'del_arch_info()');
}
link.appendChild(document.createTextNode('X'));
closer.appendChild(link);
div.appendChild(closer);
// archive course content
var cont = document.createElement('div');
if (navigator.userAgent.match(/MSIE/) && !navigator.userAgent.match(/MSIE 8/))
{
cont.setAttribute('className', 'a-content');
}
else
{
cont.setAttribute('class', 'a-content');
}
var table = document.createElement('table');
var tbody = document.createElement('tbody');
for (var i = 0; i < elem.length; i++)
{
var tr = document.createElement('tr');
var dat = elem.item(i).getElementsByTagName('date');
dat = dat.item(0).firstChild.nodeValue;
var course = elem.item(i).getElementsByTagName('course');
course = course.item(0).firstChild.nodeValue;
//var arch = elem.item(i).getElementsByTagName('archive_course');
//arch = arch.item(0).firstChild.nodeValue;
tr.appendChild(create_th(dat));
tr.appendChild(create_td(course));
//tr.appendChild(create_td(arch));
tbody.appendChild(tr);
}
table.appendChild(tbody);
cont.appendChild(table);
div.appendChild(cont);
// set position
var pos = getElementPosition(parE);
// correction child position (move from right corner)
var div_main = document.getElementById('main');
var correction = 0;
if ((pos.curleft+125) >= (div_main.offsetLeft+div_main.offsetWidth))
{
correction = pos.curleft-(div_main.offsetLeft+div_main.offsetWidth-120);
}
var l = pos.curleft+10-correction;
var t = pos.curtop+15;
if (navigator.userAgent.match(/MSIE/) && !navigator.userAgent.match(/MSIE 8/))
{
div.style.cssText = 'display:block;top:'+t+'px;left:'+l+'px;';
}
else
{
div.setAttribute('style', 'display:block;top:'+t+'px;left:'+l+'px;');
}
document.body.appendChild(div);
}
}
else
{
show_xhr_error();
}
}
}
// }}}
// function del_arch_info() {{{
/**
* Delete archive courses information box.
*
* @return void
*/
function del_arch_info()
{
var box = document.getElementById('aodds-info');
if (box != undefined)
{
document.body.removeChild(box);
}
}
// }}}
// function tz() {{{
/**
* Generate table for change timezone.
*
*/
var tz_uri = null;
var timezone = null;
function tz(uri)
{
tz_uri = uri;
create_xhr();
xhr.onreadystatechange = _tz;
xhr.open('GET', '/res/timezone.php');
xhr.send(null);
return false;
}
function _tz()
{
if (xhr.readyState == 4)
{
if (xhr.status == 200)
{
// check if exists timezone element
var tz = document.getElementById('timezone');
if (tz != undefined)
{
getElement('panel').removeChild(tz);
}
xml = xhr.responseXML;
var sel = xml.getElementsByTagName('selected_zone');
sel = sel.item(0).firstChild.nodeValue;
var div = document.createElement('div');
div.id = 'timezone';
var table = document.createElement('table');
var tbody = document.createElement('tbody');
var zone = xml.getElementsByTagName('timezone');
if (zone.length > 0)
{
for (var i = 0; i < zone.length; i++)
{
var row = document.createElement('tr');
var offset = zone.item(i).getElementsByTagName('offset');
offset = offset.item(0).firstChild.nodeValue;
var location = zone.item(i).getElementsByTagName('location');
location = location.item(0).firstChild.nodeValue;
if(timezone == offset)
{
if(navigator.userAgent.match(/MSIE/))
row.setAttribute('className', 'local');
else
row.setAttribute('class', 'local');
row.title = 'Probably your local timezone';
}
var destination = "window.location='"+tz_uri+offset+"';";
if (navigator.userAgent.match(/MSIE/))
{
row.onclick = new Function("env", destination);
row.onmouseover = new Function("env", "over(this)");
row.onmouseout = new Function("env", "out(this)");
if (offset == sel)
{
row.setAttribute('className', 'set');
}
}
else
{
row.setAttribute('onclick', destination);
if (offset == sel)
{
row.setAttribute('class', 'set');
}
}
row.appendChild(create_th(offset));
row.appendChild(create_td(location));
tbody.appendChild(row);
}
}
table.appendChild(tbody);
var table_foot = document.createElement('div');
table_foot.id = 'tz-foot';
table_foot.appendChild(document.createTextNode(' '));
div.appendChild(table);
div.appendChild(table_foot);
document.getElementById('panel').appendChild(div);
}
else
{
show_xhr_error();
}
}
return false;
}
// }}}
var last_cls; // content last class for row
function over(elem)
{
if (navigator.userAgent.match(/MSIE/))
{
last_cls = elem.getAttribute('className');
elem.setAttribute('className', 'hover');
}
else
{
last_cls = elem.getAttribute('class');
elem.setAttribute('class', 'hover');
}
}
// function out() {{{
function out(elem)
{
if (last_cls != undefined && last_cls != '')
{
if (navigator.userAgent.match(/MSIE/))
{
elem.setAttribute('className', last_cls);
}
else
{
elem.setAttribute('class', last_cls);
}
}
else
{
if (navigator.userAgent.match(/MSIE/))
{
elem.removeAttribute('className');
}
else
{
elem.removeAttribute('class');
}
}
}
// }}}
// function getElement() {{{
/**
* Alias for document.getElementById function.
*
* @return object
*/
function getElement(id)
{
return document.getElementById(id);
}
// }}}
// function legend() {{{
/**
* Show legend for overall tables.
*
* @param object parentElem Parent element.
* @param string elem ID of legend table.
* @return void
*/
function legend(parentElem, elem)
{
var e = getElement(elem).style;
var pe = getElementPosition(parentElem);
var sc = getElementPosition(document.getElementById('main'));
if (e.display == 'none')
{
e.left = pe.curleft-190+'px';
e.top = pe.curtop-sc.curtop+5+'px';
e.display = 'block';
}
else
{
e.display = 'none';
}
}
// }}}
// function d_option() {{{
/**
* Disable (remove) option element in pared element (mutual matches combo).
*
* @param string elem ID of paired element.
* @return void
*/
var lastRemove;
var lastData;
function d_option(elem)
{
// get paired element
var mainElemID = (elem == 'home' ? 'away' : 'home');
var pairSel = getElement(elem);
var mainSel = getElement(mainElemID);
pairSel.focus();
if (lastRemove != undefined && lastData != undefined)
{
var lastSel = getElement(lastRemove);
var opt = new Array();
var selected;
// get all option
for (var i = 0; i < lastSel.length; i++)
{
opt.push(lastSel.options[i].text+'|=|'+lastSel.options[i].value);
}
opt.push(lastData[1]+'|=|'+lastData[0]);
selected = lastSel.options[lastSel.selectedIndex].text;
// sort option
opt.sort();
// remove all childs
while (lastSel.firstChild)
{
lastSel.removeChild(lastSel.firstChild);
}
// generate new options
for (i in opt) {
if (typeof opt[i] == 'string') {
var option = document.createElement('option');
var split = opt[i].split('|=|');
option.setAttribute('value', split[1]);
if (split[0] == selected) {
option.setAttribute('selected', true);
}
option.appendChild(document.createTextNode(split[0]));
lastSel.appendChild(option);
}
}
}
for (var i = 0; i < pairSel.length; i++)
{
if (pairSel.options[i].value == mainSel.options[mainSel.selectedIndex].value)
{
lastRemove = elem;
lastData = [pairSel.options[i].value, pairSel.options[i].text];
pairSel.removeChild(pairSel.options[i]);
break;
}
}
}
// }}}
// function show_tab() {{{
var last_tab;
/**
* Show tabs for tables.
*
* @param string $show ID of tabs which to show.
* @return void
*/
function show_tab(show)
{
if (last_tab == undefined)
{
last_tab = 'overall';
}
var last = getElement('tab-'+last_tab);
var last_a = getElement('a-'+last_tab);
var new_tab = getElement('tab-'+show);
var new_a = getElement('a-'+show);
setStyle(last, 'display:none;');
rmClass(last_a);
setStyle(new_tab, 'display:block;');
setClass(new_a, 'set');
last_tab = show;
}
// }}}
// function isIE() {{{
/**
* Check if user's browser is Internet Explorer.
*
* @return boolean Return true if yes, otherwise false.
*/
function isIE()
{
return (navigator.userAgent.match(/MSIE/) ? true : false);
}
// }}}
// function setStyle() {{{
/**
* Set CSS style for element.
*
* @param object element Element for set CSS.
* @param string style CSS style.
*/
function setStyle(element, style)
{
if (isIE())
{
element.style.cssText = style;
}
else
{
element.setAttribute('style', style);
}
}
// }}}
// function rmClass() {{{
/**
* Remove CSS class style for element.
*
* @param object element Element for set CSS.
* @param string style CSS class style.
* @deprecated
*/
function rmClass(element)
{
if (isIE())
{
element.removeAttribute('className');
}
else
{
element.removeAttribute('class');
}
}
// }}}
// function setClass() {{{
/**
* Set CSS class style for element.
*
* @param object element Element for set CSS.
* @param string style CSS class style.
* @deprecated
*/
function setClass(elem, cls)
{
if (isIE())
{
elem.setAttribute('className', cls);
}
else
{
elem.setAttribute('class', cls);
}
}
// }}}
/**
* Set CSS class style for element.
*
* @param object element Element for set CSS.
* @param string style CSS class style.
*/
function setCls(elem, cls)
{
if (isObject(elem)) {
isIE() ? elem.setAttribute('className', cls) : elem.setAttribute('class', cls);
}
};
/**
* Remove CSS class style for element.
*
* @param object element Element for set CSS.
* @param string style CSS class style.
*/
function rmCls(elem)
{
if (isObject(elem)) {
isIE() ? elem.removeAttribute('className') : elem.removeAttribute('class');
}
};
var hSel = new Array();
/**
* Show / hide match status in 'spider-man'.
*
* @param {String} id ID of match stats.
*/
function showHide_matches(id)
{
var minMax = getElement('mm-' + id);
var minMaxImage = minMax.firstChild;
var element = getElement('matches-' + id);
var selAway = getElement('away');
var selHome = getElement('home');
if (isObject(element)) {
if (element.style.display != 'block') {
element.style.visibility = 'hidden';
element.style.display = 'block';
if (isIE()) {
var dimensionMatchStat = getElementSize(element);
var positionMatchStat = getElementPosition(element);
var dimensionAway = getElementSize(selAway);
var dimensionHome = getElementSize(selHome);
var positionAway = getElementPosition(selAway);
var positionHome = getElementPosition(selHome);
// match stats overlay Away option => hide it
if (((positionMatchStat.curleft >= positionAway.curleft || (positionMatchStat.curleft + dimensionMatchStat.width) >= positionAway.curleft) && ((positionAway.curleft + dimensionAway.width) >= positionMatchStat.curleft))
&& ((positionMatchStat.curtop >= positionAway.curtop || (positionMatchStat.curtop + dimensionMatchStat.height) >= positionAway.curtop) && ((positionAway.curtop + dimensionAway.height) >= positionMatchStat.curtop)))
{
selAway.style.visibility = 'hidden';
if (!hSel.inArray(id + '-away')) {
hSel[hSel.length] = id + '-away';
}
}
// match stats overlay Home option => hide it
if (((positionMatchStat.curleft >= positionHome.curleft || (positionMatchStat.curleft + dimensionMatchStat.width) >= positionHome.curleft) && ((positionHome.curleft + dimensionHome.width) >= positionMatchStat.curleft))
&& ((positionMatchStat.curtop >= positionHome.curtop || (positionMatchStat.curtop + dimensionMatchStat.height) >= positionHome.curtop) && ((positionHome.curtop + dimensionHome.height) >= positionMatchStat.curtop)))
{
selHome.style.visibility = 'hidden';
if (!hSel.inArray(id + '-home')) {
hSel[hSel.length] = id + '-home';
}
}
}
// show element
element.style.visibility = 'visible';
// change title
minMaxImage.setAttribute('title', 'Klikněte pro skrytí detailů zápasů');
minMaxImage.setAttribute('alt', 'Klikněte pro skrytí detailů zápasů');
// change minMax DIV CSS class
setClass(minMax, 'showHideMatches maximize');
} else {
element.style.display = 'none';
var retObj = unsetHSel(id, 'away');
hSel = retObj.hSel;
if (retObj.another == false) {
selAway.style.visibility = 'visible';
}
var retObj = unsetHSel(id, 'home');
hSel = retObj.hSel;
if (retObj.another == false) {
selHome.style.visibility = 'visible';
}
// change title
minMaxImage.setAttribute('title', 'Klikněte pro zobrazení starších kursů');
minMaxImage.setAttribute('alt', 'Klikněte pro zobrazení starších kursů');
// change minMax DIV CSS class
setClass(minMax, 'showHideMatches minimize');
}
}
};
/**
* Finds whether the given variable is object.
*
* @param {Mixed} element The variable being evaluated.
* @return {Boolean} Returns TRUE if element is object, FALSE otherwise.
*/
function isObject(element)
{
return (!isNull(element) && typeof element == 'object' ? true : false);
};
/**
* Finds whether the given variable is NULL.
*
* @param {Mixed} element The variable being evaluated.
* @return {Boolean} Returns TRUE if element is null, FALSE otherwise.
*/
function isNull(element)
{
return (typeof element == 'undefined' || element == null ? true : false);
};
/**
* Create new array with overlayed element and test if exists another match stats.
*
* @param {String} id ID of overlay element.
* @param {String} elemType Type of combo box. May by 'home|away'.
* @return {Object}
*/
function unsetHSel(id, elemType)
{
var newArray = new Array();
var anotherType = false;
var pattern = '([0-9]{1,})-' + elemType;
var chunk = null;
if (!isNull(id) && !isNull(elemType)) {
for (var i = 0; i < hSel.length; i++) {
if (typeof this[i] != 'function') {
chunk = hSel[i].match(pattern);
if (chunk != null) {
if (chunk[1] != id) {
anotherType = true;
}
}
if (hSel[i].match(id) == null) {
newArray[newArray.length] = hSel[i];
}
}
}
}
return {hSel:newArray, another:anotherType};
};
function changeNextSport(obj)
{
window.location=obj.options[obj.selectedIndex].value;
};
function streakMenuDataSh(idData)
{
document.getElementById('streakMenu_1').className = 'first';
document.getElementById('streakMenu_2').className = '';
document.getElementById('streakMenu_3').className = '';
document.getElementById('streakMenu_' + idData).className = (idData == 1 ? 'first ' : '') + 'set';
document.getElementById('menuStreakData_1').style.display = 'none';
document.getElementById('menuStreakData_2').style.display = 'none';
document.getElementById('menuStreakData_3').style.display = 'none';
document.getElementById('menuStreakData_' + idData).style.display = 'block';
};
/**
* Checks if a value exists in an array.
*
* @param {String} needle The searched value.
* @param {Boolean} strictSearch Search by the first occurrence of the specified value in index array.
* @return {Boolean} Returns TRUE if needle is found in the array, FALSE otherwise.
*/
Array.prototype.inArray = function(needle, strictSearch)
{
exists = false;
strictSearch = isNull(strictSearch) || strictSearch != false ? true : false;
if (!isNull(needle) && isObject(this) && this.length > 0) {
for (var i in this) {
if (typeof this[i] != 'function') {
if (!strictSearch) {
if (this[i].indexOf(needle) > -1) {
exists = true;
break ;
}
} else {
if (this[i] == needle) {
exists = true;
break ;
}
}
}
}
}
return exists;
};
/**
* Searches the array for a given value and returns the corresponding key if successful.
*
* @param {Mixed} needle The searched value.
* @param {Boolean} strictSearch Search by the first occurrence of the specified value in index array.
* @return {Mixed} Returns the key for needle if it is found in the array, FALSE otherwise.
*/
Array.prototype.search = function(needle, strictSearch)
{
var key = false;
strictSearch = isNull(strictSearch) || strictSearch != false ? true : false;
if (!isNull(needle) && isObject(this) && this.length > 0) {
for (var i = 0; i < this.length; i++) {
if (!strictSearch) {
if (this[i].indexOf(needle) > -1) {
key = i;
break ;
}
} else {
if (this[i] == needle) {
key = i;
break ;
}
}
}
}
return key;
};