/*
 * 360Hubs.js
 *
 * Javascript files to help with AJAX and other site-wide needs
 */


function $EL(v){ return document.getElementById(v);}
function $P(){ return window.parent.document;}
function $ST(v){ return $EL(v).style}

var genericWaitingString = '<img src="/images/waiting.gif" alt="Please Wait"/> Processing, please wait...';

function getFormPOSTString(formID){
  var inForm = document.getElementById(formID);
  var poststr = '';

  for (var i=0; i < inForm.elements.length; i++){

    if (inForm.elements[i].tagName == "INPUT") {
      if (inForm.elements[i].type == "text") {
         poststr += inForm.elements[i].name + "=" + encodeURIComponent(inForm.elements[i].value) + "&";
      }
      if (inForm.elements[i].type == "hidden") {
         poststr += inForm.elements[i].name + "=" + encodeURIComponent($EL(inForm.elements[i].id).value) + "&";
      }
      if (inForm.elements[i].type == "submit") {
         poststr += inForm.elements[i].name + "=" + encodeURIComponent(inForm.elements[i].value) + "&";
      }
      if (inForm.elements[i].type == "password") {
         poststr += inForm.elements[i].name + "=" + encodeURIComponent(inForm.elements[i].value) + "&";
      }
      if (inForm.elements[i].type == "checkbox") {
        if (inForm.elements[i].checked) {
          poststr += inForm.elements[i].name + "="+inForm.elements[i].value+"&";
        }
      }
      if (inForm.elements[i].type == "radio") {
        if (inForm.elements[i].checked) {
          poststr += inForm.elements[i].name + "=" + encodeURIComponent(inForm.elements[i].value) + "&";
        }
      }
    }
    if (inForm.elements[i].tagName == "SELECT") {
      var sel = inForm.elements[i];
      if(sel.selectedIndex != -1){
        poststr += sel.name + "=" + encodeURIComponent(sel.options[sel.selectedIndex].value) + "&";
      }
    }

    if (inForm.elements[i].tagName == "TEXTAREA") {
      poststr += inForm.elements[i].name + "=" + encodeURIComponent(inForm.elements[i].value) + "&";
    }
  }

  return poststr;
}

/*
 * A function that receives a response from the server, hides the busy element
 * if it exists, and refreshes one element on the page.
 */

function AJAXReceiveAndRefresh(req){

  if(req.userData.noticeID != null){
    document.getElementById(req.userData.noticeID).innerHTML=req.xhRequest.responseText;
  }

  if(undefined != req.userData && undefined != req.userData.refreshID && undefined != req.userData.refreshID){
    var myObj = new Object;
    myObj.noticeID = req.userData.refreshID;
    Spry.Utils.loadURL('GET', req.userData.refreshURL, true, AJAXNoticeReceive, { userData: myObj});
  }

}





/*
 * A function that makes a POST to the server, and
 * updates a noticeID element with the server's response,
 * and will refresh an element on the page with the inputted
 * refreshID and refreshURL
 */
function AJAXAndRefresh(inURL, noticeID, formID, refreshID, refreshURL) {
  var myObj = new Object;
  myObj.refreshID = refreshID;
  myObj.refreshURL = refreshURL;
  myObj.noticeID = noticeID;

  if(noticeID != null){
    $EL(noticeID).innerHTML = genericWaitingString;
  }

  poststr = 'Ajax=true&'+getFormPOSTString(formID);
  Spry.Utils.loadURL('POST', inURL, true, AJAXReceiveAndRefresh, {postData: poststr, headers: {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}, userData: myObj});
}





/*
 * AJAX DOM Refreshing Functions
 * Functions to make AJAX requests and refresh areas of the page
 * These functions will run the javascript embedded in the response text
 */


/*
 * Same as the standard AJAXNoRefresh but will run the javascript.
 */
function AJAXNoRefreshDOM(inURL, noticeID, formID)
{
  AJAXAndRefreshSetDOM(inURL, noticeID, formID);
}

/*
 * Same as the standard AJAXAndRefresh but will run the javascript.
 */
function AJAXAndRefreshDOM(inURL, noticeID, formID, refreshID, refreshURL)
{
  var refSet = Array();
  refSet[refreshURL] = refreshID;

  AJAXAndRefreshSetDOM(inURL, noticeID, formID, refSet);
}

/*
 * Same as the standard AJAXAndRefreshTwo but will run the javascript.
 */
function AJAXAndRefreshTwoDOM(inURL, noticeID, formID, refreshID1, refreshURL1, refreshID2, refreshURL2)
{
  var refSet = Array();
  refSet[refreshURL1] = refreshID1;
  refSet[refreshURL2] = refreshID2;

  AJAXAndRefreshSetDOM(inURL, noticeID, formID, refSet);
}

/*
 * This function has the same basic functionality of AJAXAndRefreshDOM but can refresh an infinite amount of nodes
 * with the data returned by ajax. JSON formatting is allowed
 * When calling this function format it like : AJAXAndRefreshSetDOM('inurl.php', 'noticediv', 'formid', {'url1':'div1','url2':'div2'});
 */
function AJAXAndRefreshSetDOM(inURL, noticeID, formID, refreshSet)
{

  var noticeObj = new Object;
  noticeObj.refreshNode = noticeID;
  noticeObj.refreshSet = refreshSet;

  if(noticeID != null)
  {
    $EL(noticeID).innerHTML = genericWaitingString;
  }

  //Send out notice and update
  poststr = 'Ajax=true&'+getFormPOSTString(formID);
  Spry.Utils.loadURL('POST', inURL, true, AJAXRefreshNoticeDOM, {postData: poststr, headers: {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}, userData: noticeObj});
}



/*
 * This function has the same basic functionality of AJAXAndRefreshDOM but can refresh an infinite amount of nodes
 * with the data returned by ajax. This function allows the inclusion of an MCEditor as well.  JSON formatting is allowed
 * When calling this function format it like : AJAXAndRefreshSetDOM('inurl.php', 'noticediv', 'formid', {'url1':'div1','url2':'div2'}, 'mceid', 'mcename');
 */
function AJAXAndRefreshSetDOMWithMCE(inURL, noticeID, formID, refreshSet, mceObj, mceName) {
  var noticeObj = new Object;
  noticeObj.refreshNode = noticeID;
  noticeObj.refreshSet = refreshSet;

  if(noticeID != null)
  {
    $EL(noticeID).innerHTML = genericWaitingString;
  }

  //Send out notice and update
  poststr = 'Ajax=true&'+getFormPOSTString(formID);

  var mceinst = tinyMCE.getInstanceById('' + mceObj);

  poststr += mceName + "=" + encodeURIComponent(mceinst.getHTML()) + "&";

  Spry.Utils.loadURL('POST', inURL, true, AJAXRefreshNoticeDOM, {postData: poststr, headers: {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}, userData: noticeObj});
}




/*
 * This is the callback function for the AJAXAndRefreshXXXDOM calls. This will receive that data and then continue to make any
 * of the additional calls that need to be made.
 */
function AJAXRefreshNoticeDOM(req)
{
  AJAXRefreshDOM(req); //Update our notice panel

  var refreshSet = req.userData.refreshSet;

  AJAXRefreshSetDOM(refreshSet);
}


/*
 * This function will take in an assocative array of AJAX request URLs and DOM nodes to refresh with the content of that data
 */
function AJAXRefreshSetDOM(refreshSet)
{
  if(refreshSet)
  {
    for(var key in refreshSet)
    {
      var dataObj = new Object();
      dataObj.refreshNode = refreshSet[key];

      Spry.Utils.loadURL('GET', key, true, AJAXRefreshDOM, {postData: null, headers: {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}, userData: dataObj});
    }
  }
}

/*
 * This function will take in an assocative array of AJAX request URLs and DOM nodes to refresh in order with that content
 */

function AJAXRefreshSetInOrderDOM(urlSet, nodeSet)
{
  if(urlSet && nodeSet)
  {
    if(urlSet.length > 0)
    {
      var url = urlSet.pop();
      var node = nodeSet.pop();

      var dataObj = new Object();
      dataObj.refreshNode = node;
      dataObj.urlSet = urlSet;
      dataObj.nodeSet = nodeSet;

      Spry.Utils.loadURL('GET', url, true, AJAXRefreshInOrderDOM, {postData: null, headers: {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}, userData: dataObj});
    }
  }
}

function AJAXRefreshInOrderDOM(req)
{
  document.getElementById(req.userData.refreshNode).innerHTML = req.xhRequest.responseText;

  //Find and execute scripts
  examineNodeTree(document.getElementById(req.userData.refreshNode));

  //Run the remaining AJAX requests

  AJAXRefreshSetInOrderDOM(req.userData.urlSet, req.userData.nodeSet);
}

/*
 * Updates a certain div with the response text of the AJAX request
 */
function AJAXRefreshDOM(req)
{
  document.getElementById(req.userData.refreshNode).innerHTML = req.xhRequest.responseText;

  //Find and execute scripts
  examineNodeTree(document.getElementById(req.userData.refreshNode));
}

/*
 * A trick to get browsers to run the javascript inside innerHTML.
 * We track down the script element nodes, and remove them and replace them with a copy of themself.
 */
function examineNodeTree(pNode)
{
  var childNodes = pNode.childNodes;

  for(var i = 0; i < childNodes.length; i++)
  {
    if(childNodes[i].nodeName == "SCRIPT")
    {

      var tempNode = document.createElement("script");
      tempNode.type = childNodes[i].type;

      //if(childNodes[i].firstChild)
      //{
      //  alert("Replace child");
      //  tempNode.appendChild(childNodes[i].firstChild);
      //}
      //else
      //{
        var scriptText = childNodes[i].innerHTML

        tempNode.text = childNodes[i].text;
      //}

      pNode.replaceChild(tempNode, childNodes[i]);
    }
    else
    {
      examineNodeTree(childNodes[i]);
    }
  }
}


/*
 * A function that makes an inputted GET to the server,
 * updates a noticeID element with the server's response,
 * and will refresh an element on the page with the inputted
 * refreshID and refreshURL
 */
function AJAXAndRefreshGET(inGET, noticeID, refreshID, refreshURL) {
  var myObj = new Object;
  myObj.refreshID = refreshID;
  myObj.refreshURL = refreshURL;
  myObj.noticeID = noticeID;

  if(noticeID != null){
    $EL(noticeID).innerHTML = genericWaitingString;
  }

  Spry.Utils.loadURL('GET', inGET, true, AJAXReceiveAndRefresh, {headers: {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}, userData: myObj});
}




/*
 * A function that receives a response from the server, hides the busy element
 * if it exists, and refreshes two elements on the page.
 */


function AJAXReceiveAndRefreshTwo(req){
  if(req.userData != undefined && undefined != req.userData.busyID && null != req.userData.busyID){
    $EL(req.userData.busyID).innerHTML = '';
  }

  Spry.Utils.loadURL('GET', req.userData.refreshURL, req.userData.refreshID, true);
  Spry.Utils.loadURL('GET', req.userData.refreshURLB, req.userData.refreshIDB, true);

}

/*
 * A function that makes a POST to the server, and
 * updates a noticeID element with the server's response, with
 * no other page refreshing.
 */
function AJAXNoRefresh(inURL, noticeID, formID){
  var myObj = new Object;
  myObj.noticeID = noticeID;

  if(noticeID != null){
    $EL(noticeID).innerHTML = genericWaitingString;
  }

  poststr = 'Ajax=true&'+getFormPOSTString(formID);
  Spry.Utils.loadURL('POST', inURL, true, AJAXNoticeReceive, {postData: poststr, headers: {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}, userData: myObj});
}





function AJAXAndRefreshTwo(inURL, busyID, formID, refID, refURL, refBID, refBURL) {
  var myObj = new Object;
  myObj.refreshID = refID;
  myObj.refreshURL = refURL;
  myObj.refreshIDB = refBID;
  myObj.refreshURLB = refBURL;
  myObj.busyID = busyID;

  if(busyID != null){
    $EL(busyID).innerHTML = genericWaitingString;
    $EL(busyID).style.display='block';
  }

  poststr = getFormPOSTString(formID);
  Spry.Utils.loadURL('POST', inURL, true, AJAXReceiveAndRefreshTwo, {postData: poststr, headers: {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}, userData: myObj});
}


function AJAXRefreshSelf(inURL, busyID, formID, selfID, selfURL) {
  var myObj = new Object;
  myObj.updateID = selfID;
  myObj.updateURL = selfURL;
  $EL(busyID + '').innerHTML = genericWaitingString;

  poststr = 'Ajax=true&' + getFormPOSTString(formID);
  Spry.Utils.loadURL('POST', inURL, true, null, {postData: poststr, headers: {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}, userData: myObj});
}


function AJAXNoticeReceive(req){
  if(undefined != req.userData && undefined != req.userData.noticeID && req.userData.noticeID != null){
    document.getElementById(req.userData.noticeID).innerHTML=req.xhRequest.responseText;
  }


  if(undefined != req.userData && undefined != req.userData.reinit){

    if(req.userData.reinit){
      reInitItems();
      alert('hmm4');
    } else {
     if(undefined == $EL('paginateList-UserManagementTable') && undefined == $EL('paginateList-UserManagementTable') && undefined == $EL('paginateList-PaginateTable')){
      if(typeof(tablePaginater) != 'undefined' && typeof(fdTableSort) != 'undefined'){
        tablePaginater.init();
        fdTableSort.init();
      }
     }
     tb_init('a.thickbox, area.thickbox, input.thickbox');
    }
  } else {
    reInitItems();
  }
}

function AJAXNotice(inURL, noticeID){
  var myObj = new Object;
  myObj.noticeID = noticeID;
  Spry.Utils.loadURL('GET', inURL, true, AJAXNoticeReceive, {userData: myObj});
}

function AJAXNoticeReinit(inURL, noticeID, reinit){
  var myObj = new Object;
  myObj.noticeID = noticeID;
  myObj.reinit = reinit;

  Spry.Utils.loadURL('GET', inURL, true, AJAXNoticeReceive, {userData: myObj});
}

function checkUser(str, noticeID){
  var myRegexp = /[^0-9a-zA-Z]/;

  if(str.length == 0){
    document.getElementById(noticeID).innerHTML='Please enter a username';
     return false;
  } else if(str.length < 4){
    document.getElementById(noticeID).innerHTML='<span class="err">Your username is too short.</span>';
     return false;
  } else if(myRegexp.test(str)){
    document.getElementById(noticeID).innerHTML='<span class="err">Your User Name may only contain letters and numbers.</span>';
  } else {
    AJAXNotice('manageusers.php?Ajax=true&CheckUsername='+str, noticeID);
  }
}

function checkPass(str1, str2, noticeID){
  if(str1.length == 0 && str2.length == 0){
    document.getElementById(noticeID).innerHTML='Please enter a password';
  } else if(str1.length < 6 && str2.length < 6){
    document.getElementById(noticeID).innerHTML='<span class="err">Your password is too short</span>';
  } else if(str1 == str2){
    document.getElementById(noticeID).innerHTML='<span class="aok">Your password is ok.</span>';
  } else {
    document.getElementById(noticeID).innerHTML='<span class="err">Your passwords do not match.</span>';
  }
}


function echeck(str, noticeID) {

    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)

    if(lstr == 0){
       document.getElementById(noticeID).innerHTML='Please enter your email address.';
       return false
    }
    if (str.indexOf(at)==-1){
       document.getElementById(noticeID).innerHTML='<span class="err">Your email address is invalid</span>';
       return false
    }
    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
       document.getElementById(noticeID).innerHTML='<span class="err">Your email address is invalid</span>';
       return false
    }
    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        document.getElementById(noticeID).innerHTML='<span class="err">Your email address is invalid</span>';
        return false
    }
     if (str.indexOf(at,(lat+1))!=-1){
        document.getElementById(noticeID).innerHTML='<span class="err">Your email address is invalid</span>';
        return false
     }
     if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        document.getElementById(noticeID).innerHTML='<span class="err">Your email address is invalid</span>';
        return false
     }
     if (str.indexOf(dot,(lat+2))==-1){
        document.getElementById(noticeID).innerHTML='<span class="err">Your email address is invalid</span>';
        return false
     }
     if (str.indexOf(" ")!=-1){
        document.getElementById(noticeID).innerHTML='<span class="err">Your email address is invalid</span>';
        return false
     }


    document.getElementById(noticeID).innerHTML='<span class="aok">Your email address is OK</span>';
      return true
  }






function checkEmptyField(value, noticeID){
  if(value.length <= 0){
    $EL(noticeID).innerHTML = '<span class="err">This field cannot be empty</span>';
  } else {
    $EL(noticeID).innerHTML = '<span class="aok">OK</span>';
  }
}











/*
        paginate table object v1.1 by frequency-decoder.com

        Released under a creative commons Attribution-ShareAlike 2.5 license (http://creativecommons.org/licenses/by-sa/2.5/)

        Please credit frequency decoder in any derivative work - thanks

        You are free:

        * to copy, distribute, display, and perform the work
        * to make derivative works
        * to make commercial use of the work

        Under the following conditions:

                by Attribution.
                --------------
                You must attribute the work in the manner specified by the author or licensor.

                sa
                --
                Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one.

        * For any reuse or distribution, you must make clear to others the license terms of this work.
        * Any of these conditions can be waived if you get permission from the copyright holder.
*/

/* The sortCompleteCallback does nothing but call the pagination object below, passing in the table id */

function sortCompleteCallback(tableId){
  tablePaginater.showPage(tableId);
}


function reInitItems(){
 if(undefined == $EL('paginateList-UserManagementTable') && undefined == $EL('paginateList-UserManagementTable') && undefined == $EL('paginateList-PaginateTable')){
  if(undefined != tablePaginater && undefined != fdTableSort){
    tablePaginater.init();
    fdTableSort.init();
  }
 }
 tb_init('a.thickbox, area.thickbox, input.thickbox');

 if(undefined != $EL('tp2') && undefined == tp2){
   var tp2 = new Spry.Widget.TabbedPanels("tp2");
 }

 if(undefined != $EL('tp1') && undefined == tp1){
   var tp1 = new Spry.Widget.TabbedPanels("tp1");
 }

}



/* This is the JS object that paginates the table (N.B: Tables do not have to be sortable to use this object) */
var tablePaginater = {
        tableInfo: {},

        init: function() {
                var tables = document.getElementsByTagName('table');

                for(var t = 0, tbl; tbl = tables[t]; t++) {
                        if(!tbl.id || tbl.id == "" || tbl.className.search(/paginate-([0-9]+)/) == -1) continue;

                        tablePaginater.tableInfo[tbl.id] = {
                                rowsPerPage:tbl.className.match(/paginate-([0-9]+)/)[1],
                                currentPage:0
                        };

                        tablePaginater.showPage(tbl.id, 0);
                        tablePaginater.createPageinationList(tbl.id);
                };
        },

        addClass: function(e,c) {
                if(new RegExp("(^|\\s)" + c + "(\\s|$)").test(e.className)) return;
                e.className += ( e.className ? " " : "" ) + c;
        },

        removeClass: function(e,c) {
                e.className = !c ? "" : e.className.replace(new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
        },

        /* I shall leave it as an excercise for the reader to create the next|prev links commonly
           found within such pagination systems. I'm just creating a simple linked list(s).       */
        createPageinationList: function(tableId) {
                // Get the table
                var tbl = document.getElementById(tableId);

                // Create the UL
                var ul = document.createElement("ul");
                ul.className = "tablePaginater";
                ul.id = "paginateList-" + tableId;

                // clone the UL
                var ulc = ul.cloneNode(true);
                ulc.id =  "paginateList-" + tableId + "-clone";

                var rows = tablePaginater.getTableRows(tableId);
                var total = rows.length;
                var rowsPerPage
                var pages = Math.max(1, Math.ceil(total / tablePaginater.tableInfo[tableId].rowsPerPage));

                // Create the li & a tags to clone within the loop
                var li = document.createElement("li");
                var a  = document.createElement("a");
                a.href = "#";

                var lic, ac;

                // For each page, create a pagination button
                for(var i = 0; i < pages; i++) {
                        lic = li.cloneNode(false);
                        ac  = a.cloneNode(true);
                        ac.title = "View page " + (i + 1);
                        ac.appendChild(document.createTextNode(i+1));
                        lic.onclick = a.onclick = tablePaginater.show;
                        lic.appendChild(ac);

                        if(i == 0) lic.className = "currentPage";

                        ul.appendChild(lic);

                        lic = lic.cloneNode(true);
                        lic.onclick = lic.getElementsByTagName("a")[0].onclick = tablePaginater.show;

                        ulc.appendChild(lic);
                };

                // Add the list below the table
                if(tbl.nextSibling) {
                        tbl.parentNode.insertBefore(ul, tbl.nextSibling);
                } else {
                        tbl.parentNode.appendChild(ul);
                };

                // Add another list above the table
                tbl.parentNode.insertBefore(ulc, tbl.previousSibling);
        },

        getTableRows: function(tableId) {
                var rows = [];
                var tbl = document.getElementById(tableId);

                var tbody = tbl.getElementsByTagName('tbody');

                if(tbody && tbody.length) {
                        tbody = tbody[0];
                        rows = tbody.getElementsByTagName('tr');
                } else {
                        var tmp = tbl.getElementsByTagName('tr');
                        for(var i = tmp.length; i--;) {
                                if(tmp[i].getElementsByTagName('th') || tmp[i].parentNode.tagName == "TFOOT") continue;
                                rows[rows.length] = tmp[i];
                        };
                };
                return rows;
        },

        showPage: function(tableId, page) {
                if(!(tableId in tablePaginater.tableInfo)) return;

                var tbl = document.getElementById(tableId);
                var rowsPerPage = tablePaginater.tableInfo[tableId].rowsPerPage;
                var rows = tablePaginater.getTableRows(tableId);

                page = typeof page == "undefined" ? tablePaginater.tableInfo[tableId].currentPage : page;

                var min = rowsPerPage * page;
                var max = Number(min) + Number(rowsPerPage);
                var rowStyle = tbl.className.search(/rowstyle-([\S]+)/) != -1 ? tbl.className.match(/rowstyle-([\S]+)/)[1] : false;
                var cnt = 0;
                var len = rows.length;

                for(var i = 0; i < len; i++) {
                        rows[i].style.display = (i >= min && i < max) ? "" : "none";
                        if(rowsPerPage % 2 && rowStyle && i >= min && i < max) {
                                tablePaginater.removeClass(rows[i], rowStyle);
                                if(cnt++ % 2) tablePaginater.addClass(rows[i], rowStyle);
                        };
                };

                tablePaginater.tableInfo[tableId].currentPage = page;
        },

        /* Event handler for the li|a click event */
        show: function(e) {
                var li = (this.tagName && this.tagName == "A") ? this.parentNode : this;
                var tableId = li.parentNode.id.replace("paginateList-", "").replace("-clone", "");
                var cnt     = 0;

                while(li.previousSibling) {
                        li = li.previousSibling;
                        if(li.tagName && li.tagName.toLowerCase() == "li") cnt++;
                };

                tablePaginater.showPage(tableId, cnt);

                var ul  = document.getElementById("paginateList-" + tableId);
                var ulc = document.getElementById("paginateList-" + tableId + "-clone");
                var i   = 0;

                while(ul.childNodes[i]) {
                        ul.childNodes[i].className = ulc.childNodes[i].className = i == cnt ? "currentPage" : "";
                        i++;
                };

                return false;
        }
}




var TagListCount = 1;

function AppendTagList(ulID, textID){
  if(undefined != $EL(ulID)){
    newEl = document.createElement("input");
    newEl.type = "text";
    newEl.name = "Tag" + TagListCount;
    newEl.value = $EL(textID).value;
    newLI = document.createElement("li");
    newLI.id="LITag" + TagListCount;
    newLI.innerHTML = '<input type="text" name="Tag' + TagListCount + '" id="Tag' + TagListCount + '" value="' + $EL(textID).value + '" /> <a href="#" onclick="removeFromTagList(\'TagListUL\', \'LITag' + TagListCount + '\'); return false;"><img src="/images/admin360/transparent.gif" alt="Delete" class="DeleteImage" /></a>';
    TagListCount++;
    $EL(ulID).appendChild(newLI);
  }
}

function removeFromTagList(ulID, liID){
  $EL(ulID).removeChild($EL(liID));
}

function ToggleDisplay(displayID){
  if($ST(displayID).display!='none'){
    $ST(displayID).display='none'
  } else {
    $ST(displayID).display='block'
  }

}













function CheckboxUpdateAll(formID, isChecked, inPrefix){
  if(undefined != $EL(formID)){
    els = $EL(formID).elements;
    for(k = 0; k < els.length; k++){
      if(els[k].type=='checkbox' && (inPrefix == undefined || inPrefix == null || els[k].name.substr(0, inPrefix.length) == inPrefix)){
        els[k].checked=isChecked;
      }
    }
  }
}




function CheckboxUpdateSeries(prefixArray, suffix, isChecked){
  for(k = 0; k < prefixArray.length; k++){
    if($EL(prefixArray[k] + suffix).type =='checkbox'){
      $EL(prefixArray[k] + suffix).checked=isChecked;
    }
  }

}






function loadContentIntoMain(contentID)
{
  var refreshSet = new Array();
  refreshSet["/page.php?loadcontent="+contentID] = "mainContent";

  AJAXRefreshSetDOM(refreshSet);
}

function updateImage(inIMG){
  var custom = '<img src="' + inIMG + '" border="0" />';

  if(undefined != tinyMCE){
    tinyMCE.execCommand('mceFocus',false,'Content');
    tinyMCE.execCommand('mceInsertContent',false,custom);
  }
}

function insertURL(inTitle, inURL, inTarget){
  if(inTarget == 1){
    inTarget = 'target="_blank"';
  } else {
    inTarget = 0;
  }
  var custom = '&nbsp;<a href="' + inURL + '" ' + inTarget +'>' + inTitle + '</a>&nbsp;';

  if(undefined != tinyMCE){
    tinyMCE.execCommand('mceFocus',false,'Content');
    tinyMCE.execCommand('mceInsertRawHTML',false,custom);
  }

}

function insertMCEContent(inContent, inTarget){
  if(undefined != tinyMCE){

    tinyMCE.execInstanceCommand(inTarget, 'mceInsertContent',false,inContent, true);
  }
}



var DraggableCount = 1;

function AppendDraggableContent(inList, inID, inText){
  var numLIs = $EL(inList).childNodes.length;

  var newLI = document.createElement("li");
  newLI.className = 'list1';
  newLI.id = 'li1_' + DraggableCount;
  newLI.title = inID;
  newLI.innerHTML = '<table width="100%"><tr><td><input type="hidden" name="ManualContentID' + DraggableCount + '" value="' + inID + '" />' + inText + '</td><td style="text-align:right;"><a href="#" onclick="if(confirm(\'Remove Content?\')){$EL(\'' + inList + '\').removeChild($EL(\'li1_' + DraggableCount + '\'))}; return false;"><img src="../images/icons/delete.gif" border="0" /></a></td></tr></table></li>';

  $EL(inList).appendChild(newLI)

  DraggableCount++;

  YAHOO.example.DDApp.init($EL(inList).childNodes.length, 1);

}



function toggleMenuClass(liID, liNum, contentID, moveLeft) {
  if(moveLeft){
    $EL(liID).className = 'list1 MenuLink1';
    $EL('MenuItemID' + liNum).value = 'MenuLink1_' + contentID;
  } else {
    $EL(liID).className = 'list1 MenuLink2';
    $EL('MenuItemID' + liNum).value = 'MenuLink2_' + contentID;
  }

}

function toggleMenuContentType(inVal){
  $ST('ContentTypeContent').display='none';
  $ST('ContentTypeDynamicContent').display='none';
  $ST('ContentTypeForms').display='none';
  $ST('ContentTypeURL').display='none';
  $ST('ContentTypeRSS').display='none';
  if(inVal == 'Content'){
    $ST('ContentTypeContent').display='block';
  } else if(inVal == 'Dynamic Content'){
    $ST('ContentTypeDynamicContent').display='block';
  } else if(inVal == 'External Link'){
    $ST('ContentTypeURL').display='block';
  } else if(inVal == 'RSS Feed'){
    $ST('ContentTypeRSS').display='block';
  } else if(inVal == 'Form'){
    $ST('ContentTypeForms').display='block';
  }


}
