﻿// This JScript File should contain all javascript used by controls

// MUST NOT USE PROTOTYPE FUNCTIONS as this is included in clients websites 
// and prototype can clash with existing scripts.

// *************************************************************************** //
// This section of the JS file contains generic javascript functions for
// manipulating controls
// *************************************************************************** //

//****************************************
// Function:  PUControl_ShowHideControl
// Purpose:   This function hides or displays the control specified in sID, depending on the value of the 
//            control oControl, and the value of oControl, specified by sValue.
//            If the value of oControl and sValue match, the control sID is displayed
// Param:     oControl - the control the user is interacting with
//            sValue - value you want oControl to be so sID is shown, otherwise it is hidden
//            sID - ID of the control you want to show/hide
// Returns:   none
//****************************************
function PUControl_ShowHideControl( oControl, sValue, sID)
{
   // Find the object
   var oObject = document.getElementById(sID);

   // Check if the value of oControl equals sValue
   if (oControl.value == sValue)
   {
     // Show the object
     oObject.style.display = "";
   }
   else
   {
     // Hide the object
     oObject.style.display = "none";
   }
}


//****************************************
// Function:  PUControl_ClearContols
// Purpose:   This function clears the values in oClearControls, if the value oControl matches sValue
// Param:     oControl - the control the user is interacting with
//            sValue - Value of which you want the control to be for the contols in oClearContols to then be cleared
//            oClearContols - IDs of the controls you want to clear
// Returns:   none
//****************************************
function PUControl_ClearContols(oControl, sValue, oClearContols )
{
  // Check if the value of oControl equals sValue
  if (oControl.value == sValue)
  {
    // Loop through the controls and clear their values
    for ( var lCounter=0, lSize=oClearContols.length; lCounter<lSize; ++lCounter )
    {
      document.getElementById(oClearContols[lCounter]).value = "";
    }
  }
}

// *************************************************************************** //
// This section of the JS file contains javascript functions used by PUFORM
// *************************************************************************** //

//****************************************
// Function:  PUFORM_UpdateCharactersRemaining
// Purpose:   This function updates the character text that follows a text box or text area
//            informing a user how many characters remaining when entering text into a control
// Param:     oControl - the control the user is entering text into
//            lmaxLength - Number of characters that are allowed
//            sCharCountLabel - Text that is displayed saying how many characters have been entered 
// Returns:   True if a character can't be added
//****************************************
function PUFORM_UpdateCharactersRemaining(oControl, lmaxLength, sCharCountLabel)
{
  var bClipped = false;
  
  //Check if we have reached the character limit
  if (oControl.value.length > lmaxLength)
  {
    // Yes, truncate the input to the limit
    oControl.value = oControl.value.substring(0,lmaxLength)

    // Update the text to say how many characters remaining, hightlighted in red
    document.getElementById(oControl.name + '_lCharCountLabel').innerHTML = '<font color="red">' + sCharCountLabel + ':</font>'
    document.getElementById(oControl.name + '_lCharCounter').innerHTML = '<font color="red">0</font>'
    bClipped = true;
  }
  else
  {
    // No, Update the text to say how many characters remaining
    document.getElementById(oControl.name + '_lCharCountLabel').innerHTML = sCharCountLabel + ':'
    document.getElementById(oControl.name + '_lCharCounter').innerHTML = lmaxLength - oControl.value.length
  }
  return bClipped;
}

