var additional_data = '';
		timeout = null;
		
var maxRate;
var enableRatingAnimation = true;
function lemonConsole(module_data){
	//alert(module_data);
	if(document.getElementById('fuzzyadmin').style.display == 'none')document.getElementById('fuzzyadmin').style.display = '';
	keepAlive();
	new Ajax.Updater('fuzzymanage','/connector/fuzzyConnector.php',
		{
			postBody:(module_data),
			asynchronous:false,
			onComplete:function(){
				if(additional_data != ''){
					setTimeout(additional_data, 500);
					//additional_data = '';
				}
				
			}
		}
		);

}
function initRte(){
	tinyMCE.init({ 
		mode : "textareas", 
		theme : "advanced",
		width : "850",
		height: "220",
//		theme_advanced_buttons1 : "bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect" 
		plugins : "fullscreen,media",
        	media_use_script : false, 
        	cleanup : true,
        	cleanup_on_startup : true,
		theme_advanced_buttons1 : "cut,copy,paste,pastetext,pasteword,|,formatselect,|,cut,copy,paste,pastetext,|,bold,italic,underline,strikethrough,link,unlink,bullist,numlist,|,justifyleft,justifycenter,justifyright,justifyfull,|,code,image,media,|,fullscreen", 
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top", 
		theme_advanced_toolbar_align : "left", 
		theme_advanced_statusbar_location : "bottom",
		extended_valid_elements : "input[name|value|size|class|onclick|type],iframe[name|src|framespacing|border|frameborder|scrolling|title|height|width],embed[src|base|flashVars|seamlesstabbing|pluginspage|bgcolor|quality|width|height|type],object[classid|codebase|width|height],param[name|value]",
		theme_advanced_resizing : false
	});


}
function closeFuzzyConsole(){
	document.getElementById('fuzzyadmin').style.display = 'none';
}
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;
}
/* NEWS MODULE */
function saveData(u){
	if(timeout != null)clearTimeout(timeout);
	tinyMCE.triggerSave(true,true);
	var ed = tinyMCE.get('elm1');
	var ed2 = tinyMCE.get('elm2');
	k = ed.getContent();
	k2 = ed2.getContent();
	new Ajax.Updater('fuzzymanage','/connector/fuzzyConnector.php',{parameters:$('news_form').serialize(true),asynchronous:false});
}

/* END NEWS MODULE */
/* CATEGORY MODULE */
function saveCategory(u){
	t = document.getElementById('categorytitle').value;
	
	i = document.getElementById('id').value;
	asdds = document.getElementById('addub').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;
	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 + '&p2=' + p2 + '&p3=' + p3 + '&addub=' + asdds;
	
	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 */

/* BEGIN MOBITEL GOFLA */
function setCountDown(divId, classn)
{
  seconds--;
  if (seconds < 0){
      minutes--;
      seconds = 59
  }
  if (minutes < 0){
      hours--;
      minutes = 59
  }
  if (hours < 0){
      days--;
      hours = 23
  }
  document.getElementById(divId).innerHTML = "<span class=\""+classn+"\">"+days+"</span> dni <span class=\""+classn+"\">"+hours+"</span> ur <span class=\""+classn+"\">"+minutes+"</span> minut in <span class=\""+classn+"\">"+seconds+"</span> sekund";
  setTimeout ( "setCountDown('"+divId+"', '"+classn+"')", 1000 );
}

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 hideDiv(div){
	document.getElementById(div).style.display = 'none';	
}

function showDiv(div){
	document.getElementById(div).style.display = 'block';		
}
	
function openPopup(){
	scroll(0,0);
	document.body.style.overflow="hidden";
	showDiv('dimmer'); 
	showDiv('popupcontain');	
}

function closePopup(){
	hideDiv('dimmer'); 
	hideDiv('popupcontain');	
	document.body.style.overflow="visible";

}

function menuOver(element){	
	element.className = 's';
}

function menuNormal(element){
	element.className = 'n';
}

function showCal(id){
	
	pos = findPos(document.getElementById(id));
	

	document.getElementById('caldisplay').style.display = '';
	document.getElementById('caldisplay').style.top = pos.top + 20 + 'px';
	document.getElementById('caldisplay').style.left = pos.left + 20 + 'px';
}
function hideCal(){
	document.getElementById('caldisplay').style.display = 'none';
}
function findPos(obj){
	var posX = obj.offsetLeft;
	var posY = obj.offsetTop;
	
	while(obj.offsetParent){
		posX = posX + obj.offsetParent.offsetLeft;
		posY = posY + obj.offsetParent.offsetTop;
		
		if (obj == document.getElementsByTagName('body')[0]){
			break;
		}else{
			obj = obj.offsetParent;
		}
	}

   	return {left:posX,top:posY};

}

// drejc
function forgotenPass(){
	document.getElementById('forgotpass').style.display = '';
}

function sendFile(fname, ftype){
		var theURL = '/connector/sendFile.php?name='+fname+'&type='+ftype;
		window.open(theURL, "download", "width=1, height=1, location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no"); 
		
	
		/*new Ajax.Request('/connector/sendFile.php', {
	  method: 'post',
  	parameters: {name: fname, type: ftype}
  	});*/
  
}

function paintStars(sel){
	if (enableRatingAnimation)
		for(i=1; i<= maxRate; i++){
			if(i <= sel)
				
				document.getElementById('star_'+i).src = '/layout/rating/on.jpg';		
			else
				document.getElementById('star_'+i).src = '/layout/rating/off.jpg';
		}	
}

function rateStars(sel){
	for(i=1; i<= maxRate; i++){
		if(i <= sel)
			
			document.getElementById('star_'+i).src = '/layout/rating/sel.jpg';		
		else
			document.getElementById('star_'+i).src = '/layout/rating/off.jpg';
	}	
}

function rate(id, sel){	
	enableRatingAnimation = false;		
	rateStars(sel);	
	setTimeout("enableRatingAnimation = true; new Ajax.Updater('rating','/connector/rate.php',{method: 'post', parameters: {id: "+id+", sel: "+sel+"}})", 600);
}

function warnRate(link){
	alert('Za glasovanje si moraš pogledati video!');
	location.href = link;
}

/* END MOBITEL GOFLA */