
var upload_attachments_saved_count=0;var upload_attachments_errored_count=0;var post_id=0;function ajax_vesti_nova_vest_time_popup()
{show_popup('vesti_nova_vest_time','');popup_title('Tajmirana vest');}
function ajax_vesti_nova_vest_submit(nova_vest_submit_type)
{nova_vest_naslov=$('vesti_nova_vest_naslov').value;nova_vest_podnaslov=$('vesti_nova_vest_podnaslov').value;nova_vest_bitna_vest=($('vesti_nova_vest_bitna_vest').checked)?'1':'0';nova_vest_text=xinha_editors['ajax_content_editor_content'].getEditorContent();if(nova_vest_text==''||nova_vest_text=='<br />')
new Effect.Shake($$('.htmlarea')[0],{distance:10,sync:false});if(nova_vest_naslov=='')
new Effect.Shake($('vesti_nova_vest_naslov'),{distance:10,sync:false});if(swfu.getStats().in_progress)
new Effect.Shake($$('fieldset.attached_files')[0],{distance:10,sync:false});if(nova_vest_text==''||nova_vest_text=='<br />'||nova_vest_naslov==''||swfu.getStats().in_progress)
return false;show_loading(1,'vesti_nova_vest_submit',32);xinha_editors['ajax_content_editor_content'].getPluginInstance('UnsavedChanges').disable(xinha_editors['ajax_content_editor_content']);var count_uploaded=0;$$('#swfUploadProgress .progressWrapper').each(function(element){if(element.style.display!='none')
count_uploaded++;});var upload_attachments=new Array();if(count_uploaded>0)
{$$('#swfUploadProgress .progressWrapper').each(function(element){if(element.style.display!='none')
{var attachment_filename=element.getElementsBySelector('input[name="attachment_filename[]"]')[0].value;var attachment_title=element.getElementsBySelector('input[name="attachment_title[]"]')[0].value;upload_attachments[upload_attachments.length+1]=[attachment_filename,attachment_title];}});upload_attachments.each(function(element){new Ajax.Request("ajax.php?mode=vesti&f=save_attachment&RandomKey="+Math.random()*Date.parse(new Date()),{method:'post',parameters:{attachments:Object.toJSON(element)},onComplete:function(xmlhttp){if(xmlhttp.responseXML.getElementsByTagName('result')[0].childNodes.length>0)
{var attachment_error_message;if(xmlhttp.responseXML.getElementsByTagName('result')[0].firstChild.nodeValue==1)
{_gaq.push(['_trackEvent','Vesti','Upload attachmenta']);upload_attachments_saved_count++;}
else
{upload_attachments_errored_count++;attachment_error_message=(new XMLSerializer()).serializeToString(xmlhttp.responseXML.getElementsByTagName('return')[0])}
var count_uploaded=0;$$('#swfUploadProgress .progressWrapper').each(function(element){if(element.style.display!='none')
count_uploaded++;});if(upload_attachments_saved_count+upload_attachments_errored_count>=count_uploaded)
{if(upload_attachments_errored_count==0)
{ajax_vesti_nova_vest_submit_post(1,nova_vest_submit_type);}
else
{hide_loading('vesti_nova_vest_submit');var error_div=document.createElement('div');error_div.style.textAlign="center";error_div.innerHTML=attachment_error_message;clear_popup();popup_title('Greška pri slanju prikačenih fajlova');$('popup_container').appendChild(document.createElement('br'));$('popup_container').appendChild(error_div);show_popup();}
upload_attachments_errored_count=0;upload_attachments_saved_count=0;}}}});});}
else
{ajax_vesti_nova_vest_submit_post(0,nova_vest_submit_type);}}
function ajax_vesti_nova_vest_submit_post(has_attachments,nova_vest_submit_type){var nova_vest_naslov=$('vesti_nova_vest_naslov').value;var nova_vest_podnaslov=$('vesti_nova_vest_podnaslov').value;var nova_vest_bitna_vest=($('vesti_nova_vest_bitna_vest').checked)?'1':'0';var nova_vest_text=xinha_editors['ajax_content_editor_content'].getEditorContent();var nova_vest_izvor=$('vesti_nova_vest_izvor').value;var upload_attachments=new Array();var nova_vest_tagovi=new Array();var nova_vest_d='';var nova_vest_m='';var nova_vest_y='';var nova_vest_time_h='';var nova_vest_time_m='';if(nova_vest_submit_type==3)
{nova_vest_d=$('vesti_nova_vest_d').value;nova_vest_m=$('vesti_nova_vest_m').value;nova_vest_y=$('vesti_nova_vest_y').value;nova_vest_time_h=$('vesti_nova_vest_time_h').value;nova_vest_time_m=$('vesti_nova_vest_time_m').value;hide_popup();}
$$('#vesti_nova_vest_tagovi_span_holder span').each(function(element){if(element.style.display!='none')
{nova_vest_tagovi[nova_vest_tagovi.length+1]=[element.innerHTML];}});if(has_attachments)
{$$('#swfUploadProgress .progressWrapper').each(function(element){if(element.style.display!='none')
{var attachment_filename=element.getElementsBySelector('input[name="attachment_filename[]"]')[0].value;var attachment_title=element.getElementsBySelector('input[name="attachment_title[]"]')[0].value;upload_attachments[upload_attachments.length+1]=[attachment_filename,attachment_title];}});}
upload_attachments=Object.toJSON(upload_attachments);nova_vest_tagovi=Object.toJSON(nova_vest_tagovi);if(nova_vest_text!=''&&nova_vest_text!='<br />'&&nova_vest_naslov!='')
{new Ajax.Request("ajax.php?mode=vesti&f=nova_vest&RandomKey="+Math.random()*Date.parse(new Date()),{method:'post',parameters:{naslov:nova_vest_naslov,podnaslov:nova_vest_podnaslov,text:nova_vest_text,has_attachments:has_attachments,attachments:upload_attachments,izvor:nova_vest_izvor,tagovi:nova_vest_tagovi,bitna_vest:nova_vest_bitna_vest,submit_type:nova_vest_submit_type,d:nova_vest_d,m:nova_vest_m,y:nova_vest_y,time_h:nova_vest_time_h,time_m:nova_vest_time_m},onComplete:function(xmlhttp){if(xmlhttp.responseXML.getElementsByTagName('result')[0].childNodes.length>0)
{if(xmlhttp.responseXML.getElementsByTagName('result')[0].firstChild.nodeValue==1)
{vest_id=xmlhttp.responseXML.getElementsByTagName('return')[0].firstChild.nodeValue;var bs_div=document.createElement('div');bs_div.style.textAlign="center";bs_div.innerHTML='<p>Vaša vest je uspešno poslata.</p>';clear_popup();popup_title('Nova vest');$('popup_container').appendChild(document.createElement('br'));$('popup_container').appendChild(bs_div);show_popup();setTimeout("window.location = http_host + '/vesti/vest/' + "+vest_id+" + '/'",3000);}
else
{var bs_div=document.createElement('div');bs_div.style.textAlign="center";bs_div.innerHTML='<p class="red">Greška.</p><br />'+xmlhttp.responseText;clear_popup();popup_title('Nova vest');$('popup_container').appendChild(document.createElement('br'));$('popup_container').appendChild(bs_div);show_popup();}}
hide_loading('vesti_nova_vest_submit');}});}
else
{if(nova_vest_text==''||nova_vest_text=='<br />')
new Effect.Shake($$('.htmlarea')[0],{distance:10,sync:false});if(nova_vest_naslov=='')
new Effect.Shake($('vesti_nova_vest_naslov'),{distance:10,sync:false});xinha_editors['ajax_content_editor_content'].firePluginEvent('enableUnsavedChanges');}}
function vesti_nova_vest_add_tag(tag)
{var tag_exists=false;$$('#vesti_nova_vest_tagovi_span_holder span').each(function(element){if(element.innerHTML==tag.strip())
tag_exists=true;});if(tag!=''&&!tag_exists)
{var tag_span=document.createElement('span');tag_span.innerHTML=tag;tag_span.className='nova_vest_tag';var tag_a_span=document.createElement('a');tag_a_span.className='nova_vest_tag';tag_a_span.onclick=function(){new Effect.DropOut(tag_a_span,{duration:0.3,afterFinish:function(){tag_a_span.parentNode.removeChild(tag_a_span);}});};tag_a_span.href='javascript: void(0);';tag_a_span.appendChild(tag_span);$('vesti_nova_vest_tagovi_span_holder').appendChild(tag_a_span);$('vesti_nova_vest_tagovi').value='';new Effect.Highlight(tag_a_span,{keepBackgroundImage:true});}}
function vesti_izmena_vesti_add_tag(tag)
{var tag_exists=false;$$('#vesti_izmena_vesti_tagovi_span_holder span').each(function(element){if(element.innerHTML==tag)
tag_exists=true;});if(tag!=''&&!tag_exists)
{var tag_span=document.createElement('span');tag_span.innerHTML=tag;tag_span.className='izmena_vesti_tag';var tag_a_span=document.createElement('a');tag_a_span.className='nova_vest_tag';tag_a_span.onclick=function(){new Effect.DropOut(tag_a_span,{duration:0.3,afterFinish:function(){tag_a_span.parentNode.removeChild(tag_a_span);}});};tag_a_span.href='javascript: void(0);';tag_a_span.appendChild(tag_span);$('vesti_izmena_vesti_tagovi_span_holder').appendChild(tag_a_span);$('vesti_izmena_vesti_tagovi').value='';new Effect.Highlight(tag_a_span,{keepBackgroundImage:true});}}
function ajax_vesti_izmena_vesti_time_popup(id)
{show_popup('vesti_izmena_vesti_time','&id='+id);popup_title('Tajmirana vest');}
function ajax_vesti_izmena_vesti_submit(izmena_vesti_submit_type)
{var izmena_vesti_id=$('vesti_izmena_vesti_id').value;var izmena_vesti_naslov=$('vesti_izmena_vesti_naslov').value;var izmena_vesti_podnaslov=$('vesti_izmena_vesti_podnaslov').value;var izmena_vesti_izvor=$('vesti_izmena_vesti_izvor').value;var izmena_vesti_bitna_vest=($('vesti_izmena_vesti_bitna_vest').checked)?'1':'0';var izmena_vesti_text=xinha_editors['ajax_content_editor_content'].getEditorContent();if(izmena_vesti_text==''||izmena_vesti_text=='<br />')
new Effect.Shake($$('.htmlarea')[0],{distance:10,sync:false});if(izmena_vesti_naslov=='')
new Effect.Shake($('vesti_izmena_vesti_naslov'),{distance:10,sync:false});if(swfu.getStats().in_progress)
new Effect.Shake($$('fieldset.attached_files')[0],{distance:10,sync:false});if(izmena_vesti_text==''||izmena_vesti_text=='<br />'||izmena_vesti_naslov==''||izmena_vesti_id==''|| swfu.getStats().in_progress)
return false;show_loading(1,'vesti_izmena_vesti_submit',32);xinha_editors['ajax_content_editor_content'].firePluginEvent('disableUnsavedChanges');var count_uploaded=0;$$('#swfUploadProgress .progressWrapper').each(function(element){if(element.style.display!='none'&&element.getAttribute('rel')!='old')
count_uploaded++;});var upload_attachments=new Array();if(count_uploaded>0)
{$$('#swfUploadProgress .progressWrapper').each(function(element){if(element.style.display!='none'&&element.getAttribute('rel')!='old')
{var attachment_filename=element.getElementsBySelector('input[name="attachment_filename[]"]')[0].value;var attachment_title=element.getElementsBySelector('input[name="attachment_title[]"]')[0].value;upload_attachments[upload_attachments.length+1]=[attachment_filename,attachment_title];}});upload_attachments.each(function(element){new Ajax.Request("ajax.php?mode=vesti&f=save_attachment&RandomKey="+Math.random()*Date.parse(new Date()),{method:'post',parameters:{attachments:Object.toJSON(element)},onComplete:function(xmlhttp){if(xmlhttp.responseXML.getElementsByTagName('result')[0].childNodes.length>0)
{var attachment_error_message;if(xmlhttp.responseXML.getElementsByTagName('result')[0].firstChild.nodeValue==1)
{_gaq.push(['_trackEvent','Vesti','Upload attachmenta']);upload_attachments_saved_count++;}
else
{upload_attachments_errored_count++;attachment_error_message=(new XMLSerializer()).serializeToString(xmlhttp.responseXML.getElementsByTagName('return')[0])}
var count_uploaded=0;$$('#swfUploadProgress .progressWrapper').each(function(element){if(element.style.display!='none'&&element.getAttribute('rel')!='old')
count_uploaded++;});if(upload_attachments_saved_count+upload_attachments_errored_count>=count_uploaded)
{if(upload_attachments_errored_count==0)
{ajax_vesti_izmena_vesti_submit_post(1,izmena_vesti_submit_type);}
else
{hide_loading('vesti_izmena_vesti_submit');var error_div=document.createElement('div');error_div.style.textAlign="center";error_div.innerHTML=attachment_error_message;clear_popup();popup_title('Greška pri slanju prikačenih fajlova');$('popup_container').appendChild(document.createElement('br'));$('popup_container').appendChild(error_div);show_popup();}
upload_attachments_errored_count=0;upload_attachments_saved_count=0;}}}});});}
else
{ajax_vesti_izmena_vesti_submit_post(0,izmena_vesti_submit_type);}}
function ajax_vesti_izmena_vesti_submit_post(has_attachments,izmena_vesti_submit_type){var izmena_vesti_id=$('vesti_izmena_vesti_id').value;var izmena_vesti_naslov=$('vesti_izmena_vesti_naslov').value;var izmena_vesti_podnaslov=$('vesti_izmena_vesti_podnaslov').value;var izmena_vesti_izvor=$('vesti_izmena_vesti_izvor').value;var izmena_vesti_bitna_vest=($('vesti_izmena_vesti_bitna_vest').checked)?'1':'0';var izmena_vesti_text=xinha_editors['ajax_content_editor_content'].getEditorContent();var izmena_vesti_mala_izmena=(($('vesti_izmena_vesti_mala_izmena').checked)?'1':'0');var upload_attachments=new Array();var izmena_vesti_tagovi=new Array();var izmena_vesti_d='';var izmena_vesti_m='';var izmena_vesti_y='';var izmena_vesti_time_h='';var izmena_vesti_time_m='';if(izmena_vesti_submit_type==3)
{izmena_vesti_d=$('vesti_izmena_vesti_d').value;izmena_vesti_m=$('vesti_izmena_vesti_m').value;izmena_vesti_y=$('vesti_izmena_vesti_y').value;izmena_vesti_time_h=$('vesti_izmena_vesti_time_h').value;izmena_vesti_time_m=$('vesti_izmena_vesti_time_m').value;hide_popup();}
var count_old=0;$$('#swfUploadProgress .progressWrapper').each(function(element){if(element.getAttribute('rel')=='old')
count_old++;});$$('#vesti_izmena_vesti_tagovi_span_holder span').each(function(element){if(element.style.display!='none')
{izmena_vesti_tagovi[izmena_vesti_tagovi.length+1]=[element.innerHTML];}});if(has_attachments|| count_old>0)
{has_attachments=1;$$('#swfUploadProgress .progressWrapper').each(function(element){if(element.style.display!='none')
{var attachment_filename=element.getElementsBySelector('input[name="attachment_filename[]"]')[0].value;var attachment_title=element.getElementsBySelector('input[name="attachment_title[]"]')[0].value;if(element.getAttribute('rel')=='old')
var attachment_id=element.getElementsBySelector('input[name="attachment_id[]"]')[0].value;else
var attachment_id=0;upload_attachments[upload_attachments.length+1]=[attachment_filename,attachment_title,attachment_id];}});}
upload_attachments=Object.toJSON(upload_attachments);izmena_vesti_tagovi=Object.toJSON(izmena_vesti_tagovi);if(izmena_vesti_text!=''&&izmena_vesti_text!='<br />'&&izmena_vesti_naslov!=''&&izmena_vesti_id!='')
{new Ajax.Request("ajax.php?mode=vesti&f=izmena_vesti&RandomKey="+Math.random()*Date.parse(new Date()),{method:'post',parameters:{id:izmena_vesti_id,naslov:izmena_vesti_naslov,podnaslov:izmena_vesti_podnaslov,text:izmena_vesti_text,izvor:izmena_vesti_izvor,tagovi:izmena_vesti_tagovi,mala_izmena:izmena_vesti_mala_izmena,bitna_vest:izmena_vesti_bitna_vest,has_attachments:has_attachments,attachments:upload_attachments,submit_type:izmena_vesti_submit_type,d:izmena_vesti_d,m:izmena_vesti_m,y:izmena_vesti_y,time_h:izmena_vesti_time_h,time_m:izmena_vesti_time_m},onComplete:function(xmlhttp){if(xmlhttp.responseXML.getElementsByTagName('result')[0].childNodes.length>0)
{if(xmlhttp.responseXML.getElementsByTagName('result')[0].firstChild.nodeValue==1)
{vest_id=xmlhttp.responseXML.getElementsByTagName('return')[0].firstChild.nodeValue;var bs_div=document.createElement('div');bs_div.style.textAlign="center";bs_div.innerHTML='<p>Vaša vest je uspešno izmenjena.</p>';clear_popup();popup_title('Izmena vesti');$('popup_container').appendChild(document.createElement('br'));$('popup_container').appendChild(bs_div);show_popup();setTimeout("window.location = http_host + 'vesti/vest/' + "+vest_id+" + '/'",3000);}
else
{var bs_div=document.createElement('div');bs_div.style.textAlign="center";bs_div.innerHTML='<p class="red">Greška.</p><br />'+xmlhttp.responseText;clear_popup();popup_title('Izmena vesti');$('popup_container').appendChild(document.createElement('br'));$('popup_container').appendChild(bs_div);show_popup();}}
hide_loading('vesti_izmena_vesti_submit');}});}
else
{if(izmena_vesti_text==''||izmena_vesti_text=='<br />')
new Effect.Shake($$('.htmlarea')[0],{distance:10,sync:false});if(izmena_vesti_naslov=='')
new Effect.Shake($('vesti_izmena_vesti_naslov'),{distance:10,sync:false});xinha_editors['ajax_content_editor_content'].firePluginEvent('enableUnsavedChanges');}}
function ajax_vesti_novi_komentar(){var novi_komentar_vest_id=$('vesti_novi_komentar_vest_id').value;var novi_komentar_id=$('vesti_novi_komentar_id').value;var novi_komentar_text=xinha_editors['vesti_novi_komentar_text'].getEditorContent();if(novi_komentar_vest_id!=''&&novi_komentar_text!='<br />'&&novi_komentar_text!='')
{show_loading(1,'vesti_novi_komentar_submit',32);new Ajax.Request("ajax.php?mode=vesti&f=novi_komentar&RandomKey="+Math.random()*Date.parse(new Date()),{method:'post',parameters:{vest_id:novi_komentar_vest_id,text:novi_komentar_text,id:novi_komentar_id},onComplete:function(xmlhttp){if(xmlhttp.responseXML.getElementsByTagName('result')[0].childNodes.length>0)
{if(xmlhttp.responseXML.getElementsByTagName('result')[0].firstChild.nodeValue==1)
{komentar_id=xmlhttp.responseXML.getElementsByTagName('return')[0].firstChild.nodeValue;var bs_div=document.createElement('div');bs_div.style.textAlign="center";if(novi_komentar_id==0)
bs_div.innerHTML='<p>Vaš komentar je uspešno poslat.</p>';else if(novi_komentar_id>0)
bs_div.innerHTML='<p>Vaš komentar je uspešno izmenjen.</p>';clear_popup();if(novi_komentar_id==0)
popup_title('Novi komentar na vest');else if(novi_komentar_id>0)
popup_title('Izmena komentara na vest');$('popup_container').appendChild(document.createElement('br'));$('popup_container').appendChild(bs_div);show_popup();setTimeout("window.location = http_host + 'vesti/komentar/' + "+komentar_id+" + '/'",3000);}
else
{var bs_div=document.createElement('div');bs_div.style.textAlign="center";bs_div.innerHTML='<p class="red">Greška.</p><br />'+xmlhttp.responseText;clear_popup();if(novi_komentar_id==0)
popup_title('Novi komentar na vest');else if(novi_komentar_id>0)
popup_title('Izmena komentara na vest');$('popup_container').appendChild(document.createElement('br'));$('popup_container').appendChild(bs_div);show_popup();}}
hide_loading('vesti_novi_komentar_submit');}});}
else
{if(novi_komentar_text==''||novi_komentar_text=='<br />')
new Effect.Shake($$('.htmlarea')[0],{distance:10,sync:false});}}
function ajax_vesti_izmena_komentara(id){if(id!='')
{show_loading(1,'vesti_izmena_komentara_'+id,15);new Ajax.Request("ajax.php?mode=vesti&f=izmena_komentara&RandomKey="+Math.random()*Date.parse(new Date()),{method:'post',parameters:{id:id},onComplete:function(xmlhttp){xinha_editors['vesti_novi_komentar_text'].setEditorContent(xmlhttp.responseText);myScrollTo($$('.htmlarea')[0]);$('vesti_novi_komentar_id').value=id;hide_loading('vesti_izmena_komentara_'+id);}});}}
function ajax_vesti_brisanje_vesti(id)
{show_loading(1,'confirmation_popup_btn1',32);new Ajax.Request("ajax.php?mode=vesti&f=brisanje_vesti&RandomKey="+Math.random()*Date.parse(new Date()),{method:'post',parameters:{id:id},onComplete:function(xmlhttp){if(xmlhttp.responseXML.getElementsByTagName('result')[0].childNodes.length>0)
{if(xmlhttp.responseXML.getElementsByTagName('result')[0].firstChild.nodeValue==1)
{var bs_div=document.createElement('div');bs_div.style.textAlign="center";bs_div.innerHTML='<p>Vest je uspešno izbrisana.</p>';clear_popup();popup_title('Brisanje vesti');$('popup_container').appendChild(document.createElement('br'));$('popup_container').appendChild(bs_div);show_popup();setTimeout("window.location = 'vesti/';",3000);}
else
{var bs_div=document.createElement('div');bs_div.style.textAlign="center";bs_div.innerHTML='<p class="red">Greška.</p><br />'+xmlhttp.responseText;clear_popup();popup_title('Brisanje vesti');$('popup_container').appendChild(document.createElement('br'));$('popup_container').appendChild(bs_div);show_popup();}}
hide_loading('confirmation_popup_btn1');}});}
function ajax_vesti_brisanje_komentara(id)
{show_loading(1,'confirmation_popup_btn1',32);new Ajax.Request("ajax.php?mode=vesti&f=brisanje_komentara&RandomKey="+Math.random()*Date.parse(new Date()),{method:'post',parameters:{id:id},onComplete:function(xmlhttp){if(xmlhttp.responseXML.getElementsByTagName('result')[0].childNodes.length>0)
{if(xmlhttp.responseXML.getElementsByTagName('result')[0].firstChild.nodeValue==1)
{var bs_div=document.createElement('div');bs_div.style.textAlign="center";bs_div.innerHTML='<p>Komentar je uspešno izbrisan.</p>';clear_popup();popup_title('Brisanje komentara na vest');$('popup_container').appendChild(document.createElement('br'));$('popup_container').appendChild(bs_div);show_popup();setTimeout("window.location.reload(true);",3000);}
else
{var bs_div=document.createElement('div');bs_div.style.textAlign="center";bs_div.innerHTML='<p class="red">Greška.</p><br />'+xmlhttp.responseText;clear_popup();popup_title('Brisanje komentara na vest');$('popup_container').appendChild(document.createElement('br'));$('popup_container').appendChild(bs_div);show_popup();}}
hide_loading('confirmation_popup_btn1');}});}
