// JavaScript Document

// CONFIRM LOGIN
function confirm_login(){ 
if (confirm("You must login to use this feature\nClick OK to register or login now.")){ 
window.location="register.php";

} 
} 



// Clear Inputs
function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

// GoTo fuction
function GoTo(url)
{
	window.location.href = url;
}

// EXPAND
function showHide(elementid){
if (document.getElementById(elementid).style.display == 'none'){
document.getElementById(elementid).style.display = '';
} else {
document.getElementById(elementid).style.display = 'none';
}
}

//
//function
function saveSearch(searchUrl, reload) {
  var searchName = prompt("Enter a name for this search:");
  if (searchName == null) { return false; }
  if (searchName == "")   { return alert("Error: No search name entered!"); }

  //
  $.ajax({
    url: '?action=saveSearch&name=' +escape(searchName)+ '&url=' + escape(searchUrl),
    error:  function(XMLHttpRequest, textStatus, errorThrown){
      alert("There was an error sending the request! (" +XMLHttpRequest['status']+" "+XMLHttpRequest['statusText'] +")");
    },
    success: function(msg){
      if (msg) { alert("Error: " + msg); }
      else {
        $('#saveSearch').hide();
        $('#removeSearch').show();
        if (reload == true) { window.location.reload(); }
      }
    }
  });

}

function removeSearch(searchUrl, reload) {

  //
  $.ajax({
    url: '?action=removeSearch&url=' + escape(searchUrl),
    error:  function(XMLHttpRequest, textStatus, errorThrown){
      alert("There was an error sending the request! (" +XMLHttpRequest['status']+" "+XMLHttpRequest['statusText'] +")");
    },
    success: function(msg){
      if (msg) { alert("Error: " + msg); }
      else {
        $('#saveSearch').show();
        $('#removeSearch').hide();

        if (reload == true) { window.location.reload(); }
      }
    }
  });
}

//function
function saveListing(tableName, recordNum) {

  $.ajax({
    url: '?action=saveListing&tablename=' +escape(tableName)+ '&num=' + escape(recordNum),
    success: function(msg){
      if (msg) { alert("Error: " + msg); }
      else {
        $('#saveListing' + recordNum).hide();
        $('#saveListing' + tableName + recordNum).hide();
        $('#removeListing' + recordNum).show();
        $('#removeListing' + tableName + recordNum).show();
      }
    }
  });

}

function removeListing(tableName, recordNum, reload) {

  //
  $.ajax({
    url: '?action=removeListing&tablename=' +escape(tableName)+ '&num=' + escape(recordNum),
    success: function(msg){
      if (msg) { alert("Error: " + msg); }
      else {
        $('#saveListing' + recordNum).show();
        $('#saveListing' + tableName + recordNum).show();
        $('#removeListing' + recordNum).hide();
        $('#removeListing' + tableName + recordNum).hide();

        if (reload == true) {
          window.location.reload();
        }
      }
    }
  });
}

