function putcookie(c_name,value,expiredays) {
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie = c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate);
}

function getcookie(c_name) {
    if(document.cookie.length > 0) {
        var c_start = document.cookie.indexOf(c_name + "=");
        if(c_start != -1) {
            c_start = c_start + c_name.length + 1;
            var c_end = document.cookie.indexOf(";",c_start);
            if(c_end == -1)
                c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return null;
}
function $(id) {
	return document.getElementById(id);
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function set_background(id,last) {
	for (i=1;i<=last;i++) {
		var obiekt=$('li_'+i);
		if (obiekt!=null) {
			if (id==i) {
				$('li_'+id).style.background='url("images/left_on.gif") no-repeat left top';
				$('a_'+id).style.background='url("images/right_on.gif") no-repeat right top';
				$('a_'+id).style.color='#ffba00';
				$('submenu_'+id).style.display='block';
			} else {
				$('li_'+i).style.background='url("images/left.gif") no-repeat left top';
				$('a_'+i).style.background='url("images/right.gif") no-repeat right top';
				$('a_'+i).style.color='#ffffff';
				$('submenu_'+i).style.display='none';
			}
		}
	}
}
function set_background2(id,last,current) {
	for (i=1;i<=last;i++) {
		var obiekt=$('li_'+i);
		if (obiekt!=null) {
			if (current==i) {
				$('li_'+current).style.background='url("images/left_on.gif") no-repeat left top';
				$('a_'+current).style.background='url("images/right_on.gif") no-repeat right top';
				$('a_'+current).style.color='#ffba00';
				$('submenu_'+current).style.display='block';
			} else if (i==id && current!=i) {
				$('li_'+id).style.background='url("images/left_on.gif") no-repeat left top';
				$('a_'+id).style.background='url("images/right_on.gif") no-repeat right top';
				$('a_'+id).style.color='#ffba00';
			} else {
				$('li_'+i).style.background='url("images/left.gif") no-repeat left top';
				$('a_'+i).style.background='url("images/right.gif") no-repeat right top';
				$('a_'+i).style.color='#ffffff';
			}
		}
	}
}
function clear_background(id,last) {
	var obiekt=$('li_'+id);
	if (obiekt!=null) {
		$('li_'+id).style.background='url("images/left.gif") no-repeat left top';
		$('a_'+id).style.background='url("images/right.gif") no-repeat right top';
		$('a_'+id).style.color='#ffffff';
	}
}
function set_background(id,last) {
	for (i=1;i<=last;i++) {
		var obiekt=$('li_'+i);
		if (obiekt!=null) {
			if (id==i) {
				$('li_'+id).style.background='url("images/left_on.gif") no-repeat left top';
				$('a_'+id).style.background='url("images/right_on.gif") no-repeat right top';
				$('a_'+id).style.color='#ffba00';
				$('submenu_'+id).style.display='block';
			} else {
				$('li_'+i).style.background='url("images/left.gif") no-repeat left top';
				$('a_'+i).style.background='url("images/right.gif") no-repeat right top';
				$('a_'+i).style.color='#ffffff';
				$('submenu_'+i).style.display='none';
			}
		}
	}
}
function back_tabs(last) {
	if (getcookie('aktual_tab')==null) {
		tab_old='1';
	} else {
		tab_old=getcookie('aktual_tab');
	}
	for (i=1;i<=last;i++) {
		var obiekt=$('ta_'+i);
		if (obiekt!=null) {
			if (i==tab_old) {
				$('ta_'+i).style.background='url("images/left_tabs_on.gif") no-repeat left top';
				$('tab_'+i).style.background='url("images/right_tabs_on.gif") no-repeat right top';
				$('tab_'+i).style.color='#ffba00';
			} else {
				$('ta_'+i).style.background='url("images/left_tabs.gif") no-repeat left top';
				$('tab_'+i).style.background='url("images/right_tabs.gif") no-repeat right top';
				$('tab_'+i).style.color='#ffffff';
			}
		}
	}
}
function show_tab(id,last) {
	for (i=1;i<=last;i++) {
		var obiekt=$('ta_'+i);
		if (obiekt!=null) {
			if (i==id) {
				$('ta_'+id).style.background='url("images/left_tabs_on.gif") no-repeat left top';
				$('tab_'+id).style.background='url("images/right_tabs_on.gif") no-repeat right top';
				$('tab_'+id).style.color='#ffba00';
			} else {
				$('ta_'+i).style.background='url("images/left_tabs.gif") no-repeat left top';
				$('tab_'+i).style.background='url("images/right_tabs.gif") no-repeat right top';
				$('tab_'+i).style.color='#ffffff';
			}
		}
	}	
}
function change_tab(tab,layer,last) {
	for (i=1;i<=last;i++) {
		var obiekt=$('ta_'+i);
		if (obiekt!=null) {
			if (i==tab) {
				putcookie('aktual_tab', tab, 7200);
				$('ta_'+tab).style.background='url("images/left_tabs_on.gif") no-repeat left top';
				$('tab_'+tab).style.background='url("images/right_tabs_on.gif") no-repeat right top';
				$('tab_'+tab).style.color='#ffba00';
			} else {
				$('ta_'+i).style.background='url("images/left_tabs.gif") no-repeat left top';
				$('tab_'+i).style.background='url("images/right_tabs.gif") no-repeat right top';
				$('tab_'+i).style.color='#ffffff';
			}
		}
	}
	if (layer!='')
		show_layer(layer);
	else
		putcookie('aktual_box', 'div_1_1', 7200);
}
function show_layer(layer) {
	if (getcookie('aktual_box')==null) {
		layer_old='div_1_1';
	} else {
		layer_old=getcookie('aktual_box');
	}
	putcookie('aktual_box', layer, 7200);
	$(layer_old).style.display='none';
	$(layer).style.display='block';
}
// Alt panels
var horizontal_offset="9px" 

var vertical_offset="0" 
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
	var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
	if (whichedge=="rightedge"){
		var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
			edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
	} else{
		var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
			edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
	}
return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
	if ((ie||ns6) && document.getElementById("onmouseBox")){
		dropmenuobj=document.getElementById("onmouseBox")
		dropmenuobj.innerHTML=menucontents
		dropmenuobj.style.left=dropmenuobj.style.top=-500
		if (tipwidth!=""){
			dropmenuobj.widthobj=dropmenuobj.style
			dropmenuobj.widthobj.width=tipwidth
		}
		dropmenuobj.x=getposOffset(obj, "left")
		dropmenuobj.y=getposOffset(obj, "top")
		dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
		dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
		dropmenuobj.style.visibility="visible"
		obj.onmouseout=hidetip
	}
}

function hidetip(e){
	dropmenuobj.style.visibility="hidden"
	dropmenuobj.style.left="-500px"
}

function createhintbox(){
	var divblock=document.createElement("div")
	divblock.setAttribute("id", "onmouseBox")
	document.body.appendChild(divblock)
}

function drukuj_oferte(id_oferty) {
	window.open('/drukuj_oferte.php?id_oferty='+id_oferty,'oferta','width=800,height=600,scrollbars=yes,menubar=no,statusbar=no,resizable=no');
	}	

function drukuj_trase(trasa) {
	window.open('/drukuj_trase.php?kierunek='+trasa,'trasa','width=600,height=400,scrollbars=yes,menubar=no,statusbar=no,resizable=no');
	}	

function pobierz_modele(id_marki){

	advAJAX.setDefaultParameters({
   		onInitialization : function(obj) { document.getElementById(obj.tag).innerHTML = "<option value='0'>wszystkie modele</option>"; },
   		onLoading : function(obj) { document.getElementById(obj.tag).innerHTML = "<option value='0'>wszystkie modele</option>"; },
  		onSuccess : function(obj) { document.getElementById(obj.tag).innerHTML = obj.responseText; },
  		onError : function(obj) { document.getElementById(obj.tag).innerHTML = "<option value='0'>wszystkie modele</option>"; }
	});
	
	advAJAX.get({ url: "/modele.php?id_marki="+id_marki, tag: "modele" });
}
function nowe_oferty(){
	window.open('/nowe_oferty.php','nowe_oferty','width=400,height=450,scrollbars=no,menubars=no,status=yes,resizable=no');
}

function ramka(tabela_id){
	if(document.getElementById('ma'+aktualna_id)){
		document.getElementById('ma'+aktualna_id).style.border="";
	}
	document.getElementById('ma'+tabela_id).style.border="1px solid #ef6c00";
	aktualna_id=tabela_id;
}

if (window.addEventListener)
	window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
	window.attachEvent("onload", createhintbox)
else if (document.getElementById)
	window.onload=createhintbox