/**
 * @author Peter Pajchl
 * @copyright Peter Pajchl
 * All Rights Reserved
 */

function createAjaxRequest() {
		
  	var XMLHttpRequestObject = false;
	
	if(window.XMLHttpRequest) {
		XMLHttpRequestObject = new XMLHttpRequest();
	}
	else if(window.ActiveXObject) {
		XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else {
		alert("It seems that your browser doesn't support ajax.");
		exit(1);
	}
		
	return XMLHttpRequestObject;
}

//////////////////////////////////////////////////////////////////////////////////////////////////

// ARCHIVED STORIES
function searchArchive(year,month) {
	
	year = escape(year);
	month = escape(month);
			
	var serverpage="/archive.php?year=" + year + "&month=" + month;
	var myTarget = document.getElementById("targetDiv");
	
	var xmlhttp = createAjaxRequest();
	xmlhttp.open("GET",serverpage,true);
	xmlhttp.onreadystatechange=function() {

		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			myTarget.innerHTML = xmlhttp.responseText;
		}
	};
	xmlhttp.send(null);
}

//////////////////////////////////////////////////////////////////////////////////////////////////

// SEARCH THROUGH FULLTEXT
function searchFulltext() {
	
	var query=document.getElementById('query').value;
	var qField=document.getElementById('qField').value;
	
	document.getElementById('query').value="";
			
	query = escape(query);
			
	var serverpage="/search.php?q=" + query + "&qField=" + qField;
	var myTarget = document.getElementById("targetDiv");
	
	var xmlhttp = createAjaxRequest();
	xmlhttp.open("GET",serverpage,true);
	xmlhttp.onreadystatechange=function() {

		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			myTarget.innerHTML = xmlhttp.responseText;
		}
	};
	xmlhttp.send(null);
}

//////////////////////////

currentPic=1;
			
        	function switchImage(imagePath, imageCaption) {
				
        		var newsImage=document.getElementById('newsImage');
				newsImage.src="/articleThumbCreator.php?path=" + imagePath;
				newsImage.setAttribute("alt", imageCaption);
				
				var imageCaptionTitle = document.getElementById('imageCaptionTitle');
				imageCaptionTitle.innerHTML = imageCaption;
			}
			
			function switchPhoto(imagePath,imageCaption) {
				
				var photoImage=document.getElementById('reportImage');
				var photoCaption=document.getElementById('imageCaption');
				
				photoImage.src="/reportBThumbCreator.php?path=" + imagePath;
				photoImage.setAttribute("alt", imageCaption);
				
				photoCaption.innerHTML=imageCaption;
			}
			
			function switchPhotoNext()
			{
				if (currentPic < (myImages.length-1)) {
					var photoImage = document.getElementById('reportImage');
					var photoCaption = document.getElementById('imageCaption');
					var imgCounter = document.getElementById('imgCounter');
					
					photoImage.src = "/reportBThumbCreator.php?path=" + myImages[currentPic+1];
					photoImage.setAttribute("alt", myCaptions[currentPic + 1]);
					
					photoCaption.innerHTML = myCaptions[currentPic + 1];
					currentPic+=1;
					imgCounter.innerHTML = (currentPic)+'/'+(myImages.length-1);
					
				}
			}
			
			function switchPhotoPrevious()
			{
				if (currentPic > 1) {
					var photoImage = document.getElementById('reportImage');
					var photoCaption = document.getElementById('imageCaption');
					var imgCounter = document.getElementById('imgCounter');
					
					photoImage.src = "/reportBThumbCreator.php?path=" + myImages[currentPic - 1];
					photoImage.setAttribute("alt", myCaptions[currentPic - 1]);
					
					photoCaption.innerHTML = myCaptions[currentPic -1];
					currentPic-=1;
					imgCounter.innerHTML = (currentPic)+'/'+(myImages.length-1);
					
				}
			}

