/*
#
#  GreatWebScripts    http://www.GreatWebScripts.com
#
#  Copyright (c)2006-2008, GreatWebScripts . All rights reserved.
#
#  No portion of this content may be copied, distributed or reproduced for any
#  reason without the express written consent of the owner. Federal copyright
#  law prohibits unauthorized reproduction by any means and imposes severe fines
#  for violation.
#

#
#  $RCSfile: photocap.js,v $ $Revision: 1.7 $   $Date: 2008-11-16 22:15:20-05 $
#
*/

// Constants (Constant values defined in _Global.php
var GWS_NO               = 0;
var GWS_LOGFILE_NONE     = 0;


function deletephoto (photofile, filestatus)
{
    input_box=confirm('Do you want to delete photo ' + photofile + '?');
    if (input_box==true) {
        window.location='?deletephoto=' + photofile + '&filestatus=' + encodeURI(filestatus);
    }
} // end deletephoto

function cleanphoto (photofile, filestatus)
{
    input_box=confirm('Clear the Thumbnails for ' + photofile + '?');
    if (input_box==true) {
        window.location='?Clean=' + photofile + '&filestatus=' + encodeURI(filestatus);
    }
} // end cleanphoto

function ChangePhotoState (state, photofile)
{
    input_box=confirm('Do you want to move photo '+ photofile + ' to ' + state + '?');
    if (input_box==true) {
        window.location='?Make' + state + '=' + encodeURI (photofile);
    }
} // end ChangePhotoState


function performrename (photofile, filestatus)
{
    var newname = prompt('New Filename:', '');

    if (newname == null) {
        // Op cancelled -- he know what he did - no popup
    }
    else if (newname.length <= 0) {
        // Op didn't enter a new name but clicked OK -
        alert ('Rename Cancelled');
    }
    else  {
        // Do it
        window.location='?renamephoto=' + photofile + '&newname=' + encodeURI (newname) + '&filestatus=' + encodeURI(filestatus);
    }
} // end performrename


function VerifyDelete (item)
{
    input_box=confirm('Do you want to delete ' + item + '?');
    return input_box;
} // end VerifyDelete

function VerifyDeleteTlog (date)
{
    if (date.length > 0) {
      input_box=confirm('Do you want to delete entries dated previous to ' + date + '?');
      return input_box;
    } else {
      confirm ('Fill in the Delete Date First!');
      return false;
    }
} // end VerifyDeleteTlog

//
// Opens the preview caption window
//
function PreviewCaption (item, width, height)
{
    itemurl = encodeURIComponent (item);

    window.open ("?PreviewCaptionPopup=" + itemurl,
                 "cpreview",
                 "resizable,scrollbars,width="+width+",height="+height);
} // end VerifyDelete

// Insert myValue at the cursor position in myField
function bracketAtCursor (myField, myValue)
{

  myValueArray = myValue.split ("=");
  myValue_command = myValueArray[0];


  //IE support
  if (document.selection)
  {
     myField.focus();
     sel = document.selection.createRange();
     sel.text = '<'+myValue+'>' + sel.text + '</'+myValue_command+'>';
  }
  //MOZILLA/NETSCAPE support
  else if (myField.selectionStart || myField.selectionStart == '0')
  {
     var startPos = myField.selectionStart;
     var endPos = myField.selectionEnd;
     var seltext;

     if (endPos > startPos)
     {
         starttext = myField.value.substring (0, startPos);
         seltext   = myField.value.substring (startPos, endPos);
         endtext   = myField.value.substring (endPos, myField.value.length);
     }
     else
     {
         starttext = myField.value;
         seltext = '';
         endtext = '';
     }

     myField.value = starttext +
                     '<' + myValue+'>' + seltext + '</' + myValue_command + '> ' +
                     endtext;

  }
  else
  {
     myField.value += '<'+myValue+'>' + '</'+myValue_command+'>';;
  }

   // Mark it changed
   myField.className = 'caption-modified';

} // end bracketAtCursor


// Insert myValue at the cursor position in myField
function prefixAtCursor (myField, myValue)
{
  myValueArray = myValue.split ("#");
  myValue_1 = myValueArray[0];
  myValue_2 = myValueArray[1];


  //IE support
  if (document.selection)
  {
     myField.focus();
     sel = document.selection.createRange();
     sel.text = '<'+ myValue_1 + sel.text + myValue_2 + '>';
  }
  //MOZILLA/NETSCAPE support
  else if (myField.selectionStart || myField.selectionStart == '0')
  {
     var startPos = myField.selectionStart;
     var endPos = myField.selectionEnd;
     var seltext;

     if (endPos > startPos)
     {
         starttext = myField.value.substring (0, startPos);
         seltext   = myField.value.substring (startPos, endPos);
         endtext   = myField.value.substring (endPos, myField.value.length);
     }
     else
     {
         starttext = myField.value;
         seltext = '';
         endtext = '';
     }

     myField.value = starttext +
                   '<' + myValue_1 + seltext.replace(/^\s+|\s+$/g,"") + myValue_2 + '> ' +
                   endtext;
  }
  else
  {
     myField.value = '<'+ myValue_1 + myField.value + myValue_2 + '>';
  }

   // Mark it changed
   myField.className = 'caption-modified';

} // end prefixAtCursor


//
// Validation Routines
//


// Handles updates to Site Active field
function changeSiteActive ()
{
  // Check if we can continue
  if (window.document.Configuration.UMS_GAME_ENABLED == null) return;

  // Extract the value set
  var selectedIndex       = window.document.Configuration.UMS_GAME_ENABLED.selectedIndex;
  var selectedIndex_value = window.document.Configuration.UMS_GAME_ENABLED.options[selectedIndex].value;

  // and determine what to do
  if (selectedIndex_value == GWS_NO)
  {
      window.document.Configuration.GAME_NOT_ACTIVE_MESSAGE.disabled = false;
      window.document.Configuration.GAME_NOT_ACTIVE_MESSAGE.className = "textbox-active";
  } // end if

  else
  {
      window.document.Configuration.GAME_NOT_ACTIVE_MESSAGE.disabled = true;
      window.document.Configuration.GAME_NOT_ACTIVE_MESSAGE.className = "textbox-inactive";
  } // end else to if

} // end changeSiteActive


// Handles updates to Logging field
function changeLoggingState ()
{
  // Check if we can continue
  if (window.document.Configuration.GWS_LOGFILE_STATUS == null) return;

  // Extract the value set
  var selectedIndex       = window.document.Configuration.GWS_LOGFILE_STATUS.selectedIndex;
  var selectedIndex_value = window.document.Configuration.GWS_LOGFILE_STATUS.options[selectedIndex].value;

  // and determine what to do
  if (selectedIndex_value == GWS_LOGFILE_NONE)
  {
      window.document.Configuration.GWS_MAX_RECORDS_IN_LOG_FILE.disabled = true;
      window.document.Configuration.GWS_MAX_RECORDS_IN_LOG_FILE.className = "textbox-active";

      window.document.Configuration.GWS_DAYS_PURGE_LOG_FILE.disabled = true;
      window.document.Configuration.GWS_DAYS_PURGE_LOG_FILE.className = "textbox-active";

      window.document.Configuration.LOGENTRIES_PER_PAGE.disabled = true;
      window.document.Configuration.LOGENTRIES_PER_PAGE.className = "textbox-active";

      window.document.Configuration.TRANS_LOG.disabled = true;
      window.document.Configuration.TRANS_LOG.className = "textbox-active";
  } // end if

  else
  {
      window.document.Configuration.GWS_MAX_RECORDS_IN_LOG_FILE.disabled = false;
      window.document.Configuration.GWS_MAX_RECORDS_IN_LOG_FILE.className = "textbox-inactive";

      window.document.Configuration.GWS_DAYS_PURGE_LOG_FILE.disabled = false;
      window.document.Configuration.GWS_DAYS_PURGE_LOG_FILE.className = "textbox-inactive";

      window.document.Configuration.LOGENTRIES_PER_PAGE.disabled = false;
      window.document.Configuration.LOGENTRIES_PER_PAGE.className = "textbox-inactive";

      window.document.Configuration.TRANS_LOG.disabled = false;
      window.document.Configuration.TRANS_LOG.className = "textbox-inactive";
  } // end else to if
} // end changeLoggingState


// Handles updates to Allow User Uploads
function changeAllowUserUploads ()
{
  // Check if we can continue
  if (window.document.Configuration.ALLOW_USER_UPLOADS == null) return;

  // Extract the value set
  var selectedIndex       = window.document.Configuration.ALLOW_USER_UPLOADS.selectedIndex;
  var selectedIndex_value = window.document.Configuration.ALLOW_USER_UPLOADS.options[selectedIndex].value;

  // and determine what to do
  if (selectedIndex_value == GWS_NO)
  {
      window.document.Configuration.USER_UPLOAD_INITIAL_STATE.disabled = true;
  } // end if

  else
  {
      window.document.Configuration.USER_UPLOAD_INITIAL_STATE.disabled = false;
  } // end else to if

} // end changeAllowUserUploads




// Handles updates to Ajax Changes
function changeAjaxState ()
{
  // Check if we can continue
  if (window.document.Configuration.ENABLE_AJAX == null) return;

  // Extract the value set
  var selectedIndex       = window.document.Configuration.ENABLE_AJAX.selectedIndex;
  var selectedIndex_value = window.document.Configuration.ENABLE_AJAX.options[selectedIndex].value;

  // and determine what to do
  if (selectedIndex_value == GWS_NO)
  {
      window.document.Configuration.PEEK_REFRESH_INTERVAL.disabled = true;
  } // end if

  else
  {
      window.document.Configuration.PEEK_REFRESH_INTERVAL.disabled = false;
  } // end else to if

} // end changeAjaxState




//
// Hides/Displays the Peek Frame
//
function SetPeekFrame (visibility)
{
  if (visibility) display = ''
  else            display = 'none';

  if (document.getElementById)  // DOM3 = IE5, NS6
  {
    document.getElementById('caption_peek_frame').style.display = display;
  }
  else
  {
    if (document.layers)  // Netscape 4
      document.caption_peek_frame.display = display;
    else  // IE 4
      document.all.caption_peek_frame.style.display = display;
  } // end if (document.getElementById)

  // Set a cookie to make it permanent
  setCookie ('photocap-peek-display', display, 360);

} // end SetPeekFrame

//
// Hides/Displays the My Captions Frame
//
function SetMineFrame (visibility)
{
  if (visibility) display = ''
  else            display = 'none';

  if (document.getElementById)  // DOM3 = IE5, NS6
  {
    document.getElementById('vote_captiontable_mine_frame').style.display = display;
  }
  else
  {
    if (document.layers)  // Netscape 4
      document.vote_captiontable_mine_frame.display = display;
    else  // IE 4
      document.all.vote_captiontable_mine_frame.style.display = display;
  } // end if (document.getElementById)

  // Set a cookie to make it permanent
  setCookie ('photocap-mine-display', display, 360);

} // end SetMineFrame


