﻿// ---------------------------------------------------------------
//
// Title:       eWidgets Utility Library
//
// Copyright:   eVolve Relationship Management 2009
//
// Author:      Matt Stannard
//
// Requires:    prototype.js
// ---------------------------------------------------------------

var ROOT_PATH;

ROOT_PATH = "/";

function doPromoteItem(TopicID,Ranking)
{
    var strURL;
    
    strURL = ROOT_PATH + "forums/ajax/RateTopic.aspx?TopicID=" + TopicID + "&Ranking=" + Ranking;

    new Ajax.Request(strURL,{method:'get',onSuccess:doPromoteItem_cb});
}

function doPromoteItem_cb(t)
{
    alert(t.responseText);
}

function doGetForumSurvey(WidgetID,CommunityID,AreaID)
{
    var eForumLayer;
    var strLayerName;
    var strURL;
    
    strLayerName = "Forum" + WidgetID;
    strURL = ROOT_PATH + "forums/ajax/Forum.aspx?CommunityID=" + CommunityID + "&AreaID=" + AreaID;
    
    if ($(strLayerName))
    {
        $(strLayerName).innerHTML = "<div style=\"text-align:center\"><img src=\"" + ROOT_PATH + "images/loading-survey.gif\" alt=\"Loading Forum\" /></div>";
        
        new Ajax.Request(strURL,{method:'get', onSuccess:function(transport){doLoadForum(WidgetID,transport.responseText);}});           
    
    }
}

function doLoadForum(WidgetID,ForumText)
{
    var strLayerName;
   
    strLayerName = "Forum" + WidgetID;
    
    if ($(strLayerName))
    {
        $(strLayerName).innerHTML = ForumText;
    }
}

function doGetVisionSurvey(WidgetID, VisionUserID, VisionSurveyID)
{
    var eSurveyLayer;
    var strLayerName;
    var strURL;
    
    
    strLayerName = "EmbeddedSurvey" + WidgetID;
    strURL = ROOT_PATH + "widgetajax/GetSurvey.aspx?GetURL=http://vision.e-rm.org/surveyajax/" + VisionUserID + "/" + VisionSurveyID;
    
    // Check the layer exists
    if ($(strLayerName))
    {
        $(strLayerName).innerHTML = "<div style=\"text-align:center\"><img src=\"" + ROOT_PATH + "images/loading-survey.gif\" alt=\"Loading Survey\" /></div>";
        
        new Ajax.Request(strURL,{method:'get', onSuccess:function(transport){doLoadSurvey(WidgetID,transport.responseText);}});           
    }
}

function doLoadSurvey(WidgetID,SurveyText)
{
    strLayerName = "EmbeddedSurvey" + WidgetID;
    
    if ($(strLayerName))
    {
        $(strLayerName).innerHTML = SurveyText;
    }
    
}