﻿
function SlideDown(ID)

{
$("#" + ID).slideDown();

}

function FormatPhoneNumber(phoneNumber)
{

phoneNumber = phoneNumber.replace(/[^0-9]+/g, "");

if (phoneNumber.length == 10)
{

phoneNumber = phoneNumber.substring(0,3) + "-" + phoneNumber.substring(3,6) + "-" + phoneNumber.substring(6,10);



}
else if (phoneNumber.length == 11 && phoneNumber.substring(0,1) == 1)
{


phoneNumber = phoneNumber.substring(0, 1) + "-" + phoneNumber.substring(1,4) + "-" + phoneNumber.substring(4,7) + "-" + phoneNumber.substring(7,11);



}

return phoneNumber;

}


/* Luhn algorithm number checker - (c) 2005-2008 shaman - www.planzero.org *
 * This code has been released into the public domain, however please      *
 * give credit to the original author where possible.                      */

function luhn_check(number) {
//<![CDATA[

  // Strip any non-digits (useful for credit card numbers with spaces and hyphens)
  var number=number.replace(/\D/g, '');

  // Set the string length and parity
  var number_length=number.length;
  var parity=number_length % 2;

  // Loop through each digit and do the maths
  var total=0;
  for (i=0; i < number_length; i++) {
    var digit=number.charAt(i);
    // Multiply alternate digits by two
    if (i % 2 == parity) {
      digit=digit * 2;
      // If the sum is two digits, add them together (in effect)
      if (digit > 9) {
        digit=digit - 9;
      }
    }
    // Total up the digits
    total = total + parseInt(digit);
  }

  // If the total mod 10 equals 0, the number is valid
  if (total % 10 == 0) {
    return true;
  } else {
    return false;
  }

//]]>
}

/**
 * When the open event is called, this function will be used to 'open'
 * the overlay, container and data portions of the modal dialog.
 *
 * onOpen callbacks need to handle 'opening' the overlay, container
 * and data.
 */
function modalOpen (dialog) {
dialog.overlay.fadeIn('slow');
dialog.container.fadeIn('fast');
dialog.data.fadeIn('slow');	 
	
}


/**
 * When the close event is called, this function will be used to 'close'
 * the overlay, container and data portions of the modal dialog.
 *
 * The SimpleModal close function will still perform some actions that
 * don't need to be handled here.
 *
 * onClose callbacks need to handle 'closing' the overlay, container
 * and data.
 */
function modalClose (dialog) {
	dialog.data.fadeOut('fast');
	dialog.container.fadeOut('fast');
	dialog.overlay.fadeOut('slow', function () {  $.modal.close();  });
	
}

/* ctlItemList */
function ToggleNode(NamingContainer, ItemID)
{
ToggleVisibilityAndPlusMinus(NamingContainer + "Toggle" + ItemID, NamingContainer + "Children" + ItemID)

}
/* Admin item*/
function ToggleList(ListName)
{
ToggleVisibilityAndPlusMinus('OpenClose' + ListName, 'ctl00_LeftContent_ul' + ListName);
}

/*ctlItemList and Admin item*/
function ToggleVisibilityAndPlusMinus(OpenClose, ShowHideControl)
{

var OpenClose = document.getElementById(OpenClose);

if (OpenClose.innerHTML.match("\\+"))
{
OpenClose.innerHTML = "−";
$("#" + ShowHideControl).slideDown("medium");
}
else if (OpenClose.innerHTML.match("−"))
{
OpenClose.innerHTML = "+";
$("#" + ShowHideControl).slideUp("medium");
}



}


/* ctlSwitcheroo */
function ToggleLists(ListOneID, ListTwoID, ButtonOneID, ButtonTwoID)
{
//var ListOne = document.getElementById(ListOneID);
//var ListTwo = document.getElementById(ListTwoID);




$("#" + ListOneID).slideToggle("slow");
$("#" + ListTwoID).slideToggle("slow");





//var ListTwoDisplay = ListTwo.style.display;

//ListTwo.style.display = ListOne.style.display;
//ListOne.style.display = ListTwoDisplay;




var ButtonOne = document.getElementById(ButtonOneID);
var ButtonTwo = document.getElementById(ButtonTwoID);

var ButtonOneClass = ButtonOne.className;
var ButtonOneLink = ButtonOne.href;

ButtonOne.className = ButtonTwo.className;
ButtonTwo.className = ButtonOneClass;

ButtonOne.href = ButtonTwo.href;
ButtonTwo.href = ButtonOneLink;


}



function HideNonMatching(SearchBoxID, ListID)
{
var SearchText = document.getElementById(SearchBoxID).value.toLowerCase();
var SearchExp = new RegExp(SearchText);

var List = document.getElementById(ListID);

var ChildNodeCount = List.childNodes.length;

for (i = 0; i < ChildNodeCount; i++)
{

    var Node = List.childNodes[i];

    if (SearchExp.test(Node.firstChild.innerHTML.toLowerCase()) || SearchText.length == 0)
    {
    $("#" + Node.id).slideDown(function(){
    $(this).css("display", "list-item");
    
    ;}
    );

    

    }
    else
    {
    $("#" + Node.id).slideUp();
    }

}

}