
var priceWithVat=0;
var discount=0;
    
    function showOrder(form){
    	//alert(form.billing.checked)
    	//alert(document.getElementById('billingDiv').style.display)
    	if(document.getElementById('cb_billing').checked) {
    		//alert('billind true')
    		document.getElementById('billingDiv').style.display='block';
    		//form.billing.checked=true;
    	}
    	else document.getElementById('billingDiv').style.display='none';
    	
    	if(document.getElementById('cb_delivery').checked) {
    		//alert('delivery true')
    		document.getElementById('deliveryDiv').style.display='block';
    		//form.delivery.checked=true;
    	}
    	else document.getElementById('deliveryDiv').style.display='none';
    }
    
    function copyToBilling(form){
    	form.bil_first_name.value=form.first_name.value;
    	form.bil_last_name.value=form.last_name.value;
    	form.bil_address.value=form.address.value;
    	form.bil_postcode.value=form.postcode.value;
    	form.bil_city.value=form.city.value;
    	//alert(document.getElementById('billingDiv').style.display)
    	
    }
    
   function setShippingCost(cost){
    	var numDiscount=discount*1;
    	var numPrice=priceWithVat*1;
    	if(numPrice>numDiscount) numPrice=numPrice-numDiscount;
    	else numPrice=0;
    	var finalPrice =cost*1+numPrice;
    	finalPrice= finalPrice+'';
    	cost=cost+'';
    		document.getElementById('shipping_cost').innerHTML=cost.replace('.',',');
    		document.getElementById('shipping_price').value=cost;
    		document.getElementById('final_price').innerHTML=finalPrice.replace('.',',');
    }

function changeImage(imgSrc,i, title){
	var temp=document.getElementById('maxImg0').href;
	document.getElementById('imageName').src='images/'+_id+'/'+imgSrc;
	document.getElementById('maxImg0').href='images/'+_id+'/maxi/'+imgSrc;	
	document.getElementById('maxImg'+i).href=temp;
	document.getElementById('imageName').alt=imgSrc;
	document.getElementById('imageName').title=title;
	document.getElementById('imageName').alt=title;
}



function goToUrl(form){
	var target=form.strona.selectedIndex
	parent.location=(form.strona.options[target].value);
}

function showOption(id){
	for(i=1;i<=4;i++){
		if(i!=id) {
			document.getElementById('option_'+i).style.display='none';
			document.getElementById('menu_'+i).className ='off';
		}
		else {
			document.getElementById('option_'+i).style.display='block';
			document.getElementById('menu_'+i).className ='on';
		}
	}    	
}

$(document).ready(function(){ 
	 PEPS.rollover.init();
	 
	//$("#basketItemsWrap li:first").hide();
	active = 5;
	$("#rating img").click(function() {
		temp = (this.id).split("_")
		id=temp[1];
		active = id;
	});
	
	$("#rating img").mouseover(function() {
		temp = (this.id).split("_");
		id=temp[1];		
		event.drain();
      	event.fill(id);
	});
	$("#rating img").mouseout(function() {
		event.drain();
      	event.reset(active);
	});
	var event = {
		fill: function(el){ // fill to the current mouse position.
			for(i=1;i<=el;i++) document.getElementById('star_'+i).src='img/starOn.gif';
		},
		drain: function() { // drain all the stars.
			for(i=1;i<=5;i++) document.getElementById('star_'+i).src='img/starOff.gif';
		},
		reset: function(){ // Reset the stars to the default index.
			for(i=1;i<=active;i++) document.getElementById('star_'+i).src='img/starOn.gif';
		}
	};
	
	$("#option_3 .submit").click(function() {
		$(".error").hide();
		var hasError= false;
		var nameVal = $("#name").val();
		if(nameVal == '') {
			$("#name").after('<p class="error">Wpisz nazwę.</p>');
			hasError = true;
		}
		var commentVal = $("#comment").val();
		if(commentVal == '') {
			$("#comment").after('<p class="error">Wpisz treść komentarza.</p>');
			hasError = true;
		}
		if(hasError==false) {
		
			var idProduct = this.id;		
			var imageIDValSplitter 	= (this.id).split("_");
			var idProduct = imageIDValSplitter[1];
		
			$("#notificationsLoader").html('<img src="img/loader.gif">');
		
			$.ajax({  
			type: "POST",  
			url: "modules/product/ajax.opinion.php",  
			data: { id: idProduct, name: nameVal, rate: active, comment: commentVal, action: "addOpinion"},  
			success: function(theResponse) {
					$("#opinionList div:last").after(theResponse);
					$("#opinionList div:last").hide();
					$("#opinionList div:last").show("slow");  
					$("#notificationsLoader").empty();
					$("#name").val('');
					$("#comment").val('');
					//editbox_init();
				//}
			}  
			}); 
		}
	});
	
});

PEPS = {};

PEPS.rollover =
{
   init: function()
   {
      this.preload();
     
      $("#menuTop .ro").hover(
         function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); },
         function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
      );
   },

   preload: function()
   {
      $(window).bind('load', function() {
         $('#menuTop .ro').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   
   newimage: function( src )
   {
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + 'on' + src.match(/(\.[a-z]+)$/)[0];
   },

   oldimage: function( src )
   {
      return src.replace(/on\./, '.');
   }
};

