function preparePhoto(id){
	$('offerPhotoID').src = photos[actual-1];
	max = photos.length;
	$('currentPhoto').innerHTML = actual;
	$('allPhotos').innerHTML = max;
	return false;
}


function nextPhoto(id){
	actual--;	
	if(actual<1) actual = max;
	return preparePhoto(id);
}

function prevPhoto(id){
	actual++;
	if(actual>max) actual = 1;
	return preparePhoto(id);
}

function isEnterKey(e)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return true;
     else
          return false;
}

var amountOuter = 0;
function bonsAmount(){
	var ids = new Array();
	var amount = 0;	
	
	$(':input.bonID').each(
			function(arrKey, arrValue){
				id = arrValue.value;
				if($('#bon_price\\['+id+'\\]') && $('#bon_count\\['+id+'\\]')){
					if( isNaN( parseInt( $('#bon_count\\['+id+'\\]').val() ) ) )
				 		$('#bon_count\\['+id+'\\]').val('0');
				 	else
				 		$('#bon_count\\['+id+'\\]').val(parseInt( $('#bon_count\\['+id+'\\]').val()));
					amount 
						+= 
						parseInt( $('#bon_price\\['+id+'\\]').val() ) 
						*  
						( parseInt( $('#bon_count\\['+id+'\\]').val() ) ? parseInt( $('#bon_count\\['+id+'\\]').val() ): 0 );
				}
			});
	amountOuter = amount;
	if(amount != Number.NaN)
		$('#spanPaymentAmout').text(amount+" zł");
	else
		$('#spanPaymentAmout').text('Błąd');
}

function selectCollectionWay(element){
	
	if(element.value == 'post')
		$('#blockCollectionAddress').css('display','block');
	else
		$('#blockCollectionAddress').css('display','none');
}

function selectInvoiceVat(element){
	
	if(element.value == 'yes')
		$('blockInvoiceAddress').css('display','block');
	else
		$('blockInvoiceAddress').css('display','none');
}

function validateFormBons(msg){
		var errors = new Array();
		
		if(!$('#chbxReservationAccept').is(':checked')) errors.push ( 'chbxReservationAccept');
		
		if(!$('#rbtnPaymentCash').is(':checked') && !$('#rbtnPaymentAccount').is(':checked'))  {errors.push ( 'rbtnPaymentCash');errors.push ( 'rbtnPaymentAccount');}
		
		if(!$('#rbtnCollectionPerson').is(':checked') && !$('#rbtnCollectionPost').is(':checked'))  {errors.push ( 'rbtnCollectionPerson');errors.push ( 'rbtnCollectionPost');}
		
		if(!$('#rbtnInvoiceYes').is(':checked') && !$('#rbtnInvoiceNo').is(':checked')) { errors.push ( 'rbtnInvoiceYes');  errors.push ( 'rbtnInvoiceNo');}
	

		if($('#collection_first_name').val().length == 0)  errors.push ('collection_first_name');
		if($('#collection_last_name').val().length == 0)  errors.push ('collection_last_name');
		
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;   			   		
		if(!reg.test($('#collection_email').val())) errors.push ('collection_email');
   	
		
		if($('#blockCollectionAddress').css('display')=='block'){
			if($('#collection_street').val().length == 0)  errors.push ('collection_street');
			if($('#collection_number').val().length == 0)  errors.push ('collection_number');
			if($('#collection_postcode').val().length == 0)  errors.push ('collection_postcode');
			if($('#collection_city').val().length == 0)  errors.push ('collection_city');
		}
	
		if($('#blockInvoiceAddress').css('display') == 'block'){
			if($('#vat_company').val().length == 0)  errors.push ('vat_company');
			if($('#vat_street').val().length == 0)  errors.push ('vat_street');
			if($('#vat_numer').val().length == 0)  errors.push ('vat_numer');
			if($('#vat_postcode').val().length == 0)  errors.push ('vat_postcode');
			if($('#vat_city').val().length == 0)  errors.push ('vat_city');
			//if($F('vat_nip').length == 0)  errors.push ('vat_nip');
		}
		if(amountOuter == 0 )  errors.push ('spanPaymentAmout');
		
		$('span.spanErrorBon').remove();

		for(var k = 0; k < errors.length; k++){
			$('#'+errors[k]).after('<span class="spanErrorBon">*</span>');
		}
		
		if(errors.length > 0){
			alert(msg);				
			return false;			
		}else{
		 	$('#bonsReservationForm').submit();
			return true;
		}
}
