// common functions
// DO NOT USE PROTOTYPE EXTENSIONS ! they kill IE on different ways, depend on version

// arrIndexOf(array,  value [[,begin], strict] ) - Return index of the first element that matches value
function arrIndexOf(arr, v, b, s ) {
    for( var i = +b || 0, l = arr.length; i < l; i++ ) {
        if( arr[i]===v || s && arr[i]==v ) { return i; };
        };
    return -1;
    }

// strTrim - Return string without leading/trailing whitespaces
function strTrim(data) {
    return String(data).replace(/^\s+|\s+$/g, '');
    }

// get selected text in in window
function getSelectionObj(){
    // methods usable with getSelection object:
    // get plaint text with    getSelectionObj().toString()
    // .anchorNode      object where the selection belongs
    // .containsNode    ???     (use FireBug console, enter "window.getSelection()  to inspect object DOM)
    if(window.getSelection){
        return window.getSelection();
    } else if(document.getSelection) {
        return document.getSelection();
//     } else if(document.selection) {
        // need to check object features
        };
    alert('common.js getSelectionObj unsupported');
    return '';
    }

function removeOptions(selectNode){
    // remove all options from SELECT tag
    var optL = selectNode.getElementsByTagName('option');
    while(optL.length)  selectNode.removeChild(optL[0]);
    }
function createOptions(selectNode, aTexts, aValues){
    // create complete new OPTIONs in a SELECT tag
    // caution - if there are more former options as aTexts.length, the old remains at the end
    // new Option(text, value, default selected, selected)
    for (var i=0; i < aTexts.length; i++){
        selectNode.options[i] = new Option(aTexts[i], strTrim(aValues[i]), i==0, i==0);
        };
    }
function replaceOptions(selectNode, aTexts, aValues){
    // shortcut for remove all old and create new options in SELECT tag
    removeOptions(selectNode);
    createOptions(selectNode, aTexts, aValues);
    }

function setClass(elem, _class){
    elem.setAttribute('class', _class);
    // IE6+7 hack
    elem.setAttribute('className', _class);
    }

function getClass(elem){
    var _class = elem.getAttribute('class');
    // IE6+7 hack
    if(!_class)     _class = elem.getAttribute('className');
    return _class;
    }

// get dictionary-like object with ULR pramameters
function getRequestArgsD() {
    // Build an empty URL structure in which we will store the individual query values by key.
    var hrefParmsD = {};
    // Use the String::replace method to iterate over each name-value pair in the query string.
    // Dynamic function used by this "walker" adds key=value pairs to the object
    window.location.search.replace(
        new RegExp( "([^?=&]+)(=([^&]*))?", "g" ),              // search iterator
        function( $0, $1, $2, $3 ) {hrefParmsD[ $1 ] = $3; }    // callBack function insted real replace
        );
    return hrefParmsD;
    }

// Populate input_nodes with names of every child of SELECT/INPUT/TEXTAREA type
function getChildInputNames(node, namesL) {
    // If node is of type which holds a user value -- store its name
    if ( node.nodeName == 'SELECT' || node.nodeName == 'INPUT' || node.nodeName == 'TEXTAREA' ) {
        namesL.push(node.getAttribute('name'));
    }
    // Run recursion on child nodes
    for (var i=0; i<node.childNodes.length; i++) {
        getChildInputNames(node.childNodes[i], namesL);
    }
    // Return node names list
    return namesL;
    }

function getParentForm(elem, /* optional */ doTrace){
    // find enclosing form node (if any) also for non-input elements, where `elem.form == undefined`
    if(!elem) throw 'ERROR getParentForm elem '+ elem;
    var form = null;
    try{
        if(elem && elem.form != undefined) form = elem.form;
        // special case of submit button embedded in <a> tag     !!! not working in IE7
        if(elem.firstElementChild && elem.firstElementChild.form) form = elem.firstElementChild.form;
    } catch (err) {};   // pass
    // loop through parents...
    var e = elem;
    if(!form){
        while(e && (e = e.parentNode) ){
            if(e.elements != undefined) form = e;
            };
        };
    // no other chance than loop through all forms...
    var trace = 'getParentForm TRACE: ' + document.forms.length;
    if(!form){
        for(var idx=0;idx<document.forms.length;idx++){
            var tmpForm = document.forms[idx];
            trace += '\n FORM: '+ tmpForm.name +': '+ tmpForm.elements.length;
            for(var i=0;i<tmpForm.elements.length;i++){
                e = tmpForm.elements[i];
                trace += ' e: '+ e +' '+ e.name +',';
                if(tmpForm.elements[i].name == elem.name) {
                    form = tmpForm;
                    break;
                    };
                };
            if(form) break;
            };
        };
    trace += '\n form: '+ form +'\n';
    if(doTrace) return trace;
    if(form) return form;
    return undefined;
    }

function inputReduceSpaces(inpElem){
    if(inpElem.value.search(/^ /) != -1)
        inpElem.value = inpElem.value.replace(/^ /, '');
    if(inpElem.value.search(/  /) != -1)
        inpElem.value = inpElem.value.replace(/  /g, ' ');
    }
function inputOnlyAlphaNumeric(inpElem){
    if(inpElem.value.search(/[^a-zA-Z0-9]/) != -1)
        inpElem.value = inpElem.value.replace(/[^a-zA-Z0-9]/g, '');
    }
function inputOnlyNumeric(inpElem){
    /* this work fine in FF, but in IE it move cursor every time to the end of field
    inpElem.value = inpElem.value.replace(/,/, '.').replace(/[^0-9\.]/g, '');
    while(inpElem.value.search(/\..*\./) > -1) inpElem.value = inpElem.value.replace(/\./, '');
    inpElem.value = inpElem.value.replace(/^00/, '0').replace(/^\.(.+)/, "0.$1")        //.replace(/^0(\d)/, "$1");
    */
//     alert('inputOnlyNumeric '+inpElem.name+': '+inpElem.value);
    // slow method for IE:
    if(inpElem.value.search(/,/) != -1)
        inpElem.value = inpElem.value.replace(/,/, '.');
    if(inpElem.value.search(/[^0-9\.]/) != -1)
        inpElem.value = inpElem.value.replace(/[^0-9\.]/g, '');
    while(inpElem.value.search(/\..*\./) > -1)
        inpElem.value = inpElem.value.replace(/\./, '');
    if(inpElem.value.search(/^00/) != -1)
        inpElem.value = inpElem.value.replace(/^00/, '0');
    if(inpElem.value.search(/^\.(.+)/) != -1)
        inpElem.value = inpElem.value.replace(/^\.(.+)/, "0.$1");
    }
function inputOnlyDigits(inpElem){
    if(inpElem.value.search(/[^0-9]/) != -1)
        inpElem.value = inpElem.value.replace(/[^0-9]/g, '');
    }
function inputOnlyPhoneNumber(inpElem){
    if(inpElem.value.search(/[^0-9 \-\/]/) != -1)
        inpElem.value = inpElem.value.replace(/[^0-9 \-\/]/g, '');
    }
function inputOnlyURLWithoutParams(inpElem){
    if(inpElem.value.search(/[^a-zA-Z0-9\-_:~\.\/]/) != -1)
        inpElem.value = inpElem.value.replace(/[^a-zA-Z0-9\-_:~\.\/]/g, '');
    }

function isElemDisabled(elem){
    // Return TRUE if givem 'button' element is disabled
    if(elem.getAttribute('disabled') ) return true;
    return false;
    }

function enableInput(elem, inHTML){
    // Make specified 'input' element enabled. Enable in HTML if requested
    // and set appropriate class
    if(inHTML == null)
        inHTML = false;
    setClass(elem, 'enabled');
    // Set to false && remove to be sure
    if(inHTML) {
        elem.disabled = false;
        elem.removeAttribute('disabled');
        }
    }
function disableInput(elem, inHTML){
    // Make specified 'input' element disabled. Disable in HTML if requested
    //and set appropriate class
    if(inHTML == null)
        inHTML = false;
    setClass(elem, 'disabled');
    if(inHTML)
        elem.disabled = 'true';
    }
function isButtonDisabled(elem){
    // Return TRUE if givem 'button' element is disabled
    if(elem.getAttribute('disabled') || elem.getAttribute('class').search('disabled') > -1
        ) return true;
    return false;
    }

// handler for NEW CSS buttons
function disableButton(elem, /* optional */ btnClass){
    // Make specified 'button' element disabled and store its class for re-use while enabling
    // return false, if action was not possible or true, if it is a CSS Button, was enabled and now is disabled
    if(elem.nodeName != 'BUTTON') return false;
    var btn_class = getClass(elem) || '';
    // if already disabled do nothing
    if(elem.getAttribute('disabled') || btn_class.search('disabled') > -1) return false;

    if(btn_class.search('cssBtn') == -1){
        // handle old style buttons with bg image
        var disabledClass = btnClass || 'disabledButton';
    } else {
        // store the original class to allow simple restore of size and color
        elem.setAttribute('btn_class', btn_class);
        // build disabled class combination with size class
        var disabledClass = 'cssBtn_disabled';
        if(btn_class.search('cb_large') > -1) disabledClass += ' '+'cb_large';
        else if(btn_class.search('cb_small') > -1) disabledClass += ' '+'cb_small';
        };
    setClass(elem, disabledClass);
    elem.setAttribute('disabled', 'true');
    return true;
    }
function enableButton(elem, /* optional */ btnClass){
    // Make specified 'button' element enabled and restore its class, if disabled
    if(elem.nodeName != 'BUTTON') return false;
    if(!isButtonDisabled) return false;
    // restore the original class
    var btn_class = elem.getAttribute('btn_class');
    if(!btn_class){
        // handle old style buttons with bg image
        btn_class = btnClass || 'enabledButton';
        };
    setClass(elem, btn_class);
    elem.disabled = false;
    elem.removeAttribute('disabled');
    return true;
    }


// helper for "navClicked" in livebase subclasses
function toggleExpandedClass(elem){
    if(getClass(elem) == 'collapsed')   setClass(elem, 'expanded');
    else                                setClass(elem, 'collapsed');
    }
function getHrefAttributeParmsD(elem){
    var hrefParmsD = {};
    var _href = elem.getAttribute('href');
    if(_href){   // get inherited attributes from href (most manual entered)
        _href.replace(new RegExp( "([^?=&]+)(=([^&]*))?", "g" ),  // search iterator(see: common.js getRequestArgsD )
            function( $0, $1, $2, $3 ) {if($1 && $3) hrefParmsD[$1] = $3; }
            );
    } else if(elem.form && elem.form.name) {    // get form fields !!! hidden inputs must contain all common data incl. LANG
        for(i=0;i<elem.form.elements.length;i++){
            var e = elem.form.elements[i];
            if( (e.type == 'radio' || e.type == 'checkbox') && !e.checked) continue;
            if( e.type == 'submit' && e.name != elem.name) continue;    // report only clicked submit button
            hrefParmsD[e.name] = e.value;
//             alert(e.type+' name: '+e.name+' value: '+e.value+' checked: '+e.checked);
            };
        };
    return hrefParmsD;
    }
var arrToScroll = [];
function _scrollArray(){
    if(arrToScroll.length){
        var item = arrToScroll.pop();
        item[0].style.display = item[1];
        window.setTimeout('_scrollArray()', 66);
        };
    }
function startScrolling(tag, styleDisplay){
    if(styleDisplay == 'none') arrToScroll.push([tag, styleDisplay, ] );
    var liChildren = tag.getElementsByTagName('li');
    for(var i=0;i<liChildren.length;i++ )
        arrToScroll.push([liChildren[i], styleDisplay, ] );
    if(styleDisplay == 'block') arrToScroll.push([tag, styleDisplay, ] );
    window.setTimeout('_scrollArray()', 99);
    }
// -------------------------------------

function sessionExpired(logoutURL){
//     alert(' SESSION EXPIRED \n\n CLOSING CONNECTION TO SERVER ');
    // reload window without any passed parameters
//     var cleanHref = window.location.href.split('?', 1)[0];
//     window.location.href = cleanHref;
    window.location.href = logoutURL;
    return 'common.js sessionExpired called';
    }

// http://www.110mb.com/forum/script-superlightweight-javascript-sha1-function-t37384.0.html
// use: SHA1.hash('passwd')
var SHA1=function(){var C=function(E,D,G,F){switch(E){case 0:return(D&G)^(~D&F);case 1:return D^G^F;
case 2:return(D&G)^(D&F)^(G&F);case 3:return D^G^F}return null;},B=function(D,E){return(D<<E)|(D>>>(32-E))},
A=function(G){var F="",D,E;for(E=7;E>=0;E--){D=(G>>>(E*4))&15;F+=D.toString(16)}return F};
return{hash:function(F){F+=String.fromCharCode(128);var I=[1518500249,1859775393,2400959708,3395469782],
U=Math.ceil(F.length/4)+2,G=Math.ceil(U/16),H=new Array(G),X=0,Q=1732584193,P=4023233417,O=2562383102,
L=271733878,J=3285377520,W=4294967295,D=new Array(80),h,g,f,Z,Y,R,V;for(;X<G;X++){H[X]=new Array(16);
for(V=0;V<16;V++){H[X][V]=(F.charCodeAt(X*64+V*4)<<24)|(F.charCodeAt(X*64+V*4+1)<<16)|(
F.charCodeAt(X*64+V*4+2)<<8)|(F.charCodeAt(X*64+V*4+3))}}H[G-1][14]=((F.length-1)*8)/Math.pow(2,32);
H[G-1][14]=Math.floor(H[G-1][14]);H[G-1][15]=((F.length-1)*8)&4294967295;for(X=0;X<G;X++){
for(R=0;R<16;R++){D[R]=H[X][R]}for(R=16;R<80;R++){D[R]=B(D[R-3]^D[R-8]^D[R-14]^D[R-16],1)}h=Q;g=P;f=O;Z=L;Y=J;
for(R=0;R<80;R++){var S=Math.floor(R/20),E=(B(h,5)+C(S,g,f,Z)+Y+I[S]+D[R])&W;Y=Z;Z=f;f=B(g,30);g=h;h=E}
Q=(Q+h)&W;P=(P+g)&W;O=(O+f)&W;L=(L+Z)&W;J=(J+Y)&W}return A(Q)+A(P)+A(O)+A(L)+A(J)}}}();


// ********************************* CalendarControl.js *****************************************
// https://engineering.purdue.edu/ECN/Support/KB/Docs/JavascriptCalendar
var cal_months = ['January', 'February', 'March', 'April', 'May', 'June',
        'July', 'August', 'September', 'October', 'November', 'December'];
var cal_daysTR = '<tr><th>Su</th><th>Mo</th><th>Tu</th>'
        +'<th>We</th><th>Th</th><th>Fr</th><th>Sa</th></tr>';
function calSwitchLang(lang) {
    if(lang == 'de'){
        window.cal_months = ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni',
                'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'];
        window.cal_daysTR = '<tr><th>So</th><th>Mo</th><th>Di</th>'
                +'<th>Mi</th><th>Do</th><th>Fr</th><th>Sa</th></tr>';
    } else if(lang == 'cs'){
        window.cal_months = ['Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen',
                'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec'];
        window.cal_daysTR = '<tr><th>Ne</th><th>Po</th><th>Út</th>'
                +'<th>St</th><th>Čt</th><th>Pá</th><th>So</th></tr>';
    } else {    // if not found, switch back to English as default
        window.cal_months = ['January', 'February', 'March', 'April', 'May', 'June',
                'July', 'August', 'September', 'October', 'November', 'December'];
        window.cal_daysTR = '<tr><th>Su</th><th>Mo</th><th>Tu</th>'
                +'<th>We</th><th>Th</th><th>Fr</th><th>Sa</th></tr>';
        };
    }

function positionInfo(object) {

  var p_elm = object;

  this.getElementLeft = getElementLeft;
  function getElementLeft() {
    var x = 0;
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    while (elm != null) {
      if(elm.style.position == 'relative') {
        break;
      }
      else {
        x += elm.offsetLeft;
        elm = elm.offsetParent;
      }
    }
    return parseInt(x);
  }

  this.getElementWidth = getElementWidth;
  function getElementWidth(){
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    return parseInt(elm.offsetWidth);
  }

  this.getElementRight = getElementRight;
  function getElementRight(){
    return getElementLeft(p_elm) + getElementWidth(p_elm);
  }

  this.getElementTop = getElementTop;
  function getElementTop() {
    var y = 0;
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    while (elm != null) {
      if(elm.style.position == 'relative') {
        break;
      }
      else {
        y+= elm.offsetTop;
        elm = elm.offsetParent;
      }
    }
    return parseInt(y);
  }

  this.getElementHeight = getElementHeight;
  function getElementHeight(){
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    return parseInt(elm.offsetHeight);
  }

  this.getElementBottom = getElementBottom;
  function getElementBottom(){
    return getElementTop(p_elm) + getElementHeight(p_elm);
  }
}

function CalendarControl() {
  var calendarId = 'CalendarControl';
  var currentYear = 0;
  var currentMonth = 0;
  var currentDay = 0;

  var selectedYear = 0;
  var selectedMonth = 0;
  var selectedDay = 0;

  var dateField = null;

  function getProperty(p_property){
    var p_elm = calendarId;
    var elm = null;

    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    if (elm != null){
      if(elm.style){
        elm = elm.style;
        if(elm[p_property]){
          return elm[p_property];
        } else {
          return null;
        }
      } else {
        return null;
      }
    }
    return null;
  }

  function setElementProperty(p_property, p_value, p_elmId){
    var p_elm = p_elmId;
    var elm = null;

    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    if((elm != null) && (elm.style != null)){
      elm = elm.style;
      elm[ p_property ] = p_value;
    }
  }

  function setProperty(p_property, p_value) {
    setElementProperty(p_property, p_value, calendarId);
  }

  function getDaysInMonth(year, month) {
    return [31,((!(year % 4 ) && ( (year % 100 ) || !( year % 400 ) ))?29:28),31,30,31,30,31,31,30,31,30,31][month-1];
  }

  function getDayOfWeek(year, month, day) {
    var date = new Date(year,month-1,day)
    return date.getDay();
  }

  this.clearDate = clearDate;
  function clearDate() {
    dateField.value = '';
    hide();
  }

  this.setDate = setDate;
  function setDate(year, month, day) {
    if (dateField) {
      if (month < 10) {month = "0" + month;}
      if (day < 10) {day = "0" + day;}

//       var dateString = month+"-"+day+"-"+year;
      var dateString = year+"-"+month+"-"+day;
      dateField.value = dateString;
      try{
        dateField.focus()     // 2011-01-31 added to allow <athena:handler event="onfocus" handler="validateElem" />
      } catch(err) {  // nothing to do
        };
      hide();
    }
    return;
  }

  this.changeMonth = changeMonth;
  function changeMonth(change) {
    currentMonth += change;
    currentDay = 0;
    if(currentMonth > 12) {
      currentMonth = 1;
      currentYear++;
    } else if(currentMonth < 1) {
      currentMonth = 12;
      currentYear--;
    }

    var calendar = document.getElementById(calendarId);
    calendar.innerHTML = calendarDrawTable();
  }

  this.changeYear = changeYear;
  function changeYear(change) {
    currentYear += change;
    currentDay = 0;
    var calendar = document.getElementById(calendarId);
    calendar.innerHTML = calendarDrawTable();
  }

  function getCurrentYear() {
    var year = new Date().getYear();
    if(year < 1900) year += 1900;
    return year;
  }

  function getCurrentMonth() {
    return new Date().getMonth() + 1;
  }

  function getCurrentDay() {
    return new Date().getDate();
  }

  function calendarDrawTable() {
    var dayOfMonth = 1;
    var validDay = 0;
    var startDayOfWeek = getDayOfWeek(currentYear, currentMonth, dayOfMonth);
    var daysInMonth = getDaysInMonth(currentYear, currentMonth);
    var css_class = null; //CSS class for each day

    var table = "<table cellspacing='0' cellpadding='0' border='0'>";
    table = table + "<tr class='cal_header'>";
    table = table + "  <td colspan='2' class='previous'><a href='#' onclick='changeCalendarControlMonth(-1);'>&nbsp;&nbsp; &larr; &nbsp;</a><br />"
        +"<a href='#' onclick='changeCalendarControlYear(-1);'>&nbsp; &laquo; &nbsp;</a></td>";
    table = table + "  <td colspan='3' class='cal_title'>" + cal_months[currentMonth-1] + "<br />" + currentYear + "</td>";
    table = table + "  <td colspan='2' class='next'><a href='#' onclick='changeCalendarControlMonth(1);'>&nbsp; &rarr; &nbsp;&nbsp;</a><br />"
        +"<a href='#' onclick='changeCalendarControlYear(1);'>&nbsp; &raquo; &nbsp;</a></td>";
    table = table + "</tr>";
    table = table + cal_daysTR;

    for(var week=0; week < 6; week++) {
      table = table + "<tr>";
      for(var dayOfWeek=0; dayOfWeek < 7; dayOfWeek++) {
        if(week == 0 && startDayOfWeek == dayOfWeek) {
          validDay = 1;
        } else if (validDay == 1 && dayOfMonth > daysInMonth) {
          validDay = 0;
        }

        if(validDay) {
          if (dayOfMonth == selectedDay && currentYear == selectedYear && currentMonth == selectedMonth) {
            css_class = 'current';
          } else if (dayOfWeek == 0 || dayOfWeek == 6) {
            css_class = 'weekend';
          } else {
            css_class = 'weekday';
          }

          table = table + "<td><a class='"+css_class
            +"' href='#' onclick='setCalendarControlDate("+currentYear+","+currentMonth+","+dayOfMonth+");'>"+dayOfMonth+"</a></td>";
          dayOfMonth++;
        } else {
          table = table + "<td class='empty'>&nbsp;</td>";
        }
      }
      table = table + "</tr>";
    }

    table = table + "<tr class='cal_header'><th colspan='7' style='padding: 3px;'>"
        +"<a href='#' onclick='clearCalendarControl();'>Clear</a> | <a href='#' onclick='hideCalendarControl();'>Close</a></td></tr>";
    table = table + "</table>";

    return table;
  }

  this.show = show;
  function show(field) {
    can_hide = 0;

    // If the calendar is visible and associated with
    // this field do not do anything.
    if (dateField == field) {
      return;
    } else {
      dateField = field;
    }

    if(dateField) {
      try {
        var dateString = new String(dateField.value);
        var dateType = 'ISO';
        if(dateString.indexOf('-') > 3){
            var dateParts = dateString.split("-");
        } else if(dateString.indexOf('-') > 0){
            var dateParts = dateString.split("-");
            dateType = 'EU';
        } else if(dateString.indexOf('/') > 3){
            var dateParts = dateString.split("/");
        } else if(dateString.indexOf('/') > 0){
            var dateParts = dateString.split("/");
            dateType = 'US';
        } else if(dateString.indexOf('.') > 3){
            var dateParts = dateString.split(".");
        } else if(dateString.indexOf('.') > 0){
            var dateParts = dateString.split(".");
            dateType = 'EU';
            };
        if(dateType == 'ISO'){
            selectedYear = parseInt(dateParts[0],10);
            selectedMonth = parseInt(dateParts[1],10);
            selectedDay = parseInt(dateParts[2],10);
        } else if(dateType == 'EU'){
            selectedDay = parseInt(dateParts[0],10);
            selectedMonth = parseInt(dateParts[1],10);
            selectedYear = parseInt(dateParts[2],10);
        } else {    // US
            selectedMonth = parseInt(dateParts[0],10);
            selectedDay = parseInt(dateParts[1],10);
            selectedYear = parseInt(dateParts[2],10);
            };

      } catch(e) {}
    }

    if (!(selectedYear && selectedMonth && selectedDay)) {
      selectedMonth = getCurrentMonth();
      selectedDay = getCurrentDay();
      selectedYear = getCurrentYear();
    }

    currentMonth = selectedMonth;
    currentDay = selectedDay;
    currentYear = selectedYear;

    if(document.getElementById){

      var calendar = document.getElementById(calendarId);
      calendar.innerHTML = calendarDrawTable(currentYear, currentMonth);

      setProperty('display', 'block');

      var fieldPos = new positionInfo(dateField);
      var calendarPos = new positionInfo(calendarId);

      var x = fieldPos.getElementLeft();
      var y = fieldPos.getElementBottom();

      setProperty('left', x + "px");
      setProperty('top', y + "px");

      if (document.all) {
        setElementProperty('display', 'block', 'CalendarControlIFrame');
        setElementProperty('left', x + "px", 'CalendarControlIFrame');
        setElementProperty('top', y + "px", 'CalendarControlIFrame');
        setElementProperty('width', calendarPos.getElementWidth() + "px", 'CalendarControlIFrame');
        setElementProperty('height', calendarPos.getElementHeight() + "px", 'CalendarControlIFrame');
      }
    }
  }

  this.hide = hide;
  function hide() {
    if(dateField) {
      setProperty('display', 'none');
      setElementProperty('display', 'none', 'CalendarControlIFrame');
      dateField = null;
    }
  }

  this.visible = visible;
  function visible() {
    return dateField
  }

  this.can_hide = can_hide;
  var can_hide = 0;
}

var calendarControl = new CalendarControl();

function showCalendarControl(textField) {
  // textField.onblur = hideCalendarControl;
  calendarControl.show(textField);
}

function clearCalendarControl() {
  calendarControl.clearDate();
}

function hideCalendarControl() {
  if (calendarControl.visible()) {
    calendarControl.hide();
  }
}

function setCalendarControlDate(year, month, day) {
  calendarControl.setDate(year, month, day);
}

function changeCalendarControlYear(change) {
  calendarControl.changeYear(change);
}

function changeCalendarControlMonth(change) {
  calendarControl.changeMonth(change);
}

document.write("<iframe id='CalendarControlIFrame' src='javascript:false;' frameBorder='0' scrolling='no' style='display:none;'></iframe>");
document.write("<div id='CalendarControl' style='display:none;'></div>");



