﻿
	var xmlHttp
	var commentId
	var frame
	var spe
	var glo;
	var loadOn;
	// ladowanie strony do diva //
	
	function loadPageToFrame(toFrame,page){		
		
		// otwieramy glowny plik odpowiedzialny za otworzenie plikow MVC
		if(spe){
			var url = "loadPageToFrame.php?mod="+page+spe;
		}else{
			var url = "loadPageToFrame.php?mod="+page;
		}
		
		// tworzymy obiekt Request
		var req = mint.Request();
   		
   		// funkcja jesli zakonczy sie powodzeniem wyslanie zadania
		req.OnSuccess = function() {					
			$(toFrame).innerHTML = this.responseText; 			
		}

		// przesylamy formularz
		req.Send(url);			
		
	}
	function loadRanking(){
		
		
		
		var req = mint.Request();   		   	
		req.OnSuccess = function() {							
			$("all").innerHTML = this.responseText; 	
			changeBack('all','mark');
		}	
		req.Send('loadPageToFrame.php?mod=ranking&from=all&by=mark&page=1');				
		
		var req2 = mint.Request();   		   	
		req2.OnSuccess = function() {					
			$("month").innerHTML = this.responseText; 	
			changeBack('month','mark');
		}	
		req2.Send('loadPageToFrame.php?mod=ranking&from=month&by=mark&page=1');				

		var req3 = mint.Request();   		   	
		req3.OnSuccess = function() {					
			$("week").innerHTML = this.responseText; 			
			changeBack('week','mark');
		}	
		req3.Send('loadPageToFrame.php?mod=ranking&from=week&by=mark&page=1');				
					
		
		
	}
	function removeFile(){
		// tworzymy obiekt Request
		var req2 = mint.Request();

		var url = "loadPageToFrame.php?mod=remove_temporary_file";
		
   		// funkcja jesli zakonczy sie powodzeniem wyslanie zadania
		req2.OnSuccess = function() {
			$('ff').innerHTML = this.responseText;		
			$('remf').style.display = "none";
		}

		// przesylamy formularz
		req2.Send(url);			
	}

	function voteOnPic(pic){
		if( !readCookie("voted_on_"+pic) ){
			var req = mint.Request();				
			var url = "loadPageToFrame.php?mod=vote_on_picture&pic="+pic+"&mark=1";								
			req.OnSuccess = function() {
				var t = this.responseText;	
				if ( document.getElementById("mark_"+pic) ){
					$("mark_"+pic).innerHTML = t;
					$("vote_img_"+pic).style.display = "none";
				}
				
				var box;
				if ( box=document.getElementById("mark2_"+pic)){
					$("mark2_"+pic).innerHTML = t;	
					$("vote2_img_"+pic).style.display = "none";
				}
				
				createCookie("voted_on_"+pic);
			}			
			req.Send(url);	
		}
	}
	
	function voteOnPicture(mark,pic,n){
		// tworzymy obiekt Request
		if(userActive == 2){
			showObject("markbox_0");
			hideObject("newmarkbox");
			alert("Nie możesz głosować na zdjęcia, ponieważ zostałeś zablokowany przez moderatorów serwisu");
		}else{
			if( !readCookie("voted_on_"+pic) ){
				if(mark == 1 || mark == -1){
					var req2 = mint.Request();				
					var url = "loadPageToFrame.php?mod=vote_on_picture&pic="+pic+"&mark="+mark;
					
					// funkcja jesli zakonczy sie powodzeniem wyslanie zadania
					req2.OnSuccess = function() {
						$("mark_"+pic).innerHTML = this.responseText;		
						$("markbox_"+n).innerHTML = "&nbsp;";		
						$("markbox_"+n).style.cursor = "default";						
						createCookie("voted_on_"+pic);
					}
			
					// przesylamy formularz
					req2.Send(url);			
				}
			}
		}
	}
	function voteOnPictureWith(mark,pic,id){
		// tworzymy obiekt Request
		if( !readCookie("voted_on_"+pic) ){
			
			if(mark == 1 || mark == -1){
				var req2 = mint.Request();
				var ch;
				var url = "loadPageToFrame.php?mod=vote_on_picture&pic="+pic+"&mark="+mark;
				
				// funkcja jesli zakonczy sie powodzeniem wyslanie zadania
				req2.OnSuccess = function() {
					createCookie("voted_on_"+pic);
					if( document.getElementById("mark_"+pic) ){
						$("mark_"+pic).innerHTML = this.responseText;		
					}				
					activeMarkBoxes("index");
					if( document.getElementById("mark2_"+pic) ){
						$("mark2_"+pic).innerHTML = this.responseText;				
					}
				}
				//if( !readCookie("voted_on_"+pic) ){
					// przesylamy formularz
					req2.Send(url);			
				//}
			}
		}
	}
	function voteOnComment(mark,pic){
		// tworzymy obiekt Request
		if(mark == 1 || mark == -1){
			var req2 = mint.Request();
	
			var url = "loadPageToFrame.php?mod=vote_on_comment&pic="+pic+"&mark="+mark;
			
			// funkcja jesli zakonczy sie powodzeniem wyslanie zadania
			req2.OnSuccess = function() {
				SetCookie("voted_on"+pic,1,999999999);
				
				$("markc_"+pic).innerHTML = this.responseText;		
				$("plusc_"+pic).style.display = "none";
				$("minusc_"+pic).style.display = "none";			
				$("plusc2_"+pic).style.display = "block";
				createCookie("voted_onc_"+pic);
			}
	
			// przesylamy formularz
			req2.Send(url);			
		}
	}

	function addComment(sub,pic){
		// tworzymy obiekt Request
		
			var req2 = mint.Request();
			if( sub == 'true' ){
				var te = document.getElementById('text').value;			
				var url = "loadPageToFrame.php?mod=add_comment&submit=1&id="+pic+"&text="+te;						
			}else{					
				var url = "loadPageToFrame.php?mod=add_comment&id="+pic;					
			}
			
			req2.OnSuccess = function() {
				
				var text = this.responseText;		
				$("bbb").innerHTML = text;	
				var re = /dodany/;
				var a = text.search(re);				
				
				if(a > 0){
					loadPageToFrame("comments","show_comments&id="+pic);
				}
				
			}
			// przesylamy formularz
			req2.Send(url);			

	}	
	
	function sendViolation(pic,text,id){
		// tworzymy obiekt Request

			var req2 = mint.Request();
			
			var te = document.getElementById(text).value;
			
			var url = "loadPageToFrame.php?submit=1&mod=sendViolation&id="+pic+"&text="+te;						
			req2.OnSuccess = function() {
				$(id).innerHTML = this.responseText;		
			}
			// przesylamy formularz
			req2.Send(url);			

	}		
	function sendCommentViolation(pic,text,id){
		// tworzymy obiekt Request		
			var req2 = mint.Request();
			
			var te = document.getElementById(text).value;
			
			var url = "loadPageToFrame.php?submit=1&mod=send_comment_violation&id="+pic+"&text="+te;						
			req2.OnSuccess = function() {
				$(id).innerHTML = this.responseText;		
			}
			// przesylamy formularz
			req2.Send(url);			

	}		
	function sendViolation2(pic,text,id){
		// tworzymy obiekt Request

			var req2 = mint.Request();
			
			var te = document.getElementById(text).value;
			
			var url = "loadPageToFrame.php?submit=1&mod=send_violation&id="+pic+"&text="+te;						
			req2.OnSuccess = function() {
				$(id).innerHTML = this.responseText;		
			}
			// przesylamy formularz
			req2.Send(url);			

	}		
	
	function checkIfBlocked(model){
		// tworzymy obiekt Request

			var req2 = mint.Request();					
			
			var url = "ajax_files/checkIfBlocked.php";						
			req2.OnSuccess = function() {				
				if(this.responseText){	
				//	alert('b');				
					blocked = true;
				}
				active(model);
			}
			// przesylamy formularz
			req2.Send(url);			

	}	
	
	function loadOnly(){
		loadOn = true;	
	}
	function sendToFriend(pic,logged){
		// tworzymy obiekt Request

			var req2 = mint.Request();
			
			if( loadOn == false){
				
				var fname = document.getElementById('fname').value;
				var femail = document.getElementById('femail').value;
				var text = document.getElementById('text').value;
				var name,email;
				
				if( logged == false ){
					name = document.getElementById('name').value;
					email = document.getElementById('email').value;
				}
				
				var url = "loadPageToFrame.php?mod=send_to_friend&pic="+pic+"&fname="+fname+"&name="+name+"&femail="+femail+"&email="+email+"&text="+text;						
				
				
			}else{				
				var url = "loadPageToFrame.php?mod=send_to_friend&logged="+logged+"&pic="+pic;
			}
			
			
			req2.OnSuccess = function() {
				$("add_favourite").innerHTML = this.responseText;		
				loadOn = false;
			}
			// przesylamy formularz
			req2.Send(url);			

	}		
	
	function loadPicturesMarks(pictures, model){
		var req = mint.Request();			
		var url = "ajax_files/loadPicturesMarks.php?model="+model+"&pictures="+pictures;		
		req.OnSuccess = function() {
			var res = this.responseText;
			a = res.split(",");
			for(i=0;i<a.length;i++){				
				b = a[i].split(" ");				
				if (box = document.getElementById("mark_"+b[0])){
					box.innerHTML = "<h3 style=margin:0px>"+b[1]+"</h3>";	
				}
			}			
		}
		req.Send(url);	
	}		
	function loadPicturesMarks2(pictures, model){
		var req = mint.Request();			
		var url = "ajax_files/loadPicturesMarks.php?model="+model+"&pictures="+pictures;		
		req.OnSuccess = function() {
			var res = this.responseText;
			a = res.split(",");
			for(i=0;i<a.length;i++){				
				b = a[i].split(" ");				
				if (box = document.getElementById("mark2_"+b[0])){
					box.innerHTML = "<h3 style=margin:0px>"+b[1]+"</h3>";	
				}
			}			
		}
		req.Send(url);	
	}		
	function getPicturesMarks(marks, model){
		
		var req2 = mint.Request();								
		var i = 0;
		var b , box, a;
		
		var url = "ajax_files/getPicturesMarks.php?model="+model+"&marks="+marks;		
	
		req2.OnSuccess = function() {	
			
			var res = this.responseText;
			//alert(res);
			if(model == 'pictures'){
			
				a = res.split("@");
				res = a[1];
				if(a[0]){
					a = a[0].split(" ");					
					box = document.getElementById("count_seen");
					box.innerHTML = a[0];				
					box = document.getElementById("count_comments");
					box.innerHTML = a[1];
				}
				return 0;	
			}
			
			//alert(res);
			a = res.split(",");
			
			for(i=0;i<a.length;i++){				
				b = a[i].split(" ");				
				box = document.getElementById("mark_"+b[0]);				
				box.innerHTML = "<h3 style=margin:0px>"+b[1]+"</h3>";	
				if(model == 'index'){
					if (box = document.getElementById("mark2_"+b[0])){
						box.innerHTML = "<h3>"+b[1]+"</h3>";	
					}					
				}
			}
		}
		
		req2.Send(url);			
		
	}					