/* Golden Drum Exceptions */
var additional_data = '';
timeout = null;
tinyMCE.init({
	mode : "none",
	theme : "advanced",
	width : "850",
	height: "195",
	plugins : "fullscreen,media,table,paste",
	theme_advanced_buttons1 : "cut,copy,paste,|,formatselect,|,cut,copy,paste,pastetext,|,bold,italic,underline,strikethrough,link,unlink,bullist,numlist,|,justifyleft,justifycenter,justifyright,justifyfull,|,fullscreen",
	theme_advanced_buttons2 : "pastetext,pasteword,|,code,tablecontrols,image,media",
	theme_advanced_buttons3 : "",
	table_styles : "Header 1=header1;Header 2=header2;Header 3=header3",
	table_cell_styles : "Header 1=header1;Header 2=header2;Header 3=header3;Table Cell=tableCel1",
	table_row_styles : "Header 1=header1;Header 2=header2;Header 3=header3;Table Row=tableRow1",
	table_cell_limit : 100,
	table_row_limit : 5,
	table_col_limit : 5,
	convert_urls : false,
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_resizing : false,
	paste_create_paragraphs : false,
	paste_create_linebreaks : false,
	paste_use_dialog : true,
	paste_auto_cleanup_on_paste : false,
	paste_convert_middot_lists : false,
	paste_unindented_list_class : "unindentedList",
	paste_convert_headers_to_strong : true,
	paste_insert_word_content_callback : "convertWord"
});
var wry = new Array;
function lemonConsole(module_data){

/*	bInp = document.getElementsByTagName('param');
	for(i = 0; i < bInp.length; i++){
		if(bInp[i].name == 'movie'){
			a = document.getElementsByNa(bInp[i].parentNode.name);
			alert(a.lenght);
			wry[i] = bInp[i].value;
			bInp[i].value = '/';
		}
		if(bInp[i].name == 'wmode'){
			bInp[i].value = 'transparent';
		}
	}
*/
	//let's change the content
	if(document.getElementById('fuzzyadmin').style.display == 'none'){
		bInp = document.getElementsByTagName('param');
		for(i = 0; i < bInp.length; i++){
			if(bInp[i].name == 'wmode'){
				bInp[i].value = 'transparent';
			}
		}
		//for mozzila
		bInp = document.getElementsByTagName('embed');
		for(i = 0; i < bInp.length; i++){
			//alert(parentNode.id);
			var flash = new SWFObject(bInp[i].src,bInp[i].name,bInp[i].width,bInp[i].height,"8");
			flash.addParam("wmode","transparent");
			flash.write(bInp[i].parentNode.id);
		}
		//for IE
		bInp = document.getElementsByTagName('object');
		var k = bInp.length;
		for(i = 0; i < k; i++){
			if(bInp[i].parentNode.id != ''){
					wry[i] = {id:bInp[i].parentNode.id,data:document.getElementById(bInp[i].parentNode.id).innerHTML};
			}
		}
		for(i = 0; i < wry.length;i++){
				document.getElementById(wry[i].id).innerHTML = '';
		}
	}

	if(document.getElementById('fuzzyadmin').style.display == 'none')document.getElementById('fuzzyadmin').style.display = '';
	keepAlive();
	killRTE();
	new Ajax.Updater('fuzzymanage','/connector/fuzzyConnector.php',
		{
			postBody:(module_data),
			asynchronous:false,
			onSuccess:function(transport){
				if(additional_data != ''){
					setTimeout(additional_data, 500);
				}

			}
		}
		);
}
function killRTE(){
	aInp = document.getElementsByTagName('textarea');
	if(lul == 1){
		for(i = 0; i < aInp.length; i++){
			tinyMCE.execCommand('mceRemoveControl', true, aInp[i].id);
		}
	}
}
function fuzzyAjax(u, el){
	new Ajax.Updater(el,'/connector/ajaxConnector.php',
		{
			postBody:(u),
			asynchronous:false,
			onSuccess:function(transport){
				if(additional_data != ''){
					setTimeout(additional_data, 500);
				}

			}
		}
	);
}

var lul = null;
function initRte(){
	//Textarea
	aInp = document.getElementsByTagName('textarea');
	for(i = 0; i < aInp.length; i++){
		tinyMCE.execCommand('mceAddControl', true, aInp[i].id);
	}
	lul = 1;
}
function closeFuzzyConsole(){
	document.getElementById('fuzzyadmin').style.display = 'none';
	pInp = document.getElementsByTagName('param');
	for(i = 0; i < pInp.length; i++){
		if(pInp[i].name = 'wmode')pInp[i].value = "window";
	}
	self.location.reload();
}
function showhide(element){
	if(document.getElementById(element).style.display == 'none')
		document.getElementById(element).style.display = '';
	else
		document.getElementById(element).style.display = 'none';
}
function classicSave(u, who){
	new Ajax.Updater('fuzzymanage','/connector/fuzzyConnector.php',{parameters:$(who).serialize(true),asynchronous:false});
}
function keepAlive() {
	box = document.getElementById('fuzzyadmin');
	bs = document.getElementById('fuzzyadmin');
	box.style.display = 'block';
	boxw = document.body.scrollWidth;
	boxh = document.body.scrollHeight;
	bsw = 1000;
	bsh = 840;
	if (boxw < bsw)boxw = bsw;
	if (boxh < bsh)boxh = bsh;
	box.style.width = boxw + 'px';
	box.style.height = boxh + 'px';
	bs.style.display = 'block';
	bs.style.width = bsw + 'px';
	bs.style.height = bsh + 'px';
	bsl = (document.body.clientWidth / 2) - (bsw / 2);
	bst = (document.body.clientHeight / 2) - (bsh / 2)
	if (bsl < 0)bsl = 0;
	if (bst < 0)bst = 0
	bs.style.left =	bsl;
	bs.style.top = bst;
}
/* PROJEKTI MODULE */
function saveProjekti(u){
	if(timeout != null)clearTimeout(timeout);
	tinyMCE.triggerSave(true,true);
	killRTE();
	new Ajax.Updater('fuzzymanage','/connector/fuzzyConnector.php',{parameters:$('projekti_form').serialize(true),asynchronous:false,onSuccess:function(transport){
				if(additional_data != ''){
					setTimeout(additional_data, 500);
				}

			}});
}
/* END NEWS MODULE */
/* NEWS MODULE */
function saveData(u){
	if(timeout != null)clearTimeout(timeout);
	tinyMCE.triggerSave(true,true);
	killRTE();
	new Ajax.Updater('fuzzymanage','/connector/fuzzyConnector.php',{parameters:$('news_form').serialize(true),asynchronous:false});

}
/* END NEWS MODULE */
/* MODULE FAQ */
function saveFaq(u){
	new Ajax.Updater('fuzzymanage','/connector/fuzzyConnector.php',{parameters:$('faqform').serialize(true),asynchronous:false});
}

/* END MODULE FAQ */
/* CATEGORY MODULE */
function saveCategory(u){
	t = document.getElementById('categorytitle').value;

	i = document.getElementById('catid').value;
	a = document.getElementById('categoryactivity').options[document.getElementById('categoryactivity').selectedIndex].value;
	p0 = document.getElementById('categorypublic').options[document.getElementById('categorypublic').selectedIndex].value;
	p1 = document.getElementById('categoryadmin').options[document.getElementById('categoryadmin').selectedIndex].value;
	friendly = document.getElementById('categoryfriendly').value;
	//p2 = document.getElementById('categoryemployer').options[document.getElementById('categoryemployer').selectedIndex].value;
	//p3 = document.getElementById('categoryemployee').options[document.getElementById('categoryemployee').selectedIndex].value;

	p = document.getElementById('categorygroup').options[document.getElementById('categorygroup').selectedIndex].value;
	la = document.getElementById('categorylayout').options[document.getElementById('categorylayout').selectedIndex].value;
	lo = document.getElementById('categorylocale').options[document.getElementById('categorylocale').selectedIndex].value;
	u += '&name=' + t + '&active=' + a + '&group=' + p + '&id=' + i + '&locale=' + lo + '&layout=' + la + '&p0=' + p0 + '&p1=' + p1 + '&friendly=' + friendly;

	lemonConsole(u);
}
/* END CATEGORY MODULE */
/* JOB MODULE */
function saveJob(u){
	fin = u;
	fin += '&id=' + document.getElementById('id').value;
	fin += '&company=' + document.getElementById('company').options[document.getElementById('company').selectedIndex].value;
	fin += '&job_active=' + document.getElementById('job_active').options[document.getElementById('job_active').selectedIndex].value;
	fin += '&job_title=' + document.getElementById('job_title_me').value;
	fin += '&job_valid_until=' + document.getElementById('job_valid_until').value;
	fin += '&job_type_payment=' + document.getElementById('job_type_payment').value;
	fin += '&job_payment=' + document.getElementById('job_payment').value;
	fin += '&job_location=' + document.getElementById('job_location').options[document.getElementById('job_location').selectedIndex].value;
	fin += '&job_type=' + document.getElementById('job_type_new').options[document.getElementById('job_type_new').selectedIndex].value;
	fin += '&job_workingtimes=' + document.getElementById('job_workingtimes').value;
	fin += '&job_expirience=' + document.getElementById('job_expirience').value;
	fin += '&job_school=' + document.getElementById('job_school').value;
	fin += '&job_specifics=' + document.getElementById('job_specifics').value;
	fin += '&job_desc=' + document.getElementById('job_desc').value;
	lemonConsole(fin);
}
/* END JOB MODULE */



function fixPNGS(){
	//<![CDATA[
// If you don't want to put nonstandard properties in your stylesheet, here's yet
 // another means of activating the script. This assumes that you have at least one
 // stylesheet included already in the document above this script.
 // To activate, delete the CSS rules above and uncomment below (remove /* and */ ).

 /*
 if (document.all && /MSIE (5\.5|6)/.test(navigator.userAgent) &&
  document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule)
 {
  document.styleSheets[0].addRule('*', 'behavior: url(/resources/iepngfix.htc)');
  // Feel free to add rules for specific elements only, as above.
  // You have to call this once for each selector, like so:
  //document.styleSheets[0].addRule('img', 'behavior: url(/css/resources/iepngfix.htc)');
  //document.styleSheets[0].addRule('div', 'behavior: url(/css/resources/iepngfix.htc)');
 }
 */

 // Here's another script that disables all PNGs in IE when the page is printed.
 /*
 if (window.attachEvent  && /MSIE (5\.5|6)/.test(navigator.userAgent))
 {
  function printPNGFix(disable)
  {
   for (var  i = 0; i < document.all.length; i++)
   {
    var e = document.all[i];
    if (e.filters['DXImageTransform.Microsoft.AlphaImageLoader'] || e._png_print)
    {
     if (disable)
     {
      e._png_print = e.style.filter;
      e.style.filter = '';
     }
     else
     {
      e.style.filter = e._png_print;
      e._png_print = '';
     }
    }
   }
  };
  window.attachEvent('onbeforeprint',  function() { printPNGFix(1) });
  window.attachEvent('onafterprint',  function() { printPNGFix(0) });
 }
 */

 //]]>
}
function resizeFlash(){
	if (document.getElementById('flash')){
		f = document.getElementById('flash');
		f.style.width = 1200 + 'px';
		w = document.getElementById('arcadia').clientWidth;
		f.style.width = w + 'px';
	}
}

function svetilasearch(u, sp, from, limit){
	//var sp = document.getElementById('searchpar').value;
	if (trim(sp) == '') return;
	var uu = u + "&search=" + trim(sp) + '&from=' + from + '&limit=' + limit;
	fuzzyAjax(uu, 'fuzzylucke1');
	document.getElementById('svetila_flash').style.padding = '10px';
	document.getElementById('svetila_flash').innerHTML = '';
	document.getElementById('fuzzylucke1').style.display = '';
}

function svetilaselectold(u, field, stri, strin, from){
	var uu = u + "&field=" + field + "&stri=" + stri  + "&strin=" + strin + "&from=" + from;
	fuzzyAjax(uu, 'aaa');
	self.location.href = '/svetila/seznam/0/0/0/0/0/';
}
function svetilaselect(u, field, stri, strin, from, limit){
	var uu = u + "&field=" + field + "&stri=" + stri  + "&strin=" + strin + "&from=" + from;
	if (limit != null) uu += '&limit=' + limit;
	fuzzyAjax(uu, 'fuzzylucke1');
	document.getElementById('svetila_flash').style.padding = '10px';
	document.getElementById('svetila_flash').innerHTML = '';
	document.getElementById('fuzzylucke1').style.display = '';
}

function trim(s){
	return s.replace(/^\s*(.*?)\s*$/,"$1")
}

function editsifrant(u, section){
	var uu = u + "&section=" + section;
	if(document.getElementById('fuzzyadmin').style.display == 'none') document.getElementById('fuzzyadmin').style.display = '';
	keepAlive();
	fuzzyAjax(uu, 'fuzzymanage');
}
function editsifrantitem(id){
	showhidemul(Array('sifrant_value_' + id,'sifrant_edit_' + id,'sifrant_valuecom_' + id,'sifrant_editcom_' + id,'sifrant_ud_' + id));
}
function addsifrant(){
	document.getElementById('sifrant_newtext').value = '';
	showhidemul(Array('sifrant_new','sifrant_addnew'));
}
function savesifrant(u, section, id, vali){
	value = document.getElementById(vali).value;
	var uu = u + "&action=save&section=" + section + "&id=" + id + "&value=" + value;
	keepAlive();
	fuzzyAjax(uu, 'fuzzymanage');
	editsifrant(u, section);
}
function deletesifrant(u, section, id){
	var yes = confirm('Do you really want to delete this?');
	if(yes){
		var uu = u + "&action=delete&section=" + section + "&id=" + id;
		keepAlive();
		fuzzyAjax(uu, 'fuzzymanage');
		editsifrant(u, section);
	}
}
function deleteatt(u, id, lid){
	var yes = confirm('Do you really want to delete this attachment?');
	if(yes){
		var uu = u + "&deleteatt=" + id + "&svetilo=" + lid;
		fuzzyAjax(uu, 'aaa');
		document.getElementById('attachment_' + id).innerHTML = '';
	}
}
function deletelight(u, id){
	var yes = confirm('Do you really want to delete this light?');
	if(yes){
		var uu = u + "&deletelight=true&id=" + id;
		fuzzyAjax(uu, 'aaa');
		//self.location.href = '/mycivis';
		history.go(-1);
	}
}

function showhidemul(kva){
	for(i=0; i < kva.length; i++){
		if(document.getElementById(kva[i]).style.display == 'none'){
			document.getElementById(kva[i]).style.display = '';
		}else{
			document.getElementById(kva[i]).style.display = 'none';
		}
	}
}
function studyonoff(kva){
	showhidemul(kva);
	obj = document.getElementById('projektidesc');
	if (obj.value == '1')
		obj.value = '';
	else
		obj.value = '1';
}
function projselect(u){
	id = document.getElementById('projsel').value;
	var uu = u + "&changeproject=" + id;
	//alert(uu);
	fuzzyAjax(uu, 'projlights');
}
function projselectbig(u){
	id = document.getElementById('projsel').value;
	var uu = u + "&changeproject=" + id;
	fuzzyAjax(uu, 'projlights');
	self.location.href='/svetila/myproject/'+id;
}
function addlighttomy(u, id){
	var uu = u + "&module=17&addlighttomy=true&svetilo=" + id;
	//alert(uu);
	fuzzyAjax(uu, 'projlights');
}
function deletelightfrommy(u, id){
	var yes = confirm('Do you really want to delete this light?');
	if(yes){
		var uu = u + "&module=17&deletelightfrommy=true&svetilo=" + id;
		//alert(uu);
		fuzzyAjax(uu, 'projlights');
		self.location.reload();
	}
}
function deletemyproj(u, id){
	var yes = confirm('Do you really want to delete this project?');
	if(yes){
		var uu = u + "&module=17&deletemyproj=true&project=" + id;
		//alert(uu);
		fuzzyAjax(uu, 'aaa');
		self.location.href='/portal/svetila/index.html';
	}
}
function saveremarktomy(u, id){
	var rmk = document.getElementById("edit_remark_text_" + id).value;
	var uu = u + "&module=17&saveremarktomy=true&svetilo=" + id + "&remark=" + rmk;
	fuzzyAjax(uu, 'aaa');
	self.location.reload();
}
function changequatomy(u, id, changeval){
	ell = document.getElementById("_qua_" + id);
	//var curval = el.innerHTML;
	var curval = ell.value;
	newval = eval(curval) + eval(changeval);
	if(eval(newval) > 0) {
		//el.innerHTML = newval;
		ell.value = newval;
		var uu = u + "&module=17&changequatomy=true&svetilo=" + id + "&changeval=" + newval;
		fuzzyAjax(uu, 'aaa');
	}
}
function naroci(){
	self.location.href="/portal/naroci/index.html";
}
function deletedocatt(u, id){
	var yes = confirm('Do you really want to delete this attachment?');
	if(yes){
		var uu = u + "&deletedocatt=" + id;
		fuzzyAjax(uu, 'aaa');
		document.getElementById('attachment_' + id).style.display = 'none';
	}
}
function sendrequest(u, id){
	var que = document.getElementById('sendrequest_text').value;
	var yes = confirm(que);
	if(yes){
		var uu = u + "&sendrequest=" + id;
		//fuzzyAjax(uu, 'aaa');
		new Ajax.Updater('aaa','/connector/ajaxConnector.php',
		{
			postBody:(uu),
			asynchronous:false,
			onSuccess:function(transport){
				self.location.href='/portal/message/index.html';
			}
		}
	);

	}
}

