/** global functions */
function gebi(obid){
	return document.getElementById(obid);
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function updateContCalculate(elementId, url){
	if(elementId=='calculateDivPrice'){
		var tekst = '<div align="center" class="calculateDivPrice"><br />Sprawdzanie dostępności oferty<br /><br /><img src="'+returnLoadingImg()+'" alt="" style="border:none;"></div>';
	}else{
		var tekst = 'pobieranie...';
	}
	var elUpd = document.getElementById(elementId);
	if(elUpd){
		elUpd.innerHTML = tekst;
	}
	Spry.Utils.updateContent(elementId, url);
}

function updateContReload(elementId, url, string, fun, small){
	if(!string){
		string = 'Sprawdzanie...';
	}
	if( !fun ) {
		fun = function() {};
	}
	if( small ) {
		var tekst = '<div align="center">' + string + '<br /><img src="'+returnLoadingImg()+'" alt="" style="border:none;"></div>';
	} else {
		var tekst = '<div align="center"><br /><br /><br />' + string + '<br /><br /><img src="'+returnLoadingImg()+'" alt="" style="border:none;"></div>';
	}
	
	var elUpd = document.getElementById(elementId);
	if(elUpd){
		elUpd.innerHTML = '<h3>'+tekst+'</h3>';
		setTimeout( "updateContReloadNow('"+elementId+"','"+ url + "', "+fun+");", 200);
	}
}

function updateContReloadNow(elementId, url, fun){
	Spry.Utils.updateContent(elementId, url, fun);
}


function returnLoadingImg () {
	return "data:image/gif;base64,R0lGODlhNAAOAJEAAPiZPf/fff///wAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQhDwACACwAAAAANAAOAAAIhAAFCBxIsKDBgwgTIgTAsGHDggEiSpQIceJEghYvCnDIsWLGAB4zYvwIciPHhyM/hrSYUqTJkwBWahxIsqTAmgJhMpRJsSVLmiRz6uQZkahNAThfnjTKFKhKpR19zrwZ1KlLnTGl9rT6k+pTrE25Tk0KVmtRs0fJDkUbFmlVhXDjyi0YEAAh+QQhDwACACwBAAEAFwAMAAAIQgADCBw4UIBBgwASKlRIsOFBhAsXNiT4UEBEiRMFVrzIMGOAjRwBePz4MKRIjyA5jkx5cWXJkC4PmowJUSXKlxwDAgAh+QQhDwACACwPAAEAFwAMAAAIQgADCBw4UIBBgwASKlRIsOFBhAsXNiT4UEBEiRMFVrzIMGOAjRwBePz4MKRIjyA5jkx5cWXJkC4PmowJUSXKlxwDAgAh+QQhDwACACwdAAEAFgAMAAAIQQADCBw4UIBBAQASKlRIsOFBhAsXNiT4MKLEiQIrWkyIMePBjRw7atzYMcBIiyVPRkz5ESRLgyABvIRIUmTLjQEBADs=";
}

function chatPopup( title ) {
	var chatUrl = 'call/index.php?m=Guest&e=login';
	window[ 'popW' ] = window.open( 	chatUrl + '&title=' + title , 'chatWindow' ,
										'width=500,height=400,resizable=0,toolbar=0,menubar=0,location=0,status=0,scrollbars=0' 	);
}

function dID( idFun ) {
	return document.getElementById( idFun );
}

function dTAG( tagFun , obFun ) {
	var ob = document;
	
	if( !tagFun ) { tagFun = '*'; }
	if( obFun ) { ob = obFun; }
	
	if( ob ) {
		return ob.getElementsByTagName( tagFun );
	}
}


function dCLASS( classFun , tagFun ) {
	if( !classFun ) { classFun = ''; }
	if( !tagFun ) { tagFun = '*'; }
	
	var divList 	= dTAG( tagFun );
	var classList 	= new Array();
	
	if( divList ) {
		for( var el in divList ) {
			if( ( divList[ el ].className == classFun ) ) {
				classList.push( divList[ el ] );
			}
		}
	}
	
	return classList;
}
