function $( id ) {
	return document.getElementById( id );
}

function getElementsByClassName(clsName, idName) {
	var retVal = new Array();
	if ( idName == undefined ) {
		var elements = document.getElementsByTagName("*");
	} else {
		if ( document.getElementById(idName) != undefined ) {
			var elements = document.getElementById(idName).getElementsByTagName("*");
		} else {
			var elements = false;
		}
	}
	for(var i = 0;i < elements.length;i++) {
		if(elements[i].className.indexOf(" ") >= 0) {
			var classes = elements[i].className.split(" ");
			for(var j = 0;j < classes.length;j++) {
				if(classes[j] == clsName) {
					retVal.push(elements[i]);
				}
			}
		} else if(elements[i].className == clsName) {
			retVal.push(elements[i]);
		}
	}
	return retVal;
}

function number_format(number, decimals, dec_point, thousand_sep, p) {

    var n = (''+(Math.round(number*(p=Math.pow(10,decimals||0)))/p)).split('.');
    for(var i=(n[0]=n[0].split('')).length-3; i>0; i-=3) {
        n[0].splice(i,0,thousand_sep);
    }

    return n[0].join('')+(n[1]?(dec_point||',')+((n[1].length==2)?n[1]:n[1]+0):'.00');
}


function comma2dot(tekst) {
    var re = new RegExp(',','g');
    var a = tekst.replace(re,".");
    return a;
}

function newWindow( url, w, h ) {
	window.open( url , url, 'width=' + w + ', height=' + h + ', resizable=0, scrollbars=auto, menubar=no' );
}

function mailtoOnClick(mailName, domainName) {
	var separator = '@';
	return document.location.href = 'mailto:' + mailName + separator + domainName;
}


function mailto(mailName, domainName) {
	var separator = '@';
	var email = '<a href' + '="" onClick' + '="mailtoOnClick(\'' + mailName +'\', \'' + domainName + '\'); return false;" title="Napisz wiadomość" />';
			email+= mailName + separator + domainName;
			email+= '</a' + '>';
	return email;
}

function chmurkaPokaz( id, element ) {
	$(id).style.display = 'inline';
	$(id).onmouseout = function() {
		setTimeout( function() {
				return chmurkaZakryj( id )
			}, 400
		);
	}
	element.onmouseout = function() {
		setTimeout( function() {
				return chmurkaZakryj( id )
			}, 400
		);
	}
}

function chmurkaZakryj( id ) {
	$(id).style.display = 'none';
}

function checkMail( q ) {
	var mail = /^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/;
	if (!(mail.test( q )) ) {
		return false;
	} else {
		return true;
	}
}

function replaceClassElement( id, c ) {
	if (navigator.appName == 'Microsoft Internet Explorer') {
		$(id).removeAttribute('class');
		$(id).className = c;
	} else {
		$(id).setAttribute('class', c);
	}
}
