/* OnMouseover dla listy produktow*/
function setBG( elem, over, count )
{
if( !count )
	count = 4;
	var item;
	var tmp;
	
	/* Kolorowanie elementów */
	for( var i = 1 ; i <= count ; i++ )
	{
	tmp = elem;
	if( tmp.indexOf('_') != -1 )
		tmp = tmp.substr( 0, tmp.length - 1 );
	tmp = tmp + '_' + i;

	item = document.getElementById( tmp );
	if( item )
		{
			if( over )
			{
				item.bgColor = 'F5F5F5';
			}
			else	
				{
					item.bgColor = 'FFFFFF';
				}
		}	//if item
	}//for
//onmouseover="style.background='#F5F5F5'" onmouseout="style.background='#ffffff'"
}

function wmu(link,desc,class_name,title)
{
	return document.writeln("<a href=\""+link+"\" class=\""+class_name+"\" title=\""+title+"\">"+desc+" </a>");
}

function wm(user,domain)
{
	return document.writeln("<a href=\"mailto:"+user+"@"+domain+"\" >"+user+"&#64;"+domain+"</a>");
}

function getc(w,n)
{
    if (n) 
    {
        window.open(w, '_blank');
 	} 
 	else 
 	{
     	document.location=w;
 	}
}

function pic_zoom(a,title)
{
	breit=370;
	hoch=370;
	big=window.open("/pic.php?img="+escape(a)+"&title="+title,breit+"zoomed"+hoch,"width="+breit+",height="+hoch+",menubar=no,status=no,locationbar=no");
	big.focus();
}

function popup(url,width,height) {
big=window.open(url,width+"zoomed"+height,"width="+width+",height="+height+",menubar=no,status=no,locationbar=no");
big.focus();
}



// funkcja ktora dekoduje algorytm rot13
function un(u)
{
var v='';
var map=new Array();
  var s="abcdefghijklmnopqrstuvwxyz";

  for (k=0;k<s.length;k++)
  {
    map[s.charAt(k)]=s.charAt((k+13)%26);
    map[s.charAt(k).toUpperCase()]=s.charAt((k+13)%26).toUpperCase();
  }

for (k=0;k<u.length;k++)
{
p=u.charAt(k);
v+=(p>='A' && p<='Z' || p>='a' && p<='z')?map[p]:p;
}

return v;
}


//funkcja przekierowuje na url, url musi byc zakodowany za pomoca algorytmu base64
function gourl_enc(url)
{  		
	location.href=decode64(url);
	return true;
} 

//funkcja przekierowuje na url, 
// drugi parametr okresla czy otwierac w nowym oknie
function gourl(url,new_window)
{  		
	if (typeof(new_window) == 'undefined')
		new_window=false;
	
	if(new_window)
		site=window.open(url);
	else
		document.location=url;	
}

// dodawanie strony do ulubionych
function addBookmark(link, name) {
    if ((navigator.appName.indexOf("Microsoft",0)>=0) && (parseInt(navigator.appVersion)>=4)) {
        window.external.AddFavorite(link,name); 
        a=new Image();a.src="";
    } else {
//        alert("Klicken Sie 'OK' um dieses Fenster zu schließen, dann drücken Sie CTRL+D um Idealo zu Ihren Favoriten zu legen.");
		alert("Proszę klikn±ć 'OK' aby zamkn±ć to okno, a następnie wcisn±ć CTRL+D aby dodać stronę do ulubionych.");
        
    }
}


// dekodowanie base64

// <textarea name="theText" cols="40" rows="6"></textarea><br>
// <input type="button" name="encode" value="Encode to base64"
// onClick="document.base64Form.theText.value=encode64(document.base64Form.theText.value);">
// <input type="button" name="decode" value="Decode from base64" 
// onClick="document.base64Form.theText.value=decode64(document.base64Form.theText.value);">

// dostepne znaki do kodowania base64
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

// kodowanie stringow base64
function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}

// dekodowanie stringow base64
function decode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}

/*
	Funkcja wykorzystywana na tpl product sluzy do zmiany widoku z short_body do long_body
	juz nie uzywana sprawdzic czy niegdzie nie wystepuje i wykasowac
*/
function changeView()
{

	if(document.getElementById("con").value=='short')
	{
		document.getElementById("cell0").innerHTML=decode64(document.getElementById("long_body").value);
		document.getElementById("more_less").innerHTML="<<< weniger";
		document.getElementById("con").value='long';
		
	}	
	else	
	{
		document.getElementById("cell0").innerHTML=decode64(document.getElementById("short_body").value);
		document.getElementById("more_less").innerHTML="mehr >>>";
		document.getElementById("con").value='short';
	}	

}


/*
	Funkcja do zmiany rozmiarow obrazka, obrazek zostanie tak zeskalowany aby sie zmieścił w podanych rozmiarach
	src - sciezka do obrazka
	x, y - rozmiary obrazka
	desc - tekst wstawiany do alt oraz title 

*/
function image(src, x, y, desc)
{
	if (typeof(desc) == 'undefined') 
		var desc = 'Image'
	
	pic = new Image();
	pic.src= src;
	
	
	// tutaj jakies tam transformacje
	org_x=pic.width;
		
	if(org_x > x)
	{
		ratio=x/org_x;
		pic.width=org_x*ratio;
		pic.height=pic.height*ratio;	
	}	 
	
	org_y=pic.height;
	if(org_y > y)
	{
		ratio=y/org_y;
		pic.width=pic.width*ratio;
		pic.height=org_y*ratio;	
	}	
	
	
	document.write('<img src="'+pic.src+'" border="0" alt="" width="'+pic.width+'" height="'+pic.height+'" alt="'+desc+'" title="'+desc+'" class="border" onerror="javascript:zaslepka(pic);" />');
}

/*
    Funkcje do obslugi gwiazdek do produktu
*/
/* 
    !!!!!!!!!!!!!!!!
        Tablica ic znajduje sie w katalogu pic dla kazdej domeny i tam jest zefinowana scizka do obrazkow z gwiazdkami
    !!!!!!!!!!!!!!!!
*/

var cOb=new Array();
var timer;

function selectRate(obj,evt) {
	if(!cOb[obj.name])
	    cOb[obj.name]=obj.src;
	if(document.all && !window.opera)
	    evt=event;

	on=getM(getCCWT(evt).x);
	//obj.style.cursor="hand";
	obj.style.cursor="pointer";
	if (document[obj.name].src != ic[on].src) {
	    document[obj.name].src = ic[on].src;
	}
};

// pzredzialy poszczegulnych gwiadek
function getM(objMX) {
	on=0;
	if(objMX>=0 && objMX<=10) on=1;
	if(objMX>=11 && objMX<=20) on=2;
	if(objMX>=21 && objMX<=30) on=3;
	if(objMX>=31 && objMX<=40) on=4;
	if(objMX>=41 && objMX<=50) on=5;
	return on;
};

function getCCWT(evt) {
	var coords = { x: 0, y: 0};
	if(document.all && !window.opera) {
		evt = window.event;
		coords.x=evt.offsetX;
		coords.y=evt.offsetY;
	} else {
		var Element=evt.target;
		var cTLeft=0;
		var cTTop=0;
		while (Element.offsetParent) {
			cTLeft+=Element.offsetLeft; 
			cTTop+=Element.offsetTop;
			Element = Element.offsetParent ;
		}
		coords.x=evt.pageX-cTLeft;
		coords.y=evt.pageY-cTTop;
	}
	return coords;
}

function freezRate(obj,evt,key)
{
    on=getM(getCCWT(evt).x);
    document.getElementById('rate_'+key).value=on;
}

function restoreRate(obj,evt,key)
{
    on=document.getElementById('rate_'+key).value;
    document[obj.name].src = ic[on].src; 
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Funkcje do obsugi formularzy do komentarzy
function isEmail(s) {
	var reEmail = /\b(^(\S+@)([a-zA-Z0-9\-]+\.)+(com|net|edu|mil|gov|org|int|([a-zA-Z]{2}))$)\b/i
	if (!reEmail.test(s.value)) {
//		alert("Bitte geben Sie eine gültige E-Mail-Adresse ein.");
		alert("Proszę podać poprawny adres email.");
		s.focus();
		s.select();
		return false;
	}
	return true;
}

function isName(s) {
	if (s.value=="") {
		alert("Proszę podać swoje imię.");
		s.focus();
		s.select();
		return false;
	}
	return true;
}

function isGoogOpinionLenght(s) {
	if (s.value.length<50) {
//		alert("Ihre Rezension ist zu kurz. Es müssen mindestens 50 Zeichen verwendet werden.");
		alert("Podany tekst jest za krótki. Proszę podać przynajmniej 50 znaków.");
		s.focus();
		s.select();
		return false;
	}
	if (s.value.length>2000) {
//		alert("Ihre Rezension ist zu lang. Es dürfen maximal 2000 Zeichen verwendet werden.");
		alert("Wprowadzony tekst jest za długi. Maksymalna ilo¶ć wynosi 2000 znaków.");
		s.focus();
		s.select();
		return false;
	}

	return true;
}

function limit_comment_size()
{
    //document.getElementById('char_counter').innerHTML=2000-this.value.length
    $siz=document.getElementById('p_comment').value.length;
    $sizsh=$siz;
    if($sizsh>2000) {$sizsh=2000;}
    document.getElementById('char_counter').innerHTML=2000-$sizsh;//2000-document.getElementById('p_comment').value.length;
    if($siz>=2000-1) 
    {
//        alert("Ihre Rezension ist zu lang. Es dürfen maximal 2000 Zeichen verwendet werden.");
		alert("Wprowadzony tekst jest za długi. Maksymalna ilo¶ć wynosi 2000 znaków.");
        document.getElementById('p_comment').value = document.getElementById('p_comment').value.substring(0,2000);
    }
}

function CheckForm_Comment()
{
    //alert(document.getElementById("p_email").value);
    //return false;
    if(!isGoogOpinionLenght( document.getElementById("p_comment") )) {return false;}
    
    if(!isEmail(document.getElementById("p_email") )) {return false;}
    if(!isName( document.getElementById("p_name") )) {return false;}

    return true;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
