var Follow =
 {
  options: null,
 
  setup: function(options)
   {
    Follow.options = options;
   },
 
  follow: function()
   {
    if (Follow.options["PID"] == 1)
     {
      $("followform").submit();
     }
     
    else
     {      
      if (Follow.options["FOLLOW_TYPE"] == "teacher" || Follow.options["FOLLOW_TYPE"] == "school")
       {
        actionURL = "/followcontroller.php?type=" + Follow.options["FOLLOW_TYPE"] + " &action=follow&id=";
        
        if (Follow.options["FOLLOW_TYPE"] == "teacher")
         {
          actionURL += Follow.options["TID"];
         }
         
        else if (Follow.options["FOLLOW_TYPE"] == "school")
         {
          actionURL += Follow.options["SID"];
         } 
        
        request = new Request({url: actionURL,
                               method: "get",
                               onSuccess: function(responseText, responseXML)
                                           {
                                            if (Follow.options["FOLLOW_TYPE"] == "teacher")
                                             {
                                              Follow.completeFollowTeacher();
                                             }
                                             
                                            else if (Follow.options["FOLLOW_TYPE"] == "school")
                                             {
                                              Follow.completeFollowSchool();
                                             } 
                                           }});

        request.send();
       }
     }
   },
   
  unfollow: function()
   {
      if (Follow.options["FOLLOW_TYPE"] == "teacher" || Follow.options["FOLLOW_TYPE"] == "school")
       {
        actionURL = "/followcontroller.php?type=" + Follow.options["FOLLOW_TYPE"] + " &action=unfollow&id=";
        
        if (Follow.options["FOLLOW_TYPE"] == "teacher")
         {
          actionURL += Follow.options["TID"];
         }
         
        else if (Follow.options["FOLLOW_TYPE"] == "school")
         {
          actionURL += Follow.options["SID"];
         } 
        
        request = new Request({url: actionURL,
                               method: "get",
                               onSuccess: function(responseText, responseXML)
                                           {
                                            if (Follow.options["FOLLOW_TYPE"] == "teacher")
                                             {
                                              Follow.completeUnfollowTeacher();
                                             }
                                             
                                            else if (Follow.options["FOLLOW_TYPE"] == "school")
                                             {
                                              Follow.completeUnfollowSchool();
                                             } 
                                           }});

        request.send();
       }
   }, 
   
  completeFollowTeacher: function(responseText)
   {
    $("headertext").innerHTML = "You are following " + Follow.options["NAME"] + ".";
    $("subheadertext").innerHTML = "You will recieve email updates every time " + Follow.options["NAME"] + " is rated or commented on.";
   
    $("follow_inputcontainer").setStyle("display", "none");
   },
   
  completeUnfollowTeacher: function(responseText)
   {
    $("headertext").innerHTML = "You are not following " + Follow.options["NAME"] + ".";
    $("subheadertext").innerHTML = "You will no longer recieve email updates about " + Follow.options["NAME"] + ".";

    $("follow_stopfollowing").setStyle("display", "none");
   },
   
  completeFollowSchool: function(responseText)
   {
    $("headertext").innerHTML = "You are following " + Follow.options["NAME"] + ".";
    $("subheadertext").innerHTML = "You will recieve email updates every time a teacher from " + Follow.options["NAME"] + " is rated or commented on.";
   
    $("follow_inputcontainer").setStyle("display", "none");
   },
   
  completeUnfollowSchool: function(responseText)
   {
    $("headertext").innerHTML = "You are not following " + Follow.options["NAME"] + ".";
    $("subheadertext").innerHTML = "You will no longer recieve email updates about " + Follow.options["NAME"] + ".";

    $("follow_stopfollowing").setStyle("display", "none");

   }, 
   
  focusInputText: function(element, text)
   {
    if (element.value == text)
     {
      element.value = "";
     }
   },
   
  blurInputText: function(element, text)
   {
    if (element.value == "")
     {
      element.value = text;
     }
   }  
 };