

function showHideLogin(showHide) {
	
	if (showHide == null) {
		showHide = true;	
	}

	var myWidth = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
	}
	
	var left = (myWidth / 2);
	window.document.getElementById('loginBox').style.left = left + 'px';
	
	window.document.getElementById('loginBoxError').style.display = 'none';
	
	if (showHide) {
		if (window.document.getElementById('loginBox').style.display != 'block') {
			window.document.getElementById('loginBox').style.display = 'block';	
		} else {
			window.document.getElementById('loginBox').style.display = 'none';
		}
	}
	
	return false;
}


function showLoginError() {
	
	var myWidth = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
	}
	
	var left = (myWidth / 2) + 100;
	window.document.getElementById('loginBoxError').style.left = left + 'px';
	
	window.document.getElementById('loginBoxError').style.display = 'block';	
}


var prev_desc_len = 0;
function clean_description(desc) {
    
	if (desc == null) {
		return '';
	}
	clean_desc = desc;

	//clean_desc = clean_desc.replace(/(^\s*)|(\s*$)/gi,"");
	clean_desc = clean_desc.replace(/[ ]{3,}/gi," ");
	clean_desc = clean_desc.replace(/\n /,"\n");

	// remove new lines
	clean_desc = clean_desc.replace(/(\r\n|\r|\n)/g, " ");
	
	clean_desc = clean_desc.replace(". -", ". ");
	
	// cut first 400 characters
	if (clean_desc.length > 400) {
		clean_desc = clean_desc.substring(0,400);
	}
	
	if ((clean_desc.length - prev_desc_len) > 50) {
		// cut half part of last sentence
		if (clean_desc.lastIndexOf(",") > clean_desc.lastIndexOf(".")) {
			
			clean_desc = clean_desc.substring(0, clean_desc.lastIndexOf(","));
			clean_desc = clean_desc + "...";
			
		} else if (clean_desc.lastIndexOf(".") > (clean_desc.length / 3) && clean_desc.lastIndexOf(".") < clean_desc.length) {
			
			clean_desc = clean_desc.substring(0, clean_desc.lastIndexOf("."));	
			
			if (clean_desc.lastIndexOf(".") != clean_desc.length) {
				clean_desc = clean_desc + ".";
			}
		}
	}
	prev_desc_len = clean_desc.length
	return clean_desc;
}


function icon_up(id) {
  window.document.getElementById('icon_'+id).src='/img/red_icon_down2.jpg';
}

function icon_down(id) {
  window.document.getElementById('icon_'+id).src='/img/red_icon2.jpg';
}

var vote_id;
var tmp_vote;
var vote_in_process = 0;
function vote(id, way) {
if (vote_in_process == 1) {
  return false;
}
vote_in_process = 1;
if (!logged) {
   window.location = '/' + current_category + '/glasanje_prijava';
   return false;
}
vote_id = id;
tmp_vote = $('votes'+id).innerHTML;
$('votes'+id).innerHTML = '<img src="/img/loading.gif" width="16" height="16" border="0" />';
var myAjax = new Ajax.Request(
            '/lib/vote', 
            {
                method: 'get',
                parameters: "id="+id+"&way="+way,
                onComplete: alertResponse
            }
            );

}
 
function alertResponse(reply)
{
   resp = reply.responseText;
   if (resp == 'not logged') {
     // alert('Glasati mogu samo prijavjeni korisnici, molimo da se prijavite');
      window.location = '/' + current_category + '/glasanje_prijava';
      $('votes'+vote_id).innerHTML = tmp_vote;
   } else if (resp == 'voted') {
      alert('Dozvoljeno je glasati samo jednom');
      $('votes'+vote_id).innerHTML = tmp_vote;
   } else {
      $('votes'+vote_id).innerHTML = resp;
   }
   vote_in_process = 0;
}



function visit(id) {

var myAjax = new Ajax.Request(
            '/lib/visit', 
            {
                method: 'get',
                parameters: "id="+id,
                onComplete: visitResponse
            }
            );
}

function visitResponse(reply)
{
   resp = reply.responseText;
   return resp;
}

function visitBanner(id) {

var myAjax = new Ajax.Request(
            '/lib/banner_visit', 
            {
                method: 'get',
                parameters: "id="+id,
                onComplete: visitResponseBanner
            }
            );
}

function visitResponseBanner(reply)
{
   resp = reply.responseText;
   return resp;
}


function visitBannerUq(id) {

var myAjax = new Ajax.Request(
            '/lib/banner_visit_unique', 
            {
                method: 'get',
                parameters: "id="+id,
                onComplete: visitResponseBannerUq
            }
            );
}

function visitResponseBannerUq(reply)
{
   resp = reply.responseText;
   return resp;
}



function tag(id, tag) {
if (tag == '') {
	alert("Molim da oznacite text i kliknete na Dodaj tag");
	return false;
}
var myAjax = new Ajax.Request(
            '/v3/lib/tag', 
            {
                method: 'get',
                parameters: "id="+id+"&tag="+tag,
                onComplete: tagResponse
            }
            );
}

function tagResponse(reply)
{
   resp = reply.responseText;
   if (resp == 'not logged') {
     // alert('Glasati mogu samo prijavjeni korisnici, molimo da se prijavite');
      alert('Niste prijavljeni');
   } else if (resp == '1') {
      alert('Tag je dodan');
   } else {
      alert('Tag nije dodan');
   }
   vote_in_process = 0;
}

function getSelText()
{
    var txt = '';
     if (window.getSelection)
    {
        txt = window.getSelection();
             }
    else if (document.getSelection)
    {
        txt = document.getSelection();
            }
    else if (document.selection)
    {
        txt = document.selection.createRange().text;
            }
    else return;
	
return  txt;
}


function selectCat(radioId) {
	window.document.getElementById(radioId).checked = true;
}

function findPosX(obj) {
	var curleft = 0;
	if(obj.offsetParent) {
		while(1) {
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	} else if(obj.x) {
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if(obj.offsetParent) {
		while(1) {
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	} else if(obj.y) {
		curtop += obj.y;
	}
	return curtop;
}

function changeImage(img_id) {
	var img_obj = window.document.getElementById('img' + img_id);
	var img_x = findPosX(img_obj);
	var img_y = findPosY(img_obj);
	
	window.document.getElementById('changeImgBox').style.left = img_x + 'px';
	window.document.getElementById('changeImgBox').style.top = (img_y + 95) + 'px';
	window.document.getElementById('changeImgBox').style.display = 'block';	
	window.document.getElementById('change_img_id').value = img_id;
}

function showAddGallery() {
	var img_obj = window.document.getElementById('imgGalleryBox');
	var img_x = findPosX(img_obj);
	var img_y = findPosY(img_obj);
	
	window.document.getElementById('youtubeBlock').style.display = 'none';
	
	window.document.getElementById('addGalleryBox').style.left = img_x + 'px';
	window.document.getElementById('addGalleryBox').style.top = (img_y + 195) + 'px';
	window.document.getElementById('addGalleryBox').style.display = 'block';	
}

function showAddVideo() {
	var img_obj = window.document.getElementById('youtubeBlock');
	var img_x = findPosX(img_obj);
	var img_y = findPosY(img_obj);
	
	window.document.getElementById('videoBox').style.left = img_x + 'px';
	window.document.getElementById('videoBox').style.top = (img_y + 250) + 'px';
	window.document.getElementById('videoBox').style.display = 'block';	
}

var radioWindow = null;
function playRadio() {
		
		if (radioWindow) {
			radioWindow.close();
		} 
		var div_obj = window.document.getElementById('radioBox');
		var div_x = (screen.width / 2) - 240;
		var div_y = (screen.height / 2) - 50;
		radioWindow = window.open('/radio','radiowin','left='+div_x+',top='+div_y+',width=435,height=75,toolbar=0,status=0,menubar=0,location=no,resizable=0,locationbar=no');
				
}


function showCommentForm (news_id, target_url, username) {
	

	if (window.document.getElementById(news_id).style.display != 'block') {
		window.document.getElementById(news_id).style.display = 'block';
		
	window.document.getElementById(news_id).innerHTML = 
'<form name="comment_form" method="post" action="'+target_url+'">'
+'<div class="newsBlock"> <!-- News Block start -->'
+'	<div class="boxBg">'

+'		<div class="commentOutBox">'
+'			<div class="commentLabel">Ime:</div>'
+'			<div class="commentFieldBox">'
+'				<input type="text" name="ime" class="inputTxt" style="height:20px;" autocomplete="off" id="ime" value="'+username+'" />'
+'			</div>'
+'			<div class="clear2"><!-- IE --></div>'
+'		</div>'
		
+'		<div class="commentOutBox">'
+'			<div class="commentLabel">Komentar:</div>'
+'			<div class="commentFieldBox">'
+'				<textarea id="comment" class="commentTextArea" name="comment"  onKeyUp="if (this.value.length > 1000) this.value = this.value.substring(0,1000);"'
+'				onBlur="if (this.value.length > 1000) this.value = this.value.substring(0,1000);" onChange="if (this.value.length > 1000) this.value = this.value.substring(0,1000);"></textarea>'
+'			</div>'
+'			<div class="clear2"><!-- IE --></div>'
+'		</div>'
			
+'		<div class="commentOutBox">'
+'			<div class="commentLabel">Prepi&#353;ite:</div>'
+'			<div class="commentFieldBox">'
+'				<img id="cryptogram" src="/v3/lib/crypt/cryptographp.php?cfg=0&amp;" width="120" height="40" alt="" align="left" />'
+'				<div class="inputCheck"><input type="text" name="code" id="code" autocomplete="off" maxlength="4" /></div>'
+'				<div class="textLnk"><a href="#" title="Ne vidite pro&#269;itati kod? Kliknite za novi" '
+'				onclick="window.document.getElementById(\'cryptogram\').src=\'/v3/lib/crypt/cryptographp.php?cfg=0&amp;&amp;\'+Math.round(Math.random(0)*1000)+1; return false;">Prika&#382;i novi kod</a></div>'
+'			</div>'
+'			<div class="clear2"><!-- IE --></div>'
+'		</div>'	
				
+'		<div style="width:570px; text-align:right;"><input type="submit" name="submit_comment" value="Objavi komentar &#187;" class="postArticleSubmit" /></div>'
				
+'	</div>'
+'</div>'
+'</form>';
	} else {
		window.document.getElementById(news_id).style.display = 'none';
		window.document.getElementById(news_id).innerHTML = '';
	}


}


function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	alert('Za dodavanje stranice u Bookmarks pritisnite tipke Ctrl+D');
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}


function borderUp(obj) {
	obj.style.border = '1px solid #FB6D09'
}

function borderDown(obj) {
	obj.style.border = '1px solid #ffffff'
}