//sprawdz rozszerzenie

function check_extension(file_name,ext_tab)
{
	var ext_string = "";
	var found = 0;
	var error = "";

	if (file_name!="")
	{
		lower = file_name.toLowerCase(); //wszystkie znaki zmniejsz
		len = lower.length; //długosc stringa
		g = len - 3; //minus trzy znaki na rozszerzenie
		ext = lower.substring(len,g); //pobierz 3 ostatnie znaki
		ext = ext.replace('.','');

		for (j=0; j<ext_tab.length; j++)
		{
			if (ext_tab[j]==ext) found = 1; //jest pasujace rozszerzenie
			ext_string += ext_tab[j] + " "; //zapisz do stringa wszystkie rozszerzenia aby pokazac w errorze
		}

		if (found == 0) //nie znaleziono pasujacego
		{
			error = "Złe rozszerzenie "+ext_string+"\n"; //niewłasciwe rozszerzenie
			return error;
		}
	}	
}

function dane(plik,element) {
								var xml = null;
								element.innerHTML = "Trwa ładowanie danych...";
								 
								if (window.XMLHttpRequest) xml = new XMLHttpRequest();
								else if (window.ActiveXObject) xml = new ActiveXObject("Microsoft.XMLHTTP");
								 
								if (xml) {
									xml.onreadystatechange = function() {
								 	  if (xml.readyState==4) {
									   	element.innerHTML = xml.responseText;
									   }
									}
									xml.open("GET", plik, true);
									xml.send(null);
								}
								return false;
							}
								 
							function pokazRozmiary(rodzaj) {
								plik = "ajax.php?o=pokazRozmiary&q="+document.getElementById('podloze').value;
								element = document.getElementById("rozmiary");
								dane(plik,element);
								if ( rodzaj == '1' )
									pokazInneCena();
							}

function number_format(num) {
	num="" + Math.floor(num*100.0 + 0.5)/100.0;

	var i=num.indexOf(".");

	if ( i<0 ) num+=",00";
	else {
	num=num.substring(0,i) + "," + num.substring(i + 1);
	i=(num.length - i) - 1;
	if ( i==0 ) num+="00";
	else if ( i==1 ) num+="0";
	else if ( i>2 ) num=num.substring(0,i + 3);
}

return num;
}
							
function przeliczWysylka( wartoscZamowienia, kosztPrzesylki, id ) {
	var suma = wartoscZamowienia + kosztPrzesylki;
	element = document.getElementById('suma');
	suma = number_format(suma);
	element.innerHTML = "<strong>"+suma+" zł</strong>";
}

function zmienZamawiajacego( rodzaj ) {
	plik = "ajax.php?o=rodzajZamawiajacego&q="+rodzaj;
	element = document.getElementById("formRodzajZamawiajacego");
	dane( plik, element );
}

function testuj(t) {
	if (t.imie_nazwisko.value.length<1) { alert("Wypełnij pole:\n     - Imię i Nazwisko"); return false; }
	if (t.adres.value.length<1) { alert("Wypełnij pole:\n     - Adres"); return false; }		
	if (t.kod_pocztowy.value.length<1) { alert("Wypełnij pole:\n     - Kod pocztowy"); return false; }		
	if (t.miejscowosc.value.length<1) { alert("Wypełnij pole:\n     - Miejscowość"); return false; }
	if (t.telefon.value.length<1) { alert("Wypełnij pole:\n     - Telefon kontaktowy"); return false; }		
	if (t.email.value.length<1) { alert("Wypełnij pole:\n     - Adres e-mail"); return false; }
	return true;
}

function blokuj(f) {
	if (f.wyslane) return false;
	f.wyslane=true;
	return true;
}
							
							function pokazInneRozmiary() {
								plik = "ajax.php?o=pokazInneRozmiary&q="+document.getElementById('podloze').value;
								element = document.getElementById("rozmiary_inne");
								dane(plik,element);
							}
							
							function pokazInneCena() {
								plik = "ajax.php?o=pokazInneCena&q="+document.getElementById('podloze').value+"&r="+document.getElementById('rozmiar_inny').value;
								element = document.getElementById("rozmiary_inne_cena");
								dane(plik,element);
							}

function form_wyslij()
{
	var error = "";
	
	//pliki lub nazwy plików
	if (document.getElementById("upfile_0"))
	fl = document.getElementById("upfile_0").value;
	
	//wskazał plik lub wpisał nazwę
	if (fl!="")
	{
		files = 1;
		
				//jeżeli wgrywanie plików przez www i wskazał przynajmniej jeden plik - pokaż progress bar
		if (files==1)
		{
			if(checkNullFileCount()){ return false; error = 'blad'; }
			if(checkFileNameFormat()){ return false; error = 'blad'; }
			if(checkDisallowFileExtensions()){ return false; error = 'blad'; }
			if(checkAllowFileExtensions()){ return false; error = 'blad'; }
			if(checkDuplicateFileCount()){ return false; error = 'blad'; }
		}
	}
	
	if ( document.getElementById("podloze").value == "" ) 
		error = "Nie wybrano rodzaju podłoża!";
	
	for ( var i = 0; i < document.forms.form_upload.rozmiar.length; i++ )
	{
		if ( document.forms.form_upload.rozmiar[i].checked == true )
			var noError = 1;
	}
	
	if( noError != '1')
		error = "Nie wybrano rozmiaru!";

	if (error=="") //nie ma błędów wysyłamy formularz
	{
		//wylacz przyciski do wysylania formularza
		document.getElementById("upload_button").disabled = true;

		document.form_upload.submit();



			//polozenie scrolla pionowego + 100 px
			//var h = f_scrollTop()+100;
			e = document.getElementById("progress_bar");
			e.style.display="block";
			//e.style.top=h; //przesun okienko w dol zeby zawsze bylo na srodku w pionie (scroll)
			uploadFiles(); //włacz progress bar			

	}
	else
	{
		alert(error);
	}
}

function Show(id)
{
 var item = null;
 if (document.getElementById) item = document.getElementById(id);
 else if (document.all) item = document.all[id];
 else if (document.layers) item = document.layers[id];
 if (item) if (item.style) item.style.display = "";
}

function Hide(id)
{
   var item = null;
 if (document.getElementById) item = document.getElementById(id);
 else if (document.all) item = document.all[id];
 else if (document.layers) item = document.layers[id];
 if (item) if (item.style) item.style.display = "none";
}
function ShowOrHide(id)
{
 var item = null;
 if (document.getElementById) item = document.getElementById(id);
 else if (document.all) item = document.all[id];
 else if (document.layers) item = document.layers[id];
 if (!item){  }
  else if (item.style)
  {
   if (item.style.display == "none") item.style.display = "";
   else item.style.display = "none";
  }
  else
  {
   item.visibility = "show";
  }
}

function toggle(hash){
  $(hash).slideToggle("normal");
 }

var oMarquees = [], oMrunning,
	oMInterv =        20,     //interval between increments
	oMStep =          1,      //number of pixels to move between increments
	oStopMAfter =     0,     //how many seconds should marquees run (0 for no limit)
	oResetMWhenStop = false,  //set to true to allow linewrapping when stopping
	oMDirection =     'left'; //'left' for LTR text, 'right' for RTL text

/***     Do not edit anything after here     ***/

function doMStop() {
	clearInterval(oMrunning);
	for( var i = 0; i < oMarquees.length; i++ ) {
		oDiv = oMarquees[i];
		oDiv.mchild.style[oMDirection] = '0px';
		if( oResetMWhenStop ) {
			oDiv.mchild.style.cssText = oDiv.mchild.style.cssText.replace(/;white-space:nowrap;/g,'');
			oDiv.mchild.style.whiteSpace = '';
			oDiv.style.height = '';
			oDiv.style.overflow = '';
			oDiv.style.position = '';
			oDiv.mchild.style.position = '';
			oDiv.mchild.style.top = '';
		}
	}
	oMarquees = [];
}
function doDMarquee() {
	if( oMarquees.length || !document.getElementsByTagName ) { return; }
	var oDivs = document.getElementsByTagName('div');
	for( var i = 0, oDiv; i < oDivs.length; i++ ) {
		oDiv = oDivs[i];
		if( oDiv.className && oDiv.className.match(/\bdmarquee\b/) ) {
			if( !( oDiv = oDiv.getElementsByTagName('div')[0] ) ) { continue; }
			if( !( oDiv.mchild = oDiv.getElementsByTagName('div')[0] ) ) { continue; }
			oDiv.mchild.style.cssText += ';white-space:nowrap;';
			oDiv.mchild.style.whiteSpace = 'nowrap';
			oDiv.style.height = oDiv.offsetHeight + 'px';
			oDiv.style.overflow = 'hidden';
			oDiv.style.position = 'relative';
			oDiv.mchild.style.position = 'absolute';
			oDiv.mchild.style.top = '0px';
			oDiv.mchild.style[oMDirection] = oDiv.offsetWidth + 'px';
			oMarquees[oMarquees.length] = oDiv;
			i += 2;
		}
	}
	oMrunning = setInterval('aniMarquee()',oMInterv);
	if( oStopMAfter ) { setTimeout('doMStop()',oStopMAfter*1000); }
}
function aniMarquee() {
	var oDiv, oPos;
	for( var i = 0; i < oMarquees.length; i++ ) {
		oDiv = oMarquees[i].mchild;
		oPos = parseInt(oDiv.style[oMDirection]);
		if( oPos <= -1 * oDiv.offsetWidth ) {
			oDiv.style[oMDirection] = oMarquees[i].offsetWidth + 'px';
		} else {
			oDiv.style[oMDirection] = ( oPos - oMStep ) + 'px';
		}
	}
}
if( window.addEventListener ) {
	window.addEventListener('load',doDMarquee,false);
} else if( document.addEventListener ) {
	document.addEventListener('load',doDMarquee,false);
} else if( window.attachEvent ) {
	window.attachEvent('onload',doDMarquee);
}
