    function AddPartnerLink()
    {
        var pName = document.getElementById('PartnerName').value;
        var pLink = document.getElementById('PartnerLink').value;
        var nPos = document.getElementById('newLinkPos').value;
        if (( trim(pName) != "") && (trim(pLink) != ""))
        {
            var xmlHttp = getNewHttp();

            xmlHttp.onreadystatechange=function()
            {
              if(xmlHttp.readyState==4)
              {
                window.location.reload();
              }
            }

            var d = new Date();
            var tm = d.getTime();
            var url = "tpl/ajax_partners.php?t="+tm+"&pName="+pName+"&pLink="+pLink+"&pos="+nPos;

            xmlHttp.open("GET",url,true);
            xmlHttp.send(null);
        }
        else
        {
            alert('Partner name and link url are required');
        }
    }
    function trim(s)
    {
        s = s.replace(/^\s+|\s+$/g, '') ;
        return s;
    }

    function SaveNewOrder()
    {
        var tbl = document.getElementById('partners_table');
        var rows = tbl.tBodies[0].rows;
        var newOrder = "";
        for (i=0; i<rows.length; i++)
        {
            if (rows[i].id != "")
            {
                newOrder = newOrder + "," + rows[i].id;
            }
        }
        var xmlHttp = getNewHttp();

        xmlHttp.onreadystatechange=function()
        {
          if(xmlHttp.readyState==4)
          {
            window.location.reload();
          }
        }

        var d = new Date();
        var tm = d.getTime();
        var url = "tpl/ajax_partners.php?t="+tm+"&do=reorder&new_order="+newOrder;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
    }

    function RemoveLink(linkName)
    {
        var xmlHttp = getNewHttp();

        xmlHttp.onreadystatechange=function()
        {
          if(xmlHttp.readyState==4)
          {
            // need to refresh page after ajax is done so that we get the updated data
            window.location.reload();
          }
        }

        var d = new Date();
        var tm = d.getTime();
        var url = "tpl/ajax_partners.php?t="+tm+"&do=removelink&pName="+linkName;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
    }

    // function to give us a new xmlHttp object
    function getNewHttp()
    {
      var xmlHttp;
      try
      {  // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
      }
      catch (e)
      {  // Internet Explorer
        try
        {
          xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
          try
          {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
          catch (e)
          {
            alert("Your browser does not support AJAX!");
            return false;
          }
        }
      }
      return xmlHttp;
    }

    // make the link edit form visible
    function EditLink(editBoxId)
    {
      editBox = document.getElementById(editBoxId);
      editBox.style.display = "block";
    }

    // hide edit box
    function HideLinkEditBox(editBoxId)
    {
      editBox = document.getElementById(editBoxId);
      editBox.style.display = "none";
    }

    // Update a partner link with a new data for name or url
    function UpdatePartnerLink(pName, pLink, pPos)
    {
      pNameVal = document.getElementById(pName).value;
      pLinkVal = document.getElementById(pLink).value;
      pPosVal  = document.getElementById(pPos).value;

      if ((trim(pNameVal) != "") && (trim(pLinkVal) != ""))
      {
        var xmlHttp = getNewHttp();

        xmlHttp.onreadystatechange=function()
        {
          if(xmlHttp.readyState==4)
          {
            // need to refresh page after ajax is done so that we get the updated data
            window.location.reload();
          }
        }

        var d = new Date();
        var tm = d.getTime();
        var url = "tpl/ajax_partners.php?t="+tm+"&do=editlink&pName="+pNameVal+"&pLink="+pLinkVal+"&pos="+pPosVal;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
      }
      else
      {
          alert('Partner name and link url are required');
      }
    }