// *************
// PHP FUNC
// *************
function is_int( mixed_var ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Alex
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: is_int(186.31);
    // *     returns 1: false
    // *     example 2: is_int(12);
    // *     returns 2: true
 
    var y = parseInt(mixed_var * 1);
    
    if (isNaN(y)) {
        return false;
    }
    
    return mixed_var == y && mixed_var.toString() == y.toString(); 
}
function empty( mixed_var ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philippe Baumann
    // *     example 1: empty(null);
    // *     returns 1: true
 
    return ( mixed_var === "" || mixed_var === 0   || mixed_var === "0" || mixed_var === null  || mixed_var === false);
}
function round ( val, precision ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // *     example 1: round(1241757, -3);
    // *     returns 1: 1242000
    // *     example 2: round(3.6);
    // *     returns 2: 4
 
    var precision = (round.arguments.length > 1) ? round.arguments[1] : 0;
    return Math.round(val * Math.pow(10, precision))/Math.pow(10, precision);
}
function explode( delimiter, string, limit) {
    // http://kevin.vanzonneveld.net
    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: kenneth
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: d3x
    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
    // *     example 2: explode('=', 'a=bc=d', 2);
    // *     returns 2: ['a', 'bc=d']
 
    var emptyArray = { 0: '' };
    
    // third argument is not required
    if ( arguments.length < 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }
 
    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }
 
    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}

// *************
// counter
// *************
var counter = new Array()

function counter_build(time) {
	document.write('<div id="counter"></div>');

	counter['value'] = time+60
	counter['go'] = setInterval('counter_go()', 60000)
	counter_go()
}
function counter_go() {
	counter['value'] = counter['value'] - 60;
	
	if (counter['value']<0) {
		document.getElementById('counter').innerHTML = '<span class="bold">Dostęp zablokowany</span>'
	}
	else {
		var time = counter['value']
		var days = Math.floor(time / 86400)
		time = time - days*86400
		var hours = Math.floor(time / 3600)
		time = time - hours*3600
		var minutes = Math.floor(time / 60)
		
		document.getElementById('counter').innerHTML = 'Pozostały czas dostępu: <span class="bold">'+days+' d '+hours+' g '+minutes+' min</span>'
	}
}

// *********
// Tooltip
// *********
var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
var tempX = 0
var tempY = 0

function tooltip_show(obj) {
	var o = document.getElementById('tooltip')
	o.src = obj.src
	
	document.onmousemove = getMouseXY;
}
function tooltip_hide() {
	document.onmousemove = function() { void(0) };

	var o = document.getElementById('tooltip')
	o.style.display = 'none'
	o.style.top = '0px';
	o.style.left = '0px';
}

function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft
		tempY = event.clientY + document.body.scrollTop
	} 
	else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX
		tempY = e.pageY
	}
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0}  

	tempX = tempX + 15
	//tempY = tempY + 5
	
	var o = document.getElementById('tooltip')
	o.style.left = tempX+'px';
	o.style.top = tempY+'px';
	o.style.display = 'block';
	return true
}

// *************
// ajaxSrart
// *************
function ajaxStart()
{
	var request = false;
    
	try {
		request = new XMLHttpRequest();
	} catch(err1) {
		try {
			request = new ActiveXObject('Msxml2.XMLHTTP');
		} catch(err2) {
			try {
				request = new ActiveXObject('Microsoft.XMLHTTP');                
			} catch(err3) {
				request = false;
			}
		}
	}
	return request;
}

// ************
// FxSlide
// ************
function FxSlide(id, action) {
	var f = new Fx.Slide(id);

	switch (action) {
	case 'show': f.show(); break;
	case 'hide': f.hide(); break;
	case 'slideIn': f.slideIn(); break;
	case 'slideOut': f.slideOut(); break;
	case 'toggle': f.toggle(); break;
	}
}