/*Function is called from discusions*/
function Colapse2(i)
{
	if (document.getElementById("msgShort_" + i).style.display == "none")
	{
		document.getElementById("msgShort_" + i).style.display = "block";
		document.getElementById("msgLong_" + i).style.display = "none";
	}
	else
	{
		document.getElementById("msgShort_" + i).style.display = "none";
		document.getElementById("msgLong_" + i).style.display = "block";
	}
}

function SubmitForm(control, buttonName)
{
	var form = control.form;
	var input = document.createElement("input");

	input.type = "hidden";
	input.name = buttonName;
	form.appendChild(input);
	form.submit();

	return false;
}

/*Function shows actual time, is called from namedays.xsl*/
function Cas()
{
		var dnes;
		var sec = new String();
		var min = new String();

		dnes=new Date();
		var tim='';
		min = dnes.getMinutes()+"";
		sec = dnes.getSeconds()+"";

		if (sec.length == 1)
		{sec = "0"+sec}

		if (min.length == 1)
		{min = "0"+min}

		tim+=' '+dnes.getHours()+':'+min+':'+sec;

		var oTime = document.getElementById("Time");
		if(oTime)
			oTime.innerText = tim;
	}


	var myTimer = window.setInterval(Cas, 1000);

/*Function redirects to NewArticle.aspx, is called from Switch.preview.xsl*/
	/*
		url		- Url to NewArticle.aspx
		editUrl	   - Url to edit page
		encodedUrl - Encoded url
	*/
	function newArt(dialogUrl, url, editUrl, encodedUrl)
	{
		var args = new Array();
		args["url"] = url;
		args["title"] = 'Novy';
		args["height"] = "510px";
		args["width"] = "710px";
		var sFeatures = "status: no; scroll: no; help:no; dialogHeight:530px; dialogWidth:715px";

		var retVal = showModalDialog(dialogUrl, args, sFeatures);

		if (retVal != null && retVal["name"] != null)
		{
			if (retVal["type"]=="template")
			{
				editUrl += "&amp;aTp=";
			}
			else
			{
				editUrl += "&amp;aFl=";
			}

			editUrl += retVal["name"];
			editUrl += "&amp;aPh=" + retVal["path"] + "&amp;rtPg=" + encodedUrl;

			location.href=editUrl;

		}
	}

	/*Creates query string from control values, sets form action and submits form*/
	function ExpandFormQuery(evt, sender, paramNames, controls)
	{
		var form   =  GetSubmitForm();
		if(form != null)
		{
			var newUrl = ChangeFormAction(evt, sender, form.action, paramNames, controls);
		}
	}

	function SubmitForwarderAndChangeAction(e, sender, forvarder, url, paramNames, controls)
	{

		var kod;
		if (!e) var e = window.event;
		if (e.keyCode) kod = e.keyCode;
		if (kod == 13)
		{
			var s = document.getElementById(forvarder);
			if (s)
			{
				var f	  = s.form;
				var h	  = document.createElement("INPUT");
				var newUrl = CreateUrlFromControlValue(e, sender, url, paramNames, controls);

				h.type = "hidden";
				h.name = s.name;
				h.value = s.value;
				f.appendChild(h);
				e.cancelBubble = true;
				e.returnValue = false;

				f.action = newUrl;
				f.submit();
				return false;
			}
			else
			{
				alert("Submit element not found");
			}
		}
	}
	/*Creates query string from control values, sets form action and submits form*/
	function ChangeFormAction(evt, sender, url, paramNames, controls)
	{
		var form   =  GetSubmitForm();
		if(form != null)
		{
		   var newUrl = CreateUrlFromControlValue(evt, sender, url, paramNames, controls);

		   if(newUrl.length > 0)
			{
				form.action = newUrl;
				form.submit();
			}
		}
	}
	/*Gets the submit form*/
	function GetSubmitForm()
	{
		return document.forms[0];
	}
	/*Creates url from control values*/
	function CreateUrlFromControlValue(evt, sender, url, paramNames, controls)
	{
		 var values = "";

		 var arrControlsId = controls.split(",");
		 var count = 0;
		 for(var i=0; i < arrControlsId.length; i++)
		 {
			var control = document.getElementById(arrControlsId[i]);
			if(control != null)
			{
				if(count > 0)
				{
					values = values + ",";
				}

				values = values + control.value;
				count++;
			}
		 }

		 return CreateUrl(evt, sender, url, paramNames, values);

	}
	function CreateUrl(evt, sender, url, paramNames, paramValues)
	{

		var arrNames  = paramNames.split(",");
		var arrValues = paramValues.split(",");

		if(arrNames.length == arrValues.length)
		{

			var query = "";
			for(var i=0; i < arrValues.length; i++)
			{
				if(query.length > 0)
				{
					query = query + "&";
				}
				query = query + arrNames[i] + "=" + encodeURIComponent(arrValues[i]);
			}

			if(query.length > 0)
			{

				if(url.indexOf('?') > 0)
				{
					url = url.substr(0, url.indexOf('?'));
				}
				url = url + "?";
			}

			url = url + query;
		}
		return url;
	}
	function GetControlByName(controlName, controls)
		{
			if(controls != null && controlName != null)
			{
				for(var i=0;i < controls.length; i++)
				{
					var control = controls[i];
					var name	= control.getAttribute('name');

					if(name != null)
					{
						if(name.toLowerCase().indexOf(controlName.toLowerCase()) >= 0)
						{
							return control;
						}
					}
				}
			}
			return null;
		}
		function URLencode(sStr) {
			 return escape(sStr)
			 }
	/*Function is called from CatalogSearch.xsl*/
	function ClearComboBox(id)
	{
		var cb = document.getElementById(id);
		while (cb.options.length > 0)
			cb.remove(0);
	}
	/*Function is called from CatalogSearch.xsl*/
	function AddOption(strComboBoxId, strCode, strText)
	{
		var cb = document.getElementById(strComboBoxId);
		var oOption = new Option(strText, strCode);
		cb.options.add(oOption);
	}
	/*Function is called from CatalogSearch.xsl*/
	function FillProductGroups(evt, sender, productGroupControlName, itemCategoryControlName, selectText)
	{
		ClearComboBox(productGroupControlName);
		var cbItemCategory = document.getElementById(itemCategoryControlName);
		var cbProductGroup = document.getElementById(productGroupControlName);

		AddOption(productGroupControlName, '', selectText);

		if (0 < cbItemCategory.selectedIndex)
		{
			var nCount = GetItemCategoryField(cbItemCategory.selectedIndex - 1, 2);
			var nIndex = GetItemCategoryField(cbItemCategory.selectedIndex - 1, 3);

			var i;
			for (i = 0; i < nCount; i++)
				AddOption(productGroupControlName, GetProductGroupField(nIndex + i, 0), GetProductGroupField(nIndex + i, 1));
		}
	}
	/*Function is called from item.preview*/
	function SetFirstChildStyle(parent, childTagName, childStyle)
	{
		if(parent != null && parent.childNodes != null)
		{
			for(var i=0; i < parent.childNodes.length;i++)
			{
				var childNode = parent.childNodes[i];
				if(childNode.tagName &&
					childNode.tagName.toLowerCase() == childTagName.toLowerCase())
				{
					childNode.className = childStyle;
					break;
				}
			}
		}
	}
	function getProps(obj)
	{
		var s = "";
		for(x in obj)
		{
			s += x + "\t";
		}
		alert(s);
	}