var p_formats = 'global';
p_formats = "DD/MM/YYYY";
var keynum = 0;

document.onkeydown = Helpdocs;

function Helpdocs(e){
  if(window.event.keyCode == 17 ){
   keynum = 17;
  }
  if((window.event.keyCode == 72 ) && ( keynum == '17' )){
    helppage = window.open("","helppage");
    helppage.location = "http://www.collect.org/Help/contents.html";
  }
}

function set_picklist(item, oprlist){
  var length = oprlist.options.length;
  if (item){
    for( var i=1; i <= length-1; i++){
      if ( oprlist.options[i].value == item ){
        oprlist.options[i].selected = true;
      }
    }
  }
}


function setCompanyInfo(){
/* Use these two for an image name */
//var name = "<img src='clogo.gif'>"
//var ename = document.createElement(name);

/* Use the below two for a text name */
var name = "Collection World Group. "
var ename = document.createTextNode(name);

/* Fill variables ending in lbl with Labels and use the other variables for your data */
var addresslbl= "Address:"
var address = "Collection WOrld Group"
var address2 = "Locked Bag 2002"
var address3 = "South Brisbane BC, QLD 4101"
var emaillbl = "Email:"
var email = "MOconnell@collectionworldgroup.com"
var phonelbl = "Phone:"
var phone = "07 3343 4242"
var faxlbl = "Fax:"
var fax = "07 3343 7429"

if(!(document.getElementById('companyinfo'))) return false;
var cotemp2 = document.getElementById('companyinfo');
cotemp2.appendChild(ename);
var cotemp = document.getElementById('cotable').getElementsByTagName("TBODY")[0];

var row1= document.createElement("TR");
var td1 = document.createElement("<td class=rlabel style='vertical-align:top'>");
var td2 = document.createElement("<td class=data>");
td1.appendChild(document.createTextNode(addresslbl));
td2.appendChild(document.createTextNode(address));
row1.appendChild(td1);
row1.appendChild(td2);

var row2= document.createElement("TR");
td1 = document.createElement("<td class=rlabel>");
td2 = document.createElement("<td class=data>");
td1.appendChild(document.createTextNode(""));
td2.appendChild(document.createTextNode(address2));
row2.appendChild(td1);
row2.appendChild(td2);

var row3= document.createElement("TR");
td1 = document.createElement("<td class=rlabel>");
td2 = document.createElement("<td class=data>");
td1.appendChild(document.createTextNode(""));
td2.appendChild(document.createTextNode(address3));
row3.appendChild(td1);
row3.appendChild(td2);

var row4= document.createElement("TR");
var td1 = document.createElement("<td class=rlabel>");
var td2 = document.createElement("<td class=data>");
var a1 = document.createElement("<a href='mailto:"+email+"'>");
td1.appendChild(document.createTextNode(emaillbl));
a1.appendChild(document.createTextNode(email));
td2.appendChild(a1);
row4.appendChild(td1);
row4.appendChild(td2);

var row5= document.createElement("TR");
td1 = document.createElement("<td class=rlabel>");
td2 = document.createElement("<td class=data>");
td1.appendChild(document.createTextNode(phonelbl));
td2.appendChild(document.createTextNode(phone));
row5.appendChild(td1);
row5.appendChild(td2);

var row6= document.createElement("TR");
td1 = document.createElement("<td class=rlabel>");
td2 = document.createElement("<td class=data>");
td1.appendChild(document.createTextNode(faxlbl));
td2.appendChild(document.createTextNode(fax));
row6.appendChild(td1);
row6.appendChild(td2);

cotemp.appendChild(row1);
cotemp.appendChild(row2);
cotemp.appendChild(row3);
cotemp.appendChild(row4);
cotemp.appendChild(row5);
cotemp.appendChild(row6);
}

function checkkeys(notes){
  if(window.event.keyCode == 17 ){
    keynum = 17;
  }
  if((window.event.keyCode == 68 ) && ( keynum == '17' )){
    var d = new Date();
    var hours = d.getHours();
    var mins = d.getMinutes();
    var secs = d.getSeconds();
    notes.value = notes.value + '@d<10>'+' '+hours+':'+mins+':'+secs+' @op.id< : ';
  }  
}


function WorkingMsg(){
var url="working.html"; //URL of popup page
var height = 100; // Height of popup
var width = 450; // Width of popup
var att='width=' + width + ',height=' + height;
WorkingMessagePopup=window.open(URL,"wmp",att);
}

function KillWorkingMsg(){
var url=""; // Blank for thankyou page.
var height = 100; // Height of popup
var width = 450; // Width of popup
var att='width=' + width + ',height=' + height;
WorkingMessagePopup=window.open(url,"wmp",att);
WorkingMessagePopup.close();
}


function Mod(a, b) {
//  var decimal = a-Math.floor(a/b)*b
//  return decimal.toFixed(2)
  return Math.round((a-Math.floor(a/b)*b)*100)
}

function Div(a, b) { return Math.floor(a/b) }

function DateAdd(startDate, numDays, numMonths, numYears){
  var returnDate = new Date(startDate.getTime());
  var yearsToAdd = numYears;
  var month = returnDate.getMonth()-numMonths;
  if (month > 11){
   yearsToAdd = Math.floor((month+1)/12);
   month -= 12*yearsToAdd;
   yearsToAdd += numYears;
  }
  returnDate.setMonth(month);
  returnDate.setFullYear(returnDate.getFullYear()+yearsToAdd);
  returnDate.setTime(returnDate.getTime()+60000*60*24*numDays);
  return returnDate;
}

function setdates(){
  var d = new Date()
  var month = (d.getMonth() + 1)
  if ( month < 10 ){  
    month = ("0"+month)
  }
  var month2 = d.getDay()
  if ( month2 < 10 ){
    month2 = ("0"+month2)
  }
  var vardate = (month+"/"+month2+"/"+(d.getFullYear()))
  tabselection.vartodate.value = vardate;
  tabselection.varfromdate.value = vardate;
}

function validatetext(field) {
var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/\%$#@!<>?~^+:;'-_(*) "
var ok = "yes";
var temp;
for (var i=0; i<field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") ok = "no";
}
if (ok == "no") {
alert("Invalid entry!  Only characters and numbers are accepted!");
field.focus();
field.select();
   }
}

function textLimit(field, maxlen) {
  if (field.value.length > maxlen) {
     field.value = field.value.substring(0, maxlen);
     alert('Your input has been truncated! Maximum size 3000 characters');
  }
}


function validatenumbers(field) {
var valid = "0123456789"
var ok = "yes";
var temp;
for (var i=0; i<field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") ok = "no";
}
if (ok == "no") {
alert("Invalid entry!  Only numbers are accepted!");
field.focus();
field.select();
   }
}

function checkrequired(which) {
var pass=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];
if (tempobj.name.substring(0,8)=="required") {
if (((tempobj.type=="text"||tempobj.type=="textarea")&&
tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
tempobj.selectedIndex==0)) {
pass=false;
break;
         }
      }
   }
}
if (!pass) {
shortFieldName=tempobj.name.substring(8,30).toUpperCase();
alert("Please make sure the "+shortFieldName+" field was properly completed.");
return false;
}
else
return true;
}



var weekend = [0,6];
var weekendColor = "#e0e0e0";
var fontface = "Verdana";
var fontsize = 2;

var gNow = new Date();
var ggWinCal;
isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;

Calendar.Months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];

// Non-Leap year Month days..
Calendar.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Leap year Month days..
Calendar.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

function Calendar(p_item, p_WinCal, p_month, p_year, p_format) {
    p_format = p_formats;
    
    if ((p_month == null) && (p_year == null))  return;

    if (p_WinCal == null)
        this.gWinCal = ggWinCal;
    else
        this.gWinCal = p_WinCal;
    
    if (p_month == null) {
        this.gMonthName = null;
        this.gMonth = null;
        this.gYearly = true;
    } else {
        this.gMonthName = Calendar.get_month(p_month);
        this.gMonth = new Number(p_month);
        this.gYearly = false;
    }

    this.gYear = p_year;
    this.gFormat = p_formats;
    this.gBGColor = "white";
    this.gFGColor = "black";
    this.gTextColor = "black";
    this.gHeaderColor = "black";
    this.gReturnItem = p_item;
}

Calendar.get_month = Calendar_get_month;
Calendar.get_daysofmonth = Calendar_get_daysofmonth;
Calendar.calc_month_year = Calendar_calc_month_year;
Calendar.print = Calendar_print;

function Calendar_get_month(monthNo) {
    return Calendar.Months[monthNo];
}

function Calendar_get_daysofmonth(monthNo, p_year) {
    /* 
    Check for leap year ..
    1.Years evenly divisible by four are normally leap years, except for... 
    2.Years also evenly divisible by 100 are not leap years, except for... 
    3.Years also evenly divisible by 400 are leap years. 
    */
    if ((p_year % 4) == 0) {
        if ((p_year % 100) == 0 && (p_year % 400) != 0)
            return Calendar.DOMonth[monthNo];
    
        return Calendar.lDOMonth[monthNo];
    } else
        return Calendar.DOMonth[monthNo];
}

function Calendar_calc_month_year(p_Month, p_Year, incr) {
    /* 
    Will return an 1-D array with 1st element being the calculated month 
    and second being the calculated year 
    after applying the month increment/decrement as specified by 'incr' parameter.
    'incr' will normally have 1/-1 to navigate thru the months.
    */
    var ret_arr = new Array();
    
    if (incr == -1) {
        // B A C K W A R D
        if (p_Month == 0) {
            ret_arr[0] = 11;
            ret_arr[1] = parseInt(p_Year) - 1;
        }
        else {
            ret_arr[0] = parseInt(p_Month) - 1;
            ret_arr[1] = parseInt(p_Year);
        }
    } else if (incr == 1) {
        // F O R W A R D
        if (p_Month == 11) {
            ret_arr[0] = 0;
            ret_arr[1] = parseInt(p_Year) + 1;
        }
        else {
            ret_arr[0] = parseInt(p_Month) + 1;
            ret_arr[1] = parseInt(p_Year);
        }
    }
    
    return ret_arr;
}

function Calendar_print() {
    ggWinCal.print();
}

function Calendar_calc_month_year(p_Month, p_Year, incr) {
    /* 
    Will return an 1-D array with 1st element being the calculated month 
    and second being the calculated year 
    after applying the month increment/decrement as specified by 'incr' parameter.
    'incr' will normally have 1/-1 to navigate thru the months.
    */
    var ret_arr = new Array();
    
    if (incr == -1) {
        // B A C K W A R D
        if (p_Month == 0) {
            ret_arr[0] = 11;
            ret_arr[1] = parseInt(p_Year) - 1;
        }
        else {
            ret_arr[0] = parseInt(p_Month) - 1;
            ret_arr[1] = parseInt(p_Year);
        }
    } else if (incr == 1) {
        // F O R W A R D
        if (p_Month == 11) {
            ret_arr[0] = 0;
            ret_arr[1] = parseInt(p_Year) + 1;
        }
        else {
            ret_arr[0] = parseInt(p_Month) + 1;
            ret_arr[1] = parseInt(p_Year);
        }
    }
    
    return ret_arr;
}

// This is for compatibility with Navigator 3, we have to create and discard one object before the prototype object exists.
new Calendar();

Calendar.prototype.getMonthlyCalendarCode = function() {
    var vCode = "";
    var vHeader_Code = "";
    var vData_Code = "";
    
    // Begin Table Drawing code here..
    vCode = vCode + "<TABLE BORDER=1 BGCOLOR=\"" + this.gBGColor + "\">";
    
    vHeader_Code = this.cal_header();
    vData_Code = this.cal_data();
    vCode = vCode + vHeader_Code + vData_Code;
    
    vCode = vCode + "</TABLE>";
    
    return vCode;
}

Calendar.prototype.show = function() {
    var vCode = "";
    
    this.gWinCal.document.open();

    // Setup the page...
    this.wwrite("<html>");
    this.wwrite("<head><title>Calendar</title>");
    this.wwrite("</head>");

    this.wwrite("<body " + 
        "link=\"" + this.gLinkColor + "\" " + 
        "vlink=\"" + this.gLinkColor + "\" " +
        "alink=\"" + this.gLinkColor + "\" " +
        "text=\"" + this.gTextColor + "\">");
    this.wwriteA("<FONT FACE='" + fontface + "' SIZE=2><B>");
    this.wwriteA(this.gMonthName + " " + this.gYear);
    this.wwriteA("</B><BR>");

    // Show navigation buttons
    var prevMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, -1);
    var prevMM = prevMMYYYY[0];
    var prevYYYY = prevMMYYYY[1];

    var nextMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, 1);
    var nextMM = nextMMYYYY[0];
    var nextYYYY = nextMMYYYY[1];
    
    this.wwrite("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0'><TR><TD ALIGN=center>");
    this.wwrite("[<A HREF=\"" +
        "javascript:window.opener.Build(" + 
        "'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)-1) + "', '" + this.gFormat + "'" +
        ");" +
        "\"><<<\/A>]</TD><TD ALIGN=center>");
    this.wwrite("[<A HREF=\"" +
        "javascript:window.opener.Build(" + 
        "'" + this.gReturnItem + "', '" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "'" +
        ");" +
        "\"><<\/A>]</TD><TD ALIGN=center>");
    this.wwrite("[<A HREF=\"javascript:window.print();\">Print</A>]</TD><TD ALIGN=center>");
    this.wwrite("[<A HREF=\"" +
        "javascript:window.opener.Build(" + 
        "'" + this.gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "'" +
        ");" +
        "\">><\/A>]</TD><TD ALIGN=center>");
    this.wwrite("[<A HREF=\"" +
        "javascript:window.opener.Build(" + 
        "'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)+1) + "', '" + this.gFormat + "'" +
        ");" +
        "\">>><\/A>]</TD></TR></TABLE><BR>");

    // Get the complete calendar code for the month..
    vCode = this.getMonthlyCalendarCode();
    this.wwrite(vCode);

    this.wwrite("</font></body></html>");
    this.gWinCal.document.close();
}

Calendar.prototype.showY = function() {
    var vCode = "";
    var i;
    var vr, vc, vx, vy;     // Row, Column, X-coord, Y-coord
    var vxf = 285;          // X-Factor
    var vyf = 200;          // Y-Factor
    var vxm = 10;           // X-margin
    var vym;                // Y-margin
    if (isIE)   vym = 75;
    else if (isNav) vym = 25;
    
    this.gWinCal.document.open();

    this.wwrite("<html>");
    this.wwrite("<head><title>Calendar</title>");
    this.wwrite("<style type='text/css'>\n<!--");
    for (i=0; i<12; i++) {
        vc = i % 3;
        if (i>=0 && i<= 2)  vr = 0;
        if (i>=3 && i<= 5)  vr = 1;
        if (i>=6 && i<= 8)  vr = 2;
        if (i>=9 && i<= 11) vr = 3;
        
        vx = parseInt(vxf * vc) + vxm;
        vy = parseInt(vyf * vr) + vym;

        this.wwrite(".lclass" + i + " {position:absolute;top:" + vy + ";left:" + vx + ";}");
    }
    this.wwrite("-->\n</style>");
    this.wwrite("</head>");

    this.wwrite("<body " + 
        "link=\"" + this.gLinkColor + "\" " + 
        "vlink=\"" + this.gLinkColor + "\" " +
        "alink=\"" + this.gLinkColor + "\" " +
        "text=\"" + this.gTextColor + "\">");
    this.wwrite("<FONT FACE='" + fontface + "' SIZE=2><B>");
    this.wwrite("Year : " + this.gYear);
    this.wwrite("</B><BR>");

    // Show navigation buttons
    var prevYYYY = parseInt(this.gYear) - 1;
    var nextYYYY = parseInt(this.gYear) + 1;
    
    this.wwrite("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0'><TR><TD ALIGN=center>");
    this.wwrite("[<A HREF=\"" +
        "javascript:window.opener.Build(" + 
        "'" + this.gReturnItem + "', null, '" + prevYYYY + "', '" + this.gFormat + "'" +
        ");" +
        "\" alt='Prev Year'><<<\/A>]</TD><TD ALIGN=center>");
    this.wwrite("[<A HREF=\"javascript:window.print();\">Print</A>]</TD><TD ALIGN=center>");
    this.wwrite("[<A HREF=\"" +
        "javascript:window.opener.Build(" + 
        "'" + this.gReturnItem + "', null, '" + nextYYYY + "', '" + this.gFormat + "'" +
        ");" +
        "\">>><\/A>]</TD></TR></TABLE><BR>");

    // Get the complete calendar code for each month..
    var j;
    for (i=11; i>=0; i--) {
        if (isIE)
            this.wwrite("<DIV ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");
        else if (isNav)
            this.wwrite("<LAYER ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");

        this.gMonth = i;
        this.gMonthName = Calendar.get_month(this.gMonth);
        vCode = this.getMonthlyCalendarCode();
        this.wwrite(this.gMonthName + "/" + this.gYear + "<BR>");
        this.wwrite(vCode);

        if (isIE)
            this.wwrite("</DIV>");
        else if (isNav)
            this.wwrite("</LAYER>");
    }

    this.wwrite("</font><BR></body></html>");
    this.gWinCal.document.close();
}

Calendar.prototype.wwrite = function(wtext) {
    this.gWinCal.document.writeln(wtext);
}

Calendar.prototype.wwriteA = function(wtext) {
    this.gWinCal.document.write(wtext);
}

Calendar.prototype.cal_header = function() {
    var vCode = "";
    
    vCode = vCode + "<TR>";
    vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Sun</B></FONT></TD>";
    vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Mon</B></FONT></TD>";
    vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Tue</B></FONT></TD>";
    vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Wed</B></FONT></TD>";
    vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Thu</B></FONT></TD>";
    vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Fri</B></FONT></TD>";
    vCode = vCode + "<TD WIDTH='16%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Sat</B></FONT></TD>";
    vCode = vCode + "</TR>";
    
    return vCode;
}

Calendar.prototype.cal_data = function() {
    var vDate = new Date();
    vDate.setDate(1);
    vDate.setMonth(this.gMonth);
    vDate.setFullYear(this.gYear);

    var vFirstDay=vDate.getDay();
    var vDay=1;
    var vLastDay=Calendar.get_daysofmonth(this.gMonth, this.gYear);
    var vOnLastDay=0;
    var vCode = "";

    /*
    Get day for the 1st of the requested month/year..
    Place as many blank cells before the 1st day of the month as necessary. 
    */

    vCode = vCode + "<TR>";
    for (i=0; i<vFirstDay; i++) {
        vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(i) + "><FONT SIZE='2' FACE='" + fontface + "'> </FONT></TD>";
    }

    // Write rest of the 1st week
    for (j=vFirstDay; j<7; j++) {
        vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" + 
            "<A HREF='#' " + 
                "onClick=\"self.opener.document." + this.gReturnItem + ".value='" + 
                this.format_data(vDay) + 
                "';window.close();\">" + 
                this.format_day(vDay) + 
            "</A>" + 
            "</FONT></TD>";
        vDay=vDay + 1;
    }
    vCode = vCode + "</TR>";

    // Write the rest of the weeks
    for (k=2; k<7; k++) {
        vCode = vCode + "<TR>";

        for (j=0; j<7; j++) {
            vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" + 
                "<A HREF='#' " + 
                    "onClick=\"self.opener.document." + this.gReturnItem + ".value='" + 
                    this.format_data(vDay) + 
                    "';window.close();\">" + 
                this.format_day(vDay) + 
                "</A>" + 
                "</FONT></TD>";
            vDay=vDay + 1;

            if (vDay > vLastDay) {
                vOnLastDay = 1;
                break;
            }
        }

        if (j == 6)
            vCode = vCode + "</TR>";
        if (vOnLastDay == 1)
            break;
    }
    
    // Fill up the rest of last week with proper blanks, so that we get proper square blocks
    for (m=1; m<(7-j); m++) {
        if (this.gYearly)
            vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) + 
            "><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'> </FONT></TD>";
        else
            vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) + 
            "><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'>" + m + "</FONT></TD>";
    }
    
    return vCode;
}

Calendar.prototype.format_day = function(vday) {
    var vNowDay = gNow.getDate();
    var vNowMonth = gNow.getMonth();
    var vNowYear = gNow.getFullYear();

    if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear)
        return ("<FONT COLOR=\"RED\"><B>" + vday + "</B></FONT>");
    else
        return (vday);
}

Calendar.prototype.write_weekend_string = function(vday) {
    var i;

    // Return special formatting for the weekend day.
    for (i=0; i<weekend.length; i++) {
        if (vday == weekend[i])
            return (" BGCOLOR=\"" + weekendColor + "\"");
    }
    
    return "";
}

Calendar.prototype.format_data = function(p_day) {
    var vData;
    var vMonth = 1 + this.gMonth;
    vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth;
    var vMon = Calendar.get_month(this.gMonth).substr(0,3).toUpperCase();
    var vFMon = Calendar.get_month(this.gMonth).toUpperCase();
    var vY4 = new String(this.gYear);
    var vY2 = new String(this.gYear.substr(2,2));
    var vDD = (p_day.toString().length < 2) ? "0" + p_day : p_day;

    switch (this.gFormat) {
        case "MM\/DD\/YYYY" :
            vData = vMonth + "\/" + vDD + "\/" + vY4;
            break;
        case "DD\/MM\/YYYY" :
            vData = vDD + "\/" + vMonth + "\/" + vY4;
            break;
        case "YYYY\/MM\/DD" :
            vData = vY4 + "\/" + vMonth + "\/" + vDD;
            break;
        case "MM\/DD\/YY" :
            vData = vMonth + "\/" + vDD + "\/" + vY2;
            break;
        case "MM-DD-YYYY" :
            vData = vMonth + "-" + vDD + "-" + vY4;
            break;
        case "MM-DD-YY" :
            vData = vMonth + "-" + vDD + "-" + vY2;
            break;
        case "DD\/MON\/YYYY" :
            vData = vDD + "\/" + vMon + "\/" + vY4;
            break;
        case "DD\/MON\/YY" :
            vData = vDD + "\/" + vMon + "\/" + vY2;
            break;
        case "DD-MON-YYYY" :
            vData = vDD + "-" + vMon + "-" + vY4;
            break;
        case "DD-MON-YY" :
            vData = vDD + "-" + vMon + "-" + vY2;
            break;
        case "DD\/MONTH\/YYYY" :
            vData = vDD + "\/" + vFMon + "\/" + vY4;
            break;
        case "DD\/MONTH\/YY" :
            vData = vDD + "\/" + vFMon + "\/" + vY2;
            break;
        case "DD-MONTH-YYYY" :
            vData = vDD + "-" + vFMon + "-" + vY4;
            break;
        case "DD-MONTH-YY" :
            vData = vDD + "-" + vFMon + "-" + vY2;
            break;
         case "DD\/MM\/YY" :
            vData = vDD + "\/" + vMonth + "\/" + vY2;
            break;
        case "DD-MM-YYYY" :
            vData = vDD + "-" + vMonth + "-" + vY4;
            break;
        case "DD-MM-YY" :
            vData = vDD + "-" + vMonth + "-" + vY2;
            break;
        default :
            vData = vMonth + "\/" + vDD + "\/" + vY4;
    }
    return vData;
}

function Build(p_item, p_month, p_year, p_format) {
    var p_WinCal = ggWinCal;
    p_format = p_formats
    gCal = new Calendar(p_item, p_WinCal, p_month, p_year, p_format);
    
    // Customize your Calendar here..
    gCal.gBGColor="white";
    gCal.gLinkColor="black";
    gCal.gTextColor="black";
    gCal.gHeaderColor="darkgreen";

    // Choose appropriate show function
    if (gCal.gYearly)   gCal.showY();
    else    gCal.show();
}

/************************************************
* David McKinnon				*
* 2002-09-04					*
************************************************/

var posX;
var posY;

	if(!window.event && window.captureEvents) {
	  // set up event capturing for mouse events (add or subtract as desired)
	  window.captureEvents(Event.MOUSEOVER|Event.MOUSEOUT|Event.CLICK|Event.DBLCLICK);
	  // set window event handlers (add or subtract as desired)
	  window.onmouseover = WM_getCursorHandler;
	  window.onmouseout = WM_getCursorHandler;
	  window.onclick = WM_getCursorHandler;
	  window.ondblclick = WM_getCursorHandler;
	  // create an object to store the event properties 
	  window.event = new Object;
	}


function WM_getCursorHandler(e) {
  // set event properties to global vars (add or subtract as desired)
  window.event.clientX = e.pageX;
  window.event.clientY = e.pageY;
  window.event.x = e.layerX;
  window.event.y = e.layerY;
  window.event.screenX = e.screenX;
  window.event.screenY = e.screenY;
  // route the event back to the intended function
  if ( routeEvent(e) == false ) {
    return false;
  } else {
    return true;
  }
}

function getPos(e){

	posX = window.event.screenX;
	posY = window.event.screenY;
	
	return true;
}

function parse_date (p_item){
//	p_item = arguments[0];
//	var origField = "document." + arguments[0] + ".value";
var origField = p_item;
var preparse;
var hldr;
var parsedArry;
var parsedDay;
var parsedMonth;
var parsedYear;
var intYear;
preparse = origField.toString();
hldr = eval(preparse);
parsedArry = hldr.split("/");
var p_format = p_formats;

      switch (p_format) {
        case "MM\/DD\/YYYY" :
          parsedDay = parsedArry[1];
          parsedMonth = parsedArry[0];
          parsedYear = parsedArry[2];
          intYear = parseInt(parsedYear);
          intYear = intYear-1900;
          parsedYear = eval(intYear);
          parsedDate = parsedYear+parsedMonth+parsedDay;
          break;
        case "DD\/MM\/YYYY" :
          parsedDay = parsedArry[0];
          parsedMonth = parsedArry[1];
          parsedYear = parsedArry[2];
          intYear = parseInt(parsedYear);
          intYear = intYear-1900;
          parsedYear = eval(intYear);
          parsedDate = parsedYear+parsedMonth+parsedDay;
          break;
        case "YYYY\/MM\/DD" :
          parsedDay = parsedArry[2];
          parsedMonth = parsedArry[1];
          parsedYear = parsedArry[0];
          intYear = parseInt(parsedYear);
          intYear = intYear-1900;
          parsedYear = eval(intYear);
          parsedDate = parsedYear+parsedMonth+parsedDay;
          break;
        default :
          parsedDay = parsedArry[1];
          parsedMonth = parsedArry[0];
          parsedYear = parsedArry[2];
          intYear = parseInt(parsedYear);
          intYear = intYear-1900;
          parsedYear = eval(intYear);
          parsedDate = parsedYear+parsedMonth+parsedDay;
      }
return (parsedDate);
}

function show_calendar() {
  var valid = "0123456789/-"
  var ok = "yes";
  var temp;
  var master = "document." + arguments[0] + ".value";
  var masterField = eval("document." + arguments[0]);
  var fieldValue = eval("document." + arguments[0] + ".value");
  var length = fieldValue.length
  if (length == 10 ){     /* makes sure data is 10 length date format */
    for (var i=0; i< fieldValue.length; i++) {       /* checks for valid text of date format */
      temp = "" + fieldValue.substring(i, i+1);
      if (valid.indexOf(temp) == "-1") ok = "no";
    }
  } else ok = "no"
  if ( length == 0 ) ok = "yes"      /* checks to see if date is empty */
  if (ok == "no") {
     alert("Invalid entry!  Correct date formats only! ie: 01/01/2004");
     masterField.focus();
  } else {

    /* 
        p_month : 0-11 for Jan-Dec; 12 for All Months.
        p_year  : 4-digit year
        p_day   : the day in the field
        p_format: Date format (mm/dd/yyyy, dd/mm/yy, ...)
        p_item  : Return Item.
    */

    var throwAway = getPos();
    var p_date;
    var tmphldr;
    var calWidth = 250;
    var calHeight = 250;
    p_format = p_formats;
    p_item = arguments[0];
    
    var initialDate;
    
    if(fieldValue == null || fieldValue == ''){
    	initialDate = new Date();
    	p_day = initialDate.getDate();
        p_month = initialDate.getMonth();
        p_year = initialDate.getFullYear().toString();
    }
    else
    {
    	initialDate = new Date(fieldValue);
        if (p_formats == "DD/MM/YYYY")
        {
             p_date = master.toString();
    	     tmphldr = eval(p_date);
    	     p_date = tmphldr.split("/");
    	     p_year = p_date[2];
   	     p_month = initialDate.getDate()-1;
             p_year = p_year.toString();
             p_day = p_date[0];
        }
        else if (p_formats == "DD-MM-YYYY")
        {
    	     p_date = master.toString();
    	     tmphldr = eval(p_date);
    	     p_date = tmphldr.split("-")
    	     p_year = p_date[2];
   	     p_month = initialDate.getDate()-1;
             p_year = p_year.toString();
             p_day = p_date[0];
        }
        else
        {
             p_day = initialDate.getDate();
             p_month = initialDate.getMonth();
             p_year = initialDate.getFullYear().toString();
        }
    }
   
        
    //format
    if (arguments[4] == null)
        p_format = p_formats;
    else
        p_format = arguments[4];
    	
    throwAway = reCalPosition(calHeight, calWidth);
    
    
    vWinCal = window.open("", "Calendar", 
        "width=" + calWidth + ",height=" + calHeight + ",status=no,resizable=no,top=" + posY + ",left=" + posX);
    vWinCal.opener = self;
    ggWinCal = vWinCal;
    Build(p_item, p_month, p_year, p_format);
  }
}

function reCalPosition(calHeight, calWidth){
	//check if the Y position is going to push
	//us off the bottom of the screen, if so
	//than adjust the Y coord so that the bottom 
	//is now where the top used to be
	if (posY + calHeight > window.screen.height){
		posY = posY - calHeight;
	}
	//repeat the procedure if this is going to 
	//push us off the right of the screen
	if (posX + calWidth > window.screen.width){
		posX = posX - calWidth;
	}
	return true;
}

/*
Yearly Calendar Code Starts here
*/
function show_yearly_calendar(p_item, p_year, p_format) {
    // Load the defaults..
    if (p_year == null || p_year == "")
        p_year = new String(gNow.getFullYear().toString());
    if (p_format == null || p_format == "")
        p_format = p_formats;

    var vWinCal = window.open("", "Calendar", "scrollbars=yes");
    vWinCal.opener = self;
    ggWinCal = vWinCal;

    Build(p_item, null, p_year, p_format);
}

function date_verify(){
  var valid = "0123456789/-"
  var ok = "yes";
  var temp;
  var master = "document." + arguments[0] + ".value";
  var masterField = eval("document." + arguments[0]);
  var fieldValue = eval("document." + arguments[0] + ".value");
  var length = fieldValue.length
  if (length == 10 ){     /* makes sure data is 10 length date format */
    for (var i=0; i< fieldValue.length; i++) {       /* checks for valid text of date format */
      temp = "" + fieldValue.substring(i, i+1);
      if (valid.indexOf(temp) == "-1") ok = "no";
    }
  } else ok = "no"
  if ( length == 0 ) ok = "yes"      /* checks to see if date is empty */
  if (ok == "no") {
     alert("Invalid entry!  Correct date formats only! ie: 01/01/2004");
     masterField.focus();
  } else {
    return false;
  }
}


function Is (){
// convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase();

// *** BROWSER VERSION ***
// Note: On IE5, these return 4, so use this.ie5up to detect IE5.
this.major = parseInt(navigator.appVersion);
this.minor = parseFloat(navigator.appVersion);

// Note: Opera and WebTV spoof Navigator.  We do strict client detection.
// If you want to allow spoofing, take out the tests for opera and webtv.
this.nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
            && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
            && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
this.nav2 = (this.nav && (this.major == 2));
this.nav3 = (this.nav && (this.major == 3));
this.nav4 = (this.nav && (this.major == 4));
this.nav4up = (this.nav && (this.major >= 4));
this.navonly      = (this.nav && ((agt.indexOf(";nav") != -1) ||
                      (agt.indexOf("; nav") != -1)) );
this.nav6 = (this.nav && (this.major == 5));
this.nav6up = (this.nav && (this.major >= 5));
this.gecko = (agt.indexOf('gecko') != -1);

this.ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
this.ie3    = (this.ie && (this.major < 4));
this.ie4    = (this.ie && (this.major == 4) && (agt.indexOf("msie 4")!=-1) );
this.ie4up  = (this.ie && (this.major >= 4));
this.ie5    = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")!=-1) );
this.ie5_5  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.5")!=-1));
this.ie5up  = (this.ie && !this.ie3 && !this.ie4);
this.ie5_5up =(this.ie && !this.ie3 && !this.ie4 && !this.ie5);
this.ie6    = (this.ie && (this.major == 4) && (agt.indexOf("msie 6.")!=-1) );
this.ie6up  = (this.ie && !this.ie3 && !this.ie4 && !this.ie5 && !this.ie5_5);
}

// set DIVs to zindex 1
function SetDivs(id){
  var oElementArray = document.getElementsByTagName('DIV')
  if ( oElementArray == null )  return; 
  for (var i=0; i<oElementArray.length; i++){
    var temp = oElementArray[i].style.zIndex;
    if ( temp > 1 ) temp = temp-1;
    oElementArray[i].style.zIndex = temp;
  }
  document.getElementById(id).style.zIndex = 5
}


// hide or show picklists
function SetDropDowns(bShow){
  var oElementArray = document.getElementsByTagName('SELECT')
  if ( oElementArray == null )  return; 
for (var i=0; i<oElementArray.length; i++)
  if ( bShow == true ) oElementArray[i].style.visibility = ''
  else oElementArray[i].style.visibility = 'hidden'
}

function popup_getCoordinates(obj) {
var newObj = new Object();
newObj.x = obj.offsetLeft;
newObj.y = obj.offsetTop;
theParent = obj.offsetParent;       
while (theParent != null){
  newObj.y += theParent.offsetTop;
  newObj.x += theParent.offsetLeft;
  theParent = theParent.offsetParent;
}
return newObj;
}

// show Client popup
function makeItVisible(id2,id,xloc,yloc, Event){
var theImageName = id2;
var theImage;
if(document.images) {     
theImage = document.images[theImageName];
}   

var is = new Is();
if (is.nav4up) {
document.getElementById(id).style.left = popup_getCoordinates(theImage).x - xloc - 10;
document.getElementById(id).style.top = popup_getCoordinates(theImage).y + yloc - 3;
var temp = document.getElementById(id).style.visibility
  if ( temp == "visible" ){ 
    document.getElementById(id).style.visibility="hidden";
    SetDropDowns(true);
  } else {
    document.getElementById(id).style.visibility="visible";
    SetDivs(id);
    SetDropDowns(false);
  }
}else {
/*
document.all[id].style.pixelLeft = (document.body.scrollLeft + event.clientX) - xloc;
document.all[id].style.pixelTop = (document.body.scrollTop + event.clientY) + 10;
*/
document.all[id].style.pixelLeft = popup_getCoordinates(theImage).x - xloc;
document.all[id].style.pixelTop = popup_getCoordinates(theImage).y + yloc;
var temp = document.all[id].style.visibility
  if ( temp == "visible" ){ 
    document.all[id].style.visibility="hidden";
    SetDropDowns(true);
  } else {
    document.all[id].style.visibility="visible";
    SetDivs(id);
    SetDropDowns(false);
  }
}
}

// Hide client popup
function hideHelp(id){
var is = new Is();
is.nav4up ? document.getElementById(id).style.visibility="hidden" : document.all[id].style.visibility="hidden";
}


/* Navigating functins for WIP list */
/* individual record navigation */
function first_record(thislist, records)
{
  records.moveFirst();
  formatTable(thislist, records);
}

function previous_record(thislist, records)
{  
  if(records.absoluteposition>1)
  {
    records.movePrevious();
    formatTable(thislist, records);
  }
}

function next_record(thislist, records)
{
  if(records.absoluteposition < records.recordcount)
  {
    records.moveNext();
    formatTable(thislist, records);
  }
}

function last_record(thislist, records)
{
  records.moveLast();
  formatTable(thislist, records);
}

function update_status(thislist, records, text)
{  
  var count = records.recordcount;
  var msg = "Record "
  msg += records.absoluteposition;
  msg += " of ";
  msg += count;
  msg += text;
  window.document.getElementById('reccount').innerText=msg;
}

function formatTable(thislist, records)
{
  var rows  = thislist.rows;
  var count = records.recordcount;
  
  for(var i=0;i<rows.length;i++)
  {
    if (i == records.absoluteposition)
    {
      rows[i].style.backgroundColor = "#4444FF";
      rows[i].style.color = "#FFFFFF";
    }
    else
    {
      if(i%2==0) 
        rows[i].style.backgroundColor = "#BBFFFF";
      else 
        rows[i].style.backgroundColor = "#DDFFFF";
      rows[i].style.color = "#000000";
    }
  }
  update_status(thislist, records, "");
}

function focusrow(el, thislist, records)
{
  var msg = "  Old Position: " + records.absoluteposition;
  msg += " Row Index: " + el.rowIndex;
  records.absoluteposition = el.rowIndex;
  update_status(thislist, records, msg);
  formatTable(thislist, records);
/*   el.style.background = "#0000FF";
   el.style.color      = "#FFFFFF";*/
}

var lastColumn = null;

function sort(column, xmlDoc, xslDoc)
{
  if(xmlDoc == null)
    xmlDoc = document.XMLDocument;
  if(xslDoc == null)
    xslDoc = document.XSLDocument;

  if(xmlDoc == null)
    alert("xmlDoc is null");
  if(xslDoc == null)
    alert("xslDoc is null");
  if((xslDoc == null)||(xmlDoc == null))
    return;   

  var node = xslDoc.selectSingleNode("//xsl:sort/@select");
  node.nodeValue = column;

  node = xslDoc.selectSingleNode("//xsl:sort/@order");
  if (lastColumn == column)
  {
    if (node.nodeValue == "descending")
      node.nodeValue = "ascending";
    else
      node.nodeValue = "descending";
  }
  else
  {
    node.nodeValue = "ascending";
  }
  node = xslDoc.selectSingleNode("//xsl:sort/@data-type");
  if ((column == "priority")||(column == "file"))
    node.nodeValue = "number";
  else
    node.nodeValue = "text";    
  
  /*
  var msg = "setting node to :";
  msg += node.nodeValue;
  alert (msg);
  */
  lastColumn = column;  
  var html = xmlDoc.documentElement.transformNode(xslDoc);
  mainDiv.innerHTML = html
}
/* end of navigating functins */