function initializeFancyBoxImages()
{
	jQuery("a.fancyBoxImage").fancybox({
		'zoomSpeedIn':	500,
		'zoomSpeedOut':	300,
		'overlayShow':	true,
		'hideOnContentClick': true
	});
}

function v()
{
	void(null);
}

function popup(mylink, windowname, width, height){
	if (!window.focus) {
		return true;
	}
	var href;
	if (typeof(mylink) == 'string') {
		href = mylink;
	} else {
	   href=mylink.href;
	}
	window.open(href, windowname, 'width='+width+',height='+height+',scrollbars=yes');
	return false;
}

function submitForm(sFormName)
{
	jQuery('#' + sFormName + 'Submit').hide();
	jQuery('#' + sFormName).submit();
}

function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}

function externalLinks() 
{ 
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("a"); 
	for (var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
		}
	}	
} 

/*** JQUERY ***/
jQuery.noConflict();
jQuery(document).ready(function() {
	externalLinks();
	/*** FANCY BOX ***/
	initializeFancyBoxImages();
});

//ENTRY USERS
function setEntryUsers(iEntryId)
{
//	showHideLoading();
	divSetEntryUsers = jQuery("#divSetEntryUsers_" + iEntryId);
	var hrefSetUsers = jQuery('#addEntryUser_' + iEntryId);
	jQuery.ajax({
		method: "get",
		url: "ajax/entries/setEntryUsers.php",data: "entryId=" + iEntryId + "&random=" + Math.random(),
		beforeSend: function(){
			toggleAjaxLoader('eventAjaxLoading_' + iEntryId);
			jQuery(hrefSetUsers).hide();
			}, //show loading just when link is clicked
//		complete: function(){ jQuery("#loading").hide("fast");}, //stop showing loading when the process is complete
		success: function(html){ //so, if data is retrieved, store it in html
//			jQuery(".content").show("slow"); //animation
			toggleAjaxLoader('eventAjaxLoading_' + iEntryId, true);
			jQuery(hrefSetUsers).show();			
			jQuery(divSetEntryUsers).html(html); //show the html inside .content div
//			getEntryUsers(iEntryId);
		}
	}); //close jQuery.ajax(
}

function toggleAjaxLoader(hjaxLoader, bHide)
{
	var objAjaxLoader = jQuery('#' + hjaxLoader);
	if (bHide) {
		jQuery(objAjaxLoader).hide();
	} else {
		jQuery(objAjaxLoader).show();
	}
}

/*** COMMENTS ***/

function getComments(sTargetDiv, iPage, sSearchKey, iSearchValue) // target div, strona, czego mo szukac, id tego szukania
{
	var divComments = jQuery('.' + sTargetDiv);
	jQuery.ajax({
		method: "get",
		url: "ajax/comments/getComments.php",
		data: "page=" + iPage + "&key=" + sSearchKey + "&value=" + iSearchValue + "&random=" + Math.random(),
		beforeSend: function(){
			showHidePreloader(sTargetDiv);
		},
		success: function(html) {
			showHidePreloader(sTargetDiv, true);
			jQuery(divComments).html(html);
		}
	}); //close jQuery.ajax(
}

/** TOGGLE PRELOADER ***/
function showHidePreloader(sTargetDiv, bHide)
{
	if (bHide == 'undefined') {
		bHide = false;
	}
	var iDivContentHeight = jQuery('div.' + sTargetDiv).height();
	var divPreloader = jQuery('div.preloaderApla_' + sTargetDiv);
	jQuery(divPreloader).height(iDivContentHeight);
	if (!bHide) {
		jQuery(divPreloader).show();
	} else {
		jQuery(divPreloader).hide();
	}
}

/*** END JQUERY ***/


