var alphaChars = "abcdefghijklmnopqrstuvwxyz";
var digitChars = "0123456789";
var asciiChars = alphaChars + digitChars + "!\"#$%&'()*+,-./:;<=>?@[\]^_`{}~";

var ie = document.all?1:0;
var ns4 = document.layers?1:0;

function popup(wURL,wTitle,wFeature)
{
        mywin=window.open(wURL,wTitle,wFeature);
        window.mywin.document.close();
}


// frm = document.aform;
hilightColor = "#CCFFFF";
clearColor = "#FFFFFF";

function showData(id, show)
{
         document.all[id].style.display = show;
}

function toggleData(id)
{
   if (document.all[id].style.display == "none") {
         document.all[id].style.display = '';
   } else {
         document.all[id].style.display = 'none';
   }
}

// Hilight checked boxes, clear unchecked

function parentof(e)
{
      return (ie)? e.parentElement(e):e.parentNode(e);
}

// assumes that frm exists and contains one, two, three
function PAINTROW(v)
{
   if (v == 1) {
       hL(frm.one);
   } else {
       dL(frm.one);
   }
   if (v == 2) {
       hL(frm.two);
   } else {
       dL(frm.two);
   }
   if (v == 3) {
       hL(frm.three);
   } else {
       dL(frm.three);
   }
}
function CR() {
         for (var i=0;i<frm.elements.length;i++)
         {
                  var e = frm.elements[i];
                  if (e.type == 'radio')
                      CCA(e);
         }
}

function RPAINT() {
         for (var i=0;i<frm.elements.length;i++)
         {
                  var e = frm.elements[i];
                  if (e.type == 'radio')
                      RRA(e);
         }
}

function RRA(RADIO) {
         if (RADIO.checked)
             colorPaint(RADIO);
         else
             colorClear(RADIO);
}

function colorPaint(E) {
    var radioColor = E.value;
         if (ie)
         {
                  while (E.tagName!="TD")
                  {E=E.parentElement;}
         }
         else
         {
                  while (E.tagName!="TD")
                  {E=E.parentNode;}
         }
         E.bgColor = radioColor;
}

function colorClear(E) {
         if (ie)
         {
                  while (E.tagName!="TD")
                  {E=E.parentElement;}
         }
         else
         {
                  while (E.tagName!="TD")
                  {E=E.parentNode;}
         }
         E.bgColor = clearColor;
}

function CA(){
         for (var i=0;i<frm.elements.length;i++)
         {
                  var e = frm.elements[i];
                  if (e.type=='checkbox')
                      CCA(e);
         }
}
function CCA(CB){
         if (CB.checked)
             hL(CB);
         else
             dL(CB);
}

function hL(E){
         if (ie)
         {
                  while (E.tagName!="TR")
                  {E=E.parentElement;}
         }
         else
         {
                  while (E.tagName!="TR")
                  {E=E.parentNode;}
         }
         E.className = "H";
         E.bgColor = hilightColor;
}
function dL(E){
         if (ie)
         {
                  while (E.tagName!="TR")
                  {E=E.parentElement;}
         }
         else
         {
                  while (E.tagName!="TR")
                  {E=E.parentNode;}
         }
         E.className = "";
         E.bgColor = clearColor;
}
function isASCII(str){
         var v_len = str.length;
         var i;
         for (i = 0; i < v_len; i++)
         {
                  if (asciiChars.indexOf(str.charAt(i)) == -1)
                  return false;
         }
         return true;
}
function ValidateEmail(str){
         var resultStr = str.replace(/ /gi, "");
         var atIndex = resultStr.indexOf("@");
         var dotIndex = resultStr.lastIndexOf(".");
         if( resultStr == "" || !isASCII(resultStr) || dotIndex == -1)
              return "";
         if ( resultStr.lastIndexOf("@") != atIndex || resultStr.charAt(atIndex+1) == ".")
              return "";
         if ( atIndex <= 0 || dotIndex < atIndex || dotIndex >= resultStr.length-1)
              return "";
         return resultStr;
}
function ValidateDomain(str){
         var resultStr = str.replace(/ /gi, "");
         var atIndex = resultStr.indexOf("@");
         var dotIndex = resultStr.lastIndexOf(".");
         if( resultStr=="" || !isASCII(resultStr) || dotIndex == -1)
             return "";
         if ( atIndex > 0 || resultStr.charAt(atIndex+1) == "." || dotIndex >= resultStr.length-1 )
              return "";
         return resultStr.replace(/@/i, "");
}
function isEmail(str) {
         var pass = 0;
         if (window.RegExp) {
                  var tempStr = "a";
                  var tempReg = new RegExp(tempStr);
                  if (tempReg.test(tempStr)) pass = 1;
         }
         if (!pass)
              return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
         var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
         var r2 = new RegExp("^[a-zA-Z0-9\\.\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\}\\~]*[a-zA-Z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\}\\~]\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
         return (!r1.test(str) && r2.test(str));
}
function clearText()
{
         var i;
         var e;
         for (i =0; i < document.forms[0].elements.length; i++) {
              e = document.forms[0].elements[i];
              if (e.type == "text" || e.type == "password")
                  e.value = "";
         }
}

function hilightCheck()
{
         var i;
         var e;
         for (i =0; i < document.forms[0].elements.length; i++) {
              e = document.forms[0].elements[i];
              if (e.type == "checkbox" && e.name.substring(0,2) == "id")
                  e.checked = true;
         }
}
function clearCheck()
{
         var i;
         var e;
         for (i =0; i < document.forms[0].elements.length; i++) {
              e = document.forms[0].elements[i];
              if (e.type == "checkbox" && e.name.substring(0,2) == "id")
                  e.checked = false;
         }
}

function allIDsChecked()
{
         var i;
         var e;
         for (i =0; i < document.forms[0].elements.length; i++) {
              e = document.forms[0].elements[i];
              if ((e.type == "checkbox") && e.name.substring(0,2) == "id" && (e.checked == false))
                  return false;
         }
         return true;
}

function allAllowed(e)
{
         if (e.checked == false) {
             document.forms[0].all_allowed.checked = false;
         } else {
             document.forms[0].all_allowed.checked = allIDsChecked();
         }
}

// Title: Tigra Calendar
// URL: http://www.softcomplex.com/products/tigra_calendar/
// Version: 3.2 (European date format)
// Date: 10/14/2002 (mm/dd/yyyy)
// Feedback: feedback@softcomplex.com (specify product title in the subject)
// Note: Permission given to use this script in ANY kind of applications if
//    header lines are left unchanged.
// Note: Script consists of two files: calendar?.js and calendar.html
// About us: Our company provides offshore IT consulting services.
//    Contact us at sales@softcomplex.com if you have any programming task you
//    want to be handled by professionals. Our typical hourly rate is $20.

// if two digit year input dates after this year considered 20 century.
var NUM_CENTYEAR = 30;
// is time input control required by default
var BUL_TIMECOMPONENT = false;
// are year scrolling buttons required by default
var BUL_YEARSCROLL = true;

var calendars = [];
var RE_NUM = /^\-?\d+$/;

function calendar1(obj_target) {

        // assing methods
        this.gen_date = cal_gen_date1;
        this.gen_time = cal_gen_time1;
        this.gen_tsmp = cal_gen_tsmp1;
        this.prs_date = cal_prs_date1;
        this.prs_time = cal_prs_time1;
        this.prs_tsmp = cal_prs_tsmp1;
        this.popup    = cal_popup1;

        // validate input parameters
        if (!obj_target)
                return cal_error("Error calling the calendar: no target control specified");
        if (obj_target.value == null)
                return cal_error("Error calling the calendar: parameter specified is not valid tardet control");
        this.target = obj_target;
        this.time_comp = BUL_TIMECOMPONENT;
        this.year_scroll = BUL_YEARSCROLL;

        // register in global collections
        this.id = calendars.length;
        calendars[this.id] = this;
}

function cal_popup1 (str_datetime) {
        this.dt_current = this.prs_tsmp(str_datetime ? str_datetime : this.target.value);
        if (!this.dt_current) return;

        var obj_calwindow = window.open(
                '../lib.js/calendar.html?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id,
                'Calendar', 'width=200,height='+(this.time_comp ? 215 : 190)+
                ',status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes'
        );
        obj_calwindow.opener = window;
        obj_calwindow.focus();
}

// timestamp generating function
function cal_gen_tsmp1 (dt_datetime) {
        return(this.gen_date(dt_datetime) + ' ' + this.gen_time(dt_datetime));
}

// date generating function
function cal_gen_date1 (dt_datetime) {
        return (
                (dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate() + "-"
                + (dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) + "-"
                + dt_datetime.getFullYear()
        );
}
// time generating function
function cal_gen_time1 (dt_datetime) {
        return (
                (dt_datetime.getHours() < 10 ? '0' : '') + dt_datetime.getHours() + ":"
                + (dt_datetime.getMinutes() < 10 ? '0' : '') + (dt_datetime.getMinutes()) + ":"
                + (dt_datetime.getSeconds() < 10 ? '0' : '') + (dt_datetime.getSeconds())
        );
}

// timestamp parsing function
function cal_prs_tsmp1 (str_datetime) {
        // if no parameter specified return current timestamp
        if (!str_datetime)
                return (new Date());

        // if positive integer treat as milliseconds from epoch
        if (RE_NUM.exec(str_datetime))
                return new Date(str_datetime);

        // else treat as date in string format
        var arr_datetime = str_datetime.split(' ');
        return this.prs_time(arr_datetime[1], this.prs_date(arr_datetime[0]));
}

// date parsing function
function cal_prs_date1 (str_date) {

        var arr_date = str_date.split('-');

        if (arr_date.length != 3) return cal_error ("Ngay thang nam sai qui cach: '" + str_date + "'.\nQui cach: dd-mm-yyyy.");
        if (!arr_date[0]) return cal_error ("Ngay thang nam sai qui cach: '" + str_date + "'.\nKhong co ngay trong thang.");
        if (!RE_NUM.exec(arr_date[0])) return cal_error ("S&#7889; ngày trong tháng không h&#7907;p l&#7879;: '" + arr_date[0] + "'.\nGiá tr&#7883; cho phép là các s&#7889; nguyên d&#432;&#417;ng.");
        if (!arr_date[1]) return cal_error ("Ngay thang nam sai qui cach: '" + str_date + "'.\nKhong co thang.");
        if (!RE_NUM.exec(arr_date[1])) return cal_error ("Thang khong hop le: '" + arr_date[1] + "'.\nGia tri cho phep la cac so nguyen duong.");
        if (!arr_date[2]) return cal_error ("Ngay thang nam sai qui cach: '" + str_date + "'.\nKhong co nam.");
        if (!RE_NUM.exec(arr_date[2])) return cal_error ("Nam khong hop le: '" + arr_date[2] + "'.\nGia tri cho phep là cac s&#7889; nguyen duong.");

        var dt_date = new Date();
        dt_date.setDate(1);

        if (arr_date[1] < 1 || arr_date[1] > 12) return cal_error ("Thang khong hop le: '" + arr_date[1] + "'.\nDai cho phep la 01-12.");
        dt_date.setMonth(arr_date[1]-1);

        if (arr_date[2] < 100) arr_date[2] = Number(arr_date[2]) + (arr_date[2] < NUM_CENTYEAR ? 2000 : 1900);
        dt_date.setFullYear(arr_date[2]);

        var dt_numdays = new Date(arr_date[2], arr_date[1], 0);
        dt_date.setDate(arr_date[0]);
        if (dt_date.getMonth() != (arr_date[1]-1)) return cal_error ("So ngay cua thang khong hop le: '" + arr_date[0] + "'.\nDai cho phep la 01-"+dt_numdays.getDate()+".");

        return (dt_date)
}

// time parsing function
function cal_prs_time1 (str_time, dt_date) {

        if (!dt_date) return null;
        var arr_time = String(str_time ? str_time : '').split(':');

        if (!arr_time[0]) dt_date.setHours(0);
        else if (RE_NUM.exec(arr_time[0]))
                if (arr_time[0] < 24) dt_date.setHours(arr_time[0]);
                else return cal_error ("Gio khong hop le: '" + arr_time[0] + "'.\nDai cho phep la 00-23.");
        else return cal_error ("Gio khong hop le: '" + arr_time[0] + "'.\nGia tri cho phep la so nguyen duong.");

        if (!arr_time[1]) dt_date.setMinutes(0);
        else if (RE_NUM.exec(arr_time[1]))
                if (arr_time[1] < 60) dt_date.setMinutes(arr_time[1]);
                else return cal_error ("Phut khong hop le: '" + arr_time[1] + "'.\nDai cho phep la 00-59.");
        else return cal_error ("Phut khong hop le: '" + arr_time[1] + "'.\nGia tri cho phep la so nguyen duong.");

        if (!arr_time[2]) dt_date.setSeconds(0);
        else if (RE_NUM.exec(arr_time[2]))
                if (arr_time[2] < 60) dt_date.setSeconds(arr_time[2]);
                else return cal_error ("Giay khong hop le: '" + arr_time[2] + "'.\nDai cho phep la 00-59.");
        else return cal_error ("Giay khong hop le: '" + arr_time[2] + "'.\nGia tri cho phep la so nguyen duong.");

        dt_date.setMilliseconds(0);
        return dt_date;
}

function cal_error (str_message) {
        alert (str_message);
        return null;
}

//
//  Cookie Functions - Second Helping  (21-Jan-96)
//  Written by:  Bill Dortch, hIdaho Design <bdortch@netw.com>
//  The following functions are released to the public domain.
//
//  The Second Helping version of the cookie functions dispenses with
//  my encode and decode functions, in favor of JavaScript's new built-in
//  escape and unescape functions, which do more complete encoding, and
//  which are probably much faster.
//
//  The new version also extends the SetCookie function, though in
//  a backward-compatible manner, so if you used the First Helping of
//  cookie functions as they were written, you will not need to change any
//  code, unless you want to take advantage of the new capabilities.
//
//  The following changes were made to SetCookie:
//
//  1.  The expires parameter is now optional - that is, you can omit
//      it instead of passing it null to expire the cookie at the end
//      of the current session.
//
//  2.  An optional path parameter has been added.
//
//  3.  An optional domain parameter has been added.
//
//  4.  An optional secure parameter has been added.
//
//  For information on the significance of these parameters, and
//  and on cookies in general, please refer to the official cookie
//  spec, at:
//
//      http://www.netscape.com/newsref/std/cookie_spec.html
//
//
// "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 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 theexpiration 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) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" :
("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}

//  Function to delete a cookie.(Sets expiration date to current date/time)
//    name - String object containing the cookie name
//
function DeleteCookie (name) {
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);  // This cookie is history
  var cval = GetCookie (name);
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

// SET UP ARGUMENTS FOR FUncTION CALLS
//
var caseSensitive = true;
var notCaseSensitive = false;
var wholeWords = true;
var anySubstring = false;


// SEARch FOR A TERM IN A TARGET STRING
//
// search(targetString,searchTerm,caseSensitive,wordOrSubstring)
//
// where caseSenstive is a boolean value and wordOrSubstring is a boolean
// value and true means whole words, false means substrings
//
function search(target,term,caseSens,wordOnly) {

  var ind = 0;
  var next = 0;

  if (!caseSens) {
    term = term.toLowerCase();
    target = target.toLowerCase();
  }

  while ((ind = target.indexOf(term,next)) >= 0) {
    if (wordOnly) {
      var before = ind - 1;
      var after = ind + term.length;
      if (!(space(target.charAt(before)) && space(target.charAt(after)))) {
        next = ind + term.length;
        continue;
      }
    }
    return true;
  }

  return false;

}

// SEARch FOR A TERM IN A TARGET STRING AND REPLACE IT
//
// replace(targetString,oldTerm,newTerm,caseSensitive,wordOrSubstring)
//
// where caseSenstive is a boolean value and wordOrSubstring is a boolean
// value and true means whole words, false means substrings
//
function replace(target,oldTerm,newTerm,caseSens,wordOnly) {

  var work = target;
  var ind = 0;
  var next = 0;

  if (!caseSens) {
    oldTerm = oldTerm.toLowerCase();
    work = target.toLowerCase();
  }

  while ((ind = work.indexOf(oldTerm,next)) >= 0) {
    if (wordOnly) {
      var before = ind - 1;
      var after = ind + oldTerm.length;
      if (!(space(work.charAt(before)) && space(work.charAt(after)))) {
        next = ind + oldTerm.length;
        continue;
      }
    }
    target = target.substring(0,ind) + newTerm +
    target.substring(ind+oldTerm.length,target.length);
    work = work.substring(0,ind) + newTerm +
    work.substring(ind+oldTerm.length,work.length);
    next = ind + newTerm.length;
    if (next >= work.length) { break; }
  }

  return target;

}

// chECK IF A chARACTER IS A WORD BREAK AND RETURN A BOOLEAN VALUE
//
function space(check) {

  var space = " .,/<>?!`';:@#$%^&*()=-|[]{}" + '"' + "\\\n\t";

  for (var i = 0; i < space.length; i++)
    if (check == space.charAt(i)) { return true; }

  if (check == "") { return true; }
  if (check == null) { return true; }

  return false;

}
function mypopUp(strURL, windowname, intHeight, intWidth, strScrollbar){

var strOptions = "toolbar=no";
strOptions += ",local=no";
strOptions += ",menubar=no";
strOptions += ",status=no";
strOptions += ",scrollbars=" + strScrollbar;
strOptions += ",resizable=yes";
strOptions += ",height=" + intHeight;
strOptions += ",width=" + intWidth;
//StrUrl="'" + strUrl + "'"
//alert(strOptions);
mywindow=window.open(strURL, windowname, strOptions);
}