﻿// JScript File


//*****************************AjaxMethods.ascx

function ObjaviIzmjeniClanak()
{
    if(validateInputs()){
    document.forms[0].btnSave.disabled = "disabled";
    var niz = new Array(7);
    niz[0] = document.getElementById("ArticleId").innerHTML;
    niz[1] = document.forms[0].drpArticleCategory.value;
    niz[2] = document.forms[0].Title.value;
    niz[3] = tinyMCE.getInstanceById('Short').getHTML();
    niz[4] = tinyMCE.getInstanceById('Full').getHTML();
    niz[5] = document.forms[0].Tags.value;
    niz[6] = document.forms[0].IsEnabled.checked;
    niz[7] = document.forms[0].EnableComments.checked;    
    AjaxMethods.modules_articles_admin_AjaxMethods.ObjaviIzmjeniClanak(niz,ObjaviClanak_CallBack);
}
}

function ObjaviClanak_CallBack(rez)
{
    if(rez.value =="true")
    {alert("izmjena je uspješna"); ClearInputs();
    document.getElementById("ArticleEditRemove").innerHTML = "";
    UpdateArticleList(); document.forms[0].btnSave.disabled = ""; //updatean    
    }
    else if(rez.value == "false")
    { alert("došlo je do neočekivane greške, pozovite administratora") //
    }
    else 
    {document.getElementById("ArticleEditRemove").innerHTML = rez.value + document.getElementById("ArticleEditRemove").innerHTML; 
    ClearInputs();document.forms[0].btnSave.disabled = ""; alert("Članak je objavljen!");}
}

function ClearInputs()
{
    document.getElementById("ArticleId").innerHTML = "";
    document.forms[0].Title.value = "";
    tinyMCE.getInstanceById('Short').setHTML("");
    tinyMCE.getInstanceById('Full').setHTML("");
    document.forms[0].Tags.value = "";
    document.forms[0].IsEnabled.checked = "checked";
    document.forms[0].EnableComments.checked = "checked"; 
}


//kontrola ArticleEditRemoveList

function UpdateArticleList()
{
    AjaxMethods.modules_articles_admin_AjaxMethods.UpdateArticleList("0",UpdateArticleList_CallBack)
}

function UpdateArticleList_CallBack(rez)
{
    document.getElementById("ArticleEditRemove").innerHTML = rez.value + document.getElementById("ArticleEditRemove").innerHTML;
}

//*******************uklanjanje članaka
function RemoveArticle(ArticleId)
{
    if(confirm("Želite li izbrisati ovaj članak?")){
    AjaxMethods.modules_articles_admin_AjaxMethods.IzbrisiClanak(ArticleId,RemoveArticle_CallBack);
    }
}

function RemoveArticle_CallBack(rez)
{if(rez.value==true){
document.getElementById("ArticleEditRemove").innerHTML = "";
UpdateArticleList(); alert("Članak je uspješno uklonjen!");ClearInputs();}else{alert("Neocekivana greska!");}
}

//*******************editiranje članaka
function getEditData(ArticleId)
{
AjaxMethods.modules_articles_admin_AjaxMethods.EditArticleData(ArticleId,getEditData_CallBack);
}


function getEditData_CallBack(rez)
{
    if(rez!=null)
    {
    document.getElementById("ArticleId").innerHTML = rez.value[0];
    document.forms[0].drpArticleCategory.value = rez.value[1];
    document.forms[0].Title.value = rez.value[2];
    tinyMCE.getInstanceById('Short').setHTML(rez.value[3]);
    if(rez.value[4]!=null)
    tinyMCE.getInstanceById('Full').setHTML(rez.value[4]);
    if(rez.value[5]!=null)
    document.forms[0].Tags.value = rez.value[5];
    if(rez.value[6]==true){
        document.forms[0].IsEnabled.checked = "checked";}
    else
        document.forms[0].IsEnabled.checked = "";
    if(rez.value[7]==true)
        document.forms[0].EnableComments.checked = "checked";
    else
        document.forms[0].EnableComments.checked="";
    }
}

function validateInputs()
{
    if(document.forms[0].Title.value==""){document.forms[0].Title.focus(); alert("Unesite naslov!"); return false;}
    if(tinyMCE.getInstanceById('Short').getHTML()==""){alert("Kratki tekst članka je obavezan!"); return false;}
    else{ return true;}
}

//**********************************AddEditRemove.aspx gzip kompresirani stream

/* bug u firefoxu mi ne dozvoljava da koristim gzip
tinyMCE_GZ.init({
	mode : "textareas",
		theme : "advanced",
		save_callback : "customSave",
		plugins : "table,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,zoom,media,searchreplace,print,contextmenu,paste,directionality,fullscreen",
		theme_advanced_buttons1_add_before : "save,newdocument,separator",
		theme_advanced_buttons1_add : "fontsizeselect",
		theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,zoom,separator,forecolor,backcolor",
		theme_advanced_buttons2_add_before: "cut,copy,paste,pastetext,pasteword,separator,search,replace,separator",
		theme_advanced_buttons3_add_before : "tablecontrols,separator",
		theme_advanced_buttons3_add : "emotions,advhr,separator,print,separator,ltr,rtl,separator,fullscreen",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		content_css : "example_word.css",
	    plugi2n_insertdate_dateFormat : "%Y-%m-%d",
	    plugi2n_insertdate_timeFormat : "%H:%M:%S",
		external_link_list_url : "example_link_list.js",
		external_image_list_url : "example_image_list.js",
		media_external_list_url : "example_media_list.js",
		file_browser_callback : "fileBrowserCallBack",
		paste_use_dialog : false,
		theme_advanced_resizing : true,
		theme_advanced_resize_horizontal : false,
		theme_advanced_link_targets : "_something=My somthing;_something2=My somthing2;_something3=My somthing3;",
		paste_auto_cleanup_on_paste : true,
		paste_convert_headers_to_strong : false,
		paste_strip_class_attributes : "all",
		paste_remove_spans : false,
		paste_remove_styles : false		
});
*/

	 tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
	//	save_callback : "customSave",		
		plugins : "table,advhr,advimage,advlink,emotions,insertdatetime,preview,zoom,media,searchreplace,print,contextmenu,paste,directionality,fullscreen",
		theme_advanced_buttons1_add_before : "save,newdocument,cut,copy,paste,pastetext,pasteword,separator",
		theme_advanced_buttons1_add : "fontsizeselect",
		theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,zoom,separator,forecolor,backcolor",
		theme_advanced_buttons2_add_before: "search,replace,separator",
		theme_advanced_buttons3_add_before : "tablecontrols,separator",
		theme_advanced_buttons3_add : "emotions,advhr,separator,print,separator,ltr,rtl,separator,fullscreen",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		content_css : "example_word.css",
	    plugi2n_insertdate_dateFormat : "%Y-%m-%d",
	    plugi2n_insertdate_timeFormat : "%H:%M:%S",
		external_link_list_url : "example_link_list.js",
		external_image_list_url : "example_image_list.js",
		media_external_list_url : "example_media_list.js",
		file_browser_callback : "fileBrowserCallBack",
		paste_use_dialog : false,
		theme_advanced_resizing : true,
		theme_advanced_resize_horizontal : false,
		theme_advanced_link_targets : "_something=My somthing;_something2=My somthing2;_something3=My somthing3;",
		paste_auto_cleanup_on_paste : true,
		paste_convert_headers_to_strong : false,
		paste_strip_class_attributes : "all",
		paste_remove_spans : false,
		paste_remove_styles : false,
		urlconvertor_callback: "MyUrlConverter"
		
	});
 function MyUrlConverter(url, node, on_save) {return url;}

//**********************selectImage.ascx

function drawIframeImageSelect()
{
    if(document.getElementById("selectImage").innerHTML=="")
    {
        var rez = "<div style='background-color:White;position:absolute; width:"+window.screen.width+"px; height:"+window.screen.height+"px; left:0%; top:0%;'>";
        rez = rez + "<div onmousedown='HideSelectImageWindow();'><a href='#'>Zatvori prikaz slika!</a></div>";
        rez = rez + "<iframe name='odaberiSlikuIframe' width='100%' height='100%' src='../../MediaGallery/getImageLink_Iframe.aspx'></iframe>"
        rez = rez + "</div>";
        document.getElementById("selectImage").innerHTML =  rez;
        document.frames['odaberiSlikuIframe'].focus();
    }
    else
    {document.getElementById('selectImage').style.visibility = "visible";}
}

function HideSelectImageWindow()
{document.getElementById('selectImage').style.visibility = "hidden"; 
document.getElementById("selectImage").style.zIndex = 10;//ovo daje neki mini bug u IE
//document.getElementById('selectImage').innerHTML = "";
}


//image upload
function drawIframeImageUpload()
{
    if(document.getElementById("uploadImage").innerHTML=="")
    {
        var rez = "<div style='background-color:White;position:absolute; width:"+window.screen.width+"px; height:"+window.screen.height+"px; left:0%; top:0%;'>";
        rez = rez + "<div onmousedown='HideSelectUploadImageWindow();'><a href='#'>Zatvori upload slika!</a></div>";
        rez = rez + "<iframe name='UploadajSlikuIframe' width='100%' height='100%' src='../../MediaGallery/uploadPicture_Iframe.aspx'></iframe>"
        rez = rez + "</div>";
        document.getElementById("uploadImage").innerHTML =  rez;       
    }
    else
    {document.getElementById('uploadImage').style.visibility = "visible";}
}

function HideSelectUploadImageWindow()
{document.getElementById("uploadImage").innerHTML = "";}