function hide_show_element(el_id){
	Effect.toggle(document.getElementById(el_id),'blind',{duration:0.5});
} 

function show_user_gallery(el_id){

	var gallery_element = document.getElementById(el_id);
	if(gallery_element.style.display == 'none'){
		if (current_open_div_id != '' && $(current_open_div_id)){
			hide_show_element(current_open_div_id);
		}
		Effect.toggle(gallery_element,'blind',{duration:0.5});
		current_open_div_id = el_id;
	}
} 

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return [curleft,curtop];
	}
}

function change_position(obj1, obj2){
	var position = findPos(obj1);
	obj2.style.left = (parseInt(position[0])+4)+'px';
	obj2.style.top = (parseInt(position[1])+4)+'px';
	obj2.style.display = '';
}


function selected_active_image(id_, max_, img_path){

	$('selecting_rank').onmouseout = function() {
		var w = 1;
		for(w ; w <= max_ ; w++){
		document.getElementById('star_'+w).style.backgroundImage = 'url('+img_path+'gray_star.png)'
		}
	}

	var i = 1;
	for(i ; i <= id_ ; i++){
		document.getElementById('star_'+i).style.backgroundImage = 'url('+img_path+'pink_star.png)';
	}
	for(i ; i <= max_ ; i++){
		document.getElementById('star_'+i).style.backgroundImage = 'url('+img_path+'gray_star.png)'
	}
}


	function add_new_upload_file(id){
		if(id < 10){
			$('file_'+id).removeAttribute('onchange');
	
			var container = document.getElementById('files_container');
			var next_id = parseInt((id+1));
			
			var tr_el = document.createElement('tr');
			tr_el.setAttribute('id', 'new_tr_'+next_id);
			container.appendChild(tr_el);
	
			var td_el_1 = document.createElement('td');
			td_el_1.setAttribute('id', 'new_td_1_'+next_id);
			td_el_1.setAttribute('class', 'file_counted_style');
			$('new_tr_'+next_id).appendChild(td_el_1);
			
			//nastepny numer pliku
			$('new_td_1_'+next_id).innerHTML=next_id+'.';
	
			var td_el_2 = document.createElement('td');
			td_el_2.setAttribute('id', 'new_td_2_'+next_id);
			td_el_2.setAttribute('class', 'color_pink');
			$('new_tr_'+next_id).appendChild(td_el_2);
	
			var new_created_td = $('new_td_2_'+next_id);
	
			var input_file = document.createElement('input');
			input_file.setAttribute('type', 'file');
			input_file.setAttribute('name', 'data[GalleryFile][]');
			input_file.setAttribute('id', 'file_'+next_id);
			input_file.setAttribute('onchange', 'add_new_upload_file('+next_id+')');
			new_created_td.appendChild(input_file);
		}

	}


	function search_by_type(search_type){
		
		$('SearchType').value = search_type;
		document.search_big_name_form.submit();
	}


	function validate_my_account_form(){
// 		var f_name_ = $('UserFirstName').value;
		var name_ = $('UserName').value;
//   		var provinve_  = $('UserProvinceId').value;
//              var usercity = $('UserCity').value;

		var returned = 0;

		//imie
// 		if(f_name_ == ''){
// 			$('UserFirstNameError').innerHTML="Imię jest wymagane.";
// 			returned = 1;
// 		}else{
// 			$('UserFirstNameError').innerHTML="";
// 		}

		//miasto
// 		if(usercity == ''){
// 			$('UserCityError').innerHTML="Miasto jest wymagane.";
// 			returned = 1;
// 		}else{
// 			$('UserCityError').innerHTML="";
// 		}

		//uzytkownik
		if(name_ == ''){
			$('UserNameError').innerHTML="Nazwa jest wymagana.";
			returned = 1;
		}else{
			$('UserNameError').innerHTML="";
		}

		//wojewodztwo
// 		if(provinve_ == ''){
// 			$('UserProvinceIdError').innerHTML="Województwo jest wymagane.";
// 			returned = 1;
// 		}else{
// 			$('UserProvinceIdError').innerHTML="";
// 		}


		if(returned == 1){
			alert('Proszę wypełnić wszystkie pola oznaczone gwiazdką');
			return false;
		}
	}
// galeria -- edycja

	function get_image_edit(id_){

		if(current_edited_photo == 0){	
				

			current_edited_photo = id_;
	
			var ed_img = document.getElementById('resized_'+id_);
			var styles = ed_img.style;
			styles.position = 'relative';
// // 			styles.paddingTop="10px;"
			styles.width="300px";
			styles.height="290px";
			styles.top = '3px';
			styles.left = '3px';
			styles.zIndex=101;
			styles.border="1px solid #D7046B";
			styles.backgroundColor='white';

			var pad_image = document.getElementById('pad_gale_thumb_'+id_);	
			pad_image.style.width="7%";

			var ed_img_right = document.getElementById('set_def_'+id_);
			var styles_right = ed_img_right.style;
			styles_right.display = 'block';
	
			var main_buttons = document.getElementById('desc_to_hide_'+id_);
			var styles_main_buttons = main_buttons.style;
			styles_main_buttons.display="none";
	
			var edit_ = document.getElementById('opt_'+id_);
			var edit_style = edit_.style;
			edit_style.display="block";

		}else{
			alert('Jestes w trakcie edycji innego zdjęcia.');
		}

	}
	
	function get_image_edit_architect(id_){

		if(current_edited_photo == 0){	
				

			current_edited_photo = id_;
	
			var ed_img = document.getElementById('resized_'+id_);
			var styles = ed_img.style;
			styles.position = 'relative';
// // 			styles.paddingTop="10px;"
			styles.width="410px";
			styles.height="190px";
			styles.top = '3px';
			styles.left = '3px';
			styles.zIndex=101;
			styles.border="1px solid #D7046B";
			styles.backgroundColor='white';

			var pad_image = document.getElementById('pad_gale_thumb_'+id_);	
			pad_image.style.width="7%";

			var ed_img_right = document.getElementById('set_def_'+id_);
			var styles_right = ed_img_right.style;
			styles_right.display = 'block';
	
			var main_buttons = document.getElementById('desc_to_hide_'+id_);
			var styles_main_buttons = main_buttons.style;
			styles_main_buttons.display="none";
	
			var edit_ = document.getElementById('opt_'+id_);
			var edit_style = edit_.style;
			edit_style.display="block";

		}else{
			alert('Jestes w trakcie edycji innego zdjęcia.');
		}

	}


	function cancel_save_img_info(id_){
		hide_gallery_edit_elements(id_);
		var textarea_id = document.getElementById(id_+'TmpDesc');
// 			textarea_id.value='';
		var ed_img = document.getElementById('resized_'+id_);
		ed_img.removeAttribute('style');
		var pad_image = document.getElementById('pad_gale_thumb_'+id_);	
		pad_image.style.width="22%";
	}
	
	function cancel_save_img_info_architect(id_){
		hide_gallery_edit_elements(id_);
		var textarea_id = document.getElementById(id_+'TmpDesc');
// 			textarea_id.value='';
		var ed_img = document.getElementById('resized_'+id_);
		ed_img.removeAttribute('style');
		var pad_image = document.getElementById('pad_gale_thumb_'+id_);	
		pad_image.style.width="40px";
	}


	function hide_gallery_edit_elements(id_){
		current_edited_photo = 0;
		var ed_img = document.getElementById('resized_'+id_);
		var styles = ed_img.style;
// 			styles.paddingTop="0px;"
			styles.position = 'static';
			styles.width="130px";
			styles.height="130px";
			styles.top = '0px';
			styles.left = '0px';
			styles.zIndex=0;
			styles.border=0;
// 			styles.backgroundColor='transparent';

		var ed_img_right = document.getElementById('set_def_'+id_);
			var styles_right = ed_img_right.style;
			styles_right.display = 'none';
		var main_buttons = document.getElementById('desc_to_hide_'+id_);
			var styles_main_buttons = main_buttons.style;
			styles_main_buttons.display="block";
		var edit_ = document.getElementById('opt_'+id_);
			var edit_style = edit_.style;
			edit_style.display="none";
	}

	function save_image_info(id_){
		current_edited_photo = 0;
		var textarea_id = document.getElementById(id_+'TmpDesc');
		var hidden_value = document.getElementById(id_+'Description');
		hidden_value.value = textarea_id.value;
		var html_info = document.getElementById('gal_desc_'+id_);
		html_info.innerHTML = textarea_id.value;
		hide_gallery_edit_elements(id_);

		var pad_image = document.getElementById('pad_gale_thumb_'+id_);	
		pad_image.style.width="22%";

		SubmitForm('category_gallery_thumbs');
		return true;
	}

	function SubmitForm(someId){

		var url = url_photo_album_edit;

		var pars = escape(Sortable.serialize(someId));
		pars += '&'+Form.serializeElements(Form.getElements('photo_main'));
		var target = 'null_container';
		var myAjax = new Ajax.Updater(target, url, {method: 'post', parameters: {rates: pars}, asynchronous: false, onsucces: document.som_forms.submit()});
		return false;
	}

	function gallery_show_bigone(_src, view) {
		var _image = document.getElementById('gallery_big_photo_holder');
		_image.src = _src;
		document.getElementById('gallery_big_photo_holder_div').style.display = 'block';
		document.getElementById('gallery_big_photo_holder_div').style.top = view+'px';
	}

	function validate_form(){

		var input_name = $('UserUsername2');
		var input_username = $('UserName');

		var passw_1 = $('UserFirstPass');
		var passw_2 = $('UserPassword2');
		
		var pass = true;
		
		//name
		if(input_name.value == ''){
			$('username_mess').innerHTML="Musisz podać e-mail";
			pass = false;
		}else{
			$('username_mess').innerHTML="";
		}
		
		
		//password - rozne
		if(passw_1.value == passw_2.value){
			if( parseInt(passw_1.value.length) == 0){
				$('password_mess').innerHTML="Puste hasło";
				pass = false;
			}else{
				$('password_mess').innerHTML="";
			}
		}else{
			$('password_mess').innerHTML="Hasła są różne";
			pass = false;
		}
		
		if (input_username.value == ''){
			alert('Wprowadź nazwę użytkownika');
			input_username.focus();
			return false;
		}
		
		//email-username
		reg = /^[a-zA-Z0-9\.ąćęłńóśżźĄĆĘŁŃÓŚŻŹ]{1,30}@[a-zA-Z0-9\.ąćęłńóśżźĄĆĘŁŃÓŚŻŹ]+(\.[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ]+)+$/;
		wyn = input_name.value.match(reg);
		if (wyn == null) {
			$('username_mess').innerHTML = 'Nieprawidłowy e-mail';
		pass = false;
		}else{
			$('username_mess').innerHTML = '';
		}
		
		
		if (!$('UserAccept').checked){
			alert('Aby zarejestrować się w serwisie musisz zaakceptować regulamin profilu');
			return false;
		}
		
		if(pass == true){
			return true;
		}else{
			return false;
		}
		
	}

	
//  GALERIE _ SHOW (photo_albums)
	function show_photo(id, controller){
		//podmiana lightboxa
		//$('lighbox_href').href=pictures_url+all_photos[id]+'_wm';
		
		$('lighbox_href').href=all_photos_wm[all_photos[id]];
		$('lighbox_href').title=all_photos_desc[id];

		var counted_desc = all_photos.length;
	
		var link_to_write = '';

		for (var i = 0; i < counted_desc; i++){
			if(i != id){
				//link_to_write=link_to_write+' '+'<a id="lighbox_href" rel="lightbox[showcases]" href="'+pictures_url+all_photos[i]+'" title="'+all_photos_desc[i]+'"></a>';
				link_to_write=link_to_write+' '+'<a id="lighbox_href" rel="lightbox[showcases]" href="'+all_photos_wm[all_photos[i]]+'" title="'+all_photos_desc[i]+'"></a>';
			}
		}

		$('other_lightbox_links').innerHTML=link_to_write;


		var img_tmp = $('bigPhotoId');
		img_tmp.src = preLoad[id];
		
// 		var photo_id = all_photos[id];
		var text_photographer = all_photos_photographer[id];
		var text_desc = all_photos_desc[id];

// 		new Ajax.Updater('photo_id', url_show_photo+photo_id, {
// 				onSuccess: function() {
// 					document.getElementById('photo_id').style.display = '';
// 					document.getElementById('photo_id_loading').style.display = 'none';
// 				},
// 				onLoading: function() {
// 					document.getElementById('photo_id').style.display = 'none';
// 					document.getElementById('photo_id_loading').style.display = '';
// 				},
// 				onFailure :function() {
// 					document.getElementById('photo_id').style.display = '';
// 					document.getElementById('photo_id_loading').style.display = 'none';
// 				}
// 			});
		current_photo = id;




		if ($('photographer_name_container_td')){
			if (text_photographer != ''){
				$('photographer_name_container_td').style.display = '';
				$('photographer_name_container').innerHTML = text_photographer;	
			}else{
				$('photographer_name_container_td').style.display = 'none';
			}
		}
		$('description_photo_container').innerHTML = text_desc;

		check_note_and_comments(all_photos[current_photo], controller);
	}
	
	function next_photo(controller){
		if (all_photos.length -1 > current_photo){
			show_photo(current_photo + 1, controller);
			
			if (current_photo > last_photo_gallery){
				next_photo_gallery();
			}
		}
	}
	
	function prev_photo(controller){
		if (current_photo > 0){
			show_photo(current_photo -1, controller);
			
			if (current_photo < first_photo_gallery){
				prev_photo_gallery();
			}
		}
	}
	
	function next_photo_gallery(){
		if (all_photos.length - 1 > last_photo_gallery){
			document.getElementById('image_'+first_photo_gallery).style.display = 'none';
			document.getElementById('image_'+(last_photo_gallery+1)).style.display = '';
			document.getElementById('ph_gal_div_'+first_photo_gallery).style.display = 'none';
			document.getElementById('ph_gal_div_'+(last_photo_gallery+1)).style.display = 'block';
			first_photo_gallery++;
			last_photo_gallery++;
			
			check_gallery();
		}
	}
	
	function prev_photo_gallery(){
		if (first_photo_gallery > 0){
			document.getElementById('image_'+(first_photo_gallery-1)).style.display = '';
			document.getElementById('image_'+last_photo_gallery).style.display = 'none';

			document.getElementById('ph_gal_div_'+(first_photo_gallery-1)).style.display = 'block';
			document.getElementById('ph_gal_div_'+last_photo_gallery).style.display = 'none';


			first_photo_gallery--;
			last_photo_gallery--;
			
			check_gallery();
		}
	}

	
	function next_photo_gallery_four(){
		if (all_photos.length - 1 > last_photo_gallery){

			for(var i=0 ; i<4 ; i++){
				document.getElementById('image_'+first_photo_gallery).style.display = 'none';
				document.getElementById('image_'+(last_photo_gallery+1)).style.display = '';
				document.getElementById('ph_gal_div_'+first_photo_gallery).style.display = 'none';
				document.getElementById('ph_gal_div_'+(last_photo_gallery+1)).style.display = 'block';
				first_photo_gallery++;
				last_photo_gallery++;
				
				check_gallery();

			}
		}
	}
	
	function prev_photo_gallery_four(){
		if (first_photo_gallery > 0){

			for(var i=0 ; i<4 ; i++){
				document.getElementById('image_'+(first_photo_gallery-1)).style.display = '';
				document.getElementById('image_'+last_photo_gallery).style.display = 'none';

				document.getElementById('ph_gal_div_'+(first_photo_gallery-1)).style.display = 'block';
				document.getElementById('ph_gal_div_'+last_photo_gallery).style.display = 'none';


				first_photo_gallery--;
				last_photo_gallery--;
				
				check_gallery();
			}
		}
	}

	function check_note_and_comments(photo_id, controller){
	
		var inputs = document.getElementsByName('data[0]['+controller.toLowerCase()+'_id]');
		
		for (var i = 0; i < inputs.length; i++){
			inputs[i].value = photo_id;
		}
		
// 		if ($('0'+controller+'Id')){
// 			$('0'+controller+'Id').value = photo_id;
// 		}
		update_note_and_comments_info();
	}
	
	function check_gallery(){
		if (first_photo_gallery == 0){
			document.getElementById('prev_gallery').style.display = 'none';
		}else{
			document.getElementById('prev_gallery').style.display = '';
		}
		
		if (last_photo_gallery == all_photos.length - 1){
			document.getElementById('next_gallery').style.display = 'none';
		}else{
			document.getElementById('next_gallery').style.display = '';
		}
	}

	function update_note_and_comments_info(){
		//new Ajax.Updater('note_info',url_update_note_note_info , {method: 'post', parameters: Form.serializeElements(Form.getElements('add_note_form'))});
		//new Ajax.Updater('comment_info',url_update_note_comment_info , {method: 'post', parameters: Form.serializeElements(Form.getElements('add_comment_form'))});
	}
	
// END GALERIA _ SHOW


// photo_albums/add_gallery

	function ajax_addItemToList1(){
		if(prev_inserted[1] != false) {
			//deleteItemImIn(prev_inserted, 'SPAN');
			//prev_inserted = false;
		}
		addItemToList(1);
	}
	
	function ajax_addItemToList2(){
		if(prev_inserted[2] != false) {
			//deleteItemImIn(prev_inserted, 'SPAN');
			//prev_inserted = false;
		}
		addItemToList(2);
	}

	function addItemToList(number) {

		invitation_count[number] ++;
		var container = $('tags_list_'+number);
		var val = $('autocomplete_'+number).value;
		var tag = val.replace('>', '').split('<');

// 		alert(email[0]+';'+email[1]);
// 		alert(email[1]);

		if( !(tag[1]) ) {
			tag = tag[0];
		}else{
			tag = tag[1]+' '+tag[0];
		}

 		//alert(tag);
// 		var name = val.slice( 0, val.index );


		var new_item = document.createElement('span');
// 		new_item.innerHTML = "<a title='click to delete' onclick=\"deleteItemImIn(this, 'SPAN'); invitation_count--;\">"+val.replace('<', '&lt;').replace('>', '&gt;')+"<input style='display:none' type='hidden' value='"+tag+"' name='data[Invitations][]'></input></a>, ";

		new_item.innerHTML = "<a title='click to delete' onclick=\"deleteItemImIn(this, 'SPAN'); invitation_count[number]--;\">"+tag+"<input style='display:none' type='hidden' value='"+tag+"' name='data[Tags][]'></input></a>, ";
		
		container.appendChild(new_item);

		prev_inserted[number] = new_item;

		clearItemValue('autocomplete_'+number);
		return false;
	}

	function clearItemValue(itemId) {
		var item = $(itemId);
		item.value ='';
		item.focus();
	}

	function checkCount(form_) {
		if(invitation_count<1) {
			alert('Email');
			return false;
		}else{
			//form_.submit();
			return true;
		}
	}






//end photo_albums/add_gallery



//KATALOG PRODUKTÓW

//odnalezienie wszystkich produktów należących do kategorii zaznaczonego produktu 
function find_products(product_id){

	var product_category_id = product_categories[product_id];
	category_id = product_category_id;
	
	var products_length = products.length;
	
	for (i = 0; i < products_length; i++){
		
		var current_product = products[i];
		
		if (product_categories[current_product] != product_category_id){
			$('product_'+current_product).disabled = true;
		}
	}
	
	check_products();
	
	//gdy odznaczył wszystko
	
	if (products_id.length == 2){
		for (i = 0; i < products_length; i++){
			$('product_'+products[i]).disabled = false;
		}
	}
}


//otworzenie porównywarki
function compare_products(){

	check_products();

	if (products_id == '/'+category_id){
		alert ('Wybierz produkty!');
	}else{
		document.location.href = product_compare_link+products_id;
	}
}


//sprawdza jakie produkty są zaznaczone
function check_products(){

	products_id = '/'+category_id;

	var products_length = products.length;

	for (i = 0; i < products_length; i++){
		if ($('product_'+products[i]).checked){
			products_id += '/'+products[i];
		}
	}
}
function hide_show_element_order(el_id){
	Effect.toggle(document.getElementById(el_id),'blind',{duration:0.5});

} 
function searchOrder(id) {
	document.getElementById("orderDiv").value=id;
	document.search_big_name_form.submit();
}

//Openx

// function OA_adjs(z,n,c,div_id, div2_id)
// {
// 	if ($(div_id) && $(div2_id)){
// 		if (z>-1) {
// 	
// 			var az = OA_p+"//www.test.Barki.pl/openx/index?n="+n+"&zoneid="+z;
// 			az+="&source="+OA_channel+"&exclude="+document.OA_used+"&r="+OA_r;
// 			az+="&mmm_fo="+(document.mmm_fo)?'1':'0';
// 			az+="&tag="+OA_tag; 
// 			
// 			if (c != null) az+= "&count="+c;
// 			if (document.context) az+= "&context=" + escape(document.context);
// 			if (window.location) az+="&loc="+escape(window.location);
// 			if (document.referrer) az+="&referer="+escape(document.referrer);
// 					
// 			new Ajax.Updater($(div_id), az, {asynchronous:true, evalScripts:true,
// 				onComplete:function()
// 				{
// 					if (div2_id != null && $(div_id).innerHTML != ''){
// 						if ($(div2_id).style.visibility == 'hidden'){
// 							$(div2_id).style.visibility = 'visible';
// 						}else{
// 							hide_show_element(div2_id);
// 						}
// 					}
// 				}
// 				}
// 			);
// 		}
// 	}
// }

//zmiana województwa w wyszukiwaniu w katalogu produktów
function change_province(id, province_name){
	$('SearchProvinceId').value = id;
	$('province_name').innerHTML = province_name;
	$('sort_provinces').style.display = 'none';

}


//dodanie komentarza
function add_comment(url_comments_add){
	var content = $('CommentContent').value;
	
	if (content != ''){
		var updater = new Ajax.Request(url_comments_add, {method: 'post',
			parameters: Form.serializeElements( Form.getElements('add_comment_form') ),
			onSuccess: function() {
				$('request').innerHTML = 'Dziękujemy za dodanie komentarza.';
				$('add_comment_div').style.display = '';
				$('add_comment_sending').style.display = 'none';
				$('CommentContent').value = '';
				if ($('CommentNickName')){
					$('CommentNickName').value = '';
				}
				//location.reload(true);
				new Ajax.Updater('comment_info',url_update_note_comment_info , {method: 'post', parameters: Form.serializeElements(Form.getElements('add_comment_form')), onComplete:function(){hide_show_element('request');}});
			},
			onLoading: function() {
				$('request').innerHTML = '';
				$('add_comment_div').style.display = 'none';
				$('add_comment_sending').style.display = '';
			},
			onFailure :function() {
				$('request').innerHTML = 'Wystąpił błąd. Komentarz nie został dodany.';
				$('add_comment_div').style.display = '';
				$('add_comment_sending').style.display = 'none';
			}
		});
	}else{
		alert ('Wpisz komentarz!');
	}
}

//dodanie oceny
function add_note(note_, url_notes_add){
	var note_for_article = document.getElementById('NoteNote');
	note_for_article.value = note_;
	new Ajax.Updater('note_info', url_notes_add, {method: 'post', parameters: Form.serializeElements(Form.getElements('add_note_form'))});
}

function change_product_info(product_info){

	if ($(product_info).style.display == 'none'){
		if (product_info == 'product_details'){
			$('product_outlets').style.display = 'none';
			$('product_details').style.display = '';
			$('product_details_info').className = 'product_more_info_title_show';
			$('product_outlets_info').className = 'product_more_info_title_hide';
		}else if (product_info == 'product_outlets'){
			$('product_details').style.display = 'none';
			$('product_outlets').style.display = '';
			$('product_outlets_info').className = 'product_more_info_title_show';
			$('product_details_info').className = 'product_more_info_title_hide';
		}
	}
}

function change_entry_info(product_info){


	if (product_info == 'all_products_info'){

		$('all_product_outlets_info').style.display = 'none';
		$('all_contact_form_info').style.display = 'none';
		$('all_products_info').style.display = 'block';
	
		$('all_products_but').className = 'product_more_info_title_show';
		$('all_product_outlets_but').className = 'product_more_info_title_hide';
		$('all_contact_form_but').className = 'product_more_info_title_hide';

	}else if(product_info == 'all_product_outlets_info'){

		$('all_products_info').style.display = 'none';
		$('all_product_outlets_info').style.display = 'block';
		$('all_contact_form_info').style.display = 'none';
	
		$('all_products_but').className = 'product_more_info_title_hide';
		$('all_product_outlets_but').className = 'product_more_info_title_show';
		$('all_contact_form_but').className = 'product_more_info_title_hide';

	}else if(product_info == 'all_contact_form_info'){

		$('all_products_info').style.display = 'none';
		$('all_product_outlets_info').style.display = 'none';
		$('all_contact_form_info').style.display = 'block';
	
		$('all_products_but').className = 'product_more_info_title_hide';
		$('all_product_outlets_but').className = 'product_more_info_title_hide';
		$('all_contact_form_but').className = 'product_more_info_title_show';
	}
}

function change_photo(id){
// 	new Ajax.Updater('product_photo', url_product_photos_product_photo_ajax+photo_id, {
// 			onComplete: function() {
// 				document.getElementById('product_photo').style.display = '';
// 				document.getElementById('product_photo_loading').style.display = 'none';
// 			},
// 			onLoading: function() {
// 				document.getElementById('product_photo').style.display = 'none';
// 				document.getElementById('product_photo_loading').style.display = '';
// 			},
// 			onFailure :function() {
// 				document.getElementById('product_photo').style.display = '';
// 				document.getElementById('product_photo_loading').style.display = 'none';
// 			}
// 		});
	$('product_photo_img').src = preLoad[id];

// 	$('lighbox_href').href=pictures_url+all_photos[id];

	//podmiana lightboxa
	$('lighbox_href').href=pictures_url+all_photos[id];
// 	$('lighbox_href').title=all_photos_desc[id];

	var counted_desc = all_photos.length;

	var link_to_write = '';

	for (var i = 0; i < counted_desc; i++){
		if(i != id){
			link_to_write=link_to_write+' '+'<a id="lighbox_href" rel="lightbox[showcases]" href="'+pictures_url+all_photos[i]+'" title=""></a>';
		}
	}

	$('other_lightbox_links').innerHTML=link_to_write;


}

function del_photo_from_gallery(id){
	document.getElementById('photo_'+id).innerHTML='';
	document.getElementById('photo_'+id).style.display='none';

}

function submit_product_form(product_url){
	$('product_sort_form').action = main_url + product_url;
	$('product_sort_form').submit();
}

function submit_product_form2(product_url){
	$('product_sort_form').action = product_url;
	$('product_sort_form').submit();
}

function submit_blog_form2(blog_url){
	$('blogs_search').action = blog_url;
	$('blogs_search').submit();
}

function submit_architect_form(product_url){
	document.architects_search_form.action = main_url + product_url;
	document.architects_search_form.submit();
}

function submit_architect_form2(product_url){
	document.architects_search_form.action = product_url;
	document.architects_search_form.submit();
}

function change_architect_province(province_id){
	$('SearchProvinceId').value = province_id;
	document.architects_search_form.submit();
}

function submit_product_search(){
	if ($('product_sort_form')){
		$('SearchProductName').value = $('SearchName').value;
		$('product_sort_form').submit();
		return false;
	}
	
	return true;
}

function submit_form_search_product(url){
	if ($('product_sort_form')){
		$('product_sort_form').action = url;
		$('product_sort_form').submit();
		return false;
	}
	
	return true;
}

function change_arrow(id, color){
	if ($('arrow_'+id)){
		$('arrow_'+id).src = img_layout_url+'right-'+color+'-trans.png';
	}
}

function clear_inputs(){

	var ask = confirm('Wyszyścić wszystkie pola?');
	if(ask == true){
		var inputs = document.getElementsByTagName('input');
		var i = 0;
		for(i ; i < inputs.length ; i++){
			if(inputs[i].getAttribute('type') == 'text') {	
				inputs[i].value = '';
			}
			if(inputs[i].getAttribute('class') == 'long_file_div') {	
				inputs[i].value = '';
			}
		}
		if ($('PhotoAlbumDescription')){
			$('PhotoAlbumDescription').value='';
		}
	}
}

	function show_additional_info(div_info, id){

// 		$(id).style.display = 'block';
		hide_show_element(id);
		var position = findPos(div_info);
		$(id).style.left = (position[0]+ div_info.offsetWidth+5)+'px';
		$(id).style.top = (position[1])+'px';
		
	}
function show_product_more_info(){
	$('product_details').style.display = 'block';
	$('product_show_more_info').style.display = 'none';
	
}

function show_hide_new_product(){
	if ($('sortable_table')){
		if ($('sortable_table').style.display == 'none'){
			$('sortable_table').style.display = 'block';
		}else if ($('sortable_table').style.display == 'block' || $('sortable_table').style.display == ''){
			$('sortable_table').style.display = 'none';
		}
	}
	if ($('new_product_hide')){
		if ($('new_product_hide').style.display == 'none'){
			$('new_product_hide').style.display = 'block';
		}else if ($('new_product_hide').style.display == 'block' || $('new_product_hide').style.display == ''){
			$('new_product_hide').style.display = 'none';
		}
	}
}

function mod_comment(model, id){
	if (confirm('Czy napewno chcesz zgłosić ten komentarz?')){
		new Ajax.Request(url_mod_comments, {method: 'post', parameters: {model: model, id: id}, onSuccess:function(){alert('Dziękujemy za zgłoszenie');}});
	}
}

//javascriptowy url :)
function change_site(url){
	document.location.href = url;
}

function check_photo_count(){
	var inputs = document.getElementsByClassName('long_file_div');
	var i = 0;
	var photos_count = 0;
	for(i ; i < inputs.length ; i++){
		if(inputs[i].value != '') {	
			photos_count++;
		}
	}
	
	if (photos_count < min_photos - current_photo_count){
		alert('Musisz wybrać co najmniej '+min_photos+' zdjęć!');
		return false;
	}
	
	var pars = Form.serializeElements(Form.getElements('architect_my_account_form'));
	new Ajax.Updater('null_cointainer', url_architects_my_account, {method: 'post', parameters: {rates: pars}, asynchronous: false});
	return true;
}

function check_architect_my_account_form(account_type){
	if ($('ArchitectName').value == ''){
		if ($('ArchitectFirstName').value == '' || $('ArchitectSecondName').value == ''){
			alert("Podaj nazwę firmy lub imię i nazwisko!");
			$('ArchitectName').focus();
			return false;
		}
	}else if (max_description_length > 0 && $('ArchitectDescription') && $('ArchitectDescription').value == ''){
		alert("Wprowadź opis działalności!")
		$('ArchitectDescription').focus();
		return false;
	}else if ($('ArchitectStreet').value == ''){
		alert("Podaj ulicę!");
		$('ArchitectStreet').focus();
		return false;
	}else if ($('ArchitectNumber').value == ''){
		alert("Podaj numer lokalu!");
		$('ArchitectNumber').focus();
		return false;
	}else if ($('ArchitectPostcode').value == ''){
		alert("Podaj kod pocztowy!");
		$('ArchitectPostcode').focus();
		return false;
	}else if ($('ArchitectCity').value == ''){
		alert("Podaj miasto!");
		$('ArchitectCity').focus();
		return false;
	}else if ($('ArchitectProvinceId').value == ''){
		alert("Wybierz województwo!");
		$('ArchitectProvinceId').focus();
		return false;
	}else if ($('ArchitectPhone').value == ''){
		alert("Podaj numer telefonu!");
		$('ArchitectPhone').focus();
		return false;
	}else if ($('ArchitectEmail').value == ''){
		alert("Podaj adres e-mail!");
		$('ArchitectEmail').focus();
		return false;
	}else if(max_description_length > 0 &&  $('ArchitectDescription') && $('ArchitectDescription').value.length > max_description_length){
		alert("Za długi opis.");
		$('ArchitectDescription').focus();
		return false;
	}else if(max_description_length > 0 &&  $('ArchitectDescription') && $('ArchitectDescription').value.length < 35){
		alert('Minimalna długość opisu to 35 znaków!');
		$('ArchitectDescription').focus();
		return false;
	}else if(account_type == designer_type){
		if (!is_miniature){
			var miniature = document.getElementsByName("data[Photo][miniature]");
			if (miniature[0].value == ''){
				alert("Wybierz zdjęcie!");
				document.location.hash = '#architect_logo_miniature';
				return false;
			}
		}
	}else if(account_type != free_type){
		if (!is_logo && !is_miniature){
			var is_logo_miniature = false;
			var miniature = document.getElementsByName("data[Photo][miniature]");
			if (miniature[0].value != ''){
				is_logo_miniature = true;
			}
			
			var logo = document.getElementsByName("data[Photo][logo]");
			if (logo[0].value != ''){
				is_logo_miniature = true;
			}
			
			if (!is_logo_miniature){
				alert("Wybierz zdjęcie lub logo!");
				document.location.hash = '#architect_logo_miniature';
				return false;
			}
		}
	}
	
	return true;
}

function change_category(poziom, selected_div, category_id, is_leaf){

	selected_div.className = 'add_product_selected';
	
	if (selected_categories[poziom] != null){
		$('category_'+selected_categories[poziom]).className = 'add_product_not_selected';
	}
	
	selected_categories[poziom] = category_id;
	
	if (is_leaf == 1){
		$('ProductProductCategoryId').value = category_id;
		find_num(poziom);
		selected_categories[poziom+1] = null;
		$('add_product_submit').style.display = 'block';
	}else{
		selected_categories[poziom+1] = null;
		find_num(poziom);
		current_category = poziom + 1;
		var div = $('categories_info');
		
		var new_div = document.createElement('div');
		new_div.id = 'product_category_'+current_category;
		new_div.className = 'add_product_select_category';
		
		if (current_category % 3 != 0){
			new_div.style.marginRight = '9px';
		}
		
		new_div.innerHTML = "<table class='table_no_border' style='width:100%;height:100%;'><tr><td class='no_border' style='text-align:center;vertical-align:middle;'><img src='"+url_img_webroot+"ajax-loader.gif'/><br/>Trwa pobieranie danych.</td></tr></table>";
		
		div.appendChild(new_div);
		
		$('ProductProductCategoryId').value = '';
		$('add_product_submit').style.display = 'none';
		
		new Ajax.Updater('product_category_'+current_category, url_products_find_category+category_id+'/'+poziom);
	}
}

function find_num(number){
	
	if (!is_ie){
		number = number + 2;
	}

	var ilosc = $('categories_info').childNodes.length;

	if (number < $('categories_info').childNodes.length){
		for(var j = $('categories_info').childNodes.length; j > number; j--){
			$('categories_info').removeChild($('categories_info').childNodes[j-1]);
		}
	}
}

function check_product(){
	
	if ($('ProductName').value == ''){
		alert(alert_no_product_name);
		return false;
	}
	
	if ($('ProductProductCategoryId').value == ''){
		alert(alert_no_product_category);
		return false;
	}	
	return true;
}

//dodanie atrybutu do produktu
function add_attribute(){
	var div = document.createElement('div');
	div.id = current_attribute;
	
	div.appendChild(document.createTextNode('Nazwa: '));
	div.className = 'other_attribute';
	
	var input_1 = document.createElement('input');
	input_1.id = current_attribute+'AttributeName';
	input_1.name = 'data[Product][attribute_name][]';
	input_1.className = 'standard_input';
	
	div.appendChild(input_1);
	
	div.appendChild(document.createTextNode(' Wartość: '));
	
	var input_2 = document.createElement('input');
	input_2.id = current_attribute+'AttributeValue';
	input_2.name = 'data[Product][attribute_value][]';
	input_2.className = 'standard_input';
	input_2.size = 10;
	
	div.appendChild(input_2);
	
	$('other_attributes').appendChild(div);
	
	current_attribute++;
}

//dodanie linku do produktu
function add_product_link(alert_no_more_links, url_product_links_autocompleter){
	if (max_links != 0 && max_links == current_link){
		alert(alert_no_more_links);
	}else{
		var div = document.createElement('div');
		div.id = 'link'+current_link;
		div.className = 'product_link';
		
		div.innerHTML = "<span class='entry_input_span'>"+current_link+". <input id='"+current_link+"Link' class='standard_input product_link_input' name='data[ProductLink][links][]'/></span><span class='entry_link_delete' onclick=\"deleteItemImIn(this, 'DIV');current_link--;\">Usuń</span><div id='autocomplete_div_"+current_link+"' class='autocomplete'/>";
		
		document.getElementById('product_links').appendChild(div);

		new Ajax.Autocompleter(current_link+'Link', 'autocomplete_div_'+current_link, url_product_links_autocompleter);
		current_link++;
	}
}

//zapisuje informacje o produkcie 
function SubmitFormProduct(someId, someId2, url_product_photos_update_gallery){
	if ($('ProductDescription').value.length > description_length){
		alert ('Za długi opis produktu ('+$('ProductDescription').value.length+').Można wpisać '+description_length+' znaków');
		return false;
	}
	if ($(someId)){
		var url = url_product_photos_update_gallery;
		var pars = escape(Sortable.serialize(someId));
		pars += '&'+Form.serializeElements(Form.getElements(someId2));
		var target = 'null_container';
		var myAjax = new Ajax.Updater(target, url, {method: 'post', parameters: {rates: pars}, asynchronous: false});
	}
	return false;
}

//zapisuje informacje o produkcie (wykorzystywane przy szybkim uploadzie)
function save_product_changes(alert_no_more_photos, url_products_edit){
	if (max_product_photos == 0 || max_product_photos <= current_photo){
		alert (alert_no_more_photos);
		return false;
	}
	
	SubmitFormProduct('category_gallery_thumbs', 'photo_miniature', url_product_photos_update_gallery);
	new Ajax.Updater('null_container', url_products_edit, {method:'post', parameters: Form.serializeElements(Form.getElements('product_edit_form'))});
	
	return true;
}

function show_default_email_info(){
	var position = findPos($('show_default_email_info'));
	$('default_email_more_info').style.left = (position[0]+ 10)+'px';
	$('default_email_more_info').style.top = (position[1])+'px';
	if ($('default_email_more_info').style.display == 'none' || $('default_email_more_info').style.display == ''){
		$('default_email_more_info').style.display = 'block';
	}else if($('default_email_more_info').style.display == 'block'){
		$('default_email_more_info').style.display = 'none';
	}
}

//dodanie telefonu
function add_phone(alert_no_more_phones){
	if (max_phones == 0 || max_phones == current_phone){
		alert(alert_no_more_phones);
	}else{
		current_phone++;
		var div = document.createElement('div');
		div.id = 'phone'+current_phone;
		div.className = 'entry_phone';
		div.innerHTML = "<span class='entry_input_span'>"+current_phone+". <input id='"+current_phone+"Phone' name='data[Entry][phones][]' class='standard_input'/></span><span class='entry_link_delete' onclick=\"deleteItemImIn(this, 'DIV');current_phone--;\">Usuń</span>";
		
		$('entry_phones').appendChild(div);
	}
}

//dodanie faxu
function add_fax(alert_no_more_faxes){
	if (max_faxes == 0 || max_faxes == current_fax){
		alert(alert_no_more_faxes);
	}else{
		current_fax++;
		var div = document.createElement('div');
		div.id = 'fax'+current_fax;
		div.className = 'entry_fax';
		
		div.innerHTML = "<span class='entry_input_span'>"+current_fax+". <input id='"+current_fax+"Fax' name='data[Entry][faxes][]' class='standard_input'/></span><span class='entry_link_delete' onclick=\"deleteItemImIn(this, 'DIV');current_fax--;\">Usuń</span>";
		
		$('entry_faxes').appendChild(div);
	}
}

//dodanie emialu
function add_email(alert_no_more_emails, add_radio){
	if (max_emails == 0 || max_emails == current_email){
		alert(alert_no_more_emails);
	}else{
		var div = document.createElement('div');
		div.id = 'email'+(current_email+1);
		div.className = 'entry_email';
		
		var inner_html = "<span class='entry_input_span'>"+(current_email+1)+". ";
		
		if (add_radio == true){
			inner_html += "<span style='margin-right:5px;'><input type='radio' name='data[Email][contact_email]' value='"+current_email+"' id='radio_email_"+current_email+"'/></span>";
		}
		
		inner_html += "<input type='text' id='"+ current_email+"Email' name='data[Entry][emails][]' class='standard_input' /></span>"
		inner_html += "<span class='entry_link_delete' onclick=\"deleteItemImIn(this, 'DIV');current_email--;\">Usuń</span>";
		
		div.innerHTML = inner_html;
		
		$('entry_emails').appendChild(div);
		
		current_email++;
	}
}

function add_www(alert_no_more_www){
	if (max_www == 0 || max_www == current_www){
		alert(alert_no_more_www);
	}else{
		current_www++;
		var div = document.createElement('div');
		div.id = 'email'+current_www;
		div.className = 'entry_www';
		
		div.innerHTML = "<span class='entry_input_span'>"+current_www+". <input id='"+current_www+"Www' name='data[Entry][www][]' class='standard_input'/></span><span class='entry_link_delete' onclick=\"deleteItemImIn(this, 'DIV');current_www--;\">Usuń</span>";
		
		$('entry_www').appendChild(div);
	}
}

function edit_outlet(id){
	if ($('entry_outlet_'+id).style.display == 'none' || $('entry_outlet_'+id).style.display == ''){
		$('entry_outlet_'+id).style.display = 'block';
	}else{
		$('entry_outlet_'+id).style.display = 'none';
	}
}

function delete_entry_outlet(id){
	$('EntryOutletName'+id).value = '';
	//$('entry_outlet_'+id).style.display = '';
	document.bbcodeform.submit();
}

//sprawdza poprawność długości opisu firmy
function check_edit_entry(){
	if ($('EntryName').value == ''){
		alert('Wpisz nazwę firmy!');
		$('EntryName').focus();
		return false;
	}else if ($('EntryDescription').value == ''){
		alert('Wprowadź opis działalności!');
		$('EntryDescription').focus();
		return false;
	}else if ($('OutletStreet').value == ''){
		alert('Wpisz ulicę!');
		$('OutletStreet').focus();
		return false;
	}else if ($('OutletNumber').value == ''){
		alert('Wpisz numer lokalu!');
		$('OutletNumber').focus();
		return false;
	}else if ($('OutletCity').value == ''){
		alert('Wpisz miasto!');
		$('OutletCity').focus();
		return false;
	}else if ($('OutletPostcode').value == ''){
		alert('Wpisz kod pocztowy!');
		$('OutletPostcode').focus();
		return false;
	}else if ($('OutletProvinceId').value == ''){
		alert('Wybierz województwo!');
		$('OutletProvinceId').focus();
		return false;
	}
	
	if (max_phones != 0){
		var phones = document.getElementsByName('data[Entry][phones][]');
		var phones_length = phones.length;
		
		if (phones_length == 0){
			alert('Podaj co najmniej 1 telefon');
			return false;
		}else{
			var is_empty_phone = true;
			var i = 0;
			
			for (i = 0; i < phones_length; i++){
				if (phones[i].value != ''){
					is_empty_phone = false;
					break;
				}
			}
			
			if (is_empty_phone){
				alert('Podaj co najmniej 1 telefon');
				return false;
			}
		}
	}
	
	if (max_emails != 0){
		var emails = document.getElementsByName('data[Entry][emails][]');
		var emails_length = emails.length;
		
		if (emails_length == 0){
			alert('Podaj co najmniej 1 e-mail');
			return false;
		}else{
			var is_empty_email = true;
			var i = 0;
			
			for (i = 0; i < emails_length; i++){
				if (emails[i].value != ''){
					is_empty_email = false;
					break;
				}
			}
			
			if (is_empty_email){
				alert('Podaj co najmniej 1 e-mail');
				return false;
			}
		}
	}
	
	if ($('EntryDescription').value.length > description_length){
		alert ('Za długi opis firmy ('+$('EntryDescription').value.length+').Można wpisać '+description_length+' znaków');
		return false;
	}
	
	return true;
}

function cancel_new_entry_outlet(){
	$('NewEntryOutletName').value = '';
	$('new_entry_outlet').style.display = 'none';
}

function add_outlet(){
	$('new_entry_outlet').style.display = 'block';
}


//sprawdza dlugosc tekstu wprowadzonego do textarea
function check_description_length(text_area_id, max_length, length_span){
	if ($(text_area_id).value.length > max_length){
		$(text_area_id).value = ($(text_area_id).value).substr(0, max_length);
	}
	$(length_span).innerHTML = $(text_area_id).value.length;
}


function search_ww(url){
	document.search_user_galleries.action = url;
	document.search_user_galleries.submit();
}

function check_new_outlet(){
	if ($('NewOutletEntryOutletTypeId').value == ''){
		alert('Wybierz typ!');
		$('NewOutletEntryOutletTypeId').focus();
		return false;
	}else if ($('NewOutletName').value == ''){
		alert('Wpisz nazwę!');
		$('NewOutletName').focus();
		return false;
	}else if ($('NewOutletCity').value == ''){
		alert('Wpisz miasto!');
		$('NewOutletCity').focus();
		return false;
	}else if ($('NewOutletPostcode').value == ''){
		alert('Wpisz kod pocztowy!');
		$('NewOutletPostcode').focus();
		return false;
	}else if ($('NewOutletProvinceId').value == ''){
		alert('Wybierz województwo!');
		$('NewOutletProvinceId').focus();
		return false;
	}else if ($('NewOutletStreet').value == ''){
		alert('Wybierz ulicę!');
		$('NewOutletStreet').focus();
		return false;
	}else if ($('NewOutletCity').value == ''){
		alert('Wybierz numer lokalu!');
		$('NewOutletCity').focus();
		return false;
	}else if ($('NewOutletPhone').value == ''){
		alert('Wybierz numer telefonu!');
		$('NewOutletPhone').focus();
		return false;
	}
	return true;
}

function check_active(){
	if (current_photo == 0){
		alert('Aby aktywować produkt musisz dodać conajmniej 1 zdjęcie!');
		return false;
	}else{
		$('ProductActive').value = 1;
		SubmitFormProduct('category_gallery_thumbs', 'photo_miniature', url_product_photos_update_gallery);
	}
	return true;
}

function check_product_form(){
	if ($('ProductName').value == ''){
		alert('Podaj nazwę produktu');
		$('ProductName').focus();
		return false;
	}else if ($('ProductPrice').value == ''){
		alert('Podaj cenę produktu');
		$('ProductPrice').focus();
		return false;
	}else if ($('ProductProducer').value == ''){
		alert('Podaj producenta produktu');
		$('ProductProducer').focus();
		return false;
	}else if ($('ProductDescription').value == ''){
		alert('Wprowadź opis produktu');
		$('ProductDescription').focus();
		return false;
	}
	
	return true;
}

function hide_product_more_info(){
	$('product_details').style.display = 'none';
	$('product_show_more_info').style.display = 'block';
}

function show_contact_form(){
	$('contact_form_div').style.display = 'block';
}

function close_gallery(el_id){
	hide_show_element(el_id);
	current_open_div_id = '';
}

function resize_entry_description(){
	var div_width = $('entry_address_details').offsetWidth;
	var entry_logo = $('entry_logo').offsetWidth;
	$('entry_description_details').style.width = (950-entry_logo-30-div_width)+'px';
}

function confirm_delete_all_products(url){
	if (confirm('Czy napewno chcesz usunąć wszystkie produkty')){
		change_site(url);
		return false;
	}
	return false;
}


function confirm_delete_photo_from_architect(url){
	if (confirm('Czy napewno chcesz usunąć to zdjęcie?')){
		change_site(url);
	}
}


function confirm_delete_architect_logo(logo_type, id){

	if (confirm('Czy napewno chcesz usunąć?')){
		change_site(url_delete_logo+logo_type+'/'+id);
		return false;
	}
	
	return false;
}

function print_article(article_id){
      window.open(article_print_page_url+article_id, 'article_print_page_'+article_id, 'menubar=no,location=no,resizable=no,scrollbars=yes,status=no, width=710, height=500');
}

function print_product(product_id){
      window.open(product_print_page_url+product_id, 'product_print_page_'+product_id, 'menubar=no,location=no,resizable=no,scrollbars=yes,status=no, width=970, height=500');
}

function print_entry(entry_id){
      window.open(entry_print_page_url+entry_id, 'entry_print_page_'+entry_id, 'menubar=no,location=no,resizable=no,scrollbars=yes,status=no, width=970, height=500');
}

//wyszukuje media po tagu
function search_media(div_info, tag_info, url_search_media, loader_div){
	if ($(div_info).style.display == ''){
		$(div_info).style.display = 'none';
	}
	if ($(loader_div)){
		$(loader_div).style.display = 'block';
	}
	new Ajax.Updater(div_info,url_search_media+$(tag_info).value, {onComplete: function(){if($(loader_div)){$(loader_div).style.display = 'none';}$(div_info).style.display = ''}});
}

//ustawia główne zdjęcie artykułu
function AddMainPhoto(photoId, url_change_main_photo){
	$('ArticleVersionArticleMediumId').value = photoId;
	$('change_main_photo').style.display = 'none';
	new Ajax.Updater('MainPhotoImg',url_change_main_photo+photoId);
}

//cytowanie komentarzy
function comments_get_quote(comment_nr){
	var text = '';
	text += "[author]"+$('comment_author_'+comment_nr).innerHTML+"[/author]\n";
	text += "[quote]"+$('comment_content_'+comment_nr).innerHTML+"[/quote]";
	
	while(text.match("\n")){
		text = text.replace("\n", "&nb;");
	}
	
	var check_author = text.match("<[sS]{1}[pP]{1}[aA]{1}[nN]{1} class=\"{0,1}comments_author_quote\"{0,1}>.*</[sS]{1}[pP]{1}[aA]{1}[nN]{1}>");
	if (check_author != null){
		text = text.replace(check_author, '');
	}
	
	var check_content = text.match("<[sS]{1}[pP]{1}[aA]{1}[nN]{1} class=\"{0,1}comments_content_quote\"{0,1}>.*</[sS]{1}[pP]{1}[aA]{1}[nN]{1}>");
	if (check_content != null){
		text = text.replace(check_content, '');
	}
	
	var check_img = text.match("<[iI]{1}[mM]{1}[gG]{1}.*>");
	while(check_img != null){
		text = text.replace(check_img, '');
		check_img = text.match("<[iI]{1}[mM]{1}[gG]{1}.*>");
	}
	text += "\n";
	
	while(text.match("&nb;")){
		text = text.replace("&nb;", "\n");
	}
	
	while(text.match("<br>")){
		text = text.replace("<br>", "");
	}
	
	$('CommentContent').value = text;
	$('CommentContent').focus();
}

function show_galleries_on_page(){
	
//	if ((clientVer >= 4) && is_ie && is_win){
//		var frame_class = fr.childNodes[1].childNodes[0];
//	}else{
//		var frame_class = fr.childNodes[3].childNodes[1];
//	}

	var divs = document.getElementsByClassName('g_gallery');
	var type_ = '';
	var gallery_ = '';
	
	if(divs.length > 0){
		for(var i = 0 ; i < divs.length ; i++){
			type_ = divs[i].childNodes[0].innerHTML;
			gallery_ = divs[i].childNodes[1].innerHTML;
			new Ajax.Updater(divs[i], galleries_url+type_+'/'+gallery_, {asynchronous:true});
		}
	}

	
	return false;
}
/**
 * Usnięcie pliku z bloga
 * @param span_info informacje o spanie
 * @param file_id id pliku
 */
function blog_delete_file(span_info, file_id){
		var container = $('current_files_to_delete');
		var new_div = document.createElement('div');
		new_div.id = 'delete_file_'+file_id;
		new_div.innerHTML = "<input type='hidden' name='data[DeleteFile][]' value='"+file_id+"'/>";
		container.appendChild(new_div);
		deleteItemImIn(span_info, 'DIV');
}

/**
 * Dodanie nowego pliku do bloga
 * Wyświetla nowy input
 */
function blog_add_next_file(){
	$('add_files').appendChild(blog_add_one_file_div.cloneNode(true));
}

/**
 * Dodanie zdjęcia komentarza
 */
function comment_add_img_url(){
	var url = prompt("Podaj adres url zdjęcia\n(zaczynający się od http://, np. http://www.jakisSerwer.pl/zdjecia/zdjecie.jpg)");
	
	if (!(url == null || url == '')){
		var new_tag = "[img_url="+url+"][/img_url]";
		change_tags('', new_tag, '', 'CommentContent');
	}
}

/**
 * Wyświetla statystyki użytkownika
 * @param month
 * @param year
 * @return
 */
function user_stats_show_stats(month, year){
	document.location.href = url_user_stats+'/'+month+'/'+year;
}

/**
 * Zaznacza wszystkie wiadomości
 */
function message_select_all(messages){
	var message_length = messages.length;
	
	for (var i = 0 ; i < message_length; i++){
		$('Message'+messages[i]).checked = true;
	}
}

/**
 * Edycja opisu pliku w wizytówce firmy
 */
function edit_entry_file(file_id){
	$('file_description_'+file_id).style.display = 'block';
}

/**
 * Edycja opisu pliku w produkcie
 */
function edit_product_file(file_id){
	$('file_description_'+file_id).style.display = 'block';
}
