// JavaScript Document

var num_bg=6;
var curBg=1;
var min=12;
var max=20;
function increaseFontSize() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 4;
      }
      p[i].style.fontSize = s+"px"
   }
}
function decreaseFontSize() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 4;
      }
      p[i].style.fontSize = s+"px"
   }   
}

function setLanguage(lang){
	var httpObj=getHTTPObject();
	if(httpObj != null){
		httpObj.open("GET", host+"/cms/inc/widget/ajax.set.lang.php?lang="+lang+"&view=web", false);
        httpObj.send(null);
		if (httpObj.readyState==4){
       		response=httpObj.responseText;
			window.location = ""+host;
      	}
	}	
}

function changeHomeBg(elem){
	curBg=curBg%num_bg;
	curBg++;	
	var element = (ie) ? document.all.elem : document.getElementById(elem);
	var traka = (ie) ? document.all.elem : document.getElementById("traka_img");
	var  l=element.getElementsByTagName("a").item(1);
	traka.src=host+"/theme/img/traka"+curBg+".jpg";
	l.href =host+"/"+perm_links[curBg];
	element.style.backgroundImage="url(./theme/img/home"+curBg+"-"+language+".jpg)";
}

function buttonActive(){
	var element = (ie) ? document.all.elem : document.getElementById("saznaj_vise_button");
	var source=element.src;
	var len=source.length-5;
	element.src=""+source.substr(0,len)+".png";
}
function buttonPassive(){
	var element = (ie) ? document.all.elem : document.getElementById("saznaj_vise_button");
	var source=element.src;
	var len=source.length-4;
	element.src=""+source.substr(0,len)+"2.png";
}

function addComment(container,ref,ref_type,parent){
	var httpObj=getHTTPObject();
	var response="";
	if(httpObj != null){
		httpObj.open("GET", host+"/cms/inc/widget/ajax.comments.php?action=add_comment&ref="+ref+"&ref_type="+ref_type+"&parent="+parent+"&conainer="+container, false);
        httpObj.send(null);
		if (httpObj.readyState==4){
       		response=httpObj.responseText;
      	}
	}
	//$("#"+container).slideUp("fast");
	$m(container).innerHTML=response;
	$("#"+container).slideDown("slow");
	tinyMCE.init({mode : "exact",theme : "simple",elements : "text",content_css : host+"/theme/tinymce_simple.css"});
}

function submitComment(form,container){
	var params=get(form);
	var httpObj=getHTTPObject();
	var response="";
	if(httpObj != null){
		httpObj.open("POST", host+"/cms/inc/widget/ajax.comments.php?action=save_comment", false);
		httpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		httpObj.setRequestHeader("Content-length", params.length);
		httpObj.setRequestHeader("Connection", "close");
		httpObj.send(params);
		httpObj.onreadystatechange = function() {
			if (httpObj.readyState==4){
 	      		response=httpObj.responseText;
			}
      	}
	}
	//$m(container).innerHTML=response;
	if(response=="") window.location=window.location.href;
}

function removeComment(i_comment,container){
	var httpObj=getHTTPObject();
	var response="";
	if(httpObj != null){
		httpObj.open("GET", host+"/cms/inc/widget/ajax.comments.php?action=trash_comment&i_comment="+i_comment, false);
		httpObj.onreadystatechange = function() {
			if (httpObj.readyState==4){
 	      		response=httpObj.responseText;
			}
      	}
		httpObj.send(null);
	}
	window.location=window.location.href;
}

function postPrint(h,c,id,y,d,m,q,po,co,p) {
	window.open(host+"/print.php?c="+c+"&id="+id+"&d="+d+"&m="+m+"&y="+y+"&offset="+po+"&offset_cat="+co+"&p="+p,"","menubar=no,width=800,height=600,scrollbars=yes,toolbar=no,frame=no,top=70,left=200");
}
