function setSearchForm() {
	YAHOO.util.Dom.get('treeFullPath').innerHTML = '';
	
	var AjaxObject = {

		handleSuccess:function(o){
			this.container.innerHTML = o.responseText;
		},

		handleFailure:function(o){
			// Failure handler
			this.container.innerHTML = 'Παρουσιάστηκε σφάλμα...';
		},

		startRequest:function() {
			this.container.innerHTML = '<img src="modules/Ergologic_client/images/loading.gif" /> '+YAHOO.tbekos.please_wait+'...';
			YAHOO.util.Connect.asyncRequest('POST', 'modules.php?name=Ergologic_client&file=search/form', callback);
		}
	};

	/*
	 * Define the callback object for success and failure
	 * handlers as well as object scope.
	 */
	var callback =
	{
		success:AjaxObject.handleSuccess,
		failure:AjaxObject.handleFailure,
		scope: AjaxObject
	};

	AjaxObject.container = YAHOO.util.Dom.get('content');
	
	// Start the transaction.
	AjaxObject.startRequest();
}

function searchFormSubmit(oForm) {
	if (oForm.search_key.value == '') {
		alert('Συμπληρώστε κάτι προς αναζήτηση...');
		return;
	}
	
	var _sFormData = '';
	for (var i=0; i<oForm.elements.length; i++){
		oElement = oForm.elements[i];
		oDisabled = oElement.disabled;
		oName = oElement.name;
		oValue = oElement.value;

		// Do not submit fields that are disabled or
		// do not have a name attribute value.
		if(!oDisabled && oName)
		{
			switch(oElement.type)
			{
				case 'select-one':
				case 'select-multiple':
					for(var j=0; j<oElement.options.length; j++){
						if(oElement.options[j].selected){
							if(window.ActiveXObject){
								_sFormData += encodeURIComponent(oName) + '=' + encodeURIComponent(oElement.options[j].attributes['value'].specified?oElement.options[j].value:oElement.options[j].text) + '&';
							}
							else{
								_sFormData += encodeURIComponent(oName) + '=' + encodeURIComponent(oElement.options[j].hasAttribute('value')?oElement.options[j].value:oElement.options[j].text) + '&';
							}
						}
					}
					break;
				case 'radio':
				case 'checkbox':
					if(oElement.checked){
						_sFormData += encodeURIComponent(oName) + '=' + encodeURIComponent(oValue) + '&';
					}
					break;
				case 'file':
					// stub case as XMLHttpRequest will only send the file path as a string.
				case undefined:
					// stub case for fieldset element which returns undefined.
				case 'reset':
					// stub case for input type reset button.
				case 'button':
					// stub case for input type button elements.
					break;
				case 'submit':
					break;
				default:
					_sFormData += encodeURIComponent(oName) + '=' + encodeURIComponent(oValue) + '&';
			}
		}
	}
	_sFormData = _sFormData.substr(0, _sFormData.length - 1);
	
	YAHOO.util.History.navigate('view','qur-'+_sFormData);
}

function getSearchResults(queryData) {
	YAHOO.util.Dom.get('treeFullPath').innerHTML = '';
	
	var AjaxObject = {
		handleSuccess:function(o){
			this.container.innerHTML = o.responseText;
			new YAHOO.widget.TabView('search_results');
			Shadowbox.setup();
		},

		handleFailure:function(o){
			// Failure handler
			this.container.innerHTML = 'Παρουσιάστηκε σφάλμα...';
		},

		startRequest:function() {
			this.container.innerHTML = '<img src="modules/Ergologic_client/images/loading.gif" /> '+YAHOO.tbekos.please_wait+'...';
			YAHOO.util.Connect.asyncRequest('POST', 'modules.php?name=Ergologic_client&file=search/search', callback, this.data);
		}

	};

	/*
	 * Define the callback object for success and failure
	 * handlers as well as object scope.
	 */
	var callback =
	{
		success:AjaxObject.handleSuccess,
		failure:AjaxObject.handleFailure,
		scope: AjaxObject
	};

	AjaxObject.data = queryData;
	AjaxObject.container = YAHOO.util.Dom.get('content');
	
	// Start the transaction.
	AjaxObject.startRequest();
}

// ==================================================== PAGING SEARCH RESULTS ==================================================
function getSearchResultsCat(queryData, page) {
	YAHOO.util.Dom.get('treeFullPath').innerHTML = '';
	
	var AjaxObject = {
		handleSuccess:function(o){
			this.container.innerHTML = o.responseText;
		},

		handleFailure:function(o){
			// Failure handler
			this.container.innerHTML = 'Παρουσιάστηκε σφάλμα...';
		},

		startRequest:function() {
			this.container.innerHTML = '<img src="modules/Ergologic_client/images/loading.gif" /> Παρακαλώ περιμένετε...';
			YAHOO.util.Connect.asyncRequest('POST', 'modules.php?name=Ergologic_client&file=search/search', callback, this.data);
		}

	};

	/*
	 * Define the callback object for success and failure
	 * handlers as well as object scope.
	 */
	var callback =
	{
		success:AjaxObject.handleSuccess,
		failure:AjaxObject.handleFailure,
		scope: AjaxObject
	};

	AjaxObject.data = 'cat=only&page='+page + queryData;
	AjaxObject.container = YAHOO.util.Dom.get('categories_search_results');
	
	// Start the transaction.
	AjaxObject.startRequest();
}

function getSearchResultsAnt(queryData, page) {
	YAHOO.util.Dom.get('treeFullPath').innerHTML = '';
	
	var AjaxObject = {
		handleSuccess:function(o){
			this.container.innerHTML = o.responseText;
		},

		handleFailure:function(o){
			// Failure handler
			this.container.innerHTML = 'Παρουσιάστηκε σφάλμα...';
		},

		startRequest:function() {
			this.container.innerHTML = '<img src="modules/Ergologic_client/images/loading.gif" /> Παρακαλώ περιμένετε...';
			YAHOO.util.Connect.asyncRequest('POST', 'modules.php?name=Ergologic_client&file=search/search', callback, this.data);
		}

	};

	/*
	 * Define the callback object for success and failure
	 * handlers as well as object scope.
	 */
	var callback =
	{
		success:AjaxObject.handleSuccess,
		failure:AjaxObject.handleFailure,
		scope: AjaxObject
	};

	AjaxObject.data = 'ant=only&page='+page + queryData;
	AjaxObject.container = YAHOO.util.Dom.get('antikeimena_search_results');
	
	// Start the transaction.
	AjaxObject.startRequest();
}

function getSearchResultsTek(queryData, page) {
	YAHOO.util.Dom.get('treeFullPath').innerHTML = '';
	
	var AjaxObject = {
		handleSuccess:function(o){
			this.container.innerHTML = o.responseText;
			Shadowbox.setup();
		},

		handleFailure:function(o){
			// Failure handler
			this.container.innerHTML = 'Παρουσιάστηκε σφάλμα...';
		},

		startRequest:function() {
			this.container.innerHTML = '<img src="modules/Ergologic_client/images/loading.gif" /> Παρακαλώ περιμένετε...';
			YAHOO.util.Connect.asyncRequest('POST', 'modules.php?name=Ergologic_client&file=search/search', callback, this.data);
		}

	};

	/*
	 * Define the callback object for success and failure
	 * handlers as well as object scope.
	 */
	var callback =
	{
		success:AjaxObject.handleSuccess,
		failure:AjaxObject.handleFailure,
		scope: AjaxObject
	};

	AjaxObject.data = 'tek=only&page='+page + queryData;
	AjaxObject.container = YAHOO.util.Dom.get('tekmiria_search_results');
	
	// Start the transaction.
	AjaxObject.startRequest();
}

// =================================== CHRONICLES ===================================
function getChroniclesResults(pid) {
	YAHOO.util.Dom.get('treeFullPath').innerHTML = '';
	
	$('#chroniclesTreeDiv').hide('slow');
	
	var AjaxObject = {
		handleSuccess:function(o){
			this.container.innerHTML = o.responseText;
			new YAHOO.widget.TabView('search_results');
			Shadowbox.setup();
		},

		handleFailure:function(o){
			// Failure handler
			this.container.innerHTML = 'Παρουσιάστηκε σφάλμα...';
		},

		startRequest:function() {
			this.container.innerHTML = '<img src="modules/Ergologic_client/images/loading.gif" /> '+YAHOO.tbekos.please_wait+'...';
			YAHOO.util.Connect.asyncRequest('POST', 'modules.php?name=Ergologic_client&file=search/chronicles', callback, this.data);
		}

	};

	/*
	 * Define the callback object for success and failure
	 * handlers as well as object scope.
	 */
	var callback =
	{
		success:AjaxObject.handleSuccess,
		failure:AjaxObject.handleFailure,
		scope: AjaxObject
	};

	AjaxObject.data = 'antikeimeno=on&tekmirio=on&periodos_id='+pid;
	if (YAHOO.util.Dom.get('chronicles_results')) {
		AjaxObject.container = YAHOO.util.Dom.get('chronicles_results');
		YAHOO.util.Dom.get('chroniclesButton').style.display = '';
		
	} else {
		YAHOO.util.Dom.get('content').innerHTML = '<div id="chroniclesTreeDiv"></div><div id="chroniclesButton" onclick="YAHOO.util.History.navigate(\'view\',\'chronicles\');" style="cursor: pointer;">&lt;&lt;</div><div id="chronicles_results"></div>';
	}
	AjaxObject.container = YAHOO.util.Dom.get('chronicles_results');
	
	// Start the transaction.
	AjaxObject.startRequest();
}

// ==================================================== PAGING CHRONICLES RESULTS ==================================================
function getChroniclesResultsAnt(pid, page) {
	YAHOO.util.Dom.get('treeFullPath').innerHTML = '';
	
	$('#chroniclesTreeDiv').hide('slow');
	
	var AjaxObject = {
		handleSuccess:function(o){
			this.container.innerHTML = o.responseText;
		},

		handleFailure:function(o){
			// Failure handler
			this.container.innerHTML = 'Παρουσιάστηκε σφάλμα...';
		},

		startRequest:function() {
			this.container.innerHTML = '<img src="modules/Ergologic_client/images/loading.gif" /> '+YAHOO.tbekos.please_wait+'...';
			YAHOO.util.Connect.asyncRequest('POST', 'modules.php?name=Ergologic_client&file=search/chronicles', callback, this.data);
		}

	};

	/*
	 * Define the callback object for success and failure
	 * handlers as well as object scope.
	 */
	var callback =
	{
		success:AjaxObject.handleSuccess,
		failure:AjaxObject.handleFailure,
		scope: AjaxObject
	};

	AjaxObject.data = 'ant=only&periodos_id='+pid+'&page='+page;
	AjaxObject.container = YAHOO.util.Dom.get('antikeimena_search_results');
	
	// Start the transaction.
	AjaxObject.startRequest();
}

function getChroniclesResultsTek(pid, page) {
	YAHOO.util.Dom.get('treeFullPath').innerHTML = '';
	
	$('#chroniclesTreeDiv').hide('slow');
	
	var AjaxObject = {
		handleSuccess:function(o){
			this.container.innerHTML = o.responseText;
		},

		handleFailure:function(o){
			// Failure handler
			this.container.innerHTML = 'Παρουσιάστηκε σφάλμα...';
		},

		startRequest:function() {
			this.container.innerHTML = '<img src="modules/Ergologic_client/images/loading.gif" /> '+YAHOO.tbekos.please_wait+'...';
			YAHOO.util.Connect.asyncRequest('POST', 'modules.php?name=Ergologic_client&file=search/chronicles', callback, this.data);
		}

	};

	/*
	 * Define the callback object for success and failure
	 * handlers as well as object scope.
	 */
	var callback =
	{
		success:AjaxObject.handleSuccess,
		failure:AjaxObject.handleFailure,
		scope: AjaxObject
	};

	AjaxObject.data = 'tek=only&periodos_id='+pid+'&page='+page;
	AjaxObject.container = YAHOO.util.Dom.get('tekmiria_search_results');
	
	// Start the transaction.
	AjaxObject.startRequest();
}

// =================================== NEWS ======================================
function getNews(id) {
	YAHOO.util.Dom.get('treeFullPath').innerHTML = '';

	var AjaxObject = {
		handleSuccess:function(o){
			this.container.innerHTML = o.responseText;
		},

		handleFailure:function(o){
			// Failure handler
			this.container.innerHTML = 'Παρουσιάστηκε σφάλμα...';
		},

		startRequest:function() {
			this.container.innerHTML = '<img src="modules/Ergologic_client/images/loading.gif" /> '+YAHOO.tbekos.please_wait+'...';
			var data = 'id='+id;
			YAHOO.util.Connect.asyncRequest('POST', 'modules.php?name=Ergologic_client&file=ajax/news', callback, data);
		}
	};

	/*
	 * Define the callback object for success and failure
	 * handlers as well as object scope.
	 */
	var callback =
	{
		success:AjaxObject.handleSuccess,
		failure:AjaxObject.handleFailure,
		scope: AjaxObject
	};

	AjaxObject.container = YAHOO.util.Dom.get('content');
	
	// Start the transaction.
	AjaxObject.startRequest();
}

function getTekmiriaByAntPer(img, antId, perId, container) {
	var AjaxObject = {
		handleSuccess:function(o){
			this.container.innerHTML = o.responseText;
			Shadowbox.setup();
		},

		handleFailure:function(o){
			// Failure handler
			this.container.innerHTML = 'Παρουσιάστηκε σφάλμα...';
		},

		startRequest:function() {
			this.container.innerHTML = '<img src="modules/Ergologic_client/images/loading.gif" /> '+YAHOO.tbekos.please_wait+'...';
			var data = 'antid='+antId+'&perid='+perId;
			YAHOO.util.Connect.asyncRequest('POST', 'modules.php?name=Ergologic_client&file=ajax/tekmiriaByAntikeimenoPeriodo', callback, data);
		}
	};

	/*
	 * Define the callback object for success and failure
	 * handlers as well as object scope.
	 */
	var callback =
	{
		success:AjaxObject.handleSuccess,
		failure:AjaxObject.handleFailure,
		scope: AjaxObject
	};

	AjaxObject.container = YAHOO.util.Dom.get(container);
	
	if (AjaxObject.container.innerHTML == '') {
		AjaxObject.container.style.display = '';
		img.src = "modules/Ergologic_client/images/minus.png";
		
		// Start the transaction.
		AjaxObject.startRequest();
	} else {
		if (AjaxObject.container.style.display == 'none') {
			AjaxObject.container.style.display = '';
			img.src = "modules/Ergologic_client/images/minus.png";
		} else {
			AjaxObject.container.style.display = 'none';
			img.src = "modules/Ergologic_client/images/plus.png";
		}
	}
}

// =================================== STATIC ======================================
function getStatic(id, page) {
	YAHOO.util.Dom.get('treeFullPath').innerHTML = '';
	
	var AjaxObject = {
		handleSuccess:function(o){
			this.container.innerHTML = o.responseText;
		},

		handleFailure:function(o){
			// Failure handler
			this.container.innerHTML = 'Παρουσιάστηκε σφάλμα...';
		},

		startRequest:function() {
			this.container.innerHTML = '<img src="modules/Ergologic_client/images/loading.gif" /> '+YAHOO.tbekos.please_wait+'...';
			var data = 'id='+id+'&page='+page;
			YAHOO.util.Connect.asyncRequest('POST', 'modules.php?name=Ergologic_client&file=ajax/static', callback, data);
		}
	};

	/*
	 * Define the callback object for success and failure
	 * handlers as well as object scope.
	 */
	var callback =
	{
		success:AjaxObject.handleSuccess,
		failure:AjaxObject.handleFailure,
		scope: AjaxObject
	};

	AjaxObject.container = YAHOO.util.Dom.get('content');
	
	// Start the transaction.
	AjaxObject.startRequest();
}

function refreshRndImgGal(img) {
	var AjaxObject = {
		handleSuccess:function(o){
			this.container.innerHTML = o.responseText;
			
			// set shadowbox for the new images
			Shadowbox.setup();
			
			img.src = "modules/Ergologic_client/images/refresh.png"; 
			// Delay ...to avoid abuse of this button
			setTimeout(function(){img.onclick = function(){refreshRndImgGal(img);}}, 500); // half second
		},

		handleFailure:function(o){
			// Failure handler
		},

		startRequest:function() {
			img.onclick = function(){};
			img.src = "modules/Ergologic_client/images/loading.gif";
			YAHOO.util.Connect.asyncRequest('POST', 'modules.php?name=Ergologic_client&file=ajax/rndimggal', callback);
		}
	};

	/*
	 * Define the callback object for success and failure
	 * handlers as well as object scope.
	 */
	var callback =
	{
		success:AjaxObject.handleSuccess,
		failure:AjaxObject.handleFailure,
		scope: AjaxObject
	};

	AjaxObject.container = YAHOO.util.Dom.get('rnd_imgal');
	
	// Start the transaction.
	AjaxObject.startRequest();
}

// =================================== LATEST SUBMISSIONS ======================================
function getLatest(page) {
	YAHOO.util.Dom.get('treeFullPath').innerHTML = '';

	var AjaxObject = {
		handleSuccess:function(o){
			this.container.innerHTML = o.responseText;
		},

		handleFailure:function(o){
			// Failure handler
			this.container.innerHTML = 'Παρουσιάστηκε σφάλμα...';
		},

		startRequest:function() {
			this.container.innerHTML = '<img src="modules/Ergologic_client/images/loading.gif" /> Παρακαλώ περιμένετε...';
			var data = (page) ? 'page='+page : '';
			YAHOO.util.Connect.asyncRequest('POST', 'modules.php?name=Ergologic_client&file=ajax/latest', callback, data);
		}
	};

	/*
	 * Define the callback object for success and failure
	 * handlers as well as object scope.
	 */
	var callback =
	{
		success:AjaxObject.handleSuccess,
		failure:AjaxObject.handleFailure,
		scope: AjaxObject
	};

	AjaxObject.container = YAHOO.util.Dom.get('content');
	
	// Start the transaction.
	AjaxObject.startRequest();
}
// by Tasos Bekos, tbekos (at) gmail


