﻿function wysokosc_strony_y()
{
	if (window.innerHeight && window.scrollMaxY)
	{// Firefox
			yWithScroll = window.innerHeight + window.scrollMaxY;
			//xWithScroll = window.innerWidth + window.scrollMaxX;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
			yWithScroll = document.body.scrollHeight;
			//xWithScroll = document.body.scrollWidth;
	} 
	else 
	{ // works in Explorer 6 Strict, Mozilla (not FF) and Safari
			yWithScroll = document.body.offsetHeight;
			//yWithScroll = document.documentElement.clientHeight
	}	
	//if(navigator.appName == "Microsoft Internet Explorer") return document.body.scrollHeight;
	//else return window.innerHeight + window.scrollMaxY;//2500;//window.scrollMaxY;
//alert('wys: '+yWithScroll);
	return yWithScroll;
}

function szerokosc_strony_x()
{
	if (window.innerWidth && window.scrollMaxX)
	{// Firefox
			//yWithScroll = window.innerWidth + window.scrollMaxX;
			xWithScroll = window.innerWidth + window.scrollMaxX;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
			//yWithScroll = document.body.scrollHeight;
			xWithScroll = document.body.scrollWidth;
	}
	else 
	{ // works in Explorer 6 Strict, Mozilla (not FF) and Safari
			//yWithScroll = document.body.offsetWidth;
			//xWithScroll = document.documentElement.clientWidth
			xWithScroll = document.body.offsetWidth;
	}
//alert('szer: '+xWithScroll);	
	return xWithScroll;
}

function ustaw_wys_strony()
{
	document.getElementById("main").style.height = wysokosc_strony_y()+'px';
}
function pokaz_obramowanie(id)
{
	obramowanie=document.getElementById(id).style.border;
	document.getElementById(id).style.border="1px dotted #000000";
}

function ukryj_obramowanie(id)
{
	document.getElementById(id).style.border=obramowanie;
}

function potwierdz_menu()
{
	if(confirm('Czy chcesz przenieść się na stronę główną? Wszystkie niezapisane zadania zostaną utracone'))
	window.location = '?m=welcome';
}



function pokaz_bez_wysrodkowania(id)
{
  document.getElementById(id).style.display='block';
}

function ukryj(id)
{
	document.getElementById(id).style.display='none';
}

function ukryj_zamknij_edycje_art(id_art)
{
	var id_art = document.getElementById('id_artykulu').value;
	document.getElementById('portal_manager_strona_nowy_art').style.display='none';
	document.getElementById('artykul_'+id_art).style.display='block';
}
  
function pokaz(id)
{
	//wysrodkuj_diva_x(id);
	document.getElementById(id).style.display='block';
}

function zapisz_wszystkie_art()
{
	// przekaz teraz wszystkie id artykulow zapamietanych w tablicy do zapisania
	dijit.byId('dialog_alert').show();
	for(var i=0; i<tablica.length; i++)
	{
			ajax_zapisz_zmiany_artykulu_bez_potwierdzenia(tablica[i])
	}
	dijit.byId('dialog_alert').hide();

}

function podaj_id_stylu(id)// funkcja przekazujaca z radio id stylu
{
	document.getElementById('styl_art').value = id;
}
  
function kontelnet(id_kwerendy) // pobranie niezbednych danych
{
	document.getElementById('dialog_alert').style.display='block';
	ajax_pobierz_producentow(id_kwerendy);
}
function kontelnet2(id_kwerendy) // wyswietlenie okna z dynamicznymi artykulami
{
	dijit.byId('dialog4').show();
	if(id_kwerendy!=null) ajax_sklep_query_get(id_kwerendy);
}


function sprawdz_mail(email)
{
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(email))
	testresults=true
	else{
	alert("Proszę wprowadzić prawidłowy adres e-mail")
	testresults=false
	}
	return (testresults)
}

function layer_up(id)
{
	//alert(document.getElementById('artykul_'+id).style.zIndex);
	document.getElementById('artykul_'+id).style.zIndex = document.getElementById('artykul_'+id).style.zIndex + 1;
}
function layer_down(id)
{
	//alert(document.getElementById('artykul_'+id).style.zIndex);
	document.getElementById('artykul_'+id).style.zIndex = document.getElementById('artykul_'+id).style.zIndex - 1;
}

function podglad_foto_z_url()
{
	if(document.getElementById('get_image_url').value=='') alert('Wpisz poprawny url');
	else
	{
		var foto1 			= document.getElementById('get_image_url').value;
		document.getElementById('podglad_pobieranego_urla').innerHTML = '<img src=\"'+foto1+'\" width=\"150px\">';
		ajax_kategorie_zdjec();
		document.getElementById('podgr_foto_ustawienia').style.display='block';
	}	 
}

function pokaz_ustawienia_menu(id_portalu)
{
	dijit.byId('dialog_ustawienia_menu').show();
}

function search(id)
{
	
	var keyword = document.getElementById('search_field').value;
	if(keyword=='') alert('Wprowadź wyrażenie do wyszukania');
	//else window.location = '?m=strona&search='+keyword;
	else window.location = '/search/'+keyword+','+id+'.html';
}

function potwierdz_menu()
{
	window.location = '/admin';
}

function potwierdz_wyloguj()
{
  if(confirm('Czy chcesz się wylogować? Wszystkie niezapisane zadania zostaną utracone'))
  window.location = '/admin/logout/';
}

function ustawCookie(nazwa, wartosc, expire)
{
  document.cookie = nazwa + "=" + escape(wartosc) + ((expire==null)?"" : ("; expires=" + expire.toGMTString()))
} 

function pokazCookie(nazwa) 
{
	if (document.cookie!="")
	{
		var toCookie=document.cookie.split("; ");
		for (i=0; i<toCookie.length; i++)
		{
			var nazwaCookie=toCookie[i].split("=")[0];
			var wartoscCookie=toCookie[i].split("=")[1];
			if (nazwaCookie==nazwa) return unescape(wartoscCookie)
		}
	}
}

function pokaz_zakladke(id)
{
var i;
	for( i=1 ; i<=liczba_zakladek ; i++ )
	{
		document.getElementById('zakladka'+i).style.display='none';
		document.getElementById('przycisk'+i).style.fontWeight='normal';
		document.getElementById('przycisk'+i).style.backgroundColor='#FFFFFF';
	}
	document.getElementById("zakladka"+id).style.display='block';
	document.getElementById('przycisk'+id).style.fontWeight='bold';
	document.getElementById('przycisk'+id).style.backgroundColor='#f5f5f5';
}

function dodaj_zdjecie(url_zdjecia, id_checkbox)
{
	if(document.getElementById(id_checkbox).checked)
	{
		zdjecia.push(url_zdjecia);
	}
	else
	{
		for (var count = 0; count < zdjecia.length; count++)
		{
			if(zdjecia[count] == url_zdjecia) zdjecia.splice(count, 1);
		}

	}
}

function ileelem()
{
	alert(zdjecia);
}

function zdjecia_zazn_wszystkie()
{
	zdjecia.splice(0, zdjecia.length);// najpierw usuwam wszystkie elementy z tablicy zeby nie bylo duplikatow
	
	for(j=0; j<zdjecia_wszystkie.length; j++)
	{
		document.getElementById(j).checked = true;
		dodaj_zdjecie(zdjecia_wszystkie[j], j);	
	}
	
}

function zdjecia_odzn_wszystkie()
{
	ile_zdjec = zdjecia_wszystkie.length; 
	
	for (var count = 0; count < ile_zdjec; count++)
	{
		document.getElementById(count).checked = false;
	}
	zdjecia.splice(0, ile_zdjec);
}






