<!--
var prev_fld = '';

function chkChrs(frm,fld,txt,searchfor,how){
 string = document.forms[frm].elements[fld].value;
 if(how){
   proof = searchfor.exec(string);
   stopit = (proof != string);
 }
 else{
   stopit = searchfor.test(string);
 }
 if(stopit && (fld == prev_fld || prev_fld == '')){
     alert(txt);
     prev_fld = fld;
     document.forms[frm].elements[fld].focus();
     return
 }
 else prev_fld = '';
}

function reg_exp(frm,fld,txt,searchfor){
  string = document.forms[frm].elements[fld].value;
  if(string != '' && string != searchfor.exec(string)){
    alert(txt);
    return false;
  }
}

function chkISODate(frm,fld,txt){
 string = document.forms[frm].elements[fld].value;
 if(string != ""){
   searchfor = /^\d\d\d\d-\d\d-\d\d$/;
   result = searchfor.test(string);
   if(result == false){
     alert(txt);
     document.forms[frm].elements[fld].focus();
     return
   }
   if(chkISODate.arguments.length == 4){
     x = "";
     i = -1;
     while(x != fld) {
          i++;
          x = document.forms[frm].elements[i].name;
     }
     i--;
     if(document.forms[frm].elements[i].value > document.forms[frm].elements[fld].value){
       txt = chkISODate.arguments[3];
       alert(txt);
       document.forms[frm].elements[i].focus();
       return
     }
   }
 }
}

function chkForm(frm) {
 for (var i=1; i<chkForm.arguments.length; i++){
   fld=chkForm.arguments[i];
   i++;
   txt=chkForm.arguments[i];
   if(document.forms[frm].elements[fld].value == ""){
     alert(txt);
     document.forms[frm].elements[fld].focus();
     return false;
   }
 }
}

function show(sessid) {
  x = document.frm.contact.value;
  if(x > 0){
    path=self.location.href;
    path = path.replace(/filemanager\/filemanager\.php.+/,'');
    path = path.replace(/todo\/todo\.php.+/,'');
    path = path.replace(/projects\/projects\.php.+/,'');
    path = path.replace(/notes\/notes\.php.+/,'');
// add 'replaces' for further modules here

    y = path + 'misc/print.php?module=contacts&contact_ID=' + x + sessid;
    window.open(y);
  }
}

// Marker and pointer for list view
var marked = new Array;
var sellist = "";
var url    = /\/\w+.php/  ;
var result = self.location.href.match(url);
if (result != null) {
    if (result[0] == "/contacts.php") {
        var cookname = "sel_cust";
    }
    else if (result[0] == "/projects.php") {
        var cookname = "sel_proj";
    }
    else if (result[0] == "/todo.php") {
        var cookname = "sel_todo";
    }
    else if (result[0] == "/notes.php") {
        var cookname = "sel_notes";
    }
    else if (result[0] == "/notes.php") {
        var cookname = "sel_notes";
    }
    if (GetCookie(cookname)) {
        var cook_selected = new Array;
        cook_selected = GetCookie(cookname).split(',');
        for(i=0;i<cook_selected.length;i++){
          marked[cook_selected[i]] = true;
        }

    } else {
        var expdate = new Date ();
        expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); // 24 hrs from now
        SetCookie (cookname, "", expdate);
    }
}

function hili(tr,i,bg){
        if(typeof(marked[i]) == 'undefined' || !marked[i]){
                        tr.style.backgroundColor = bg;
        }
}

function marker(tr,i,color,mark_color){
        if(typeof(marked[i]) == 'undefined' || !marked[i]){
                marked[i] = true;
                tr.style.backgroundColor = mark_color;
                showlast(tr,i);
        }
        else{
                marked[i] = false;
                tr.style.backgroundColor = color;
        }
        review_sel();
}

function markit(tr,i,mark_color){
    marked[i] = true;
    tr.style.backgroundColor = mark_color;
}

function unmarkit(tr,i,mark_color){
    marked[i] = false;
    tr.style.backgroundColor = mark_color;
}

function showlast (tr,i) {
    document.exprtfrm.lastitem.value = i;
    var children = tr.getElementsByTagName("td")
    var lasttext = "";
    for (var i = 0; i < children.length; i++) {
            var child = children[i];
            if (i > 0 && i < 4) lasttext = lasttext + child.innerHTML + "|";
    }
    lasttext = DelHTML(lasttext);
    lasttext = lasttext.replace(/&nbsp;/g,"");
    lasttext = lasttext.replace(/\[No Value\]/g,"");
    lasttext = lasttext.replace(/\|\|/g,"");
    lasttext = lasttext.replace(/\|/g," ");
    document.exprtfrm.lasttext.value = lasttext;
}

function DelHTML(Word) {
         a = Word.indexOf("<");
         b = Word.indexOf(">");
         len = Word.length;
         c = Word.substring(0, a);
         if(b == -1) b = a;
         d = Word.substring((b + 1), len);
         Word = c + d;
         tagCheck = Word.indexOf("<");
         if(tagCheck != -1) Word = DelHTML(Word);
         return Word;
}

function review_sel(action) {
        var item_count = 0;
        var sellist = "";
        for(i=0;i<marked.length;i++){
//                 if(typeof(marked[i]) == 'undefined' || !marked[i]){
//                 }
//                 else{
               if (marked[i]) {
                    item_count = item_count + 1;
                    if (sellist == "") {
                        sellist = i;
                    } else {
                        sellist = sellist + ',' + i;
                    }
                }
        }
        var children = document.getElementsByTagName("tr")
        var srch = /ID=\d+/
        var items_selected = new Array;
        if (item_count == 1) items_selected[0] = sellist;
        else items_selected = sellist.split(",");          
        for (var i = 0; i < children.length; i++) {
                var child = children[i];
                var lineID = child.innerHTML.match(srch);
                if (lineID == null) continue;
                var ID = lineID[0].split("=");
                var uid = ID[1];
                if (action == "Des-All") {
                    DeleteCookie(cookname);
                    unmarkit(child,uid,'#E3E3E3');
                    item_count = 0;
                    sellist = "";
                    marked = Array();
                    continue;
                }
                if (action == "All-This" && (typeof(marked[uid]) == 'undefined' || !marked[uid])) {
//                    alert (marked[ID] + " " + ID);
//                    child.style.backgroundColor = "E6DE90";
                    markit(child,uid,'#E6DE90');
                    item_count = item_count + 1;
                    if (sellist == "") {
                        sellist = uid;
                    } else {
                        sellist = sellist + ',' + uid;
                    }
                    continue;
                }
                for (var j = 0; j < items_selected.length; j++) {
                    if (items_selected[j] == uid) {
//                        alert ("debug !!! " + items_selected[j] + " " + ID[1]);
//                        child.style.backgroundColor = "E6DE90";
                          markit(child,uid,'#E6DE90');
                    }
                }
        }
        SetCookie (cookname, sellist);
        if(typeof document.exprtfrm != "undefined") {        
            document.exprtfrm.selitems.value = sellist;
        }
        if(typeof document.navitems != "undefined") {                
            document.navitems.selitems.value = sellist;
        }        
        if(typeof document.profitems != "undefined") {
            document.profitems.selitems.value = sellist;
        }
        if(typeof document.frm_count != "undefined") {        
           document.frm_count.itemcount.value = item_count;
        }
}

function contains(a, e) {
        for(j=0;j<a.length;j++)if(a[j]==e)return true;
        return false;
}

// "Internal" function to return the decoded value of a cookie
//
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
//
//  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!  See example at the end of this document.
//
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);
}
//
//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
//
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}
//
//  Function to create or update a cookie.
//    name - String object containing the cookie name.
//    value - String object containing the cookie value.  May contain
//      any valid string characters.
//    [expires] - Date object containing the expiration data of the cookie.  If
//      omitted or null, expires the cookie at the end of the current session.
//    [path] - String object indicating the path for which the cookie is valid.
//      If omitted or null, uses the path of the calling document.
//    [domain] - String object indicating the domain for which the cookie is
//      valid.  If omitted or null, uses the domain of the calling document.
//    [secure] - Boolean (true/false) value indicating whether cookie transmission
//      requires a secure channel (HTTPS).
//
//  The first two parameters are required.  The others, if supplied, must
//  be passed in the order listed above.  To omit an unused optional field,
//  use null as a place holder.  For example, to call SetCookie using name,
//  value and path, you would code:
//
//      SetCookie ("myCookieName", "myCookieValue", null, "/");
//
//  Note that trailing omitted parameters do not require a placeholder.
//
//  To set a secure cookie for path "/myPath", that expires after the
//  current session, you might code:
//
//      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
//
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" : "");
}

//  Function to delete a cookie. (Sets expiration date to start of epoch)
//    name -   String object containing the cookie name
//    path -   String object containing the path of the cookie to delete.  This MUST
//             be the same as the path used to create the cookie, or null/omitted if
//             no path was specified when creating the cookie.
//    domain - String object containing the domain of the cookie to delete.  This MUST
//             be the same as the domain used to create the cookie, or null/omitted if
//             no domain was specified when creating the cookie.
//
function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

//
//  Examples - Unremark if you want to see how this code works
/*
var expdate = new Date ();
FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); // 24 hrs from now
SetCookie ("ccpath", "http://www.hidaho.com/colorcenter/", expdate);
SetCookie ("ccname", "hIdaho Design ColorCenter", expdate);
SetCookie ("tempvar", "This is a temporary cookie.");
SetCookie ("ubiquitous", "This cookie will work anywhere in this domain",null,"/");
SetCookie ("paranoid", "This cookie requires secure communications",expdate,"/",null,true);
SetCookie ("goner", "This cookie must die!");
document.write (document.cookie + "<br>");
DeleteCookie ("goner");
document.write (document.cookie + "<br>");
document.write ("ccpath = " + GetCookie("ccpath") + "<br>");
document.write ("ccname = " + GetCookie("ccname") + "<br>");
document.write ("tempvar = " + GetCookie("tempvar") + "<br>");
*/
//-->
