var isLoaded = false;
var y2top = 0;
var x2left = 0;
// overly simplistic test for IE
isIE = (document.all ? true : false);
// both IE5 and NS6 are DOM-compliant (well, sort of...)
isDOM = (document.getElementById ? true : false);

// get the true offset of anything on NS4, IE4/5 & NS6, even if it's in a table!
function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }
function getAbsPos(elt,which) {
 iPos = 0;
 while (elt != null) {
  iPos += elt["offset" + which];
  elt = elt.offsetParent;
 }
 return iPos;
}

function getDivStyle(divname) {
 var style;
 if (isDOM) { style = document.getElementById(divname).style; }
 else { style = isIE ? document.all[divname].style
                     : document.layers[divname]; } // NS4
 return style;
}

function getDivElement(divname) {
 var element;
 if (isDOM) { element = document.getElementById(divname); }
 else { element = isIE ? document.all[divname]
                     : document.layers[divname]; } // NS4
 return element;
}

function hideElement(divname) {
 getDivStyle(divname).visibility = 'hidden';
 clearTimeout(intPID);
}
function showElement(divname) {
 getDivStyle(divname).visibility = 'visible';
}
function hideBlockElement(divname) {
 getDivStyle(divname).display = 'none';
}
function showBlockElement(divname) {
 getDivStyle(divname).display = 'block';
}
function ukryjszuk() {
 hideBlockElement('szukaj');
 showBlockElement('pokazszuk');
}
function pokazszuk() {
 hideBlockElement('pokazszuk');
 showBlockElement('szukaj');
}
// annoying detail: IE and NS6 store elt.top and elt.left as strings.
function moveBy(elt,deltaX,deltaY) {
 elt.left = parseInt(elt.left) + deltaX;
 elt.top = parseInt(elt.top) + deltaY;
}
function moveTo(elt,deltaX,deltaY) {
 elt.left = deltaX;
 elt.top = deltaY;
}
function toggleVisible(divname) {
 divstyle = getDivStyle(divname);
 if (divstyle.visibility == 'visible' || divstyle.visibility == 'show') {
   divstyle.visibility = 'hidden';
 } else {
   fixPosition(divname);
   divstyle.visibility = 'visible';
 }
}

function setPosition(elt,positionername,isPlacedUnder) {
 var positioner;
 if (isIE) {
  positioner = document.all[positionername];
 } else {
  if (isDOM) {
    positioner = document.getElementById(positionername);
  } else {
    // not IE, not DOM (probably NS4)
    // if the positioner is inside a netscape4 layer this will *not* find it.
    // I should write a finder function which will recurse through all layers
    // until it finds the named image...
    positioner = document.images[positionername];
  }
 }
 elt.left = getAbsX(positioner);
 elt.top = getAbsY(positioner) + (isPlacedUnder ? positioner.height : 0);
}









function showbigimage(elem,bigimagesrc,y2topb,x2leftb)
{
y2top = y2topb;
x2left = x2leftb;
mini = getDivElement(elem);
bigimgdivs = getDivStyle('bigimgdiv');
bigimgs = getDivStyle('bigimg');
bigimgo = getDivElement('bigimg');
hideElement('bigimgdiv');
x = getAbsX(mini);
y = getAbsY(mini);
//alert(bigimgo);
isLoaded = false;
bigimgo.src=bigimagesrc;
//bigimgdiv bigimg
//alert(bigimgo.src);
//document.body.appendChild(newelement);
//alert(bigimgdivs.top+'  '+x+','+y);
//LoadAndShow;
//clearTimeout(intPID);
//loadAndShow();
intPID = setTimeout( "loadAndShow2()", 300 );
//iWidth = (!isIE)?window.innerWidth:document.body.clientWidth;
//iHeight = (!isIE)?window.innerHeight:document.body.clientHeight;
//iWidth = (iWidth - bigimgo.width)/2;
//alert(iWidth+' - '+bigimgo.width);
//iHeight = bigimgo.height - iHeight;     
//bigimgdivs.left = iWidth+'px';
//bigimgdivs.top = (y-bigimgo.height-30)+'px';
//showElement('bigimgdiv');
//alert(bigimgdivs.left+'  '+bigimgdivs.top);
//bigimgdivs.left = '100px';
//bigimgdivs.top = '100px';
//newelement.style.position='absolute';
} 

function loadAndShow()
{

//if(isLoaded)
if(IsImageOk(bigimgo))
{
iWidth = (!isIE)?window.innerWidth:document.body.clientWidth;
iHeight = (!isIE)?window.innerHeight:document.body.clientHeight;
iWidth = (iWidth - bigimgo.width)/2;
//alert(iWidth+' - '+bigimgo.width);
//iHeight = bigimgo.height - iHeight;     
bigimgdivs.left = (iWidth+x2left)+'px';
//alert('y: '+y+' top: '+(y-bigimgo.height-30+y2top) );
bigimgdivs.top = (y-bigimgo.height-30+y2top)+'px';
showElement('bigimgdiv');
clearTimeout(intPID);
}
else
{
	intPID = setTimeout( "loadAndShow2()", 300 );
}
}
function loadAndShow2()
{
	loadAndShow();
}

//function loaded()
//{
//	isLoaded = true;
//}

var bigimgdivs;
var bigimgs;
var bigimgo;
var intPID;
//onload="loaded();"
function IsImageOk(img) {

    // During the onload event, IE correctly identifies any images that
    // weren't downloaded as not complete. Others should too. Gecko-based
    // browsers act like NS4 in that they report this incorrectly.
    if (!img.complete) {
    return false;
    }

    // However, they do have two very useful properties:  naturalWidth and
    // naturalHeight. These give the true size of the image. If it failed
    // to load, either of these should be zero.
    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
    	return false;
    }
    // No other way of checking: assume it's ok.
    return true;

}
//document.bigimg.onload=function() {
//	loaded();
//}
//intPID = setTimeout( eval('5'), 3 );

function sprawdzFormKontakt(alert1)
{
	if( document.oferta.imie.value == '' || document.oferta.nazwisko.value == '' || ( document.oferta.telstac.value == '' && document.oferta.telkom.value == '')  )
	{
		alert(alert1);
		return false;
	}
	return true;
}

function dzielnice()
{
	with(document.wyszukiwarka)
	{
	//wziac funkcje z mediamixu i zrobic tak jak teraz na bekrze - najpierw wykasowac, a potem dodac nowe
	//miasto
	//dzielnica
		m = miasto.options[miasto.selectedIndex].value;
		dzielnica.options.length = 1;
		if( m > 0 )
		{
			var dzielnice = dzi[m];
			var opisy = dzo[m];
			 for (var i=1; i <= dzielnice.length; i++)
			 {
			 	dzielnica.options[i]= new Option(opisy[i-1],dzielnice[i-1]);
			 }
		}
	}
}


