AjaxLoaderImage = new Image();
AjaxLoaderImage.src = "public/images/ajax.gif";

function ajaxProgressBar(IDToApply, ImageToProgress) {
    var div = $(IDToApply);
    
    div.style.minHeight = "100px";
    div.innerHTML = '<div style="position: absolute; margin: 18px 0px 0px 230px; background: url(\'public/images/ajax.gif\') transparent; width: 70px; height: 64px;"></div>';
}

/* START GLOBAL FUNCTIONS */
function submitForm(FormID, FormName, ActionURL) {
    var tempForm = $(FormID);
    tempForm.action = ActionURL;
    document.forms[FormName].submit();
}

function goToLink(Link) {
    document.location = Link;
}
/* END GLOBAL FUNCTIONS */

/* START POPUP FUNCTIONS */
function createButton(OnClickFunction, ButtonName, ButtonValue) {
    return '<input class="formbutton" onclick="' + OnClickFunction + '" type="button" name="' + ButtonName + '" value="' + ButtonValue + '" />';
}

function showConfirmationBox(Headline, Message, Buttons) {
    var tempBlackOut = $("siteblackout");
    if(tempBlackOut == null)
    {
        document.body.innerHTML = '<div id="siteblackout" onclick="javascript:hideConfirmationBox();"></div>' + document.body.innerHTML;
        var tempSite = $("site");
        tempSite.innerHTML = '<div id="confirmationbox"><p class="headline">' + Headline + '</p><hr /><div class="container"><p>' + Message + '</p></div><div class="formbuttonsbackground">' + Buttons + '</div></div>' + tempSite.innerHTML;
    }
}

function hideConfirmationBox() {
    var tempBlackOut = $("siteblackout");
    if(tempBlackOut != null)
    {
        document.body.removeChild(tempBlackOut);
        var tempPopUp = $("confirmationbox");
        var tempSite = $("site");
        tempSite.removeChild(tempPopUp);
    }
}
/* END POPUP FUNCTIONS */

/* START CONFIRMATION FUNCTIONS */
function confirmMessageDelete(DeletionLink) {
    var tempButtons = createButton("javascript:delMessage('" + DeletionLink + "');", "yes", "Yes") + createButton("javascript:hideConfirmationBox();", "no", "No");
    showConfirmationBox("Please confirm...", "Do you really want to delete this message? If you're sure please press Yes.", tempButtons);
}

function confirmUserDelete(DeletionLink) {
    var tempButtons = createButton("javascript:goToLink('" + DeletionLink + "');", "yes", "Yes") + createButton("javascript:hideConfirmationBox();", "no", "No");
    showConfirmationBox("Please confirm...", "Do you really want to delete this user?<br />If you're sure please press Yes.", tempButtons);
}

function confirmPictureDelete(DeletionLink) {
    var tempButtons = createButton("javascript:goToLink('" + DeletionLink + "');", "yes", "Yes") + createButton("javascript:hideConfirmationBox();", "no", "No");
    showConfirmationBox("Please confirm...", "Are you sure you want to delete this picture?<br />If you want to continue and delete this picture please press Yes.", tempButtons);
}

function confirmDownloadDelete(DeletionLink) {
    var tempButtons = createButton("javascript:goToLink('" + DeletionLink + "');", "yes", "Yes") + createButton("javascript:hideConfirmationBox();", "no", "No");
    showConfirmationBox("Please confirm...", "Do you really want to delete this download?<br />If you're sure please press Yes.", tempButtons);
}

function confirmDownloadDeleteCompletly(DeletionLink) {
    var tempButtons = createButton("javascript:goToLink('" + DeletionLink + "');", "yes", "Yes") + createButton("javascript:hideConfirmationBox();", "no", "No");
    showConfirmationBox("Please confirm...", "Do you really want to delete this download COMPLETLY?<br />If you're sure please press Yes.", tempButtons);
}

function confirmDeleteSnippet(DeletionID) {
    var tempButtons = createButton("javascript:delSnippetByID(" + DeletionID + ");", "yes", "Yes") + createButton("javascript:hideConfirmationBox();", "no", "No");
    showConfirmationBox("Please confirm...", "Are you sure you want to delete this snippet?<br />If you want to continue and delete this snippet please press Yes.", tempButtons);
}

function confirmNewsDelete(DeletionLink) {
    var tempButtons = createButton("javascript:goToLink('" + DeletionLink + "');", "yes", "Yes") + createButton("javascript:hideConfirmationBox();", "no", "No");
    showConfirmationBox("Please confirm...", "Are you sure you want to delete this news?<br />If you want to continue and delete this news please press Yes.", tempButtons);
}

function confirmBackupDelete(DeletionLink) {
    var tempButtons = createButton("javascript:goToLink('" + DeletionLink + "');", "yes", "Yes") + createButton("javascript:hideConfirmationBox();", "no", "No");
    showConfirmationBox("Please confirm...", "Are you sure you want to delete this backup?<br />If you want to continue and delete this backup please press Yes.", tempButtons);
}
/* END CONFIRMATION FUNCTIONS */

/* START COMMENTING/GUESTBOOK FUNCTIONS */
function getComments(Category, ParentID, LimitStart, LimitEnd) {
    ajaxProgressBar('commentsarea', AjaxLoaderImage);
	var update = new Ajax.Updater('commentsarea', '?spcl=getcomments&cat=' + Category + '&pid=' + ParentID + '&scn=' + LimitStart + '&ecn=' + LimitEnd,
	{
		method: 'get'
	});
}

function sendComment(CommittingLink, IDToUpdate) {
    
    var formData = $('commentsubmition').serialize(true);
    
    ajaxProgressBar(IDToUpdate, AjaxLoaderImage);
	var update = new Ajax.Updater(IDToUpdate, CommittingLink,
	{
		method: 'post',
		parameters: formData
	});
}

function deleteComment(CommittingLink, CommentID, IDToUpdate) {
    ajaxProgressBar(IDToUpdate, AjaxLoaderImage);
    var update = new Ajax.Updater(IDToUpdate, CommittingLink + '&delcomment=' + CommentID,
    {
        method: 'get'
    });
}
/* END COMMENTING/GUESTBOOK FUNCTIONS*/

/* START MESSAGING FUNCTIONS */
function getInboxMessages() {
    ajaxProgressBar('messages', AjaxLoaderImage);
    var linktoget = '?spcl=usermessaging&loc=inbox';
	var update = new Ajax.Updater('messages', linktoget,
	{
		method: 'get'
	});
}

function getOutboxMessages() {
    ajaxProgressBar('messages', AjaxLoaderImage);
    var linktoget = '?spcl=usermessaging&loc=outbox';
	var update = new Ajax.Updater('messages', linktoget,
	{
		method: 'get'
	});
}

function delMessage(LocationAndID) {
    hideConfirmationBox();
    ajaxProgressBar('messages', AjaxLoaderImage);
    var linktoget = '?spcl=usermessaging&' + LocationAndID;
	var update = new Ajax.Updater('messages', linktoget,
	{
		method: 'get',
	});
}

function readMessage(LocationAndID, ReplyUserID) {
    ajaxProgressBar('themessage', AjaxLoaderImage);
    var linktoget = '?spcl=usermessaging&' + LocationAndID;
	var update = new Ajax.Updater('themessage', linktoget,
	{
		method: 'get'
	});
}

function sendMessage(CommittingLink, IDToUpdate) {
    
    var formData = $('usermessagesubmition').serialize(true);
    
    ajaxProgressBar(IDToUpdate, AjaxLoaderImage);
	var update = new Ajax.Updater(IDToUpdate, CommittingLink,
	{
		method: 'post',
		parameters: formData
	});
}
/* END MESSAGING FUNCTIONS */

/* START USERPROFILE FUNCTIONS */
function getUserprofileDescription(UserID) {

    ajaxProgressBar('usercontent', AjaxLoaderImage);
    
	var update = new Ajax.Updater('usercontent', '?spcl=userdescription&uid=' + UserID,
	{
		method: 'get'
	});
}

function getUserprofileGuestbook(UserID, LimitStart, LimitEnd) {

    ajaxProgressBar('usercontent', AjaxLoaderImage);
    
	var update = new Ajax.Updater('usercontent', '?spcl=userguestbook&uid=' + UserID + '&scn=' + LimitStart + '&ecn=' + LimitEnd,
	{
		method: 'get'
	});
}

function getUserprofileGallery(UserID){

    ajaxProgressBar('usercontent', AjaxLoaderImage);
    
	var update = new Ajax.Updater('usercontent', '?spcl=usergallery&uid=' + UserID,
	{
		method: 'get'
	});
}

function getUserprofileSendMsg(UserID, Topic) {

    ajaxProgressBar('usercontent', AjaxLoaderImage);
    
	var update = new Ajax.Updater('usercontent', '?spcl=usersendmsg&uid=' + UserID + "&topic=" + Topic,
	{
		method: 'get'
	});
}
/* END USERPROFILE FUNCTIONS*/

/* START DOWNLOADS FUNCTIONS */
function getDownloadList(LimitStart, LimitEnd)
{
    ajaxProgressBar('thedownloadlist', AjaxLoaderImage);
    var searchlink = '?spcl=downloadlist&search=' + $('searchinput').value + '&scn=' + LimitStart + '&ecn=' + LimitEnd;
	var update = new Ajax.Updater('thedownloadlist', searchlink,
	{
		method: 'get'
	});
}
/* END DOWNLOADS FUNCTIONS */

/* START SNIPPETS FUNCTIONS */
function getSnippetList(LimitStart, LimitEnd)
{
    ajaxProgressBar('snippetlist', AjaxLoaderImage);
    var searchlink = '?spcl=snippetlist&search=' + $('searchinput').value + '&langid=' + $('langinput').value + '&scn=' + LimitStart + '&ecn=' + LimitEnd;
	var update = new Ajax.Updater('snippetlist', searchlink,
	{
		method: 'get'
	});
}

function delSnippetByID(SnippetID) {
    hideConfirmationBox();
    ajaxProgressBar('snippetlist', AjaxLoaderImage);
    var update = new Ajax.Updater("snippetlist", "?spcl=snippetlist&langid=" + $('langinput').value + "&search=" + $('searchinput').value + "&delid=" + SnippetID,
    {
      method: 'get'
    });
}
/* END SNIPPETS FUNCTIONS */


