/*
  $Id: general.js,v 1.1.1.1 2004/11/26 17:41:45 sam Exp $
  Script Connector CastleKart, Open Source E-Commerce Solutions
  http://www.scriptconnector.org/
  Copyright (c) 2004-2005 Script Connector Corporation
  Copyright (c) 2003 osCommerce
  Released under the GNU General Public License
*/

function SetFocus(TargetFormName) {
  var target = 0;
  if (TargetFormName != "") {
    for (i=0; i<document.forms.length; i++) {
      if (document.forms[i].name == TargetFormName) {
        target = i;
        break;
      }
    }
  }

  var TargetForm = document.forms[target];
    
  for (i=0; i<TargetForm.length; i++) {
    if ( (TargetForm.elements[i].type != "image") && (TargetForm.elements[i].type != "hidden") && (TargetForm.elements[i].type != "reset") && (TargetForm.elements[i].type != "submit") ) {
      TargetForm.elements[i].focus();

      if ( (TargetForm.elements[i].type == "text") || (TargetForm.elements[i].type == "password") ) {
        TargetForm.elements[i].select();
      }

      break;
    }
  }
}

function RemoveFormatString(TargetElement, FormatString) {
  if (TargetElement.value == FormatString) {
    TargetElement.value = "";
  }

  TargetElement.select();
}

function CheckDateRange(from, to) {
  if (Date.parse(from.value) <= Date.parse(to.value)) {
    return true;
  } else {
    return false;
  }
}

function IsValidDate(DateToCheck, FormatString) {
  var strDateToCheck;
  var strDateToCheckArray;
  var strFormatArray;
  var strFormatString;
  var strDay;
  var strMonth;
  var strYear;
  var intday;
  var intMonth;
  var intYear;
  var intDateSeparatorIdx = -1;
  var intFormatSeparatorIdx = -1;
  var strSeparatorArray = new Array("-"," ","/",".");
  var strMonthArray = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
  var intDaysArray = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

  strDateToCheck = DateToCheck.toLowerCase();
  strFormatString = FormatString.toLowerCase();
  
  if (strDateToCheck.length != strFormatString.length) {
    return false;
  }

  for (i=0; i<strSeparatorArray.length; i++) {
    if (strFormatString.indexOf(strSeparatorArray[i]) != -1) {
      intFormatSeparatorIdx = i;
      break;
    }
  }

  for (i=0; i<strSeparatorArray.length; i++) {
    if (strDateToCheck.indexOf(strSeparatorArray[i]) != -1) {
      intDateSeparatorIdx = i;
      break;
    }
  }

  if (intDateSeparatorIdx != intFormatSeparatorIdx) {
    return false;
  }

  if (intDateSeparatorIdx != -1) {
    strFormatArray = strFormatString.split(strSeparatorArray[intFormatSeparatorIdx]);
    if (strFormatArray.length != 3) {
      return false;
    }

    strDateToCheckArray = strDateToCheck.split(strSeparatorArray[intDateSeparatorIdx]);
    if (strDateToCheckArray.length != 3) {
      return false;
    }

    for (i=0; i<strFormatArray.length; i++) {
      if (strFormatArray[i] == 'mm' || strFormatArray[i] == 'mmm') {
        strMonth = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'dd') {
        strDay = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'yyyy') {
        strYear = strDateToCheckArray[i];
      }
    }
  } else {
    if (FormatString.length > 7) {
      if (strFormatString.indexOf('mmm') == -1) {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mm'), 2);
      } else {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mmm'), 3);
      }

      strDay = strDateToCheck.substring(strFormatString.indexOf('dd'), 2);
      strYear = strDateToCheck.substring(strFormatString.indexOf('yyyy'), 2);
    } else {
      return false;
    }
  }

  if (strYear.length != 4) {
    return false;
  }

  intday = parseInt(strDay, 10);
  if (isNaN(intday)) {
    return false;
  }
  if (intday < 1) {
    return false;
  }

  intMonth = parseInt(strMonth, 10);
  if (isNaN(intMonth)) {
    for (i=0; i<strMonthArray.length; i++) {
      if (strMonth == strMonthArray[i]) {
        intMonth = i+1;
        break;
      }
    }
    if (isNaN(intMonth)) {
      return false;
    }
  }
  if (intMonth > 12 || intMonth < 1) {
    return false;
  }

  intYear = parseInt(strYear, 10);
  if (isNaN(intYear)) {
    return false;
  }
  if (IsLeapYear(intYear) == true) {
    intDaysArray[1] = 29;
  }

  if (intday > intDaysArray[intMonth - 1]) {
    return false;
  }
  
  return true;
}

function IsLeapYear(intYear) {
  if (intYear % 100 == 0) {
    if (intYear % 400 == 0) {
      return true;
    }
  } else {
    if ((intYear % 4) == 0) {
      return true;
    }
  }

  return false;
}


function checkLoyaltyPos(val)
{
        var val = parseFloat(val);
        document.forms['checkout_address'].elements['val'].value = val;

}

function makeCountPts(one_ptk_price, s)
{
        var actual_ptk = document.forms['checkout_address'].elements['pts_avaliable'].value;
        actual_ptk = parseInt(actual_ptk); //dostepna ilosc ptk

        var delivery_price = document.forms['checkout_address'].elements['val'].value;
        delivery_price = parseFloat(delivery_price); //cena za przesyłke
        var one_ptk_price = parseFloat(one_ptk_price); //cena za jeden ptk



        var ilosc_ptk_pot_do_przesylki = Math.round(delivery_price/one_ptk_price);
// alert('dd'+one_ptk_price);
if(s == 1)
{


        if(delivery_price > 0)
         {

                if(ilosc_ptk_pot_do_przesylki <= actual_ptk)
                {
                        var result = actual_ptk - ilosc_ptk_pot_do_przesylki; 
                        document.forms['checkout_address'].elements['pts_avaliable'].value = result;

                        document.forms['checkout_address'].elements['pts_avaliable2'].value = result;
                        var suma = ilosc_ptk_pot_do_przesylki * one_ptk_price;
                        document.forms['checkout_address'].elements['cena_do_odjecia'].value = suma;

                }
                else if(ilosc_ptk_pot_do_przesylki > actual_ptk)
                {
//                         for (counter = 0; counter < checkout_address.shipping.length; counter++)
//                         {
//                         if (checkout_address.shipping[counter].checked)
//                         alert(checkout_address.shipping[counter].value);
//                         }
                        var val = document.forms['checkout_address'].elements['val'].value
                        var result = ilosc_ptk_pot_do_przesylki - actual_ptk; 
                        var suma = actual_ptk * one_ptk_price;
                        document.forms['checkout_address'].elements['cena_do_odjecia'].value = suma;
                        document.forms['checkout_address'].elements['pts_avaliable'].value = 0;

                        document.forms['checkout_address'].elements['pts_avaliable2'].value = 0;

                }


         }

/*              var act_pts = parseFloat(Math.round(delivery_price/one_ptk_price));
              var result = actual_ptk - act_pts; 
              document.forms['checkout_address'].elements['pts_avaliable'].value = result;*/              
               

}
else
{
        if(delivery_price > 0)
         {

              document.forms['checkout_address'].elements['pts_avaliable'].value = document.forms['checkout_address'].elements['pts_avaliable_orgin'].value;      

              document.forms['checkout_address'].elements['pts_avaliable2'].value = document.forms['checkout_address'].elements['pts_avaliable_orgin'].value;         
        }  

       document.forms['checkout_address'].elements['cena_do_odjecia'].value = 0;
}

}


function checkPosibility(needed, avaliable)
{
        var n = parseInt(needed);
        var a = parseInt(avaliable);



        if(a >= n) return true;
        else{ alert("Nie posiadasz wystarczającej ilości punktów aby zamówić ten produkt"); return false; }
          

}

function showDetails()
{
        var id = document.getElementById('mmSel').value;
        new Ajax.Updater('result', 'coupons_show_details.php?id='+id);
}


function flineUnder(el, dl, i)
{
        var el = el;
        var i = parseInt(i);
        var dl = parseInt(dl);
        if(i < dl)
        {
                document.getElementById(el).src = "./images/pixel_white.gif";
                document.getElementById(el).width = i;
		if(el == 'link_kt')
                document.getElementById(el).height = 2;

                var i = i+10;
                setTimeout("flineUnder(\'"+el+"\', "+dl+", "+i+")", 0);
        }
}

function flineUnderNo(el, dl, i)
{

        var el = el;
        var i = parseInt(i);
        var dl = parseInt(dl);
        if(i >= 0)
        {
                document.getElementById(el).src = "./images/pixel_white.gif";
                document.getElementById(el).width = i;

                if(i<0)  i = 0;
                var i = i-10;
                setTimeout("flineUnderNo(\'"+el+"\', "+dl+", "+i+")", 0);
        }
        else
        document.getElementById(el).src = "./images/pixel_trans.gif"; 
}


//grey
function flineUnderGrey(el, dl, i)
{
        var el = el;
        var i = parseInt(i);
        var dl = parseInt(dl);
        if(i < dl)
        {
                document.getElementById(el).src = "./images/kamai sklep/pixel_666.gif";
                document.getElementById(el).width = i;


                var i = i+10;
                setTimeout("flineUnderGrey(\'"+el+"\', "+dl+", "+i+")", 0);
        }
}

function flineUnderNoGrey(el, dl, i)
{

        var el = el;
        var i = parseInt(i);
        var dl = parseInt(dl);
        if(i >= 0)
        {
                document.getElementById(el).src = "./images/kamai sklep/pixel_666.gif";
                document.getElementById(el).width = i;

                if(i<0)  i = 0;
                var i = i-10;
                setTimeout("flineUnderNoGrey(\'"+el+"\', "+dl+", "+i+")", 0);
        }
        else
        document.getElementById(el).src = "./images/pixel_trans.gif"; 
}



function scrolledMenuShow(i)
{

        var i = parseInt(i);
        if(i >= 70)
        {
                document.getElementById('left-side').style.border = "1px solid #cecdc8"; 
                document.getElementById('left-side').style = "border-bottom: 1px solid #cecdc8;";

                document.getElementById('right-side').style = "border-right: 1px solid #cecdc8;"; 
                document.getElementById('right-side').style = "border-bottom: 1px solid #cecdc8;";
        }
        if(i < 70)
        {
                document.getElementById('scrolled_login_field').style.display = "block";
                document.getElementById('scrolled_login_field').style.top = i;


                var i = i+5;
                setTimeout("scrolledMenuShow("+i+")", 100);
        }


}

function ch_subcat(p)
{

var el = document.getElementById("subcat_"+p);

if(el.style.display == 'none')
{
el.style.display = 'block';
document.getElementById("subcat_"+p).height== "60";
}
else
{
el.style.display = 'none';
document.getElementById("subcat_"+p).height== "0";
}
}




        function resizeLogin(new_position_value) {
                if(new_position_value == 'hw')
                {    

                        if(navigator.appName == "Microsoft Internet Explorer")
                        {
                                document.getElementById('login_face').style.left = '6px';
                                document.getElementById('login_face').style.borderRight = "2px solid #cccccc";
                                document.getElementById('login_face').style.borderLeft = "1px solid #cccccc";
                        }
                        else
                        {
                                document.getElementById('login_face').style.left = '6px';
                                document.getElementById('login_face').style.borderRight = "2px solid #cccccc";
                                document.getElementById('login_face').style.borderLeft = "1px solid #cccccc";
                        }



                }
                        if(new_position_value == 'hw2')
                        {
                                document.getElementById('login_face').style.borderRight = "0px solid #cccccc";
                                document.getElementById('login_face').style.borderLeftWidth = "0px";
                        }
                var new_value_str = new_position_value + 'px';
                document.getElementById('login').style.top=new_value_str;
        }

        function showLogin() {
                document.getElementById('login').style.display = "block";
                var new_position_value = -125;
                var time_delay = 0;
                while (true) {
                        setTimeout("resizeLogin(" + new_position_value + ")", time_delay * 4);

                        new_position_value++;
                        time_delay++;

                        if (new_position_value >= 30) {
                        setTimeout("resizeLogin(\'hw\')", 1000);
                                break;
                        }
                }
        }


function hideLogin()
{
setTimeout("resizeLogin(\'hw2\')", 500);
document.getElementById('login').style.display = "none";


}

        function resizeBasket(new_position_value) {
                if(new_position_value == 'szym')
                {    

                        if(navigator.appName == "Microsoft Internet Explorer")
                        {
                                document.getElementById('login_face').style.left = '9px';
                                document.getElementById('login_face').style.borderRight = "2px solid #cccccc";
                                document.getElementById('login_face').style.borderLeft = "1px solid #cccccc";
                        }
                        else
                        {
                                document.getElementById('login_face').style.left = '6px';
                                document.getElementById('login_face').style.borderRight = "2px solid #cccccc";
                                document.getElementById('login_face').style.borderLeft = "1px solid #cccccc";
                        }



                }
                        if(new_position_value == 'szym2')
                        {
                                document.getElementById('login_face').style.borderRight = "0px solid #cccccc";
                                document.getElementById('login_face').style.borderLeftWidth = "0px";
                        }
                var new_value_str = new_position_value + 'px';
                document.getElementById('basket').style.top=new_value_str;
        }

        function showBasket() {

                document.getElementById('basket').style.display = "block";
                var new_position_value = -125;
                var time_delay = 0;
                while (true) {
                        setTimeout("resizeBasket(" + new_position_value + ")", time_delay * 4);

                        new_position_value++;
                        time_delay++;

                        if (new_position_value >= 30) {
                        setTimeout("resizeBasket(\'szym\')", 1000);

                                break;
                        }
                }
        }



        function hideBasket(el) {

                var new_position_value = 30;
                var time_delay = 0;
                while (true) {
                        setTimeout("resizeBasket(" + new_position_value + ")", time_delay * 4);

                        new_position_value--;
                        time_delay++;

                        if (new_position_value <= el) {
                        setTimeout("resizeBasket(\'szym2\')", 1000);
                                break;
                        }
                }
//                 document.getElementById('basket').style.display = "none";
        }


function addToNewsletter()
{
        if(document.getElementById('news').style.display == "none")
                document.getElementById('news').style.display = "block";
        else if(document.getElementById('news').style.display == "block")
                document.getElementById('news').style.display = "none";

}

function makeCenterProduct()
{
var position = Get_Cookie("position");
var address = "http://"+Get_Cookie("address");
// alert("1="+address+"   2="+document.location.href);
 if(address == document.location.href) 
        document.body.scrollTop = position;

}

function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

function Get_Cookie( check_name ) {
        // first we'll split this cookie up into name/value pairs
        // note: document.cookie only returns name=value, not the other components
        var a_all_cookies = document.cookie.split( ';' );
        var a_temp_cookie = '';
        var cookie_name = '';
        var cookie_value = '';
        var b_cookie_found = false; // set boolean t/f default f
        var a_temp_all = '';
        for ( i = 0; i < a_all_cookies.length; i++ )
        {
                // now we'll split apart each name=value pair
                a_temp_cookie = a_all_cookies[i].split( '=' );
                
                for(j=1; j < a_temp_cookie.length; j++) {
                     if(j != (a_temp_cookie.length-1))
                        a_temp_all += a_temp_cookie[j]+"=";
                     else
                        a_temp_all += a_temp_cookie[j];
                }

                // and trim left/right whitespace while we're at it
                cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
        
                // if the extracted name matches passed check_name
                if ( cookie_name == check_name )
                {
                        b_cookie_found = true;
                        // we need to handle case where cookie has no value but exists (no = sign, that is):
                        if ( a_temp_cookie.length > 1 )
                        {
                                cookie_value = a_temp_all;
                        }
                        // note that in cases where cookie is initialized but no value, null is returned
                        a_temp_all = '';
                        return cookie_value;
                        break;
                }
                a_temp_all = '';
                a_temp_cookie = null;
                cookie_name = '';
        }
        if ( !b_cookie_found )
        {
                return null;
        }
}

       
function addPosition(adres) {

 document.cookie="address="+adres;
     if(navigator.appName == "Microsoft Internet Explorer" || navigator.appName == "Opera")
     {

         ccc = document.body.scrollTop;

     }
     else
     {
        var ccc = window.scrollY;
     }

 document.cookie="position="+ccc; 

}


function open_baner() {

        new Ajax.Updater('p2baner', "szymen.html");
  

}

function showLogin2() {
		  jQuery("#login_content").show("slide", { direction: "up" }, 1000);
		  jQuery("#frame_face").attr("style","border-left: 1px solid #cccccc; border-right: 2px solid #cccccc; padding-top: 13px;");

}


function hideBorder() {
    jQuery("#frame_face").attr("style","border-left: 1px solid #f4f3ed; border-right: 2px solid #f4f3ed; padding-top: 13px;");
}


function hideBasket2() {
		  jQuery("#basket_content").hide("slide", { direction: "up" }, 1000);
		  setTimeout("hideBorder()", 1000);

}


function hideLogin2() {
		  jQuery("#login_content").hide("slide", { direction: "up" }, 1000);
		  setTimeout("hideBorder()", 1000);

}


function showBasket2() {
		  jQuery("#basket_content").show("slide", { direction: "up" }, 1000);
		  jQuery("#frame_face").attr("style","border-left: 1px solid #cccccc; border-right: 2px solid #cccccc; padding-top: 13px;");

}


  function getBaner(idek) {
   if(document.getElementById("main_def_baner")) {
    jQuery("div#main_def_baner div").attr("style", "display: none");
    jQuery("#main_baner_"+idek).attr("style", "display: block");
   }

	    if(document.getElementById("strzalka_"+idek+"").src != "http://concept.netarch.eu/kamai_shop/images/kamai%20sklep/strzalki_red_down.png") {
				jQuery("#strzalka_"+idek+"").attr("src","./images/kamai sklep/strzalki_red_right.png");
				jQuery("#link_"+idek+"").css("color","red");				
			}
  }


  function hideBaner(idek) {
   if(document.getElementById("main_def_baner")) {
    jQuery("#main_baner_"+idek).attr("style", "display: none");
    jQuery("#kt_link").attr("style", "display: block; position: absolute; top: 191; left: 20; z-index: 90");
    jQuery("#kt_link2").attr("style", "display: block;");
    jQuery("#kt_link2").attr("style", "display: block; padding-left: 45px;");		
	 }

	    if(document.getElementById("strzalka_"+idek+"").src != "http://concept.netarch.eu/kamai_shop/images/kamai%20sklep/strzalki_red_down.png") {
				jQuery("#strzalka_"+idek+"").attr("src","./images/kamai sklep/strzalki_grey_right.png");
				jQuery("#link_"+idek+"").css("color","#666666");	
			}
  }




function getStartWithOnOff() {
      var tabelka = document.getElementById("main_frame_cat").childNodes['0'];
      var tr = tabelka.getElementsByTagName("tr")
 	  for(i = 0; i<tr.length; i++) {
	      if(tr[i].id == 'ci') {
		 var td = tr[i].getElementsByTagName("td");
// alert(td.length);
		  for(j = 0; j<td.length; j++) {

		      if(td[j].id != '') {
// alert(td[j].id);
			var element = td[j].id;
			var ide = Array();
			re = /^[a-zA-Z_]+([0-9]{2})$/;
			ide = re.exec(element);
			if(ide != null) {
			  idek = ide[1];
			  getPositionInOut(idek);
			}

		      }

		  }
	      }
	  }
}



        jQuery(document).ready(
        function()
        {
	  var isDialogOpen = false;


	      jQuery("#dialog_log").dialog({ autoOpen: false, bgiframe: true, modal: true, resizable: false, width: 450 });

	      jQuery("#zobacz_log").click( function() {     // assign the link the click

		    jQuery("#dialog_log").dialog('open');

	      } );
	setTimeout("getStartWithOnOff()", 2000);


	      jQuery("#koszyk3kroki").click( function() {     // assign the link the click

		  jQuery.ajax ({
		    url: "jquery_functions.php",
		    data: "action=dialog_login",
		    dataType: "html",
		    type: "get",
		    success: function(ret) {
			jQuery("#dialog_todo").html(ret);
			jQuery("#dialog_new").dialog({ autoOpen: true, bgiframe: true, modal: true, resizable: false, width: 500, close: function(ev, ui) { jQuery(this).remove(); } });
		    }
		  }); 

	      } );

	      jQuery("#koszyk2Email").click( function() {  
		  var xx = 0;
		  var yy = 0;
		  xx = jQuery("#koszyk2Email").offset().left - 100;
		  yy = jQuery("#koszyk2Email").offset().top - jQuery(window).scrollTop() - 100;

		jQuery("#dialog_todo").html('');
		jQuery("#dialog_todo").load("jquery_functions.php?action=dialog_koszyk2email", { }, function() { 
			  jQuery("#dialog_k2e").dialog({ autoOpen: true, bgiframe: true, modal: true, resizable: false, width: 250, position: [xx, yy], dialogClass: "mt",close: function(ev, ui) { jQuery(this).remove(); } });
		  } );

// 		  jQuery.ajax ({
// 		    url: "jquery_functions.php",
// 		    data: "action=dialog_koszyk2email",
// 		    dataType: "html",
// 		    type: "get",
// 		    success: function(ret) {
// 			jQuery("#dialog_todo").html(ret);
// 			jQuery("#dialog_k2e").dialog({ autoOpen: true, bgiframe: false, modal: true, resizable: false, width: 250, position: [xx, yy], dialogClass: "mt" });
// 		    }
// 		  }); 

	      } );




//--------------- dialog dla kosza --------------

	      jQuery("#showMyBasket").click( function() {  


 		  jQuery.ajax ({
 		    url: "jquery_functions.php",
 		    data: "action=dialog_showmybasket",
 		    dataType: "html",
 		    type: "get",
 		    success: function(ret) {
 			jQuery("#dialog_todo").html(ret);
 			jQuery("#dialog_koszykMain").dialog({ autoOpen: true, bgiframe: true, modal: true, resizable: false, width: 680, dialogClass: "ks",close: function(ev, ui) { jQuery(this).remove();  } });

//!!!!!!!!!!!!!!!!!-------------------- działania na dialog-koszyku ------------------!!!!!!!!!!!!!!!!!!!!!

			jQuery("#continueShopping").click( function() {
			    jQuery("#dialog_koszykMain").remove();
			});

			jQuery("#buy3").click( function() {
			    jQuery("#dialog_koszykMain").remove();
			    jQuery.ajax ({
			      url: "jquery_functions.php",
			      data: "action=dialog_login",
			      dataType: "html",
			      type: "get",
			      success: function(ret) {
				  jQuery("#dialog_todo").html(ret);
				  jQuery("#dialog_new").dialog({ autoOpen: true, bgiframe: true, modal: true, resizable: false, width: 500, close: function(ev, ui) { jQuery(this).remove(); } });
			      }
			    }); 
			});


			jQuery("input:hidden[name=dialog_products_id[]]").each( function() {
			    var vartosc = this.value;
			    var q = jQuery("#dialog_q"+vartosc).val();
			    jQuery("#dialog_main_price").html('');
			    jQuery("#dialog_main_price").attr('class','loader');


			  if(vartosc != '' && typeof(vartosc) != 'undefined' && q != '' && typeof(q) != 'undefined') {
			    jQuery.ajax({
			      url: 'dialog_shopping_cart.php',
			      data: 'action=getPriceWithoutShipp&products_id='+vartosc+'&quantity='+q,
			      type: 'post',
			      dataType: 'json',
			      success: function(j) {

			      // jQuery("#price_"+j.idek).html('<b>'+j.price+'</b>');
				jQuery("#dialog_main_price").attr('class','blank');
				jQuery("#dialog_main_price").html('<b>'+j.main_price+'</b>');
			      },
			      error: function(j) {
				alert("error");
			      }
			    });
			  }
			});


			jQuery("input:text[name=dialog_cart_quantity[]]").keyup( function() {
			    var q = this.value;
			    var products_id = this.id.substring(8);

			    //alert(this.timer);
			    if (this.timer) clearTimeout(this.timer);
			    jQuery("#dialog_main_price").html('');
			    jQuery("#dialog_main_price").attr('class','loader');


			  if(products_id != '' && typeof(products_id) != 'undefined' && q != '' && typeof(q) != 'undefined') {
			  this.timer = setTimeout(function () {
			    jQuery.ajax({
			      url: 'dialog_shopping_cart.php',
			      data: 'action=getPriceWithoutShipp&change_quantity=1&products_id='+products_id+'&quantity='+q,
			      type: 'post',
			      dataType: 'json',
			      success: function(j) {
				jQuery("#dialog_main_price").attr('class','blank');
				jQuery("#dialog_main_price").html('<b>'+j.main_price+'</b>');
			      }
			    });
			    }, 200);
			  }

			});


			jQuery("input:checkbox[name=dialog_cart_delete[]]").click( function() {
			    var products_id = this.value;
			    var q = jQuery("#dialog_q"+products_id).val();


			  if(confirm('Czy jesteś pewnien, że chcesz usunąć ten produkt?'))
			      location.href='./index.php?action=delete_from_cart&products_id='+products_id+'&products_quantity='+q;
			});




 		    }
 		  }); 

	      } );





	    jQuery("#a_open").click(function () {
		  jQuery("#basket_content").show("slide", { direction: "up" }, 1000);
		  jQuery("#frame_face").attr("style","border-left: 1px solid #cccccc; border-right: 2px solid #cccccc; padding-top: 13px;");
	    });


jQuery("#s1").show(); 
jQuery("#s1").cycle({ 
    fx:    'fade', 
    pause:  1 
});


jQuery("#s2").show(); 
jQuery("#s2").cycle({ 
    fx:    'fade', 
    pause:  1 
});

/*		  var id  = jQuery("#cat_id").val();
			jQuery.ajax( {
			  type: "get",
			  dataType: "html",
			  url: "jquery_functions.php?action=get_opis&cat_id="+id,
			  success: function(msg) {
			    jQuery("#cat_desc").attr('innerHTML',msg);
			  }
			});*/	
			
			
        var RPshow = Get_Cookie("RPshow");
        if(RPshow == 0)
          closeRP();
        else
          openRP();

        var string_strony = '';
         ust = Get_Cookie("remRP");
        if(ust != null) {
         var tab_rem = ust.split("%2C");


        for(indeks in tab_rem){
           var pan_num = parseInt(indeks)+1; 

//               if(tab_rem[indeks] == '1')
//                 jQuery("#1").load('panel_schowek.php'); 
              if(tab_rem[indeks] == '2')
                jQuery("#2").load('panel_przypominacz.php'); 
              else if(tab_rem[indeks] == '3')
                jQuery("#3").load('panel_dzisiaj.php'); 
              else if(tab_rem[indeks] == '4')
                jQuery("#4").load('panel_pogoda.php');
              else if(tab_rem[indeks] == '5')
                jQuery("#5").load('panel_kalendarz.php'); 
              else if(tab_rem[indeks] == '6')
                jQuery("#6").load('panel_zwrot-wymiana.php'); 
              else if(tab_rem[indeks] == '7')
                jQuery("#7").load('panel_sposob-dostawy.php'); 
              else if(tab_rem[indeks] == '8')
                jQuery("#8").load('panel_serwis.php'); 
//               else if(tab_rem[indeks] == '9')
//                 jQuery("#9").load('panel_serwis.php'); 
//               else if(tab_rem[indeks] == '10')
//                 jQuery("#11").load('panel_pl.php'); 
//                 jQuery("#10").load('panel_regulamin.php'); 
//               else if(tab_rem[indeks] == '11')

        }
        }
        else {

//                 jQuery("#1").load('panel_schowek.php');
                jQuery("#2").load('panel_przypominacz.php');
                jQuery("#3").load('panel_dzisiaj.php');
                jQuery("#4").load('panel_pogoda.php');
                jQuery("#5").load('panel_kalendarz.php');
                jQuery("#6").load('panel_zwrot-wymiana.php');
                jQuery("#7").load('panel_sposob-dostawy.php');
                jQuery("#8").load('panel_serwis.php');
//                 jQuery("#9").load('panel_konto.php');
//                 jQuery("#10").load('panel_regulamin.php');
//                 jQuery("#10").load('panel_pl.php');
        }


// 			document.getElementById("cat_desc").style.display = "block";
                jQuery("#strz_1").click(function() {
// alert(document.getElementById("cat_desc").style.overflow);
		    if(document.getElementById("cat_desc").style.display == "none") {
                       // jQuery("#cat_desc").show('slow');
			document.getElementById("cat_desc").style.height = 'auto';
			document.getElementById("cat_desc").style.overflow = "visible";
			document.getElementById("cat_desc").style.display = "block";
			document.getElementById("strz_1").src = "./images/kamai sklep/zwin.png";
		    }
		    else if(document.getElementById("cat_desc").style.display == "block" && document.getElementById("cat_desc").style.overflow == "hidden") {
                       // jQuery("#cat_desc").hide('slow');
			document.getElementById("cat_desc").style.height = '100%';
			document.getElementById("cat_desc").style.overflow = "visible";
			document.getElementById("cat_desc").style.display = "block";
			document.getElementById("strz_1").src = "./images/kamai sklep/zwin.png";
		    }
		    else if(document.getElementById("cat_desc").style.display == "block" && document.getElementById("cat_desc").style.overflow == "visible") {
                       // jQuery("#cat_desc").hide('slow');
			document.getElementById("cat_desc").style.overflow = "hidden";
			document.getElementById("cat_desc").style.height = 'auto';
			document.getElementById("cat_desc").style.display = "none";
			document.getElementById("strz_1").src = "./images/kamai sklep/strzalki_black_down.png";
		    }
                });


        });



function getActuallPositions() {
        objParent = document.getElementById("thelist2");
        arrChildren = objParent.childNodes;
        objChild = '';
        // loop thru all child nodes
                for(i = 0; i < arrChildren.length; i++)
                {
                     if(i != (arrChildren.length-1))
                        objChild += arrChildren[i].id+',';
                     else
                        objChild += arrChildren[i].id;
                        // do something with node here
                }
/*                                jQuery.ajax ({
                                url: "jquery_functions.php",
                                data: "action=add_positions&values="+objChild,
                                dataType: "html",
                                type: "get",
                                success: function(ww) {
                       // alert(ww);
                                }
                                });  */  
        //tworzenie ciastka z ustawieniami panela
        SetCookie('remRP',objChild,30);

    
}

function open_window(page) {


        var w = screen.width/3;
        var h = screen.height/4;

        window.open("pan_"+page+".php", 'Opis','menubar=no, toolbar=no, location=yes, scrollbars=yes, resizable=no, status=yes, width='+w+', height='+h+'');

}


function changePhoto(image,nr) {
/*        big_image = document.getElementById("big_image");
        big_image_cp = big_image;
        small_image = document.getElementById("small_image")*/;
        
for(i=0;i<=nr;i++) {
    if(image == i)
        document.getElementById("photo_"+i).style.display = 'block';
    else
        document.getElementById("photo_"+i).style.display = 'none';
}

//         big_image.src="images/"+image;
//         big_image.width = 300;
// 
//         document.getElementById("my_highslide").href = "images/"+image;

}


function closeRP() {
        jQuery("#rpanel_schowek").hide();
        jQuery("#rpanel_top").hide();
        jQuery("#rpanel_content").hide();
        jQuery("#rpanel_open").toggle('slow');
        SetCookie('RPshow',0,30);
}

function openRP() {
        jQuery("#rpanel_schowek").show();
        jQuery("#rpanel_top").show();
        jQuery("#rpanel_content").show();
        jQuery("#rpanel_open").hide();
        SetCookie('RPshow',1,30);
}





        function formsend(formId) {
            document.getElementById(formId).submit();
        }

        function switchDiv(div_id) {

            var style_sheet = document.getElementById(div_id);
            var style_sheet_img = document.getElementById("st");
            if(style_sheet.style.display == "none") {
                style_sheet.style.display = "block";
                style_sheet_img.src = "./images/kamai sklep/strzalki_black_down.png";
            }
            else {
                style_sheet.style.display = "none";
                style_sheet_img.src = "./images/kamai sklep/strzalki_black.png";
            }
//             var style_sheet = getStyleObject(div_id);
//
//             if (style_sheet) {
//
//                 hideAll();
//                 changeObjectVisibility(div_id, "block");
//
//             }
//             else {
//                 alert("Twoja przegladarka nie obsluguje DHTML!");
//             }
        }

        function getStyleObject(objectId) {
            if (document.getElementById && document.getElementById(objectId)) {
                return document.getElementById(objectId).style;
            }
            else if (document.all && document.all(objectId)) {
                return document.all(objectId).style;
            }
            else if (document.layers && document.layers[objectId]) {
                return document.layers[objectId];
            }
            else {
                return false;
            }
        }

        function changeObjectVisibility(objectId, newVisibility) {
            var styleObject = getStyleObject(objectId);

            if (styleObject) {
                styleObject.display = newVisibility;
                return true;
            }
            else {
                return false;
            }
        }

        function hideAll()
        {
            changeObjectVisibility("ez","hidden");
            changeObjectVisibility("full","hidden");
        }


function fromWishlist2Shop(products_id) {
  var qty = document.getElementById("wishlist_quantity"+products_id+"").value;
//alert(qty)

    location.href = "./index.php?action=buy_now_wishlist&products_id="+products_id+"&wishlist_quantity="+qty;
}


	function closeDiv(name){
	    document.getElementById(name).style.display = "none";
	}


function openUnderWin(elem) {
  jQuery("#"+elem+"").show("clip", { direction: 'vertical' }, 500);
}


function closeUnderWin(elem) {
  jQuery("#"+elem+"").hide("scale", { direction: 'vertical' }, 500);
}

function openChatWin() {
        window.open("./chat/index.php", 'Chat','menubar=no, toolbar=no, location=no, scrollbars=no, resizable=yes, status=yes, width=500, height=535');
}


//===================================

function getPositionInOut(id) {

// document.getElementById('frame_cat_'+id).onmouseout = testOut;
document.getElementById('frame_cat_'+id).onmouseover = testIn;
document.getElementById('frame_cat_'+id).onmouseover = overlib_start;
document.body.onmouseover = testIn;




}


  function testIn(e) {
	if (!e) e = window.event;

//OUT
var byl_element;
  if (e.relatedTarget) byl_element = e.relatedTarget;
  else if (e.fromElement) byl_element = e.fromElement;

var jest_element;
  if (e.target) jest_element = e.target;
  else if (e.srcElement) jest_element = e.srcElement;

//  alert('in: '+element.id+' out: '+element2.id);

//=== id elementy ommouseover
  if(jest_element) {
   if(jest_element.id) {
    if(jest_element.id && jest_element.id != '') {
	var id_jest = jest_element.id;
	tab_jest = new Array();
	re = /^[a-zA-Z_]+([0-9]{2,3})$/;
	tab_jest = re.exec(id_jest);
	if(tab_jest != null && tab_jest[1] != '' && tab_jest.length != 0 && tab_jest[1] != '60' && tab_jest[1] != '82')
	  id_jest = tab_jest[1];
    }
   }
  }


//=== id elementy ommouseout
  if(byl_element) {
    if(byl_element.id && byl_element.id != '') {
	var id_byl = byl_element.id;
	tab_byl = new Array();
	re = /^[a-zA-Z_]+([0-9]{2,3})$/;
	tab_byl = re.exec(id_byl);
	if(tab_byl != null && tab_byl[1] != '' && tab_byl.length != 0 && tab_byl[1] != '60' && tab_byl[1] != '82')
	  id_byl = tab_byl[1];
	else if(tab_byl != null && tab_byl[0] != '' && tab_byl.length != 0 && tab_byl[0] != '60' && tab_byl[0] != '82')
	  id_byl = tab_byl[0];
	else
	  id_byl = '';
    }
  }


//jezeli przechodze miedzy elementami różnych kategorii
    if(id_jest && id_jest != '' && id_byl && id_byl != '' && id_byl != 'main_def_baner') {
	  if(id_jest != id_byl) {
	   if(document.getElementById('main_baner_'+id_byl))
		document.getElementById('main_baner_'+id_byl).style.display = "none";
	   if(document.getElementById('main_baner_'+id_jest))
		document.getElementById('main_baner_'+id_jest).style.display = "block";
		jQuery("#strzalka_"+id_jest+"").attr("src","./images/kamai sklep/strzalki_red_right.png");
		jQuery("#link_"+id_jest+"").css("color","red");
		jQuery("#strzalka_"+id_byl+"").attr("src","./images/kamai sklep/strzalki_grey_right.png");
		jQuery("#link_"+id_byl+"").css("color","#666666");
	   if(document.getElementById('main_baner_'+id_jest))
		document.getElementById('frame_cat_'+id_jest).onmouseover = overlib_start;

	  }
	  else if(id_jest == id_byl) {
	    if((byl_element.id != 'main_bimage_'+id_byl && byl_element.id != 'link_'+id_byl && byl_element.id != 'frame_cat_'+id_byl && byl_element.id != 'strzalka_'+id_byl && byl_element.id != 'free_'+id_byl) || (byl_element.id == 'frame_cat_'+id_byl+'' && jest_element.id == 'main_bimage_'+id_byl+''))
		nd();
	  }
    }

//jezeli przechodze z kategorii poza obszar 
    else if(!id_jest && id_byl && id_byl != '') {
	  if(document.getElementById('main_baner_'+id_byl))
		document.getElementById('main_baner_'+id_byl).style.display = "none";
		jQuery("#strzalka_"+id_byl+"").attr("src","./images/kamai sklep/strzalki_grey_right.png");
		jQuery("#link_"+id_byl+"").css("color","#666666");
		nd();

    }

//jezeli przechodze na obszar kategorii
    else if(id_jest && id_jest != '' && !id_byl) {
	  if(document.getElementById('main_baner_'+id_jest))
		document.getElementById('main_baner_'+id_jest).style.display = "block";
		jQuery("#strzalka_"+id_jest+"").attr("src","./images/kamai sklep/strzalki_red_right.png");
		jQuery("#link_"+id_jest+"").css("color","red");
	  if(document.getElementById('main_baner_'+id_jest))
		document.getElementById('frame_cat_'+id_jest).onmouseover = overlib_start;
    }


  }


  function overlib_start() {
    return overlib("kliknij aby wejść do tej kategorii",  WRAP,BASE,'2',OFFSETX,'-1',OFFSETY,'20',TEXTPADDING,'4',TEXTSIZE,'10px', SHADOW, SHADOWCOLOR,'#7f7f7f', BORDER, '0' );
  }


  function overlib_start2() {
    return overlib("kliknij aby rozwinąć",  WRAP,BASE,'2',OFFSETX,'-1',OFFSETY,'20',TEXTPADDING,'4',TEXTSIZE,'10px', SHADOW, SHADOWCOLOR,'#7f7f7f', BORDER, '0' );
  }

  function showStateList(cuntry_id, woj, j) {
	jQuery.ajax ({
           url: "jquery_functions.php",
           data: "action=state_list&cuntry_id="+cuntry_id+"&woj="+woj+"&j="+j,
           dataType: "html",
           type: "get",
           success: function(ww) {
	      document.getElementById('state'+j).innerHTML = ww;
	   }
        });    
  }





  function rdiv_open(name_div) {


	    jQuery.ajax ({
	      url: "panelright_div.php",
	      data: "action=state_list&name="+name_div,
	      dataType: "html",
	      type: "get",
	      success: function(ww) {
		  jQuery("#serwis_div").html(ww);
		  jQuery("#windek_"+name_div).dialog({ autoOpen: false, bgiframe: true, modal: true, resizable: true, width: 'auto', height: 'auto', position: 'top' });
		  jQuery("#windek_"+name_div).dialog('open');
	      }
	    }); 


  }



   var isDialogOpen = false;

   jQuery(document).ready( function() {

      jQuery("#dialog_log").dialog({ autoOpen: false, bgiframe: true, modal: true, resizable: false, width: 450 });

      jQuery("#zobacz_log").click( function() {     // assign the link the click

             jQuery("#dialog_log").dialog('open');

      } );




  
/*
      jQuery("input:text[name=postcode_],input:text[name=_postcode]").keyup( function() {
	  var postcode0 = document.getElementById("postcode_").value;
	  var postcode1 = document.getElementById("_postcode").value;

// 	  if (this.timer) clearTimeout(this.timer); 
	  if((postcode0.length + postcode1.length) == 5) {


// 	    this.timer = setTimeout(function () {
	      jQuery.ajax({
		url: 'jquery_functions.php',
		data: 'action=getPostcode&code0='+postcode0+'&code1='+postcode1,
		type: 'post',
		dataType: 'json',
		success: function(j) {
		  jQuery("input:text[name=city]").val(j.city);
		  showStateList('170', j.state);
		}
	      });
// 	      }, 200);


	  }
      });*/




   } );

(function($){
 $.fn.itemPopup = function(){
 function showPopup(popup){
 var link = popup.find('.imgContainer');
 var img = $('<img class="popupThumb" />');
 var trigger = popup.parents('tr.dusa').find('.popupTrigger');
 var t = trigger.position().top;
 if ( link.html() == '' ){
 link.append(img.attr('src', link.attr('rel'))).removeAttr('rel');
 }

 var p = popup.height() + 10; 
 var s = $(window).scrollTop();
 var w = $(window).height();
 var top_pos = (t + p) > (s + w) ? (s + w - p) : t - 10;
//   alert("t="+t+"p="+p+"s="+s+"w="+w);
 popup.css({top: top_pos, left: trigger.position().left + 90});
 popup.find('.pointerArrow').css({top: t + (popup.hasClass('withoutThumb') ? 0 : 10) - top_pos});

 popup.fadeIn(200);
 }
 return this.each(function(){
 var popup = $(this);
 var timer;
 var trigger = $(this).parents('tr.dusa').find('.popupTrigger');
 var closer = $(this).parents('tr.dusa').find('.popupClose');

 trigger
 .bind('mouseenter', function(){
 clearTimeout(timer);
 timer = setTimeout(function(){ showPopup(popup); }, 500);
 })
 .bind('mouseleave', function(){
 clearTimeout(timer);
 timer = setTimeout(function(){ popup.fadeOut(200); }, 500);
 });

 closer.click(function() {
  popup.fadeOut(200);
  });


 popup
 .bind('mouseenter', function(){
 clearTimeout(timer);
 })
 .bind('mouseleave', function(){
 clearTimeout(timer);
 timer = setTimeout(function(){ popup.fadeOut(200); }, 500);
 });
 });
 };

 $(function(){
 $('.itemPopup').itemPopup();
 $('.itemListing tbody tr.dusa').hover(function(){ $(this).addClass('hover'); }, function(){ $(this).removeClass('hover'); });
 });
})(jQuery);




function dialogReminder(products_id) {
		      jQuery.ajax ({
			url: "jquery_functions.php",
			data: "action=form_reminder&products_id="+products_id,
			dataType: "html",
			type: "get",
			success: function(ret) {
			jQuery("#dialog_todo").html(ret);
			if(jQuery.browser.msie == false)
			  jQuery("#dialog_reminder").dialog({ autoOpen: true, bgiframe: true, modal: true, resizable: false, width: 'auto', dialogClass: "rm",close: function(ev, ui) { jQuery(this).remove(); } });
			else
			  jQuery("#dialog_reminder").dialog({ autoOpen: true, bgiframe: true, modal: true, resizable: false, width: '450px', dialogClass: "rm",close: function(ev, ui) { jQuery(this).remove(); } });

			jQuery("#dialog_reminder").createShadow();

			}
		      }); 
}


function remSubmit(products_id) {

var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
    if(jQuery('#rem_email').val() == 'wpisz adres e-mail...' || jQuery('#rem_email').val() == '') {
      alert("Wpisz adres e-mail.");
      return false;
    } else if(!regex.test(jQuery('#rem_email').val())) {
      alert("Podany e-mail wygląda na niepoprawny.");
      return false;
    } else {
      var em = jQuery('#rem_email').val();
		      jQuery.ajax ({
			url: "jquery_functions.php",
			data: "action=submit_reminder&products_id="+products_id+"&email="+em,
			dataType: "html",
			type: "get",
			success: function(ret) {
			  jQuery("#dialog_todo").html(ret);
			  jQuery("#dialog_reminder").remove();
			  jQuery("#dialoginfo_reminder").dialog({ autoOpen: true, bgiframe: true, modal: true, resizable: false, width: '300px',close: function(ev, ui) { jQuery(this).remove(); } });  
			}
		      });   

    }
}


function addMoreEmail(ei) {

 	       if(ei == 1 && jQuery("form[name='form_koszyk2email']").find(":input").size() < 2)
		jQuery("#k2e_email"+ei).after('<br/><input class="login_grej" type="text" name="k2e_email[]" id="k2e_email2"  style="width: 210px"/>');



}



function hygt() {

var all_in_one = '';
var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;

		      jQuery("form[name='form_koszyk2email']").find(":input").each(function() {
			if(!regex.test(jQuery(this).val())) {
			  alert("Podany e-mail wygląda na niepoprawny.");
			  jQuery(this).clearQueue();
			} else {
			    all_in_one += jQuery(this).val()+','; 

			}
		      });

		      jQuery.ajax ({
			url: "jquery_functions.php",
			data: "action=submit_koszyk2email&inputki="+all_in_one,
			dataType: "html",
			type: "get",
			success: function(ret) {
			jQuery("#dialog_todo").html(ret);
			    jQuery("form[name='form_koszyk2email']").find(':input').each(function() {
				jQuery(this).remove();
			    });
			jQuery("#hereAdd").after('<input class="login_grej" type="text" name="k2e_email[]" id="k2e_email1" onClick="addMoreEmail(1)"  style="width: 210px"/>');
			jQuery("#dialog_k2e").remove();
			jQuery("#dialoginfo_k2e").dialog({ 
							  autoOpen: true, 
							  bgiframe: true, 
							  modal: true, 
							  resizable: false, 
							  width: '300px',
							  close: function(ev, ui) { jQuery(this).remove(); }
							});
			    
			}
		      }); 
}



function makeSome(item) {
              jQuery("#dialog_new").dialog('close');

	      jQuery("#dialog_todo").load('registerStart.php', function() { 

		if(jQuery("#register")) {
		    jQuery("#register").dialog({ autoOpen: true, bgiframe: true, modal: true, resizable: false, width: 600, close: function(ev, ui) { jQuery(this).remove(); }});
// 		    jQuery("#register").dialog('open');
		}

	      });

}


function dialog_passwordForgotten() {

			    jQuery("#dialog_new").remove();
			    jQuery.ajax ({
			      url: "jquery_functions.php",
			      data: "action=dialog_passwordForgotten",
			      dataType: "html",
			      type: "get",
			      success: function(ret) {
				  jQuery("#dialog_todo").html(ret);
				  jQuery("#dialog_pass").dialog({ autoOpen: true, bgiframe: true, modal: true, resizable: false, width: 500, close: function(ev, ui) { jQuery(this).remove(); } });
			      }
			    }); 
}

function dialog_passwordForgottenSend(email) {

			    jQuery("#dialog_pass").remove();
			    jQuery.ajax ({
			      url: "jquery_functions.php",
			      data: "action=dialog_passwordForgottenSend&email="+email,
			      dataType: "html",
			      type: "get",
			      success: function(ret) {
				  alert(ret);
			      }
			    }); 
}


