function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

function chBgCol(obj,col)
{
	obj.style.backgroundColor=col;
}

function toggle_visibility(id) {
	var e = document.getElementById(id);
	if(!e) return false;
	if(e.style.display == 'none')
		e.style.display = 'block';
	else
		e.style.display = 'none';
}

function toggle_visibility_footer(id) {
	var e = document.getElementById(id);
	if(!e) return false;
	if(e.style.display == 'none')
		e.style.display = 'block';

	else
		e.style.display = 'none';

		if (navigator.appName=="Microsoft Internet Explorer") {
		document.getElementById('footer').style.position='relative';
		document.getElementById('footer').style.position='absolute';
		}
}

function toggle_check(id) {
	if(window.togglelock && togglelock == true ) return false;
	var e = document.getElementById(id);
	if(!e) return false;
	if(e.checked == true)
		e.checked = false;
	else
		e.checked = true;
}

function switch_check( cells, checkedi )
{
	for (var i = 0; i < cells.length; i++)
	{
		if( i == checkedi )
			cells[i].checked=true;
		else
			cells[i].checked=false;
	}
}

function switch_blocks(id1,id2) {
	toggle_visibility(id1);
	toggle_visibility(id2);
}

function hide6All(name,lastId,myId)
{
	for(var i=7; i <= lastId; i++)
	{
		if ( document.getElementById(name + i))
			toggle_visibility(name + i);
	}
	myId.innerHTML = '<img src="/static/img/cushion_down.gif" alt="" /> więcej <img src="/tpl/_img/cushion_down_r.gif" alt="" />';
	myId.onclick = function() {show6All(name,lastId,myId)};
}

function show6All(name,lastId,myId)
{
	for(var i=7; i <= lastId; i++)
	{
		togname = name + i;
		if ( document.getElementById(name + i))
			toggle_visibility(togname);
	}
	myId.innerHTML = '<img src="/static/img/cushion_up.gif" alt="" /> ukryj <img src="/tpl/_img/cushion_up_r.gif" alt="" />';
	myId.onclick = function() {hide6All(name,lastId,myId)};
}

function hide(id) {
	var e = document.getElementById(id);
	e.style.display = "none";
}

function hideMe(obj) {
	obj.style.display = "none";
}

function show(id,display) {
	var e = document.getElementById(id);
	e.style.display = display;
	document.getElementById(id).focus();
}

function isCompany(company)
{
	var browserName=navigator.appName;

	if ( company == "0" )
	{
		disp = "inline";
		cdisp = "none";
		rdisp = "none";
	}
	else if ( company == "1" )
	{
		disp = "none";
		cdisp = "inline";
		if (browserName=="Microsoft Internet Explorer")
		{
			rdisp = "inline";
		}
		else
		{
			rdisp = "table-row";
		}
		//document.getElementById("address_name1").value = '';
		//document.getElementById("address_name2").value = '';
	}
	document.getElementById("name1").style.display = disp;
	document.getElementById("name2").style.display = disp;
	document.getElementById("name3").style.display = disp;
	document.getElementById("company1").style.display = cdisp;
	document.getElementById("company2").style.display = cdisp;
	document.getElementById("company3").style.display = cdisp;
	document.getElementById("slash1").style.display = "none";
	document.getElementById("slash2").style.display = "none";
	document.getElementById("slash3").style.display = "none";
	document.getElementById("row3").style.display = rdisp;
	if(document.getElementById("rownip"))
		document.getElementById("rownip").style.display = rdisp;
}

function isOtherAddress(other)
{
	if ( other == "0" )
	{
		if(document.getElementById("otheraddressform"))
			document.getElementById("otheraddressform").style.display = "none";
	}
	else if ( other == "1" )
	{
		document.getElementById("otheraddressform")
			document.getElementById("otheraddressform").style.display = "inline";
	}
}

function switchNewCustomer(type)
{

	{
		var divFull = document.getElementById("divFull");
		var divNo = document.getElementById("divNo");
		var divSimple = document.getElementById("divSimple");

		switch( type )
		{
			case 2:
				divFull.style.display = "block";
				divNo.style.display = "none";
				divSimple.style.display = "none";
			break;
			case 3:
				divFull.style.display = "none";
				divNo.style.display = "block";
				divSimple.style.display = "none";
			break;
			case 1:
				divFull.style.display 	= "none";
				divNo.style.display 	= "none";
				divSimple.style.display = "block";
			break;
		}
	}
}

function checkIds(mainId)
{
	var total=mainId
	if(document.cs_list.cs.length > 1 )
	{
		for(var i=0; i < document.cs_list.cs.length; i++){
		if(document.cs_list.cs[i].checked)
			total += "," + document.cs_list.cs[i].value
		}
	}
	else
		total += "," + document.cs_list.cs.value

	return total;
}


function toggle_menu(id, picture) {

  if (document.getElementById(id).style.display=="none") {
      document.getElementById(id).style.display="block";
      document.getElementById(picture).className = "menu_minus";
      document.cookie = "position="+(id);
  } else {
      document.getElementById(id).style.display="none";
      document.getElementById(picture).className = "menu_plus";
  }

}

function menu_open(id){

      document.getElementById(id).style.display="block";

}

function switch_image(imid)
{
	imgs = document.getElementsByName('prdfullimg');
	for (var i = 0; i < imgs.length; i++)
	{
		if( imgs[i].id == 'prdf_'+imid )
			imgs[i].style.display = 'block';
		else
			imgs[i].style.display = 'none';
	}
}

function fox_image(g) {
var arr = new Array('tab1', 'tab2', 'tab3');
for (i = 0; i < 3; i++) {
  if (document.getElementById(arr[i])) {
  document.getElementById(arr[i]).style.display = 'none';}
  }
document.getElementById(g).style.display = 'block';
}

function security_em(x1,x2,x3,a1,a2,a3) {
	var fl='@';
	var pd='.';
	var h1='<a href=\"mailto:';
	var h2='\">';
	var h3='<\/a>';

	adress  = h1;
	adress += x1;
	adress += fl;
	adress += x2;
	adress += pd;
	adress += x3;
	adress += h2;
	adress += a1;
	adress += fl;
	adress += a2;
	adress += pd;
	adress += a3;
	adress += h3;
	return adress;
}

function basket_value( value )
{

	return Tip("<table><tbody><tr><td id=\"writeHere\">Aktualnie masz w koszyku<br \/> towar o wartości = <strong>"+value+"<\/strong> zł<\/td><\/tr><\/tbody><\/table>", DELAY, 100, WIDTH, 160, SHADOW, true, OFFSETX, -215, OFFSETY, 10);
}

function openPicture(src,sWidth,sHeight) {
writesPictures=window.open('', 'newwin', 'top=10,left=100,width='+sWidth+',height='+sHeight+',toolbar=0,location=0,directories=0,menubar=0,resizeable=0');
writesPictures.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">');
writesPictures.document.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">');
writesPictures.document.write('<head>');
writesPictures.document.write('<title>Morele.net</title>');
writesPictures.document.write('</head>');
writesPictures.document.write('<body>');
writesPictures.document.write('<table><tr><td style="text-align: center;">');
writesPictures.document.write('<img src="'+src+'" style="cursor: pointer" border="0" alt="Kliknij, aby zamknąć" onclick="window.close()">');
writesPictures.document.write('</td></tr></table>');
writesPictures.document.write('</body>');
writesPictures.document.write('</html>');
writesPictures.document.close();
}
function disable_submits()
{
	for (fi=0; fi<document.forms.length; fi++){
		els = document.forms[fi].getElementsByTagName("INPUT");
		for (i=0; i<els.length; i++){
		  if ( els[i].type == 'submit' )
		    els[i].disabled=true;
		}
	}
}

function enable_submits()
{
	for (fi=0; fi<document.forms.length; fi++){
		els = document.forms[fi].getElementsByTagName("INPUT");
		for (i=0; i<els.length; i++){
		  if ( els[i].type == 'submit' )
		    els[i].disabled=false;
		}
	}
}

function delRow()
{
		document.getElementById('footer').style.position='relative';
		document.getElementById('footer').style.position='absolute';
}

function FormsTimeout(tms)
{
	setTimeout('disable_submits()', tms*100);
	setTimeout('enable_submits()', tms*1000);
}

function toggle_visibilityList(id, end, name) {
	for ( id ; id <= end; id++ )
	{
	var e = document.getElementById('cs_' + name + '_' + id);
	if(e.style.display == 'none')
		e.style.display = '';
	else
		e.style.display = 'none';
	}
}

//Dwie funkcja dla formularza ratalnego
//Usuwa wszystkie opcje z listy wybieralnej
function delOptions(selectId)
{
   	document.getElementById(selectId).options.length=0;
}
//wstawia opcje do listy wybieralnej
function addOption(selectId, val, txt)
{
	var objOption = new Option(txt, val);
	document.getElementById(selectId).options.add(objOption);
}

function goInstallment( )
{
	var bUrl=document.getElementById('toBasket').href;
	if ( bUrl.charAt(bUrl.length-1) == '/' )
		bUrl += 'raty/';
	else
		bUrl += '/raty/';
	window.location.href=bUrl;
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			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 "";
}

function setCookie(c_name,value,days)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+days);
	document.cookie=c_name+ "=" +escape(value)+
	((days==null) ? "" : ";expires="+exdate.toGMTString());
}

function delCookie(c_name)
{
	setCookie(c_name,"",-1);
}

function test_cookies( )
{
	setCookie('m2_cookietest','ok',1);
	if( getCookie('m2_cookietest')) delCookie('m2_cookietest');
	else document.writeln('<p style=\"color:red;display:block\">Ta strona wymaga włączonej obsługi <strong>cookies<\/strong> do prawidłowego działania.<\/p>');
}

function product_page( id )
{
	location.assign('/produkt/' + id + '/#opis');
}
//funkcje dla jquery
function jquery_showhide(elem)
{
    if( $(elem).css('display') == 'none' )
    	$(elem).show('slow');
    else
     	 $(elem).hide('slow');
}

//funkcje dla jquery
function jquery_slide(elem)
{
    if( jQuery(elem).css('display') == 'none' )
    	jQuery(elem).slideDown(600);
    else
     	 jQuery(elem).slideUp(600);
}

function loadingInit(id)
{
	var me=document.getElementById(id);
	me.innerHTML='<div class="center"><img src="/static/img/loading.gif" alt="loading..." /></div>';
	me.style.display='block';
}

//wyszukiwarka
function showAddSearch()
{
	var s_span = document.getElementById("span_add_searchext");
	var s_href = document.getElementById("add_searchext");
	var s_href_to = "";
	var sinst = false;
	if(!s_href)
	{
		return;
	}
	if(navigator.userAgent.indexOf("Gecko")>-1&&navigator.userAgent.indexOf("KHTML")==-1)
		s_href_to = "Firefoksa";
	else if( navigator.userAgent.indexOf("MSIE")>-1 )
		s_href_to = "Internet Explorer";

	if(!!navigator.userAgent.match(/Flock/))
	{
		s_href_to = "Flock";
		sinst=window.external&&window.external.IsSearchProviderInstalled&&(window.external.IsSearchProviderInstalled("http://www.morele.net")==0)
	}
	else
	{
		sinst=window.external&&(window.external.IsSearchProviderInstalled("http://www.morele.net")==0);
	}
	if (window.external && ("AddSearchProvider" in window.external)) {
	    s_span.style.display='block';
	}
	if(sinst)
	{
		s_href.onclick=function(){
			window.external.AddSearchProvider("http://www.morele.net/static/xml/searchplugin.xml");
			return false;
		}
		s_href.innerHTML="Dodaj wyszukiwarkę Morele.net do "+s_href_to;
	}
}
function showAddSearchUA()
{
	var s_span = document.getElementById("span_add_searchext");
	var s_href = document.getElementById("add_searchext");
	var s_href_to = "";
	var sinst = false;
	if(!s_href)
	{
		return;
	}
	if(navigator.userAgent.indexOf("Gecko")>-1&&navigator.userAgent.indexOf("KHTML")==-1)
		s_href_to = "Firefoxу";
	else if( navigator.userAgent.indexOf("MSIE")>-1 )
		s_href_to = "Internet Explorer";

	if(!!navigator.userAgent.match(/Flock/))
	{
		s_href_to = "Flock";
		sinst=window.external&&window.external.IsSearchProviderInstalled&&(window.external.IsSearchProviderInstalled("http://www.morele.net")==0)
	}
	else
	{
		sinst=window.external&&(window.external.IsSearchProviderInstalled("http://www.ua.morele.net")==0);
	}
	if(sinst)
	{
		s_href.onclick=function(){
			window.external.AddSearchProvider("http://ua.morele.net/static/xml/searchpluginua.xml");
			return false;
		}
		s_href.innerHTML="Додати пошукову систему Morele.net до "+s_href_to;
		s_span.style.display='block';
	}
}