var browserCheck=new Object();
//-------------------------------------------------------------------------------------
//2011-05-24
function browser_closePrompt()
{
	jQuery.post("index_functions/browser_test.php", {closePrompt:1}, function(data)
	{
			jQuery("#browser_check").hide("slide", { direction: "up" }, 1000);
	});	
}
//-------------------------------------------------------------------------------------
//2011-01-12
function showSearchType(documentType)
{
	var showDoctypeSearch="";
	
	jQuery.post("searchengine/kancUnimarcSearch.php?c="+uniqueTIME(), {ShowDocumentTypeParameterBox:1, documentType:documentType}, function(data)
	{
		jQuery("#refineSearchFlag").html(data);
		jQuery("#refineSearchFlag").show("fast");
	});	
}
//-------------------------------------------------------------------------------------
//2011-01-03
function addToParent(childID, parentID, galleryParam)
{
	
	jQuery.post("document_functions/document_group.php?c="+uniqueTIME(), {addToParent:1, childID: childID, parentID: parentID}, function(data)
	{	
		//sNotify.addToQueue("childID: "+childID+", parentID:"+parentID+ ", data: "+data);
		jQuery('#pub_'+childID).fadeOut(400).hide();
		openGallery_showPublished(galleryParam);
	});
}
//-------------------------------------------------------------------------------------
function MakeSortList()
{
sNotify.addToQueue("sort test");
//    jQuery("#menu-list").sortable(
		jQuery('#menu-list').nestedSortable({
			/*disableNesting: 'no-nest',*/
			forcePlaceholderSize: true,
			handle: 'div',
			items: 'li',
			opacity: .9,
			placeholder: 'placeholder',
			tabSize: 25,
			tolerance: 'pointer',
			toleranceElement: '> div'
		});
}
//-------------------------------------------------------------------------------------
//2010-11-11
function BubbleToolTip(elementID, popuptext)
{
	var popupelement=jQuery("#"+elementID);	
	var testpopup=popupelement.IsBubblePopupOpen();	//provjeravam dali je popup aktivan
	if (!testpopup)
	{
		popupelement.CreateBubblePopup(
		{
			selectable: true,
			position : 'top',
			align	 : 'center',
			innerHtml: popuptext,
			innerHtmlStyle: {
										color:'#000000', 
										'text-align':'center'
									},
			themeName: 	'azure',
			themePath: 	'styles/bubblepopup/jquerybubblepopup-theme'
		});
	}
}
//-------------------------------------------------------------------------------------
//2010-11-14
function noviUPLOADER(divid, savetype, saveID, parentID)
{			
	jQuery("#progressbar").progressBar({steps: 1, showText:true});
	var button_text = document.getElementById(divid).getAttribute('alt');
	//sNotify.addToQueue(divid+", "+savetype+", "+saveID+", "+button_text);
	//---------------------------------------------------
	var uploader = new qq.FileUploader
	({
		//element: jQuery("#"+divid).get(0),
		element: document.getElementById(divid),
		action: 'uploader/server/php.php?savetype='+savetype+'&saveID='+saveID+"&parentID="+parentID,
		allowedExtensions:[],
		sizeLimit: 0,
		multiple: true,
		maxConnections: 1,
		template: 	'<div class="qq-uploader">' + 
						'<div class="qq-upload-drop-area"><span>Ubaci datoteku</span></div>' +
						'<div class="qq-upload-button">'+button_text+'</div>' +
						'<ul class="qq-upload-list"></ul>' + 
						'</div>',		
		onSubmit: function()
		{
			uploadSessionInterval = window.setInterval(function(data) 
			{
				var session_refresh_url="uploader/session_refresh.php";
				jQuery.get(session_refresh_url);
			},60000);		
		},
		onProgress: function(id, fileName, loaded, total)
		{
			//alert("onProgres - noviuploader");
			var percentage = Math.floor(100 * parseInt(loaded) / parseInt(total));
			jQuery("#progressbar").progressBar(percentage, { showText: true }); //showText: false
		},
		onComplete: function(id, fileName, responseJSON)
		{
				//jQuery.dump(responseJSON);
			clearInterval(uploadSessionInterval);
				if (savetype=="publikacijaIMG")
					RefreshKarticePrikaza(saveID);
			
			var uspjeh = false;
			if( responseJSON.success && !responseJSON.error ) 
			{
				uspjeh = true;
			} 
			else 
			{
				uspjeh = false;
			}			
			if ( uspjeh ) 
			{
				if (savetype=="publikacijaIMG")
				{
					RefreshKarticePrikaza(saveID);
					/*
					var vracena_slika=responseJSON.relative_file_path;
					var recordID=responseJSON.record_ID;
					jQuery("#thumb_"+recordID).attr("src", vracena_slika);
					*/
				}
				if (savetype=="userIMG"){ 
					//RefreshAvatarPrikaza(saveID); 
					var image=responseJSON.relative_file_path;
					jQuery("#userAvatarImage_"+saveID).attr("src", image);
					jQuery(".qq-uploader").hide();
				}
			} 
			else 
			{
				sNotify.addToQueue("Došlo je do pogreške tijekom uploada ili spremanja!<br>Datoteka/slika nije spremljena!");
			}
		}
	});
}
//-------------------------------------------------------------------------------------
//2010-11-18
var documentINF = new Object();
function SelectTypeForUpload_BasicUpload(uploadType)
{
	documentINF.doctype=uploadType;
	//alert(uploadType);
	//alert("upload type: "+uploadType);
	noviUPLOADER('PubUploadContainer', 'publikacijaDocument', uploadType);
	jQuery('#emptyPub').show();
}
//-------------------------------------------------------------------------------------
//2010-12-06
function SelectTypeForUpload_ChildDocUpload(parentid, uploadType)
{
	documentINF.doctype=uploadType;
	documentINF.parentid=parentid;
	//alert(uploadType);
	//alert("upload type: "+uploadType);
	noviUPLOADER('PubUploadContainer', 'publikacijaChildDoc', uploadType, parentid);
	jQuery('#emptyPub').show();
}
//-------------------------------------------------------------------------------------
//2010-11-12
function BubbleToolsTooltip(elementID, docID, page)
{
	var popupelement=jQuery("#"+elementID);	
	var unique_name=uniqueTIME();
	
	var testpopup=popupelement.IsBubblePopupOpen();	//provjeravam dali je popup aktivan
	if (testpopup)
	{
		popupelement.RemoveBubblePopup();
		
		popupelement.ShowBubblePopup();
		testpopup=popupelement.IsBubblePopupOpen();
		//
	}
	if (!testpopup)
	{
		popupelement.CreateBubblePopup(
		{
			selectable: true,
			position : 'right',
			align	 : 'middle',
			innerHtml: '<img src="styles/main_theme/icon_loading_01.gif" style="border:0px; vertical-align:middle; margin-right:10px; display:inline;height:100%;" />',
			innerHtmlStyle: {
										color:'#000000', 
										'text-align':'center'
									},
			themeName: 	'azure',
			themePath: 	'styles/bubblepopup/jquerybubblepopup-theme'
		});
		testpopup=popupelement.IsBubblePopupOpen();
		
		jQuery.post("menu_functions/popup_menu.php?docid="+docID+"&page="+page+"&uniquename="+unique_name, function(data)
		{
			popupelement.SetBubblePopupInnerHtml(data, false);
			noviUPLOADER('pubFirstImage_'+unique_name, 'publikacijaIMG', docID);
		});			
	}
//---------------------------------------------
}
//-------------------------------------------------------------------------------------
//2010-11-14
function pubEDIT(pubID, elem) 
{
	jQuery(elem).children('.icon').html('<img alt="jl" src="admin/css/ajaxLoad4.gif">');
	jQuery("#prikazPodataka").load("metadata_functions/izbornik.php?pub=2&pubID="+pubID+"&c="+uniqueTIME() ,
		function() 
		{
			noviUPLOADER('avatarBTNpub', 'publikacijaIMG', pubID);
			noviUPLOADER('datotekaBTN', 'publikacija', pubID);
		}
	);
};
//-------------------------------------------------------------------------------------
//2010-09-27
 function alertMSG() // PAZI - moras HIDE samo onaj DIV s porukom -- NE parent DIV (jQuery("#alertMSG");)
 {  
	var DIV_ID = jQuery("#info_div");
	var delay_var=3000;
	
	//DIV_ID.hide().html('');
	if (DIV_ID.is(":hidden")) 
	{
		DIV_ID.show();
	}
	var topMargin = jQuery(window).scrollTop();
	DIV_ID.css("margin-top",topMargin);
	
	var div_text=jQuery("#info_div").text();
	
	div_text='<div style="padding: 0pt 0.7em; opacity:0.9; margin-top:5px; cursor:pointer; background-color:#fff;" class="ui-state-highlight ui-corner-all"><p><span style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-info"></span><strong>Info:</strong> '+div_text;
	div_text=div_text+'</p></div>';
	
	jQuery("#info_div").html(div_text);
	
	DIV_ID.slideDown(200).delay(delay_var).fadeOut(400);	
	//DIV_ID.show();
	DIV_ID.mouseenter(function() 
	{ 
		DIV_ID.stop(true, true);
	}).mouseleave(function() 
	{ 
		DIV_ID.slideDown(100).delay(500).fadeOut(200);
	});
}
//-------------------------------------------------------------------------------------
function ExpandDiv(divid)
{
	jQuery("#"+divid).slideToggle('slow');
//	alert(divid);
}
//-------------------------------------------------------------------------------------
function dodajid(sel)
{
    var text=sel.value;
    var idoffset = (text).indexOf("=", 0);
    var textid=text.substr(idoffset+1, 100);
    
    document.getElementById("linkinput").value = sel.value;
    document.getElementById("submenuid").value = textid;
	document.getElementById("textchildid").value = textid;
	

    //alert (textid);
}
//-------------------------------------------------------------------------------------
        function javaaddimage(imagepath)
        {
         // var d=document.getElementById(textarea);
          document.getElementById("textarea").value += "<div class=\"img-shadow\"><img src=\""+imagepath+"\"></div>";
          alert ("slika dodana na dno textbox-a");
        }
        function javaaddsilverimage(imagepath, name, page)
        {
         // var d=document.getElementById(textarea);
          document.getElementById("textarea").value += "<div class=\"img-shadow\">[silverlink id=\""+name+"\" page=\""+page+"\" imagepath=\""+imagepath+"\"/]<img src=\""+imagepath+"\"></a></div>";
          alert ("slika dodana na dno textbox-a");
        }
        
        function javaaddsilver(path)
        {
         // var d=document.getElementById(textarea);
          document.getElementById("textarea").value += "[silverlight page=\"0\" width=\"700\" height=\"450\" id=\""+path+"\"/]";
          alert ("silverlight dodan na dno textbox-a");
        }
//-------------------------------------------------------------------------------------        
 function showhidediv(divid)
  {
     //alert("show/hide")
     if (document.getElementById(divid).style.display != "block")
     {
         document.getElementById(divid).style.display="block";
         showdecade=1;
     }
     else if(document.getElementById(divid).style.display == "block")
     {
         document.getElementById(divid).style.display="none";
         showdecade=0;
     }
  }
//-------------------------------------------------------------------------------------
  function SilverlightToJava(page, galerija)
  {
		ChangeTranskript(page, galerija);	
		//alert("page: "+page+" galerija: "+galerija);
		return false;
  }
  
		function init()
		{
		}

		function doit()
        {
			alert(eval("document.JUpload." + document.forms["testform"].cmd.value));
		}
/*
        function startGallery()
        {
			var myGallery = new gallery(jQuery('myGallery'),
            {
				timed: true,
				defaultTransition: "fadeslideleft"
			});
        }
		window.addEvent('domready', startGallery);
		*/
//-------------------------------------------------------------------------------------
	function preLoadImages()
    {
		var imSrcAr = new Array("btn_add.gif","btn_clean.gif","btn_upload.gif","ico_file.png","ico_image.png","ico_sound.png","ico_video.png","ico_zip.png","pb_back.gif","pb_demoUload.gif","pb_empty.gif");
		var imAr = new Array(0);
		for(var i=0;i<imSrcAr.length;i++){
			imAr[imAr.length] = new Image();
			imAr[imAr.length-1].src = "uploader/imgs/"+imSrcAr[i];
		}
	}
//-------------------------------------------------------------------------------------	
        //var vault = null;
        function doOnLoad()
        {
            //preLoadImages();
            //vault = new dhtmlXVaultObject();
            //vault.setServerHandlers("uploader/UploadHandler.php", "uploader/GetInfoHandler.php", "uploader/GetIdHandler.php");
            //vault.create("vault1");
			/*
			      jQuery(function() {
          jQuery("div.bannerdiv img").lazyload({placeholder : "images/loading.gif", threshold : 500, container: jQuery("div.contentContainer")});
				});
			*/
	    }
//-------------------------------------------------------------------------------------		
function Alert ()
{
	alert ("message");
}
//-------------------------------------------------------------------------------------
function AutocompleteTest()
{
					var dataurl_autor="searchengine/autocomplete_data.php?type=autor";
					jQuery("#pretraga_autor").autocomplete(dataurl_autor);
						alert(dataurl_autor);
}
