/*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 is called from discusions*/
function SubmitForm(button)
{
	var oBtn = document.getElementById(button);
	var oTmp = document.getElementById("tmpHidden");
	var strTemp;

	strTemp = oTmp.name;
	oTmp.name = oBtn.name;
	oBtn.name = strTemp;

	document.getElementById("_ctl0").submit();
}
/*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 features  = "status: yes; scroll: no; help:no; dialogHeight:565px; dialogWidth:715px"; 
		//var features  = "width=720,height=570,toolbars=0,resizable=0"; 
		//var retVal    = showModalDialog(url, features);
		var args = new Array();		
		args["url"] = url;
		args["title"] = 'Novy';
		args["height"] = "500px";
		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] + "=" + escape(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 SearchTree.xsl*/
    function ClearComboBox(id)
    {
        var cb = document.getElementById(id);
        while (cb.options.length > 0)
	        cb.remove(0);
    }
    /*Function is called from SearchTree.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 SearchTree.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(i, 0), GetProductGroupField(i, 1));		    					
	    }
    }