﻿
var popup;
var afterSave = defaultAfterSave;

function editSetClick(setID) {
  popup = document.getElementById('popup');
  if (popup) {
    ajaxGet(popupOpen, '/ajax_links_addset.aspx?s='+setID, false);
  }
  return false;  
}

function editLinkClick(setID, linkID) {
  popup = document.getElementById('popup');
  if (popup) {
    ajaxGet(popupOpen, '/ajax_link_add.aspx?s='+setID+'&l='+linkID, false);
  }
  return false;  
}

function addBlogEntryLinkClick(postID) {
  popup = document.getElementById('popup');
  if (popup) {
    ajaxGet(popupOpen, '/ajax_link_add.aspx?be='+postID, false);
  }
  return false;  
}

function saveSetClick(setID) {
  var txtName = document.getElementById('txtName');
  var txtDesc = document.getElementById('txtDesc');
  var lstShow = document.getElementById('lstShow');
  var param = 'txtName='+encodeURI(txtName.value)+'&txtDesc='+encodeURI(txtDesc.value)+'&lstShow='+lstShow.options[lstShow.selectedIndex].value+'&setID='+setID;
  ajaxPost(saveComplete, '/ajax_links_addset.aspx', param, false);
  
}

function saveLinkClick(linkID) {
  var txtName = document.getElementById('txtName');
  var txtDesc = document.getElementById('txtDesc');
  var txtURL = document.getElementById('txtURL');
  var txtTags = document.getElementById('txtTags');
  var setID=0;
  var lstSets = document.getElementById('lstSets');
  if (lstSets)
    setID = lstSets.options[lstSets.selectedIndex].value;
  var showTo=0;
  var lstShow = document.getElementById('lstShow');
  if (lstShow)
    showTo = lstShow.options[lstShow.selectedIndex].value;
    var copymode = document.getElementById('copy');
  var param = 'txtName='+encodeURI(txtName.value)+'&txtDesc='+encodeURI(txtDesc.value)+'&txtURL='+encodeURI(txtURL.value)+'&txtTags='+encodeURI(txtTags.value)+'&lstShow='+showTo+'&setID='+setID+'&linkID='+linkID+'&copy='+copymode.value;
  ajaxPost(saveComplete, '/ajax_link_add.aspx', param, false);
  
}

function popupOpen(http_request) {
  if (http_request) {
    if (http_request.readyState == 4) {
      if (http_request.status == 200) {
        var top = 100+((window.pageYOffset)?(window.pageYOffset):(document.documentElement)?document.documentElement.scrollTop:document.body.scrollTop);
        popup.innerHTML = http_request.responseText;
        //popup.style.left=((document.body.clientWidth/2) - (popup.offsetWidth/2))+'px';
        popup.style.top=top+'px';
        popup.style.visibility='visible';
      }
    }
  }
}

function saveComplete(http_request) {
  if (http_request) {
    if (http_request.readyState == 4) {
      if (http_request.status == 200) {
        popupClose();
        afterSave();
      }
    }
  }
}

function popupClose() {
  popup.style.visibility='hidden';
  popup.innerHTML = '';
  popup = null;
}

function showCloud() {
  var cloud = document.getElementById('cloud');
  cloud.style.display='';
}

function cloudSelect(tagname) {
  addToTextBox('txtTags', tagname)
  return false;
}

function defaultAfterSave() {
  window.location.reload(true);
}