// vygenerovani FCK Editoru	
function generateFckArea(bCustomisedProject, bDhtmlDescription){
	fck_toolbar_name = fck_useCustomToolbar ? 'CustomToolbar' : 'NetDog';

	if ((null != document.getElementById('textaBody')  && document.getElementById('textaBody').type == 'textarea')) {
		var oFCKeditor_textaBody = new FCKeditor('textaBody','','', fck_toolbar_name);
		oFCKeditor_textaBody.BasePath = 'resources/fckEditor/';
		oFCKeditor_textaBody.Config["AutoDetectLanguage"] = false ;
		oFCKeditor_textaBody.Config["DefaultLanguage"] = fck_language;
		if (fck_custom_styles) {
			oFCKeditor_textaBody.Config["EditorAreaCSS"] = fck_editorarea_css ;
			oFCKeditor_textaBody.Config["StylesXmlPath"] = fck_styles_xml ;
			oFCKeditor_textaBody.Config["TemplatesXmlPath"] = fck_templates ;
			oFCKeditor_textaBody.Config['CustomConfigurationsPath'] = fck_config_url ;
			oFCKeditor_textaBody.Config['ForcePasteAsPlainText'] = fck_paste_as_text ;
		}
		if (bCustomisedProject) {
			oFCKeditor_textaBody.Config["PluginsPath"] = '../../../../resources/fckEditor/plugins/';
			oFCKeditor_textaBody.Config["LinkBrowserURL"] = '../../../../../../resources/fckEditor/browser/browser.html?Connector=connectors/connector.php';
		}
		oFCKeditor_textaBody.ReplaceTextarea() ;
	}
	if (bDhtmlDescription) {
		if ((null != document.getElementById('textaDescription') && document.getElementById('textaDescription').type == 'textarea')){
			var oFCKeditor_textaDescription = new FCKeditor('textaDescription','','','NetDog');
			oFCKeditor_textaDescription.BasePath = 'resources/fckEditor/';
			oFCKeditor_textaDescription.Config["AutoDetectLanguage"] = false ;
			oFCKeditor_textaDescription.Config["DefaultLanguage"] = fck_language;
			if (fck_custom_styles) {
				oFCKeditor_textaDescription.Config["EditorAreaCSS"] = fck_editorarea_css ;
				oFCKeditor_textaDescription.Config["StylesXmlPath"] = fck_styles_xml ;
				oFCKeditor_textaDescription.Config["TemplatesXmlPath"] = fck_templates ;
			}
			if (bCustomisedProject) {
				oFCKeditor_textaDescription.Config["PluginsPath"] = '../../../../resources/fckEditor/plugins/';
				oFCKeditor_textaDescription.Config["LinkBrowserURL"] = '../../../../../../resources/fckEditor/browser/browser.html?Connector=connectors/connector.php';
			}
			oFCKeditor_textaDescription.ReplaceTextarea() ;
		}		
	}
}
	
function addAuthor() {
	var sel = document.getElementById('selAuthors');
	var klic = sel.options[sel.selectedIndex].value;
	var hodnota = sel.options[sel.selectedIndex].text;
	
	var upperSel = window.opener.document.getElementById('selAuthors[]');
	
	if(window.opener.findByValue(upperSel,klic) == -1) {
		window.opener.appendOption(upperSel,klic,hodnota);
	}
	window.opener.selectOneByValue(upperSel,klic);  
}

/*pridavani hodnot volitelnych vlastnosti*/
function addAlternateValue() {
	var translatable = document.getElementById('selTranslatable');
	var translate = translatable.options[translatable.selectedIndex].value;
	var nazev = document.getElementById('txtName').value;
		
	window.opener.prepareFormAlternateValue(nazev, translate);
	
	window.close();
}

function prepareFormAlternateValue(nazev, kPrekladu) {
	var sel = document.getElementById('selAlternateValues[]');
	var newValues = document.getElementById('newAlternateValues');
	var count = document.getElementById('newValuesCount');
	
	count.value = parseInt(count.value) + 1;
	var newId = 'x' + count.value;
	appendOption(sel, newId, nazev);
	
	newValues.value += newId + '|' + nazev + '|' + kPrekladu + ';;';
	
	selectOneByValue(sel, newId);
}
/*konec pridavani*/

/*editace hodnot volitelnych vlastnosti*/
function editAlternateValue() {
	var nazev = document.getElementById('txtName').value;
	var id = document.getElementById('hidIdAlternateValue').value;
	
	window.opener.upateFormAlternateValue(id, nazev);
	
	window.close();
}

function upateFormAlternateValue(id, nazev){
	var sel = document.getElementById('selAlternateValues[]');
	for (i = 0; i < sel.options.length; i++) {
		if (sel.options[i].value == id) {
			sel.options[i].text = nazev;
		}
	}
	
	var editedValues = document.getElementById('editedAlternateValues');
	editedValues.value += id + '|' + nazev + ';;';
}
/*konec editace*/


/* Funkce zmeni oznaceni variant podle vybrane moznosti.
* @param aSelect Odkaz na HTML prvek <SELECT>
* @param aSize Pocet variant ke zmene.
* pozor Pro Netscape a Mozillu je nutne mit u prvku
*/
function zmenOznaceniVariant(aSelect, aSize) {
  selectedValue = aSelect.options[aSelect.selectedIndex].value;

  if (selectedValue == 'ciselne') 
    start = 49;
  if (selectedValue == 'velkaPismena') 
    start = 65;	
  if (selectedValue == 'malaPismena') 
    start = 97;		
  
  var str = "";
  var oznaceni = 0;
  for (var i = 0; i < aSize; i++) {

	  var elem = document.getElementById('oznaceni['+i+']');
	  
	  if (elem != null) {
	    elem.value = String.fromCharCode(oznaceni + start);
		oznaceni++; 
	  } else {
	    aSize++;
	  }
  }
 
}	

/* 
* Nastvuje metodu akce a popripade jeji parametr
*
*/
function runMethod(aMethodName, aParametr){
  element = changeElementValue('method',aMethodName);
  if (aParametr != null)
  	changeElementValue('methodParametr', aParametr);
  
  if(element != null) 
    element.form.submit();
}


function runMethodDelete(aMethodName, aParametr, aText) {
  if (confirmDialog(aText)) {
	  runMethod(aMethodName, aParametr);  
  }
}

/*
 * Funkce pro simulaci target="_blank" pres class="popupLink"
 */
function popupLinks() {
  $("a.popupLink").each(function (i) {
         this.onclick = function() { return !window.open(this.href); }
      });
  return true;    	
}

window.onload = popupLinks;