////////////////////////////////////////////////////////////////////////////////////////////
// Open window for UploadDocument2 /////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
function openUploadDocument2(targeturl){
   printWindow = window.open( targeturl ,"UploadDocument2","width=685,height=387,scrollbars=no,location=no,resizable=yes,directories=no,status=1,menubar=0,toolbar=no,titlebar=0,left=20,top=20");
}

////////////////////////////////////////////////////////////////////////////////////////////
// Open window for print-version ///////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
function openPrint(targeturl){
   printWindow = window.open( targeturl ,"print","width=600,height=480,scrollbars=yes,location=no,resizable=yes,directories=no,status=1,menubar=0,toolbar=no,titlebar=1,left=50,top=50");
}

////////////////////////////////////////////////////////////////////////////////////////////
// Open window for external pages //////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
function openExternal(targeturl){
   printWindow = window.open( targeturl ,"external","width=700,height=580,scrollbars=yes,location=no,resizable=yes,directories=no,status=0,menubar=0,toolbar=no,titlebar=1,left=20,top=20");
}

////////////////////////////////////////////////////////////////////////////////////////////
// Open window for pdf-documents ///////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
function openPDF(targeturl){
   printWindow = window.open( targeturl ,"pdf","width=700,height=580,scrollbars=no,location=no,resizable=yes,directories=no,status=no,menubar=no,toolbar=no,titlebar=1,left=20,top=20");
}

////////////////////////////////////////////////////////////////////////////////////////////
// Display header information depending on browser  ////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
function reDisplayLocation(){
  if (ns4) {
    parent.header.location.reload();	
  } 
  //else if (ie4) {
  //  parent.header.location.reload();
  //}
}
////////////////////////////////////////////////////////////////////////////////////////////
// Function to correct for 2.x Mac date bug.  Call this function to   //////////////////////
//  fix a date object prior to passing it to SetCookie.               //////////////////////
//  IMPORTANT:  This function should only be called *once* for        //////////////////////
//  any given date object!                                            //////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}


////////////////////////////////////////////////////////////////////////////////////////////
// Heinle's function for retrieving a cookie.  /////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
function getCookie(name){
  var cname = name + "=";
  var dc = document.cookie;
  if (dc.length > 0) {
    begin = dc.indexOf(cname);
    if (begin != -1) {
      begin += cname.length;
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    }
  }
  return '';
}

////////////////////////////////////////////////////////////////////////////////////////////
// An adaptation of Dorcht's function for setting a cookie.  ///////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
function setCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

////////////////////////////////////////////////////////////////////////////////////////////
// An adaptation of Dorcht's function for deleting a cookie.  //////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
function delCookie (name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

////////////////////////////////////////////////////////////////////////////////////////////
// Counts the number of occurrences of one string within another string     ////////////////
// use like this:                                                           ////////////////
// test = "this, as you see, is a sentence, containing many ','s";          ////////////////
// numberOfCommas = test.count(','); //4                                    ////////////////
// numberOfSblank = test.count('s '); //2                                   ////////////////
////////////////////////////////////////////////////////////////////////////////////////////
String.prototype.count=function(s1) { 
	return (this.length - this.replace(new RegExp(s1,"g"), '').length) / s1.length;
}

////////////////////////////////////////////////////////////////////////////////////////////
// Gets the value of a query-string-variable, returning an empty string if  ////////////////
// the query-string-parameter does not exist.                               ////////////////
////////////////////////////////////////////////////////////////////////////////////////////
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  //alert('Query Variable ' + variable + ' not found');
  return ""
  }

////////////////////////////////////////////////////////////////////////////////////////////
// Sets the value of a text field in the parent window.  ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////  
function SetTxt(txt_id, txt_value) {    
    try {
       self.opener.document.getElementById(txt_id).value = txt_value
    } catch (e) {
    }
  }
  
////////////////////////////////////////////////////////////////////////////////////////////
// Gets the value of a text field in the current window.  ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////  
function GetTxt(txt_id) { 
    var ausgabe = txt_id;
    //alert("GetTxt: " + txt_id)   
    //alert("GetTxt: " + document.getElementById(txt_id).value)
    try {
        ausgabe = document.getElementById(txt_id).value
        ausgabe = escape(trim(ausgabe))
    } catch (e) {
    }
    
    //alert("GetTxt: ausgabe: " + ausgabe)
    return ausgabe;
  }  
  
////////////////////////////////////////////////////////////////////////////////////////////
// Gets the ID of a control by fbtype and rid (to be used when calling GetTxt). ////////////
////////////////////////////////////////////////////////////////////////////////////////////  
function GetID(fbt, rid, fieldname)
   {
   id = "";
   var prefix = "DlPtt__ctl" // use ptt-selection as default
   if (fbt == "rev") {
      prefix = "DlReviewer__ctl"
   }
   // Find the ID depending on parameter "fieldname"
   if (fieldname == "FName") {
      id = prefix + rid + "_TxtFName"
   }
   if (fieldname == "LName") {
      id = prefix + rid + "_TxtLName"
   }
   if (fieldname == "Email") {
      id = prefix + rid + "_TxtEmail"
   }
 
   // return ID to calling function
   return id;
}   

////////////////////////////////////////////////////////////////////////////////////////////
// Gets the fname-, lname- and email-parameters for the query-string.  /////////////////////
// These are then passed on to the clients address-book.               /////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
function GetABParams(fbt, rid) { 
    var ausgabe = "";
    var ausgabe_tmp = "";
     
    // get the first name
    try {
       ausgabe_tmp = GetTxt(GetID(fbt, rid, 'FName'))
       if (ausgabe_tmp.length > 0) {
          ausgabe = ausgabe + "&fname=" + ausgabe_tmp
       }     
    } catch (e) {
    }
    
    // get the last name
    try {
       ausgabe_tmp = GetTxt(GetID(fbt, rid, 'LName'))
       if (ausgabe_tmp.length > 0) {
          ausgabe = ausgabe + "&lname=" + ausgabe_tmp
       }     
    } catch (e) {
    }
    
    // get the email
    try {
       ausgabe_tmp = GetTxt(GetID(fbt, rid, 'Email'))
       if (ausgabe_tmp.length > 0) {
          ausgabe = ausgabe + "&email=" + ausgabe_tmp
       }     
    } catch (e) {
    }
    
    //alert("GetABParams: " + ausgabe)
    return ausgabe;
  }    
  
////////////////////////////////////////////////////////////////////////////////////////////
// Selects a dropdownlist-entry by value in the parent window.  ////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////   
function SetDdl(ddl_id, ddl_value) {    
    try {
       // Get a reference to the drop-down
       var myDropdownList = self.opener.document.getElementById(ddl_id);
   
       // Loop through all the items
       for (iLoop = 0; iLoop< myDropdownList.options.length; iLoop++)
       {    
         if (myDropdownList.options[iLoop].value == ddl_value)
         {
           // Item is found. Set its selected property, and exit the loop
           myDropdownList.options[iLoop].selected = true;
           break;
         }
       }
    } catch (e) {
    }
  }
  
////////////////////////////////////////////////////////////////////////////////////////////
// Selects a dropdownlist-entry by value in the parent window.  ////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////   
function SetDdlByID(ddl_id, ddl_value) {    
    try {
       // Get a reference to the drop-down
       var myDropdownList = document.getElementById(ddl_id);
   
       // Loop through all the items
       for (iLoop = 0; iLoop< myDropdownList.options.length; iLoop++)
       {    
         if (myDropdownList.options[iLoop].value == ddl_value)
         {
           // Item is found. Set its selected property, and exit the loop
           myDropdownList.options[iLoop].selected = true;
           break;
         }
       }
    } catch (e) {
    }
  }
  
////////////////////////////////////////////////////////////////////////////////////////////
// A general replace-function.   ///////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////   
function replace(string,suchen,ersetzen) {
   ausgabe = "" + string;
   while (ausgabe.indexOf(suchen)>-1) {
   pos= ausgabe.indexOf(suchen);
   ausgabe = "" + (ausgabe.substring(0, pos) + ersetzen +
   ausgabe.substring((pos + suchen.length), ausgabe.length));
   }
   return ausgabe;
  }
  
////////////////////////////////////////////////////////////////////////////////////////////  
// A general trim function.                                                     ////////////  
// Removes leading and trailing spaces from the passed string. Also removes     ////////////
// consecutive spaces and replaces it with one space. If something besides      ////////////
// a string is passed in (null, custom object, etc.) then return the input.     ////////////
////////////////////////////////////////////////////////////////////////////////////////////
function trim(inputString) {
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
}

////////////////////////////////////////////////////////////////////////////////////////////
// Functionality for PassAddress.htm: Gets values from the query-string and passes  ////////
// them on to the parent window. Child window is closed afterwards.                 ////////
////////////////////////////////////////////////////////////////////////////////////////////   
function passBack()
   {
   var fbt = getQueryVariable("fbt")
   var prefix = "DlPtt__ctl" // use ptt-selection as default
   if (fbt == "rev") {
      prefix = "DlReviewer__ctl"
   }
   var rid = getQueryVariable("rid")
   var salutation = unescape(getQueryVariable("salutation"))
   // var title = unescape(getQueryVariable("title"))
   var fname = unescape(getQueryVariable("fname"))
   var lname = unescape(getQueryVariable("lname"))
   var email = unescape(getQueryVariable("email")) 
   var gender = unescape("gender")
   var lge = getQueryVariable("lge")
   
   // first all textboxes
   SetTxt(prefix + rid + "_TxtSalutation", salutation);
   // SetTxt(prefix + rid + "_TxtTitle", title);
   SetTxt(prefix + rid + "_TxtFName", fname);
   SetTxt(prefix + rid + "_TxtLName", lname);
   SetTxt(prefix + rid + "_TxtEmail", email);
    
   // now dropdownlists
   SetDdl(prefix + rid + "_DdlGender", gender);
   SetDdl(prefix + rid + "_DdlLge", lge);
   
   close();
   }
   
////////////////////////////////////////////////////////////////////////////////////////////
// tmp-solution for passing values via 360g.com.                 ///////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////   
function passBackTmp()
   {
   var fbt = getQueryVariable("fbt")
   var rid = getQueryVariable("rid")
   var salutation = replace(getQueryVariable("salutation"),"~"," ")
   var title = replace(getQueryVariable("title"),"~"," ")
   var fname = replace(getQueryVariable("fname"),"~"," ")
   var lname = replace(getQueryVariable("lname"),"~"," ")
   var email = replace(getQueryVariable("email"),"~"," ") 
   var gender = getQueryVariable("gender")
   var lge = getQueryVariable("lge")
   
   location.replace("https://www.360g.com/private/PassAddress.htm?salutation=" + salutation + "&fname=" + fname + "&lname=" + lname + "&email=" + email + "&gender=" + gender + "&fbt=" + fbt + "&rid=" + rid + "" );
   }   
////////////////////////////////////////////////////////////////////////////////////////////
// Function for check or uncheck checkboxes. commonly used in selfmade ddls  ///////////////
// Runs only on elements INPUT type CHECKBOX                                 ///////////////
// Args:                                                                     ///////////////
//       1: Substring from ID-Name of element                                ///////////////
//       2: true for checked | nothing for unchecked                         /////////////// 
////////////////////////////////////////////////////////////////////////////////////////////   
function Sckb(n,val) {
   var e = document.getElementsByTagName("input");
   for (i=0;i<e.length;i++) {
       if ((e[i].type=='checkbox') && ( e[i].name.indexOf(n) != -1)) {
            e[i].checked=val;} 
   }
}
////////////////////////////////////////////////////////////////////////////////////////////
// Function for clearing / resetting a filter in filter-section              ///////////////
// Applies to: custom multi-select-ddls                                      ///////////////
// Args:                                                                     ///////////////
//       1: Substring from ID-Name of element (checkboxes)                   /////////////// 
//       2: ID of the tablecell in which we want to write ' *' - message     /////////////// 
////////////////////////////////////////////////////////////////////////////////////////////   
function ClearFilter(n, TextID) {
   try {
      var e = document.getElementsByTagName("input");
      for (i=0;i<e.length;i++) {
          if ((e[i].type=='checkbox') && ( e[i].name.indexOf(n) != -1)) {
               e[i].checked=false;
          } 
      }
      // and write ' *' to TextID
      document.getElementById(TextID).value = ' *';
   }  catch (e) {
   }
}
////////////////////////////////////////////////////////////////////////////////////////////
// Function for clearing / resetting a filter in filter-section              ///////////////
// Applies to: textbox                                                       ///////////////
// Args:                                                                     ///////////////
//       1: ID of the textbox to reset                                       /////////////// 
////////////////////////////////////////////////////////////////////////////////////////////   
function ClearFilterTextbox(TextID) {
   try {
      var id_prefix = "ctl00_cphMain_";
      document.getElementById(id_prefix + TextID).value = '';
   }  catch (e) {
   }
}
////////////////////////////////////////////////////////////////////////////////////////////
// Function for clearing / resetting a filter in filter-section              ///////////////
// Applies to: dropdownlist                                                  ///////////////
// Args:                                                                     ///////////////
//       1: ID of the dropdownlist to reset (i.e. select the first entry)    /////////////// 
////////////////////////////////////////////////////////////////////////////////////////////   
function ClearFilterDdl(TextID) {
   try {
      var id_prefix = "ctl00_cphMain_";
      SetDdlByID(id_prefix + TextID, -1);
   }  catch (e) {
   }
}
////////////////////////////////////////////////////////////////////////////////////////////
// Function for setting customer specific default values in a filter in      ///////////////
// filter-section                                                            ///////////////
// Applies to: custom multi-select-ddls  (for now only cpy85 stat-filter)    ///////////////
// Args:                                                                     ///////////////
//       1: Substring from ID-Name of element (checkboxes)                   /////////////// 
//       2: ID of the tablecell in which we want to write ' *' - message     /////////////// 
////////////////////////////////////////////////////////////////////////////////////////////   
function SetFilterDefault(n, TextID) {
   try {
      var e = document.getElementsByTagName("input");
      for (i=0;i<e.length;i++) {
          if ((e[i].type=='checkbox') && ( e[i].name.indexOf(n) != -1)) {
             if (e[i].id.indexOf('_ctl13') > -1) {
                e[i].checked=false;
             }
             else if (e[i].id.indexOf('_ctl14') > -1) {
                e[i].checked=false;
             }
             else if (e[i].id.indexOf('_ctl15') > -1) {
                e[i].checked=false;
             }
             else if (e[i].id.indexOf('_ctl16') > -1) {
                e[i].checked=false;
             }
             else {
                e[i].checked=true;
             }              
          } 
      }
   }  catch (e) {
   }
}
////////////////////////////////////////////////////////////////////////////////////////////
// Function to uncheck Check-All-Checkbox if one of the checkboxes is un-    ///////////////
// checked. commonly used in selfmade ddls                                   ///////////////
// Runs only on elements INPUT type CHECKBOX                                 ///////////////
// Args:                                                                     ///////////////
//       1: ID of the check-all-checkbox we want to uncheck                  /////////////// 
////////////////////////////////////////////////////////////////////////////////////////////   
function Uncheck(ElementID, Checkbox) {
   if (Checkbox.checked == false) {
      var ckbAll = document.getElementById(ElementID);
      if (ckbAll.checked == true) {
         ckbAll.checked = false;
      }
   }
}
////////////////////////////////////////////////////////////////////////////////////
// Function to show or hide div`s like help and instruction boxes    ///////////////
// Needs the 2 CssClasses block and none                             ///////////////
// Args:                                                             ///////////////
//       1: Substring from ID-Name of element                        ///////////////
////////////////////////////////////////////////////////////////////////////////////   
function Toggle(ElementID) {
   var container = document.getElementById(ElementID);
   if (container.className == 'block') {
      container.className = 'none';
      if (ElementID == 'ctl00_pnlInstructionBox') {
         document.getElementById('ctl00_hfInstState').value = 'Hide';
      } 
      else if (ElementID == 'ctl00_cphMain_pnlInsertBox') {
         document.getElementById('ctl00_cphMain_hfInsertState').value = 'Hide';
      }
      else if (ElementID == 'ctl00_cphMain_pnlFilterBox') {
         document.getElementById('ctl00_cphMain_hfFilterState').value = 'Hide';
      }
      else if (ElementID == 'ctl00_cphMain_pnlDmnDescBox') {
         document.getElementById('ctl00_cphMain_hfDmnDescState').value = 'Hide';
      }      
   }
   else if (container.className == 'none') {
      container.className = 'block';
      if (ElementID == 'ctl00_pnlInstructionBox') {
         document.getElementById('ctl00_hfInstState').value = 'Show';
      }
      else if (ElementID == 'ctl00_cphMain_pnlInsertBox') {
         document.getElementById('ctl00_cphMain_hfInsertState').value = 'Show';
      }
      else if (ElementID == 'ctl00_cphMain_pnlFilterBox') {
         document.getElementById('ctl00_cphMain_hfFilterState').value = 'Show';
      }
      else if (ElementID == 'ctl00_cphMain_pnlDmnDescBox') {
         document.getElementById('ctl00_cphMain_hfDmnDescState').value = 'Show';
      }
   }
}
////////////////////////////////////////////////////////////////////////////////////
// Function to show or hide div`s like help and instruction boxes    ///////////////
// NEW VERSION WHICH ALSO SETS NUMBER OF SELECTED RECORDS IN TextID  ///////////////
// Needs the 2 CssClasses block and none                             ///////////////
// Args:                                                             ///////////////
//       1: ID of the container / table we want to toggle            ///////////////
//       2: ID of the tablecell in which we want to write 'x items   ///////////////
//          selected' - message                                      ///////////////
//       3: ID-Stub of the checkboxes which may be selected or not   ///////////////
//       4: Flag to decide whether to close ElementID if it is open  ///////////////
//          but never to open it                                     ///////////////
////////////////////////////////////////////////////////////////////////////////////   
function Toggle2(ElementID, TextID, CkbID, ForceClose) {
   try {
      var container = document.getElementById(ElementID);
      if (container.className == 'block') {
         container.className = 'none';
         if (TextID.length > 0) {
            // determine how many rows there are in total and how many are selected
            var n_tot = 0;
            var n_sel = 0;
            var e = document.getElementsByTagName("input");
            for (i=0;i<e.length;i++) {
               if ((e[i].type == 'checkbox') && ( e[i].name.indexOf(CkbID) != -1)) {
                  n_tot = n_tot + 1;
                  if (e[i].checked == true) {
                     n_sel = n_sel + 1;
                  }
               } 
            }
            // determine the correct text depending on the numbers we determined above
            var text = '';
            if ((n_sel == 0) || (n_sel == n_tot)) {
               text = ' *';
            }
            else if (n_sel == 1) {
               text = ' ' + document.getElementById('ctl00$cphMain$hfItemSelected').value;
            }
            else if (n_tot > 1) {
               text = document.getElementById('ctl00$cphMain$hfItemsSelected').value;
               text = ' ' + replace(text,"~count~",n_sel);
            }
            // and write this text to TextID
            document.getElementById(TextID).value = text;
         }
      }
      else if ((container.className == 'none') && (ForceClose != true )) {
         container.className = 'block';
      }    
   }  catch (e) {
   }
}
////////////////////////////////////////////////////////////////////////////////////
// Function to show or hide datalist-detail-section-divs             ///////////////
// Needs the 2 CssClasses block and none                             ///////////////
// Args:                                                             ///////////////
//       1: Substring from ID-Name of element                        ///////////////
////////////////////////////////////////////////////////////////////////////////////   
function ToggleDetail(e) {
   var ElementID = e.id;
   var container = document.getElementById(ElementID);
   var end_pos = ElementID.indexOf("ctl",10) + 3; // We start searching at 10 because this way we should always hit the second ctl (example: ctl00_cphMain_DlPtt_ctl01_tdFoldInOut)
   var id_prefix = ElementID.substring(0, end_pos);
   //alert (id_prefix);
   var end_pos_rownum = ElementID.indexOf("_",21); // We start searching at 21 because this way we should always hit the fourth _ (example: ctl00_cphMain_DlPtt_ctl01_tdFoldInOut)
   var rownum = ElementID.substring(end_pos, end_pos_rownum);
   var hfRowsFoldOut = document.getElementById("ctl00_cphMain_hfRowsFoldOut");
   //alert (rownum); 
   
   if (container.className == 'HideDetail') {
      container.className = 'ShowDetail';
      if (ElementID == id_prefix + rownum + '_tdFoldInOut') {
         //document.getElementById(id_prefix + rownum + '_tdFoldInOut').rowspan = 2;
         //document.getElementById(id_prefix + rownum + '_tdButtons').rowspan = 2;
         if (document.getElementById(id_prefix + rownum + '_trDetail').className.substring(0,8) == 'ViewItem') {
            document.getElementById(id_prefix + rownum + '_trDetail').className = 'ViewItemDetailFoldOut'; /* alt: ShowRow */
            document.getElementById(id_prefix + rownum + '_trMain').className = 'ViewItemMainFoldOut';
            document.getElementById(id_prefix + rownum + '_tblDetail').className = 'xxxx';
         }
         else if (document.getElementById(id_prefix + rownum + '_trDetail').className.substring(0,11) == 'AltViewItem') {
            document.getElementById(id_prefix + rownum + '_trDetail').className = 'AltViewItemDetailFoldOut';
            document.getElementById(id_prefix + rownum + '_trMain').className = 'AltViewItemMainFoldOut';
            document.getElementById(id_prefix + rownum + '_tblDetail').className = 'xxxx';
         }
         else if (document.getElementById(id_prefix + rownum + '_trDetail').className.substring(0,8) == 'EditItem') {
            document.getElementById(id_prefix + rownum + '_trDetail').className = 'EditItemDetailFoldOut';
            document.getElementById(id_prefix + rownum + '_trMain').className = 'EditItemMainFoldOut';
            document.getElementById(id_prefix + rownum + '_tblDetail').className = 'xxxx';
         }
         else if (document.getElementById(id_prefix + rownum + '_trDetail').className.substring(0,10) == 'FooterItem') {
            document.getElementById(id_prefix + rownum + '_trDetail').className = 'FooterItemDetailFoldOut';
            document.getElementById(id_prefix + rownum + '_trMain').className = 'FooterItemMainFoldOut';
            document.getElementById(id_prefix + rownum + '_tblDetail').className = 'xxxx';
         }
      }
      hfRowsFoldOut.value = hfRowsFoldOut.value + "$" + rownum + "$"     
   }
   else if (container.className == 'ShowDetail') {
      container.className = 'HideDetail';
      if (ElementID == id_prefix + rownum + '_tdFoldInOut') {
         //document.getElementById(id_prefix + rownum + '_tdFoldInOut').rowspan = 1;
         //document.getElementById(id_prefix + rownum + '_tdButtons').rowspan = 1;
         if (document.getElementById(id_prefix + rownum + '_trDetail').className.substring(0,8) == 'ViewItem') {
            document.getElementById(id_prefix + rownum + '_trDetail').className = 'ViewItemDetailFoldIn'; /* alt: HideRow */
            document.getElementById(id_prefix + rownum + '_trMain').className = 'ViewItemMainFoldIn';
            document.getElementById(id_prefix + rownum + '_tblDetail').className = 'none';
         }
         else if (document.getElementById(id_prefix + rownum + '_trDetail').className.substring(0,11) == 'AltViewItem') {
            document.getElementById(id_prefix + rownum + '_trDetail').className = 'AltViewItemDetailFoldIn';
            document.getElementById(id_prefix + rownum + '_trMain').className = 'AltViewItemMainFoldIn';
            document.getElementById(id_prefix + rownum + '_tblDetail').className = 'none';
         }
         else if (document.getElementById(id_prefix + rownum + '_trDetail').className.substring(0,8) == 'EditItem') {
            document.getElementById(id_prefix + rownum + '_trDetail').className = 'EditItemDetailFoldIn';
            document.getElementById(id_prefix + rownum + '_trMain').className = 'EditItemMainFoldIn';
            document.getElementById(id_prefix + rownum + '_tblDetail').className = 'none';
         }
         else if (document.getElementById(id_prefix + rownum + '_trDetail').className.substring(0,10) == 'FooterItem') {
            document.getElementById(id_prefix + rownum + '_trDetail').className = 'FooterItemDetailFoldIn';
            document.getElementById(id_prefix + rownum + '_trMain').className = 'FooterItemMainFoldIn';
            document.getElementById(id_prefix + rownum + '_tblDetail').className = 'none';
         }
      }
      hfRowsFoldOut.value = replace(hfRowsFoldOut.value,"$" + rownum + "$","")  
   }
   //alert(hfRowsFoldOut.value);
}
////////////////////////////////////////////////////////////////////////////////////////////
// Function to toggle all detail-foldouts. Usually triggered from within     ///////////////
// the header-template                                                       ///////////////
// Runs only on elements ??????? type ?????????                             ///////////////
// Args:                                                                     ///////////////
//       1: Substring from ID-Name of element                                ///////////////
//       2: true for checked | nothing for unchecked                         /////////////// 
// Args:                                                                     ///////////////
//       1: ID of the check-all-checkbox we want to uncheck                  /////////////// 
////////////////////////////////////////////////////////////////////////////////////////////   
function ToggleAllDetails(ElementID, e) {
   var container = document.getElementById(e.id);
   var table = document.getElementById('ctl00_cphMain_DlPtt');
   // set image of Header-cell
   if (container.className == 'HideDetail') {
      container.className = 'ShowDetail';
   }
   else if (container.className == 'ShowDetail') {
      container.className = 'HideDetail';
   }
   // toggle all content cells
   var tds = table.getElementsByTagName('td');
   for (i=0;i<tds.length;i++) {
      if ((tds[i].id != null) && (tds[i].id != undefined)) {   
         if ((tds[i].id.indexOf("ctl00_cphMain_DlPtt_ctl") != -1) && (tds[i].id.indexOf("_tdFoldInOut") != -1) && (tds[i].id.indexOf("ctl00_cphMain_DlPtt_ctl00") == -1)) {
            if (container.className != tds[i].className) { ToggleDetail(tds[i]); }
         }
      }
   }
}
////////////////////////////////////////////////////////////////////////////////////////////
// Function to fold-out all detail-foldouts according to rownumbers in       ///////////////
// hfRowsFoldOut. Triggered after the relevant datalist has been created.    ///////////////
// Runs only on elements ??????? type ?????????                              ///////////////
// Args:                                                                     ///////////////
//       1: Substring from ID-Name of element                                ///////////////
//       2: true for checked | nothing for unchecked                         /////////////// 
// Args:                                                                     ///////////////
//       1: ID of the check-all-checkbox we want to uncheck                  /////////////// 
////////////////////////////////////////////////////////////////////////////////////////////   
function InitDetailFoldOuts() {
   var table = document.getElementById('ctl00_cphMain_DlPtt');
   var hfRowsFoldOut = document.getElementById("ctl00_cphMain_hfRowsFoldOut");
   
   var tds = table.getElementsByTagName('td');
   for (i=0;i<tds.length;i++) {
      if ((tds[i].id != null) && (tds[i].id != undefined)) {   
         if ((tds[i].id.indexOf("ctl00_cphMain_DlPtt_ctl") != -1) && (tds[i].id.indexOf("_tdFoldInOut") != -1) && (tds[i].id.indexOf("ctl00_cphMain_DlPtt_ctl00") == -1)) {
            var end_pos = tds[i].id.indexOf("ctl",10) + 3; // We start searching at 10 because this way we should always hit the second ctl (example: ctl00_cphMain_DlPtt_ctl01_tdFoldInOut)
            var end_pos_rownum = tds[i].id.indexOf("_",21); // We start searching at 21 because this way we should always hit the fourth _ (example: ctl00_cphMain_DlPtt_ctl01_tdFoldInOut)
            var rownum = tds[i].id.substring(end_pos, end_pos_rownum);
            if (hfRowsFoldOut.value.indexOf("$" + rownum + "$") != -1) { ToggleDetail(tds[i]); }
         }
      }
   }
}
////////////////////////////////////////////////////////////////////////////////////
// Function to set text-boxes and dropdownlist-entries according to  ///////////////
// an entry being selected in a AJAX Autocompleter doing employee-   ///////////////
// lookups.                                                          ///////////////
// Args:                                                             ///////////////
//       Both args do not have to be supplied!!                      ///////////////
////////////////////////////////////////////////////////////////////////////////////   
function SetEmpValues(source, eventArgs) {
   try {
      var content = eventArgs.get_value() + "|";
      var value_to_set = "";
      // Get the prefix of all controls, depending on the current context
      var id_prefix = source._id;
      // We start searching at 21 because this way we should always hit the fourth _ (example: ctl00_cphMain_DlPtt_ctl03_acLName)
      var end_pos = id_prefix.indexOf("_",23) + 1;
      // OR .. at 21 if we are handling with a nested list-control ion order to hit the sixth _ (example: ctl00_cphMain_DlPtt_ctl03_DlCon_ctl01_acConLName)
      if (id_prefix.count('_') >= 6) {
         end_pos = id_prefix.indexOf("_",34) + 1;
      }
      id_prefix = id_prefix.substring(0, end_pos);
      
      // Now try to set individual fields one by one, just ignoring errors if they occur (example return string: |Herr|Fritz|Walter|f.walter@stefan-dirk.com|100|DE)
      // title
      try {
         end_pos = content.indexOf("|",0);
         value_to_set = content.substring(0,end_pos);
         content = content.substring(end_pos + 1);
         document.getElementById(id_prefix + "TxtTitle").value = value_to_set;
      }  catch (e2) {
      }      
      // salutation
      try {
         end_pos = content.indexOf("|",0);
         value_to_set = content.substring(0,end_pos);         
         content = content.substring(end_pos + 1);        
         document.getElementById(id_prefix + "TxtSalutation").value = value_to_set;
      }  catch (e2) {
      }
      // first_name
      try {
         end_pos = content.indexOf("|",0);
         value_to_set = content.substring(0,end_pos);
         content = content.substring(end_pos + 1);
         document.getElementById(id_prefix + "TxtFName").value = value_to_set;
      }  catch (e2) {
      }
      // last_name
      try {
         end_pos = content.indexOf("|",0);
         value_to_set = content.substring(0,end_pos);
         content = content.substring(end_pos + 1);
         document.getElementById(id_prefix + "TxtLName").value = value_to_set;
      }  catch (e2) {
      }
      // email
      try {
         end_pos = content.indexOf("|",0);
         value_to_set = content.substring(0,end_pos);
         content = content.substring(end_pos + 1);
         document.getElementById(id_prefix + "TxtEmail").value = value_to_set;
      }  catch (e2) {
      }
      // gender and gender 2 (if gender is being displayed as salutation)
      try {
         end_pos = content.indexOf("|",0);
         value_to_set = content.substring(0,end_pos);
         content = content.substring(end_pos + 1);
         SetDdlByID(id_prefix + "DdlGender", value_to_set); // SetDdl uses the ID containing underscores...
         SetDdlByID(id_prefix + "DdlSalutationGender", value_to_set); // SetDdl uses the ID containing underscores...
      }  catch (e2) {
      }
      // language
      try {
         end_pos = content.indexOf("|",0);
         value_to_set = content.substring(0,end_pos);
         SetDdlByID(id_prefix + "DdlLge", value_to_set); // SetDdl uses the ID containing underscores...
      }  catch (e2) {
      }             
   }  catch (e) {
   }
}
////////////////////////////////////////////////////////////////////////////////////
// Function to update the Enddate-calendar-control if the StartDate- ///////////////
// calendar is being updated (EditParticipant.aspx-only).            ///////////////
// Args:                                                             ///////////////
//                                                                   ///////////////
////////////////////////////////////////////////////////////////////////////////////   
function updateEndDateEditParticipant(sender) {
   //alert('triggered');
   // Get duration of the review
   var IntReview = -1;
   IntReview = document.getElementById('ctl00_cphMain_hfIntReview').value * 1;
   if (IntReview > 0) {
      // Move end-date of review synchronously
      ctl00_cphMain_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview));
   }
}
////////////////////////////////////////////////////////////////////////////////////
// Function to update the Enddate-calendar-control if the StartDate- ///////////////
// calendar is being updated (NameParticipant.aspx-only).            ///////////////
// Args:                                                             ///////////////
//                                                                   ///////////////
////////////////////////////////////////////////////////////////////////////////////   
function updateEndDateNameParticipant(sender) {
   // Use name of start-date-control to determine name of end-date-control
   var enddateControlName = replace(sender.clientID,"Startdate","Enddate");
   var IntReview = document.getElementById('ctl00_cphMain_hfIntReview').value * 1;
   if (IntReview > 0) {
      // As we don't seem to be able to assign the calendar-control to a variable: use  this stupid switch-statement
      switch (enddateControlName) {
         case "ctl00_cphMain_DlPtt_ctl01_bdpEnddate": ctl00_cphMain_DlPtt_ctl01_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview)); break;
         case "ctl00_cphMain_DlPtt_ctl02_bdpEnddate": ctl00_cphMain_DlPtt_ctl02_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview)); break;
         case "ctl00_cphMain_DlPtt_ctl03_bdpEnddate": ctl00_cphMain_DlPtt_ctl03_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview)); break;
         case "ctl00_cphMain_DlPtt_ctl04_bdpEnddate": ctl00_cphMain_DlPtt_ctl04_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview)); break;
         case "ctl00_cphMain_DlPtt_ctl05_bdpEnddate": ctl00_cphMain_DlPtt_ctl05_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview)); break; 
         case "ctl00_cphMain_DlPtt_ctl06_bdpEnddate": ctl00_cphMain_DlPtt_ctl06_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview)); break; 
         case "ctl00_cphMain_DlPtt_ctl07_bdpEnddate": ctl00_cphMain_DlPtt_ctl07_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview)); break; 
         case "ctl00_cphMain_DlPtt_ctl08_bdpEnddate": ctl00_cphMain_DlPtt_ctl08_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview)); break; 
         case "ctl00_cphMain_DlPtt_ctl09_bdpEnddate": ctl00_cphMain_DlPtt_ctl09_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview)); break; 
         case "ctl00_cphMain_DlPtt_ctl10_bdpEnddate": ctl00_cphMain_DlPtt_ctl10_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview)); break; 
         case "ctl00_cphMain_DlPtt_ctl11_bdpEnddate": ctl00_cphMain_DlPtt_ctl11_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview)); break; 
         case "ctl00_cphMain_DlPtt_ctl12_bdpEnddate": ctl00_cphMain_DlPtt_ctl12_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview)); break; 
         case "ctl00_cphMain_DlPtt_ctl13_bdpEnddate": ctl00_cphMain_DlPtt_ctl13_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview)); break; 
         case "ctl00_cphMain_DlPtt_ctl14_bdpEnddate": ctl00_cphMain_DlPtt_ctl14_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview)); break; 
         case "ctl00_cphMain_DlPtt_ctl15_bdpEnddate": ctl00_cphMain_DlPtt_ctl15_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview)); break; 
         case "ctl00_cphMain_DlPtt_ctl16_bdpEnddate": ctl00_cphMain_DlPtt_ctl16_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview)); break; 
         case "ctl00_cphMain_DlPtt_ctl17_bdpEnddate": ctl00_cphMain_DlPtt_ctl17_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview)); break; 
         case "ctl00_cphMain_DlPtt_ctl18_bdpEnddate": ctl00_cphMain_DlPtt_ctl18_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview)); break; 
         case "ctl00_cphMain_DlPtt_ctl19_bdpEnddate": ctl00_cphMain_DlPtt_ctl19_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview)); break; 
         case "ctl00_cphMain_DlPtt_ctl20_bdpEnddate": ctl00_cphMain_DlPtt_ctl20_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview)); break; 
         case "ctl00_cphMain_DlPtt_ctl21_bdpEnddate": ctl00_cphMain_DlPtt_ctl21_bdpEnddate.setSelectedDate(sender.getSelectedDate().addDays(IntReview)); break; 
      }
   }
}
////////////////////////////////////////////////////////////////////////////////////
// Testprocedure to identify client-side-ID of controls.             ///////////////
// Args:                                                             ///////////////
//                                                                   ///////////////
//////////////////////////////////////////////////////////////////////////////////// 
function IdentifyMe(sender) {
   var myID = sender.clientID;
   alert(myID);
}
////////////////////////////////////////////////////////////////////////////////////
// Function to new window                                            ///////////////
// Steve: bitte noch kommentieren......                              ///////////////
// Args:                                                             ///////////////
//                                                                   ///////////////
////////////////////////////////////////////////////////////////////////////////////   
function PopupWindow(strUrl, Width, Height) {
   var frame = window.open(strUrl,'Feedback2', 'width=' + Width + ',height=' + Height + ',resizeable=1,menubar=0,toolbar=0,scrollbars=1');
   frame.focus;
}
////////////////////////////////////////////////////////////////////////////////////
// Function to show or hide elemnts by value                         ///////////////
// Args:                                                             ///////////////
//         1. actuel value                                           ///////////////
//         2. given value (for showing the elemnt)                   ///////////////
//         3. element name                                           ///////////////
////////////////////////////////////////////////////////////////////////////////////
function Sebv(ist,soll,e) {
   el = document.getElementById(e);
   if ( ist != soll) { 
      el.style.display = 'none';
   } else {
      el.style.display = 'inline';
   }
}
////////////////////////////////////////////////////////////////////////////////////
// Function to enable or disable elements by id                      ///////////////
// Args:                                                             ///////////////
//         1. element name                                           ///////////////
//         2. e|d                                                    ///////////////
////////////////////////////////////////////////////////////////////////////////////
function Tel(e,val) {
   el = document.getElementById(e);
   if ( val == 'e') {
      el.disabled = false;
   }
   if ( val == 'd') {
      el.disabled = true;
   }
}
////////////////////////////////////////////////////////////////////////////////////
// Function to show tooltip only if value is not empty or *          ///////////////
// Args:                                                             ///////////////
//         1. value                                                  ///////////////
////////////////////////////////////////////////////////////////////////////////////
function TTW(val) {
   if ((val=='')||(val=='*')) {
     // do nothing
   } else {
     Tip(val);
   }
}   
////////////////////////////////////////////////////////////////////////////////////
// Function to check length of input in textarea                     ///////////////
// Args:                                                             ///////////////
////////////////////////////////////////////////////////////////////////////////////      
function CheckLen(target, maxlength) {

   StrLen=target.value.length;
 
   if (StrLen==1&&target.value.substring(0,1)==" ") {
      target.value=""; 
      StrLen=0;
   }
   if (StrLen>maxlength) {
      target.value=target.value.substring(0,maxlength);
      CharsLeft=0;
   } else {
      CharsLeft=maxlength-StrLen;
   }
   //document.zaehlformular.Anzahl.value=CharsLeft;
}
////////////////////////////////////////////////////////////////////////////////////
//Some functions for prompt-on-unsaved-changes-functionality.        ///////////////
// Args:                                                             ///////////////
////////////////////////////////////////////////////////////////////////////////////
function assignInitialValuesForMonitorChanges() {
   if ( window.monitorChangesIDs != undefined ) {
      for (var i = 0; i < monitorChangesIDs.length; i++) {
         var elem = document.getElementById(monitorChangesIDs[i]);
         if (elem) {
            if (elem.type == 'checkbox' || elem.type == 'radio') {
               monitorChangesValues[i] = elem.checked;
            } else { 
               monitorChangesValues[i] = elem.value;
            }
         }
      }
   }
}
function confirmClose() {
   if (!needToConfirm) return;
   el = document.getElementById('ctl00_lblSavePromptA');
   for (var i = 0; i < monitorChangesValues.length; i++) {
      var elem = document.getElementById(monitorChangesIDs[i]);
      if (elem) { 
         if (((elem.type == 'checkbox' || elem.type == 'radio') && elem.checked != monitorChangesValues[i]) || (elem.type != 'checkbox' && elem.type != 'radio' && elem.value != monitorChangesValues[i])) { 
            needToConfirm = false; 
            setTimeout('resetFlag()', 750);
            var retMessage = "****************************************************************************************\n\n";
            retMessage += el.firstChild.data;
            retMessage += "\n\n****************************************************************************************";
            return retMessage; 
         }
      }
   }
}
function confirmCloseLB(e) {
   if (!needToConfirm) return true;
   // Save the name of the button / linkbutton that was clicked to a hidden field to later mimic this element's postback in doManualConfirmPostback
   hfCallingElement = document.getElementById('ctl00_hfCallingElement');
   hfCallingElement.value = e.id;  
   for (var i = 0; i < monitorChangesValues.length; i++) {
      var elem = document.getElementById(monitorChangesIDs[i]);
      if (elem) { 
         if (((elem.type == 'checkbox' || elem.type == 'radio') && elem.checked != monitorChangesValues[i]) || (elem.type != 'checkbox' && elem.type != 'radio' && elem.value != monitorChangesValues[i])) { 
            needToConfirm = false; 
            setTimeout('resetFlag()', 750);
            tb_show("", "#TB_inline?height=200&width=400&inlineId=hiddenSavePrompt&modal=true", true);
            return false;
         }
      }
   }
   return true;
}
function resetFlag() { 
   needToConfirm = true;
}
function doManualConfirmPostback() {
   needToConfirm = false;
   hfCallingElement = document.getElementById('ctl00_hfCallingElement');
   __doPostBack(replace(hfCallingElement.value,'_','$'),'');
}
////////////////////////////////////////////////////////////////////////////////////
// Function to clear text-boxes and dropdownlist-entries for the     ///////////////
// current-consultant-row.                                           ///////////////
// Args:                                                             ///////////////
//       Both args do not have to be supplied!!                      ///////////////
////////////////////////////////////////////////////////////////////////////////////   
function ClearConRecord(e) {
   try {
      // Get the prefix of all controls, depending on the current context
      var id_prefix = e.id;
      // We start searching at 21 because this way we should always hit the fourth _ (example: ctl00_cphMain_DlPtt_ctl03_acLName)
      var end_pos = id_prefix.indexOf("_",23) + 1;
      // OR .. at 21 if we are handling with a nested list-control ion order to hit the sixth _ (example: ctl00_cphMain_DlPtt_ctl03_DlCon_ctl01_acConLName)
      if (id_prefix.count('_') >= 6) {
         end_pos = id_prefix.indexOf("_",34) + 1;
      }
      id_prefix = id_prefix.substring(0, end_pos);
      
      // Now try to set individual fields one by one, just ignoring errors if they occur
      // salutation
      try {
         document.getElementById(id_prefix + "TxtSalutation").value = "";
      }  catch (e2) {
      }
      try {
         document.getElementById(id_prefix + "TxtFName").value = "";
      }  catch (e2) {
      } 
      try {
         document.getElementById(id_prefix + "TxtLName").value = "";
      }  catch (e2) {
      }
      try {
         document.getElementById(id_prefix + "TxtEmail").value = "";
      }  catch (e2) {
      }
      try {
         SetDdlByID(id_prefix + "DdlGender", -1);
      }  catch (e2) {
      }
      try {
         SetDdlByID(id_prefix + "DdlLge", "");
      }  catch (e2) {
      }
   } catch (e) {
   }
   return false;
}
