var gCookieName = 'AmphenolCanada' ;
var gCookiePswd = '' ;
var gCookieUser = '' ;
var gSeparator = ':' ; 
var gDateToday  = new Date() ;
var gYear       = gDateToday.getYear() ;
var gDateExpire = new Date(gYear < 2000 ? 1901 + gYear : gYear + 1 ,
                           gDateToday.getMonth(),
               gDateToday.getDate()) ;
var gBlank      = '                       ' ;
var gNRText     = '--- Not Required ---' ;
var gSelectText = '--- Select A Territory ---' ;
var gSelectSeriesText = '--- Select A Series ---' ;
var gGeographical = '';
var gTerritory    = '';
var gProductType = '';
var gSeries    = '';
var isIE = (navigator.appName.indexOf('Microsoft') != -1) ;
var isNav = (navigator.appName.indexOf('Netscape') != -1) ;
if (navigator.appVersion.charAt(0) == "5")
{ 
   if (navigator.appName == "Netscape")
   { 
      isNav6 = true
   } 
}

function fGeographical(pId,pGeographical,pTerritory)
  {
  this.Id        = pId ;
  this.Name      = pGeographical ;
  this.Territory = pTerritory ;
  }

function fTerritory(pId,pTerritory)
  {
  this.Id   = pId ;
  this.Name = pTerritory ;
  }

function fProductType(pId,pProductType,pSeries)
  {
  this.Id        = pId ;
  this.Name      = pProductType ;
  this.Series    = pSeries ;
  }

function fSeries(pId,pSeries)
  {
  this.Id   = pId ;
  this.Name = pSeries ;
  }
  
function Upload_Statistics(pHTML_DSI,pFile)
      {
      alert (pHTML_DSI);
	    var vMessageWin = window.open('Execute?application=webapp&Program=REPORT-Upload_Stats&DSI=' + pHTML_DSI + '&File_Uploaded=' + pFile
                    ,'MessageWindow','titlebar=no,resizable=no,scrollbars=yes,top=200,left=270,width=0,height=0') ;

      }

function PDF_Statistics(pHTML_DSI,pPDF)
      {
	    var vMessageWin = window.open('Execute?application=Runapp&Program=REPORT-PDF_Stats&DSI=' + '&PDF=' + pPDF
                    ,'MessageWindow','titlebar=no,resizable=no,scrollbars=yes,top=200,left=270,width=0,height=0') ;

      }

function PDF_Stats(pHTML_DSI,pPDF)
      {
	    var vMessageWin = window.open('Execute?Program=REPORT-PDF_Stats&DSI=' + pHTML_DSI + '&PDF=' + pPDF
                    ,'MessageWindow','titlebar=no,resizable=no,scrollbars=yes,top=200,left=270,width=0,height=0') ;

      }

function Download_Stats(pHTML_DSI,pDOC)
      {
	    var vMessageWin = window.open('Execute?Program=REPORT-Download-Stats&DSI=' + pHTML_DSI + '&DOC=' + pDOC
                    ,'MessageWindow','titlebar=no,resizable=no,scrollbars=yes,top=200,left=270,width=0,height=0') ;

      }
      
function SortName(pObject1, pObject2)
  {
  if      (pObject1.Name <  pObject2.Name) return -1 ;
  else if (pObject1.Name == pObject2.Name) return  0 ;
  else if (pObject1.Name >  pObject2.Name) return  1 ;
  }

function InitGeoTerr(pGeographical,pTerritory,pGeographicalSelected,pTerritorySelected)
  {
  if (!pGeographical || !pTerritory) return ;
  if (pGeographical.options[1].value != '1') return ;

  pGeographical.length = 1 ;                      /* discard all Geographical regions */
  pTerritory.length = 1 ;                         /* discard all Territories */
  pTerritory.options[0].text = gBlank ;

  if (pGeographicalSelected == ' ') pGeographicalSelected = false ;
  if (pTerritorySelected  == ' ') pTerritorySelected = false ;

  /* ------------------------- build Geographical and Territory in name order */
  Geographical.sort(SortName) ;
  for (var i = 0; i < Geographical.length; i++)
    {
    with (Geographical[i])
      {
      pGeographical.options[i + 1] = new Option(Name, Id) ;
      if (Territory)
        {
        for (var j = 0, k = 0; j < Territory.length; j++)
          {
          if (Territory[j])
            {
            Territory[k] = Territory[j] ;
            k += 1 ;
            }
          }
        Territory.length = k ;              /* discard undefined Territory */
        Territory.sort(SortName) ;
        }
      }
    }

  /* ------------------------------------- select Geographical and Territory */
  if (!pGeographicalSelected)
    return ;
  with (pGeographical)
    for (i = 1; i <= length; i++)
      {
      if (options[i].value == pGeographicalSelected)
        {
        options[i].selected = true ;
        BuildTerritory(options[i].value,pTerritory) ;
        for (j = 1; j <= pTerritory.length; j++)
          if (pTerritorySelected && pTerritory.options[j].value == pTerritorySelected)
            {
            pTerritory.options[j].selected = true ;
            break ;
            }
        break;
        }
      }
  }

function BuildTerritory(pSearchGeographical,pTerritory)
  {
  pTerritory.length = 1 ;                         /* discard all Territories */
  if (pSearchGeographical == ' ')
    {
    pTerritory.options[0].text = gBlank ;
    return ;
    }
  for (var i = 0; i < Geographical.length; i++)
    with (Geographical[i])
      if (pSearchGeographical == Id)
        {
        if (Territory.length > 0)
          {
          pTerritory.options[0].text = gSelectText ;
          for (var j = 0; j < Territory.length; j++)
             {

              pTerritory.options[j + 1] = new Option(Territory[j].Name, Territory[j].Id) ;
             }
          }
        else
          {
          pTerritory.options[0].text = gNRText ;
          }

        pTerritory.options[0].selected = true ;

        return ;
        }
  }

function InitProductTypeSeries(pProductType,pSeries,pProductTypeSelected,pSeriesSelected)
  {
  if (!pProductType || !pSeries) return ;
  if (pProductType.options[1].value != '1') return ;

  pProductType.length = 1 ;                      /* discard all ProductType  */
  pSeries.length = 1 ;                         /* discard all Series */
  pSeries.options[0].text = gBlank ;

  if (pProductTypeSelected == ' ') pProductTypeSelected = false ;
  if (pSeriesSelected  == ' ') pSeriesSelected = false ;

  /* ------------------------- build ProductType and Series in name order */
  ProductType.sort(SortName) ;
  for (var i = 0; i < ProductType.length; i++)
    {
    with (ProductType[i])
      {
      pProductType.options[i + 1] = new Option(Name, Id) ;
      if (Series)
        {
        for (var j = 0, k = 0; j < Series.length; j++)
          {
          if (Series[j])
            {
            Series[k] = Series[j] ;
            k += 1 ;
            }
          }
        Series.length = k ;              /* discard undefined Series */
        Series.sort(SortName) ;
        }
      }
    }

  /* ------------------------------------- select ProductType and Series */
  if (!pProductTypeSelected)
    return ;
  with (pProductType)
    for (i = 1; i <= length; i++)
      {
      if (options[i].value == pProductTypeSelected)
        {
        options[i].selected = true ;
        BuildSeries(options[i].value,pSeries) ;
        for (j = 1; j <= pSeries.length; j++)
          if (pSeriesSelected && pSeries.options[j].value == pSeriesSelected)
            {
            pSeries.options[j].selected = true ;
            break ;
            }
        break;
        }
      }
  }

function BuildSeries(pSearchProductType,pSeries)
  {
  pSeries.length = 1 ;                         /* discard all Series */
  if (pSearchProductType == ' ')
    {
    pSeries.options[0].text = gBlank ;
    return ;
    }
  for (var i = 0; i < ProductType.length; i++)
    with (ProductType[i])
      if (pSearchProductType == Id)
        {
        if (Series.length > 0)
          {
          pSeries.options[0].text = gSelectSeriesText ;
          for (var j = 0; j < Series.length; j++)
             {

              pSeries.options[j + 1] = new Option(Series[j].Name, Series[j].Id) ;
             }
          }
        else
          {
          pSeries.options[0].text = gNRText ;
          }

        pSeries.options[0].selected = true ;

        return ;
        }
  }


function showorhide1(f)
  {
    if(f)
      {visi="visible";}
    else
      {visi="hidden";}
      
    if(document.layers)
      {
        document.Processing.visibility=visi;
      }
     
    if(document.all)
      {
       document.all.Processing.style.visibility=visi;
      }
    if(document.getElementById)
      {
      document.getElementById("Processing").style.visibility=visi;
      }
      
    with (document.RecordForm)
       {
         submit() ;
       }
      
  } 
  
  
  function OpenMonth(pDateField,pPath,pDateFormat,pDateLang)
    {
    var vVersion = parseInt(navigator.appVersion.substring(0,navigator.appVersion.indexOf('.',0))) ;
    if (vVersion <= 2) return ;
  
    if (pDateField.value != '')
      {
      var vDateField = pDateField.value;
  
      vOut = "-";
      vAdd = " ";
      
      while (vDateField.indexOf(vOut)>-1)
        {
        vPos       = vDateField.indexOf(vOut);
        vDateField = "" + (vDateField.substring(0, vPos) + vAdd + 
                     vDateField.substring((vPos + vOut.length), vDateField.length));
        }
  
      var vDateToday = new Date(vDateField);
      }
      
    if (vDateToday == "NaN" | pDateField.value == '')
      {
      vDateToday = gDateToday;
      }
      
    var vYear       = vDateToday.getYear() ;
    var vMonth      = vDateToday.getMonth() + 1 ;
    var vMonthWin   = window.open(pPath + 'month.html?' + pDateFormat
                                                + ',' + (vYear < 2000 ? 1900 + vYear : vYear)
                                                + ',' + vMonth,
                                  'Month',
                                  'resizable,top=0,left=0,width=330,height=380') ;
    vMonthWin.Field = pDateField ;
    vMonthWin.Lang  = pDateLang;
    }
  

function CheckDate(dateStr)
   {
      // no validation if date = space

      if (dateStr.value == " ")
         return true;

      if (dateStr.value.length == 8 && isNaN(dateStr.value))
         {
         alert("Error ! Date must be numeric.");
         dateStr.focus();
         dateStr.select();
         return false;
         }

      if (dateStr.value.length != 8)
      {
         if (dateStr.value.substring(2,3) != "-" || dateStr.value.substring(6,7) != "-")
         {
         alert("Error ! Date should be in DD-MMM-YYYY format.");
         dateStr.focus();
         dateStr.select();
         return false;
         }
      }

      // parse date into variables

      // date in YYYYMMDD format

      if (dateStr.value.length == 8)
         {
          month = dateStr.value.substring(4,6);
          day   = dateStr.value.substring(6,8);
          year  = dateStr.value.substring(0,4);
         }

      // date in DD-MMM-YYYY format

      if (dateStr.value.length == 11)
         {
          var monthstr;
          var month = 0;

          year     = dateStr.value.substring(7,11);
          day      = dateStr.value.substring(0,2);
          monthstr = dateStr.value.substring(3,6);

          switch (monthstr.toUpperCase())
          {
             case "JAN": month = 1;break;
             case "FEB": month = 2;break;
             case "MAR": month = 3;break;
             case "APR": month = 4;break;
             case "MAY": month = 5;break;
             case "JUN": month = 6;break;
             case "JUL": month = 7;break;
             case "AUG": month = 8;break;
             case "SEP": month = 9;break;
             case "OCT": month = 10;break;
             case "NOV": month = 11;break;
             case "DEC": month = 12;break;
          }
         }

      // check month range
      if (month < 1 || month > 12)
      {
         alert("Month must be between 1 and 12 !");
         dateStr.focus();
         dateStr.select();
         return false;
      }

      // check day numeric
      if (isNaN(day))
      {
         alert("Day must be numeric !");
         dateStr.focus();
         dateStr.select();
         return false;
      }

      // check day range
      if (day < 1 || day > 31)
      {
         alert("Date must be between 1 and 31 !");
         dateStr.focus();
         dateStr.select();
         return false;
      }

      // check year numeric
      if (isNaN(year))
      {
         alert("Year must be numeric !");
         dateStr.focus();
         dateStr.select();
         return false;
      }

      // check some months with 30 days, not 31 days
      if ((month==4 || month==6 || month==9 || month==11) && day==31)
      {
         alert("Month no. " + month + " has only 30 days !");
         dateStr.focus();
         dateStr.select();
         return false;
      }

      // check for Feb 29
      if (month==2)
      {
         var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
         if (day > 29 || (day==29 && !isleap))
         {
          alert("February " + year + "does not have " + day + " days !");
          dateStr.focus();
          dateStr.select();
          return false;
         }
      }
      
      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)
 {
	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_format;
	this.gBGColor = "white";
	this.gFGColor = "navy";
	this.gTextColor = "navy";
	this.gHeaderColor = "navy";
	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>");

	// 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=0 CELLSPACING=0 CELLPADDING=0><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 bgcolor=navy><font color=white><b>");

      this.wwrite(this.gMonthName + " " + this.gYear + "</b></font></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>");

	// 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 bgcolor=eee583 WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Sun</B></FONT></TD>";
	vCode = vCode + "<TD bgcolor=eee583 WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Mon</B></FONT></TD>";
	vCode = vCode + "<TD bgcolor=eee583 WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Tue</B></FONT></TD>";
	vCode = vCode + "<TD bgcolor=eee583 WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Wed</B></FONT></TD>";
	vCode = vCode + "<TD bgcolor=eee583 WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Thu</B></FONT></TD>";
	vCode = vCode + "<TD bgcolor=eee583 WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Fri</B></FONT></TD>";
	vCode = vCode + "<TD bgcolor=eee583 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 = "";
        NextYear = parseFloat(this.gYear) + 1;
        NextYear2 = parseFloat(this.gYear) + 2;

	/*
	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 "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\/YYYY" :
			vData = vDD + "\/" + vMonth + "\/" + vY4;
			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 = vDD + "\-" + vMon + "\-" + vY4;
	}

	return vData;
}

function Build(p_item, p_month, p_year, p_format) {
	var p_WinCal = ggWinCal;
	gCal = new Calendar(p_item, p_WinCal, p_month, p_year, p_format);

	// Customize your Calendar here..
	gCal.gBGColor="white";
	gCal.gLinkColor="navy";
	gCal.gTextColor="navy";
	gCal.gHeaderColor="navy";

	// Choose appropriate show function
	if (gCal.gYearly)	gCal.showY();
	else	gCal.show();
}

function show_calendar() {
	/*
		p_month : 0-11 for Jan-Dec; 12 for All Months.
		p_year	: 4-digit year
		p_format: Date format (mm/dd/yyyy, dd/mm/yy, ...)
		p_item	: Return Item.
	*/
	p_item = arguments[0];
	if (arguments[1] == null)
		p_month = new String(gNow.getMonth());
	else
		p_month = arguments[1];
	if (arguments[2] == "" || arguments[2] == null)
		p_year = new String(gNow.getFullYear().toString());
	else
		p_year = arguments[2];
	if (arguments[3] == null)
		p_format = "DD-MMM-YYYY";
	else
		p_format = arguments[3];

	vWinCal = window.open("", "Calendar",
		"width=250,height=210,status=no,resizable=no,top=200,left=200");
	vWinCal.opener = self;
	ggWinCal = vWinCal;

	Build(p_item, p_month, p_year, p_format);
}
/*
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 = "DD-MMM-YYYY";

	var vWinCal = window.open("", "Calendar", "scrollbars=yes");
	vWinCal.opener = self;
	ggWinCal = vWinCal;

	Build(p_item, null, p_year, p_format);
}


var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
function LZ(x) {return(x<0||x>9?"":"0")+x}

// ------------------------------------------------------------------
// isDate ( date_string, format_string )
// Returns true if date string matches format of format string and
// is a valid date. Else returns false.
// It is recommended that you trim whitespace around the value before
// passing it to this function, as whitespace is NOT ignored!
// ------------------------------------------------------------------
function isDate(val,format) {
	var date=getDateFromFormat(val,format);
	if (date==0) { return false; }
	return true;
	}

// -------------------------------------------------------------------
// compareDates(date1,date1format,date2,date2format)
//   Compare two date strings to see which is greater.
//   Returns:
//   1 if date1 is greater than date2
//   0 if date2 is greater than date1 of if they are the same
//  -1 if either of the dates is in an invalid format
// -------------------------------------------------------------------
function compareDates(date1,dateformat1,date2,dateformat2) {
	var d1=getDateFromFormat(date1,dateformat1);
	var d2=getDateFromFormat(date2,dateformat2);
	if (d1==0 || d2==0) {
		return -1;
		}
	else if (d1 > d2) {
		return 1;
		}
	return 0;
	}

// ------------------------------------------------------------------
// formatDate (date_object, format)
// Returns a date in the output format specified.
// The format string uses the same abbreviations as in getDateFromFormat()
// ------------------------------------------------------------------
function formatDate(date,format) {
	format=format+"";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=date.getYear()+"";
	var M=date.getMonth()+1;
	var d=date.getDate();
	var E=date.getDay();
	var H=date.getHours();
	var m=date.getMinutes();
	var s=date.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
	// Convert real date parts into formatted versions
	var value=new Object();
	if (y.length < 4) {y=""+(y-0+1900);}
	value["y"]=""+y;
	value["yyyy"]=y;
	value["yy"]=y.substring(2,4);
	value["M"]=M;
	value["MM"]=LZ(M);
	value["MMM"]=MONTH_NAMES[M-1];
	value["NNN"]=MONTH_NAMES[M+11];
	value["d"]=d;
	value["dd"]=LZ(d);
	value["E"]=DAY_NAMES[E+7];
	value["EE"]=DAY_NAMES[E];
	value["H"]=H;
	value["HH"]=LZ(H);
	if (H==0){value["h"]=12;}
	else if (H>12){value["h"]=H-12;}
	else {value["h"]=H;}
	value["hh"]=LZ(value["h"]);
	if (H>11){value["K"]=H-12;} else {value["K"]=H;}
	value["k"]=H+1;
	value["KK"]=LZ(value["K"]);
	value["kk"]=LZ(value["k"]);
	if (H > 11) { value["a"]="PM"; }
	else { value["a"]="AM"; }
	value["m"]=m;
	value["mm"]=LZ(m);
	value["s"]=s;
	value["ss"]=LZ(s);
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (value[token] != null) { result=result + value[token]; }
		else { result=result + token; }
		}
	return result;
	}
	
// ------------------------------------------------------------------
// Utility functions for parsing in getDateFromFormat()
// ------------------------------------------------------------------
function _isInteger(val) {
	var digits="1234567890";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
		}
	return true;
	}
function _getInt(str,i,minlength,maxlength) {
	for (var x=maxlength; x>=minlength; x--) {
		var token=str.substring(i,i+x);
		if (token.length < minlength) { return null; }
		if (_isInteger(token)) { return token; }
		}
	return null;
	}
	
// ------------------------------------------------------------------
// getDateFromFormat( date_string , format_string )
//
// This function takes a date string and a format string. It matches
// If the date string matches the format string, it returns the 
// getTime() of the date. If it does not match, it returns 0.
// ------------------------------------------------------------------
function getDateFromFormat(val,format) {
	val=val+"";
	format=format+"";
	var i_val=0;
	var i_format=0;
	var c="";
	var token="";
	var token2="";
	var x,y;
	var now=new Date();
	var year=now.getYear();
	var month=now.getMonth()+1;
	var date=1;
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getSeconds();
	var ampm="";
	
	while (i_format < format.length) {
		// Get next token from format string
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		// Extract contents of value based on format token
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { x=4;y=4; }
			if (token=="yy")   { x=2;y=2; }
			if (token=="y")    { x=2;y=4; }
			year=_getInt(val,i_val,x,y);
			if (year==null) { return 0; }
			i_val += year.length;
			if (year.length==2) {
				if (year > 70) { year=1900+(year-0); }
				else { year=2000+(year-0); }
				}
			}
		else if (token=="MMM"||token=="NNN"){
			month=0;
			for (var i=0; i<MONTH_NAMES.length; i++) {
				var month_name=MONTH_NAMES[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
					if (token=="MMM"||(token=="NNN"&&i>11)) {
						month=i+1;
						if (month>12) { month -= 12; }
						i_val += month_name.length;
						break;
						}
					}
				}
			if ((month < 1)||(month>12)){return 0;}
			}
		else if (token=="EE"||token=="E"){
			for (var i=0; i<DAY_NAMES.length; i++) {
				var day_name=DAY_NAMES[i];
				if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
					i_val += day_name.length;
					break;
					}
				}
			}
		else if (token=="MM"||token=="M") {
			month=_getInt(val,i_val,token.length,2);
			if(month==null||(month<1)||(month>12)){return 0;}
			i_val+=month.length;}
		else if (token=="dd"||token=="d") {
			date=_getInt(val,i_val,token.length,2);
			if(date==null||(date<1)||(date>31)){return 0;}
			i_val+=date.length;}
		else if (token=="hh"||token=="h") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>12)){return 0;}
			i_val+=hh.length;}
		else if (token=="HH"||token=="H") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>23)){return 0;}
			i_val+=hh.length;}
		else if (token=="KK"||token=="K") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>11)){return 0;}
			i_val+=hh.length;}
		else if (token=="kk"||token=="k") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>24)){return 0;}
			i_val+=hh.length;hh--;}
		else if (token=="mm"||token=="m") {
			mm=_getInt(val,i_val,token.length,2);
			if(mm==null||(mm<0)||(mm>59)){return 0;}
			i_val+=mm.length;}
		else if (token=="ss"||token=="s") {
			ss=_getInt(val,i_val,token.length,2);
			if(ss==null||(ss<0)||(ss>59)){return 0;}
			i_val+=ss.length;}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
			else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
			else {return 0;}
			i_val+=2;}
		else {
			if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
			else {i_val+=token.length;}
			}
		}
	// If there are any trailing characters left in the value, it doesn't match
	if (i_val != val.length) { return 0; }
	// Is date valid for month?
	if (month==2) {
		// Check for leap year
		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
			if (date > 29){ return 0; }
			}
		else { if (date > 28) { return 0; } }
		}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return 0; }
		}
	// Correct hours value
	if (hh<12 && ampm=="PM") { hh=hh-0+12; }
	else if (hh>11 && ampm=="AM") { hh-=12; }
	var newdate=new Date(year,month-1,date,hh,mm,ss);
	return newdate.getTime();
	}

// ------------------------------------------------------------------
// parseDate( date_string [, prefer_euro_format] )
//
// This function takes a date string and tries to match it to a
// number of possible date formats to get the value. It will try to
// match against the following international formats, in this order:
// y-M-d   MMM d, y   MMM d,y   y-MMM-d   d-MMM-y  MMM d
// M/d/y   M-d-y      M.d.y     MMM-d     M/d      M-d
// d/M/y   d-M-y      d.M.y     d-MMM     d/M      d-M
// A second argument may be passed to instruct the method to search
// for formats like d/M/y (european format) before M/d/y (American).
// Returns a Date object or null if no patterns match.
// ------------------------------------------------------------------
function parseDate(val) {
	var preferEuro=(arguments.length==2)?arguments[1]:false;
	generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d');
	monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d');
	dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M');
	var checkList=new Array('generalFormats',preferEuro?'dateFirst':'monthFirst',preferEuro?'monthFirst':'dateFirst');
	var d=null;
	for (var i=0; i<checkList.length; i++) {
		var l=window[checkList[i]];
		for (var j=0; j<l.length; j++) {
			d=getDateFromFormat(val,l[j]);
			if (d>0) { return new Date(d); }
			}
		}
	return null;
	}


function ReadCookie()
  {
  var vVersion = parseInt(navigator.appVersion.substring(0,navigator.appVersion.indexOf('.',0))) ;
  if (vVersion <= 2) return ;

  var vCurrentCookies = new Array() ;
  var vNameValues = new Array() ;
  var vParms = new Array() ;
  var vStartPos ;

  if (document.cookie)
    {
    vCurrentCookies = document.cookie.split(';') ;
    for (var i = 0; i < vCurrentCookies.length; i++)
      {
      vStartPos = (i == 0)? 0 : 1 ;

      vCurrentCookies[i] = vCurrentCookies[i].substring(vStartPos,vCurrentCookies[i].length) ;
      vNameValues = vCurrentCookies[i].split('=') ;
      if (vNameValues[0] == gCookieName)
        {
        vParms      = vNameValues[1].split(gSeparator) ;
        gCookieUser = unescape(vParms[0]) ;
        gCookiePswd = unescape(vParms[1]) ;
        break ;
        }
      }
    }
  }


function WriteCookie(USERID,USERPASS)
  {
  var vVersion = parseInt(navigator.appVersion.substring(0,navigator.appVersion.indexOf('.',0))) ;
  if (vVersion <= 2) return ;
  
  document.cookie = gCookieName + '=' + escape(USERID.value) + gSeparator
                                      + escape(USERPASS.value) 
                                + ';path=/'
                                + ';expires=' + gDateExpire.toGMTString() ;
  }
