var xmlHttpContentP;
var idWyslijAjax = 0;
var ocenaArt = {
_tabElem : null,
_actualElem : 0,
_IE : ((navigator.appName == 'Microsoft Internet Explorer')? 1 : 0),
_ocena : null,
_idArt : null,
_wysylanieAjax : true,

init : function(ocena,idArt,glosuj){
ocenaArt._ocena = parseInt(ocena);
ocenaArt._idArt = idArt;

//if(ocenaArt._IE) ocenaArt._tabElem = ocenaArt.getElementsByName_iefix('span','ocena');
//else ocenaArt._tabElem = document.getElementsByName('ocena');

ocenaArt._tabElem = ocenaArt.getElementsByName_iefix('span','ocena');

ocenaArt.ustawOcenaPrev(ocenaArt._ocena);

if(window.navigator.cookieEnabled && glosuj==1){

for(var i=0;i<ocenaArt._tabElem.length;i++){
ocenaArt.addEvent(ocenaArt._tabElem[i],'mouseover',ocenaArt.pokazOcena);
ocenaArt.addEvent(ocenaArt._tabElem[i],'mousemove',ocenaArt.pokazToolTip);
ocenaArt.addEvent(ocenaArt._tabElem[i],'mouseout',ocenaArt.outOcena);
//ocenaArt.addEvent(ocenaArt._tabElem[i],'click',ocenaArt.ocen);
}
}else{
for(var i=0;i<ocenaArt._tabElem.length;i++){
ocenaArt._tabElem[i].style.cursor = 'default';
//ocenaArt.addEvent(ocenaArt._tabElem[i],'mouseover',ocenaArt.pokazOcenaDis);
//ocenaArt.addEvent(ocenaArt._tabElem[i],'mouseout',ocenaArt.outOcenaDis);
}
}
},
pokazToolTip : function(e){
var event = (e)?e:event; 
var element;
if(event.srcElement) element = event.srcElement;
else element = this;

var idElem = parseInt((element.id).replace('o',''));
showTooolTipMapka(element,e,tabOcena[idElem]);
},
outOcenaDis : function(e){
var event = (e)?e:event; 
var element;
if(event.srcElement) element = event.srcElement;
else element = this;
hiddenTooolTipMapka(element,e);
},
addEvent : function(elem,eventS,funkcja){
if(window.addEventListener) elem.addEventListener(eventS,funkcja,false);
else elem.attachEvent('on'+eventS,funkcja,false);  
},
removeEvent : function(elem,eventS,funkcja){
if(window.removeEventListener) elem.removeEventListener(eventS,funkcja,false);
else elem.detachEvent('on'+eventS,funkcja,false);  
},
getElementsByName_iefix : function(tag, name) {
var elem = document.getElementsByTagName(tag);
var arr = new Array();
  for(i = 0,iarr = 0; i < elem.length; i++) {
     att = elem[i].getAttribute("title");
       if(att == name) {
               elem[i].setAttribute('title','');   
               arr[iarr] = elem[i];
               iarr++;
       }
 }
return arr;
},
pokazOcena : function(e){
var event = (e)?e:event; 
var element;
if(event.srcElement) element = event.srcElement;
else element = this;

var idElem = parseInt((element.id).replace('o',''));

//showTooolTipMapka(element,e,tabOcena[idElem]);
ocenaArt.ustawOcena(idElem);
},
outOcena : function(e){
var event = (e)?e:event; 
var element;
if(event.srcElement) element = event.srcElement;
else element = this;

hiddenTooolTipMapka(element,e);
ocenaArt.ustawOcenaPrev(ocenaArt._ocena);
},
ustawOcenaPrev : function(IDocena){
for(var i=0;i<ocenaArt._tabElem.length;i++){
if(i<=IDocena) ocenaArt._tabElem[i].className = 'ocenArtSelectLight';
else ocenaArt._tabElem[i].className = 'ocenArt';
}
},
ustawOcena : function(IDocena){
for(var i=0;i<ocenaArt._tabElem.length;i++){
if(i<=IDocena) ocenaArt._tabElem[i].className = 'ocenArtSelect';
else ocenaArt._tabElem[i].className = 'ocenArt';
}
},
ocen : function(e){
if(ocenaArt._wysylanieAjax){
ocenaArt._wysylanieAjax = false;
xmlHttpContentP = createAjaxObject();
var event = (e)?e:event; 
var element;
if(event.srcElement) element = event.srcElement;
else element = this;

var komunikatOcena = document.getElementById('komunikatOcena');
komunikatOcena.innerHTML = "Obliczanie głosów...";

hiddenTooolTipMapka(element,e);


       for(var i=0;i<ocenaArt._tabElem.length;i++){
       	    ocenaArt._tabElem[i].style.cursor = 'default';
       	   	ocenaArt.removeEvent(ocenaArt._tabElem[i],'mouseover',ocenaArt.pokazOcena);
       	   	ocenaArt.removeEvent(ocenaArt._tabElem[i],'mousemove',ocenaArt.pokazToolTip);
       	   	ocenaArt.removeEvent(ocenaArt._tabElem[i],'mouseout',ocenaArt.outOcena);
            ocenaArt.removeEvent(ocenaArt._tabElem[i],'click',ocenaArt.ocen);
		}


var idElem = parseInt((element.id).replace('o',''));
var plik = path+'ajax/zapiszOcenaArtykul.php';
var paramsPost = "idArt="+ocenaArt._idArt+"&ocena="+(idElem+1);
idWyslijAjax = 1;
processContent(plik,paramsPost);
}
}
};

//######################################
function changeText(el,size){
var Aselect = document.getElementsByName('aSelect');
var content = document.getElementById('content');
for(var i=0;i<Aselect.length;i++){
Aselect[i].className = 'titleDetailPowieksz';
if(Aselect[i] == el) Aselect[i].className = 'titleDetailPowiekszSelect';
}
content.style.fontSize = size+"px";
}
//#######################################


function processContent(plik,paramsPost){
if (xmlHttpContentP.readyState==4||xmlHttpContentP.readyState==0){
     xmlHttpContentP.open("POST",plik,true);
      xmlHttpContentP.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xmlHttpContentP.setRequestHeader("Content-length", paramsPost.length);
      xmlHttpContentP.setRequestHeader("Connection", "close");  
   xmlHttpContentP.onreadystatechange = handleServerResponse;
   xmlHttpContentP.send(paramsPost);
 }
}

function handleServerResponse(){
//try{
   if (xmlHttpContentP.readyState == 4){
    if (xmlHttpContentP.status == 200){
    
     if(idWyslijAjax == 1){
       var xmlResponse = xmlHttpContentP.responseXML;
       var xmlDoc = xmlResponse.documentElement;
       var oc = xmlDoc.getElementsByTagName('ocena').item(0).firstChild.data;
       
       var komunikatOcena = document.getElementById('komunikatOcena');
       var wynikOcena = document.getElementById('wynikOcena');
       oc = parseInt(oc);
       ocenaArt._ocena = oc;
       ocenaArt.ustawOcena(oc);
      
      
      
        komunikatOcena.innerHTML = "Dziękujemy za oddanie głosu";
        wynikOcena.innerHTML = tabOcena[oc];
        
       ocenaArt._wysylanieAjax = true;
      }
    }
    else{
   alert('blad1');
    
   }}
   //}
  //catch (e){
  //alert('blad2');
  //}
}

function wylaczZd(){
return false;
}
function getImageArt(id,source)
{
	var con    = document.getElementById("artImgSpo");
	var conpom = document.getElementById("preloader");
	var conpage = document.getElementById("artSpPage");
	var title = source.innerHTML.substring(0,source.innerHTML.length-2);
	conpom.src = "http://zasoby.ekologia.pl/art/11965/max/max_artykul_sponsorowany" + id + ".jpg";
	con.src = "http://www.ekologia.pl/assets/images/ajaxBigCircle.gif";
	con.title = title;
	con.alt = title;
	con.parentNode.style.verticalAlign = "middle";	
	conpage.style.display = "none";
	conpage.innerHTML = title;
	updateLink(id);
	setTimeout("insertImageArt('artImgSpo','preloader','artSpPage')",2000);
}
function updateLink(id)
{
	var el;
	var licz = 1;
	while(el = document.getElementById("spLink" + licz))
	{
		el.style.color = "#1C5BB6";
		el.style.textDecoration = "underline";
		licz++;
	}
	document.getElementById("spLink" + id).style.color = "black";
	document.getElementById("spLink" + id).style.textDecoration = "none";
}

function insertImageArt(con_id, conpom_id, conpage_id)
{
	var con    = document.getElementById(con_id);
	var conpom = document.getElementById(conpom_id);
	var conpage = document.getElementById(conpage_id);
	con.src = conpom.src;
	con.parentNode.style.verticalAlign = "top";
	conpage.style.display = "block";
}	
function adElements()
{
	if(insertedDiv==1) return false;
	var div = "<a id='" + arrayID[3] + "' onmouseover='showElements(3,\"a" + arrayID[3] + "\")' onmouseout='hideElements(3,\"a" + arrayID[3] + "\")'><span class='btc btc1'></span><span class='btc btc2'></span><span class='btc btc3'></span><span class='btc btc4'></span></a>";
	div += "<a id='" + arrayID[4] + "' onmouseover='showElements(4,\"a" + arrayID[4] + "\")' onmouseout='hideElements(4,\"a" + arrayID[4] + "\")'><span class='bpf bpf1'></span><span class='bpf bpf2'></span><span class='bpf bpf3'></span><span class='bpf bpf4'></span><span class='bpf bpf5'></span><span class='bpf bpf6'></span></a>";
	
//	div += "<a id='" + arrayID[7] + "' onmouseover='showElements(7,\"a" + arrayID[7] + "\")' onmouseout='hideElements(7,\"a" + arrayID[7] + "\")'></a>";
	div += "<a id='" + arrayID[5] + "' onmouseover='showElements(5,\"a" + arrayID[5] + "\")' onmouseout='hideElements(5,\"a" + arrayID[5] + "\")'></a>";
	div += "<a id='" + arrayID[2] + "' onmouseover='showElements(2,\"a" + arrayID[2] + "\")' onmouseout='hideElements(2,\"a" + arrayID[2] + "\")'></a>";
	div += "<a id='" + arrayID[8] + "' onmouseover='showElements(8,\"aSekcja\")' onmouseout='hideElements(8,\"aSekcja\")'></a>";
	div += "<a id='" + arrayID[9] + "' onmouseover='showElements(9,\"aSekcja\")' onmouseout='hideElements(9,\"aSekcja\")'></a>";
/*	div += "<a id='" + arrayID[10] + "' onmouseover='showElements(10,\"aSekcja\")' onmouseout='hideElements(10,\"aSekcja\")'></a>";*/
	div += "<a id='" + arrayID[11] + "' onmouseover='showElements(11,\"aSekcja\")' onmouseout='hideElements(11,\"aSekcja\")'></a>";
	div += "<a id='" + arrayID[14] + "' onmouseover='showElements(14,\"a" + arrayID[14] + "\")' onmouseout='hideElements(14,\"a" + arrayID[14] + "\")'></a>";
	div += "<a id='" + arrayID[1] + "' onmouseover='showElements(1,\"a" + arrayID[1] + "\")' onmouseout='hideElements(1,\"a" + arrayID[1] + "\")'></a>";
	div += "<a id='" + arrayID[6] + "' onmouseover='showElements(6,\"a" + arrayID[6] + "\")' onmouseout='hideElements(6,\"a" + arrayID[6] + "\")'></a>";
	div += "<a id='" + arrayID[12] + "' onmouseover='showElements(\"tapeta\",\"aTapeta\")' onmouseout='hideElements(\"tapeta\",\"aTapeta\")'></a>";
	div += "<a id='" + arrayID[13] + "' onmouseover='showElements(\"tapeta\",\"aTapeta\")' onmouseout='hideElements(\"tapeta\",\"aTapeta\")'></a>";	
	var con    = document.getElementById("conImgMain");
	con.innerHTML += div; 
	insertedDiv = 1;	
}

function showElements(id,ida)
{
	adElements();
	var childNel,childN;
	var aLink = document.getElementById(ida);
	if(aLink)
	{	
		var aLinkCon = aLink.innerHTML;
		var aLInkHref = aLink.href;
		aLink.style.textDecoration = "underline";
		//alert(aLinkCon);
	}
	if(id==3 || id==4)
	{
		document.getElementById(arrayID[id]).style.background="transparent";
//		document.getElementById(arrayID[id]).style.background="white";
		childN = document.getElementById(arrayID[id]).childNodes;
		if(aLink)
		{
			document.getElementById(arrayID[id]).title = aLinkCon;
			document.getElementById(arrayID[id]).href = aLInkHref;
		}	
		var licz=0;
		while(childNel = childN[licz])
		{
			childNel.style.background = colorBG;
			licz++;
		}	
	}	
	else if(id=="tapeta")
	{
		if(aLink)
		{		
			document.getElementById(arrayID[12]).title = aLinkCon;
			document.getElementById(arrayID[12]).href = aLInkHref;
			document.getElementById(arrayID[13]).title = aLinkCon;
			document.getElementById(arrayID[13]).href = aLInkHref;
		}	
		document.getElementById(arrayID[12]).style.background=colorBG;
		document.getElementById(arrayID[13]).style.background=colorBG;			
	}	
	else if(id=="sekcja")
	{
		if(aLink)
		{		
			document.getElementById(arrayID[8]).title = aLinkCon;
			document.getElementById(arrayID[8]).href = aLInkHref;
			document.getElementById(arrayID[9]).title = aLinkCon;
			document.getElementById(arrayID[9]).href = aLInkHref;
//			document.getElementById(arrayID[10]).title = aLinkCon;
//			document.getElementById(arrayID[10]).href = aLInkHref;
			document.getElementById(arrayID[11]).title = aLinkCon;
			document.getElementById(arrayID[11]).href = aLInkHref;
		}	
		document.getElementById(arrayID[8]).style.background=colorBG;
		document.getElementById(arrayID[9]).style.background=colorBG;
//		document.getElementById(arrayID[10]).style.background=colorBG;
		document.getElementById(arrayID[11]).style.background=colorBG;
	}	
	else if(id=="surround")
	{	
		document.getElementById(arrayID[1]).style.background=colorBG;
		document.getElementById(arrayID[2]).style.background=colorBG;
	}	
	else	
	{	
		if(aLink)
		{		
			document.getElementById(arrayID[id]).title = aLinkCon;
			document.getElementById(arrayID[id]).href = aLInkHref;
		}	
		document.getElementById(arrayID[id]).style.background=colorBG;
		if(ida=="adoubleb")
		{
			document.getElementById(arrayID[id]).style.height = "38px";
			document.getElementById(arrayID[id]).style.marginTop = "-3px";
		}	
	}	
	
}

function hideElements(id,ida)
{
	var childNel,childN;
	var aLink = document.getElementById(ida);
	if(aLink)
	{	
		var aLinkCon = aLink.innerHTML;
		aLink.style.textDecoration = "none";
	}
	if(id==3 || id==4)
	{
		document.getElementById(arrayID[id]).style.background="none";
		childN = document.getElementById(arrayID[id]).childNodes;
		var licz=0;
		while(childNel = childN[licz])
		{
			childNel.style.background = "none";
			licz++;
		}	
	}
	else if(id=="tapeta")
	{
		document.getElementById(arrayID[12]).style.background = "none";
		document.getElementById(arrayID[13]).style.background = "none";		
	}	
	else if(id=="sekcja")
	{
		document.getElementById(arrayID[8]).style.background="none";
		document.getElementById(arrayID[9]).style.background="none";
//		document.getElementById(arrayID[10]).style.background="none";
		document.getElementById(arrayID[11]).style.background="none";
	}	
	else if(id=="surround")
	{
		document.getElementById(arrayID[1]).style.background="none";
		document.getElementById(arrayID[2]).style.background="none";
	}	
	else
	{	
		document.getElementById(arrayID[id]).style.background="none";
		if(ida=="adoubleb")
		{
			document.getElementById(arrayID[id]).style.height = "28px";
			document.getElementById(arrayID[id]).style.marginTop = "3px";
		}	
	}
	
}

function fminiSonda(o){

var inputMiniSonda = document.getElementById('inputMiniSonda');
var formMiniSonda = document.getElementById('formMiniSonda');

inputMiniSonda.value = o;
formMiniSonda.submit();

}


arrayID = new Array();
arrayID[1] = "show-billboard";
arrayID[2] = "show-rectangle";
arrayID[3] = "show-boxTargowy";
arrayID[4] = "show-boxProFirm";
arrayID[5] = "show-banPoz";
arrayID[6] = "show-artSpo";
arrayID[7] = "show-belkaPro";
arrayID[8] = "show-belkaSek1";
arrayID[9] = "show-belkaSek2";
/*arrayID[10] = "show-belkaSek3";*/
arrayID[11] = "show-belkaSek4";
arrayID[12] = "show-belkaTap1";
arrayID[13] = "show-belkaTap2";
arrayID[14] = "show-banPio";

insertedDiv = 0;
colorBG = "#808080";
