﻿function changeClass(obj, new_class)
{
    obj.className = new_class;
}

function changeBgColor(obj, new_color)
{
	obj.style.backgroundColor=new_color;
}

function changePic(name, pic)
{
	name.src = pic;
}
function removeError(obj){
	obj.className=obj.className.replace(" error", "");
}

function openHide(obj, id){
	class_name = obj.className;
	if(class_name.indexOf(' closed')==-1){
		// close menu
		obj.className += ' closed';
		setCookie("admin_menu_"+id, "closed",8640000);
	}else{
		obj.className=obj.className.replace(/ closed/g, '');
		setCookie("admin_menu_"+id, "opened",8640000);
	}
}
function getCheckedValues(group, hiddenForm)
{
	hiddenForm.value="";
	var x=0;
	for (i = 0; i < group.length; i++)
	{
		if(group[i].checked == true)
		{
			if(x!=0)
			{
				hiddenForm.value+=",";
			}
			hiddenForm.value+=group[i].value;
			x=1;
		}
	}
	
}	

function checkAll(obj,parent_id){
	childs = document.getElementById(parent_id).getElementsByTagName("input");
	for(x=0; x<childs.length; x++){
		if(childs[x].type=="checkbox"){
			if(!childs[x].disabled){
				if(obj.checked)
				childs[x].checked=true;
				else
				childs[x].checked=false;
			}
		}
	
	}
}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
		// otherwise, update 'characters left' counter
	else 
		countfield.value = "Znakov na voljo: "+ (maxlimit - field.value.length);
}
function decryptEmail(mail){
	
	//var mail = "klemen#ghb#nagode#atz#email#ghb#si";
	var mail_link = mail;
	while(mail_link.indexOf("#ghb#")>0)
	var mail_link = mail_link.replace("#ghb#", ".");
	mail_link = mail_link.replace("#atz#", "@");
	document.location="mailto:"+mail_link;
}
function cryptEmail(mail){
	var mail_link = mail;
	while(mail_link.indexOf(".")>0)
	var mail_link = mail_link.replace(".", "#ghb#");
	mail_link = mail_link.replace("@", "#atz#");
	return mail_link;
}
var xmlhttp
var into_content_id;
function loadXMLDoc(url, target_id){
	loadXMLDoc(url, target_id, false)
}

/* xmlHTTPrequest: update site using AJAX */
//array.concat()
function loadXMLDoc(url, target_id, post_data)
{
document.getElementById("loading").style.display='block';
// code for Mozilla, etc.
target_element = document.getElementById(target_id);

//target_element.innerHTML = "<div class='loading_content' style='height:"+getStyle(target_element, "height")+'></div>';
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  xmlhttp.onreadystatechange=function (){
		xmlhttpChange(target_id);
  }
  if(post_data!=''){
  xmlhttp.open("POST",url,true)
  xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
  xmlhttp.setRequestHeader("Method", "POST " + url + " HTTP/1.1");

  xmlhttp.send(post_data)
  }else{
  xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
  }
 
}
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    if (xmlhttp)
    {
    xmlhttp.onreadystatechange=function (){
		xmlhttpChange(target_id);
    }
  if(post_data!=''){
  xmlhttp.open("POST",url,true)
  xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  
  xmlhttp.send(post_data)
  }else{
  xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
  }
    }
  }
}

function xmlhttpChange(target_id)
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
    {
		
		htmlText = xmlhttp.responseText;
		document.getElementById(target_id).innerHTML = htmlText ;
		onAjaxLoad();
    }
  else
    {
    alert("Problem retrieving XML data, error: " +xmlhttp.status);
	//alert(xmlhttp.responseText);
    }
	
	document.getElementById("loading").style.display='none';
  }
}
function getFieldsValues(form){
	navRoot = form.getElementsByTagName("INPUT");
	navRoot_textArea = form.getElementsByTagName("textarea");
	var getLikePost="";
	var value;
	for (i=0; i<navRoot.length; i++) {
		node = navRoot[i];
		
		/*  we have to replace &  */
		value=node.value.replace(/&/gi, '{[and]}');  //=
		
		
		if(node.getAttribute("type")=="radio" ){
			if(node.checked==true)
				getLikePost+=node.name+"="+value+"&";
				
		}else{

			getLikePost+=node.name+"="+value+"&"
		}
	}
	for (i=0; i<navRoot_textArea.length; i++) {
		node = navRoot_textArea[i];
		getLikePost+=node.name+"="+node.value
	}	
	return getLikePost;
}
function tryRequestPost(action_url, target_id, form){
	values = getFieldsValues(form);
	submited=false;
	loadXMLDoc(action_url, target_id, values);
	return false;
}




function bbCodeTag(tag, button, post_id){
	post = document.getElementById(post_id);
	start = post.selectionStart;
	end = post.selectionEnd;
	if(start!=end && end){
		text = post.value;
		post.value=text.slice(0, start)+"["+tag+"]"+text.slice(start, end)+"[/"+tag+"]"+text.slice(end, text.length);
	}else{
		if(button.value.substring(button.value.length-1, button.value.length )=='*'){
			button.value=button.value.substring(0,button.value.length-1 )
			post.value+='[/'+tag+'] ';
		}else{
			button.value+='*';
			post.value+='['+tag+']';
		}
	}
	post.focus();
}


//Function for adding font color and size tags

function font(bbopen, bbclose, post_id) {
	var post = document.getElementById(post_id);
	start = post.selectionStart;
	end = post.selectionEnd;
	if(start!=end && end){
		text = post.value;
		post.value=text.slice(0, start)+bbopen+text.slice(start, end)+bbclose+text.slice(end, text.length);
	}else{
		post.value += bbopen + bbclose;
		post.focus();
	}
	return;
}
//Function for adding smilies

function smilie (smilie, post_id) {
	var post = document.getElementById(post_id);
	start = post.selectionStart;
	end = post.selectionEnd;
	if(end){
		text = post.value;
		post.value=text.slice(0, start)+smilie+" "+text.slice(end, text.length);
	}else{
        post.value += smilie+" ";
	}
	post.focus();
	return;
}

// Shows the help messages in the helpline window
function helpline(help, helpbox_id) {
        var helpbox = document.getElementById(helpbox_id);
        helpbox.value = help;
}


function jumpToDate(msgYear, msgMonth, error, url, id){
	var year;
	if(year = prompt(msgYear));
	if(year>1980 && year<2040){
		month = prompt(msgMonth);
		if(month>0 || month<13){
			var fulUrl = url+"&event_date="+year+"-"+month;
			loadXMLDoc(fulUrl, id,'') ;
		}else{
			alert(error);
		}
	}else{
		alert(error);
	}
}



var jsTitle = {
	obj	: null, 
	content: null,
	visible: true,
	objWidth: null, 
	init: function(o){
		obj=o;
		this.start();
		objWidth=getStyle(o, "width");
	},
	start: function(e){
	
		this.hide();
		//obj.innerHTML=Math.random();
		document.onmousemove=this.drag;
	},
	drag: function(e){
		if(visible){
		
			e = jsTitle.fixE(e);
			var y	= e.clientY;
			var x	= e.clientX;
	
			if(x > (2*screen.width/3)){
				x-= objWidth	? parseInt(objWidth) : 60;
			}
			
			xOffset = window.pageXOffset ? window.pageXOffset: parseInt(document.documentElement.scrollLeft);
			yOffset = window.pageYOffset ? window.pageYOffset: parseInt(document.documentElement.scrollTop);
			
			obj.style["left"]=(x+2+xOffset)+"px";
			obj.style["top"]=(y+2+yOffset)+"px"; 
			
		}
	},
	show: function(content, width){
		if(obj){
		visible=true;
		
		obj.innerHTML = content;
		objWidth=getStyle(obj, "width");
		jsTitle.start;
		$(obj).show();
		//obj.style["display"]="block";
		//obj.innerHTML=Math.random();
		//fade_in(obj, 100, 0);
		}
	},
	hide: function(){
		if(obj){
		obj.style["display"]="none";
		visible=false;
		}
	},
	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
}

function opacityIncrease(){
	if(fadeOpacity<fadeOpacityEnd && fadeOpacity<100){
		fadeObj.style["opacity"]="."+fadeOpacity;
		fadeOpacity+=4;
		
		window.setTimeout("opacityIncrease()", 30);
	}else{
		
	}
}



on_load = new Array();
 

var reportBox, iReportCount = 0;


function getStyle(el,styleProp)
{
	var x = el;
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}
var autoOpenTab=false;

function getCookie(name){
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
function setCookie(name, value, expiresSecond){
			var today = new Date();
			var expire = new Date();
			expire.setTime(today.getTime() + expiresSecond);
			document.cookie = name+"="+escape(value)+ ";expires="+expire.toGMTString();
}
var is_preview=false;
function preview(linkObj, text1, text2){
	previewObj = document.getElementById("preview");	
	leftMenu = document.getElementById("left");
	centerContent=document.getElementById("center");
	drager=document.getElementById("drager");
	
	if(!is_preview){
		is_preview=true;
		centerContent.style["display"]="none";
		drager.style["display"]="none";
		leftMenu.style["display"]="none";
		previewObj.style["display"]="block"; 
		bodyObj=document.getElementById("body");
		//height = 
		previewObj.innerHTML = '<iframe id="preview_frame" src ="index.php" width="98%" style="height:430px"> </iframe>';
	}else{
		is_preview=false;
		centerContent.style["display"]="block";
		drager.style["display"]="block";
		leftMenu.style["display"]="block";
		previewObj.style["display"]="none"; 
		previewObj.innerHTML = '';
	
	}
}
function classAllTables(){
	table = document.getElementsByTagName("TABLE");

	for(i=0; i<table.length; i++){
		obj = table[i];

		if(obj.className == "dynamic"){
			classTable(obj);
		}
	}	
}
function classTable(obj){	
	tr = obj.getElementsByTagName("TR");
	for(x=0; x<tr.length; x+=1){
		td = tr[x].getElementsByTagName("TD");

		for(y=0; y<td.length; y+=1){
			td[y].className = "td_"+y+" td_mod_"+y%2;				
		}
		tr[x].className += " tr_"+x +" tr_mod_"+x%2;
	}
}
function img_open(src, width, height){
	obj = document.getElementById("fancy_popup");
	
	yOffset = window.pageYOffset ? window.pageYOffset: parseInt(document.documentElement.scrollTop);
	document.body.style.overflow="hidden";
	obj.innerHTML = "<div style=\"height:"+innerHeight+"px;margin-top:"+yOffset+"px\" onclick=\"img_close(); return false\" ><a title=\"pop_top\"></a></div><img onclick=\"img_close();\" src=\""+src+"\" style=\"margin-top:"+yOffset+"px\" widht=\""+width+"\" height=\""+height+"\" />d";
	
	obj.style.display="block";
	window.scrollBy(33, 33);
	
	}
function img_close(){
	obj = document.getElementById("fancy_popup");
	obj.innerHTML ="";
	obj.style.display="none";
	document.body.style.overflow="auto";
}
function flash_popup(src, width, height){
	//alert(src);
	//alert(width);
	//alert(height);
	var w=0+parseInt(width);
	var h=0+parseInt(height);
	//w=200;
	//h=200;
	//alert(w);
	//alert(h);
	var x=screen.width; 
	var feautures; 
	//window.open("Sample.htm",null,   "height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
	window.open("http://www.secaplast.si/popup.php?src="+src,null,'scrollbars=no,width='+w+',height='+h).moveTo((screen.width - w) / 2, (screen.height - h) / 2); 
	/**/
}
function flash_titles(){
	$("h1").each(function(index){
		//alert("kk");
		
		
		var text = ($(this).html()).replace(/<(.|\n)*?>/g, "");
		
		if(text.length<48){
			var f = new SWFObject(DOMAIN+"text_zverinica.swf", "sotester"+index, "450", "50", "5", "#FFFFFF");
		
			text = text.replace(/š/g, "sch");
			text = text.replace(/č/g, "ch");
			text = text.replace(/ž/g, "zh");
			text = text.replace(/Č/g, "CH");
			text = text.replace(/Š/g, "SCH");
			text = text.replace(/Ž/g, "ZH");
			
			f.addVariable('txt',text  );
			f.addParam("wmode", "transparent");
			
			$(this).html(f.getSWFHTML());
			
			$(this).css("background", "none");
		}
	});
}

function show_title(divID, action) {
	switch (action)
	{
		case "over":
			document.getElementById(divID).style.display = "block"; 
			break;
		case "out":
			document.getElementById(divID).style.display = "none";
			break;
	}
} 

/* patern picker */
function onAjaxLoad(){
	//flash_titles();
}
window.onload = function(){

	if (document.all || document.getElementById)
	{
		var mouseObj = document.all ? document.all["mousemove"] : document.getElementById("mousemove");
		jsTitle.init(mouseObj);
	}

	for(x=0; x<on_load.length; x++){
		eval(on_load[x]);
		
	}

 /*  settings = {
      tl: { radius: 12 },
      tr: { radius: 12 },
      bl: { radius: 12 },
      br: { radius: 12 },
      antiAlias: true,
      autoPad: false
    }

    var divObj = document.getElementById("top");

    var cornersObj = new curvyCorners(settings, divObj);
	
    cornersObj.applyCornersToAll();*/
}

$(document).ready(function(){
	
	
	
	classAllTables();
	
	
	//flash_titles();
	
});
