$=function(x){return document.getElementById(x)}

mkPopup=function(mypage,myname,w,h,scroll){
 var winl=(screen.width-w)/2;
 var wint=(screen.height-h)/2;
 var settings='height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no';
 win=window.open(mypage,myname,settings);
}
resBody=function(o){
	return true;
	var w=o.width;
	var h=o.height;
	if (w>0&&h>0) {
		var resWidth = w + 0;
		var resHeight = h + 40;
		var ua = navigator.userAgent.toLowerCase();
		var isOp=(ua.indexOf("opera")!=-1?true:false);
		var isIe=(ua.indexOf("msie")!=-1&&!isOp?true:false);
		if (isIe) {
			resWidth = w + 35;
			resHeight = h + 65;
		}
	
		if (window.screen.width < resWidth)resWidth=window.screen.width-20;
		if (window.screen.height < resHeight)resHeight=window.screen.height-20;
		
		window.resizeTo(resWidth, resHeight);
		
		var wx=(screen.width-w)/2, wy=(screen.height-h)/2;
 		window.moveTo(wx,wy);
		//self.focus();
	}
}
function preloadImg(src) {
	new Image().src=src;
}

function tabs(tabsconfig)
{
	this.tabsconfig = tabsconfig;
	
	this.ch = function(tab_active)
	{
		for(i=0; i<this.tabsconfig.length; i++)
		{
			if (this.tabsconfig[i] == tab_active)
			{
				$('t'+this.tabsconfig[i]).className = this.tabsconfig[i]+'_a';
				$('c'+this.tabsconfig[i]).className = 'txt'+this.tabsconfig[i]+'_a';
			}
			else
			{
				$('t'+this.tabsconfig[i]).className = this.tabsconfig[i];
				$('c'+this.tabsconfig[i]).className = 'txt'+this.tabsconfig[i];
			}
		}
	}
}

function gourl(u)
{
	document.location.replace(u);
	return false;
}

function cart()
{
	this.addProduct = function(prodId)
	{
		//alert('Obsługa dodania do koszyka produktu o ident. '+prodId)
		document.location.replace('/koszyk/?a=prod_add&p='+prodId);
	}
}

function chmimg(imgid) {
	if (imgs[imgid]) {
		$('phone_mimg').src = imgs[imgid].S;
		$('phone_mimg').parentNode.href=imgs[imgid].D;
		new Image().src=imgs[imgid].D;
	}
}

cart = new cart();
function checkOrderFrm(fobj)
{
	var paytype_checked = false;
	for(var i=0; i<fobj.paytype.length; i++)
	{
		if (fobj.paytype[i].checked)
		{
			paytype_checked = true;
			throw $break;
		}
	}
	if (!paytype_checked)
	{
		alert('Wybierz sposób płatności.');
		return false;
	}
}

/* newsletter */
function newsletter_change(obj){input_change(obj,'Wpisz swój adres e-mail')}
function input_change(obj,txt){if(obj.value==txt)obj.value=''};
function newsletter_send(o){
	if (typeof o == 'undefined') {
		o = '';
	}
	var err=false;
	var eObj=$('newsletter_email'+o);
	if (eObj.value==null||eObj.value==''||eObj.value=='Wpisz swój adres e-mail'||!isEmail(eObj.value))
	{
		err=true;
		alert('Wpisz poprawny adres e-mail.');
		eObj.focus();
		return false;
	}
	
	advAJAX.get({
		url: "/index.php?m=newsletter&a=addemail&email="+eObj.value,
		onLoading : function(obj){ /* Wy?wietlenie obrazka wskazuj?cego na ?adowanie */ },
		onComplete : function(obj) { /* Ukrycie obrazka... */ },
		onSuccess : function(obj) {
			eval('ret = obj.responseText');
			if (ret == '-1') {
				alert('Podany adres email już został dopisany do naszej bazy.');
				eObj.value='';
				eObj.focus();
			} else if (ret == '1') {
				alert('Dziękujemy. Twój email został dopisany do naszego newslettera.');
				eObj.value='';
			} else {
				alert('Wpisz poprawny adres e-mail.');
			}
		}
	})
	return false;
}

function search_change(obj){input_change(obj,'szukaj...')}

/** email validation stuff. Based on: SmartWebby.com (http://www.smartwebby.com/dhtml/) */
isEmail=function(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
		return false
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
		return false
	}
	
	if (str.indexOf(" ")!=-1){
		return false
	}

	return true					
}

function checkHeight(d) {
	if (!d) return false;
	var divHeight=0;
	//d=$(arguments[0]);
	if(d.offsetHeight)
		divHeight=d.offsetHeight;
	else if(d.style.pixelHeight)
		divHeight=d.style.pixelHeight;
	return divHeight;
}
function max(a,b) {return (a>b)?a:b}
function bim(){try{window.event.returnValue=false}catch(e){};return false}

function addToFavorite()
{
	try {
		window.external.AddFavorite(document.location, document.title);
	} catch(e) {
		alert('Jeśli chcesz dodać tą stronę do ulubionych, naciśnij OK a następnie CTRL+D');
	}
}

lcw = {
	change_lang: function(s){
		var l = s[s.selectedIndex].value;//s.getValue();
		if (l.length > 0) {
			$('flng').action = SERVOFFSET+'/'+l+'/';
			$('flng').submit();
			//document.location.replace(SERVOFFSET+'/'+l+'/?m=chlng');
		}
	}
}