function intro_page_close()
  {
  //createCookie('intro_page','hide',1);
  document.getElementById('intro_page').style.display='none';
  }
  
////////////////////////////////////////////////////////////////////////////////////////////////////  
function opennewsletter(id,cena,id_prod){
 
emailwindow=dhtmlmodal.open('EmailBox', 'iframe', '/Negocjuj-cene.html?neg=' + id + '&cena=' + cena+ '&id_prod=' + id_prod, 'Negocjuj cenę', 'width=400px,height=450px,center=1,resize=0,scrolling=1')

emailwindow.onclose=function(){ //Define custom code to run when window is closed
	var theform=this.contentDoc.forms[0] //Access first form inside iframe just for your reference
	var theemail=this.contentDoc.getElementById("emailfield") //Access form field with id="emailfield" inside iframe
	if (theemail.value.indexOf("@")==-1){ //crude check for invalid email
		alert("Please enter a valid email address")
		return false //cancel closing of modal window
	}
	else{ //else if this is a valid email
		document.getElementById("youremail").innerHTML=theemail.value //Assign the email to a span on the page
		return true //allow closing of window
	}
}
} //End "opennewsletter" function

//////////////////////////////////////////////////////////////////////////////////////////////////////////
function opennewsletter2(id,cena,id_prod){
 
emailwindow=dhtmlmodal.open('EmailBox', 'iframe', '/Wypozycz.html?wyp=' + id + '&cena=' + cena+ '&id_prod=' + id_prod, 'Wypożycz', 'width=420px,height=450px,center=1,resize=0,scrolling=1')

emailwindow.onclose=function(){ //Define custom code to run when window is closed
	var theform=this.contentDoc.forms[0] //Access first form inside iframe just for your reference
	var theemail=this.contentDoc.getElementById("emailfield") //Access form field with id="emailfield" inside iframe
	if (theemail.value.indexOf("@")==-1){ //crude check for invalid email
		alert("Please enter a valid email address")
		return false //cancel closing of modal window
	}
	else{ //else if this is a valid email
		document.getElementById("youremail").innerHTML=theemail.value //Assign the email to a span on the page
		return true //allow closing of window
	}
}
}
    



function main_flash()
  {
  document.write ('<div style="padding-left:0px;margin-top:0px;z-index:1;" align="center">');
	if (AC_FL_RunContent == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', '1009',
			'height', '42',
			'src', 'universallPasek',
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',	
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'transparent',
			'devicefont', 'false',
			'id', 'universallPasek',
			'bgcolor', 'transparent',
			'name', 'universallPasek',
			'menu', 'true',
			'allowFullScreen', 'false',
			'allowScriptAccess','sameDomain',
			'movie', 'universallPasek',
			'salign', 'center',
			'flashvars', 'fw=3&pozX=910&'  
			); // end AC code
	
				//dostępne tryby modułu
				//1) slideShowMode
				//2) mottoMode
				//3) defaultNewsMode
				//4) manualNewsMode
				//5) fullManualMode
				//6) promoMode	
	}
	document.write ('</div>');
  } 
  
function main_flash2()
  {
  document.write ('<div style="padding-left:0px;margin-top:0px;z-index:1;" align="center">');
	if (AC_FL_RunContent == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', '1009',
			'height', '42',
			'src', 'universallPasek',
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',	
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'transparent',
			'devicefont', 'false',
			'id', 'universallPasek',
			'bgcolor', 'transparent',
			'name', 'universallPasek',
			'menu', 'true',
			'allowFullScreen', 'false',
			'allowScriptAccess','sameDomain',
			'movie', 'universallPasek',
			'salign', 'center',
			'flashvars', 'fw=3&pozX=910&'  
			); // end AC code
	
				//dostępne tryby modułu
				//1) slideShowMode
				//2) mottoMode
				//3) defaultNewsMode
				//4) manualNewsMode
				//5) fullManualMode
				//6) promoMode	
	}
	document.write ('</div>');
  }   

function subproductadd(id){
  var quantity = $('quantity_'+id).get('value').toInt();
  window.location.href='/Order/Basket.html?add_product['+id+']='+quantity+'&return='+window.location.href;
  }
  
function subproductadd2(id){
  var quantity = $('quantity_'+id).get('value').toInt();
  alert("Dodano produkt do koszyka!");
  window.location.href='/Order/Basket.html?add_product['+id+']='+quantity+'&return='+window.location.href;
  }  

function $save(id){
  if ( $(id) ) $(id).submit();
  return false;
  }	

/*--------------------------------------------------------------------------------------------------------------------------------*/

function menu (obj){
  var li = $(obj).getParent();
  var ul = li.getElement('ul');
  ul.toggleClass('hide');  
  if ( li.hasClass('active' ) )
    li.removeClass('active')
  else if ( !ul.hasClass('hide') ) 
    li.addClass('active');
  }
  
/*--------------------------------------------------------------------------------------------------------------------------------*/
  
function swich_order_row ( obj ){
  var obj = $(obj);
  var className = obj.get('name') ;
  if( className ){
    if ( obj.get('value') ){
      $$('.'+className).removeClass('hide');
      }      
    else{
      $$('.'+className).addClass('hide');
      }      
    }
  }

/*--------------------------------------------------------------------------------------------------------------------------------*/
  
function clear_input( input ){
  var input = $(input);
  if ( input ){
    input.addEvent('focus',function(){ 
      if ( input.get('title') == input.get('value') ) { 
        input.set('value','');
        if ( input.get('name') == 'password' ){
          input.set('type','password');
          }
        }
      });
    input.addEvent('blur',function(){ 
      if ( input.get('value') == '' ){
        input.set('value', input.get('title') );
        if ( input.get('name') == 'password' ){
          input.set('type','text');
          }        
        }  
      });
    }
  }

/*--------------------------------------------------------------------------------------------------------------------------------*/  

function add_comment(sub){
  var comment_form = $('comment_form');
  new Element('input',{'name':'sub','value':sub,'type':'hidden'}).inject(comment_form);
  comment_form.submit();  
  }

/*--------------------------------------------------------------------------------------------------------------------------------*/

function show_comment_form(obj){
  $('comment_form').removeClass('hide');
  obj.setStyle('display','none'); 
  }

/*--------------------------------------------------------------------------------------------------------------------------------*/

function add_to_basket(prod_basket){
  var prod_basket = $(prod_basket);
  if ( prod_basket ){
    var valid = true;
    var choose_options = prod_basket.getElements('.choose_options');
    if ( choose_options ){
      choose_options.each(function(el){
        if ( el.get('value') == '' && valid ){
          valid = false;
          alert('Wybierz '+el.get('title')+'.' );      
          el.focus();          
          }
        });
      }
    if ( valid ){
      prod_basket.submit();
      }      
    }  
  }
  
function add_to_basket_sub(subproduct_form){
  var subproduct_form = $(subproduct_form);
  if ( subproduct_form ){
    var valid = true;
    var choose_options = subproduct_form.getElements('.choose_options');
    if ( choose_options ){
      choose_options.each(function(el){
        if ( el.get('value') == '' && valid ){
          valid = false;
          alert('Wybierz '+el.get('title')+'.' );      
          el.focus();          
          }
        });
      }
    if ( valid ){
      subproduct_form.submit();
      }      
    }  
  }  

/*--------------------------------------------------------------------------------------------------------------------------------*/

window.addEvent('domready', function() {
  var forms = document.getElements('form');
  if ( forms ){
    forms.addEvent('submit',function(e){
      //new Event(e).stop();
      this.getElements('input').each(function(el){      
        var title = el.get('title');      
        if ( title && title == el.get('value') ){ 
          el.set('value','');
          }
        });
      //this.submit();
      });    
    }
  //clear_input( $('login_field_top') );
  //clear_input( $('password_field_top') );
  //clear_input( $('search_field_top') );
  //$$('ul li:last-child').addClass('last_child');
});

/*--------------------------------------------------------------------------------------------------------------------------------*/
  
window.addEvent('domready', function() {
  var dodajdokoszyka = $('dodajdokoszyka') ;  
  if ( dodajdokoszyka ){
    dodajdokoszyka.addEvent('click',function(e){
      new Event(e).stop();
      $('order_add_form').submit();
      });
    }
});

/*--------------------------------------------------------------------------------------------------------------------------------*/

function order_fields_copy(input,wrap){
  var checked = input.get('checked');
  var prefix = input.get('rel');
  var fields = wrap.getElements('input[name*='+prefix+'_]');
  if ( fields ){
    fields.each(function(el){
      if ( checked ){
        var name = el.get('name').replace(prefix+'_','');        
        if ( name == 'name' ){
          var pattern = wrap.getElement('input[name=company]');
          var value = pattern ? pattern.get('value') : '';
          if ( !value ){
            var pattern = wrap.getElements('input[name=name], input[name=surname]');
            value = pattern[0].get('value')+' '+pattern[1].get('value');
            }
          }
        else {
          var pattern = wrap.getElement('input[name='+ name +']');
          var value = pattern ? pattern.get('value') : '';
          }                 
        if ( pattern ){
          el.set('defaultValue',el.get('value'));
          el.set('value',value);
          }        
        }
      else {
        el.set('value',el.get('defaultValue') || '');
        }
      });
    }
  }

/*--------------------------------------------------------------------------------------------------------------------------------*/

window.addEvent('domready', function() {
  var order_your_acount = $('order-your-acount'); 
  if ( order_your_acount && !$('order-basket') ){
    var field_groups = new Array('send_to','invoice');
    field_groups.each(function(field_prefix){
      var _field_prefix = field_prefix.replace('_to','');
      var has_inputs = order_your_acount.getElements('input[name*='+_field_prefix+'_]');
      var td = order_your_acount.getElement('tr.'+field_prefix+' td.tab1');
      if ( td && has_inputs.length ){
        td.setStyle('textAlign','left');
        var transfer_span = new Element('span').set('html','kopiuj dane&nbsp;');
        var transfer_input = new Element('input',{'type':'checkbox','rel':_field_prefix});
        transfer_input.addEvent('click', order_fields_copy.pass([transfer_input,order_your_acount]) );
        transfer_span.setStyles({'float':'right','fontWeight':'normal'});
        transfer_input.setStyles({'float':'right'});
        transfer_span.inject( td , 'top' );
        transfer_input.inject( td , 'top' );
        }        
      });
    }
});


/*--------------------------------------------------------------------------------------------------------------------------------*/

window.addEvent('domready', function() {
  var product_desc = $('product_desc');
  if ( product_desc ){  
    $$('#product_desc_link , #product_details_link, #product_addons_link').addEvent('click', function(e){
      product_desc.set('class', this.get('rel') );
      Cookie.write('product_desc_class',this.get('rel'),{'path':'/'});
      });
    }
 
 var actual_promotions = $('actual_promotions');
 if ( actual_promotions ){
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  var actual_promotion_slider = actual_promotions.getElement('#actual_promotion_slider');
  var actual_promotions_list = actual_promotions.getElements('.promo_pager a');
  if ( actual_promotions_list ){
    actual_promotions_list.each(function(el,i){
      el.addEvent('click',function(e){
        new Event(e).stop();
        var marginLeft = -(240 * i);
        actual_promotions_list.removeClass('active');
        el.addClass('active');
        Cookie.write('actual_promotion',i,{'path':'/'});
        actual_promotion_slider.morph({'marginLeft':marginLeft+'px'});  
        });
      });    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     var Parms = { actual_promotions_list:actual_promotions_list , actual_promotions_count : actual_promotions_list.lenght };
     var changePromo = function(){  
      var actual_promotion = 0;
      this.actual_promotions_list.each(function(el,i){
        if ( el.hasClass('active') ){
          actual_promotion = i;
          }
        });  
      var index = ( actual_promotions_list[actual_promotion+1] ) ? actual_promotion+1 : 0;  
      actual_promotions_list[index].fireEvent('click',actual_promotions_list[index]);
      actual_promotions_list.removeClass('active');
      actual_promotions_list[index].addClass('active');
      }; 
     changePromo.periodical(6000,Parms);
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    }
  } 
 });



/*--------------------------------------------------------------------------------------------------------------------------------*/


window.addEvent('domready', function() {
   
 var actual_promotions2 = $('actual_promotions2');
 if ( actual_promotions2 ){
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  var actual_promotion_slider2 = actual_promotions2.getElement('#actual_promotion_slider2');
  var actual_promotions_list2 = actual_promotions2.getElements('.promo_pager2 a');
  if ( actual_promotions_list2 ){
    actual_promotions_list2.each(function(el,i){
      el.addEvent('click',function(e){
        new Event(e).stop();
        var marginLeft = -(230 * i);
        actual_promotions_list2.removeClass('active');
        el.addClass('active');
        Cookie.write('actual_promotion2',i,{'path':'/'});
        actual_promotion_slider2.morph({'marginLeft':marginLeft+'px'});  
        });
      });    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     var Parms2 = { actual_promotions_list2:actual_promotions_list2 , actual_promotions_count2 : actual_promotions_list2.lenght };
     var changePromo2 = function(){  
      var actual_promotion2 = 0;
      this.actual_promotions_list2.each(function(el,i){
        if ( el.hasClass('active') ){
          actual_promotion2 = i;
          }
        });  
      var index = ( actual_promotions_list2[actual_promotion2+1] ) ? actual_promotion2+1 : 0;  
      actual_promotions_list2[index].fireEvent('click',actual_promotions_list2[index]);
      actual_promotions_list2.removeClass('active');
      actual_promotions_list2[index].addClass('active');
      }; 
     changePromo2.periodical(4000,Parms2);
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    }
  } 
 });


