I have a javascript file named select.js. This is a file which is use
to pop up a calendar, when clicked on a calendar icon in an ASP file.
have a close button in the calendar. When i click on the button, th
calendar is not closing.
here is the select.js file
x999NS4compatib le = (document.layer s);
var x999IE4compatib le = (document.all);
var x999dayabbs = [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ];
var x999daynames = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday'
'Thursday', 'Friday', 'Saturday' ];
var x999monthnames = [ 'January', 'February', 'March', 'April', 'May'
'June', 'July', 'August', 'September', 'October', 'November'
'December' ];
var x999monthabbs = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul'
'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ];
var x999weekdays = [ 'Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa' ];
var x999months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul'
'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ];
var x999years = new Array(10);
for (i = 0; i < x999years.lengt h; i++) x999years[i] = 1999 + i;
var x999today = new Date();
var x999currentday = x999today.getDa te();
var x999currentmont h = x999today.getMo nth();
var x999currentyear = x999today.getFu llYear();
var x999left = 100;
var x999top = 80;
var x999width = 220;
var x999height = 260;
var x999cell_width = 25;
var x999cell_height = 25;
var x999bg_color = '#0072a0';
var x999offsety = 32;
var x999fontface = "verdana";
var x999weekcolor = "yellow";
var x999weeksize= "2";
var x999lowyear = 1900;
var x999highyear = 2999;
var x999weekfont = '<font face="' + x999fontface + '" size="'
x999weeksize + '" color="' + x999weekcolor + '">';
var x999font = '<font face="' + x999fontface + '" size="1">';
+ ";color:#000000 ;font-size:7pt;font-weight:bold;'";
var x999stylecombo = "style = 'font-family:" + x999fontface
";color:#000000 ;font-size:7pt;font-weight:bold;'";
var x999style = "style = 'font-family:" + x999fontface
";BACKGROUN D-COLOR: #004680; FONT-SIZE: xx-small; FONT-WEIGHT: bold
HEIGHT: 22px; WIDTH: 23px ;COLOR: WHITE'";
var x999stylebut = "style = 'font-family:" + x999fontface
";BACKGROUN D-COLOR: #004680; FONT-SIZE: xx-small; FONT-WEIGHT: bold
HEIGHT: 22px; WIDTH: 43px ;COLOR: WHITE'";
var x999headerstyle = "style = 'font-family:" + x999fontface
";color:#000000 ;font-size:1;font-weight:bold;'";
var x999daystyle = "style = 'BACKGROUND-COLOR: #004680; FONT-SIZE
xxx-small; FONT-WEIGHT: bold; HEIGHT: 20px; WIDTH: 24px ;COLOR
WHITE;BORDER-TOP:BLUE;BORDER-LEFT:BLUE'";
var x999tableborder = '1';
var frm_name = '';
var frm_fld = ''
function x999cal(is_popu p, win
handler,form_na me,field_name,f ield_value,left , top, height
bg_color,width,
cell_width, cell_height, sel_month, sel_year)
{
this.is_popup = is_popup;
this.parent = null;
this.window = null;
if (this.is_popup)
this.parent = win;
else
this.window = win;
frm_name = form_name;
frm_fld = field_name;
fld_val = field_value;
this.handler = handler;
this.left = left;
this.top = top;
this.width = width || x999width;
this.height = height || x999height;
this.cell_width = cell_width || x999cell_width;
this.cell_heigh t = cell_height || x999cell_height ;
this.bg_color = bg_color || x999bg_color;
this.sel_month = sel_month;
this.sel_year = sel_year;
if((fld_val) != "")
{
if (fld_val.length > 10 || fld_val.length < 8)
{
alert("Invalid date");
return false;
exit();
}
a=fld_val.split ("/");
mon = a[0];
dat = a[1];
yr = a[2];
if (yr == 0000)
{
alert("This is an invalid year");
return false;
exit();
}
else if (mon == null || dat == null || yr == null || mon.length > 2 |
dat.length > 2 || yr.length !=4)
{
alert("The date format has to be mm/dd/yyyy");
return false;
exit();
}
else if (isNaN(mon) == 1 || isNaN(dat) == 1 || isNaN(yr) == 1)
{
alert("Invalid date : No text form date allowed, only numeric forma
to be entered");
return false;
exit();
}
else if (mon < 1 || mon > 12)
{
alert("Invalid Date : The date format should be mm/dd/yyyy , mont
has to be between 1 and 12")
return false;
exit();
}
else if (mon == 1 || mon == 3 || mon == 5 || mon == 7 || mon == 8 ||
mon == 10 || mon == 12)
{
if (dat < 1 || dat > 31)
{
alert("Invalid Date : The date format should be mm/dd/yyyy , the
date value you have entered is not a valid date for this month")
return false;
exit();
}
}
else if(mon == 4 || mon == 6 || mon == 9 || mon == 11)
{
if(dat < 1 || dat > 31)
{
alert("Invalid Date : The date format should be mm/dd/yyyy , the
date value you have entered is not a valid date for this month")
return false;
exit();
}
}
else if (mon == 2)
{
if (yr%4 == 0)
{
if(yr%100 != 0 || yr%400 == 0)
{
if (dat < 1 || dat > 29)
{
alert("Invalid Date : The date format should be mm/dd/yyyy , the
date value you have entered is not a valid date for this month")
return false;
exit();
}
}
}
else if (dat < 1 || dat > 28)
{
alert( "Invalid Date : The date format should be mm/dd/yyyy , the
date value you have entered is not a valid date for this month");
return false;
exit();
}
}
this.sel_year = yr;
this.sel_month = mon-1;
}
else
{
this.sel_year = x999currentyear ;
this.sel_month = x999currentmont h;
}
this.days = new Array(42);
this.cal = null;
this.day_table = null;
if (x999NS4compati ble)
{
x999cal.prototy pe.create_cal = x999cal_create_ cal_NS4;
x999cal.prototy pe.show_days = x999cal_show_da ys_NS4();
}
else
{
x999cal.prototy pe.create_cal = x999cal_create_ cal_IE4;
x999cal.prototy pe.show_days = x999cal_show_da ys_IE4;
}
x999cal.prototy pe.popup_cal = x999cal_popup_c al;
x999cal.prototy pe.prev_year = x999cal_prev_ye ar;
x999cal.prototy pe.next_year = x999cal_next_ye ar;
x999cal.prototy pe.new_year = x999cal_new_yea r;
x999cal.prototy pe.prev_month = x999cal_prev_mo nth;
x999cal.prototy pe.next_month =
x999cal_next_mo nth;x999cal.pro totype.clicked_ day =
x999cal_clicked _day;
if (x999cal.protot ype.id == null) x999cal.prototy pe.id = 0;
x999cal.prototy pe.id++;
this.id = x999cal.prototy pe.id;
this.cal_id = 'cal' + this.id;
this.day_table_ id = 'day_table' + this.id;
this.select_for m_id = 'select_form' + this.id;
}
function x999cal_create_ cal_NS4()
{
if (this.is_popup)
{
var x = this.parent.scr eenX + (this.parent.ou terWidth -
this.parent.inn erWidth) + (this.left || x999left);
var y = this.parent.scr eenY + (this.parent.ou terHeight -
this.parent.inn erHeight) + (this.top || x999top);
this.window = this.parent.ope n("", this.cal_id, 'screenX=' + x +
',screenY=' + y + ',innerWidth=' + this.width + ',innerHeight=' +
this.height + ',scrollbars=no ,resizeable=no' );
this.window.doc ument.open(); //Need to open and close document in
Navigator
this.window.doc ument.writeln(' <title>CCC STS Calendar</title>');
this.window.doc ument.close();
}
this.cal = new Layer(this.widt h, this.window);
this.cal.name = this.cal_id;
if (this.is_popup)
{
this.cal.left = 0;
this.cal.top = 0;
}
else
{
this.cal.left = this.left || x999left;
this.cal.top = this.top || x999top;
}
this.cal.zIndex = 1;
this.cal.clip.w idth = this.width;
this.cal.clip.h eight = this.height;
this.cal.bgColo r = this.bg_color;
this.cal.visibi lity = 'show';
var doc = this.cal.docume nt;
var x999today = new Date();
var vYear = x999today.getFu llYear();
doc.picker = this;
doc.open();
doc.writeln("<c enter>");
doc.writeln("<t able align='center' border='0' cellpadding='0' >");
doc.writeln(" <tr>");
doc.writeln(" <td align='center'> ");
doc.writeln(" <form name='" + this.select_for m_id + "'>" +
x999font);
doc.writeln(" <input type='button' value='<< '
onClick='docume nt.picker.prev_ year()' " + x999style + ">");
doc.writeln(" <input type='button' value=' &l t; '
onClick='docume nt.picker.prev_ month()' " + x999style + ">");
doc.writeln(" <select name='month_sel '
onChange='docum ent.picker.new_ year()' " + x999style + " >");
for (i = 0; i < x999months.leng th; i++)
doc.writeln(" <option value='" + i + "'>" + x999months[i]);
doc.writeln(" </select></font>");
doc.writeln(" " + x999font + " <input type = 'text' value = '"
+ vYear + "' size = '4' maxlength = '4' name = 'year_sel' " +
x999headerstyle + " onBlur='documen t.picker.new_ye ar()'>\n");
doc.writeln(" <input type='button' value=' &g t; '
onClick='docume nt.picker.next_ month()' " + x999style + ">");
doc.writeln(" <input type='button' value='>> '
onClick='docume nt.picker.next_ year()' " + x999style + ">");
doc.writeln(" </form>");
doc.writeln(" </td>");
doc.writeln(" </tr>");
doc.writeln("</table>");
doc.writeln("</center>");
doc.close();
this.day_table = new Layer(this.widt h, this.cal);
this.day_table. name = this.day_table_ id;
this.day_table. left = 0;
this.day_table. top = x999offsety;
this.day_table. zIndex = 2;
this.day_table. visibility = 'inherit';
}
function x999cal_show_da ys_NS4()
{
var month_select =
this.cal.docume nt.forms[this.select_for m_id]['month_sel'];
var year_select =
this.cal.docume nt.forms[this.select_for m_id]['year_sel'];
month_select.se lectedIndex = this.sel_month;
year_select.val ue = this.sel_year;
var days_in_month = get_days_in_mon th(this.sel_mon th,
this.sel_year);
var day_of_week_fir st = (new Date(this.sel_y ear, this.sel_month,
1)).getDay() - 0;
if (day_of_week_fi rst< 1) day_of_week_fir st += 7;
for (i = 0; i < this.days.lengt h; i++) this.days[i] = 0;
for (i = 0; i < days_in_month; i++)
this.days[i + day_of_week_fir st] = i + 1;
var doc = this.day_table. document;
doc.picker = this;
doc.open();
doc.writeln("<c enter>");
doc.writeln("<t able align='center' border='" + x999tableborder
"'>");
doc.writeln("<f orm>");
doc.writeln(" <tr>");
for (j = 0; j < x999weekdays.le ngth; j++)
{
doc.writeln(" <td align='center' valign='middle' width='"
this.cell_width + "' >" + x999weekfont + x999weekdays[j] + "</td>");
}
doc.writeln(" </tr>");
for (i = 0; i < 6; i++)
{
doc.writeln(" <tr>");
for(j = 0; j < 7; j++)
{
var val = this.days[i * 7 + j];
if (val > 0 && val < 10) val = " " + val + " ";
if (this.days[i * 7 + j])
{
doc.writeln(" <td align='center' valign='middle' height='"
this.cell_heigh t + "'>" + x999font + "<input type='button' value='"
val + "' onClick='docume nt.picker.click ed_day(" + this.days[i * 7 + j
+ ")'></td>");
}
else
doc.writeln(" <td> </td>");
}
doc.writeln(" </tr>");
}
doc.writeln("<i nput type='button' value='Close' onClick='' "
x999stylebut + ">");
doc.writeln("</form>");
doc.writeln("</table>");
doc.writeln("</center>");
doc.close();
}
function x999cal_create_ cal_IE4()
{
if (this.is_popup)
{
var x = this.parent.scr eenLeft + (this.left || x999left);
var y = this.parent.scr eenTop + (this.top || x999top);
this.window = this.parent.ope n("", this.cal_id, 'left=' + x
',top=' + y + ',width=' + this.width + ',height=' + this.height
',scrollbars=no ,resizeable=no' );
this.window.doc ument.open();
this.window.doc ument.writeln(' <title>CCC STS Calendar</title>');
this.window.doc ument.close();
}
this.window.doc ument.body.inse rtAdjacentHTML( "beforeEnd" , "<div id='
+ this.cal_id + "' style='position :absolute'></div>");
this.cal = this.window.doc ument.all[this.cal_id];
if (this.is_popup)
{
this.cal.style. pixelLeft = 0;
this.cal.style. pixelTop = 0;
}
else
{
this.cal.style. pixelLeft = this.left || x999left;
this.cal.style. pixelTop = this.top || x999top;
}
this.cal.style. zIndex = 1;
this.cal.style. width = this.width;
this.cal.style. height = this.height;
this.cal.style. backgroundColor = this.bg_color;
this.cal.style. visibility = 'visible';
this.cal.picker = this;
var x999today = new Date();
var vYear = x999today.getFu llYear();
var str =
"<center>\n " +
"<table align='center' border='0' cellpadding='0
cellspacing='0' ><tr><td><tab le align='center' border='0'>\n" +
" <form name='" + this.select_for m_id + "'>\n" +
" <tr>\n" +
" <td align='center'> \n" +
" <input type='button' " + x999style + " value='<<
onClick='docume nt.all." + this.cal_id + ".picker.prev_y ear()'>\n" +
" <input type='button' " + x999style + " value='<&nbs p;
onClick='docume nt.all." + this.cal_id + ".picker.prev_m onth()'>\n" +
" <select name='month_sel ' " + x999stylecombo + "
onChange='docum ent.all." + this.cal_id + ".picker.new_ye ar()'>\n";
for (i = 0; i < x999months.leng th; i++)
str += " <option value='" + i + "'>" + x999months[i] + "\n";
str += " </select>\n" +
" <input type = 'text' value = '" + vYear + "' size = '4
maxlength = '4' name = 'year_sel' " + x999stylecombo +
onBlur='documen t.all." + this.cal_id + ".picker.new_ye ar()'>\n" +
" <input type='button' " + x999style + " value='>&nbs p;
onClick='docume nt.all." + this.cal_id + ".picker.next_m onth()'>\n" +
" <input type='button' " + x999style + " value='>>
onClick='docume nt.all." + this.cal_id + ".picker.next_y ear()'>\n" +
" </td>\n" +
" </tr>\n" +
" </form>\n" +
"</table>\n" +
"</center>\n" +
"<div id='" + this.day_table_ id + "
style='position :absolute'></div>\n";this.ca l.innerHTML = str;
this.day_table = this.window.doc ument.all[this.day_table_ id];
this.day_table. style.pixelLeft = 4;
this.day_table. style.pixelTop = x999offsety;
this.day_table. style.zIndex = 2;
this.day_table. style.visibilit y = 'inherit';
this.day_table. picker = this;
}
function y2k(number)
{
return (number < 1000) ? number + 1900 : number;
}
function getWeek(year,mo nth,day)
{
var when = new Date(year,month ,day);
var newYear = new Date(year,0,1);
var offset = 7 + 1 - newYear.getDay( );
if (offset == 8) offset = 1;
var daynum =
((Date.UTC(y2k( year),when.getM onth(),when.get Date(),0,0,0) -
Date.UTC(y2k(ye ar),0,1,0,0,0)) /1000/60/60/24) + 1;
var weeknum = Math.floor((day num-offset+7)/7);
if (month == 0 && weeknum > 7) weeknum = 0;
if (offset != 1) weeknum = weeknum + 1;
if (weeknum == 0) {
year--;
var prevNewYear = new Date(year,0,1);
var prevOffset = 7 + 1 - prevNewYear.get Day();
if (prevOffset == 2 || prevOffset == 8) weeknum = 53; else
weeknum = 52;
}
return weeknum;
}
function x999cal_show_da ys_IE4()
{
var month_select =
this.window.doc ument.forms[this.select_for m_id]['month_sel'];
var year_select =
this.window.doc ument.forms[this.select_for m_id]['year_sel'];
month_select.se lectedIndex = this.sel_month;
year_select.val ue = this.sel_year;
var days_in_month = (new Date(this.sel_y ear, this.sel_month+ 1,
0)).getDate();
var day_of_week_fir st = (new Date(this.sel_y ear, this.sel_month,
1)).getDay() - 0;
if (day_of_week_fi rst< 0 ) day_of_week_fir st += 7;
for (i = 0; i < this.days.lengt h; i++) this.days[i] = 0;
for (i = 0; i < days_in_month; i++)
this.days[i + day_of_week_fir st] = i + 1;
var str =
"<center>\n " +
" <t able align='center' border='" + x999tableborder +
"'>\n" +
"<form>\n" +
" <tr>\n";
for (j = 0; j < x999weekdays.le ngth; j++)
{
str += " <td align='center' valign='middle' width='" +
this.cell_width + "'>" + x999weekfont + x999weekdays[j] + "</td>\n";
}
str += " </tr>\n";
for (i = 0; i < 6; i++)
{
str += " <tr>\n";
for(j = 0; j < 7; j++)
{
var val = this.days[i * 7 + j];
if (val > 0 && val < 10) val = " " + val + " ";
if (this.days[i * 7 + j])
{
str += " <td align='center' valign='middle' height='" +
this.cell_heigh t + "'>" + x999font + "<input type='button' " +
x999daystyle + " value='" + val + "' onClick='docume nt.all." +
this.day_table_ id + ".picker.clicke d_day(" + this.days[i * 7 + j] +
")'></td>\n";
}
else
str += " <td> </td>\n";
}
str += " </tr>\n";
}
str +=
"</form>\n" +
"</table>\n" +
"</center>\n" +
"<input type='button' value='Close' onClick='x999ca l_clicked_day(1 )'"
+ x999stylebut + ">";
this.day_table. innerHTML = str;
}
function funclose_button ()
{
var dt1 = eval("document. "+frm_name+"."+ frm_fld);
var x999today = new Date();
var x999currentday = x999today.getDa te();
var x999currentmont h = x999today.getMo nth();
var x999currentyear = x999today.getFu llYear();
dt1.value = x999currentday + '/' + x999currentmont h+1 + '/' +
x999currentyear ;
}
function x999cal_popup_c al()
{
if (this.is_popup)
{
if (this.cal && this.window && !this.window.cl osed)
this.window.clo se();
else
{
this.create_cal ();
this.show_days( );
}
}
else
{
if (!this.cal)
{
this.create_cal ();
this.show_days( );
}
else
{
if (x999NS4compati ble)
{
if (this.cal.visib ility == 'show')
this.cal.visibi lity = 'hide';
else
this.cal.visibi lity = 'show';
}
else
{
if (this.cal.style .visibility == 'visible')
this.cal.style. visibility = 'hidden';
else
this.cal.style. visibility = 'visible';
}
}
}
}
function x999cal_new_yea r()
{
var month_select =
this.cal.docume nt.forms[this.select_for m_id]['month_sel'];
this.sel_month = new
Number(month_se lect.options[month_select.se lectedIndex].value);
var year_select =
this.cal.docume nt.forms[this.select_for m_id]['year_sel'];
this.sel_year = new Number(year_sel ect.value);
if ( (isNaN(parseInt (this.sel_year) )) || (this.sel_year < x999lowyear)
|| (this.sel_year > x999highyear) )
{
window.alert('T his is not a valid year.');
var x999today = new Date;
var yr = x999today.getFu llYear();
this.sel_year = yr;
}
this.show_days( );
function");
}
function x999cal_clicked _day(day)
{
day = 5;
alert(day);
if (this.is_popup)
this.window.clo se();
if (x999NS4compati ble)
this.cal.visibi lity = 'hide';
else
this.cal.style. visibility = 'hidden';
var sel_date = new Date(this.sel_y ear, this.sel_month, day);
if (this.handler) this.handler(th is, sel_date);
}
function twodigit(num)
{
var numStr = num + '';
if (numStr.length == 1)
{
numStr = "0" + numStr;
}
return numStr;
}
function righttwodigits( num)
{var numStr = num + '';
if (numStr.length == 4) {
numStr = numStr.substrin g(1,3);}
return numStr;
}
function get_days_in_mon th(mon, yr)
{
var month = new Number(mon);
var year = new Number(yr);
var mdays = [ [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] ];
var isleap =
(year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? 1 : 0;
return mdays[isleap][month];}
function my_date_selecte d(cal, date)
{
var dt = eval("document. "+frm_name+"."+ frm_fld);
dt.value = twodigit(date.g etMonth() + 1) + '/' +
twodigit(date.g etDate()) + '/' + date.getFullYea r();
}
if i include window.close( for the close button, the whole parent
window is only closing. I want to close only the calendar.
vinu
------------------------------------------------------------------------
Posted via http://www.forum4designers.com
------------------------------------------------------------------------
View this thread: http://www.forum4designers.com/message34935.html
Comment