﻿var ErrorMessage = "";
var Error_ConfirmDelete = 'Are you sure , you want to delete this entry?';

function WS_Blog(params)
{
	glbXmlRequest = new AkimanXmlHTTP(getID(strLoadingDiv),getID(strDebugDiv));
	var soapData = SoapDataBuilder("BlogService",params);	
	AjaxRequest("/Mod/Blog/WS_Blog.asmx",soapData,"",strLoadingDiv);	
}

function ApproveBlog(lngBlogID)
{
    var	params = CustomParamBuilder("strOperation", "ApproveBlog");	
    params += CustomParamBuilder("lngBlogID", lngBlogID);
    WS_Blog(params); 
}

function ViewBlog(lngBlogID)
{
    location.href="/mod/blog/blogitem.aspx?lngBlogID="+lngBlogID;
}

function ViewUserBlog(lngUserID)
{
    location.href="/mod/blog/bloglist.aspx?lngObjectID="+lngUserID;
}

function EditBlog(lngBlogID)
{
    if(lngBlogID > 0)
    {
        location.href="/mod/blog/blogitemedit.aspx?lngblogid="+lngBlogID;
    }else
    {
        location.href="/mod/blog/blogitemedit.aspx";
    }
}

function DeleteBlog(lngBlogID)
{
    if (confirm(Error_ConfirmDelete))
    {
	    var	params = CustomParamBuilder("strOperation", "DeleteBlog");	
	    params += CustomParamBuilder("lngBlogID", lngBlogID);
	    WS_Blog(params);
    }
}

function SaveBlog(lngBlogID)
{
    SetAspFormField("lngBlogID", lngBlogID);
    if(lngBlogID > 0)
    {
        var	params = CustomParamBuilder("strOperation", "UpdateBlog");
    }else
    {
        var	params = CustomParamBuilder("strOperation", "SaveBlog");
    }
    params += parseAspForm();
    WS_Blog(params);
}

function CancelBlog(lngBlogID)
{
    var	params = CustomParamBuilder("strOperation", "CancelBlog");	
    params += CustomParamBuilder("lngBlogID", lngBlogID);
    WS_Blog(params);
}

function PreviewBlogItemRow(lngBlogID)
{
    Hide('BlogItemRowBody_'+lngBlogID);
}

function GoLiveBlog(lngBlogID)
{
    var	params = CustomParamBuilder("strOperation", "GoLiveBlog");	
    params += CustomParamBuilder("lngBlogID", lngBlogID);
    WS_Blog(params); 
}

function GoLiveAllBlogs()
{
    var	params = CustomParamBuilder("strOperation", "GoLiveAllBlogs");	
    WS_Blog(params); 
}

/*Blog Media Operation - TODO: needs to be updated in modular style*/
function EditAudio(lngAudioID)
{
	location.href="/editaudio.aspx?intMainContentType=40&lngAudioID=" + lngAudioID + "&strReturnTo="+getID('lngBlogID').value;
}

function DeleteAudio(lngAudioID)
{
	if (confirm(Error_ConfirmDelete))
	{
		BlogOperation("DeleteAudio",lngAudioID,"");
	}
}

function AddAudio()
{
	location.href="/editaudio.aspx?intMainContentType=40&strReturnTo="+getID('lngBlogID').value;
}

function EditVideo(lngVideoID)
{
	location.href="/editvideo.aspx?intMainContentType=40&lngVideoID=" + lngVideoID + "&strReturnTo="+getID('lngBlogID').value;
}

function DeleteVideo(lngVideoID)
{
	if (confirm(Error_ConfirmDelete))
	{
		BlogOperation("DeleteVideo",lngVideoID,"");
	}
}

function AddVideo()
{
	location.href="/editvideo.aspx?intMainContentType=40&strReturnTo="+getID('lngBlogID').value;
}

function EditImage(lngImageID)
{
	location.href="/editimage.aspx?intMainContentType=40&lngImageID=" + lngImageID + "&sngPositionOrder=1&strReturnTo=" + getID('lngBlogID').value;
}

function DeleteImage(lngImageID)
{
	if (confirm(Error_ConfirmDelete))
	{
		BlogOperation("DeleteImage",lngImageID,"");
	}
}

function AddImage()
{
	location.href="/editimage.aspx?intMainContentType=40&sngPositionOrder=1&strReturnTo="+getID('lngBlogID').value;
}

function EditDocument(lngDocumentID)
{
	location.href="/editdocument.aspx?intMainContentType=40&lngDocumentID=" + lngDocumentID + "&sngPositionOrder=1&strReturnTo=" + getID('lngBlogID').value;
}

function DeleteDocument(lngDocumentID)
{
	if (confirm(Error_ConfirmDelete))
	{
		BlogOperation("DeleteDocument",lngDocumentID,"");
	}
}

function AddDocument()
{
	location.href="/editdocument.aspx?intMainContentType=40&sngPositionOrder=1&strReturnTo="+getID('lngBlogID').value;
}

function BlogOperation(strOperation,strCriteria,strTargetDiv)
{
	glbXmlRequest = new AkimanXmlHTTP(document.getElementById("loading"),document.getElementById("debug"));
	
	var	params = CustomParamBuilder("strOperation", strOperation);
	params += CustomParamBuilder("strCriteria", strCriteria);
	params += CustomParamBuilder("lngStoryID", getID('lngBlogID').value);
	params += parseForm("aspnetForm");
	var soapData = SoapDataBuilder("BlogOperation",params);
	AjaxRequest("/mod/blog/ws_blogoperation.asmx",soapData,strTargetDiv,"loading");	
}
/*Blog Media Operation*/
