var openvcat="";
var showvcattimerID=0;

function showvcat(divid) {
	if (openvcat != "")
		hidevcat(openvcat);
	closevcat();
	openvcat=divid;
	document.getElementById('popup'+divid).style.display="block";
	openedBBplayerBig = document.getElementById('videobox_flash_video');
	if (openedBBplayerBig != null){
		openedBBplayerBig.BBPlayerPause();
	}
	var openedBBplayerSmall = document.getElementById('flash_'+divid);
	setTimeout(function(){playOpenedPlayerSmall(openedBBplayerSmall, 5);},200);
}

function playOpenedPlayerSmall(openedBBplayerSmall, ttl){
	try{
		openedBBplayerSmall.BBminiPlayerPlay();
	}catch(e){
		if(ttl<0)
			return;
		setTimeout(function(){playOpenedPlayerSmall(openedBBplayerSmall, --ttl);},200);
	}
}

var userStop = false;
function videoPlayed(val)
{
userStop = val;
}


function hidevcat(divid) {
	openvcat="";
	document.getElementById('popup'+divid).style.display="none";
	openedBBplayerBig = document.getElementById('videobox_flash_video');
	
	if (openedBBplayerBig != null){
		if (userStop == false){
			openedBBplayerBig.BBPlayerResume();
		}
	}
	openedBBplayer = document.getElementById('flash_'+divid);
	if (openedBBplayer != null){
		if (document.getElementById('flash_'+divid).BBminiPlayerPause != null){
		openedBBplayer.BBminiPlayerPause();
		}
	}


	if (document.getElementById("loginbox") != null){
		document.getElementById("loginbox").style.display='none';
	}

}


function closevcat() {
	if (showvcattimerID != 0) killtimedclose();
	if (openvcat!="") hidevcat(openvcat);
}



function timedvcatclose(divid) {
	if (showvcattimerID++ == 0) {
		showvcattimerID=setTimeout("closevcat()",300);
	} else {
		showvcattimerID--;
	}
}


function killtimedclose() {
	clearTimeout(showvcattimerID);
	showvcattimerID=0;
}

//function debug(mymsg) {
//	document.getElementById("debugdiv").innerHTML+=mymsg+" | ";
//}

function showlogin(){
	showvcat("loginboxInner");
	 document.getElementById("loginbox").style.display='block';
}
function message_videochat(){
	 document.getElementById("videochat_login").style.display='block';
	 if (document.getElementById("login_error")){
	 	document.getElementById("login_error").style.display='none';
	 	}
}

function submitSearchForm(searchForm, hiddenSearchForm){
	hiddenSearchForm.q.value = searchForm.q.value;
//	alert(hiddenSearchForm.childNodes);
	for(node in hiddenSearchForm.childNodes)
		alert(hiddenSearchForm.childNodes[node]);
	hiddenSearchForm.submit();
}


function getXmlHttp(){
	var xmlHttp;
	try{
		xmlHttp=new XMLHttpRequest();
	}catch (e){
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e){
			    alert("Your browser does not support AJAX!");
				return null;
			}
		}
	}
	return xmlHttp;
}

function xmlLoadUrl(url, callback){
	var xmlHttp = getXmlHttp();
	if(xmlHttp == null){
		return false;
	}
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
			if(callback)
				callback(xmlHttp);
		}
	}
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function openDivById(id){
	document.getElementById(id).style.display='block';
}

function closeDivById(id){
	document.getElementById(id).style.display='none';
}

function openCloseDivById(id){
	var node = document.getElementById(id);
	if(node.style.display=='none'){
		document.getElementById(id).style.display='block';
		return false;
	}
	document.getElementById(id).style.display='none';
	return true;
}


/*
//functions for fake select
$(document).ready(function() {
	$('.fakeSelect').hide();

//	    $("#map_canvas").animate({"opacity": 0}, 1500, function(){alert("all done");}); 

	
	$('.i_cont2p').click(function() {
		$(this).parent('div').children('div').show();
	});	

//	$('.i_cont2p').mouseout(function(){
//		$(this).children('div').hide();
//	});	

	$('.fakeSelect > span').click(function() {
		$(this).parent('div').hide();
	});	
	
	
	$('#langSelectBoxFlags > ul > li > a').click(function() {
		$('#langSelectBox').fadeOut('fast');
	});

	$('#opencloseMap').click(function() {
		$('#locationDetails').toggle();
	});	
});
*/
function setfakeSelectvalue(id,val){
	document.getElementById(id).innerHTML = val;	
	document.getElementById('i'+id).value = val;
}

function loadRelatedPage(ownerid,offset) {
	xmlLoadUrl(tmplwebpath+'/ptp_related.jsp?article='+ownerid+'&offset='+offset, function(xmlHttp){
		document.getElementById('relatedHolder').innerHTML = xmlHttp.responseText;
	});
}

function loadCommentsPage(ownerid, offset, noCommentsPerPage) {
	var noComments = '';
	if(noCommentsPerPage && noCommentsPerPage != '')
		noComments = '&nocommentsperpage='+noCommentsPerPage;
	xmlLoadUrl(tmplwebpath+'/ptp_comments.jsp?owner='+ownerid+'&offset='+offset+noComments, function(xmlHttp){
		document.getElementById('commentsHolder').innerHTML = xmlHttp.responseText;
		var commentsDiv = document.getElementById('comments');
		var popupBottom = commentsDiv.offsetHeight + getOffsetPosition(commentsDiv).y;
		fixDocumentHeight(popupBottom);
	});
}

var lastCommentsGlobalRef_el_id = null;

function showCommentsGlobal(ownerid, ref_el_id, event, leftMargin, noCommentsPerPage) {
	try {
		document.getElementById('commentGlobalThankyou').style.display = 'none';
	} catch (e) {}
	var commentsDiv = document.getElementById('comments');
	if(commentsDiv.style.display=='block' && lastCommentsGlobalRef_el_id==ref_el_id) {
			return;
	}
	lastCommentsGlobalRef_el_id = ref_el_id;
	var commentform = document.getElementById('commentform');
	if (commentform) {
		commentform.owner.value=ownerid;
		commentform.comment.value="";
	}
	
	var commentsHolder = document.getElementById('commentsHolder');
	commentsHolder.innerHTML = "LOADING...";
	//position in reference to ref_el (by element id)
	loadCommentsPage(ownerid, 0, noCommentsPerPage);
	commentsDiv.style.display="";
	closePopups();
	positionCommentsGlobal(commentsDiv, ref_el_id, event, leftMargin);
}

var documentOnClickCommentsGlobalBackup = null;
var documentOnKeyPressCommentsGlobalBackup = null;

function commentsGlobalDocumentOnKeyPress(event){
	if(!event)
		event = window.event;
	if(!event)
		return;
	if ((event.charCode || event.keyCode) == 27)
		closeCommentsGlobal();
}

function closeCommentsGlobal(){
	var cdiv = document.getElementById("comments");
	cdiv.style.display = 'none';
	document.onclick = documentOnClickCommentsGlobalBackup;
	document.onkeypress = documentOnKeyPressCommentsGlobalBackup;
	document.getElementById('push').style.paddingBottom = "";
}

function positionCommentsGlobal(commentsDiv, ref_el_id, event, leftMargin) {
	var ref_el = document.getElementById(ref_el_id);
	var pos = getOffsetPosition(ref_el);
	var posParent = getOffsetPosition(commentsDiv);
	if(window.event)
		event = window.event;
	if(event)
		stopEventBubbling(event);
	documentOnClickCommentsGlobalBackup = document.onclick;
	document.onclick = closeCommentsGlobal;//function(){alert("close");};
	documentOnKeyPressCommentsGlobalBackup = document.onkeypress;
	document.onkeypress = commentsGlobalDocumentOnKeyPress;
	
	commentsDiv.onclick = stopEventBubbling;
	commentsDiv.style.display = 'block';
	
	var addLeft = 0;
	try{
		if(pos.x>document.body.offsetWidth/2)
			addLeft -= commentsDiv.offsetWidth - ref_el.offsetWidth;
	}catch(e){}
	var cdiv = commentsDiv;
	cdiv.style.top = (pos.y+ref_el.offsetHeight-81)+'px';
	cdiv.style.left = (pos.x+addLeft)+'px';
//	cdiv.style.width = (ref_el.offsetWidth-4)+'px';
	if(leftMargin)
		cdiv.style.marginLeft = leftMargin+'px';
	else
		cdiv.style.marginLeft = '0px';
	
	var popupBottom = commentsDiv.offsetHeight + getOffsetPosition(commentsDiv).y;
	fixDocumentHeight(popupBottom);
}

function getOffsetPosition(e){
	var left = 0;
	var top  = 0;
	if(!e)
		return {x:0, y:0};
	
	while (e.offsetParent){
		left += e.offsetLeft;
		if(e.style.marginLeft) left -= parseInt(e.style.marginLeft);
		if(e.style.paddingLeft) left -= parseInt(e.style.paddingLeft);
		if(e.style.margin) left -= parseInt(e.style.margin);
		if(e.style.padding) left -= parseInt(e.style.padding);
		top  += e.offsetTop;
		if(e.style.marginTop) top -= parseInt(e.style.marginTop);
		if(e.style.paddingTop) top -= parseInt(e.style.paddingTop);
		if(e.style.margin) top -= parseInt(e.style.margin);
		if(e.style.padding) top -= parseInt(e.style.padding);
		e = e.offsetParent;
	}
	
	left += e.offsetLeft;
	top  += e.offsetTop;

	return {x:left, y:top};
}

function stopEventBubbling(event){
	if (!event) var event = window.event;
	event.cancelBubble = true;
	if (event.stopPropagation) event.stopPropagation();
}

function deleteComment(id, noCommentsPerPage) {
	var ownerid = document.commentform.owner.value;
	if(noCommentsPerPage && noCommentsPerPage != '')
		noComments = '&nocommentsperpage='+noCommentsPerPage;
	xmlLoadUrl(tmplwebpath+'/ptp_comments.jsp?owner='+ownerid+'&deleteComment='+id+noComments, function(xmlHttp){
		document.getElementById('commentsHolder').innerHTML = xmlHttp.responseText;
	});
}

function postCommentGlobal(noCommentsPerPage) {
	var ta = document.getElementById("comment");
	if (ta.value.length<2){
		document.getElementById('commentGlobalThankyou').innerHTML = 'Molimo unesite komentar (najmanje 2 znaka)';
		document.getElementById('commentGlobalThankyou').style.display = 'block';
		ta.focus();
		return false;
	}
	document.getElementById('commentGlobalThankyou').style.display = 'block';
	document.getElementById('commentGlobalThankyou').innerHTML = 'Zahvaljujemo na va?em komentaru.';
	var ownerid = document.commentform.owner.value;
	var comment = ta.value;
	document.commentform.comment.value="";
	if(noCommentsPerPage && noCommentsPerPage != '')
		noComments = '&nocommentsperpage='+noCommentsPerPage;
	xmlLoadUrl(tmplwebpath+'/ptp_comments.jsp?owner='+ownerid+'&comment='+comment+noComments, function(xmlHttp){
		document.getElementById('commentsHolder').innerHTML = xmlHttp.responseText;
	});
}

function closePopups() {
	try {
		document.getElementById("comments").style.display="none";
		try{closeAddArticle();}catch(e){}
		try{closeAddArticle2();}catch(e){}
		try{closeActiveAnketaSuggest();}catch(e){}
		try{closeActiveArticleShare();}catch(e){}
		
		try {
			document.getElementById('push').style.paddingBottom = "";
		} catch (e) {}
	}catch(e){}
}

function validateAddArticleForm(form) {
	if(form.fname.value=='') {
		document.getElementById("writeAnArticleErrorfname").style.display="block";
		return false;
	}
	document.getElementById("writeAnArticleErrorfname").style.display="none";
	if(form.body.value=='') {
		document.getElementById("writeAnArticleErrorbody").style.display="block";
		return false;
	}
	document.getElementById("writeAnArticleErrorbody").style.display="none";
	return true;
}

function validateAddArticle2Form(form) {
	if(form.fname.value=='') {
		document.getElementById("writeAnArticle2Errorfname").style.display="block";
		return false;
	}
	document.getElementById("writeAnArticle2Errorfname").style.display="none";
	if(form.body.value=='') {
		document.getElementById("writeAnArticle2Errorbody").style.display="block";
		return false;
	}
	document.getElementById("writeAnArticle2Errorbody").style.display="none";
	return true;
}

function showAddArticle(ref_el_id, articleid, articleUser, bg,  event, leftMargin) {
	closePopups();
	document.getElementById("addarticleform").article.value = articleid;
	var articleFrom = '';
//	document.getElementById("addarticleDNAME").innerHTML = articleUser;
	if (bg)
		document.getElementById("picwaotbg").src=bg;
	document.getElementById("addarticle").style.display="";
	positionAddArticle(document.getElementById('addarticle'), ref_el_id, event, leftMargin);
}

var documentOnClickCommentsAddArticle = null;
var documentOnKeyPressCommentsAddArticle = null;

function addArticleDocumentOnKeyPress(event){
	if(!event)
		event = window.event;
	if(!event)
		return;
	if ((event.charCode || event.keyCode) == 27)
		closeAddArticle();
}

function closeAddArticle(){
	var cdiv = document.getElementById("addarticle");
//	if(cdiv.style.display != 'none') {
//		cdiv.style.display = 'none';
	if(cdiv.style.left != '-1000px') {
		cdiv.style.top = '1px';
		cdiv.style.left = '-1000px';
		document.onclick = documentOnClickAddArticleBackup;
		document.onkeypress = documentOnKeyPressAddArticleBackup;
		document.getElementById('push').style.paddingBottom = "";
		document.getElementById("writeAnArticleErrorfname").style.display="none";
		document.getElementById("writeAnArticleErrorbody").style.display="none";
	}
}

function positionAddArticle(addArticleDiv, ref_el_id, event, leftMargin) {
	var ref_el = document.getElementById(ref_el_id);
	var pos = getOffsetPosition(ref_el);
	var posParent = getOffsetPosition(addArticleDiv.parentNode);
	if(window.event)
		event = window.event;
	if(event)
		stopEventBubbling(event);
	documentOnClickAddArticleBackup = document.onclick;
	document.onclick = closeAddArticle;
	documentOnKeyPressAddArticleBackup = document.onkeypress;
	document.onkeypress = addArticleDocumentOnKeyPress;
	
	addArticleDiv.onclick = stopEventBubbling;
	
	var addLeft = 0;
	try{
		if(pos.x>document.body.offsetWidth/2)
			addLeft -= addArticleDiv.offsetWidth-ref_el.offsetWidth;
	}catch(e){}
	var cdiv = addArticleDiv;
	
	cdiv.style.top = (pos.y+ref_el.offsetHeight-posParent.y)+'px';
	cdiv.style.left = (pos.x-posParent.x+addLeft)+'px';
	if(leftMargin)
		cdiv.style.marginLeft = leftMargin+'px';
	else
		cdiv.style.marginLeft = '0px';
	
	var popupBottom = addArticleDiv.offsetHeight + getOffsetPosition(addArticleDiv).y;
	fixDocumentHeight(popupBottom);
}

//ADDARTICLE2 START
function showAddArticle2(event) {
	closePopups();
	if(userLogin=='') {
		openLoginBox();
		return;
	}
	var articleFrom = '';
//	document.getElementById("addarticle2DNAME").innerHTML = articleUser;
//	if (bg)
//		document.getElementById("picwaotbg").src=bg;
	document.getElementById("addarticle2").style.display="";
	positionAddArticle2(document.getElementById('addarticle2'), event);
}

var documentOnClickCommentsAddArticle2 = null;
var documentOnKeyPressCommentsAddArticle2 = null;

function addArticle2DocumentOnKeyPress(event){
	if(!event)
		event = window.event;
	if(!event)
		return;
	if ((event.charCode || event.keyCode) == 27)
		closeAddArticle2();
}

function closeAddArticle2(){
	var cdiv = document.getElementById("addarticle2");
	if(cdiv.style.display != 'none') {
		cdiv.style.display = 'none';
//	if(cdiv.style.left != '-1000px') {
//		cdiv.style.top = '1px';
//		cdiv.style.left = '-1000px';
		document.onclick = documentOnClickAddArticle2Backup;
		document.onkeypress = documentOnKeyPressAddArticle2Backup;
//		document.getElementById('push').style.paddingBottom = "";
		document.getElementById("writeAnArticle2Errorfname").style.display="none";
		document.getElementById("writeAnArticle2Errorbody").style.display="none";
	}
}

function positionAddArticle2(addArticleDiv, event) {
	var posParent = getOffsetPosition(addArticleDiv.parentNode);
	if(window.event)
		event = window.event;
	if(event)
		stopEventBubbling(event);
	documentOnClickAddArticle2Backup = document.onclick;
	document.onclick = closeAddArticle2;
	documentOnKeyPressAddArticle2Backup = document.onkeypress;
	document.onkeypress = addArticle2DocumentOnKeyPress;
	
	addArticleDiv.onclick = stopEventBubbling;
	
	return;
	var addLeft = 0;
	try{
		if(pos.x>document.body.offsetWidth/2)
			addLeft -= addArticleDiv2.offsetWidth-ref_el.offsetWidth;
	}catch(e){}
	var cdiv = addArticleDiv;
	
	cdiv.style.top = (pos.y+ref_el.offsetHeight-posParent.y)+'px';
	cdiv.style.left = (pos.x-posParent.x+addLeft)+'px';
	if(leftMargin)
		cdiv.style.marginLeft = leftMargin+'px';
	else
		cdiv.style.marginLeft = '0px';
	
	var popupBottom = addArticleDiv.offsetHeight + getOffsetPosition(addArticleDiv).y;
	fixDocumentHeight(popupBottom);
}
//ADDARTICLE2 END

function fixDocumentHeight(popupBottom) {
	if(getOffsetPosition(document.getElementById('push')).y < popupBottom)
		try {
			document.getElementById('push').style.paddingBottom = popupBottom - getOffsetPosition(document.getElementById('push')).y + 'px';
		} catch (e) {}
}

function initOnBodyLoad() {
	try {
		if(articleInner) {
			var addArticle = document.getElementById("addarticle");
			addArticle.parentNode.removeChild(addArticle);
			document.getElementById("contentContainer").appendChild(addArticle);
		}
	}catch(e){}
	cutAllArticleExcessContentText();
	initHeaderBannerChange();
	
	
}

var headerBanners = null;
var activeHeaderBanner = 0;
var activeHeaderBannerPosition = null;

function changeHeaderBanner() {

	var nextActiveHeaderBanner = activeHeaderBanner+1;
	if(nextActiveHeaderBanner>=headerBanners.length)
		nextActiveHeaderBanner = 0;

	var active = headerBanners[activeHeaderBanner];
	var next = headerBanners[nextActiveHeaderBanner];

	active.style.position = 'absolute';
	active.style.top = activeHeaderBannerPosition.y + 'px';
	active.style.left = activeHeaderBannerPosition.x + 'px';

	next.style.position = 'absolute';
	next.style.top = activeHeaderBannerPosition.y + 'px';
	next.style.left = activeHeaderBannerPosition.x + 'px';

	activeHeaderBanner = nextActiveHeaderBanner;
	active.style.zIndex = '100';
	next.style.zIndex = '101';
	next.style.display = 'block';
	Animation.fadeIn(next, function() {
		//active.style.display = 'none';
		setTimeout(changeHeaderBanner, 10000);
	});
}

function initHeaderBannerChange() {
	headerBanners = getChildNodesByClass(document.body, "bannerContainer");
	if(headerBanners[0]) {
		activeHeaderBannerPosition = getOffsetPosition(headerBanners[0]);
		var tmpPos = getOffsetPosition(headerBanners[0].parentNode);
		activeHeaderBannerPosition.x -= tmpPos.x;
//		activeHeaderBannerPosition.y += 10;//tmpPos.y;
		activeHeaderBannerPosition.y = 0;
	}
	//document.getElementById('headerBannerContainerHolder').style.display = 'block';
	setTimeout(changeHeaderBanner, 10000);
}

var activeArticleShare = null;
var activeArticleShareParent = null;

function findFirstParentWithClass(item, className) {
	while(item.parentNode && item.parentNode!=null) {
		item = item.parentNode;
		try {
			if(item && item.attributes && item.attributes['class'] && item.attributes['class'].value.indexOf(className)>-1)
				return item;
		} catch (e) {}
	}
}

function showArticleShareInner(link) {
	var parent = findFirstParentWithClass(link, 'article_2ndPage');
	closePopups();
	activeArticleShare = findFirstChildByName(parent, "shareDiv");
	activeArticleShare.style.display="block";
	activeArticleShareParent = parent;
}

var documentOnClickShowArticleShareBackup = null;
var documentOnKeyPressShowArticleShareBackup = null;

function articleShareDocumentOnKeyPress(event){
	if(!event)
		event = window.event;
	if(!event)
		return;
	if ((event.charCode || event.keyCode) == 27)
		closeActiveArticleShare();
}

function showArticleShare(event, parentId){
	var parent = document.getElementById(parentId);
	closePopups();
	activeArticleShare = findFirstChildByName(parent, "shareDiv");
	activeArticleShareParent = activeArticleShare.parentNode;
	
	activeArticleShare.style.position = "absolute";
	
	if(window.event)
		event = window.event;
	if(event)
		stopEventBubbling(event);
	
	documentOnClickArticleShareBackup = document.onclick;
	document.onclick = closeActiveArticleShare;
	documentOnKeyPressArticleShareBackup = document.onkeypress;
	document.onkeypress = articleShareDocumentOnKeyPress;
	
	activeArticleShare.style.display="block";
	
	var pos = getOffsetPosition(activeArticleShare);
	var posParent = getOffsetPosition(parent);
	var addLeft = 0;
	try{
		if(pos.x>document.body.offsetWidth/2)
			addLeft -= activeArticleShare.offsetWidth - parent.offsetWidth;
	}catch(e){}
	var cdiv = activeArticleShare;
	cdiv.style.top = (posParent.y + parent.offsetHeight)+'px';
	cdiv.style.left = (posParent.x+addLeft)+'px';
	activeArticleShareParent.removeChild(activeArticleShare);
	document.body.appendChild(activeArticleShare);
	var popupBottom = activeArticleShare.offsetHeight + getOffsetPosition(activeArticleShare).y;
	fixDocumentHeight(popupBottom);
}

function closeActiveArticleShare() {
	if(activeArticleShare && activeArticleShare != null)
		closeArticleShare(activeArticleShare);
}

function closeArticleShare(shareDiv){
	try {
		shareDiv.style.display="none";
		document.body.removeChild(shareDiv);
		activeArticleShareParent.appendChild(shareDiv);
	} catch (e) {}
	activeArticleShare = null;
	activeArticleShareParent = null;
	document.getElementById('push').style.paddingBottom = "";
}

function findFirstChildByName(item, name){
	if(!item.childNodes)
		return null;
	var i=0;
	for(i=0;i<item.childNodes.length;i++){
		try{
			if(item.childNodes[i].attributes['name'] && item.childNodes[i].attributes['name'].value==name){
				return item.childNodes[i];
			}
			var tmp = findFirstChildByName(item.childNodes[i], name);
			if(tmp!=null)
				return tmp;
		}catch(e){}
	}
	return null;
}

function openLoginBox() {
	document.getElementById('loginPopup').style.display = 'block';
	setTimeout('window.location="show.jsp?loginpage=true&amp;takemeback=true"', 4000);
}

function openLoginBox1(takemeback) {
	document.getElementById('loginPopup').style.display = 'block';
	setTimeout('window.location="show.jsp?loginpage=true&takemeback='+takemeback+'"', 4000);
}

function addBodyOnLoad(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

var measurediv = document.createElement('div');

function measureHeight(element, innerHTML) {

	var styleVar = element.style.cssText;
	measurediv.style.cssText = styleVar;
	var indexOfScript = innerHTML.indexOf("<script")!=-1 ? innerHTML.indexOf("<script") : innerHTML.indexOf("<SCRIPT");
	if (indexOfScript!=-1) {
		innerHTML = innerHTML.substring(0, indexOfScript);
	}
	
	var indexHeight = innerHTML.indexOf("height:")!=-1 ? innerHTML.indexOf("height:") : innerHTML.indexOf("HEIGHT:");
	while (indexHeight!=-1) {
		innerHTML = innerHTML.substring (0, indexHeight).concat(innerHTML.substring(indexHeight+14));
		indexHeight = innerHTML.indexOf("height:")!=-1 ? innerHTML.indexOf("height:") : innerHTML.indexOf("HEIGHT:");
	}
	
	var indexAbsolute = innerHTML.indexOf("position: absolute;")!=-1 ? innerHTML.indexOf("position: absolute;") : innerHTML.indexOf("POSITION: absolute;");
	while (indexAbsolute!=-1) {
		innerHTML = innerHTML.substring (0, indexAbsolute).concat(innerHTML.substring(indexAbsolute+19));
		indexAbsolute = innerHTML.indexOf("position: absolute;")!=-1 ? innerHTML.indexOf("position: absolute;") : innerHTML.indexOf("POSITION: absolute;");
	}

	
	measurediv.innerHTML = innerHTML;
	measurediv.style.height = '';
	measurediv.style.left = '-2000px';
	measurediv.style.position = 'absolute';
	var height = measurediv.offsetHeight;

	return height+45;
}


function cutArticleExcessContentTextRecursive(element, content, originalHTML, cut, size) {
	content.innerHTML = originalHTML.substr(0, cut);
	innerHTMLToPass = element.innerHTML;
	var sheight = parseInt(element.style.height);
	
	var height = measureHeight(element, innerHTMLToPass);
	
	if(height + 20 > sheight && height < sheight)
		return cut;
	if(height >= sheight) {
		if(size/2<0.5)
			return -1;
		var r1 = cutArticleExcessContentTextRecursive(element, content, originalHTML, cut - size, size/2);
		return r1;
	} else {
		if(size/2<0.5)
			return cut;
		var r2 = cutArticleExcessContentTextRecursive(element, content, originalHTML, cut + size, size/2);
		return r2;
	}
}


function cutArticleExcessContentText(element, flag) {

	if(!findFirstDivByClass(element, 'articleHorizontal') && !findFirstDivByClass(element, 'articleVertical'))
		return;
	
	innerHTMLToPass = element.innerHTML;
	
	var sheight = parseInt(element.style.height);

	
	var height = measureHeight(element, innerHTMLToPass);

	if(height > sheight) {
		var contents = getChildNodesByClass(element, 'content');
		if(contents != null && contents.length>0) {
			var content = contents[0];
			var htmllength = content.innerHTML.length;
			
			var length = cutArticleExcessContentTextRecursive(element, content, ""+content.innerHTML, htmllength / 2, htmllength / 4);
			var tmplength = content.innerHTML.lastIndexOf(" ", length-1);
			if(tmplength>-1) {
				length = tmplength;
				tmplength = content.innerHTML.lastIndexOf(" ", length-1);
				if(tmplength>-1)
					length = tmplength;
			}

			content.innerHTML = content.innerHTML.substring(0, length)+"...";

			try {
				if(isPreview)
					if (flag==0) {
						
						saveArticleExcessContentText(content, length);
					}
			} catch (e) {
			}
		}
	} else {
		try {
			var contents = getChildNodesByClass(element, 'content');
			if(contents != null && contents.length>0) {
				var content = contents[0];
				if(isPreview)
					if (flag==0) {
						saveArticleExcessContentText(content, 0);
					}
			}
		} catch (e) {
		}
	}
	
	$(element).find(".wrapper").height(sheight);
	//$(element).find(".item1holder").css("position", "absolute");
	//$(element).find(".item2holder").css("position", "absolute");
	
}

function saveArticleExcessContentText(element, length) {
	var id = element.attributes['id'].value.substr(19);
	var url = 'admin/views/site_structure/edit/ptp_article_cat.jsp?savecontenttextlength='+length+'&oid='+id;
	xmlLoadUrl(url);
}


function cutArticleExcessContentTextAjaxSpec(element, divid) {
	document.body.appendChild(measurediv);
	cutArticleExcessContentTextSpec(element, 0,divid);
	//alert (measurediv.innerHTML);
	document.body.removeChild(measurediv);
}


function cutAllArticleExcessContentText() {
	document.body.appendChild(measurediv);
	var toCheck = getChildNodesByClass(document.body, 'cloudContainer');
	for(var i=0;i<toCheck.length;i++) {
		cutArticleExcessContentText(toCheck[i]);
	}
	document.body.removeChild(measurediv);
}

//addBodyOnLoad(cutAllArticleExcessContentText);

function getChildNodesByClass(parent, className){
	var childs = parent.childNodes;
	var result = [];
	if(childs){
		var i;
		for(i=0;i<childs.length;i++){
			try{
				var child = childs[i];
				if(child.attributes)
					if(child.attributes['class'])
						if(child.attributes['class'].value.indexOf(className)>-1)
							result.push(child);
				var tmp = getChildNodesByClass(child, className);
				if(tmp!=null)
					result = result.concat(tmp);
			}catch(e){alert(e);}
		}
	}
	return result;
}

function findFirstDivByClass(parent, className){
	var childs = parent.childNodes;
	if(childs){
		var i;
		for(i=0;i<childs.length;i++){
			try{
				var child = childs[i];
				if(child.attributes)
					if(child.attributes['class'])
						if(child.attributes['class'].value.indexOf(className)>-1)
							return child;
				var result = findFirstDivByClass(child, className);
				if(result!=null)
					return result;
			}catch(e){alert(e);}
		}
	}
	return null;
}

function findChildrenByClass(parent, className){
	var result = new Array();
	var childs = parent.childNodes;
	if(childs){
		var i;
		for(i=0;i<childs.length;i++){
			try{
				var child = childs[i];
				if(child.attributes)
					if(child.attributes['class'])
						if(child.attributes['class'].value.indexOf(className)>-1)
							return child;
				var tmp = findChildrenByClass(child, className);
				if(tmp!=null && tmp && tmp.length>0)
					return tmp;
			}catch(e){alert(e);}
		}
	}
	return result;
}

function validateMessageToThePresident(form) {
	if(form.sms.value=='') {
		try {
			findFirstDivByClass(form, 'smsErrorMessage').style.display='block';
		} catch (e) {
		}
		return false;
	}
	return true;
}





function measureHeightSpec(element, innerHTML, divid) {

//alert ("prije"+	innerHTML);
	var styleVar = element.style.cssText;
	measurediv.style.cssText = styleVar;
	var articleRealId = (divid.substring(divid.indexOf("_")+1));
	if (eval("nextDivToRender_" + articleRealId).indexOf("next")!=-1) {

		var start= innerHTML.indexOf('div id="currentitem_'+articleRealId)!=-1 ? innerHTML.indexOf('div id="currentitem_'+articleRealId) : innerHTML.indexOf('DIV id=currentitem_'+articleRealId);
		var end= innerHTML.indexOf('div id="currentitemend_'+articleRealId)!=-1 ? innerHTML.indexOf('div id="currentitemend_'+articleRealId) : innerHTML.indexOf('DIV id=currentitemend_'+articleRealId);
		if (start!=-1 && end!=-1) {	
			var rest = innerHTML.substring(end);
			var ind = rest.indexOf("</div>")+6;
			innerHTML = innerHTML.substring(0, start-1).concat(innerHTML.substring(end+ind));
			
		}

	} else {


		$('#nexttitem_'+divid).html("");
		$('#nexttitempicture_'+divid).html("");
		var start= innerHTML.indexOf('div id="nextitem_'+articleRealId)!=-1? innerHTML.indexOf('div id="nextitem_'+articleRealId) : innerHTML.indexOf('DIV id=nextitem_'+articleRealId);
		var end= innerHTML.indexOf('div id="nextitemend_'+articleRealId)!=-1? innerHTML.indexOf('div id="nextitemend_'+articleRealId) : innerHTML.indexOf('DIV id=nextitemend_'+articleRealId);
		
		if (start!=-1 && end!=-1) {
			
			var rest = innerHTML.substring(end);
			var ind = rest.indexOf("</div>")+6;
			innerHTML = innerHTML.substring(0, start-1).concat(innerHTML.substring(end+ind));
		}
	}


	var start = innerHTML.indexOf('<div id="fromdelete"');
	var end = innerHTML.indexOf('<div id="todelete"');
	if (start!=-1 && end!=-1) {
		innerHTML = innerHTML.substring(0, start).concat(innerHTML.substring(end+25));
	}	

	start = innerHTML.indexOf('<DIV id=fromdelete');
	end = innerHTML.indexOf('<DIV id=todelete');
	if (start!=-1 && end!=-1) {
		innerHTML = innerHTML.substring(0, start).concat(innerHTML.substring(end+23));
	}	

	start = innerHTML.indexOf('<div id="from2delete');
	end = innerHTML.indexOf('<div id="to2delete');
	if (start!=-1 && end!=-1) {
		innerHTML = innerHTML.substring(0, start).concat(innerHTML.substring(end+26));
	}	

	start = innerHTML.indexOf('<DIV id=from2delete');
	end = innerHTML.indexOf('<DIV id=to2delete'); 
	
	if (start!=-1 && end!=-1) {
		innerHTML = innerHTML.substring(0, start).concat(innerHTML.substring(end+24));
	} 
	

	var indexOfScript = innerHTML.indexOf("<script")!=-1 ? innerHTML.indexOf("<script") : innerHTML.indexOf("<SCRIPT");

	if (indexOfScript!=-1) {
		innerHTML = innerHTML.substring(0, indexOfScript);
	}

	var indexHeight = innerHTML.indexOf("height:")!=-1 ? innerHTML.indexOf("height:") : innerHTML.indexOf("HEIGHT:");

	while (indexHeight!=-1) {
		innerHTML = innerHTML.substring (0, indexHeight).concat(innerHTML.substring(indexHeight+14));
		indexHeight = innerHTML.indexOf("height:")!=-1 ? innerHTML.indexOf("height:") : innerHTML.indexOf("HEIGHT:");
	}

	var indexAbsolute = innerHTML.indexOf("position: absolute;")!=-1 ? innerHTML.indexOf("position: absolute;") : innerHTML.indexOf("POSITION: absolute;");
	while (indexAbsolute!=-1) {
		innerHTML = innerHTML.substring (0, indexAbsolute).concat(innerHTML.substring(indexAbsolute+19));
		indexAbsolute = innerHTML.indexOf("position: absolute;")!=-1 ? innerHTML.indexOf("position: absolute;") : innerHTML.indexOf("POSITION: absolute;");
	}


	measurediv.innerHTML = innerHTML;
	measurediv.style.height = '';
	measurediv.style.left = '-2000px';
	measurediv.style.position = 'absolute';
// document.body.appendChild(measurediv);
	var height = measurediv.offsetHeight;
	//alert(innerHTML);


	
// document.body.removeChild(measurediv);
 //alert(measurediv.innerHTML);
 	
 	//alert ("nakon"+	innerHTML);
 
 
	return height+45;
}

function cutArticleExcessContentTextRecursiveSpec(element, content, originalHTML, cut, size, divid) {
	content.innerHTML = originalHTML.substr(0, cut);
	innerHTMLToPass = element.innerHTML;
	var sheight = parseInt(element.style.height);
	
	//$(element).find(".wrapper").height(sheight-120);

	var height = measureHeightSpec(element, innerHTMLToPass, divid);
		
	if(height + 20 > sheight && height < sheight)
		return cut;
	if(height >= sheight) {
		if(size/2<0.5)
			return -1;
		var r1 = cutArticleExcessContentTextRecursiveSpec(element, content, originalHTML, cut - size, size/2,divid);
		return r1;
	} else {
		if(size/2<0.5)
			return cut;
		var r2 = cutArticleExcessContentTextRecursiveSpec(element, content, originalHTML, cut + size, size/2,divid);
		return r2;
	}
}

function cutArticleExcessContentTextSpec(element, flag, divid) {

	if(!findFirstDivByClass(element, 'articleHorizontal') && !findFirstDivByClass(element, 'articleVertical'))
		return;
	
	innerHTMLToPass = element.innerHTML;

	var sheight = parseInt(element.style.height);

	var height = measureHeightSpec(element, innerHTMLToPass, divid);

	if(height > sheight) {
		var contents = getChildNodesByClass(element, 'content');
		var articleRealId = (divid.substring(divid.indexOf("_")+1));

		if(contents != null && contents.length>0) {
			if (eval("nextDivToRender_" + articleRealId).indexOf("next")!=-1) {
				var content = contents[0];
			} else {
				var content = contents[1];
			}
			var htmllength = content.innerHTML.length;
			
			var length = cutArticleExcessContentTextRecursiveSpec(element, content, ""+content.innerHTML, htmllength / 2, htmllength / 4, divid);
			var tmplength = content.innerHTML.lastIndexOf(" ", length-1);
			if(tmplength>-1) {
				length = tmplength;
				tmplength = content.innerHTML.lastIndexOf(" ", length-1);
				if(tmplength>-1)
					length = tmplength;
			}

			content.innerHTML = content.innerHTML.substring(0, length)+"...";
			
			try {
				if(isPreview)
					if (flag==0) {
						
						saveArticleExcessContentText(content, length);
					}
			} catch (e) {
			}
		}
	} else {
		try {
			var contents = getChildNodesByClass(element, 'content');
			if(contents != null && contents.length>0) {
				var content = contents[0];
				if(isPreview)
					if (flag==0) {
						saveArticleExcessContentText(content, 0);
					}
			}
		} catch (e) {
		}
	}
}





