var $ = function(node){
	return document.getElementById(node);
} 
var $IMG = function(node){
	return document.images[node];
}
var $DOM_T = function(node){
	return function(nameT){
		return node.getElementsByTagName(nameT);
	}
}
var _A = function(){
	return document.URL;
}();
var _find = function(txtNode){
	return function(txt){
		if(txtNode.indexOf(txt)>-1){
			return true;
		}else{
			return false;
		}
	}
}
var addEventSimple = function(_h,_e,_mF,_uC){
	try{
		_h.addEventListener(_e, _mF, _uC); 
	}catch(e){
		try{
			_h.attachEvent('on'+_e, _mF);
		}catch(e2){}
	}
}
var removeEventSimple = function(_h,_e,_mF,_uC){
	try{
		_h.removeEventListener(_e, _mF, _uC); 
	}catch(e){
		try{
			_h.detachEvent('on'+_e, _mF);
		}catch(e2){}
	}
}

// browser name must be a one from browserList, and to chceck name browser must be acronym name's browser. 
// The browserList have four acronym IE(MS IE), FF(Mozilla Firefox), O(Opera), S(Safari)
navigatorCheck = function(){
	this.browser = navigator.userAgent.toUpperCase();
	this.browserList = {'IE':'MSIE','FF':'FIREFOX','O':'OPERA','S':'SAFARI','GC':'CHROME'};
	this.engineList={'WK' : 'WEBKIT','KH' : 'KHTML','TI' : 'TRIDENT','PR' : 'PRESTO','GE' : 'GECKO'};
	this.checkName = function($name){
		switch($name){
			case 'IE':
				return _find(this.browser)(this.browserList[$name]);
			break;
			case 'FF':
				return _find(this.browser)(this.browserList[$name]);
			break;
			case 'O':
				return _find(this.browser)(this.browserList[$name]);
			break;
			case 'S':
				return _find(this.browser)(this.browserList[$name]);
			break;
			case 'GC':
				return _find(this.browser)(this.browserList[$name]);
			break;
			default:
				return false;
		}
	}	
	this.checkVersion = function($name,$number){
		switch($name){
			case 'IE':
				return _find(this.browser)(this.browserList[$name]+' '+new String($number));
			break;
			case 'FF':
				if(_find(this.browser)(this.browserList[$name]+'/'+new String($number))){
					return true;
				}else{
					return _find(this.browser)(this.browserList[$name]+' '+new String($number));
				}
			break;
			case 'O':
				return _find(this.browser)(this.browserList[$name]+'/'+new String($number));
			break;
			case 'S':
				return _find(this.browser)(this.browserList[$name]+'/'+new String($number));
			break;
			case 'GC':
				return _find(this.browser)(this.browserList[$name]+'/'+new String($number));
			break;
			default:
				return false;
		}
	}
	this.checkEngine = function($name){
		switch($name){
			case 'WK':
				return _find(this.browser)(this.engineList[$name]);
			break;
			case 'KH':
				return _find(this.browser)(this.engineList[$name]);
			break;
			case 'TI':
				return _find(this.browser)(this.engineList[$name]);
			break;
			case 'PR':
				return _find(this.browser)(this.engineList[$name]);
			break;
			case 'GE':
				return _find(this.browser)(this.engineList[$name]);
			break;
			default:
				return false;
		}
	}
}
var nC = new navigatorCheck();
//-----------------------------------------

var stopEventPropagation = (!nC.checkName('IE'))?(function(e){
	e.preventDefault();
}):(function(e){
	return false;
});
stopOnSelect = function(){
	if(!nC.checkName('IE')){
		addEventSimple(document.body,'dblclick',stopEventPropagation,false);
		addEventSimple(document.body,'click',stopEventPropagation,false);
		addEventSimple(document.body,'mousedown',stopEventPropagation,false);
	}else{
		addEventSimple(document.body,'selectstart',stopEventPropagation,false);
	}
}
startOnSelect = function(){
	if(!nC.checkName('IE')){
		removeEventSimple(document.body,'dblclick',stopEventPropagation,false);
		removeEventSimple(document.body,'click',stopEventPropagation,false);
		removeEventSimple(document.body,'mousedown',stopEventPropagation,false);
	}else{
		removeEventSimple(document.body,'selectstart',stopEventPropagation,false);
	}
}

stopOnSelectElement = function(el){
	if(!nC.checkName('IE')){
		addEventSimple(el,'dblclick',stopEventPropagation,false);
		addEventSimple(el,'click',stopEventPropagation,false);
		addEventSimple(el,'mousedown',stopEventPropagation,false);
	}else{
		addEventSimple(el,'selectstart',stopEventPropagation,false);
		addEventSimple(el,'copy',stopEventPropagation,false);
		addEventSimple(el,'select',stopEventPropagation,false);
		addEventSimple(el,'dragstart',stopEventPropagation,false);
		addEventSimple(el,'drag',stopEventPropagation,false);
		addEventSimple(el,'contextmenu',stopEventPropagation,false);
	}
}

startOnSelectElement = function(el){
	if(!nC.checkName('IE')){
		removeEventSimple(el,'dblclick',stopEventPropagation,false);
		removeEventSimple(el,'click',stopEventPropagation,false);
		removeEventSimple(el,'mousedown',stopEventPropagation,false);
	}else{
		removeEventSimple(el,'selectstart',stopEventPropagation,false);
		removeEventSimple(el,'copy',stopEventPropagation,false);
		removeEventSimple(el,'select',stopEventPropagation,false);
		removeEventSimple(el,'dragstart',stopEventPropagation,false);
		removeEventSimple(el,'drag',stopEventPropagation,false);
		removeEventSimple(el,'contextmenu',stopEventPropagation,false);
	}
}
stopOnSelectElement2 = function(el){
	addEventSimple(el,'selectstart',stopEventPropagation,false);
	addEventSimple(el,'copy',stopEventPropagation,false);
	addEventSimple(el,'select',stopEventPropagation,false);
	addEventSimple(el,'contextmenu',stopEventPropagation,false);
	addEventSimple(el,'drop',stopEventPropagation,false);
}
startOnSelectElement2 = function(el){
	removeEventSimple(el,'selectstart',stopEventPropagation,false);
	removeEventSimple(el,'copy',stopEventPropagation,false);
	removeEventSimple(el,'select',stopEventPropagation,false);
	removeEventSimple(el,'contextmenu',stopEventPropagation,false);
	removeEventSimple(el,'drop',stopEventPropagation,false);
}
var ucwordsProperty = function(type){
	var res = new String;
	var i = 1;
	var sT = type.split('-');
	res += sT[0];
	while(sT[i]){
		for(var k = 0;k<sT[i].length;k++){
			if(k == 0){
				var tmp = new String(sT[i].charAt(k));
				res += tmp.toUpperCase();
			}else{
				res += sT[i].charAt(k);
			}
		}
		i++;
	}
	return res;
}
var getCssProperty = function(node,type){
		if (node.style[type]) {
			return node.style[type];
		} else if (document.defaultView && document.defaultView.getComputedStyle) {
			return document.defaultView.getComputedStyle(node, null).getPropertyValue(type);
		} else if (node.currentStyle) {
			type = ucwordsProperty(type);
			return node.currentStyle[type];
		} else {
			return null;
		}
}
var setCssOpacity = function(node, value){
	var opacity = typeof(value) != "undefined" ? value : 0.5;
	try{
		node.style.filter = 'alpha(opacity=' + (opacity * 100) + ')';
	}catch(err){
	}finally{
		node.style.opacity = opacity;
	}
}
var filertRemover = function(node){
	try{
		node.style.filter = undefined;
	}catch(e){}
}
var getObjFromString = function(val,sV,objVal){
	var ret = {};
	var splitRes = val.split(sV);
	var i = 0;
	for(var v in objVal){
		ret[objVal[v]] = {value : splitRes[i]?splitRes[i]:null};
		i++; 
	}
	return ret;
}
var setSpecCssProperty = function(node,type,valInc){
	var retVal = parseInt(getCssProperty(node,type))+valInc;
	return retVal+'px';
}
var setSpecCssProperty2 = function(node,valInc){
	var retVal = parseInt(node)+valInc;
	return retVal+'px';
}

VisualPresentation = function(){
	this.closeV = function(){
		var vP = $("v");
		vP.style.visibility = "hidden";
		vP.style.top = '-100000px';
	}
	this.cursor = function(_n,_t){
		if(_t==1){
			_n.style.cursor = 'url(/style/images/icon_lupa.png),url(/style/images/icon_lupa.cur),pointer';
		}else{
			_n.style.cursor = 'auto';
		}
	}
	this.imageVis = function(imgSrc){
		var ScrollTop = document.body.scrollTop;
		if (ScrollTop == 0){
			if(window.pageYOffset)
				ScrollTop = window.pageYOffset;
			else
				ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}
		imageTitle = (imgSrc.title==undefined)?'':imgSrc.title;
		imgSrc = imgSrc.src.replace(/size=[-0-9]{1,3}/gi,"size=-1");
		var vP = $("v");
		vP.innerHTML = '<div id="visualPresentationImg" onclick="visual.closeV();"></div>' +
				'<div id="imgVP" class="imgVP">' +
					'<div style="background:#FFF; padding:3px; border:1px solid #AAA;"><table style="width:32px;"><tr><td  style="width:100%;" align="center">' +
					'<img src="/style/images/ajax-loader.gif" alt="" style="border:1px solid silver;" /></td></tr>' +
					'</table></div>' +
				'</div><div style="position:absolute;top:-2000px;z-index:1;">' +
				'<div style="background:#FFF; padding:3px; border:1px solid #AAA;"><table><tr><td>' +
				'<img src="'+imgSrc+'" alt="" name="visImgPres" style="border:1px solid silver;" /></td></tr><tr><td align="right"><div id="imageTit" style="position:relative;z-index:1; float:left; text-align:left;">'+imageTitle+'</div>' +
				'<a style="width:20px; display:block; color:black; float:right; margin-left:10px;" align="center" href="javascript:visual.closeV();"><div></div></a></td></tr></table></div></div>';
		vP.style.visibility = "visible";
		vP.style.width = '100%';
		vP.style.top = (ScrollTop+100)+'px';
		vP.style.left = '0px';
		vP.style.height = '100%';		
		var w = document.body.clientWidth;
		var h = window.screen.height;
		vP.childNodes[1].style.left = new String(w/2 - 8)+ 'px';
		vP.childNodes[1].style.top = '0px';
		switch(nC.checkName('IE')){
			case true:{
				var sP = 'alpha(opacity=80)';
				vP.childNodes[0].style.filter=sP;
				if(nC.checkVersion('IE',6)){
					visualPresentationImg.style.height = document.body.scrollHeight+'px';
				}
				break;
			}
			default:{
				vP.childNodes[0].style.opacity = '0.8';
			}
		}
		var imgPre = new Image();
		imgPre.src = imgSrc;
		upVisualPresentation = function(){
				if(imgPre.complete){
					var imgWidth = document.images['visImgPres'].width;
					var imageTit = $('imageTit');
					imageTit.style.width = (parseInt(imgWidth)-80)+'px';
					var imgTop = (w/2 - imgWidth/2)>0?(w/2 - imgWidth/2):0;
					vP.childNodes[1].style.left = imgTop+'px';
					vP.childNodes[1].innerHTML = '';
					vP.childNodes[1].appendChild(vP.childNodes[2].childNodes[0]);
					return;
				}else{
					window.setTimeout('upVisualPresentation()',500);
				}
		}
		window.setTimeout('upVisualPresentation()',500);
	}
}
var visual = new VisualPresentation();


var newMessageWindow = function(_message){
	var vP = $("v");
	vP.innerHTML = 	'<div id="windowInfoBg"></div>'+
	'<div class="windowInfo">'+
	'<span>Komunikat</span>'+
	'<p>'+_message+'</p>'+
	'<a href="#" onclick="visual.closeV();">OK</a>'+
	'</div>';
	vP.style.visibility = "visible";
	vP.style.width = '100%';
	vP.style.top = '0px';
	vP.style.left = '0px';
	vP.style.height = '100%';
}
var newMessageWindow2 = function(_link,_message){
	var vP = $("v");
	vP.innerHTML = 	'<div id="windowInfoBg"></div>'+
	'<div class="windowInfo2">'+
	'<span>Komunikat</span>'+
	'<p>'+_message+'</p>'+
	'<a href="#" onclick="visual.closeV();window.location = \''+_link+'\';">OK</a><a href="#" onclick="visual.closeV();">Anuluj</a>'+
	'</div>';
	vP.style.visibility = "visible";
	vP.style.width = '100%';
	vP.style.top = '0px';
	vP.style.left = '0px';
	vP.style.height = '100%';
}
var newMessageWindow3 = function(_link,_message){
	var vP = $("v");
	vP.innerHTML = 	'<div id="windowInfoBg"></div>'+
	'<div class="windowInfo">'+
	'<span>Komunikat</span>'+
	'<p>'+_message+'</p>'+
	'<a href="#" onclick="visual.closeV();window.location = \''+_link+'\';">OK</a>'+
	'</div>';
	vP.style.visibility = "visible";
	vP.style.width = '100%';
	vP.style.top = '0px';
	vP.style.left = '0px';
	vP.style.height = '100%';
}
var formcat = function(){
	this.success = false;
	
	this.length_input = function(s,e,n,m){
		if ((n.value.length>=s)&&(n.value.length<=e)){
			this.success = true;
			return true;
		}
		else{
			newMessageWindow(m);
			this.success = false;
			return false;
		}		
	}
	
	this.post_code = function(n,m){
		if (n.value.match(/^[0-9]{2}\-[0-9]{3}$/)){
			this.success = true;
			return true;
		}
		else{
			newMessageWindow(m);
			this.success = false;
			return false;
		}	
	}
	
	this.chars_val = function(n,m){
		if (n.value.match(/^[a-zA-ZąężźćłóńśŁÓŃĘŚĄŻŹĆ ]{3,150}$/)){
			this.success = true;
			return true;
		}
		else{
			newMessageWindow(m);
			this.success = false;
			return false;
		}	
	}
	this.login_pass = function(n,m){
		if (n.value.match(/^[a-zA-Z0-9ąężźćłóńśŁÓŃĘŚĄŻŹĆ\-\_]{5,40}$/)){
			this.success = true;
			return true;
		}
		else{
			newMessageWindow(m);
			this.success = false;
			return false;
		}	
	}
	
	this.email_val = function(n,m){
		if (n.value.match(/^[^@^\#^\=^\!^\&^\(^\)^\%^\,^\\^\|^\[^\{^\]^\}^\<^\>^\?^\/^\+^\$^\*^\~^\`^\^^\'^\"]+@([a-z0-9\-]+\.)+[a-z]{2,4}$/)){
			this.success = true;
			return true;
		}
		else{
			newMessageWindow(m);
			this.success = false;
			return false;
		}			
	}
	this.checkpass = function(p1,p2,m){
		if (p1.value === p2.value){
			this.success = true;
			return true;
		}
		else{
			newMessageWindow(m);
			this.success = false;
			return false;
		}		
	}
	this.notEmpty = function(n,m){
		if (n.value.length>0){
			this.success = true;
			return true;
		}
		else{
			newMessageWindow(m);
			this.success = false;
			return false;
		}	
	}
}
var deleteLink = function(_link,_name){
	newMessageWindow2(_link,'Czy napewno chcesz usunąć: '+_name );
	//if(window.confirm('Czy napewno chcesz usunąć: '+_name)){
	//		window.location = _link;
	//}
}
window.onload = function(){
	var _footer = $('menubottom');
	var x = document.createElement('div');
	x.style.height = '100%';
	x.style.position = 'fixed';
	x.style.zIndex = '-1';
	x.style.width = '10px';
	x.style.top = '0px';
	x.style.left = '0px';
	x.style.backgroundColor = "#FFF";
	x.style.visibility = 'hidden';
	x.setAttribute('id','innerHeight1');
	document.body.appendChild(x);
	var _x = $('innerHeight1');
	if((window.innerHeight?window.innerHeight:_x.clientHeight)-document.body.clientHeight>0){
		var _w = ((document.body.clientWidth - 960)/2); 
		_footer.style.position = 'fixed';
		_footer.style.bottom = '0px';
		_footer.style.left = _w+'px';
		var x2 = document.createElement('div');
		x2.style.height = '100%';
		x2.style.position = 'fixed';
		x2.style.zIndex = '-1';
		x2.style.width = '960px';
		x2.style.top = '0px';
		x2.style.left = (_w)+'px';
		x2.style.backgroundColor = "#FFF";
		document.body.appendChild(x2);
	}
}
var changeImage = function(_dest,_src){
	$(_dest).src = _src.replace(/size=[-0-9]{1,3}\&c=[0-9]{1,4}/gi,"size=2&c=200");
	//	$tmp['images2'] = preg_replace("/\&size=0\&c=[0-9]{1,4}/","&size=2&c=200",$res['images']);;
}
