var height = $(window).height();
var width = $(window).width();
var ajaxTYPE = 'POST';
var ajaxURL = '../ajax_JQuery/ajax.jquery.php';

//FULL DIV
function FULL(size,functionCheck,id){
	$("html").append('<div id="full_div"></div>')
	$("#full_div").css({"width":width, "height":height})
	$("#page_all").css("position","fixed")
	if($("#newDIVJquery").length == 1){
		$("#newDIVJquery").fadeOut('slow',function(){
			$("#newDIVJquery li").text('trwa ładowanie...')
			functionCheck(id)
			$(this).fadeIn('slow')
	});
	}else{
		newDIVJquery(size)
		functionCheck(id)
		}
}

//TEXTAREA HIDDEN
function textareaResize(id)
{
	$(id).keyup(function(){
		$(this).css("height","");
		this.rows=this.value.split('\n').length;
		$(this).css("height", (this.scrollHeight)+'px');
	});
}

//coment textarea
function comentTextarea(id,idCom,place){
		$(id).text('')
			$(id).bind('keypress', function(e) {
			var info = htmlspecialchars($(id).val());			
			if(e.keyCode==13 && info.length >= 2){
				$(id).attr("disabled","disabled");
				$.ajax({
			  	type: ajaxTYPE,
		   	url: ajaxURL,
		   	data: "action=saveComent&idCom="+idCom+"&place="+place+"&info="+info,
		   	beforeSend: function(){
			   	$(id).val('zapisuje komentarz...');
		   	},
		   	success: function(coment){
		   		$("#CMbg_"+idCom).html(coment);		   		
		   		$(id).val('dodaj komentarz i wciśnij enter');
		   	},
		   	error: function(html){
		   		$(id).val('błąd wysyłania');
		   	}
			});				
			}
		});
}

//dell com
function dellCom(id){
			$.ajax({
			type: ajaxTYPE,
		  	url: ajaxURL,
		  	data: "action=dellCom&idCom="+id,
		  	success: function(dell){
		   	$(".comentBGid[rel="+id+"]").html(dell);
		   }
		});
}

//show full CM
function showFullCM(id,place){
			$("#comentBG_"+id).text('trwa ładowanie...');
			$.ajax({
			type: ajaxTYPE,
		  	url: ajaxURL,
		  	data: "action=showFull&place="+place+"&idCom="+id,
		  	success: function(show){
		   	$("#CMbg_"+id).html(show);		   		
		   }
		});
}

//root click foto
function next_foto(user){
	full_info(user)
}

//LOGIN
function login(){
	$.ajax({
	  	type: ajaxTYPE,
   	url: ajaxURL,
   	data: "action=login",
   	success: function(login){
   		$("#newDIVJquery li").html(login)
   		changeBOX(true)
   	}
});
}

//FORGET PASS
function forgetPass(){
		$.ajax({
	  	type: ajaxTYPE,
   	url: ajaxURL,
   	data: "action=forgetPass",
   	success: function(forgetPass){
   		$("#newDIVJquery li").html(forgetPass)
   		changeBOX(true)
   	}
});
}

function changeBOX(animate){
	var box_width = $("#newDIVJquery").width();
	var box_height = $("#newDIVJquery").height();
	var pr_width = 50-(((box_width*100)/width)/2);
	var pr_height = 50-(((box_height*100)/height)/2);
	if(animate) $("#newDIVJquery").animate({"left":pr_width+"%","top":pr_height+"%"}, "slow")
	else $("#newDIVJquery").css({"left" : pr_width+"%","top" : pr_height+"%"});
}

function changeBOXmini(animate){
	var box_width = $("#newDIVmini").width();
	var box_height = $("#newDIVmini").height();
	var pr_width = 50-(((box_width*100)/width)/2);
	var pr_height = 50-(((box_height*100)/height)/2);
	if(animate) $("#newDIVmini").animate({"left":pr_width+"%","top":pr_height+"%"}, "slow")
	else $("#newDIVmini").css({"left" : pr_width+"%","top" : pr_height+"%"});
}

function newDIVJquery(size_width,size_height){
	$("#newDIVJquery").remove();
	$("html").append('<div id="newDIVJquery"><li>trwa ładowanie...</li><button class="newDIV_button_close" title="zamknij"></button></div>')
	$("#newDIVJquery").css({"width" : size_width, "height" : size_height});
	changeBOX()
	$("#newDIVJquery button").click(function(){
		$("#newDIVJquery").fadeOut("slow", function(){
			$("#newDIVJquery").remove()
			$("#full_div").fadeOut("slow", function(){
				$("#full_div").remove()
				$("#page_all").css("position","relative")
			});
		});
	});
}

function MINI(size_width,size_height){
	$("html").append('<div id="newDIVmini"><li>trwa ładowanie...</li><button class="newDIV_button_close" title="zamknij"></button></div>')
	$("#newDIVmini").css({"width" : size_width, "height" : size_height});
	changeBOXmini()
	$("#newDIVmini button").click(function(){
		$("#newDIVmini").fadeOut("slow", function(){
			$("#newDIVmini").remove()
		});
	});	
}

//FULL INFO ABOUT USER
function full_info(id){
	$("html").append('<div id="full_div"></div>')
	$("#full_div").css({"width":width, "height":height})
	$("#page_all").css("position","fixed")
	
	if($("#id_user").length == 1){
		$("#id_user").fadeOut('slow',function(){
			$("#id_user li").text('Trwa ładowanie...');
			$(this).fadeIn('slow',function(){
			fullAjax(id);		
			});
		});
	}else{
	$("html").append('<div id="id_user"><li>Trwa ładowanie...</li><div id="Sclose">zamknij</div></div>')
	var box_width = $("#id_user").width();
	var pr_width = 50-(((box_width*100)/width)/2);
	$("#id_user").css({"left":pr_width+"%","top":"20px"})
	///info about user
	fullAjax(id);
	}
}

function fullAjax(id)
{
	$.ajax({
		type: ajaxTYPE,
		url: ajaxURL,
		data: "action=infoUser&id="+id,
		success: function(userInfo){
			$("#id_user li").html(userInfo);
			$("#Sclose").click(function(){
				$("#id_user").fadeOut('slow',function(){
					$(this).remove()
					$("#full_div").fadeOut('slow',function(){
						$(this).remove()
						$("#page_all").css("position","relative")	
					});					
				});
			});
			}			
	});
}

$("html").append('<div id="changeBG"></div>')
var move = (height - 32)+'px';
$("#changeBG").css("top",move);
$.ajax({
	  	type: ajaxTYPE,
   	url: ajaxURL,
   	data: "action=loadModule",
   	success: function(module){
			$("#changeBG").html(module)
			$("#changeBG ul li").css("cursor","pointer");
			//save BG to BLOG
			$(".saveBGbutton").click(function(){
				$.ajax({
				  	type: ajaxTYPE,
			   	url: ajaxURL,
			   	data: "action=saveBGblog",
			   	success: function(saveBG){
			   		alert(saveBG)
			   	}
				});
			});			
   	}
});


//CHANGE BG
function changeBG()
{
		$.ajax({
   	type: ajaxTYPE,
   	url: ajaxURL,
   	data: "action=changeBG",
   	success: function(msn){
			$("#newDIVJquery li").html(msn)			
			changeBOX()
			$(".backgroundNewBG").click(function(){
					$(".backgroundNewBG").css({"border-width":"3px","border-color":"#e7e7e7"})
					$(this).attr('alt', function(i, val){
						$(this).css({"border-width":"3px","border-color":"#000"})
						var url = 'url(../index_files/backgroundBG/'+val+')'
						$("html").css({"background":url,"background-attachment":"fixed"})
						$.ajax({
					   	type: ajaxTYPE,
					   	url: ajaxURL,
					   	data: "action=changeBG&info="+val,
					   	success: function(ajx){
					   		$("#newDIVJquery li .title").html(ajx)
					   	}
						});
					});
			});
   }
 });
}

/* ADV */
function howPeople()
{
		var sex = $("#advWho").val();
		var region = $("#region").val();
		
		$.ajax({
			type: ajaxTYPE,
			url: ajaxURL,
			data: "action=advHowPeople&sex="+sex+"&region="+region,
			success: function(howpeople){
				$("#howPeople").text(howpeople)
			}			
		});
}

function costADV()
{
	var klik = $("#klik").val();
		$.ajax({
			type: ajaxTYPE,
			url: ajaxURL,
			data: "action=advCost&cost="+klik,
			success: function(advCost){
				$("#cost").text(advCost)
			}			
		});	
}

function ADVup(id)
{
	$.ajax({
			type: ajaxTYPE,
			url: ajaxURL,
			data: "action=ADVup&info="+id,
			success: function(ADVup){
				$("#adminADV_"+id).text(ADVup)
			}			
		});	
}

//check on klik ADV
function addLENADV(id){
	var atr = $(id).attr('atr')
		$.ajax({
			type: ajaxTYPE,
			url: ajaxURL,
			data: "action=addKlikADV&info="+atr
		});	
}

function ADV_root(id){
	var atr = $(id).attr('atr')
	$("#ADV_show_"+atr).fadeIn('slow',function(){
		$(this).click(function(){
			$(this).fadeOut('slow')
		});
	});
}

//html special chars
function htmlspecialchars(txt) {
  return txt
      .replace(/&/g, "%amp;")
      .replace(/</g, "%lt;")
      .replace(/>/g, "%gt;")
      .replace(/"/g, "%quot;")
      .replace(/'/g, "%#039");
//      .replace(/\n/g, "<br>");
      }


function createADV()
{
		$.ajax({
   	type: ajaxTYPE,
   	url: ajaxURL,
   	data: "action=advLoad",
   	success: function(advLoad){
			$("#newDIVJquery li").html(advLoad)			
			changeBOX(true)
			$(".advButtonAjax").click(function(){
				if(!$("#passADV").val()) $("#newDIVJquery li .title").html('Wprowadź hasło !')
				else{
					$.ajax({
					   	type: ajaxTYPE,
					   	url: ajaxURL,
   						data: "action=advLoad&info="+$("#passADV").val(),
					   	success: function(advcheck){
					   		$("#newDIVJquery li").html(advcheck)
					   		changeBOX(true)
					   		//check title length
					   		$("#titleADVform").keyup(function(){
					   			$("#titleADVform").css("background","#fff")
					   			var maxSize = 35;
					   			var len = (maxSize - $(this).val().length)
					   			if(len >= 0){
									$("#newDIVJquery .titleADV b").html(len)
										$(".advIDAtitle").text($(this).val())
									}else{
									$(this).attr("disabled","disabled")
									}
					   		});
					   		//check txt
					   		$("#txtADVform").keyup(function(){
					   			$("#txtADVform").css("background","#fff")					   		
					   			var maxSize = 135;
					   			var len = (maxSize - $(this).val().length)
					   			if(len >= 0){
									$("#newDIVJquery .txtADV b").first().html(len)
									$(".advTXTajax").text($(this).val())									
									}else{
									$(this).attr("disabled","disabled")
									}
					   		});
					   		//check photos
					   		$("#advMyPhotos img").click(function(){
					   			$("#advMyPhotos img").css("border-color","#e7e7e7")
					   			$(this).css("border-color","#000")
					   			$(this).attr('title', function(i, val){
					   				var url = '../img/'+val
										$("#rootADVimg").attr('src',url)
										$("#rootADVimg").attr('title',val)
					   			});
					   		});
					   		//check save
					   		$("#saveADV").click(function(){
									//check title
									if($(".advIDAtitle").text() == 'Twój tytuł reklamy' || !$(".advIDAtitle").text()) $("#titleADVform").css("background","red")
									else{
										//check info
										if($(".advTXTajax").text() == 'Tekst dodajesz tutaj.' || !$(".advTXTajax").text()) $("#txtADVform").css("background","red")
										else{
											//next step
$("#advFirstStep").fadeOut('slow',function(){
	$.ajax({
	type: ajaxTYPE,
	url: ajaxURL,
	data: "action=advNextStep&img="+$("#rootADVimg").attr('title')+"&txt="+$(".advTXTajax").text()+"&title="+$(".advIDAtitle").text(),
	success: function(advNextStep){
		$("#newDIVJquery li").html(advNextStep)
		changeBOX(true)
		$("#howPeople").text('ładowanie...')
			howPeople()
			/*sex*/
			$("#advWho").change(function(){
			howPeople()
			});
			/*region*/
			$("#region").change(function(){
			howPeople()
			});
			
		//check cost
		$("#cost").text('ładowanie...')
			costADV()
			$("#klik").change(function(){
			costADV()
			});
			//click
			$(".advButtonAjax").click(function(){
				$("#threStep").fadeIn('slow',function(){
				changeBOX(true)
					$("#acceptReg").click(function(){
						$("#secondStep").fadeOut('slow',function(){
							$("#forStep").fadeIn('slow',function(){
								$.ajax({
									type: ajaxTYPE,
									url: ajaxURL,
									data: "action=advcheckWallet",
									success: function(checkWallet){
										$("#newDIVJquery li").html(checkWallet)
										changeBOX(true)
									}
								});
							});
						});
					});
				});
			});
	}	
	});	
});
}
									}
					   		});					   		
					   	}
					});
				}
			});
   	}
   	});   	
}

//WISHES
function wishes(user_id){
	$.ajax({
	  	type: ajaxTYPE,
   	url: ajaxURL,
   	data: "action=wishes&info="+user_id,
   	success: function(wishes){
   		$("#newDIVJquery li").html(wishes)
   		changeBOX(true)
   	}
});	
}

//save Wishes
function saveWishes(){
	var info = $("textarea[name=wishes]").val();
	if(info.length >= 3)
	{
		//hidden
		var hidden = $("input[name=wishes_hidden]").val();
		$.ajax({
	  	type: ajaxTYPE,
   	url: ajaxURL,
   	data: "action=wishesAdd&id="+hidden+"&info="+info,
   	success: function(wishesAdd){
   		$("#newDIVJquery li .title").text(wishesAdd)
   	}
});		
	}else $("textarea[name=wishes]").css("background","red");
}

//FIND COUPLES
function findCouples(id){
	$.ajax({
	  	type: ajaxTYPE,
   	url: ajaxURL,
   	data: "action=findCouples&id="+id,
   	success: function(couples){
   		$("#newDIVJquery li").html(couples)
   		changeBOX(true)
   	}
});	
}

//add Couples
function addCouples(){
	var about = $("input[name=about_me]").val();
	var find = $("input[name=who_find]").val();
	var disco = $("input[name=about_disco]").val();	
	
	if(about.length >= 3){
		$("input[name=about_me]").css("background","#fff");
		if(find.length >= 3){
			$("input[name=who_find]").css("background","#fff");
			if(disco.length >= 3){
				$("input[name=about_disco]").css("background","#fff");
				//save
				$.ajax({
			  	type: ajaxTYPE,
		   	url: ajaxURL,
		   	data: "action=saveCouples&about="+about+"&whofind="+find+"&disco="+disco,
		   	success: function(savecouples){
	   		$("#newDIVJquery li .title").text(savecouples)
		   	}
				});
			}else $("input[name=about_disco]").css("background","red");
		}else $("input[name=who_find]").css("background","red");
	}else $("input[name=about_me]").css("background","red");
}

//ADD FRIEND
function addFriend(id){
	$("li[name=friend]").text('wysyłam zaproszenie...');
	$.ajax({
	type: ajaxTYPE,
	url: ajaxURL,
	data: "action=addFriend&info="+id,
	success: function(addFriend){
	   $("li[name=friend]").html(addFriend);
	}
	});	
}

//DELL FRIEND
//ADD FRIEND
function dellFriend(id){
	$("li[name=friend]").text('usuwam...');
	$.ajax({
	type: ajaxTYPE,
	url: ajaxURL,
	data: "action=dellFriend&info="+id,
	success: function(addFriend){
	   $("li[name=friend]").html(addFriend);
	}
	});	
}

//ADD OBSERVED
function addObserved(id){
	$("li[name=observed]").text('trwa dodawanie...');
	$.ajax({
	type: ajaxTYPE,
	url: ajaxURL,
	data: "action=addObserved&info="+id,
	success: function(addobv){
	   $("li[name=observed]").html(addobv);
	}
	});	
}

//FUNCTION SEND MESSAGE
function sendMessageBOX(id){
	MINI(600);
	$.ajax({
	type: ajaxTYPE,
	url: ajaxURL,
	data: "action=sendMessage&info="+id,
	success: function(send){
	   $("#newDIVmini li").html(send);
	   changeBOXmini(true)	   
	}
	});	
}

function sendMessage(id){
	var mess = document.getElementById('message_info').value
	var num = mess.length
	if(num > 0){
		mess = mess.replace(/\n/g, "<br>")
		var reg = mint.Request();
		var ajax = reg.Send("../ajax/ajax.php?ajax=sendMess&userid="+id+"&info="+mess+"",'menu_bg');
		document.getElementById('message_info').value = '';
	}
}

function closeMINI(){
	$("#newDIVmini").fadeOut('slow',function(){
		$(this).remove();
	});
}

function closenewDIVJquery(){
	$("#newDIVJquery").fadeOut('slow',function(){
		$(this).remove();
		$("#full_div").fadeOut('slow',function(){
		$(this).remove();
		$("#page_all").css("position","relative");
		});
	});
}

//SAVE MESS
function sendMess(id){
	var mess = $("textarea[name=message]");
	if(mess.val().length >= 3){
		mess.css("background","#fff");
	$.ajax({
	type: ajaxTYPE,
	url: ajaxURL,
	data: "action=saveMessage&id="+id+"&info="+mess.val(),
	success: function(save){
	   $("#newDIVmini").html(save);
		setTimeout("closeMINI()",2000);
		changeBOXmini(true)
	}
	});
	}else mess.css("background","red");
}

//ALL FRIENDS
function allFriends(id){
	MINI(760);
	$.ajax({
	type: ajaxTYPE,
	url: ajaxURL,
	data: "action=allFriends&info="+id,
	success: function(all){
	   $("#newDIVmini li").html(all);
	   changeBOXmini(true)	   
	}
	});	
}

//GALLERY
function nextFOTOgal(idThis,id,iduser,patch){
	var JPGheight = - ($(".GALimgBIG").height()) / 2;
	var JPGwidth = $(".GALimgBIG").width();
	$("center[name=fotoGAL]").append('<div id="newJPGid">Trwa ładowanie fotografii...</div>');
	$("#newJPGid").css({"top":JPGheight,"width":JPGwidth});
	$.ajax({
	type: ajaxTYPE,
	url: ajaxURL,
	data: "action=nextFOTOgal&iduser="+iduser+"&patch="+patch+"&info="+id,
	success: function(gal){
	   $("#GALleft").html(gal);
	}
	});	
}

//PROFIL FOTO
function add_profil_foto(id){
	$.ajax({
	  	type: ajaxTYPE,
   	url: ajaxURL,
   	data: "action=profilFoto&id="+id,
   	success: function(profilFoto){
   		$("#newDIVJquery li").html(profilFoto)
		   changeBOX(true)   		
   	}
});
}

//ADD FOTO GALLERY
function add_foto(id){
	$.ajax({
	  	type: ajaxTYPE,
   	url: ajaxURL,
   	data: "action=galleryFoto&id="+id,
   	success: function(galeryFoto){
   		$("#newDIVJquery li").html(galeryFoto)
		   changeBOX(true)   		
   	}
});
}

//DELL FOTO
function dellFotoUser(id){
		var conf = confirm("Czy napewno ?");
		if(conf){
		$.ajax({
	  	type: ajaxTYPE,
   	url: ajaxURL,
   	data: "action=dellFotoUser&info="+id,
   	success: function(sbm){
   		$("li[name=dellPhoto]").text(sbm)
   	}
});
		}
}

//CHANGE PASS
function change_pass(id){
	$.ajax({
	  	type: ajaxTYPE,
   	url: ajaxURL,
   	data: "action=changePass&id="+id,
   	success: function(changePass){
   		$("#newDIVJquery li").html(changePass)
		   changeBOX(true)   		
   	}
});
}

function dell_profil(id){
	$.ajax({
	  	type: ajaxTYPE,
   	url: ajaxURL,
   	data: "action=dellProfil&id="+id,
   	success: function(dellProfil){
   		$("#newDIVJquery li").html(dellProfil)
		   changeBOX(true)   		
   	}
});
}

//FOTO KAT
function add_foto_kat(id){
	$.ajax({
	  	type: ajaxTYPE,
   	url: ajaxURL,
   	data: "action=addFotoKat&info="+id,
   	success: function(addFotoKat){
   		$("#newDIVJquery li").html(addFotoKat)
		   changeBOX(true)   		
   	}
});
}

//Rand photo
function change_rand_photo(id){
	$.ajax({
	  	type: ajaxTYPE,
   	url: ajaxURL,
   	data: "action=changeRandPhoto",
   	success: function(smb){
   		$("#newDIVJquery li").html(smb)
		   changeBOX(true)   		
   	}
});
}

// EVENTS ADD
function events_add(event,id)
{
	size = id.value.length;
	event = event || window.event;
	if(event.keyCode == 13 && size > 0){
		FULL(600,eventsNew(id.value))
		clear_form(id)
	}
}

function eventsNew(info){
	$.ajax({
	  	type: ajaxTYPE,
   	url: ajaxURL,
   	data: "action=eventsNew&info="+info,
   	success: function(smb){
   		$("#newDIVJquery li").html(smb)
		   changeBOX(true) 	
   	}
});	
}

//APPLY EVENTS
function i_apply(id){
	var conf = confirm("Czy napewno edytować udział ?");
	if(conf){
	$.ajax({
	  	type: ajaxTYPE,
   	url: ajaxURL,
   	data: "action=applyEvents&id="+id,
   	success: function(smb){
				$(".apply_information").html(smb)
   	}
	});	
	}
}

//OFERIA ADD CLICK
function oferia_add_click()
{
	$.ajax({
	  	type: ajaxTYPE,
   	url: ajaxURL,
   	data: "action=OferiaAdd&info=Twoje zapytanie...",
   	success: function(smb){
	   		$("#newDIVJquery li").html(smb)
			   changeBOX(true) 
   	}
	});
}

//ABOUT
function about(id){
	FULL(600,aboutShow(id))
}

function aboutShow(id){
		$.ajax({
	  	type: ajaxTYPE,
   	url: ajaxURL,
   	data: "action=about&info="+id,
   	success: function(smb){
	   		$("#newDIVJquery li").html(smb)
			   changeBOX(true) 
   	}
	});
}

//JOIN FRIENDS
function join_friends(id){
		$.ajax({
	  	type: ajaxTYPE,
   	url: ajaxURL,
   	data: "action=joinFriends&info="+id,
   	success: function(smb){
	   		$("#newDIVJquery li").html(smb)
			   changeBOX(true) 
   	}
	});
}

//ACCEPT FRIEND
function accept_friend(id){
		$.ajax({
	  	type: ajaxTYPE,
   	url: ajaxURL,
   	data: "action=acceptFriend",
   	success: function(smb){
	   		$("#newDIVJquery li").html(smb)
			   changeBOX(true) 
   	}
	});
}

//WALL
function addWall(id){
	$(id).val('');
	textareaResize(id);
	$("button[name=saveWall]").fadeIn('slow');
	$("button[name=saveWall]").click(function(){
		var val = $(id).val();
		if(val.length >= 2){
			$(".wallTextarea").attr("disabled","disabled");
			$.ajax({
	  		type: ajaxTYPE,
   		url: ajaxURL,
   		data: "action=addWall&info="+val,
   		success: function(smb){
	   		$("#BL_WALL").html(smb)
   	}
	});
		}
	});
}

function dellWALL(id){
	var conf = confirm("Czy napewno ?");
	if(conf){
			$("#BLid_"+id).css("background","#fff")
			$.ajax({
	  		type: ajaxTYPE,
   		url: ajaxURL,
   		data: "action=dellWall&info="+id,
   		success: function(smb){
	   		$("#BL_WALL").html(smb)
   	}
	});	
	}	
}

function readMoreBL(id){
			$(".BLreadMore").text('Trwa wczytywanie...')
			$.ajax({
	  		type: ajaxTYPE,
   		url: ajaxURL,
   		data: "action=moreWall&info="+id,
   		success: function(smb){
	   		$("#BL_WALL").html(smb)
   	}
	});
}

//ADD INFO PATCH
function addInfoPatch(id){
			$.ajax({
	  		type: ajaxTYPE,
   		url: ajaxURL,
   		data: "action=addInfoPatch&id="+id,
   		success: function(smb){
	   		$("#newDIVJquery li").html(smb)
	   		changeBOX(true)
	   		
	   		//save
	   		$("button[name=savePatchInfo]").click(function(){
					var val = $("#sixtentextarea").val();
					if(val.length > 3){
							$("#sixtentextarea").attr("disabled","disabled");
							$.ajax({
					  		type: ajaxTYPE,
				   		url: ajaxURL,
				   		data: "action=saveInfoPatch&info="+val+"&id="+id,
   						success: function(smb){
								$("#newDIVJquery").html(smb)
					   		changeBOX(true);
					   		val = val.replace(/\n/g,"<br>");
					   		$("#GALinfoPatchShow").html(val);
					   		setTimeout("closenewDIVJquery()",2000);
					   	}
						});						
					}else $(".title li").text('Wprowadź opis dłuższy niż 3 znaki !')
	   		});
   	}
	});
}

function popUp(){
 popup = window.open('include/popUp.php','download','height=600,width=600');
 if (window.focus) { popup.focus() }
 return false;
}

function popUpMIXlr(){
 popup = window.open('include/popUpMIXlr.php','download','height=300,width=600');
 if (window.focus) { popup.focus() }
 return false;
}

//ADD INFO JPG
function addInfoJPG(id){
			$.ajax({
	  		type: ajaxTYPE,
   		url: ajaxURL,
   		data: "action=addInfoJPG&id="+id,
   		success: function(smb){
	   		$("#newDIVJquery li").html(smb)
	   		changeBOX(true)
	   		
	   		//save
	   		$("button[name=savePatchJPG]").click(function(){
					var val = $("#sixtentextarea").val();
					if(val.length > 3){
							$("#sixtentextarea").attr("disabled","disabled");
							$.ajax({
					  		type: ajaxTYPE,
				   		url: ajaxURL,
				   		data: "action=saveInfoJPG&info="+val+"&id="+id,
   						success: function(smb){
								$("#newDIVJquery").html(smb)
					   		changeBOX(true);
					   		val = val.replace(/\n/g,"<br>");
					   		$(".GALjpgInfoId").html(val);
					   		setTimeout("closenewDIVJquery()",2000);
					   	}
						});						
					}else $(".title li").text('Wprowadź opis dłuższy niż 3 znaki !')
	   		});
   	}
	});
}

//ADV slide
	function selectADV(){
		$.ajax({
		type: ajaxTYPE,
		url: ajaxURL,
		data: "action=advertismentRoot",
	   success: function(smb){
			$("#imgADVroot").ImageSwitch({
			Type: "FadeIn",			
			EffectOriginal: true,  
			Speed: 1400,
			StartLeft: 50, //The position the effect start compare to original position could be (-)  
			StartTop: 0,  
			StartOpacity: 0, //Which start opacity it would be  
			EndLeft: -50, //The position the effect end compare to the original position could be (-)  
			EndTop: 0,  
			EndOpacity: 0, //Which start opacity it would be  
			Direction: "LeftRight", //Which Way the image will be sroll  
			NewImage:smb
			});		
			}
		});
	}	
			
			function startInterval(){
				intval = window.setInterval("selectADV()",10000);
			}

			function downloadStart(){
						$.ajax({
							type: ajaxTYPE,
							url: ajaxURL,
							data: "action=loadDownload",
						  	beforeSend: function(){
								$("#newDIVJquery li").html('Trwa ładowanie działu download ...');
							},
							success: function(download){
								$("#newDIVJquery li").html(download);
								changeBOX(true)
							},
							error: function(){
								$("#newDIVJquery li").html('Wystąpił błąd podczas ładowanie działu download !');
							}
						});				
			};			
			
			function showAllUser(){
						$.ajax({
							type: ajaxTYPE,
							url: ajaxURL,
							data: "action=loadAllUsers",
						  	beforeSend: function(){
								$("#newDIVJquery li").html('Trwa ładowanie podglądu wszystkich użytkowników serwisu proszę czekać ...');
							},
							success: function(allusers){
								$("#newDIVJquery li").html(allusers);
								changeBOX(true)
									$(".buttonTrue[name=showMoreUsers]").click(function(){
										$.ajax({
											type: ajaxTYPE,
											url: ajaxURL,
											data: "action=showMoreUsers",
										  	beforeSend: function(){
												$(".buttonTrue[name=showMoreUsers]").text('Trwa ładowanie ...');
											},
											success: function(more){
												$(".moreUsersShow:last").html(more);
												$(".buttonTrue[name=showMoreUsers]").text('Pokaż więcej klubowiczów');
												$(".loadAllUsers").scrollTo('+=300px', 800);
											},
											error: function(){
												$(".moreUsersShow").html('<div class="false"><li>Wystąpił błąd podczas ładowania.</li></div>');
											}
										});									
									});								
							},
							error: function(){
								$("#newDIVJquery li").html('Wystąpił błąd podczas ładowania !');
							}
						});				
			}
	
			
	$(document).ready(function(){
	//show All User
	$(".buttonTrue[name=showAllUser]").click(function(){
			FULL(900,showAllUser,1)
	});	
	
	//crop box
        $('#cropbox').Jcrop({
        	onChange: showCoords,
	 		onSelect: showCoords,
			setSelect: [1024, 300, 0, 0],
			bgColor: '#000',
			bgOpacity: .4,
			aspectRatio: 1024/300,
			allowResize: true,
			allowSelect: false
        });

 	function showCoords(c){
 		$("input[name=imgCutX]").val(c.x);
 		$("input[name=imgCutY]").val(c.y); 	
 		$("input[name=imgCutWidth]").val(c.w);
 		$("input[name=imgCutHeight]").val(c.h);
 	}
	
		startInterval();
		
		
	function adminAdvertisment(){
		$.ajax({
			type: ajaxTYPE,
			url: ajaxURL,
			data: "action=adminAdvertisment",
			beforeSend: function(){
				$("#newDIVJquery li").html('Trwa ładowanie aplikacji ...');
			},
			success: function(admin){
				$("#newDIVJquery li").html(admin);
				changeBOX(true)
				$("input[class=adminADVbutton]").click(function(){
					var id = $(this).attr("rel");
					var answer = confirm("Czy napewno ?");
					if(answer){
								$.ajax({
									type: ajaxTYPE,
									url: ajaxURL,
									data: "action=adminAdvertismentDell&id="+id,
									beforeSend: function(){
										$("#newDIVJquery li .title li").text('Trwa wykonywanie akcji ...');
									},
									success: function(adminDell){
										$("#newDIVJquery li .title li").text('Administracja Banerami');
										$("#"+adminDell).fadeOut();
										changeBOX(true)
									},
									error: function(){
										$("#newDIVJquery li .title li").text('Wystąpił błąd podczas usuwania pliku !');
									}
								});						
					}
				});
			},
			error: function(){
				$("#newDIVJquery li").html('Wystąpił błąd podczas ładowania aplikacji !');
			}
		});		
	}	

		
		//adminadvertisment
		$("a[href=#adminadvertisment]").click(function(){
			FULL(800,adminAdvertisment,1);
		});
		
		//add advertisment
		$("a[href=#addadvertisment]").click(function(){
			newDIVJquery(600)
						$.ajax({
							type: ajaxTYPE,
							url: ajaxURL,
							data: "action=addadvertisment",
						  	beforeSend: function(){
								$("#newDIVJquery li").html('Trwa ładowanie aplikacji dodawania baneru ...');
							},
							success: function(adv){
								$("#newDIVJquery li").html(adv);
								changeBOX(true)
								//chcek if select foto
								$("input[type=file]").bind('change',function(){
										var valIMG = $(this).val();
										$.ajax({
											type: ajaxTYPE,
											url: ajaxURL,
											data: "action=addadvertismentFoto&info="+valIMG,
										  	beforeSend: function(){
											  	$(".selectFotoADV").css({
											  	'background':'#57a14b', 
											  	'float':'left', 
											  	'text-align':'center', 
											  	'padding':'5px 0px 5px 0px', 
											  	'width':'100%', 
											  	'color':'#fff'
											  	});
												$(".selectFotoADV").html('Trwa ładowanie wybranego zdjęcia ...');
												$(".ADVdate").fadeIn(function(){
												changeBOX(true)
$( "#datepicker" ).datepicker({
monthNames: ['Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec','Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień'],
dayNamesMin: ['Po', 'Wt', 'Śr', 'Cz', 'Pi', 'So', 'Ni'],
dateFormat: 'yy-mm-dd',
onSelect: function(show){
	$(".advdescbg").fadeIn(function(){
		changeBOX(true)
		//save button
		$(".advSaveButton").click(function(click){
			var data = htmlspecialchars($("#datepicker").val());
			var txt = htmlspecialchars($(".advDescription").val());
						$.ajax({
							type: ajaxTYPE,
							url: ajaxURL,
							data: "action=saveBanerADV&infoSecond="+data+"&info="+txt,
						  	beforeSend: function(){
								$(".selectFotoADV").text('Trwa zapisywanie baneru do bazy danych...');
							},
							success: function(saveBaner){
								if(saveBaner == 'true'){
									$(".selectFotoADV").text('Baner został zapisany przejdź teraz do edycji zdjęcia... proszę czekać');
									setTimeout("document.location='../editadv'", 4000);
								}
								else $(".selectFotoADV").text('błąd');
							},
							error: function(){
								$(".selectFotoADV").text('Wystąpił błąd podczas zapisu ! Spróbuj jeszcze raz.')
							}
						});			
		});
	});
}

});


												});
											},
											success: function(adv){
												$(".selectFotoADV").html(adv);
												changeBOX(true)
											},
											error: function(){
												$(".selectFotoADV").html('Wystąpił błąd podczas ładowania aplikacji !');
											}
						});		
								});
							},
							error: function(){
								$("#newDIVJquery li").html('Wystąpił błąd podczas ładowania aplikacji !');
							}
						});			
		});
		
		//close search
		$("body").click(function(){
			$("#search_find").html('');
		});
		
				//load new music for root site
				function loadMusic(){
				$.ajax({
			  	type: ajaxTYPE,
		   	url: ajaxURL,
		   	data: "action=loadMusic",
		   	beforeSend: function(){
			   	$(".lastmp").html('<div class="musicFalse">Trwa ładowanie plików</div>');
		   	},
		   	success: function(smt){
		   		//show information
	  				$(".lastmp").html(smt);
	  				//check if dell
		   		$(".dellMusic").click(function(){
						var idDell = $(this).attr("rel");
						$.ajax({
							type: ajaxTYPE,
							url: ajaxURL,
							data: "action=dellMusic&id="+idDell,
						  	beforeSend: function(){
								alert('Trwa usuwanie ...');
							},
							success: function(dell){
								loadMusic();
							},
							error: function(){
								alert('błąd podczas usuwania !');
							}
						});
		   		});
		   		//show more files
		   		$(".moreMusic").click(function(moreFiles){
						$.ajax({
							type: ajaxTYPE,
							url: ajaxURL,
							data: "action=moreMusic",
						  	beforeSend: function(){
								$(this).html('Trwa wczytywanie ...');
							},
							success: function(){
								loadMusic();								
							},
							error: function(){
								alert('błąd podczas wczytywania !');
							}
						});
		   		});
		   		
	  				$("#addNewMusicID").bind('keypress', function(e){
	  					if(e.keyCode == 13 && $(this).val().length > 3){
	  						$(this).attr("disabled","true");
	  						$(this).css("border","0px");
		  					$("#addNewMusicIDLink").fadeIn('fast', function(){
								$(this).bind('keypress', function(e){
									if(e.keyCode == 13 && ($(this).val().length > 3 && $("#addNewMusicID").val().length > 3)){
										var title = htmlspecialchars($("#addNewMusicID").val());
										var link = htmlspecialchars($(this).val())
										if(title.length > 3 && link.length > 3){
					  						$(this).fadeOut('fast', function(){
												$.ajax({
											  	type: ajaxTYPE,
										   	url: ajaxURL,
										   	data: "action=saveMusic&infoSecond="+link+"&info="+title,
										   	success: function(smtSave){
										   		$("#addNewMusicID").val(smtSave);
										   		loadMusic();
										   	},
										   	error: function(smtSave){
										   		$("#addNewMusicID").val('błąd zapisu !')
										   	}
												});												
					  						});
										};
									};
								});
		  					});
	  					};
	  				});	  				
		   	},
		   	error: function(){
			   	$(".lastmp").html('<div class="musicFalse">Błąd podczas ładowania !</div>');
		   	}
			});
			};
			//load music function
			loadMusic();
			
			//download
			$(".menu_id[name=download]").bind('click',
				function(){
				FULL(800,downloadStart,1);
			});
			
			//add shadow in form
		$(".formShadow").bind('click', function(){
			$(".formShadow").css({"webkit-box-shadow" : "inset 0px 1px 2px #888", "color" : "#808080"});
			$(this).css({"webkit-box-shadow" : "0px 0px 8px #0340aa", "color" : "#000"});
			$(this).val('');
		});
		
     		//validate active Facebook acount
     		$("input[name=buttonActiveFB]").bind('click', function(){
				var val = new String($(".formShadow").val());
				if(val != 'adres email:' && val.length > 3){
					var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
					if(!emailReg.test(val)) $("#FaleActiveMail li").text("Błędny adres e-mail !");
					else{
						//check mail in database
						$.ajax({
							type: ajaxTYPE,
							url: ajaxURL,
							data: "action=ActiveFacebookAccount&info="+val,
						  	beforeSend: function(){
								$("#FaleActiveMail li").text("Trwa sprawdzanie adresu email...");
							},
							success: function(act){
								if(act == 'true'){
									$("#FaleActiveMail li").text("Adres został zapisany... proszę czekać");
									setTimeout("window.location.href='http://"+document.domain+"'", 1000);
								}
								else $("#FaleActiveMail li").text(act);
							},
							error: function(){
								$("#FaleActiveMail li").text("Błąd podczas sprawdzania adresu email !");
							}
						});						
					}
				}
     		});
	});

