[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/admin/includes/javascript/ -> calendarcode.js (source)

   1  /*
   2   * Bazillyo's Spiffy DHTML Popup Calendar v. 1.0  2000 S. Ousta
   3   *   - freeware with this comment
   4   *   - for download size, you can strip all spaces & comments except the  notices
   5   *   - Thanks to Chris for the domlay() function
   6   *   - this requires calendarcode.js, calendar.css, and calendarTest.htm
   7   *   - works in IE4.x, IE5.x, NS4.75 possibly 4.x, NS6 (with slight cosmetic issues)
   8   *   - Netscape does display some controls overtop of the layer so layout is important
   9   *
  10   */
  11   
  12  // initialiZe variables... 
  13  var ppcIE=((navigator.appName == "Microsoft Internet Explorer") || ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion)==5)));
  14  var ppcNN6=((navigator.appName == "Netscape") && (parseInt(navigator.appVersion)==5));
  15  //var ppcIE=(navigator.appName == "Microsoft Internet Explorer");
  16  var ppcNN=((navigator.appName == "Netscape")&&(document.layers));
  17  var ppcX = 4;
  18  var ppcY = 4;
  19  
  20  var IsCalendarVisible;
  21  var calfrmName;
  22  var maxYearList;
  23  var minYearList;
  24  var todayDate = new Date; 
  25  var curDate = new Date; 
  26  var curImg;
  27  var curDateBox;
  28  var minDate = new Date;
  29  var maxDate = new Date;
  30  var hideDropDowns;
  31  var IsUsingMinMax;
  32  var FuncsToRun;
  33  var img_del;
  34  var img_close;
  35  img_del=new Image();
  36  img_del.src="./images/cal_del_small.gif";
  37  img_close=new Image();
  38  img_close.src="./images/cal_close_small.gif";
  39  
  40  minYearList=todayDate.getFullYear()-10;
  41  maxYearList=todayDate.getFullYear()+10;
  42  IsCalendarVisible=false;
  43  
  44  img_Date_UP=new Image();
  45  img_Date_UP.src="./images/cal_date_up.gif";
  46  
  47  img_Date_OVER=new Image();
  48  img_Date_OVER.src="./images/cal_date_over.gif";
  49  
  50  img_Date_DOWN=new Image();
  51  img_Date_DOWN.src="./images/cal_date_down.gif";
  52  
  53  
  54  function calSwapImg(whatID, NewImg,override) {
  55      if (document.images) {
  56       if (!( IsCalendarVisible && override )) {
  57          document.images[whatID].src = eval(NewImg + ".src");
  58       }
  59      }
  60      window.status=' ';
  61      return true;
  62  }
  63  
  64  function getOffsetLeft (el) {
  65      var ol = el.offsetLeft;
  66      while ((el = el.offsetParent) != null)
  67          ol += el.offsetLeft;
  68      return ol+130;
  69  }
  70  
  71  function getOffsetTop (el) {
  72      var ot = el.offsetTop;
  73      while((el = el.offsetParent) != null)
  74          ot += el.offsetTop;
  75      return ot-50;
  76  }
  77  
  78  function showCalendar(frmName, dteBox,btnImg, hideDrops, MnDt, MnMo, MnYr, MxDt, MxMo, MxYr,runFuncs) {
  79      hideDropDowns = hideDrops;
  80      FuncsToRun = runFuncs;
  81      calfrmName = frmName;
  82      if (IsCalendarVisible) {
  83          hideCalendar();
  84      }
  85      else {
  86          if (document.images['calbtn1']!=null ) document.images['calbtn1'].src=img_del.src;
  87          if (document.images['calbtn2']!=null ) document.images['calbtn2'].src=img_close.src;
  88          
  89          if (hideDropDowns) {toggleDropDowns('hidden');}
  90          if ((MnDt!=null) && (MnMo!=null) && (MnYr!=null) && (MxDt!=null) && (MxMo!=null) && (MxYr!=null)) {
  91              IsUsingMinMax = true;
  92              minDate.setDate(MnDt);
  93              minDate.setMonth(MnMo-1);
  94              minDate.setFullYear(MnYr);
  95              maxDate.setDate(MxDt);
  96              maxDate.setMonth(MxMo-1);
  97              maxDate.setFullYear(MxYr);
  98          }
  99          else {
 100              IsUsingMinMax = false;
 101          }
 102          
 103          curImg = btnImg;
 104          curDateBox = dteBox;
 105          if ( ppcIE ) {
 106              ppcX = getOffsetLeft(document.images[btnImg]);
 107              ppcY = getOffsetTop(document.images[btnImg]) + document.images[btnImg].height;
 108          }
 109          else if (ppcNN){
 110              ppcX = document.images[btnImg].x + 90; 
 111              ppcY = document.images[btnImg].y - 45;
 112          }
 113  
 114          domlay('popupcalendar',1,ppcX,ppcY,Calendar(todayDate.getMonth(),todayDate.getFullYear()));       
 115  
 116          //domlay('popupcalendar',1,ppcX,ppcY,Calendar(curDate.getMonth(),curDate.getFullYear()));
 117  
 118          IsCalendarVisible = true;
 119      }
 120  }
 121  
 122  function toggleDropDowns(showHow){
 123      var i; var j;
 124      for (i=0;i<document.forms.length;i++) {
 125          for (j=0;j<document.forms[i].elements.length;j++) {
 126              if (document.forms[i].elements[j].tagName == "SELECT") {
 127                  if (document.forms[i].name != "Cal")
 128                      document.forms[i].elements[j].style.visibility=showHow;
 129              }
 130          }
 131      }
 132  }
 133  
 134  function hideCalendar(){
 135      domlay('popupcalendar',0,ppcX,ppcY);
 136      calSwapImg(curImg, 'img_Date_UP');    
 137      IsCalendarVisible = false;
 138      if (hideDropDowns) {toggleDropDowns('visible');}
 139  }
 140  
 141  function calClick() {
 142          window.focus();
 143  }
 144  
 145  function domlay(id,trigger,lax,lay,content) {
 146      /*
 147       * Cross browser Layer visibility / Placement Routine
 148       * Done by Chris Heilmann ([email protected])
 149       * Feel free to use with these lines included!
 150       * Created with help from Scott Andrews.
 151       * The marked part of the content change routine is taken
 152       * from a script by Reyn posted in the DHTML
 153       * Forum at Website Attraction and changed to work with
 154       * any layername. Cheers to that!
 155       * Welcome DOM-1, about time you got included... :)
 156       */
 157      // Layer visible
 158      if (trigger=="1"){
 159          if (document.layers) document.layers[''+id+''].visibility = "show"
 160          else if (document.all) document.all[''+id+''].style.visibility = "visible"
 161          else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"                
 162          }
 163      // Layer hidden
 164      else if (trigger=="0"){
 165          if (document.layers) document.layers[''+id+''].visibility = "hide"
 166          else if (document.all) document.all[''+id+''].style.visibility = "hidden"
 167          else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"             
 168          }
 169      // Set horizontal position  
 170      if (lax){
 171          if (document.layers){document.layers[''+id+''].left = lax}
 172          else if (document.all){document.all[''+id+''].style.left=lax}
 173          else if (document.getElementById){document.getElementById(''+id+'').style.left=lax+"px"}
 174          }
 175      // Set vertical position
 176      if (lay){
 177          if (document.layers){document.layers[''+id+''].top = lay}
 178          else if (document.all){document.all[''+id+''].style.top=lay}
 179          else if (document.getElementById){document.getElementById(''+id+'').style.top=lay+"px"}
 180          }
 181      // change content
 182  
 183      if (content){
 184      if (document.layers){
 185          sprite=document.layers[''+id+''].document;
 186          // add father layers if needed! document.layers[''+father+'']...
 187          sprite.open();
 188          sprite.write(content);
 189          sprite.close();
 190          }
 191      else if (document.all) document.all[''+id+''].innerHTML = content;  
 192      else if (document.getElementById){
 193          //Thanx Reyn!
 194          rng = document.createRange();
 195          el = document.getElementById(''+id+'');
 196          rng.setStartBefore(el);
 197          htmlFrag = rng.createContextualFragment(content)
 198          while(el.hasChildNodes()) el.removeChild(el.lastChild);
 199          el.appendChild(htmlFrag);
 200          // end of Reyn ;)
 201          }
 202      }
 203  }
 204  
 205  function Calendar(whatMonth,whatYear) {
 206      var output = '';
 207      var datecolwidth;
 208      var startMonth;
 209      var startYear;
 210      startMonth=whatMonth;
 211      startYear=whatYear;
 212  
 213      curDate.setMonth(whatMonth);
 214      curDate.setFullYear(whatYear);
 215      curDate.setDate(todayDate.getDate());
 216      if (ppcNN6) {
 217          output += '<form name="Cal"><table width="185" border="3" class="cal-Table" cellspacing="0" cellpadding="0"><tr>';
 218      }
 219      else {
 220          output += '<table width="185" border="3" class="cal-Table" cellspacing="0" cellpadding="0"><form name="Cal"><tr>';
 221      }
 222       
 223      output += '<td class="cal-HeadCell" align="center" width="100%"><a href="javascript:clearDay();"><img name="calbtn1" src="./images/cal_del_small.gif" border="0" width="12" height="10"></a>&nbsp;&nbsp;<a href="javascript:scrollMonth(-1);" class="cal-DayLink">&lt;</a>&nbsp;<SELECT class="cal-TextBox" NAME="cboMonth" onChange="changeMonth();">';
 224      for (month=0; month<12; month++) {
 225          if (month == whatMonth) output += '<OPTION VALUE="' + month + '" SELECTED>' + names[month] + '<\/OPTION>';
 226          else                output += '<OPTION VALUE="' + month + '">'          + names[month] + '<\/OPTION>';
 227      }
 228  
 229      output += '<\/SELECT><SELECT class="cal-TextBox" NAME="cboYear" onChange="changeYear();">';
 230  
 231      for (year=minYearList; year<maxYearList; year++) {
 232          if (year == whatYear) output += '<OPTION VALUE="' + year + '" SELECTED>' + year + '<\/OPTION>';
 233          else              output += '<OPTION VALUE="' + year + '">'          + year + '<\/OPTION>';
 234      }
 235  
 236      output += '<\/SELECT>&nbsp;<a href="javascript:scrollMonth(1);" class="cal-DayLink">&gt;</a>&nbsp;&nbsp;<a href="javascript:hideCalendar();"><img name="calbtn2" src="./images/cal_close_small.gif" border="0" width="12" height="10"></a><\/td><\/tr><tr><td width="100%" align="center">';
 237  
 238      firstDay = new Date(whatYear,whatMonth,1);
 239      startDay = firstDay.getDay();
 240  
 241      if (((whatYear % 4 == 0) && (whatYear % 100 != 0)) || (whatYear % 400 == 0))
 242           days[1] = 29;
 243      else
 244           days[1] = 28;
 245  
 246      output += '<table width="185" cellspacing="1" cellpadding="2" border="0"><tr>';
 247  
 248      for (i=0; i<7; i++) {
 249          if (i==0 || i==6) {
 250              datecolwidth="15%"
 251          }
 252          else
 253          {
 254              datecolwidth="14%"
 255          }
 256          output += '<td class="cal-HeadCell" width="' + datecolwidth + '" align="center" valign="middle">'+ dow[i] +'<\/td>';
 257      }
 258      
 259      output += '<\/tr><tr>';
 260  
 261      var column = 0;
 262      var lastMonth = whatMonth - 1;
 263      var lastYear = whatYear;
 264      if (lastMonth == -1) { lastMonth = 11; lastYear=lastYear-1;}
 265  
 266      for (i=0; i<startDay; i++, column++) {
 267          output += getDayLink((days[lastMonth]-startDay+i+1),true,lastMonth,lastYear);
 268      }
 269  
 270      for (i=1; i<=days[whatMonth]; i++, column++) {
 271          output += getDayLink(i,false,whatMonth,whatYear);
 272          if (column == 6) {
 273              output += '<\/tr><tr>';
 274              column = -1;
 275          }
 276      }
 277      
 278      var nextMonth = whatMonth+1;
 279      var nextYear = whatYear;
 280      if (nextMonth==12) { nextMonth=0; nextYear=nextYear+1;}
 281      
 282      if (column > 0) {
 283          for (i=1; column<7; i++, column++) {
 284              output +=  getDayLink(i,true,nextMonth,nextYear);
 285          }
 286          output += '<\/tr><\/table><\/td><\/tr>';
 287      }
 288      else {
 289          output = output.substr(0,output.length-4); // remove the <tr> from the end if there's no last row
 290          output += '<\/table><\/td><\/tr>';
 291      }
 292      
 293      if (ppcNN6) {
 294          output += '<\/table><\/form>';
 295      }
 296      else {
 297          output += '<\/form><\/table>';
 298      }
 299      curDate.setDate(1);
 300      curDate.setMonth(startMonth);
 301      curDate.setFullYear(startYear);
 302      return output;
 303  }
 304  
 305  function getDayLink(linkDay,isGreyDate,linkMonth,linkYear) {
 306      var templink;
 307      if (!(IsUsingMinMax)) {
 308          if (isGreyDate) {
 309              templink='<td align="center" class="cal-GreyDate">' + linkDay + '<\/td>';
 310          }
 311          else {
 312              if (isDayToday(linkDay)) {
 313                  templink='<td align="center" class="cal-DayCell">' + '<a class="cal-TodayLink" onmouseover="self.status=\' \';return true" href="javascript:changeDay(' + linkDay + ');">' + linkDay + '<\/a>' +'<\/td>';
 314              }
 315              else {
 316                  templink='<td align="center" class="cal-DayCell">' + '<a class="cal-DayLink" onmouseover="self.status=\' \';return true" href="javascript:changeDay(' + linkDay + ');">' + linkDay + '<\/a>' +'<\/td>';
 317              }
 318          }
 319      }
 320      else {
 321          if (isDayValid(linkDay,linkMonth,linkYear)) {
 322  
 323              if (isGreyDate){
 324                  templink='<td align="center" class="cal-GreyDate">' + linkDay + '<\/td>';
 325              }
 326              else {
 327                  if (isDayToday(linkDay)) {
 328                      templink='<td align="center" class="cal-DayCell">' + '<a class="cal-TodayLink" onmouseover="self.status=\' \';return true" href="javascript:changeDay(' + linkDay + ');">' + linkDay + '<\/a>' +'<\/td>';
 329                  }
 330                  else {
 331                      templink='<td align="center" class="cal-DayCell">' + '<a class="cal-DayLink" onmouseover="self.status=\' \';return true" href="javascript:changeDay(' + linkDay + ');">' + linkDay + '<\/a>' +'<\/td>';
 332                  }
 333              }
 334          }
 335          else {
 336              templink='<td align="center" class="cal-GreyInvalidDate">'+ linkDay + '<\/td>';
 337          }
 338      }
 339      return templink;
 340  }
 341  
 342  function isDayToday(isDay) {
 343      if ((curDate.getFullYear() == todayDate.getFullYear()) && (curDate.getMonth() == todayDate.getMonth()) && (isDay == todayDate.getDate())) {
 344          return true;
 345      }
 346      else {
 347          return false;
 348      }
 349  }
 350  
 351  function isDayValid(validDay, validMonth, validYear){
 352      
 353      curDate.setDate(validDay);
 354      curDate.setMonth(validMonth);
 355      curDate.setFullYear(validYear);
 356      
 357      if ((curDate>=minDate) && (curDate<=maxDate)) {
 358          return true;
 359      }
 360      else {
 361          return false;
 362      }
 363  }
 364  
 365  function padout(number) { return (number < 10) ? '0' + number : number; }
 366  
 367  function clearDay() {
 368      eval('document.' + calfrmName + '.day.value = \'\'');
 369      eval('document.' + calfrmName + '.month.value = \'\'');
 370      eval('document.' + calfrmName + '.year.value = \'\'');
 371      hideCalendar();
 372      if (FuncsToRun!=null)
 373          eval(FuncsToRun); 
 374  }
 375  
 376  function changeDay(whatDay) {
 377      curDate.setDate(whatDay);
 378  //    eval('document.' + calfrmName + '.' + curDateBox + '.value = "'+ padout(curDate.getDate()) + '-' + padout(curDate.getMonth()+1) + '-' + curDate.getFullYear() + '"');
 379      eval('document.' + calfrmName + '.day.value = "'+ padout(curDate.getDate()) + '"');
 380      eval('document.' + calfrmName + '.month.value = "'+ padout(curDate.getMonth()+1) + '"');
 381      eval('document.' + calfrmName + '.year.value = "'+ curDate.getFullYear() + '"');
 382      hideCalendar();
 383      if (FuncsToRun!=null)
 384          eval(FuncsToRun); 
 385  }
 386  
 387  function scrollMonth(amount) {
 388      var monthCheck;
 389      var yearCheck;
 390      
 391      if (ppcIE) {
 392          monthCheck = document.forms["Cal"].cboMonth.selectedIndex + amount;
 393      }
 394      else if (ppcNN) {
 395          monthCheck = document.popupcalendar.document.forms["Cal"].cboMonth.selectedIndex + amount;    
 396      }
 397      if (monthCheck < 0) {
 398          yearCheck = curDate.getFullYear() - 1;
 399          if ( yearCheck < minYearList ) {
 400              yearCheck = minYearList;
 401              monthCheck = 0;
 402          }
 403          else {
 404              monthCheck = 11;
 405          }
 406          curDate.setFullYear(yearCheck);
 407      }
 408      else if (monthCheck >11) {
 409          yearCheck = curDate.getFullYear() + 1;
 410          if ( yearCheck > maxYearList-1 ) {
 411              yearCheck = maxYearList-1;
 412              monthCheck = 11;
 413          }
 414          else {
 415              monthCheck = 0;
 416          }      
 417          curDate.setFullYear(yearCheck);
 418      }
 419      
 420      if (ppcIE) {
 421          curDate.setMonth(document.forms["Cal"].cboMonth.options[monthCheck].value);
 422      }
 423      else if (ppcNN) {
 424          curDate.setMonth(document.popupcalendar.document.forms["Cal"].cboMonth.options[monthCheck].value );
 425      }
 426      domlay('popupcalendar',1,ppcX,ppcY,Calendar(curDate.getMonth(),curDate.getFullYear()));
 427  }
 428  
 429  function changeMonth() {
 430  
 431      if (ppcIE) {        
 432          curDate.setMonth(document.forms["Cal"].cboMonth.options[document.forms["Cal"].cboMonth.selectedIndex].value);
 433          domlay('popupcalendar',1,ppcX,ppcY,Calendar(curDate.getMonth(),curDate.getFullYear()));
 434      }
 435      else if (ppcNN) {
 436  
 437          curDate.setMonth(document.popupcalendar.document.forms["Cal"].cboMonth.options[document.popupcalendar.document.forms["Cal"].cboMonth.selectedIndex].value);
 438          domlay('popupcalendar',1,ppcX,ppcY,Calendar(curDate.getMonth(),curDate.getFullYear()));
 439      }
 440  
 441  }
 442  
 443  function changeYear() {
 444      if (ppcIE) {
 445  
 446          curDate.setFullYear(document.forms["Cal"].cboYear.options[document.forms["Cal"].cboYear.selectedIndex].value);
 447          domlay('popupcalendar',1,ppcX,ppcY,Calendar(curDate.getMonth(),curDate.getFullYear()));
 448  
 449  
 450      }
 451      else if (ppcNN) {
 452  
 453          curDate.setFullYear(document.popupcalendar.document.forms["Cal"].cboYear.options[document.popupcalendar.document.forms["Cal"].cboYear.selectedIndex].value);
 454          domlay('popupcalendar',1,ppcX,ppcY,Calendar(curDate.getMonth(),curDate.getFullYear()));
 455      }
 456  
 457  }
 458  
 459  function makeArray0() {
 460      for (i = 0; i<makeArray0.arguments.length; i++)
 461          this[i] = makeArray0.arguments[i];
 462  }
 463  
 464  var names     = new makeArray0('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
 465  var days      = new makeArray0(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
 466  var dow       = new makeArray0('S','M','T','W','T','F','S');


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7