﻿$(document).ready(function(){
	//MAIN MENU
	$("#menu > li > ul").each(function(index, item){
		var th = $(this);
		th.parent().addClass("unpack");
	});
	$("#menu > li:last").addClass("last");

	//QUICK SEARCH
	$(".cat-fast-search").each(function(index, item){
		var th = $(this);
		th.bind("change", function(){
			var sText = th.val();
			if(sText!="")
			{
				document.location = sText;
			}
		});
	});

	var oFindIn = GetQueryStringParam("catsrfield");
	if(oFindIn!="")
	{
		oFindIn		= oFindIn.split("|");
		var oFindWhat 	= GetQueryStringParam("catsrtext").split("|");
		for(var i=0; i<oFindIn.length;i++)
		{
			$("#CatField" + oFindIn[i] + " > option[value='" + decodeURI(oFindWhat[i]) + "']").attr("selected","true");
		}
	}
	var oFindIn = $(".CatDetail");
	if(oFindIn.length>0)
	{	
		$(".oddil" + (oFindIn.attr("id").replace("CD","")) + "").attr("selected","true");
	}

	//PHOTOGALLERY
	$('#gallery').galleryView({
		panel_width: 575,
		panel_height: 400,
		frame_width: 80,
		frame_height: 80,
		pause_on_hover: true
	});
});

function SearchCatalog()
{
	var sField = new Array();
	var sText = new Array();
	$(".cat-fast-search-complex").each(function(index, item){
		var th = $(this);
		var v = th.val();
		if(v!="")
		{
			sText.push(encodeURI(v));
			sField.push(th.attr("id").replace("CatField",""));
		}
	});
	if(sText.length>0)
	{
		document.location="/databaze-skolek-a-pripravek/?catsrfield=" + sField.join("|") + "&catsrtext=" + sText.join("|");
	}
}

function GetQueryStringParam(name)
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if(results == null)
	{
		return "";
	}
	else
	{
    		return results[1];
	}
}

function saveBody()
{
	$(".ReplyText").val($("#Editor").val());
	return true;
}

function ShowArticleImage(idF,w,h,t)
{
	var wa = window.open("/ShowFullThumbNail.aspx?id_file=" + idF, "APDFullImage", "scrollbars=no,status=yes")
	void(0);
	return false;
}
