/* ---- Filename: com.wjstc.DatePicker.js ---- */


// ----------------------------- ***** -------------------------------
//
// Ardent JavaScript
// JavaScript Module 'com.wjstc.DatePicker.js'
// Copyright (c) 2008 Ardent Edge LLC.  All rights reserved.
//
// Author: George M. Toms, Ph.D.
// 8755 Navajo Rd., #1
// San Diego, CA 92119 - USA
// Tel.: (858) 240-2632
// e-mail: george@toms-us.com
//
// Created:       April 02, 2007
// Last modified: November 10, 2007
//
// ----------------------------- ***** -------------------------------


Module.createNamespace('com.wjstc.DatePicker');
Module.require('com.wjstc.Common',1.1);
Module.require('com.wjstc.HideSelectIE6',1.1);
Module.require('com.wjstc.Util',1.1);

com.wjstc.DatePicker.NAME='com.wjstc.DatePicker';
com.wjstc.DatePicker.VERSION=1.1;

// ------------ DatePicker Constants

com.wjstc.DatePicker.oDefaultDatePickerConfig={
//                        {simple:'yes', advanced:'yes', footer:'yes'}, // Type
  size:1.0,   // Date picker size: float
  format:'%b %D, %Y', // Date format '%b %D, %Y','%M/%D/%y','%y-%M-%D', '%B %D, %Y'
  draggable:'Y',       // draggable
  hideSelect:'Y',       // hideSelect
  replaceHeader:'N',    // replaceHeader
  zIndexValue:98,
  firstWeekDay:0,          // firstWeekDay; (0-Sunday, 1-Monday,...
  startDateIn:'Jan 01, 0001', // start Date
  endDateIn:'Dec 31, 2200', // end Date
  dayColor:'#000000',  // dayColor;
  weekEndColor:'#FF3300',  // weekEndColor;
  titleBackground:'#FAF7E6',  // titleBackground;
  mainBorderColor:'#999999',  // this.mainBorderColor;
  weekBackground:'#D7D4C3',  // weekBackground
  bodyBackground:'#F6F6F6',  // bodyBackground;
  anotherMonthDayBackground:'#FFFFFF',  // anotherMonthDayBackground;
  anotherMonthDayColor:'#999999',  // anotherMonthDayColor;
  anotherMonthWeekEndColor:'#FF9999',  // anotherMonthWeekEndColor
  footerBackground:'#FAF7E6',  // footerBackground;
  todayBackground:'#FFFF99',  // todayBackground;
  currentBackground:'#99FF99',  // currentBackground;
  selectedBorder:'#999999',  // selectedBorder;
  selectedOver:'#FFD494',  // selectedOver;
  selectedDown:'#FFB874'   // selectedDown;
};







com.wjstc.DatePicker.DatePicker=function(
//                        type,
                        size,
                        format,
                        draggable,
                        hideSelect,
                        replaceHeader,
                        zIndexValue,
                        firstWeekDay,
                        startDateIn,
                        endDateIn,
                        dayColor,
                        weekEndColor,
                        titleBackground,
                        mainBorderColor,
                        weekBackground,
                        bodyBackground,
                        anotherMonthDayBackground,
                        anotherMonthDayColor,
                        anotherMonthWeekEndColor,
                        footerBackground,
                        todayBackground,
                        currentBackground,
                        selectedBorder,
                        selectedOver,
                        selectedDown
                        )
{
// Properties
/*
this.type=(typeof(type)!='undefined')?type:{simple:'yes', advanced:'yes', footer:'yes'};
if(typeof(this.type.simple)=='undefined'){
   this.type.simple='yes';
}else{
  this.type.simple=(this.type.simple+'').toLowerCase();
  if(this.type.simple.indexOf(0)=='y'){
   this.type.simple='yes';
  }   
}
if(typeof(this.type.advanced)=='undefined'){
   this.type.advanced='yes';
}else{
  this.type.advanced=(this.type.advanced+'').toLowerCase();
  if(this.type.advanced.indexOf(0)=='y'){
   this.type.advanced='yes';
  }   
}
if(typeof(this.type.footer)=='undefined'){
   this.type.footer='yes';
}else{
  this.type.footer=(this.type.footer+'').toLowerCase();
  if(this.type.footer.indexOf(0)=='y'){
   this.type.footer='yes';
  }   
}
*/
this.size=(typeof(size)!='undefined')?size:1.0;
//if(this.size!='small' && this.size!='smaller' && this.size!='medium' && this.size!='larger' && this.size!='largest'){
//  this.size='medium';
//}

this.format=(typeof(format)!='undefined')?format:'%m %D, %Y'; 
this.align='Br'; 

this.d=new Array(   // week day name: "Sunday",
 "Sunday",
 "Monday",
 "Tuesday",
 "Wednesday",
 "Thursday",
 "Friday",
 "Saturday");
this.sd=new Array(  // short week day name: "Sun",
 "Sun",
 "Mon",
 "Tue",
 "Wed",
 "Thu",
 "Fri",
 "Sat");
this.m_l=new Array(    // month name long
 "January",
 "February",
 "March",
 "April",
 "May",
 "June",
 "July",
 "August",
 "September",
 "October",
 "November",
 "December");
this.m_s=new Array(  // short month name
 "Jan",
 "Feb",
 "Mar",
 "Apr",
 "May",
 "Jun",
 "Jul",
 "Aug",
 "Sep",
 "Oct",
 "Nov",
 "Dec");
this.draggable=(typeof(draggable)!='undefined')?draggable:'Y';
this.hideSelect=(typeof(hideSelect)!='undefined')?hideSelect:'Y';
this.replaceHeader=(typeof(replaceHeader)!='undefined')?replaceHeader:'Y';
this.zIndexValue=(typeof(zIndexValue)!='undefined')?zIndexValue:98;
this.firstWeekDay=(typeof(firstWeekDay)!='undefined')?firstWeekDay:0;

this.dayColor=(typeof(dayColor)!='undefined')?dayColor:'#000000';
this.weekEndColor=(typeof(weekEndColor)!='undefined')?
    weekEndColor:'#FF3300';
this.titleBackground=(typeof(titleBackground)!='undefined')?
    titleBackground:'#FAF7E6';
this.mainBorderColor=(typeof(mainBorderColor)!='undefined')?
    mainBorderColor:'#999999';
this.weekBackground=(typeof(weekBackground)!='undefined')?
    weekBackground:'#D7D4C3';
this.bodyBackground=(typeof(bodyBackground)!='undefined')?
    bodyBackground:'#E6E6E6';
this.anotherMonthDayBackground=(typeof(anotherMonthDayBackground)!='undefined')?
    anotherMonthDayBackground:'#FFFFFF';
this.anotherMonthDayColor=(typeof(anotherMonthDayColor)!='undefined')?
    anotherMonthDayColor:'#666666';
this.anotherMonthWeekEndColor=(typeof(anotherMonthWeekEndColor)!='undefined')?
    anotherMonthWeekEndColor:'#FF6666';
this.footerBackground=(typeof(footerBackground)!='undefined')?
    footerBackground:'#FAF7E6';
this.todayBackground=(typeof(todayBackground)!='undefined')?
    todayBackground:'#66CCCC';
this.currentBackground=(typeof(currentBackground)!='undefined')?
    currentBackground:'#99FF99';
this.selectedBorder=(typeof(selectedBorder)!='undefined')?
    selectedBorder:'#999999';
this.selectedOver=(typeof(selectedOver)!='undefined')?
    selectedOver:'#FFD494';
this.selectedDown=(typeof(selectedDown)!='undefined')?
    selectedDown:'#FFB874';
    
this.startDate=new Date(1901,0,1);
this.endDate=new Date(9999,11,31);
  this.startDateIn=startDateIn;
  this.endDateIn=endDateIn;
  this._setLanguageDP();
    
this.target='div';
this.formName='';
this.fieldName='';
this.fieldId='';
this.inputType='fieldId';

//this.d=new Array();   // week day name
//this.sd=new Array();  // short week day name
//this.m=new Array();   // month name
//this.sm=new Array();  // short month name
//this.md=new Array();  // month decoder for for day parser

// Dragging Objects
this.disY=0;
this.disX=0;
this.dragging=false;

this.dpCharset='utf-8';

// generated Date Picker Body
this.dp_body='';

// ------------ DatePicker functions
}

com.wjstc.DatePicker.DatePicker.prototype._setLanguageDP=function(){
    this._mMap=com.wjstc.Util.getMonthMap(this.m_l.concat(this.m_s));

  if(typeof(this.startDateIn)!='undefined'){
    var da=this._parseFormattedDateIn18n(this.startDateIn,this.format,this._mMap);
    this.startDate=new Date(da.y,da.m,da.d);
  }else{
    this.startDate=new Date(1901,0,1);
  }

  if(typeof(this.endDateIn)!='undefined'){
    var da=this._parseFormattedDateIn18n(this.endDateIn,this.format,this._mMap);
    this.endDate=new Date(da.y,da.m,da.d);
  }else{
    this.endDate=new Date(9999,11,31);
  }

}

com.wjstc.DatePicker.DatePicker.prototype.closeDatePicker=function(){
   if(this.target=='window'){
     window.close();
   }else{
     if(com.wjstc.Common.getObjById('wjst_DatePickerDiv')){
       com.wjstc.Common.getObjById('wjst_DatePickerDiv').style.display = 'none';
       if(this.hideSelect=='Y'){
         com.wjstc.HideSelectIE6.hs.unregisterObj('wjst_DatePickerDiv');
       }
     }
   }
}



// Generates 'About the Professional Date Picker' page
com.wjstc.DatePicker.DatePicker.prototype._aboutDP=function(divHeight,size){
  var s="<div style='width:"+(14*size)+"em;'><div style='overflow: visible; font-family:Helvetica,Arial,Verdana,sans-serif; font-size:"+(0.8*size)+"em;width:100%;"+
    "font-weight:bold; text-align: center; vertical-align: middle;"+
    " border: solid 1px #CCCCCC; background-color: #D0E0FE;'><br \/>"+
    com.wjstc.Util.t('Professional Date Picker')+"<br \/>"+com.wjstc.Util.t('Version 1.1')+"<br \/>"+
    "<b>&copy;<\/b>&#160;2001-2008 "+
    "Ardent Edge LLC<br \/>"+
    "All Rights Reserved<br \/><br \/>"+
//    com.wjstc.Util.t('This copy of Professional Date Picker')+"<br \\/>"+com.wjstc.Util.t('is licenced to ')+"<b>YourCompany, Inc.<br \/>"+
//    "(www.YourCompany.com)<\/b>.<br \/><br \/>"+
    com.wjstc.Util.t('For latest version please visit:')+"<br \/>"+
    "<a href='http://www.ardentedge.com'>www.ardentedge.com<\/a><br \/><br \/>"+
    "<\/div><\/div>";
  return s;
}


com.wjstc.DatePicker.DatePicker.prototype._parseFormattedDateIn18n=function(inDate,format,mMap){
  var n = new Date();
  var d = n.getDate();
  var m = n.getMonth();
  var y = n.getFullYear();
  var fo=com.wjstc.Util.strCompressDateFormat(format);
  var a={s:inDate};
  var fr='';
  var c;
  for(var i=0;i<fo.length;++i){
    c=fo.charAt(i);
    fr=com.wjstc.Util.strSelectFragment(a,7);
    if(c=='s'){
      continue;
    }
    if(c=='y'){
       if(fr!=''){
         y=com.wjstc.Util.strToLimitedInt(fr,4,1,9999);
         if(y<100){
           y=(y-0)+2000;
         }
       }
    }else if(c=='d'){
       if(fr!=''){
         d=com.wjstc.Util.strToLimitedInt(fr,2,1,31);
         if(y<100){
           y=(y-0)+2000;
         }
       }
    }else{
       if(fr!=''){
         if(fr.charAt(0)>='0' && fr.charAt(0)<='9'){
           m=com.wjstc.Util.strToLimitedInt(fr,2,1,12)-1;
         }else{
           m=com.wjstc.Util.getMonthIntFromStr(fr,mMap);
         }
       }
    }
  }
  var max=com.wjstc.Util.getDaysInMonth((m-0)+1,y);
  if(d>max){
    d=max;
  }

  return {d:d,m:m,y:y}
}



com.wjstc.DatePicker.DatePicker.prototype._getPickerToday=function(){
  var now   = new Date();
  var day   = now.getDate();
  var month = now.getMonth();
  var year  = now.getFullYear();
  return this.formatDate(day,month,year,this.format);
}

com.wjstc.DatePicker.DatePicker.prototype._getPickerPreselected=function(){
  var inDate='';
  var obj=null;
  if(this.target=='window'){
    if(this.inputType=='fieldId'){
      if(document.getElementById){
        obj=com.wjstc.Common.getObjById(this.fieldId);
      }else if(document.all && document.all(this.fieldId)){
        obj=document.all(this.fieldId);
      }else if(document.layers && document.layers[this.fieldId]){
        obj=document.layers[this.fieldId];
      } 
    }else{
      obj=document.forms[this.formName].elements[this.fieldName];
    }
  }else{
     if(this.inputType=='fieldId'){
      obj=com.wjstc.Common.getObjById(this.fieldId); 
    }else{
      obj=document.forms[this.formName].elements[this.fieldName];
    }
  }
  

  var da={y:1,m:0,d:1};
  if(obj!=null && typeof(obj.value)!='undefined'){   
    inDate=obj.value;
    da=com.wjstc.DatePicker.dp._parseFormattedDateIn18n(inDate,this.format,this._mMap);
  }else{
    var ss="1. Programmer, please check for existence of:";
    if(this.inputType=='fieldId'){
      ss+="\nfield with ID: '"+this.fieldId+"' on the page.";
    }else{
      ss+="\nform with name: '"+this.formName+"' and.";
      ss+="\nfield with name: '"+this.fieldName+"' in this form.";
    }
    inDate = 'Jan 01, 0001';  
  }
  var inDa=new Date(da.y,da.m,da.d);
  if(inDa<com.wjstc.DatePicker.dp.startDate){
   inDa=com.wjstc.DatePicker.dp.startDate;
  }
  if(inDa>com.wjstc.DatePicker.dp.endDate){
   inDa=com.wjstc.DatePicker.dp.endDate;
  }
  return {da:this.formatDate(inDa.getDate(), inDa.getMonth(), inDa.getFullYear(),this.format),d:inDa.getDate(),m:inDa.getMonth(),y:inDa.getFullYear()}
}



// Displays Current Date in Date Picker
// f - form
com.wjstc.DatePicker.DatePicker.prototype._showDatePickerToday=function(){
  var f=com.wjstc.Common.getObjById('com_wjstc_DatePicker_form');
  var now   = new Date();
  var day   = now.getDate();
  var month = now.getMonth();
  var year  = now.getFullYear();
  this._displayDatePicker(f,day, month, year);
}

// Displays new Date Picker state
// f - form
com.wjstc.DatePicker.DatePicker.prototype._showDatePickerSelectedDate=function(){
  var f=com.wjstc.Common.getObjById('com_wjstc_DatePicker_form');
  var year  = f.y.value;
  var day   = f.day.value;
  var month = f.m.value;
  this._displayDatePicker(f, day, month, year);
}



// Displays another month in Date Picker
// f - form
// a - month displacement ...,-1,0,1,2,...
com.wjstc.DatePicker.DatePicker.prototype._showDatePickerNextMonth=function(a){
  var f=com.wjstc.Common.getObjById('com_wjstc_DatePicker_form');
  var year  = f.y.value;
  var day   = f.day.value;
  var month = f.m.value;
  month=month-0+(a-0);           
  if(month >11){
    month = 0;
    if(year<9998){
      year++;
    }
  }
  if(month<0){                          
    month = 11;
    if(year>1){
      year--;
    }
  }
  if(typeof(f.year)!='undefined'){
    f.year.value = year;
  }
  if(typeof(f.datePickerMonth)!='undefined'){
    f.datePickerMonth.selectedIndex=month;
  }
    this._displayDatePicker(f,day, month, year);
}


// Displays the same month for another year in Date Picker
// f - form
// a - year displacement ...,-1,0,1,2,...
com.wjstc.DatePicker.DatePicker.prototype._showDatePickerNextYear=function(a){
  var f=com.wjstc.Common.getObjById('com_wjstc_DatePicker_form');
  var year  = f.y.value;
  var day   = f.day.value;
  var month = f.m.value;
  year=year-0+(a-0);
  if(year>9999){
    year='9999';
  }
  if(year<1){
    year='0001';
  }
  if(typeof(f.year)!='undefined'){
    f.year.value = year;
  }
  this._displayDatePicker(f, day, month, year);
}

// Displays Calendar in to form f
// Similar to function com.wjstc.DatePicker.DatePicker._showDatePickerSelectedDate, but need new 3 parameters:
// day - integer - 1,2,...,31
// month - integer - 0,1,...,11
// year - integer - 1,2,...,9999
com.wjstc.DatePicker.DatePicker.prototype._displayDatePicker=function(f,day, month, year){
  var startDate= new Date(f.startDate.value);
  var endDate= new Date(f.endDate.value);
  var format=f.format.value;
  var ob=null;
  var i;
  var now = new Date();
  var nowMonth=now.getMonth();
  var nowYear=now.getFullYear();
  var nowDate=now.getDate();
  var preYear=year;
  var preMonth=month-1;
  if(preMonth<0){
    preYear=year-1;
    preMonth=11;
  }
  var postYear=year;
  var postMonth=(month-0)+1;
  if(postMonth>11){
    postYear=(year-0)+1;
    postMonth=0;
  }
  var days = com.wjstc.Util.getDaysInMonth((month-0)+1,year-0);
  var predays = (com.wjstc.Util.getDaysInMonth((preMonth-0)+1,preYear)-0)+1;
  var firstOfMonth = new Date (year, month, 1);
  var startingPos  = com.wjstc.Util.getDayOfWeek(year, month, 1)-f.firstWeekDay.value;
  if(startingPos<0){
    startingPos+=7;
  }
  if(typeof(f.datePickerMonth)!='undefined'){
    f.datePickerMonth.selectedIndex=month;
  }
  if(typeof(f.year)!='undefined'){
    f.year.value =
     ((year<10)?'0':'')+((year<100)?'0':'')+((year<1000)?'0':'')+(year-0);
  }
  f.day.value  = day;
  f.cmonth.value  = month;
  f.m.value=month;
  f.y.value=year;
  days += startingPos;
  for (i = 0; i< 42; i++){
    var k=(i+(f.firstWeekDay.value-0))%7;
    ob= com.wjstc.Common.getObjById('cal_day'+i);
    if(k==0 || k==6){
      ob.style.color=f.weekEndColor.value;
      if(i<7){
        com.wjstc.Common.getObjById('week_day'+i).style.color=f.weekEndColor.value;
        com.wjstc.Common.getObjById('week_day'+i).innerHTML=com.wjstc.Util.t(com.wjstc.DatePicker.dp.sd[k]);
      }
    }else{
      ob.style.color=f.dayColor.value;
      if(i<7){
        com.wjstc.Common.getObjById('week_day'+i).style.color=f.dayColor.value;
        com.wjstc.Common.getObjById('week_day'+i).innerHTML=com.wjstc.Util.t(com.wjstc.DatePicker.dp.sd[k]);
      }
    }
    ob.style.backgroundColor=f.bodyBackground.value;
    ob.style.borderColor=f.bodyBackground.value;
    if(i< startingPos){
      ob.innerHTML = (predays-startingPos+i)+'';
      var tmpD=new Date(preYear,preMonth,(predays-startingPos+i));
      if(tmpD<startDate || tmpD>endDate){
        ob.style.textDecoration='line-through';
      }else{
        ob.style.textDecoration='none';
      }
   
      ob.style.color=(k==0||k==6)?f.anotherMonthWeekEndColor.value:f.anotherMonthDayColor.value;
      ob.style.backgroundColor=f.anotherMonthDayBackground.value;
      f['m'+i].value=preMonth+'';
      f['y'+i].value=preYear+'';
   
      if(f.today.value==this.formatDate((predays-startingPos+i),(preMonth-0),(preYear-0),format)){
        ob.style.backgroundColor=f.todayBackground.value;
        ob.style.borderColor=f.selectedBorder.value;
      }
   
      if(f.current.value==this.formatDate((predays-startingPos+i),preMonth,preYear,format)){
        ob.style.backgroundColor=f.currentBackground.value;
        ob.style.borderColor=f.selectedBorder.value;
      }
    }else if(i< days){
      ob.innerHTML = ((i-startingPos)+1)+'';
      var tmpD=new Date(year,month,((i-startingPos)+1));
      if(tmpD<startDate || tmpD>endDate){
        ob.style.textDecoration='line-through';
      }else{
        ob.style.textDecoration='none';
      }


     ob.style.Color=(k==0||k==6)?f.weekEndColor.value:f.dayColor.value;
      f['m'+i].value=month+'';
      f['y'+i].value=year+'';
   
      if(f.today.value==this.formatDate(((i-startingPos)+1),month,year,format)){
        ob.style.backgroundColor=f.todayBackground.value;
        ob.style.borderColor=f.selectedBorder.value;
      }
   
      if(f.current.value==this.formatDate(((i-startingPos)+1),month,year,format)){
        ob.style.backgroundColor=f.currentBackground.value;
        ob.style.borderColor=f.selectedBorder.value;
      }
    }else{
      ob.innerHTML = ((i-days)+1)+'';
      var tmpD=new Date(postYear,postMonth,((i-days)+1));
      if(tmpD<startDate || tmpD>endDate){
        ob.style.textDecoration='line-through';
      }else{
        ob.style.textDecoration='none';
      }
   
      ob.style.color=(k==0||k==6)?f.anotherMonthWeekEndColor.value:f.anotherMonthDayColor.value;
      ob.style.backgroundColor=f.anotherMonthDayBackground.value;
      f['m'+i].value=postMonth+'';
      f['y'+i].value=postYear+'';
   
      if(f.today.value==this.formatDate(((i-days)+1),postMonth,postYear,format)){
        ob.style.backgroundColor=f.todayBackground.value;
        ob.style.borderColor=f.selectedBorder.value;
      }
   
      if(f.current.value==this.formatDate(((i-days)+1),postMonth,postYear,format)){
        ob.style.backgroundColor=f.currentBackground.value;
        ob.style.borderColor=f.selectedBorder.value;
      }
    }
  }
  //com.wjstc.Common.getObjById('cal_day'+((day-0)+startingPos-1)).focus();
}


// Determines if date d is today and/or preselected date
// f - form
// d - date in current format
// returns one of the strings:
// - ''
// - 'today'
// - 'preselected'
// - 'today, preselected'
com.wjstc.DatePicker.DatePicker.prototype._getDatePickerTodayCurrent=function(d){
  var f=com.wjstc.Common.getObjById('com_wjstc_DatePicker_form');
  var s='';
  if(f.today.value==d){
    s+='today';
  }
  if(f.current.value==d){
    if(s!=''){
      s+=', ';
    }
    s+='preselected';
  }
  if(s!=''){
    s=' ('+s+')';
  }
  return s;
}


// Returns day of the week for cell in row 'week day'
// cell - cell #
com.wjstc.DatePicker.DatePicker.prototype._getDatePickerCellWeekDay=function(cell){
  var ob= com.wjstc.Common.getObjById('week_day'+cell);
  var day=ob.innerHTML;
  for(var i=0;i<7;++i){
    if(day==com.wjstc.Util.t(com.wjstc.DatePicker.dp.sd[i])){
      return com.wjstc.DatePicker.dp.d[i];
    }
  }
   return 'Error';
}


 
// Generates date string representation, using format 'format'
// day - integer - 1,2,...,31
// month - integer - 0,1,..., 11
// year - integer - 1,2,..., 9999
// format - string with components:
//    %b - Abbreviated month name(Jan,...,Dec)
//    %B - Full month name(January,...,December)
//    %c - Century number (1,...,99)
//    %C - Century number (01,...,99)
//    %d - The day of the month (1,...,31)
//    %D - The day of the month (01,...,31)
//    %j - The day of the year (1,...,366)
//    %J - The day of the year (001,...,366)
//    %m - Month (1,...,12)
//    %M - Month (01,...,12)
//    %w - Abbreviated weekday name(Mon,...,Sun)
//    %W - Full weekday name(Monday,...,Sunday)
//    %y - Year without the century (00,...,99)
//    %Y - Year including the century (0001,...,9999)
 
//    %% - A literal % character
com.wjstc.DatePicker.DatePicker.prototype.formatDate=function(day,month,year,format){
   var da=new Date(year,month,day);           // date
   var week=com.wjstc.Util.getDayOfWeek(year, month, 1);// Day of Week
   var dy=com.wjstc.Util.getDayOfYear(year,month,day);  // Day of Year
   var cen=(year-(year%100))/100+1;           // century
   // month name
   var s=com.wjstc.Util.strReplStr('%b',com.wjstc.Util.t(com.wjstc.DatePicker.dp.m_s[(month-0)])+'',format+'');
   s=com.wjstc.Util.strReplStr('%B',com.wjstc.Util.t(com.wjstc.DatePicker.dp.m_l[(month-0)])+'',s);
   // century
   s=com.wjstc.Util.strReplStr('%c',(cen-0),s);
   s=com.wjstc.Util.strReplStr('%C',((cen<10)?"0":"")+(cen-0),s);
   // day of the month
   s=com.wjstc.Util.strReplStr('%d',(day-0),s);
   s=com.wjstc.Util.strReplStr('%D',((day<10)?"0":"")+(day-0),s);
   // day of the year
   s=com.wjstc.Util.strReplStr('%j',(dy-0),s);
   s=com.wjstc.Util.strReplStr('%J',((dy<10)?"0":"")+(dy-0),s);
   // month   
   s=com.wjstc.Util.strReplStr('%m',((month-0)+1)+'',s)
   s=com.wjstc.Util.strReplStr('%M',((month<9)?"0":"")+((month-0)+1)+'',s)
   // week
   s=com.wjstc.Util.strReplStr('%w',com.wjstc.Util.t(com.wjstc.DatePicker.dp.sd[week])+'',s);
   s=com.wjstc.Util.strReplStr('%W',com.wjstc.Util.t(com.wjstc.DatePicker.dp.d[week])+'',s);
   // year
   s=com.wjstc.Util.strReplStr('%y',(((year%100)<10)?"0":"")+(year%100)+'',s);
   s=com.wjstc.Util.strReplStr('%Y',((year<1000)?"0":"")+((year<100)?"0":"")+
      ((year<10)?"0":"")+year+'',s);

   s=com.wjstc.Util.strReplStr('%%','%',s);
   return s;
}
 









// returns Cell date in right format
// cell - cell #
// format - string with components:
//          'dd' - Day of the month - 01,02,...,31
//          'mm' - Month - 01,02,...,12
//          'mmm' - Month - 'Jan','Feb',...,'Dec'
//          'mmmm' - Month - 'January','February',...,'December'
//          'yy' - Two last digits of the year - 01,02,...,99
//          'yyyy' - Year - 0001,0002,...,9999

com.wjstc.DatePicker.DatePicker.prototype._getDatePickerCellDay=function(cell,format){
  var f=com.wjstc.Common.getObjById('com_wjstc_DatePicker_form');
  var ob= com.wjstc.Common.getObjById('cal_day'+cell);
  var day=ob.innerHTML;
  var month = f['m'+cell].value-0;
  var year  = f['y'+cell].value-0;
  return this.formatDate(day,month,year,format);
}



// returns true is date is between startDate and endDate
// and false otherwise
// cell - cell #

com.wjstc.DatePicker.DatePicker.prototype._isDateValid=function(cell){
  var f=com.wjstc.Common.getObjById('com_wjstc_DatePicker_form');
  var ob= com.wjstc.Common.getObjById('cal_day'+cell);
  var day=ob.innerHTML;
  var month = f['m'+cell].value-0;
  var year  = f['y'+cell].value-0;
  var da=new Date(year,month,day);
  var startDate= new Date(f.startDate.value);
  var endDate= new Date(f.endDate.value);
  return (da>=startDate && da<=endDate);
}



// Assign date from selected cell to the field of the form
// located on mother window (opener)
// cell - number of cell, which contains selected date
// format - to present selected date
// dP - datePicker Object
com.wjstc.DatePicker.DatePicker.prototype._returnDatePickerDate=function(cell,format,dP){
  var f=com.wjstc.Common.getObjById('com_wjstc_DatePicker_form');
  var newVal=this._getDatePickerCellDay(cell,format);
  if(!this._isDateValid(cell)){
    return;
  }
  var obj=null;
  if(f.target.value=='window'){
    if(f.inputType.value=='fieldId'){
      if(opener.document.getElementById){
        obj=opener.com.wjstc.Common.getObjById(f.fieldId.value);
      }else if(opener.document.all && document.all(f.fieldId.value)){
        obj=opener.document.all(f.fieldId.value);
      }else if(opener.document.layers && document.layers[f.fieldId.value]){
        obj=opener.document.layers[f.fieldId.value];
      } 
    }else{
      obj=opener.document.forms[f.formName.value].elements[f.fieldName.value];
    }
  }else{
     if(f.inputType.value=='fieldId'){
      obj=com.wjstc.Common.getObjById(f.fieldId.value) 
    }else{
      obj=document.forms[f.formName.value].elements[f.fieldName.value];
    }
  }
  if(typeof(obj.value)!='undefined'){   
    obj.value=newVal;
    obj.focus();
  }else{
    var ss="2. Programmer, please check for existence of:";
    if(f.inputType.value=='fieldId'){
       ss+="\nfield with ID: '"+f.fieldId.value+"' on the page.";
    }else{
       ss+="\nform with name: '"+f.formName.value+"' and.";
       ss+="\nfield with name: '"+f.fieldName.value+"' in this form.";
    }
  }
    
//opener.document.forms[f.formName.value].elements[f.fieldName.value].value=
//     newVal;
//opener.document.forms[f.formName.value].elements[f.fieldName.value].focus();
  if(f.target.value=='window'){
    window.close();
  }else{
    if(dP.hideSelect=='Y'){
      com.wjstc.HideSelectIE6.hs.unregisterObj('wjst_DatePickerDiv');
    }
    com.wjstc.Common.getObjById('wjst_DatePickerDiv').style.display = 'none';
    
  }
//  opener.document.forms[opener.formName].elements[opener.fieldName].value
//    = newVal;
//  opener.document.forms[opener.formName].elements[opener.fieldName].focus();
}


com.wjstc.DatePicker.DatePicker.prototype._generateDatePickerBody=function(){
var fs9=8;
var fs11=10;
var fs12=11;
var cs=40;
  var S_J=new com.wjstc.Util.StrJoin();
  S_J.set();
  if(this.target=='window'){
//    S_J.put("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
    S_J.put("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='"+com.wjstc.Util.locale+"' lang='"+com.wjstc.Util.locale+"'>");
    S_J.put("<head>");
    S_J.put("<meta http-equiv='Content-Type' content='text/html; charset="+com.wjstc.Util.t(this.dpCharset)+"' />");
    S_J.put("<title>Date Picker<\/title>");
    S_J.put("<script type='text\/javascript' src='include/Module.js'><\/script>");
    S_J.put("<script type='text\/javascript' src='include/com.wjstc.Common.js'><\/script>");
    S_J.put("<script type='text\/javascript' src='include/com.wjstc.Util.js'><\/script>");
    S_J.put("<script type='text\/javascript' src='include/com.wjstc.DatePicker.js'><\/script>");
    S_J.put("<\/head>");
    S_J.put("<body bgcolor='#ffffff'");
    S_J.put(">");
    S_J.put("<center>");
  }
    S_J.put("<script type='text/javascript'>\n");
    S_J.put("\n");
    S_J.put("</script>\n");
  var preSel=this._getPickerPreselected();
  S_J.put("<form name='com_wjstc_DatePicker_form' id='com_wjstc_DatePicker_form' action='' onsubmit='return false;'>");
  S_J.put("<input type='hidden' name='format' value='"+this.format+"' \/>");
  S_J.put("<input type='hidden' name='bodyBackground' "+
    "value='"+this.bodyBackground+"' \/>");
  S_J.put("<input type='hidden' name='anotherMonthWeekEndColor' "+
    "value='"+this.anotherMonthWeekEndColor+"' \/>");
  S_J.put("<input type='hidden' name='anotherMonthDayColor' "+
    "value='"+this.anotherMonthDayColor+"' \/>");
  S_J.put("<input type='hidden' name='todayBackground' "+
    "value='"+this.todayBackground+"' \/>");
  S_J.put("<input type='hidden' name='selectedBorder' "+
    "value='"+this.selectedBorder+"' \/>");
  S_J.put("<input type='hidden' name='currentBackground' "+
    "value='"+this.currentBackground+"' \/>");
  S_J.put("<input type='hidden' name='anotherMonthDayBackground' "+
    "value='"+this.anotherMonthDayBackground+"' \/>");
  S_J.put("<input type='hidden' name='weekEndColor' "+
    "value='"+this.weekEndColor+"' \/>");
  S_J.put("<input type='hidden' name='formName' value='"+this.formName+"' \/>");
  S_J.put("<input type='hidden' name='fieldName' value='"+this.fieldName+"' \/>");
  S_J.put("<input type='hidden' name='fieldId' value='"+this.fieldId+"' \/>");
  S_J.put("<input type='hidden' name='inputType' value='"+this.inputType+"' \/>");
  S_J.put("<input type='hidden' name='dayColor' value='"+this.dayColor+"' \/>");
  S_J.put("<input type='hidden' name='target' value='"+this.target+"' \/>");
  S_J.put("<input type='hidden' name='day' value='' \/>");
  S_J.put("<input type='hidden' name='cmonth' value='' \/>");
  S_J.put("<input type='hidden' name='m' value='' \/>");
  S_J.put("<input type='hidden' name='y' value='' \/>");
  S_J.put("<input type='hidden' name='aboutActivated' value='' \/>");
  S_J.put("<input type='hidden' name='today' value='"+this._getPickerToday()+"' \/>");
  S_J.put("<input type='hidden' name='current' value='"+preSel.da+"' \/>");
  S_J.put("<input type='hidden' name='startDate' value='"+this.startDate.toGMTString()+"' \/>");
  S_J.put("<input type='hidden' name='endDate' value='"+this.endDate.toGMTString()+"' \/>");
  S_J.put("<input type='hidden' name='firstWeekDay' "+
    "value='"+this.firstWeekDay+"' \/>");
  for(var i=0;i<42;++i){
    S_J.put("<input type='hidden' name='m"+i+"' value='0' \/>"+
            "<input type='hidden' name='y"+i+"' value='0' \/>");
  }


S_J.put("<table cellpadding='1' cellspacing='0' border='0' style='width:"+(14*this.size)+"em; font-family:Arial,Verdana,Helvetica,sans-serif; font-size:"+(0.9*this.size)+"em; font-weight:bold; text-align: center; vertical-align: middle; border: solid 2px "+this.mainBorderColor+"; background-color: "+this.bodyBackground+";'>");
S_J.put("<tr>");
S_J.put("<td align='center' style='background-color:"+this.titleBackground+";border: solid 1px "+this.mainBorderColor+"; border-width: 0px 0px 1px 0px;'>");
S_J.put("<table cellpadding='0' cellspacing='0' border='0' style='width:100%;'>");
S_J.put("<tr>");
S_J.put("<td align='center' style='background-color:"+this.titleBackground+";"+
  "height: "+(1.1*this.size)+"em; width:"+(12*this.size)+"em; border: solid 1px "+this.titleBackground+";  "+
  "padding: 1px; font-family:Helvetica,Arial,Verdana,sans-serif; font-size:"+(1.0*this.size)+"em; "+
  "font-weight:bold; vertical-align: middle;'");
  if(this.draggable=='Y' && this.target=='div'){
    S_J.put(
      " onmousedown=\"this.style.borderColor='"+this.selectedBorder+"';"+
      "this.style.backgroundColor='"+this.selectedDown+"';"+
      "this.style.cursor='move';return com.wjstc.DatePicker.dp._startDraggingDP(event);\""+
      " onmouseup=\"this.style.borderColor='"+this.selectedBorder+"';"+
      "this.style.backgroundColor='"+this.selectedOver+"';"+
      "this.style.cursor='move';\""+
      " onmouseover=\"if(typeof(com)!='undefined'){if(!com.wjstc.DatePicker.dp.dragging){this.style.borderColor='"+this.selectedBorder+"';this.style.cursor='move';"+
      "this.style.backgroundColor='"+this.selectedOver+"';");
      if(this.replaceHeader=='Y'){
        S_J.put("this.innerHTML=com.wjstc.Util.t('Drag to move...');");
      }
      S_J.put("}}\" onmouseout=\"if(typeof(com)!='undefined'){if(!com.wjstc.DatePicker.dp.dragging){this.style.borderColor='"+this.titleBackground+"'; "+
      "this.style.backgroundColor='"+this.titleBackground+"'; "+
      "this.style.cursor='default';this.innerHTML=com.wjstc.Util.t('Please pick a date');"+
      "}}\"");
  }
  S_J.put(">"+com.wjstc.Util.t('Please pick a date')+"<\/td>");

if(!com.wjstc.Util.tmp2){
  S_J.put("<td align='center' style='background-color:"+this.titleBackground+";"+
  "height: "+(1.0*this.size)+"em; width:"+(2*this.size)+"em; border: solid 1px "+this.titleBackground+"; "+
  "padding: 4px;font-family:Helvetica,Arial,Verdana,sans-serif; font-size:"+(0.9*this.size)+"em; "+
  "font-weight:bold; vertical-align: middle;text-align:center;'"+
  " onmouseover=\"this.style.borderColor='"+this.selectedBorder+"';"+
  "this.style.backgroundColor='"+this.selectedOver+"';"+
  "this.style.cursor='pointer';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg');"+
  "if(o!=null){o.innerHTML=com.wjstc.Util.t('About the Professional Date Picker');}};\""+
  " onmousedown=\"this.style.borderColor='"+this.selectedBorder+"';"+
  "this.style.backgroundColor='"+this.selectedDown+"';\""+
  " onmouseup=\"this.style.borderColor='"+this.selectedBorder+"';"+
  "this.style.backgroundColor='"+this.selectedOver+"';\" "+
  "onmouseout=\"this.style.backgroundColor='"+this.titleBackground+"'; "+
  "this.style.borderColor='"+this.titleBackground+"';"+
  "this.style.cursor='default';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg');"+
  "if(o!=null){o.innerHTML=com.wjstc.Util.t('Select Date');}};\""+
  "onclick=\"var oo=com.wjstc.Common.getObjById('calInfo');var state=(oo.innerHTML.indexOf('www.ardentedge.com')<0);"+
  "var o=com.wjstc.Common.getObjById('cal_msg'); if(o!=null){if(state){o.innerHTML=com.wjstc.Util.t('Select Date');};} "+
  "else{o.innerHTML=com.wjstc.Util.t('About the Professional Date Picker');}; "+
  "if(oo!=null){if(state){o.innerHTML=com.wjstc.Util.t('About the Professional Date Picker');oo.tinnerHTML=oo.innerHTML;"+
  "oo.innerHTML=com.wjstc.DatePicker.dp._aboutDP(com.wjstc.Common.getH(oo),"+this.size+"); com.wjstc.Common.getObjById('wjst_date_picker_tr1').style.display='none';com.wjstc.Common.getObjById('wjst_date_picker_tr2').style.display='none';}"+
  "else{oo.innerHTML=oo.tinnerHTML; com.wjstc.Common.getObjById('wjst_date_picker_tr1').style.display='';com.wjstc.Common.getObjById('wjst_date_picker_tr2').style.display='';};};\""+
  ">?</td>");
 } 
S_J.put("<td align='center' style='background-color:"+this.titleBackground+";"+
  "height: "+(1.0*this.size)+"em; width:"+(2*this.size)+"em; border: solid 1px "+this.titleBackground+";"+
  " padding: 4px; font-family:Helvetica,Arial,Verdana,sans-serif; "+
  "font-size:"+(0.9*this.size)+"em; font-weight:bold; text-align: center; vertical-align: middle;'"+
  " onmouseover=\"this.style.borderColor='"+this.selectedBorder+"';"+
  "this.style.backgroundColor='"+this.selectedOver+"';"+
  "this.style.cursor='pointer';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); "+
  "if(o!=null){o.innerHTML=com.wjstc.Util.t('Cancel');}};\""+
  " onmousedown=\"this.style.borderColor='"+this.selectedBorder+"';"+
  "this.style.backgroundColor='"+this.selectedDown+"';\""+
  " onmouseup=\"this.style.borderColor='"+this.selectedBorder+"';"+
  "this.style.backgroundColor='"+this.selectedOver+"';\""+
  " onmouseout=\"this.style.backgroundColor='"+this.titleBackground+"'; "+
  "this.style.borderColor='"+this.titleBackground+"';"+
  "this.style.cursor='default';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg');"+
  "if(o!=null){o.innerHTML=com.wjstc.Util.t('Select Date');}};\""+
    " onclick=\"");
   if(this.target=='window'){
     S_J.put("window.close();");
   }else{
     S_J.put("com.wjstc.Common.getObjById('wjst_DatePickerDiv').style.display = 'none';");
     if(this.hideSelect=='Y'){
       S_J.put("com.wjstc.HideSelectIE6.hs.unregisterObj('wjst_DatePickerDiv');");
     }
   }
  S_J.put("\"><img src='img/cancel.gif' style='vertical-align:bottom;' border='0' alt='Cancel' /><\/td>");
S_J.put("</tr>");
S_J.put("</table>");
S_J.put("</td>");
S_J.put("</tr>");
S_J.put("<tr id='wjst_date_picker_tr1'>");
S_J.put("<td align='center' style='height: "+(0.2*this.size)+"em;background-color:"+this.titleBackground+";border: solid 1px "+this.mainBorderColor+"; border-width: 0px 0px 1px 0px;'>");
S_J.put("<table cellpadding='0' cellspacing='0' border='0' style='width:100%;'>");
S_J.put("<tr>");
S_J.put("<td align='center' style='background-color:"+this.titleBackground+";"+
  "height: "+(1.0*this.size)+"em; width:"+(8.9*this.size)+"em; border: solid 1px "+this.titleBackground+";  "+
  "padding: 1px; font-family:Helvetica,Arial,Verdana,sans-serif; "+
  "font-size:"+(0.9*this.size)+"em; font-weight:bold; vertical-align: middle;'"+
  " onmouseover=\"this.style.borderColor='"+this.selectedBorder+"';"+
  "this.style.backgroundColor='"+this.selectedOver+"';"+
  "this.style.cursor='pointer';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); "+
  "if(o!=null){o.innerHTML=com.wjstc.Util.t('Select month');}};\""+
  " onmousedown=\"this.style.borderColor='"+this.selectedBorder+"';"+
  "this.style.backgroundColor='"+this.selectedDown+"';\""+
  " onmouseup=\"this.style.borderColor='"+this.selectedBorder+"';"+
  "this.style.backgroundColor='"+this.selectedOver+"';\""+
  " onmouseout=\"this.style.borderColor='"+this.titleBackground+"';"+
  " this.style.backgroundColor='"+this.titleBackground+"';"+
  " this.style.cursor='default';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg');"+
  " if(o!=null){o.innerHTML=com.wjstc.Util.t('Select Date');}};\">");
S_J.put("<select name='datePickerMonth' id='wjst_DatePickerDivMonth' style='background-color: "+this.titleBackground+"; "+
  "width: "+(9.0*this.size)+"em; border: solid 1px "+this.mainBorderColor+"; "+
  "padding: 0px; font-family:Helvetica,Arial,Verdana,sans-serif; font-size:"+(1.0*this.size)+"em; "+
  "font-weight:bold; vertical-align: middle;display:block;'"+
  " onchange=\"com.wjstc.Common.getObjById('com_wjstc_DatePicker_form').m.value=this.selectedIndex;"+
  "com.wjstc.DatePicker.dp._showDatePickerSelectedDate();\">");
  for(var i=0;i<12;++i){
    S_J.put("<option VALUE='"+i+"'>"+com.wjstc.Util.t(com.wjstc.DatePicker.dp.m_l[i])+"<\/option>");
  }
S_J.put("</select>");
S_J.put("</td>");
S_J.put("<td style='width: "+(1*this.size)+"em;height: "+(1*this.size)+"em;vertical-align: middle;'>");
S_J.put("<table border='0' cellspacing='1' cellpadding='0'>");
S_J.put("<tr>");
S_J.put("<td align='center' style='height:50%;font-size:1px;background-color:"+this.titleBackground+";border: solid 0px "+this.titleBackground+";  padding: 0px; vertical-align: bottom;' onmouseover=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedOver+"';this.style.cursor='pointer';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); if(o!=null){o.innerHTML=com.wjstc.Util.t('Show next month');}};\" onmousedown=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedDown+"';\" onmouseup=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedOver+"';\" onmouseout=\"this.style.borderColor='"+this.titleBackground+"'; this.style.backgroundColor='"+this.titleBackground+"'; this.style.cursor='default';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); if(o!=null){o.innerHTML=com.wjstc.Util.t('Select Date');}};\" onclick=\"com.wjstc.DatePicker.dp._showDatePickerNextMonth(1);\">");
S_J.put("<img src='img/a1w.gif' name='scAdd' BORDER='0' style='height: 8px; width:11px;' alt='Add' \/>");
S_J.put("</td>");
S_J.put("</tr>");
S_J.put("<tr>");
S_J.put("<td align='center' style='height:50%;font-size:1px;background-color:"+this.titleBackground+";border: solid 0px "+this.titleBackground+";padding:0px;vertical-align: top;' onmouseover=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedOver+"';this.style.cursor='pointer';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); if(o!=null){o.innerHTML=com.wjstc.Util.t('Show previous month');}};\" onmousedown=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedDown+"';\" onmouseup=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedOver+"';\" onmouseout=\"this.style.borderColor='"+this.titleBackground+"'; this.style.backgroundColor='"+this.titleBackground+"'; this.style.cursor='default';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); if(o!=null){o.innerHTML=com.wjstc.Util.t('Select Date');}};\" onclick=\"com.wjstc.DatePicker.dp._showDatePickerNextMonth(0-1);\">");
S_J.put("<img align='middle' src='img/a2w.gif' name='scSub' BORDER='0' style='height: 8px; width:11px;' alt='Subtract' \/>");
S_J.put("</td>");
S_J.put("</tr>");
S_J.put("</table>");
S_J.put("</td>");
S_J.put("<td align='center' style='background-color:"+this.titleBackground+";"+
  "width:"+(3.0*this.size)+"em; border: solid 1px "+this.titleBackground+"; "+
  "padding: 1px; font-family:Helvetica,Arial,Verdana,sans-serif; font-size:"+(0.9*this.size)+"em; "+
  "font-weight:bold; vertical-align: middle; display:block;'"+
  " onmouseover=\"this.style.borderColor='"+this.selectedBorder+"';"+
  "this.style.backgroundColor='"+this.selectedOver+"';"+
  "this.style.cursor='pointer';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); "+
  "if(o!=null){o.innerHTML=com.wjstc.Util.t('Specify year');}};\""+
  " onmousedown=\"this.style.borderColor='"+this.selectedBorder+"';"+
  "this.style.backgroundColor='"+this.selectedDown+"';\""+
  " onmouseup=\"this.style.borderColor='"+this.selectedBorder+"';"+
  "this.style.backgroundColor='"+this.selectedOver+"';\""+
  " onmouseout=\"this.style.borderColor='"+this.titleBackground+"'; "+
  "this.style.backgroundColor='"+this.titleBackground+"'; "+
  "this.style.cursor='default';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); "+
  "if(o!=null){o.innerHTML=com.wjstc.Util.t('Select Date');}};\">"+
  "<input name='year' type='text' maxlength='4' "+
  "style='background-color: "+this.titleBackground+"; "+
  "width: "+(2.4*this.size)+"em; border: solid 1px "+this.mainBorderColor+"; "+
  "padding: 0px; padding-right: 2px; ; display:block;"+
  "font-family:Helvetica,Arial,Verdana,sans-serif; "+
  "font-size:"+(1.0*this.size)+"em; font-weight:bold; text-align: right; vertical-align: middle;'"+
  " onfocus='this.select();'"+
  " onchange=\"this.value=com.wjstc.Util.strToInt(this.value,4); "+
  "if(this.value<1){this.value='0001';}; "+
  "com.wjstc.Common.getObjById('com_wjstc_DatePicker_form').y.value=this.value;"+
  "com.wjstc.DatePicker.dp._showDatePickerSelectedDate();\""+
  " onkeyup=\"var c=com.wjstc.Util.getKeyValue(event); if(c==13){this.blur();};return true;\" "+
  " onkeypress=\"return (com.wjstc.Util.isKeyInteger(event)>0);\" \/>");
S_J.put("</td>");
S_J.put("<td style='width: "+(1*this.size)+"em;height: "+(1*this.size)+"em;'>");
S_J.put("<table border='0' cellspacing='1' cellpadding='0'>");
S_J.put("<tr>");
S_J.put("<td align='center' style='height:50%;font-size:1px;background-color:"+this.titleBackground+";border: solid 0px "+this.titleBackground+";padding:0px;vertical-align: bottom;' onmouseover=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedOver+"';this.style.cursor='pointer';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); if(o!=null){o.innerHTML=com.wjstc.Util.t('Show next year');}};\" onmousedown=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedDown+"';\" onmouseup=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedOver+"';\" onmouseout=\"this.style.borderColor='"+this.titleBackground+"'; this.style.backgroundColor='"+this.titleBackground+"'; this.style.cursor='default';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); if(o!=null){o.innerHTML=com.wjstc.Util.t('Select Date');}};\" onclick=\"com.wjstc.DatePicker.dp._showDatePickerNextYear(1);\">");
S_J.put("<img align='middle' src='img/a1w.gif' name='scAdd' BORDER='0' style='height: 8px; width:11px;' alt='Add' \/>");
S_J.put("</td>");
S_J.put("</tr>");
S_J.put("<tr>");
S_J.put("<td align='center' style='height:50%;font-size:1px;background-color: "+this.titleBackground+";border: solid 0px "+this.titleBackground+";padding:0px;vertical-align: top;' onmouseover=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedOver+"';this.style.cursor='pointer';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); if(o!=null){o.innerHTML=com.wjstc.Util.t('Show previous year');}};\" onmousedown=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedDown+"';\" onmouseup=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedOver+"';\" onmouseout=\"this.style.borderColor='"+this.titleBackground+"'; this.style.backgroundColor='"+this.titleBackground+"'; this.style.cursor='default';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); if(o!=null){o.innerHTML=com.wjstc.Util.t('Select Date');}};\" onclick=\"com.wjstc.DatePicker.dp._showDatePickerNextYear(0-1);\">");
S_J.put("<img align='middle' src='img/a2w.gif' name='scSub' BORDER='0' style='height: 8px; width:11px;' alt='Subtract' \/>");
S_J.put("</td>");
S_J.put("</tr>");
S_J.put("</table>");
S_J.put("</td>");
S_J.put("</tr>");
S_J.put("</table>");
S_J.put("</td>");
S_J.put("</tr>");
S_J.put("<tr>");
S_J.put("<td colspan='1' align='center' style='background-color:"+this.titleBackground+";border: solid 1px "+this.mainBorderColor+";border-width: 0px 0px 1px 0px;'>");
S_J.put("<table border='0' cellspacing='1' cellpadding='0'>");
S_J.put("<tr id='wjst_date_picker_tr2' style='width:"+(14*this.size)+"em;'>");
S_J.put("<td align='center' style='background-color:"+this.titleBackground+";height:"+(1.1*this.size)+"em; width:"+(2*this.size)+"em; border: solid 1px "+this.titleBackground+";  padding: 0px;font-family:Helvetica,Arial,Verdana,sans-serif; font-size:"+(0.9*this.size)+"em;  font-weight:bold; vertical-align: middle;' onmouseover=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedOver+"';this.style.cursor='pointer';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); if(o!=null){o.innerHTML=com.wjstc.Util.t('Show previous year');}};\" onmousedown=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedDown+"';\" onmouseup=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedOver+"';\" onmouseout=\"this.style.borderColor='"+this.titleBackground+"'; this.style.backgroundColor='"+this.titleBackground+"'; this.style.cursor='default';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); if(o!=null){o.innerHTML=com.wjstc.Util.t('Select Date');}};\" onclick=\"com.wjstc.DatePicker.dp._showDatePickerNextYear(0-1);\">&lt;&lt;</td>");
S_J.put("<td align='center' style='background-color:"+this.titleBackground+";height:"+(1.1*this.size)+"em; width:"+(2*this.size)+"em; border: solid 1px "+this.titleBackground+";  padding: 0px;font-family:Helvetica,Arial,Verdana,sans-serif; font-size:"+(0.9*this.size)+"em; font-weight:bold; vertical-align: middle;' onmouseover=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedOver+"';this.style.cursor='pointer';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); if(o!=null){o.innerHTML=com.wjstc.Util.t('Show previous month');}};\" onmousedown=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedDown+"';\" onmouseup=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedOver+"';\" onmouseout=\"this.style.borderColor='"+this.titleBackground+"'; this.style.backgroundColor='"+this.titleBackground+"'; this.style.cursor='default';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); if(o!=null){o.innerHTML=com.wjstc.Util.t('Select Date');}};\"onclick=\"com.wjstc.DatePicker.dp._showDatePickerNextMonth(0-1);\">&lt;</td>");
S_J.put("<td align='center' style='background-color:"+this.titleBackground+";height:"+(1.1*this.size)+"em; width:"+(6*this.size)+"em; border: solid 1px "+this.titleBackground+";  padding: 0px;font-family:Helvetica,Arial,Verdana,sans-serif; font-size:"+(0.9*this.size)+"em; font-weight:bold; vertical-align: middle;' onmouseover=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedOver+"';this.style.cursor='pointer';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); if(o!=null){o.innerHTML=com.wjstc.Util.t('Show today');}};\" onmousedown=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedDown+"';\" onmouseup=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedOver+"';\" onmouseout=\"this.style.borderColor='"+this.titleBackground+"'; this.style.backgroundColor='"+this.titleBackground+"'; this.style.cursor='default';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); if(o!=null){o.innerHTML=com.wjstc.Util.t('Select Date');}};\" onclick=\"com.wjstc.DatePicker.dp._showDatePickerToday();\">"+com.wjstc.Util.t('Today')+"</td>");
S_J.put("<td align='center' style='background-color:"+this.titleBackground+";height:"+(1.1*this.size)+"em; width:"+(2*this.size)+"em; border: solid 1px "+this.titleBackground+";  padding: 0px;font-family:Helvetica,Arial,Verdana,sans-serif; font-size:"+(0.9*this.size)+"em; font-weight:bold;vertical-align: middle;' onmouseover=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedOver+"';this.style.cursor='pointer';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); if(o!=null){o.innerHTML=com.wjstc.Util.t('Show next month');}};\" onmousedown=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedDown+"';\" onmouseup=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedOver+"';\" onmouseout=\"this.style.borderColor='"+this.titleBackground+"'; this.style.backgroundColor='"+this.titleBackground+"'; this.style.cursor='default';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); if(o!=null){o.innerHTML=com.wjstc.Util.t('Select Date');}};\" onclick=\"com.wjstc.DatePicker.dp._showDatePickerNextMonth(1);\">&gt;</td>");
S_J.put("<td align='center' style='background-color:"+this.titleBackground+";height:"+(1.1*this.size)+"em; width:"+(2*this.size)+"em; border: solid 1px "+this.titleBackground+";  padding: 0px;font-family:Helvetica,Arial,Verdana,sans-serif; font-size:"+(0.9*this.size)+"em; font-weight:bold;vertical-align: middle;' onmouseover=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedOver+"';this.style.cursor='pointer';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); if(o!=null){o.innerHTML=com.wjstc.Util.t('Show next year');}};\" onmousedown=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedDown+"';\" onmouseup=\"this.style.borderColor='"+this.selectedBorder+"';this.style.backgroundColor='"+this.selectedOver+"';\" onmouseout=\"this.style.borderColor='"+this.titleBackground+"'; this.style.backgroundColor='"+this.titleBackground+"'; this.style.cursor='default';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg'); if(o!=null){o.innerHTML=com.wjstc.Util.t('Select Date');}};\" onclick=\"com.wjstc.DatePicker.dp._showDatePickerNextYear(1);\">&gt;&gt;</td>");
S_J.put("</tr>");
S_J.put("</table>");
S_J.put("</td>");
S_J.put("</tr>");
S_J.put("<tr>");
S_J.put("<td>");
S_J.put("<div id='calInfo'>");
S_J.put("<table id='calCells' cellpadding='0' cellspacing='0' border='0'>");
S_J.put("<tr style='background-color:"+this.weekBackground+";'>");
S_J.put(" ");
  for(var i=0;i<7;++i){
    var k=(i+(this.firstWeekDay-0))%7;
  S_J.put("<td align='center' id='week_day"+i+"' style='background-color:"+this.weekBackground+"; ");
  S_J.put("  height:"+(1.1*this.size)+"em; width:"+(2*this.size)+"em; border: solid 1px "+this.weekBackground+";   ");
  S_J.put("  padding-right: 4px;font-family:Helvetica,Arial,Verdana,sans-serif;  ");
  S_J.put("  font-size:"+(0.9*this.size)+"em; font-weight:normal;vertical-align: middle;'  ");
  S_J.put(" onmouseover=\"this.style.borderColor='"+this.selectedBorder+"'; ");
  S_J.put("  this.style.backgroundColor='"+this.selectedOver+"'; ");
  S_J.put("  this.style.cursor='pointer';  ");
  S_J.put("  if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg');  ");
  S_J.put("  if(o!=null){ ");
  S_J.put("  o.innerHTML=com.wjstc.Util.t('Show '+com.wjstc.DatePicker.dp._getDatePickerCellWeekDay("+i+")+' first');}};\"  ");
  S_J.put(" onmousedown=\"this.style.borderColor='"+this.selectedBorder+"'; ");
  S_J.put("  this.style.backgroundColor='"+this.selectedDown+"';\"  ");
  S_J.put(" onmouseup=\"this.style.borderColor='"+this.selectedBorder+"'; ");
  S_J.put("  this.style.backgroundColor='"+this.selectedOver+"';\"  ");
  S_J.put(" onmouseout=\"this.style.borderColor='"+this.weekBackground+"'; ");
  S_J.put("  this.style.backgroundColor='"+this.weekBackground+"';  ");
  S_J.put("  this.style.cursor='default';if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg');  ");
  S_J.put("  if(o!=null){o.innerHTML=com.wjstc.Util.t('Select Date');}};\" ");
  S_J.put(" onclick=\"com.wjstc.Common.getObjById('com_wjstc_DatePicker_form').firstWeekDay.value= ");
  S_J.put("  (("+i+"-0)+(com.wjstc.Common.getObjById('com_wjstc_DatePicker_form').firstWeekDay.value-0))%7; ");
  S_J.put("   com.wjstc.DatePicker.dp._showDatePickerSelectedDate();\">"+com.wjstc.Util.t(com.wjstc.DatePicker.dp.sd[k])+"</td>");
}
  for(var i=0;i<42;++i){
    if(i%7==0){
      S_J.put("<\/tr><tr style='padding: 1px'>");
    }
    var k=(i%7)+(this.firstWeekDay-0);
    if(k>6){
      k=k-7;
    }
   S_J.put("<td align='right' id='cal_day"+i+"' style=' background-color:"+this.bodyBackground+"; ");
  S_J.put("  height:"+(1.1*this.size)+"em; width:"+(2*this.size)+"em; border: solid 1px "+this.bodyBackground+";padding-right: 6px;  ");
  S_J.put("  font-family:Helvetica,Arial,Verdana,sans-serif;font-size:"+(1.0*this.size)+"em;  ");
  S_J.put("  font-weight:bold;vertical-align: middle;'  ");
  S_J.put(" onmouseover=\"this.style.borderColor='"+this.selectedBorder+"'; ");
  S_J.put("  this.style.backgroundColor='"+this.selectedOver+"';this.style.cursor='pointer';  ");
  S_J.put("  if(typeof(com)!='undefined'){var o=com.wjstc.Common.getObjById('cal_msg');  ");
  S_J.put("  var d=com.wjstc.DatePicker.dp._getDatePickerCellDay("+i+",'"+this.format+"'); ");
  S_J.put(" if(o!=null){o.innerHTML=d+com.wjstc.DatePicker.dp._getDatePickerTodayCurrent(d);}};\" ");
  S_J.put(" onmousedown=\"this.style.borderColor='"+this.selectedBorder+"';  ");
  S_J.put("  this.style.backgroundColor='"+this.selectedDown+"';\" ");
  S_J.put("  onmouseup=\"this.style.borderColor='"+this.selectedBorder+"'; ");
  S_J.put("  this.style.backgroundColor='"+this.selectedOver+"';\" ");
  S_J.put(" onmouseout=\"if(typeof(com)!='undefined'){var d=com.wjstc.DatePicker.dp._getDatePickerCellDay("+i+",'"+this.format+"');  ");
  S_J.put("  if(com.wjstc.Common.getObjById('com_wjstc_DatePicker_form').current.value!=d &&  ");
  S_J.put("  com.wjstc.Common.getObjById('com_wjstc_DatePicker_form').today.value!=d){ ");
  S_J.put("  this.style.borderColor='"+this.bodyBackground+"';  ");
  S_J.put("  if(com.wjstc.Common.getObjById('com_wjstc_DatePicker_form')['m'+"+i+"].value== ");
  S_J.put("  com.wjstc.Common.getObjById('com_wjstc_DatePicker_form').cmonth.value) ");
  S_J.put("  {this.style.backgroundColor='"+this.bodyBackground+"';}else{this.style.backgroundColor='"+this.anotherMonthDayBackground+"';}} ");
  S_J.put("  else{this.style.borderColor='"+this.mainBorderColor+"'; ");
  S_J.put("  this.style.backgroundColor= ");
  S_J.put("  ((com.wjstc.Common.getObjById('com_wjstc_DatePicker_form').current.value==d)?'"+this.currentBackground+"':'"+this.todayBackground+"');};  ");
  S_J.put("  this.style.cursor='default';var o=com.wjstc.Common.getObjById('cal_msg');  ");
  S_J.put("  if(o!=null){o.innerHTML=com.wjstc.Util.t('Select Date');}};\" ");
  S_J.put(" onclick=\"com.wjstc.DatePicker.dp._returnDatePickerDate("+i+",'"+this.format+"',com.wjstc.DatePicker.dp);\">"+i+"<\/td>");
  }

  S_J.put("<\/tr><\/table><\/div><\/td><\/tr>");

  S_J.put("<tr><td colspan='1'  id='cal_msg' style='background-color: "+
     this.footerBackground+"; height: "+(1.1*this.size)+"em; width:"+(14*this.size)+"em; border: solid 1px "+
     this.mainBorderColor+"; border-width: 1px 0px 0px 0px; padding: 4px; "+
     "font-family:Helvetica,Arial,Verdana,sans-serif; font-size:"+(1.0*this.size)+"em; "+
     "font-weight:normal; text-align: center; vertical-align: middle;' ");
     if(this.draggable=='Y' && this.target=='div'){
       S_J.put(
        " onmousedown=\"this.style.borderColor='"+this.selectedBorder+"';"+
        "this.style.backgroundColor='"+this.selectedDown+"';"+
        "this.style.cursor='move';return com.wjstc.DatePicker.dp._startDraggingDP(event);\""+
        " onmouseup=\"this.style.borderColor='"+this.selectedBorder+"';"+
        "this.style.backgroundColor='"+this.selectedOver+"';"+
        "this.style.cursor='move';\""+
        " onmouseover=\"if(typeof(com)!='undefined'){if(!com.wjstc.DatePicker.dp.dragging){this.style.borderColor='"+this.selectedBorder+"';"+
        "this.style.backgroundColor='"+this.selectedOver+"';this.style.cursor='move';");
        if(this.replaceHeader=='Y'){
          S_J.put("this.innerHTML=com.wjstc.Util.t('Drag to move...');");
        }
        S_J.put("this.innerHTML=com.wjstc.Util.t('Drag to move...');}}\""+
        " onmouseout=\"if(typeof(com)!='undefined'){if(!com.wjstc.DatePicker.dp.dragging){this.style.borderColor='"+this.mainBorderColor+"'; "+
        "this.style.backgroundColor='"+this.titleBackground+"'; "+
       "this.style.cursor='default';this.innerHTML=com.wjstc.Util.t('Select Date');}}\"");
     }
   S_J.put(">"+com.wjstc.Util.t('Select Date')+"<\/td><\/tr>");

  S_J.put("<\/table>");
  S_J.put("<\/form>");
  S_J.put("<\/center>");
  if(this.target=='window'){
    S_J.put("<script type='text/javascript'>\n");
    S_J.put("com.wjstc.DatePicker.dp._displayDatePicker(com.wjstc.Common.getObjById('com_wjstc_DatePicker_form'), "+preSel.d+", "+preSel.m+", "+preSel.y+");\n");
    S_J.put("\n");
    S_J.put("</script>");
  }
  S_J.put("<\/body>");
  S_J.put("<\/html>");
  return {s:S_J.get(),d:preSel.d,m:preSel.m,y:preSel.y};
}



com.wjstc.DatePicker.DatePicker.prototype._setDatePickerStartPosition=function(po,o){
  var va=this.align.charAt(0); 
  var ha=this.align.charAt(1);
  com.wjstc.Common.moveToXY(po,10000,10000);
  po.style.display = "block";
  var w = com.wjstc.Common.getW(po);
  var h = com.wjstc.Common.getH(po);
  var oX=com.wjstc.Common.getX(o);
  var oY=com.wjstc.Common.getY(o);
  var oW=com.wjstc.Common.getW(o);
  var oH=com.wjstc.Common.getH(o);
/*
  // vertical alignment
  if(va=='T'){
      com.wjstc.Common.moveToTop(po,oY-h);
  }else if(va=='C'){
      com.wjstc.Common.moveToTop(po,oY + ((oH - h)>>1));
  }else if(va=='t'){
      com.wjstc.Common.moveToTop(po,oY + oH - h);
  }else if(va=='b'){
      com.wjstc.Common.moveToTop(po,oY-1);
  }else{ // 'B'
      com.wjstc.Common.moveToTop(po,oY + oH);
  }
  // horizontal alignment
  if(ha=='L'){
      com.wjstc.Common.moveToLeft(po,oX-w);
  }else if(ha=='R'){
      com.wjstc.Common.moveToLeft(po,oX + oW);
  }else if(ha=='C'){
      com.wjstc.Common.moveToLeft(po,oX + ((oW - w)>>1));
  }else if(ha=='l'){
      com.wjstc.Common.moveToLeft(po,oX + (oW - w));
  }else{  // r
      com.wjstc.Common.moveToLeft(po,oX);
  }
*/
  var mY=oY + oH;  // 'B'
  // vertical alignment
  if(va=='T'){
      mY=oY-h;
  }else if(va=='C'){
      mY=oY + ((oH - h)>>1);
  }else if(va=='t'){
      mY=oY + oH - h;
  }else if(va=='b'){
      mY=oY-1;
  } // else 'B'
  
  var mX=oX; // 'r''
  // horizontal alignment
  if(ha=='L'){
      mX=oX-w;
  }else if(ha=='R'){
      mX=oX + oW;
  }else if(ha=='C'){
      mX=oX + ((oW - w)>>1);
  }else if(ha=='l'){
      mX=oX + (oW - w);
  } // else 'r' 


  var poX = (com.wjstc.Util.getViewportW()-com.wjstc.Common.getW(po)-20);// + com.wjstc.Common.getPageScrollX();
  var poY = (com.wjstc.Util.getViewportH()-com.wjstc.Common.getH(po)-20);// + com.wjstc.Common.getPageScrollY();
  if(poX<mX){
    mX=poX;
  }
  if(poY<mY){
    mY=poY;
  }
  com.wjstc.Common.moveToXY(po,mX,mY);

  po.style.display = 'block';
  this.pw = w;
  this.ph = h;
  com.wjstc.HideSelectIE6.hs.registerObj('wjst_DatePickerDiv');
}



// fieldId - string - Form Object field input Id

com.wjstc.DatePicker.DatePicker.prototype.showDatePickerInWindow=function(fieldId,startDateIn,endDateIn,locale){
var ws=265;
if(this.size=='small'){
  ws=230;
}
if(this.size=='smaller'){
  ws=250;
}
if(this.size=='larger'){
  ws=290;
}
if(this.size=='largest'){
  ws=330;
}
if(typeof(locale)!='undefined'){
  com.wjstc.Util.setLocale(locale); 
}


  if(typeof(startDateIn)!='undefined'){
    this.startDateIn=startDateIn;
  }
  if(typeof(endDateIn)!='undefined'){
    this.endDateIn=endDateIn;
  }
  this._setLanguageDP();
/*
if(typeof(startDate)!='undefined'){
    var da=com.wjstc.DatePicker.DatePicker._parseFormattedDateIn18n(startDate,this.format,this._mMap);
    this.startDate=new Date(da.y,da.m,da.d);
}
if(typeof(endDate)!='undefined'){
    var da=com.wjstc.DatePicker.DatePicker._parseFormattedDateIn18n(endDate,this.format,this._mMap);
    this.endDate=new Date(da.y,da.m,da.d);
}
*/
  this.fieldId=fieldId;
  this.inputType='fieldId';
  this.target='window';
  var reportw=window.open("","DatePicker",
    "toolbar=no,location=no,directories=no,status=no,menubar=no,"+
    "scrollbars=no,resizable=no,width="+ws+",height="+ws+",left=100,top=40"+
    ",screenX=100,screenY=40,titlebar=no");
  var d=reportw.document;
  d.write(this._generateDatePickerBody().s);
  d.close();
  return;
}

com.wjstc.DatePicker.DatePicker.prototype.showDatePickerInWindowForm=function(formName,fieldName,startDateIn,endDateIn,locale){
var ws=265;
if(this.size=='small'){
  ws=230;
}
if(this.size=='smaller'){
  ws=250;
}
if(this.size=='larger'){
  ws=290;
}
if(this.size=='largest'){
  ws=330;
}
if(typeof(locale)!='undefined'){
  com.wjstc.Util.setLocale(locale); 
}
  if(typeof(startDateIn)!='undefined'){
    this.startDateIn=startDateIn;
  }
  if(typeof(endDateIn)!='undefined'){
    this.endDateIn=endDateIn;
  }
  this._setLanguageDP();
/*
if(typeof(startDate)!='undefined'){
    var da=com.wjstc.DatePicker.DatePicker._parseFormattedDateIn18n(startDate,this.format,this._mMap);
    this.startDate=new Date(da.y,da.m,da.d);
}
if(typeof(endDate)!='undefined'){
    var da=com.wjstc.DatePicker.DatePicker._parseFormattedDateIn18n(endDate,this.format,this._mMap);
    this.endDate=new Date(da.y,da.m,da.d);
}
*/
  this.formName=formName;
  this.fieldName=fieldName;
  this.inputType='formfield';
  this.target='window';
  var reportw=window.open("","DatePicker",
    "toolbar=no,location=no,directories=no,status=no,menubar=no,"+
    "scrollbars=no,resizable=no,width="+ws+",height="+ws+",left=100,top=40"+
    ",screenX=100,screenY=40,titlebar=no");
  var d=reportw.document;
  d.write(this._generateDatePickerBody().s);
  d.close();
  return;
}



com.wjstc.DatePicker.DatePicker.prototype._makeDatePickerDiv=function(cp){
  var bd = document.getElementsByTagName( 'body' )[0];
  var poi = com.wjstc.Common.getObjById('wjst_DatePickerDiv');
  if(poi==null){
    poi = document.createElement('div');
    poi.setAttribute( 'id','wjst_DatePickerDiv');
    poi.style.position='absolute';
    poi.style.zIndex = cp.zIndexValue;
    poi.style.display = 'none';
    poi.style.background='transparent';
    poi.innerHTML = "";
    bd.appendChild(poi);
  }
}


com.wjstc.DatePicker.DatePicker.prototype.showDatePickerInDiv=function(fieldId,startDateIn,endDateIn,locale){
if(typeof(locale)!='undefined'){
  com.wjstc.Util.setLocale(locale); 
}
  if(typeof(startDateIn)!='undefined'){
    this.startDateIn=startDateIn;
  }
  if(typeof(endDateIn)!='undefined'){
    this.endDateIn=endDateIn;
  }
  this._setLanguageDP();
/*
if(typeof(startDate)!='undefined'){
    var da=com.wjstc.DatePicker.DatePicker._parseFormattedDateIn18n(startDate,this.format,this._mMap);
    this.startDate=new Date(da.y,da.m,da.d);
}
if(typeof(endDate)!='undefined'){
    var da=com.wjstc.DatePicker.DatePicker._parseFormattedDateIn18n(endDate,this.format,this._mMap);
    this.endDate=new Date(da.y,da.m,da.d);
}
*/
  this.fieldId=fieldId;
  this.inputType='fieldId';
  this.target='div';
  this._makeDatePickerDiv(this);
  var o=com.wjstc.Common.getObjById(fieldId);
  var po=com.wjstc.Common.getObjById('wjst_DatePickerDiv');
  
  var b= this._generateDatePickerBody();
  po.innerHTML = b.s;
  this._displayDatePicker(com.wjstc.Common.getObjById('com_wjstc_DatePicker_form'), b.d, b.m, b.y);
  this._setDatePickerStartPosition(po,o);
}


// fieldId - string - Form Object field input Id
com.wjstc.DatePicker.DatePicker.prototype.showDatePickerInDivForm=function(formName,fieldName,startDateIn,endDateIn,locale){
if(typeof(locale)!='undefined'){
  com.wjstc.Util.setLocale(locale); 
}
  if(typeof(startDateIn)!='undefined'){
    this.startDateIn=startDateIn;
  }
  if(typeof(endDateIn)!='undefined'){
    this.endDateIn=endDateIn;
  }
  this._setLanguageDP();
/*
  if(typeof(startDate)!='undefined'){
    var da=com.wjstc.DatePicker.DatePicker._parseFormattedDateIn18n(startDate,this.format,this._mMap);
    this.startDate=new Date(da.y,da.m,da.d);
  }
  if(typeof(endDate)!='undefined'){
    var da=com.wjstc.DatePicker.DatePicker._parseFormattedDateIn18n(endDate,this.format,this._mMap);
    this.endDate=new Date(da.y,da.m,da.d);
  }
*/
  this.formName=formName;
  this.fieldName=fieldName;
  this.inputType='formfield';
  this.target='div';
  this._makeDatePickerDiv(this);
  var o=document.forms[formName].elements[fieldName];
  var po=com.wjstc.Common.getObjById('wjst_DatePickerDiv');
  var b= this._generateDatePickerBody();
  po.innerHTML = b.s;
  this._displayDatePicker(com.wjstc.Common.getObjById('com_wjstc_DatePicker_form'), b.d, b.m, b.y);
  this._setDatePickerStartPosition(po,o);
}


// ------------------ Drag and Drop -------------------------


com.wjstc.DatePicker.DatePicker.prototype._startDraggingDP=function(e){
  if ( typeof(com.wjstc.DatePicker.dp)== "undefined"){
    return false;
  }
  com.wjstc.DatePicker.dp.dragging=true;
  
  var po=com.wjstc.Common.getObjById('wjst_DatePickerDiv');
  com.wjstc.DatePicker.dp.disX = com.wjstc.Common.getMouseScrollX(e) - com.wjstc.Common.getX(po);
  com.wjstc.DatePicker.dp.disY = com.wjstc.Common.getMouseScrollY(e) - com.wjstc.Common.getY(po);
  com.wjstc.Util.objAddEvent(window.document,"mousemove",com.wjstc.DatePicker.dp._goDraggingDP);
  com.wjstc.Util.objAddEvent(window.document,"mousedown",com.wjstc.DatePicker.dp._goDraggingDP);
  com.wjstc.Util.objAddEvent(window.document,"mouseup",com.wjstc.DatePicker.dp._stopDraggingDP);
  com.wjstc.HideSelectIE6.hs.hideShowHS();
  if(typeof(document.body.style.zoom)!='undefined' && com.wjstc.Common.ZoomSensor.getZoom()!=1.0){
    com.wjstc.DatePicker.dp.dp_body=po.innerHTML;
  }

  return false;
};

com.wjstc.DatePicker.DatePicker.prototype._goDraggingDP=function(e){
  if ( typeof(com.wjstc.DatePicker.dp)== "undefined"){
    return false;
  }

  var _fX=com.wjstc.Common.getMouseScrollX(e)-com.wjstc.DatePicker.dp.disX;
  var _fY=com.wjstc.Common.getMouseScrollY(e)-com.wjstc.DatePicker.dp.disY;
  var _mX=com.wjstc.Util.getViewportW()-com.wjstc.DatePicker.dp.disX-30;
  var _mY=com.wjstc.Util.getViewportH()-com.wjstc.DatePicker.dp.disY-30;
  if(_fX>_mX){_fX=_mX;};
  if(_fY>_mY){_fY=_mY;};
  if(_fX<0){
    _fX=0;
  }
  if(_fY<0){
    _fY=0;
  }


  com.wjstc.Common.moveToXY('wjst_DatePickerDiv',_fX,_fY);
  if(com.wjstc.DatePicker.dp.hideSelect=='Y'){
    com.wjstc.HideSelectIE6.hs.hideShowHS();
  }

  if(typeof(document.body.style.zoom)!='undefined' && com.wjstc.Common.ZoomSensor.getZoom()!=1.0){
     var po=com.wjstc.Common.getObjById('wjst_DatePickerDiv');
     po.innerHTML= com.wjstc.DatePicker.dp.dp_body;
  }
  return false;
};

com.wjstc.DatePicker.DatePicker.prototype._stopDraggingDP=function(){
  com.wjstc.DatePicker.dp.dragging=false;
  com.wjstc.Util.objRemoveEvent(document,'mousemove',com.wjstc.DatePicker.dp._goDraggingDP);
  com.wjstc.Util.objRemoveEvent(document,'mousedown',com.wjstc.DatePicker.dp._goDraggingDP);
  com.wjstc.Util.objRemoveEvent(document,'mouseup',com.wjstc.DatePicker.dp._stopDraggingDP);
  return false;
};

com.wjstc.DatePicker.DatePicker.prototype.setDateFormat=function(_f){
  this.format=(typeof(_f)!='undefined')?_f:'%m %D, %Y'; ;
};


com.wjstc.DatePicker.DatePicker.prototype.setDatePicker=function(oDatePickerConfigs){
  com.wjstc.Util.parseObjectConfigs(this, com.wjstc.DatePicker.oDefaultDatePickerConfig, 'com.wjstc.DatePicker.DatePicker.prototype.setDatePicker=function(com.wjstc.DatePicker.oDefaultDatePickerConfig)', 'com.wjstc.DatePicker.oDefaultDatePickerConfig');
  if(typeof(oDatePickerConfigs)=='undefined'){
    return this;
  }
  if(!oDatePickerConfigs || typeof(oDatePickerConfigs) != 'object') {
    throw new Error("Parameter oDatePickerConfigs=["+oDatePickerConfigs+"] in function 'com.wjstc.DatePicker.DatePicker.prototype.setDatePicker=function(oDatePickerConfigs)' is not an Object .");
    return this;
  }  
  com.wjstc.Util.parseObjectConfigs(this, oDatePickerConfigs, 'com.wjstc.DatePicker.DatePicker.prototype.setDatePicker=function(oDatePickerConfigs)', 'oDatePickerConfigs');

  this._setLanguageDP();
  return this;
}

com.wjstc.DatePicker.dp=new com.wjstc.DatePicker.DatePicker(
//                        {simple:'yes', advanced:'yes', footer:'yes'}, // Type
                        1.0,   // Date picker size: float
                        '%b %D, %Y', // Date format '%b %D, %Y','%M/%D/%y','%y-%M-%D', '%B %D, %Y'
                        'Y',       // draggable
                        'Y',       // hideSelect
                        'N',      // replaceHeader
                        98,         // zIndexValue
                        0,          // firstWeekDay;
                        'Mar 05, 2008', // start Date
                        'Mar 25, 2008', // end Date
                        '#000000',  // dayColor;
                        '#FF3300',  // weekEndColor;
                        '#FAF7E6',  // titleBackground;
                        '#999999',  // this.mainBorderColor;
                        '#D7D4C3',  // weekBackground
                        '#F6F6F6',  // bodyBackground;
                        '#FFFFFF',  // anotherMonthDayBackground;
                        '#999999',  // anotherMonthDayColor;
                        '#FF9999',  // anotherMonthWeekEndColor
                        '#FAF7E6',  // footerBackground;
                        '#FFFF99',  // todayBackground;
                        '#99FF99',  // currentBackground;
                        '#999999',  // selectedBorder;
                        '#FFD494',  // selectedOver;
                        '#FFB874'   // selectedDown;
                        );

com.wjstc.DatePicker.dp.setDatePicker(com.wjstc.DatePicker.oDefaultDatePickerConfig);


