
function setAction() {
    if (navigator.appName.indexOf('Netscape') > -1) {
         document.formName.action = document.formName.selectName.options[document.formName.selectName.selectedIndex].value;
         return true;
    }
    else {
        alert('Sorry, your browser does not support the changing of the action property of a form');
        return false;
    }

}

// OPEN WINDOW 
openWin = function(url,name,width,height,xpos,ypos,chrome,scroll){
  var x, y, w, h, moveX=0, moveY=0, features="";
  chrome = chrome ? "yes" : "no";
  scroll = scroll ? "yes" : "no";
  features += "toolbar="+chrome+",location="+chrome+",status="+chrome+",menubar="+chrome;
  features += ",scrollbars="+scroll+",resizable="+scroll;
  if(width) features += ",width="+width;
  if(height) features += ",height="+height;
  if(xpos && window.screen){
    w = window.screen.availWidth;
    width = parseInt(width);
    switch(xpos){
      case "left": x = 0; break;
      case "center": x = (w-width)/2; break;
      case "right": x = w-width; break;
      default: x = xpos;
    }
    features += ",screenX="+x+",left="+x;
    var moveX = x;
  }
  if(ypos && window.screen){
    h = window.screen.availHeight;
    height = parseInt(height);
    switch(ypos){
      case "top": y = 0; break;
      case "middle": y = (h-height)/2; break;
      case "bottom": y = h-height; break;
      default: y = ypos;
    }
    features += ",screenY="+y+",top="+y;
    var moveY = y;
  }
  openWinReference = window.open(url,name,features);
  if(moveX || moveY){
    // position the window for browsers that don't recognize screenX, screenY
    openWinReference.moveTo(moveX,moveY);
  }
}
openScroll = function(url,name,width,height){
  openWin(url,name,width,height,false,false,false,"scroll");
}
openCenter = function(url,name,width,height){
  openWin(url,name,width,height,"center","middle");
}
openCenterScroll = function(url,name,width,height){
  openWin(url,name,width,height,"center","middle",false,"scroll");
}
openFull = function(url,name){
  openWin(url,name,false,false,false,false,"chrome","scroll");
}

/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetfrommouse=[25,-15]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 60;	// maximum image size.

if (document.getElementById || document.all){
	document.write('<div id="imgid">');
	document.write('</div>');
}

function gettrailobj(){
if (document.getElementById)
return document.getElementById("imgid").style
else if (document.all)
return document.all.trailimagid.style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("imgid")
else if (document.all)
return document.all.trailimagid
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
var showTrailDelay;
function showtrail(txt,height){
            var displayTrail = function() {
            var gton = gettrailobjnostyle();
            if(gton.childNodes[0]) {
                gton.removeChild(gton.childNodes[0]);
            }
            document.onmousemove=followmouse;
            var newHT = document.createElement('div');
            newHT.setAttribute("class", "onFrame");
            var newHT2 = document.createElement('div');
            newHT2.setAttribute("class", "onFrameIn");
            newHT2.innerHTML = txt;
            newHT.appendChild(newHT2);
            gton.appendChild(newHT);
            gettrailobj().visibility="visible";
        }

        showTrailDelay = setTimeout(displayTrail, 250);
}

function hidetrail(){
        clearTimeout(showTrailDelay);
	gettrailobj().visibility="hidden"
	document.onmousemove=""
	gettrailobj().left="-500px"
}

function followmouse(e) {

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 320){
			xcoord = e.pageX - xcoord - 300; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight + 180)){
			ycoord += e.pageY - Math.max(0,(180 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < 320){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 300; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 180)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(180 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
		if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
}

function textCounter (field, countfield, maxlimit) {
if (field.value.length > maxlimit) {
field.value = field.value.substring(0, maxlimit);
alert ('Zbyt dlugi tekst.');
}
else 
countfield.value = maxlimit - field.value.length;
}

function isUrl(s) {
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}

function checkField(el, type){
    var chck = false;
    var msg = "Ups, popraw:";
    if(!el || !type){
        return false;
    }
    if(type==='url') {
        msg += "\n - adres url uwzgledniajac http://"
        chck = isUrl(el.value); 
    }
    if(!chck){
        alert(msg);
        el.value = "";
        el.focus();
        return false;
    }
    return true;
}

function submitSearchForm(that) {
    if(that.selectName.options[that.selectName.selectedIndex].value == 0) {
         window.location = '/search.php?query='+that.query.value+'&mode='+that.mode.value+'&type=all';
    } else {
         window.location = '/search.php?query='+that.query.value+'&mode=google&cx='+that.cx.value+'&cof='+that.cof.value+'&ie='+that.ie.value;
    }
}

// include separated js files
function includeJS(url) {document.writeln("<script type=\"text/javascript\" src=\"" + url + "\"></script>");}
function includeCSS(url) {document.writeln("<style type=\"text/css\">@import url(\"" + url + "\");</style>");}

if (/page=mapa-gliwic$/i.test(location.href)) {
    includeJS("http://www.google.com/jsapi?key=ABQIAAAA-jQMa40V6uOul4ZyrhYAxhTEC5XGw1_68gzXIkLI3jNdMLuPVxRb9XzMNN5MBbjJtM_qLgAIs1iwBg");
    includeJS("http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA-jQMa40V6uOul4ZyrhYAxhTEC5XGw1_68gzXIkLI3jNdMLuPVxRb9XzMNN5MBbjJtM_qLgAIs1iwBg&amp;hl=pl");
    includeJS("/js/gmap.js"); 
}
