function GetID(id)
{
	return document.getElementById(id);
}


function input_click(obj, wartosc)
{
	if (obj.value == wartosc) obj.value = "";
}

function input_blur(obj, wartosc)
{
	if (obj.value == "") obj.value = wartosc;
}


function sel(obj, val,cena,wartosc)
{
	if(document.getElementById('new_query'))
		document.getElementById('new_query').value ='true';
	GetID(obj).value = val;
	hidemenu();
	if(cena)
		GetID("price").value = wartosc;
	
	
}

function sel_kwota2(obj, val, kwota)
{
	document.getElementById(obj).value = val;
	document.getElementById("panstwo_kwota").innerHTML = kwota+" zł";
	hidemenu();
}

function sel_kwota(obj, val, id_country, kwota,curr)
{
	GetID(obj).value = val;
	GetID(obj+'_h').value = id_country;
	GetID("panstwo_kwota").innerHTML = kwota+" "+curr;
	hidemenu();
}

function sel_ecard(obj, val, id)
{
	GetID(obj).value = val;
	GetID(obj+'_h').value = id;
	hidemenu();
}


function show_checkbox(obj, target)
{
	if (obj.checked) 
		show_obj(target);
	else
		hide_obj(target);
}


function show_obj(obj)
{
	GetID(obj).style.display = "block";
}

function hide_obj(obj)
{
	GetID(obj).style.display = "none";
}


function color(img, obj, val)
{
	if(document.getElementById('new_query'))
		document.getElementById('new_query').value ='true';
	GetID(obj).value = val;
	GetID(obj+"_img").src = img.firstChild.src;
	hidemenu();
}



var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1
var ns6=document.getElementById&&!document.all
var ns4=document.layers
var menuobj;
var delayhide;

function showmenu(e,object)
{
	
	if (window.menuobj != undefined) hidemenu();
	
	clearhidemenu();	
	GetID(object).style.display = "block";
	
	menuobj = object;
return false
}

function hidemenu()
{
	if (GetID(menuobj))
	{
		GetID(menuobj).style.display = "none";
	}
}

function dynamichide(e)
{
	delayhidemenu()
}

function delayhidemenu(){
	delayhide=setTimeout("hidemenu()",500);
}

function delayhidemenu2(){
	if($.browser.mozilla && $.browser.version.substring(0,3) == "1.8"){
		//alert("test");
		return false;
	}
	delayhide=setTimeout("hidemenu()",500);
}

function clearhidemenu()
{
	if (delayhide)
 		clearTimeout(delayhide);
}


function sel_change(object)
{
	clearhidemenu();

	if (object.className=='zmien_on')
		object.className='zmien_off';
	else
		object.className='zmien_on';
}

if (ie4||ns6)
	document.onClick=hidemenu();

function hide_kwota_dostawy(val)
{
	var p0 = !val ? 'none' : 'block';
	var p1 = p0 == 'block' ? 'none' : 'block';
	
	GetID('d2p[0]').style.display = p0;
	GetID('d3p[0]').style.display = p0;
	GetID('d8p[0]').style.display = p0;
	GetID('d10p[0]').style.display = p0;
	GetID('d11p[0]').style.display = p0;

	GetID('d2p[1]').style.display = p1;
	GetID('d3p[1]').style.display = p1;
	GetID('d8p[1]').style.display = p1;
	GetID('d10p[1]').style.display = p1;
	GetID('d11p[1]').style.display = p1;	
}

function hidde_all_delivery()
{
	GetID('poczta').style.display = 'none';
	GetID('inpost').style.display = 'none';
	GetID('kurier').style.display = 'none';
	GetID('zagranica').style.display = 'none';
	
	GetID("d1o").className = "";
	GetID("d4o").className = "";
	GetID("d5o").className = "";
	GetID("d6o").className = "";
	
	GetID("d2").checked = false;
	GetID("d3").checked = false;
	if(GetID("d15")!=undefined) GetID("d15").checked = false;
	if(GetID("d16")!=undefined) GetID("d16").checked = false;
	GetID("d8").checked = false;
	//GetID("d9").checked = false;
	GetID("d10").checked = false;
	GetID("d11").checked = false;
	if(GetID("d17")!=undefined) GetID("d17").checked = false;
	if(GetID("d18")!=undefined) GetID("d18").checked = false;
	
	GetID("d2o").className = "";
	GetID("d3o").className = "";
	GetID("d8o").className = "";
	//GetID("d9o").className = "";	
	GetID("d10o").className = "";
	GetID("d11o").className = "";
	
	if(GetID("d15o")!=undefined) GetID("d15o").className = "";
	if(GetID("d16o")!=undefined) GetID("d16o").className = "";
		
	GetID("d2k").className = "";
	GetID("d3k").className = "";
	GetID("d8k").className = "";
	//GetID("d9k").className = "";	
	GetID("d10k").className = "";
	GetID("d11k").className = "";	
	
	if(GetID("d15k")!=undefined) GetID("d15k").className = "";
	if(GetID("d16k")!=undefined) GetID("d16k").className = "";	
	
	if(GetID("d17k")!=undefined) GetID("d17k").className = "";
	if(GetID("d18k")!=undefined) GetID("d18k").className = "";		
}

var prev_id = 'd2';

function NoClass()
{
	//poczta
	GetID("d2o").className = ""; GetID("d2k").className = "";
	GetID("d3o").className = ""; GetID("d3k").className = "";
	if(GetID("d15o")!=undefined) { GetID("d15o").className = ""; GetID("d15k").className = ""; }
	//kurier
	GetID("d10o").className = ""; GetID("d10k").className = "";
	GetID("d11o").className = ""; GetID("d11k").className = "";
	if(GetID("d16o")!=undefined) { GetID("d16o").className = ""; GetID("d16k").className = "";	}
	//zagranica
	if(GetID("d17o")!=undefined) GetID("d17o").className = "";
	if(GetID("d18o")!=undefined) GetID("d18o").className = "";	
}

function dostawa_sel(obj,dt,pt,val)
{
	var prev_delivery = GetID('delivery_type').value;
	var prev_payment = GetID('payment_type').value;
	//var prev_id = '';
	
	if( obj.id == 'd15' ) 
      $('#d15e').show(); 
  else
   // if( obj.id != 'd1' && obj.id != 'd5' && obj.id != 'd6' ) 
          $('#d15e').hide();
    
    
	if( obj.id == 'd16' ) 
    $('#d16e').show(); 
  else 
  //  if( obj.id != 'd1' && obj.id != 'd5' && obj.id != 'd6' )
           $('#d16e').hide();

	if( prev_delivery != dt && dt == 'zagranica' )
	{
		$('#zagranica_p_h').val('');
		$('#zagranica_p').val('Wybierz panstwo');
		$('#panstwo_kwota').html('');
	}

// top level
	if( obj.name == 'dostawa' )
	{
		if(dt != prev_delivery )
		{
			hidde_all_delivery();
			GetID(obj.id + "o").className = "grey2";
			if( GetID(obj.value) != undefined ) GetID(obj.value).style.display = 'block';
		}
	}	

// bottom level
	if( obj.name == 'poczta' )
	{
		NoClass();

		GetID(obj.id + "o").className = 'grey2';
		GetID(obj.id + "k").className = 'grey2';
		
		prev_id = obj.id;
	}
	
	if( obj.name == 'inpost' )
	{
		GetID(obj.id + "o").className = 'grey2';
		GetID(obj.id + "k").className = 'grey2';
		
		prev_id = obj.id;
	}	
	
	if( obj.name == 'kurier' )
	{
		NoClass();

		GetID(obj.id + "o").className = 'grey2';
		GetID(obj.id + "k").className = 'grey2';
		
		prev_id = obj.id;
	}
	
	if( obj.name == 'zagranica' )
	{
		NoClass();
		GetID(obj.id + "o").className = 'grey2';
		prev_id = obj.id;
	}

	GetID('delivery_type').value = dt;
	GetID('payment_type').value = pt;
	GetID('delivery_base').value = val;
}



function inpost_ok()
{
	GetID("d8").disabled = false;
	//GetID("d9").disabled = false;
}


/*function otworz_komentarz()
{
//	if ( navigator.appName == "Microsoft Internet Explorer" && (parseFloat(navigator.appVersion)<7 && navigator.appVersion.search("MSIE 7.0")<0) )
	{
		var okno = document.body.offsetHeight;
		var popup = GetID("popup").clientHeight;
		
		if (okno>popup)
			GetID("overlay").style.height=okno  + "px";
		else 
			GetID("overlay").style.height=popup  + "px";

	}
}*/

function isNumberKey(evt)
{ 
   var charCode = (evt.which) ? evt.which : evt.keyCode
   if (charCode > 31 && (charCode < 48 || charCode > 57))
      return false;

   return true;
}

function enable()
{
	if (GetID("dostepne").checked)
	{		
		GetID("sel_on").style.display = "block";
		GetID("sel_off").style.display = "none";
		GetID("szary").style.opacity = "0.99";
		GetID("szary").style.MozOpacity = "0.99";
		GetID("szary").style.filter = "alpha(opacity=99)";
		GetID("sr_1").style.filter = "alpha(opacity=99)";
		GetID("sc_1").style.filter = "alpha(opacity=99)";
		GetID("rozmiar_1").disabled = false;
		GetID("kolor_1").disabled = false;
		GetID("cena_1").disabled = false;
		GetID("price").disabled = false;
		d = 0;
	}
	else
	{
		GetID("sel_on").style.display = "none";
		GetID("sel_off").style.display = "block";
		GetID("szary").style.opacity = "0.29";
		GetID("szary").style.MozOpacity = "0.29";
		GetID("szary").style.filter = "alpha(opacity=29)";
		GetID("sr_1").style.filter = "alpha(opacity=29)";
		GetID("sc_1").style.filter = "alpha(opacity=29)";
		GetID("rozmiar_1").disabled = true;
		GetID("kolor_1").disabled = true;
		GetID("cena_1").disabled = true;
		GetID("price").disabled = true;
		d = 1;
	}									
}
// FAQ

var last_faq;

function sel_faq(nr, obj, val)
{
	if (last_faq)
	{
		GetID("faq_z"+last_faq).style.display = "none";
	}
	
	GetID("faq_z"+nr).style.display = "block";
	last_faq = nr;
	GetID(obj).value = val;
	hidemenu();
}

var scroller_faq  = null;
var scrollbar_faq = null;

function faq(obj)
{

	o = GetID(obj).innerHTML;
	GetID("faq_odp").innerHTML = o;
	GetID("faq_box").style.display = "block"; //hidden

	if (!scrollbar_faq)
	{
		scroller_faq  = new jsScroller(document.getElementById("pole_1"), 250, 335);
		scrollbar_faq = new jsScrollbar (document.getElementById("pole_1_winda"), scroller_faq, false);
	}
	else
	{
		scroller_faq.reset();
		scrollbar_faq.reset();
	}
		
}


function close_faq()
{
	GetID("faq_odp").innerHTML = "";
	GetID("faq_box").style.display = "none"; //hidden
	var scroller  = null;
	var scrollbar = null;	
}

var f;
var obj_pom;

var start_width = 0;
var start_height = 0;
var url_path;
var popup_show = false;

var width = 0;
var height = 0;

var max_width = 412; // maksymalna szerokosc zdjecia



function ZoomFoto(obj,url,orginal_width,orginal_height)
{
	width = orginal_width;
	height = orginal_height;
	url_path = url;
	obj_pom = obj;
	obj.onclick = new Function("return false;");
		
	var foto = new Image;
	foto.src = obj.href;
	
	//width = foto.width;
	//height = foto.height;
		
	d = document.createElement("img");
	d.src = foto.src;
	d.style.position = "absolute";
	d.style.zIndex = 155;
	d.style.top = 0;
	d.style.left = 0;
	d.id="tescik";
	d.className = "big_foto";
	d.width = width;
	d.height = height;	
	
	
	start_width = obj.getElementsByTagName("*")[0].width;
	start_height = obj.getElementsByTagName("*")[0].height;
	
	d.style.width = Math.round(start_height*d.width/d.height)+"px";
	d.style.height = start_height+"px";
	
	obj.appendChild(d);
	f = d;
	
	if (width > max_width)
	{
		height = Math.round(max_width*height/width);
		width = max_width;
	}
	ZoomIn();

}



function ZoomIn()
{
	s_width = parseInt(f.style.width);
	

	if ( width > s_width )
	{
		liczba = Math.ceil((width - s_width)/4);		
		f.style.width = (s_width + liczba) +"px";
		f.style.height = Math.round(parseInt(f.style.width)*height/width)+"px";
		setTimeout("ZoomIn()", 1);
	}
	else
	{
		obj_pom.onclick = new Function("ZoomOut(); return false;");
		//alert(s_width);
		if(!popup_show)
		{
			var close = document.createElement("img");
			close.src = url_path+"www/img/krzyzyk_.png";
			close.style.position = "absolute";
			close.style.top = "5px";
			close.style.left = (s_width-25)+"px";;
			close.style.zIndex = 255;
			close.id="popup_close";
			close.width = 21;
			close.height = 20;							
			obj_pom.appendChild(close);
			$.ifixpng('../../root/res/www/img/pixel.gif');
			$("#popup_close").ifixpng();
		}else
		{
			document.getElementById('popup_close').style.display = "block";			
		}
		
		popup_show = true;
	}
	
}


function ZoomOut()
{
	
	document.getElementById('popup_close').style.display = "none";
	s_width = parseInt(f.style.width);

	if ( start_width < s_width )
	{
		liczba = Math.ceil((s_width - start_width)/4);		
		f.style.width = (s_width - liczba) +"px";
		f.style.height = Math.round(parseInt(f.style.width)*start_height/start_width)+"px";
		setTimeout("ZoomOut()", 1);
	}
	else
	{
		obj_pom.onclick = new Function("ZoomFoto(this,'"+url_path+"',"+width+","+height+"); return false;");
		f.style.display = "none";
		f=false;
	}
	
}