var floater;
var pause        = "";
var thisButton   = "";
var globalobj    = false;//default bogus initial object/div
var displayvalue = "block";
var prevButton   = false
var prevDiv      = ""

/*
 *Used as a standard message confirmation which will be
 *used to have the user confirm any message via javascript.
 */
function confirmMessage( msgString )
{
  var agree=confirm( msgString );
  if (agree) {
  return true;
  }else{
  return false;
  }
}

/*
 *Used as a standard alert for user to confirm they actual want to delete
 *said object
 */
function confirmDelete( thingToDelete )
{
  var msg = 'Click OK to delete "';
  msg += thingToDelete;
  msg += '".';
  var agree=confirm( msg );
  if (agree) {
  return true;
  }else{
  return false;
  }
}

function cleartimer()
{
  clearTimeout(pause);
  return true;
}



function toggleoptions(clickedbutton,objname)
{
    thisButton = clickedbutton;
    globalobj = document.getElementById(objname);
    if( globalobj != null ) {
      //turn off display of previous div to "NONE"
    if((prevDiv)&&(globalobj!=prevDiv))
  {
    /*alert('in here');*/clearTimeout(pause);prevDiv.style.display='none'; prevButton.value='+';

  }
      //alert(globalobj.id + '\n' +globalobj.style.display)
  displayvalue = (globalobj.style.display == 'block') ? 'none' : 'block';

      //alert(globalobj.id+' ' + ' '+ globalobj.style.display+ ' '+displayvalue);

    if(displayvalue=='none')
    {
     //thisButton = clickedbutton;
    //globalobj = document.getElementById(objname);
         //if (!thisButton.value)
         //  {thisButton= document.getElementById(thisButton)}
  pause=setTimeout("thisButton.title='Show button options'; globalobj.style.display=displayvalue;",1500);
    } else {
  //DISPLAY the proper NEW div
        //window.status=globalobj.id;
   /*thisButton.value='-'; */thisButton.title='Hide button options'; globalobj.style.display=displayvalue;

    }
    }
     prevButton = thisButton;
     prevDiv    = globalobj;

}

function CheckAll()
{
    count = document.forms[0].elements.length;
    for (i=0; i < count; i++)
    {
      if( document.forms[0].elements[i].type == "checkbox") {
        if(document.forms[0].elements[i].checked == 1)
          {document.forms[0].elements[i].checked = 0; }
        else {document.forms[0].elements[i].checked = 1;}
      }
    }
}

function checkAllByFormNumber(x)
{
  count = document.forms[x].elements.length;
  allchecked = 1;
  for (i=0; i < count; i++)
  {
   if (document.forms[x].elements[i].checked == 0 && document.forms[x].elements[i].id != document.forms[x].selectall.id)
   { allchecked = 0; }
  }
  		
  if (allchecked)
  {
    for (i=0; i < count; i++)
      document.forms[x].elements[i].checked = 0;
  }
  else
  {
    for (i=0; i < count; i++)
    document.forms[x].elements[i].checked = 1;
  }
}
function checkAllByFormName(x)
{
  count = document.getElementById(x).elements.length;
  allchecked = 1;
  for (i=0; i < count; i++)
  {
   if (document.getElementById(x).elements[i].checked == 0 && document.getElementById(x).elements[i].id != document.getElementById(x).selectall.id)
   { allchecked = 0; }
  }
  		
  if (allchecked)
  {
    for (i=0; i < count; i++)
      document.getElementById(x).elements[i].checked = 0;
  }
  else
  {
    for (i=0; i < count; i++)
    document.getElementById(x).elements[i].checked = 1;
  }
}

function printWithAction(ssid,chkBoxName) {
  /*
   * This function will call the print page for badges
   * and will perform the checkin of the user clicked.
   */

    var url, name, atts, newWindow, i;
    name = "Print_Page";
    ssID = "prm_ss_0"
    rowID = "ROW_ID_0"
    siteParmName  =  "id_site"
    siteid = document.visitor.id_site.value;

    atts = "?" + siteParmName + "=" + siteid +  "&print_badge=true&" + ssID + "=" + ssid +"&"+ rowID + "=true";
    url= document.visitor.HDR_printurl.value;
    if( document.forms['visitor'].elements['FaceFilename'] &&
        document.forms['visitor'].elements['FaceFilename'].value != "" ) {
      atts += "&include=face";
    }

   //Loop through the elements and check the box that was chosen
    for (i = 0; i < document.visitor.elements.length; i++)
    {
      if(document.visitor.elements[i].type == "checkbox"){
         name = document.visitor.elements[i].name;
         if(name.toString() == chkBoxName.toString()  ){
            document.visitor.elements[i].checked = true;
         }
      }
    }

    document.visitor.prm_checkin_y.value = true;

    // Open the PrintWindow
    newOpen(url+atts);

    //setTimeout('document.visitor.submit()',3000);

    //document.visitor.submit();

}

function printMult() {
  /*
   * This function will call the print page for badges
   */


    var url, name,ckdBadges, atts, basePrintName, atts2, newWindow, counter;
    name = "Print_Page";

    siteParmName  =  "id_site"
    siteid = document.forms['visitor'].elements['id_site'].value;

    atts = "?" + siteParmName + "=" + siteid +"&print_badge=true";
    atts2 = "";
    ssidParmName = "prm_ss_";
    url= document.visitor.HDR_printurl.value;
    if( document.forms['visitor'].elements['FaceFilename'] &&
        document.forms['visitor'].elements['FaceFilename'].value != "" ) {
      atts += "&include=face";
    }
    PrintCheckbox = "BADGE_CKBOX"

     if(document.visitor.BADGE_CKBOX != null){

       counter = -1;


       ckdBadges = new Array(document.visitor.BADGE_CKBOX.length);


       // Put the badge checkboxes in it's own array
       if(document.visitor.BADGE_CKBOX.length != null){
           checkBoxes = new Array(document.visitor.BADGE_CKBOX.length);
            checkBoxes = document.visitor.BADGE_CKBOX
       }else{
          checkBoxes =new Array(1);
          checkBoxes[0] = document.visitor.BADGE_CKBOX
       }


        // Loop through the elements and find the print checked print boxes
       for (var i = 0; i < checkBoxes.length; i++)
       {
          if(checkBoxes[i].checked ){
             counter++;
             ckdBadges[counter] = checkBoxes[i].value;
             checkBoxes[i].checked = false;

          }
       }



      // If there were print boxes checked carry on with processing
      if(counter>=0){
        // Now loop through the array and create the Parammeters for the URL
          for (it =0; it<ckdBadges.length; it++)
          {
            if (ckdBadges[it]) atts2 = atts2 + "&" + ssidParmName + it + "=" + ckdBadges[it];
          }

         // Open the PrintWindow for submission and badge printing
         newOpen(url + atts + atts2);
        //floater.focus();
        //floater.print();
        // floater.close();
         //alert("Here");
      }
    }





}



function printSingle(ssid) {
  /*
   * This function will call the print page forthe supplied ssid
   */
   //window.abc;

    var url, name, atts,newWindow;
    name = "Print_Page";
    siteParmName  =  "id_site"
    siteid = document.forms['visitor'].elements['id_site'].value;

    atts = "?" + siteParmName + "=" + siteid +"&print_badge=true&prm_ss_0=" + ssid;
    url= document.forms['visitor'].elements['HDR_printurl'].value;
    if( document.forms['visitor'].elements['FaceFilename'] &&
        document.forms['visitor'].elements['FaceFilename'].value != "" ) {
      atts += "&include=face";
    }

    // Open the PrintWindow for submission and badge printing
  if(newOpen(url+atts)){
  //floater.close();
  }
   //alert(floater);
   //floater.focus().print();
   //window.showModalDialog
   //floater.focus();
   //floater.close();

}


function printClose() {
  /*
   * This function will call the print print then close
   */

    //window.print();
    //window.close();
}

function printalert() {
  /*
   * This function will call the print print then close
   */

    alert("before");



}

function printalertAfter() {
  /*
   * This function will call the print print then close
   */

    alert("after");
}




function newOpen(URL) {
//-- This function opens the new, empty window named floater.

   winStats='toolbar=no,location=no,directories=no,menubar=no,';
   winStats+='scrollbars=no,width=330,height=175';
   if (navigator.appName.indexOf("Microsoft")>=0) {
      winStats+=',left=222,top=100';
   }else{
      winStats+=',screenX=222,screenY=100';
   }

   floater=window.open(URL,'GPrint',winStats);
   floater.focus();
   // floater.print();
   // alert( floater.document );
   //setTimeout("floater.print() ",2000);
   //setTimeout("floater.close() ",2000);
   // floater.close();

   return true;

}
function checkEMail(emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address.
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
  alert("Email Error: The address is incorrect (check @ and .'s)")
  return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid
if (user.match(userPat)==null) {
    // user is not valid
    alert("Email Error: The username isn't valid.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
    for (var i=1;i<=4;i++) {
      if (IPArray[i]>255) {
          alert("Email Error: Destination IP address is invalid!")
    return false
      }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
  alert("Email Error: The domain name doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 ||
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   alert("Email Error: The address must end in a three-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="Email Error: This address is missing a hostname!"
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}
function chkNumeric(objName) {
  //alert( " we are in check numeric");
  var field = objName;
  if (IsNumeric(objName.value) == false) {
    field.select();
    alert("The number is invalid.  Please try again.");
    field.focus();
    return false;
  } else {
    //alert("about to return true, ya baby, you entered the date correctly, grr!!!");
    return true;
  }
}
function IsNumeric(strString) {
   //  check for valid numeric strings
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}
<!-- Begin
function checkdate(dateInput) {
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables
var dateStr = dateInput.value;
//var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

// To require a 4 digit year entry, use this line instead:
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert("The date is invalid please try again. With this format MM/DD/YYYY.")
dateInput.focus();
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
dateInput.focus();
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
dateInput.focus();
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
dateInput.focus();
return false
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("February " + year + " doesn't have " + day + " days!");
dateInput.focus();
return false;
   }
}
return true;  // date is valid
}
//  End -->
//function checkdate(objName) {
//  var datefield = objName;
//  if (chkdate(objName) == false) {
//    datefield.select();
//    alert("The date is invalid please try again. With either this format MM/DD/YYYY or MM/DD/YY");
//    datefield.focus();
//    return false;
//  } else {
//    //alert("about to return true, ya baby, you entered the date correctly, grr!!!");
//    return true;
//  }
//}
function chkdate(objName) {
  //alert(" we are in chkDate ");
  var strDatestyle = "US"; //United States date style
  //var strDatestyle = "EU";  //European date style
  var strDate;
  var strDateArray;
  var strDay;
  var strMonth;
  var strYear;
  var intday;
  var intMonth;
  var intYear;
  var booFound = false;
  var datefield = objName;
  var strSeparatorArray = new Array("/");
  var intElementNr;
  var err = 0;
  strDate = datefield.value;
  if (strDate.length < 1) {
    return true;
  }

  for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
    if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
      strDateArray = strDate.split(strSeparatorArray[intElementNr]);
      if(strDateArray.length != 3) {
  err = 1;
  return false;
      }
      else {
  strDay = strDateArray[0];
  strMonth = strDateArray[1];
  strYear = strDateArray[2];
  booFound = true;
      }
    }
  }

  if (booFound == false) {
    if (strDate.length>5) {
      strDay = strDate.substr(0, 2);
      strMonth = strDate.substr(2, 2);
      strYear = strDate.substr(4);
    }
  }
  if ( strYear != null && strYear.length < 4) {
    err = 4;
    return false;
    //strYear = '20' + strYear;
  }

  // US style
  if (strDatestyle == "US") {
    strTemp = strDay;
    strDay = strMonth;
    strMonth = strTemp;
  }

  intday = parseInt(strDay, 10);
  if (isNaN(intday)) {
    err = 2;
    return false;
  }

  intMonth = parseInt(strMonth, 10);

  if (isNaN(intMonth)) {
    for (i = 0;i<12;i++) {
      if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
  intMonth = i+1;
  strMonth = strMonthArray[i];
  i = 12;
      }
    }
    if (isNaN(intMonth)) {
      err = 3;
      return false;
    }
  }
  intYear = parseInt(strYear, 10);
  if (isNaN(intYear)) {
    err = 4;
    return false;
  }

  if (intMonth>12 || intMonth<1) {
    err = 5;
    return false;
  }
  if ( (intMonth == 1 ||
  intMonth == 3 ||
  intMonth == 5 ||
  intMonth == 7 ||
  intMonth == 8 ||
  intMonth == 10 ||
  intMonth == 12) &&
       (intday > 31 || intday < 1)) {
    err = 6;
    return false;
  }

  if (
      (intMonth == 4 ||
       intMonth == 6 ||
       intMonth == 9 ||
       intMonth == 11) &&
      (intday > 30 || intday < 1)) {

    err = 7;
    return false;
  }
  if (intMonth == 2) {
    if (intday < 1) {
      err = 8;
      return false;
    }
    if (LeapYear(intYear) == true) {
      if (intday > 29) {
        err = 9;
        return false;
      }
    }
    else {
      if (intday > 28) {
        err = 10;
        return false;
      }
    }
  }
  // if (strDatestyle == "US") {
  //        datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
  // }
  //else {
  //   datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
  //}

  return true;
}

function LeapYear(intYear) {
          if (intYear % 100 == 0) {
           if (intYear % 400 == 0) { return true; }
           }
           else {
                if ((intYear % 4) == 0) { return true; }
           }
         return false;
}
/*
 * Regex trim function for validation of fields when user attempts
 * to iunput a single space or leading and trailing spaces.
 */
function Trim(val) {
  val = val.replace( /^\s+/g, "" );// strip leading
  return val.replace( /\s+$/g, "" );// strip trailing
}
/**
 * Replaces reserved xml characters with a safe version.   The order
 * of ampersand being first is important due to a double replaces bug.
 */
function XMLReplace(sInString) {
  sInString = sInString.replace(/&/g,'&amp;');
  sInString = sInString.replace(/>/g,'&gt;');
  sInString = sInString.replace(/</g,'&lt;');
  return sInString;

}
/**
 * Universal show/hide for the drag and drop contacts list currently used
 * in the broadcast, COI, and reminder pages.
 * id - parent element to expand or contract
 * switchType - Tag to check for incase multiple parents are being shown. ex org
 * liName - Used to get the list of elements ex. nameList
 */
function showHideContacts(id,switchType,liName) {
    if(document.getElementById(id).style.listStyleImage == "url(/includes/zptree/themes/img/plus.gif)") {
      document.getElementById(id).style.listStyleImage = "url(/includes/zptree/themes/img/minus.gif)";
    } else {
      document.getElementById(id).style.listStyleImage = "url(/includes/zptree/themes/img/plus.gif)";
    }

    var title = Trim(document.getElementById(id).innerHTML);
    var type = document.getElementById(id).id.split("_")[0];
    var id = document.getElementById(id).id.split("_")[1];

    if(type == switchType) {
      var lis = document.getElementById(liName).getElementsByTagName("li");
      var temp = "";
      for(var i=0; i < lis.length; i++) {
        temp = XMLReplace(lis[i].title);
        if((lis[i].title) && (temp == title)) {
          if (lis[i].style.display == "none") {
            lis[i].style.display = "block";
          } else {
            lis[i].style.display = "none";
          }
        }
      }
    }
  }

function areAnyChecked(checkbox_name) {
  var checkboxes = document.getElementsByName(checkbox_name);
  for(var i = 0; i < checkboxes.length; i++) {      
    if(checkboxes[i].checked == true) {
      return true;
    }
  }
  return false;
}
