
var old_idsel=0;

        function checkform(){
                if(document.getElementById("name").value==""){
                        alert("Wypełnij pole Imię i nazwisko"); return false;
                }
                if(document.getElementById("phone").value==""){
                        alert("Wypełnij pole Telefon kontaktowy"); return false;
                }
                if(document.getElementById("email").value==""){
                        alert("Wypełnij pole E-mail"); return false;
                }
                return true;
        }

function loadek_moj(id){
advAJAX.setDefaultParameters({
    onInitialization : function(obj) { document.getElementById(obj.tag).innerHTML = "Przygotowywanie..."; },
    onLoading : function(obj) { document.getElementById(obj.tag).innerHTML = "Pobieranie danych..."; },
    onSuccess : function(obj) { document.getElementById(obj.tag).innerHTML = "" + obj.responseText; },
    onError : function(obj) { document.getElementById(obj.tag).innerHTML = "Błąd..."; }
});


advAJAX.get({ url: 'products_wypozyczalnia_container.php?prod_id='+id, tag: 'dialog_con'});
}



$(document).ready(function() {	

	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		//Get the A tag
		var id = $(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set height and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight,'top':0,'left':0});
		
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		
		$(id).css('top', $(window).scrollTop()+10);
		//$(id).css('top',  0);
		$(id).css('left', winW/2-$(id).width()/2);
		//$(id).css('left', 0);
	
		//transition effect
		$(id).fadeIn(2000); 
	
	});
	
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		$('#mask, .window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});			
	
});


function search_switch(input_date){
	if(document.getElementById(input_date).value=="DD/MM/RR"){
		document.getElementById(input_date).value="";
	}
	return true;
}
function search_switch2(input_date){
	if(document.getElementById(input_date).value==""){
		document.getElementById(input_date).value="DD/MM/RR";
	}
	document.getElementById(input_date).style.border='1px solid black';
	return true;
}

function reload_page_search(source,idselect) {
var selekcik=document.getElementById(idselect).options[document.getElementById(idselect).selectedIndex].value;
if (selekcik!="")
 {
   window.location=source+selekcik;
 }
else
 {
  }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



function checkOnSubmit(){
	

	
	if( $("#wybrana_przesylka").val() == ""){
		//alert("Wybierz wybierz sposób zapłaty i wysyłki");
		$.prompt('Wybierz wybierz sposób zapłaty i wysyłki!' );
		return false;
	}
	else if($("#wybrana_zaplata").val() == ""){
		//alert("Wybierz bank za pośrednictwem którego dokonasz zapłaty!");
		 $.prompt('Wybierz bank za pośrednictwem którego dokonasz zapłaty!' );
		return false;
	} else
		
	if ($("#faktura_tak").attr('checked') && $("#fakturaNip").val() == "") {
		//alert("Aby otrzymać fakturę musisz podać numer NIP!");
		 $.prompt('Aby otrzymać fakturę musisz podać numer NIP!' );
		return false;
	} else
	
	if ($("#faktura_tak").attr('checked') && $("#fakturaNazwaFirmy").val() == "") {
		//alert("Aby otrzymać fakturę musisz podać nazwę firmy!");
		 $.prompt('Aby otrzymać fakturę musisz podać nazwę firmy!' );
		 return false;
	}
	
	
	
}




function setPaymentValues(kosztPrzesylki, formaPrzesylki, formaZaplaty){ 
	
	if ( formaPrzesylki  == 5) // odbior osobisty
		$("#tabela_adres_wysylki").hide();
	else
		$("#tabela_adres_wysylki").show();
	
	$("#tabela_sposob_platnosci").hide();
	$("#price_przesylka").val(kosztPrzesylki);
	$("#wybrana_przesylka").val(formaPrzesylki);
	$("#wybrana_zaplata").val(formaZaplaty);
}


function setBackGroundTransparent(){
	for (i=3; i < 25; i++){
		$("#BankPicture"+i).css('background-color','transparent');
		$("#BankPicture"+i).css('border-width','0px');
	//	$("#BankPicture"+i).css('border-color','transparent');
	}
}

function setPaymentForm(formaZaplaty, formaZaplatyNazwa){ 
	
	setBackGroundTransparent();
	$("#BankPicture"+formaZaplaty).css('background-color','#FFFFFF');
	$("#BankPicture"+formaZaplaty).css('border','1px solid black');
	$("#wybrana_zaplata").val(formaZaplaty);
	$("#wybranaFormaZaplatyPotwierdzenie").html("Wybrany bank: <br> <b>" + formaZaplatyNazwa + "</b>");
}



function choosePaymentForm(kosztPrzesylki, formaPrzesylki){
	if ( formaPrzesylki  == 5) // odbior osobisty
		$("#tabela_adres_wysylki").hide();
	else
		$("#tabela_adres_wysylki").show();
	
	$("#price_przesylka").val(kosztPrzesylki);
	$("#wybrana_przesylka").val(formaPrzesylki);
	$("#wybrana_zaplata").val("");
	
	setBackGroundTransparent();
	$("#wybranaFormaZaplatyPotwierdzenie").html("Nie wybrano banku - <br>aby wybrać kliknij logo");
	$("#tabela_sposob_platnosci").show();
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// submit-uje formularz po wyswietleniu komunikatu i potwierdzeniu przeczytania
function callBackFunction(v,m,f){
	document.forms["prod_details"].submit();
}

// zwraca właściwą formę słowa SZTUKA
function getCorrectForm(number){
  if (number == 1)
    return ' sztukę';
  else if ((number < 10 || number > 20) && (number % 10 >= 2) && (number % 10 <= 4))    // 2, 3, 4, 22, 23, 25, 32...
    return ' sztuki';
  else
    return ' sztuk';
}



// sprawdza czy jest wystarczajaca ilosc towaru w magazynie
function check_quantity() {
		try{
			var storeQuantity = parseInt(document.getElementById("prod_quantity").value);
			var chosenQuantity = parseInt(document.getElementById("Text1").value);
		 
			if (chosenQuantity == 0){          // ilosc wybranych produktów wynosi zero
         $.prompt('<p align="justify">Wybierz co najmniej 1 sztukę produktu!</p>');
				 return false;
      }
			else if (storeQuantity > 600){     // produkty dostepne tylko na zamowienie
				$.prompt('<p align="justify">Drogi kliencie wybrałeś produkt dostępny wyłącznie na zamówienie.</p>' + 
                '<p align="justify"> Skontaktuje się z Tobą pracownik sklepu w celu ustalenia dokładnego terminu realizacji zamówienia.</p>',{callback: callBackFunction});
				return false;
			}
			else if (chosenQuantity > storeQuantity){    // klient zamowil wiecej produktow niz posiadamy w magazynie
			   if (storeQuantity == 0){      // mamy 0 produktow
            $.prompt('<p align="justify">Drogi kliencie wybranego przez Ciebie produktu nie posiadamy aktualnie w magazynie.</p>' + 
                    '<p align="justify">Z tego powodu ilość sztuk produktu w koszyku została ustawiona na <i>0</i>, a&nbsp;w komentarzu do zamówienia została dodana fraza <i>"Prośba o ' 
                      + chosenQuantity + getCorrectForm(chosenQuantity) + '"</i>.</p>' +
                    '<p align="justify">Skontaktuje się z Tobą pracownik sklepu w celu ustalenia dokładnego terminu realizacji zamówienia.</p>',{callback: callBackFunction});
      			return false;
      	 }
      	 else {
        		$.prompt('<p align="justify">Drogi kliencie w magazynie posiadamy tylko ' + storeQuantity + getCorrectForm(storeQuantity) + ' wybranego przez Ciebie produktu.</p>' +       
                    '<p align="justify">Ponieważ zamówiłeś <i>' + chosenQuantity + getCorrectForm(chosenQuantity) + '</i> - ilość sztuk produktu w koszyku została ustawiona na ' +
                      storeQuantity + ', a&nbsp;w komentarzu do zamówienia została dodana fraza <i>"Prośba o ' + chosenQuantity + getCorrectForm(chosenQuantity) + '"</i>.</p>' +  
                    '<p align="justify">Skontaktuje się z Tobą pracownik sklepu w celu ustalenia dokładnego terminu realizacji zamówienia.</p>',{callback: callBackFunction});
          				return false;
         }  
      }
    } catch(error){}     
}

// sprawdza czy wybrano cechy dla produktu i prosi o ich uzupelnienie
function check_attr(idselect,idselect2) {

	try{
			var tmp = document.getElementById("attribute_first").value;
			var selekcik=document.getElementById(idselect).options[document.getElementById(idselect).selectedIndex].value;

			if (selekcik==""){
				$.prompt('<p align = "center">Wybierz wartość pola "' + tmp + '"!</p>',{prefix : 'smallPrompt', top : '20%'});
				return false;
			}
		}
	catch(error){}

	try{
			var tmp = document.getElementById("attribute_second").value;
			var selekcik2=document.getElementById(idselect2).options[document.getElementById(idselect2).selectedIndex].value;

			if ((selekcik=="")||((selekcik2==""))){
				$.prompt('<p align = "center">Wybierz wartość pola "' + tmp + '"!</p>',{prefix : 'smallPrompt', top : '20%'});
				return false;
			}
		}
	catch(error){}

	// produkt o podanych cechach niedostepny w wystarczającej ilosci
	if (check_quantity() == false) return false;

}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function prod_details_cena(idselect) {
var selekcik=document.getElementById(idselect).options[document.getElementById(idselect).selectedIndex].value;
var idcena="";
var idcena2="";
if (selekcik!="")
 {

        document.getElementById("price_from").style.display="none"; 

        if(old_idsel!=0){
                idcena="cena"+old_idsel;
				idcena2="cena"+old_idsel+"_av";
                document.getElementById(idcena).style.display="none"; 
				document.getElementById(idcena2).style.display="none"; 
        }
        old_idsel=selekcik;
        idcena="cena"+selekcik;
		idcena2="cena"+selekcik+"_av";
                
                idcena_wybor="prod_cena"+selekcik;				
                idczas_wybor="prod_wys_czas"+selekcik;
				idilosc_wybor="prod_ilosc"+selekcik;
                
				
				
				document.getElementById("prod_cena").value=document.getElementById(idcena_wybor).value;
                document.getElementById("prod_wys_czas").value=document.getElementById(idczas_wybor).value;
				document.getElementById("prod_quantity").value=document.getElementById(idilosc_wybor).value;
                
				document.getElementById("prod_cecha").value=selekcik;
                document.getElementById(idcena).style.display="block";
				document.getElementById(idcena2).style.display="block";
        
 }
else
 {
 idcena="cena"+old_idsel;
 idcena2="cena"+old_idsel+"_av";
                document.getElementById(idcena).style.display="none";
				document.getElementById(idcena2).style.display="none";

                                document.getElementById("price_from").style.display="block"; 
  }
}



function addOption(selectObject,optionText,optionValue) {
    var optionObject = new Option(optionText,optionValue)
    var optionRank = selectObject.options.length
    selectObject.options[optionRank]=optionObject
}

var old_idsel1="";
var flag_sel="";

function prod_details_cena2a(idselect) {
var selekcik=document.getElementById(idselect).options[document.getElementById(idselect).selectedIndex].value;

if (selekcik!="")
 {
                

        var tab1=tablica1[selekcik].split("|");

        for (var i=document.getElementById("cecha2").options.length-1; i>=0; i--){
        document.getElementById("cecha2").options[i] = null;
        }
        addOption(document.getElementById("cecha2"),"Wybierz","");
        document.getElementById("cecha2").selectedIndex = 0;

        for (var n = 0; n < tab1.length; ++n)
        addOption(document.getElementById("cecha2"),tab1[n],tab1[n]);
                
 }
else
 {
        document.getElementById("cecha2").disabled=true; 
        document.getElementById("price_from").style.display="block";
        if(old_idsel1!=""){
                idcena="cena"+old_idsel1;
				idcena2="cena"+old_idsel1+"_av";
        document.getElementById(idcena).style.display="none";
		document.getElementById(idcena2).style.display="none";
        }
        flag_sel="1";
        
 }
}




function prod_details_cena2b(idselect) {
var selekcik2=document.getElementById(idselect).options[document.getElementById(idselect).selectedIndex].value;

var idcena="";
if (selekcik2!="")
 {

 document.getElementById("price_from").style.display="none"; 
        
        var attr_name=document.getElementById("cecha1").options[document.getElementById("cecha1").selectedIndex].value + " - " + selekcik2.replace(",","___").replace("-","_").replace("&minus;","_").replace("&euro;","").replace("\u20AC","").replace("+","__").replace("\&#8242","").replace(";","").replace("\u2019","");
        /*alert("wart: "+attr_name);*/
        var selekcik3=document.getElementById(attr_name).value;


        if(old_idsel!=0){
                idcena="cena"+old_idsel;
				idcena2="cena"+old_idsel+"_av";
                document.getElementById(idcena).style.display="none"; 
				document.getElementById(idcena2).style.display="none"; 
        }
        old_idsel=selekcik3;
                old_idsel1=selekcik3;
        idcena="cena"+selekcik3;
		idcena2="cena"+selekcik3+"_av";
                
                idcena_wybor="prod_cena"+selekcik3;
                idczas_wybor="prod_wys_czas"+selekcik3;
				idilosc_wybor="prod_ilosc"+selekcik3;
				
                document.getElementById("prod_cena").value=document.getElementById(idcena_wybor).value;
                document.getElementById("prod_wys_czas").value=document.getElementById(idczas_wybor).value;
				document.getElementById("prod_quantity").value=document.getElementById(idilosc_wybor).value;
				
                document.getElementById("prod_cecha").value=selekcik3;				
                document.getElementById(idcena).style.display="block";
				document.getElementById(idcena2).style.display="block";
                
 }
else
 {
 idcena="cena"+old_idsel;
 idcena2="cena"+old_idsel+"_av";
                document.getElementById(idcena).style.display="none";
				document.getElementById(idcena2).style.display="none";
                                document.getElementById("price_from").style.display="block"; 
  }
}



function prod_details_cena_wypozycz(idselect) {
var tab_wypozycz=idselect.split("_");
var prod_id=tab_wypozycz[1];
var selekcik=document.getElementById(idselect).options[document.getElementById(idselect).selectedIndex].value;
var idcena="";
if (selekcik!="")
 {

        
                       document.getElementById("cecha_"+prod_id).value=selekcik;
                
        
 }
else
 {
 
  }
}

function prod_details_cena2a_wypozycz(idselect) {

var tab_wypozycz=idselect.split("_");
var prod_id=tab_wypozycz[1];

var selekcik=document.getElementById(idselect).options[document.getElementById(idselect).selectedIndex].value;

if (selekcik!="")
 {                

        var tab1=tablica1[selekcik].split("|");

        for (var i=document.getElementById("cecha2_"+prod_id).options.length-1; i>=0; i--){
        document.getElementById("cecha2_"+prod_id).options[i] = null;
        }
        addOption(document.getElementById("cecha2_"+prod_id),"Wybierz","");
        document.getElementById("cecha2_"+prod_id).selectedIndex = 0;

        for (var n = 0; n < tab1.length; ++n)
        addOption(document.getElementById("cecha2_"+prod_id),tab1[n],tab1[n]);
                
 }
else
 {
        document.getElementById("cecha2_"+prod_id).disabled=true; 
        
        flag_sel="1";
        
 }
}

function prod_details_cena2b_wypozycz(idselect) {
var tab_wypozycz=idselect.split("_");
var prod_id=tab_wypozycz[1];
var selekcik2=document.getElementById(idselect).options[document.getElementById(idselect).selectedIndex].value;

var idcena="";
if (selekcik2!="")
 {

        
        var attr_name=document.getElementById("cecha1_"+prod_id).options[document.getElementById("cecha1_"+prod_id).selectedIndex].value + " - " + selekcik2.replace(",","___").replace("-","_").replace("&minus;","_").replace("&euro;","").replace("\u20AC","").replace("+","__").replace("\&#8242","").replace(";","").replace("\u2019","");
        /*alert("wart: "+attr_name);*/
        var selekcik3=document.getElementById(attr_name).value;


                document.getElementById("cecha_"+prod_id).value=selekcik3;

                
 }
else
 {
				document.getElementById("cecha_"+prod_id).value="";
  }
}

function wys_adres() {
if(document.getElementById("duel_shop_klientf_dane_wys").checked==true){
        document.getElementById("wys_adres").style.display="block";
}else{document.getElementById("wys_adres").style.display="none";}
}

function check_register_form() {
if(document.getElementById("get_login").value!=""){
if(document.getElementById("duel_shop_klientlogin").value=="" && document.getElementById("duel_shop_klientlogin").type!="hidden"){
        alert("Wpisz LOGIN"); return false;
}
}

if((document.getElementById("get_login").value!="")&&(document.getElementById("duel_shop_klientpassword").value=="")){
        alert("Wpisz HASLO"); return false;
}

if(document.getElementById("duel_shop_klientpassword").value!=document.getElementById("duel_shop_klientpassword2").value){
                alert("Powtorz HASLO"); return false;
}

if(document.getElementById("duel_shop_klientimie").value==""){
        alert("Wpisz IMIE"); return false;
}
if(document.getElementById("duel_shop_klientnazwisko").value==""){
        alert("Wpisz NAZWISKO"); return false;
}
/*if((document.getElementById("duel_shop_klientf_dane_fk").checked==true)&&(document.getElementById("duel_shop_klientf_nip").value=="")){
        alert("Wpisz NIP"); return false;
}
if((document.getElementById("duel_shop_klientf_dane_fk").checked==true)&&(document.getElementById("duel_shop_klientnazwa_firmy").value=="")){
        alert("Wpisz NAZWE FIRMY"); return false;
}*/
if(document.getElementById("duel_shop_klientulica").value==""){
        alert("Wpisz ULICE"); return false;
}

if(document.getElementById("duel_shop_klientkod_pocz").value==""){
     alert("Wpisz KOD POCZTOWY"); return false;
}
if(document.getElementById("duel_shop_klientmiasto").value==""){
        alert("Wpisz MIASTO"); return false;
}
if(document.getElementById("duel_shop_klientnrd").value==""){
        alert("Wpisz NR DOMU"); return false;
}
/*if(document.getElementById("duel_shop_klientnrm").value==""){
       alert("Wpisz NR MIESZKANIA"); return false;
}
if(document.getElementById("duel_shop_klientagree").checked==false){
        alert("Musisz zaakceptowac regulamin"); return false;
}                   

if((document.getElementById("duel_shop_klientf_dane_wys").checked==true)&&(document.getElementById("duel_shop_klientf_imie").value=="")){
        alert("Wpisz IMIE"); return false;
}
if((document.getElementById("duel_shop_klientf_dane_wys").checked==true)&&(document.getElementById("duel_shop_klientf_nazwisko").value=="")){
        alert("Wpisz NAZWISKO"); return false;
}                   */


if(document.getElementById("duel_shop_klientemail").value==""){
        alert("Wpisz E-MAIL"); return false;
}
if(document.getElementById("duel_shop_klienttel").value==""){
        alert("Wpisz NR TELEFONU"); return false;
}

if(document.getElementById("duel_shop_klientzgoda_przetw").checked==false){
        alert("Zaakceptuj zgode na przetwarzanie danych"); return false;
}

}

function startList() {

        // code for IE
        if(!document.body.currentStyle) return;
        var subs = document.getElementsByName('submenu');
        for(var i=0; i<subs.length; i++) {
                var li = subs[i].parentNode;
                if(li && li.lastChild.style) {
                        li.onmouseover = function() {
                                this.lastChild.style.visibility = 'visible';
                        }
                        li.onmouseout = function() {
                                this.lastChild.style.visibility = 'hidden';
                        }
                }
        }
}



/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert("Adres e-mail jest niepoprawny!");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Adres e-mail jest niepoprawny!");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Adres e-mail jest niepoprawny!");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Adres e-mail jest niepoprawny!");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Adres e-mail jest niepoprawny!");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Adres e-mail jest niepoprawny!");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Adres e-mail jest niepoprawny!");
		    return false;
		 }

 		 return true					
	}

function ValidateForm(){
	var emailID=document.getElementById('newsletterduel_shop_news_addemail');
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Wpisz swoj e-mail!");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}
	return true;
 }

