JavaScript - Get Day From Formatted Date
I'm a bit confused as to how to use the getDay() function. I have an input field with a date in the following format 12.06.2012 and I'd like to run the function to get the day of the week from any date in that input field.
All the examples I have found using getDay(), do so from a new Date() and not from one existing in an input field. Also my format is not the usual 06/12/2012. Any help appreciated. Here's what I have tried: Code: var d="12.06.2012"; var weekday=new Array(7); weekday[0]="Sunday"; weekday[1]="Monday"; weekday[2]="Tuesday"; weekday[3]="Wednesday"; weekday[4]="Thursday"; weekday[5]="Friday"; weekday[6]="Saturday"; document.write("The day is " + weekday[d.getDay()]); Similar TutorialsSo I'm picking up on a project that was left off by another developer. He developed the search engine for this website using mustache.js as a templating plugin. However, I have this giant if/else statement in the Javascript to implement it in the template.. but it's ugly in my opinion so I'm curious on if anybody has a better way of going about this. Here is my template in the view: Code: <script id="search_result_item" type="x-tmpl-mustache"> <div id="Box_Book1" class="clearfix search-result-item"> <a href="{{encore_url}}"> <img id="Image1" src="{{ image_url }}" onerror="this.src = 'http://origin.syndetics.com/index.php?upc=x/MC.gif&client=stlip&type=hw7';" class="image {{material_type}}" /> <span class="{{ label_class }}">{{ label_text }}</span> </a> <div class="title-container"> <span id="textspan5" class="more-details"> <a href="{{ encore_url }}" target="_blank">+ More Details</a> </span> <div class="text-title1-container"> <p class="title"> {{ title }} </p> </div> </div> <p id="Text_Author1"> {{ author }}<br /> </p> </div> </script> Here is my Javascript that is rending into the template: Code: // this is gnarly i know..hopefully temporary var item_type = result.material_type; var label_class; var label_text; // This needs rewritten too once search is written in different format if(item_type == 'z') { // EBook label_class = 'ebook'; label_text = 'EBook'; } else if(item_type == 'w') { // EAudio label_class = 'eaudio'; label_text = 'EAudio'; } else if(item_type == 'x') { // EVideo label_class = 'evideo'; label_text = 'EVideo'; } else if(item_type == 'h') { // EMagazine label_class = 'emag'; label_text = 'EMag'; } var css_image_class = args.material_type; if (css_image_class == '24_7_online_library') { css_image_class = 'online_library'; } var template_args = { 'image_url' : image_url, 'error_image_url' : error_image_url, 'author' : result.author, 'title' : result.title, 'year' : '(' + result.year + ')', 'encore_url' : encore_url, 'material_type' : css_image_class, 'label_class' : label_class, 'label_text' : label_text }; div.html(Mustache.render(result_item_template, template_args)); Thank you for any ideas on how to make it prettier.. the item_type is what's terrifying ugly to me. Hi guys, Just wondering if this javascript is valid. I have about 150 variables, and I want to check, before I start writing it all out. Anything that could reduce it a bit would be great, save time and make the code more efficient! By the way, all values are numbers entered in a html text field. The script does calculations on it, and posts the result to a hidden field, which is submitted to a php email script. Code: <script language="JavaScript"> function calculate() { "use strict"; var sofa_3_seaterX = (document.form1.sofa_3_seater.value * 6); var sofa_2_seaterX = (document.form1.sofa_2_seater.value * 35); var armchair_largeX = (document.form1.armchair_large.value * 9); var armchair_smallX = (document.form1.armchair_small.value * 2); var wall_unitX = (document.form1.wall_unit.value * 3); var total = (sofa_3_seaterX + sofa_2_seaterX + armchair_largeX + armchair_smallX + wall_unitX); document.form1.total.value = total; } </script> Not sure if this is possible in javascript: I'm looking for two different dates (bill date and due date) on an invoice that are captured by OCR. If one of them exists, but the other does not, I want the empty field to be 14 days before (or after) the other. For example: if the bill date is 7/27/2010 and the due date was not captured, I want to set the due date as 8/10/2010 (14 days after the bill date). If the due date was captured as 8/10/2010, but the due date is blank, I want to assign the bill date as 7/27/2010 (14 days before the due date). if both dates have values, do nothing. Thanks. Hi, I've inherited a Form which calculates a future date based on a calculation and then inserts today's date and the future date into a database. The day part of the date is formatted as a number. This is fine, but up to 9 the numbers display in single figures with no leading zeros. I want them to display leading zeros (e.g. 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11... 30, 31) So; 1/12/2010 is NOT wanted 01/12/2010 IS wanted The inherited code originally set the Month names as "Jan", "Feb" etc, and it was easy to kludge these to 01, 02... 12, but I suspect there's a more elgant solution to this as well, this bit of the code works so it's not as vital to neaten this but my database needs dd/mm/yyyy format (it's a third party email program). Code: </script> <script type="text/javascript"> var todaysDate = new Date(); function updateExpiryDate(){ var weeklyMileage = document.getElementById('AvWeeklyMileage').value; var expiryDate; var weeks = 0; var expiryDateString = ''; if (!isNaN(parseInt(weeklyMileage))){ weeks = 700/weeklyMileage; expiryDate = new Date(todaysDate.getTime() + (1000 * 3600 * 24 * 7 * weeks)); var expiryDateString = expiryDate.getDate() + '/' + getMonthString(expiryDate.getMonth()+1) + '/' + expiryDate.getFullYear(); document.getElementById('expiryDate').innerHTML = expiryDateString; document.getElementById('ShoeExpiryDate').value = expiryDateString; } else { document.getElementById('ShoeExpiryDate').value = ''; document.getElementById('expiryDate').innerHTML = 'Please enter a valid weekly average mileage' } } function getMonthString(monthNumber){ var monthString = ""; switch(monthNumber){ case 1: monthString = "01"; break; case 2: monthString = "02"; break; case 3: monthString = "03"; break; case 4: monthString = "04"; break; case 5: monthString = "05"; break; case 6: monthString = "06"; break; case 7: monthString = "07"; break; case 8: monthString = "08"; break; case 9: monthString = "09"; break; case 10: monthString = "10"; break; case 11: monthString = "11"; break; case 12: monthString = "12"; break; default: // do nothing; } return monthString; } function setTodaysDate(){ var todaysDateString = todaysDate.getDate() + '/' + getMonthString(todaysDate.getMonth()+1) + '/' + todaysDate.getFullYear(); document.getElementById('todaysDate').innerHTML =todaysDateString; document.getElementById('DateOfPurchase').value = todaysDateString; } Can someone point me in the right direction please? Hi, I need to add days to a date in javascript, My requirement is as follows: Date is coming from a textbox. eg:- 26/07/2010 days from this statement var day1=document.getElementById('<%=HiddenDate.ClientID %>').value; an eg:- if the date is 28/01/2012 and days Needed to be added=5 the added date should be 02/02/2012. Can anybody help me? Thanks Jamuna Using Adobe Form Javascript validation, how would I do this code for Visual Basic in Javascript (non web) Code: If PurchaseDate.Value > Date Then MsgBox ("PurchaseDate cannot be greater than Today's Date!") Cancel = True End If Something along these lines but this isnt working: Code: If (PurchaseDate.Value > Date) Then { app.alert ("Purchase Date cannot be greater than Today's Date!"); } Thanks I have a drop down menu where people can select a month, day and year. Based on their selection, I want to show them an image. If their selection is >= July 26, 2010 but <= July 25, 2011, show the red image; If their selection is >= July 26, 2011 but <= July 25, 2012, show the white image; If their selection is >= July 26, 2012 but <= July 25, 2013, show the blue image; If their selection is >= July 26, 2013 but <= July 25, 2014, show the yellow image; I don't know how to compare a selected date to a range of dates like this. Hello, I really need your help with one. How can I use the following code below to save the date from my popup window datepicker back into a var and relay it back onto its parent page? I can't seem to figure this out: Code: <html> <head> <script> function open_cal() { var str_html = "" + "<!DOCTYPE html>\n" + "<html lang=\"en\">\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>CALENDAR</title>\n" + "<link href=\"jq/jquery-ui.css\" rel=\"stylesheet\" type=\"text/css\">\n" + "<script src=\"jq/jquery.min.js\" type=\"text/javascript\"></" + "script>\n" + "<script src=\"jq/jquery-ui.min.js\" type=\"text/javascript\"></" + "script>\n" + "<script src=\"jq/datepicker.js\" type=\"text/javascript\"></" + "script>\n" + "</head>\n" + "<body>\n" + "<div id=\"text\" style=\"font: bold 10pt Tahoma\">Enter Approval Date:</div>\n" + "<div id=\"datepicker\"></div>\n" + "</body>\n" + "</html>" var j = window.open("","CALENDAR","width=200,height=250,status=no,resizable=yes,top=200,left=200") j.opener = self; j.document.write(str_html); } </script> </head> <body> <input onclick="open_cal()" type="button" value="Open" name="B1"> </body> </html> Datepicker.js: Code: $(function() { $( "#datepicker" ).datepicker({ dateFormat: 'dd/mm/yy', onSelect: function(dateText, inst) { alert(dateText) window.close() } }) }); Any help with this is greatly and mostly appreciated. Thanks in advance, Cheers, J hello there this is in vb script. but i dont where to post it. can any one hlep me out plzz I need to check if the date entered by user is within 5th date from current date. I am trying to do it this way entered date has month and date value Code: sResvDate = 01/24 Set sMaxDays to getdate(5) but get date will give year too. and how do i compare if it less than 5th day or not. Hi folks, i am trying to generate a dynamic datefield with date mask "mm/dd/yyyy" and trying to insert it into Oracle db ...i still got the error ORA invalid month ehich means the date filed is not recognized as date: below is what i am doing : newStartDate = document.createElement( 'INPUT' ); newStartDate.setAttribute('type','Date'); newStartDate.setAttribute('id1','id'+ elementid+elementrow); newStartDate.setAttribute('name','StartDateName'+ elementid+elementrow); newStartDate.size=8; newStartDate.style.backgroundColor= bgc; any help thanks ?? Also i want to add a datepicke to this textbox..how it is posible / other option is to use Jquery datepicker but could not know how to impement it thanks again I am delving into the coding world and while I understand the basic principle of cookies, conditional statements, arrays, etc... I am still learning how to properly implement them. Any asistance with the following situation would be greatly appreciated and help with my learning as I try to reverse engineer the logic. I have looked around the web and this forum with little success. If the situation below is too complicated, I would really appreciate even a shove in the right direction regarding the logic. ----------------- How could I show a preset counter which counts up from a preset, beginning number toward a preset, end number? I imagine the increment and speed is set be the difference between the two numbers and a timeframe. Assumptions: I would rather not set the increment but edit the end number to show a steady increase. As I update that number, the increment adapts dynamically. I would want the number/script to be useful, so it should not refresh to the beginning number on each page load (i.e. num=0). When a visitor comes to the page, it must seem like the counter has been steadily been increasing in their absence. Coke or Pesi did something similar one time regarding cans sold to date (doubt it was plugged into a DB somewhere but rather based on a steady sales figure) and it was pretty cool. All the best! Hi, i need to get the current date into some format so that it doesn't change? here i have some code: Code: function printTime(){ var d=new Date(); var utc = d.toUTCString(); alert(utc); } for example this show for me: Mon, 26 Dec 2011 21:55:43 GMT I would like to get this information again, lets say 5 minutes later - but i want the information to still read Mon, 26 Dec 2011 21:55:43 GMT not Mon, 26 Dec 2011 22:00:43 GMT for example Any help greatly appreciated I acquired this from joh6nn a year ago and now need one small addtion. This code produces the next meeting date based on one's local PC date. For the days, I need ST, ND, RD, TH added. For example, instead of "August 29", I need it to kick out "August 29th". Possible!?
Code: <table border="0" cellpadding="2" cellspacing="0" width="100%" bgcolor="#EFEFEF"> <!-- BEGIN NEXT BOOSTER CLUB AND NEXT GAME NOTICES --> <tr> <td width="13" valign="top"><img border="0" src="images/dot_red_anim_13x13.gif" width="13" height="13"></td> <td valign="top"><span class="bold"><span class="red">Next Booster Club Meeting:</span></span><br> <!-- SCRIPT below automatically updates the date of the next meeting based on the PC's date --> <script> var Schedule = new Array(12); for ( var i = 0; i < 12; i++ ) { Schedule[i ] = new Array(); } var Games = new Array(12); for ( var i = 0; i < 12; i++ ) { Games[i ] = new Array(); } var weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; // Set the days you want // Because the array starts with 0, 0=January, 1=February, and so on. So, the month [7] below is one number behind the actual month number // Schedule[month-1][day] = ["first message" , "second message"]; // Schedule[7][20] = ["7:00PM" , "THIS IS THE TOPIC TEXT"]; --- see original script in another file...shows where "topic" line is added, etc. Schedule[7][19] = ["7:00pm" , ""]; // AUGUST Schedule[7][26] = ["7:00pm" , ""]; Games[7][29] = ["7:30pm", "Leander (@ Leander)"]; // Season Opener Schedule[8][2] = ["7:00pm" , ""]; // SEPTEMBER Schedule[8][9] = ["7:00pm" , ""]; Games[8][12] = ["7:30pm" , "Westwood (@ Burger Center)"]; Schedule[8][16] = ["7:00pm" , ""]; Games[8][19] = ["7:30pm" , "McNeil (@ Round Rock)"]; Schedule[8][23] = ["7:00pm" , ""]; Games[8][26] = ["7:30pm" , "Hays (@ Burger Center)"]; Schedule[8][30] = ["7:00pm" , ""]; Games[9][3] = ["7:30pm" , "S F Austin (@ House Park)"]; // OCTOBER Schedule[9][7] = ["7:00pm" , ""]; Games[9][9] = ["7:00pm" , "Westlake (@ Burger Center)"]; Schedule[9][14] = ["7:00pm" , ""]; Games[9][17] = ["7:30pm" , "Seguin (@ Seguin)"]; Schedule[9][21] = ["7:00pm" , ""]; Games[9][23] = ["7:00pm" , "Akins (@ Burger Center)"]; Schedule[9][28] = ["7:00pm" , ""]; Games[9][30] = ["7:00pm" , "San Marcos (@ Burger Center)"]; Schedule[10][4] = ["7:00pm" , ""]; // NOVEMBER Games[10][7] = ["7:30pm" , "Crockett (@ Burger Center)"]; Schedule[10][11] = ["7:00pm" , ""]; // ADD MORE MEETINGS AND-OR PLAYOFF EVENTS HERE .... WHAT YOU SEE IS FROM 2002 RIGHT NOW // Games[10][16] = ["1:00pm" , "Judson (@ Hays Stadium)"]; // Schedule[10][18] = ["7:00pm" , ""]; // Schedule[10][25] = ["7:00pm" , ""]; function dateWriter() { var today, then, start; today = new Date(); if ( Schedule[today.getMonth()][today.getDate()] ) {// only true if you explicitly set it return ("Today at " + Schedule[today.getMonth()][today.getDate()][0] + '.'); } else { for (var m = today.getMonth(); m < 12; m++) { start = ( m == today.getMonth() ) ? today.getDate() : 1; for (var d = start; d < 31; d++) { if (Schedule[m][d]) { then = new Date(today.getFullYear(), m, d); return (weekdays[then.getDay()] + ", " + months[m] + " " + d + " @ " + Schedule[m][d][0]); } } } } } function dateWriter2() { var today, then, start; today = new Date(); if ( Games[today.getMonth()][today.getDate()] ) {// only true if you explicitly set it return ("Today at " + Games[today.getMonth()][today.getDate()][0] + ' vs ' + Games[today.getMonth()][today.getDate()][1]+'.'); } else { for (var m = today.getMonth(); m < 12; m++) { start = ( m == today.getMonth() ) ? today.getDate() : 1; for (var d = start; d < 31; d++) { if (Games[m][d]) { then = new Date(today.getFullYear(), m, d); return (weekdays[then.getDay()] + ", " + months[m] + " " + d + " @ " + Games[m][d][0] + "<br>" + " vs " + Games[m][d][1]); } } } } } document.writeln("<span class='bold'>" + dateWriter() + " in the cafeteria.</span><br>All football parents are highly encouraged to attend!"); document.writeln("<br><img src='images/1x1.gif' width='1' height='5' border='0'></td></tr>"); document.writeln("<tr><td width='13' valign='top'><img border='0' src='images/dot_red_anim_13x13.gif' width='13' height='13'></td><td valign='top'><span class='bold'><span class='red'>Next Game (<a href='schedule_v.htm'><span class='bold'>details</span></a>):</span></span></span><br><span class='bold'>" + dateWriter2() + "</span><br><img src='images/1x1.gif' width='1' height='5' border='0'></td></tr>"); // document.writeln(dateWriter2()); </script> </td> </tr> </table> Hi guys, I hope to seek your help about the date function. I had the date store in my database under the type of timestamp. Now i wish to retrieve out the date store on my database and match it with today date however, I am facing problem with it. I know that I had to create a variable for it, however, after trying for many time, it still show me error. Would appreciate your kind help I have found many examples for checking CC exp year and month, but none that do this type of format. I know Js doesn't have a native explode function or anything of the sort so I don't know where to even begin. I have already checked if the field is empty, now what I need to do is validate the expiration date, the date is in format "MM/YY". Any ideas? hi friends, i have one textbox(txtdate) ,if user enters into the textbox automatically it has to format (dd/mm/yyyy). how to do. for your reference i have vbscript code but i don't know how to convert. can u please tell me . vbscript code: Hi all, I have vbscript code to validate date.can u please tell me how to convert it to javascript. Code: <script language='vbscript'> <!-- Function formatDate() Dim sMonth Dim sDay Dim sYear Dim sDate Dim vDate Dim sDateValue Dim dateformat Dim regEx Dim bTest Dim scMonth Dim scYear Dim vYear On error resume next formatDate=True sCurrDay = Right("0" & Cstr(Day(Now())),2) sCurrYear = Cstr(Year(Now())) sDateValue = window.event.srcElement.value if (len(sDateValue)=0) Then Exit Function Select Case len(sDateValue) Case 1: If (sDateValue="0") Then sDateValue = "1" End If sDateValue = "0" & sDateValue & "/" & sCurrDay & "/" & sCurrYear Case 2: sDateValue = sDateValue & "/" & sCurrDay & "/" & sCurrYear Case 3: sDateValue = sDateValue & sCurrDay & "/" & sCurrYear Case 4: sDateValue = Mid(sDateValue,1,3) & "0" & Mid(sDateValue,4,1) & "/" & sCurrYear Case 5: sDateValue = sDateValue & "/" & sCurrYear Case 6: sDateValue = sDateValue & sCurrYear Case 7: if (Mid(sDateValue,7,1)="1") then sDateValue = Mid(sDateValue,1,7) & "9" Else sDateValue = Mid(sDateValue,1,7) & "0" End If Case 8: window.event.srcElement.value = sDateValue Case 9: sDateValue=mid(sDateValue,1,6) & mid(sdateValue,8,2) Case Else If (len(sDateValue)<>10 and len(sDateValue)<>8) Then window.event.cancelBubble=true window.event.returnValue = false window.event.srcElement.setAttribute "valid","false" alert "Invalid Date, must enter 8 or 10 characters!" window.event.cancelBubble=true Window.event.returnValue = False window.event.srcElement.focus() window.event.srcElement.select() window.event.cancelBubble=true Window.event.returnValue = False formatDate=False On Error Goto 0 Exit Function End If End Select If (instr(1,sDateValue,"/") or instr(1,sDateValue,"-")) Then sDate=sDateValue Else sMonth = Mid(sDateValue,1,2) sDay = Mid(sDateValue,3,2) sYear = Mid(sDateValue,5,4) sDate = translateDate(sMonth,sDay,sYear) End If sMonth = Mid(sDateValue, 1, 2) If (CLng(sMonth) > 12 Or CLng(sMonth) < 0) Then window.event.cancelBubble=true Window.event.returnValue = False window.event.srcElement.setAttribute "valid","false" alert "Invalid Month!" window.event.cancelBubble=true Window.event.returnValue = False Window.event.srcElement.focus() window.event.srcElement.select() window.event.cancelBubble=true Window.event.returnValue = False formatDate=False Exit Function End If on error resume next vDate = CDate(sDate) If (Err.number <> 0) Then window.event.cancelBubble=true window.event.returnValue = false window.event.srcElement.setAttribute "valid","false" alert "Invalid Date!" window.event.cancelBubble=true Window.event.returnValue = False window.event.srcElement.focus() window.event.srcElement.select() window.event.cancelBubble=true Window.event.returnValue = False formatDate=False Else vYear=Year(vDate) If (vYear<1980) Then window.event.cancelBubble=true window.event.returnValue = false window.event.srcElement.setAttribute "valid","false" alert "The date must be greater than 1979!" window.event.cancelBubble=true Window.event.returnValue = False window.event.srcElement.focus() window.event.srcElement.select() window.event.cancelBubble=true Window.event.returnValue = False formatDate=False Else window.event.srcElement.value = sDate window.event.srcElement.setAttribute "valid","true" window.event.returnValue=true End If End If On Error Goto 0 End Function //--> </script> Regards Hi, Got input boxes for begin and end dates - using JQuery for date picker calendar for each. Need to validate 2 things - 1 is that end date is => than begin date, 2 is that user enters date into begin date rather than just numbers. I got date picker JQuery from another office where I work and can not change their parameters or code. So my input boxes allow for date picker selection or manual data entry. The end date input box can be empty if user only inputting one day for begin date and not a range. Also have 3 more begin/end date input box sets which are not visible until user clicks "Add Row" button - one click, one set added. Want to insure if user added row and input date then removed row (clicked "Remove Row" button) that the data entered is removed and not inserted into database. Add & remove rows: Code: <script type="text/javascript"> var showing = 0; function showAnother() { if ( showing <= 3 ) { ++showing; document.getElementById("row"+showing).style.display =""; } if ( showing == 3) { alert("Maximum number of rows allowed."); } } </script> <script type="text/javascript"> function removeRow() { if ( showing >= 0 ) { document.getElementById("row"+showing).style.display ="none"; showing--; } if ( showing == 0 ) { return true; } } </script> Begin & end date input boxes: Code: <td><input style="width: 70px" type="text" id="startdate1" name="startdate1" /></td> <td><input name="stopdate1" style="width: 70px" type="text" id="stopdate1"/></td> Other 3 begin & end date input boxes same with names increased by one digit - startdate2/stopdate2, and so on to 4. Thanks, John I can't wrap my head around this at the moment so with the hope of finding someone willing to take a stab I am posting this to all of you. I need to create a savings ticker that shows $ saved per second. The data is as follows then = date script is created now = current date std = savings to date in $ avg = average savings per second in $ It would need to calculate the difference in time between then and now, convert that to an integer that can then be multiplied by avg then std would be added. thanks in advance Hello, and thanks for a great forum I have downloaded a script called Display time of last visit. Since I live in Norway, so the date is on the wrong line. It's November 18, but I want the date to be before the month if ya know what I mean. Is there anyone out there who can be so kind and help me change the script so that it is correct? I've tried, but ..... this is what it says now: Thursday, November 18, 2010 09:59:28 AM I want it to be (is it is possibe to remove AM ?) Thursday, 18, November 2010 09:59:28 AM Sincerely, from Norway Jon isprinsessa.com hi there all, i am working on an application built using JSP, and many screens in the application have date fields that use a calendar.js file to show and pick the date. the requirement is to set a validation where the user cannot enter a date bigger than the current date, fair enough, but my problem is that i am a newb and this whole application is built by ppl that don't work for my company no more so im stuck with it, below is the calendar.js file maybe u guys could help me on where should i put the validation. thanks in advance Code: var weekend = [4,5]; var weekendColor = "#EAF4D6"; var fontface = "Verdana"; var fontsize = 1; var TYPE = 1; // 1 for arabic and 2 for hirji var gNow = new Date(); var ggWinCal; isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false; isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false; Calendar.Months = ["�����", "������", "����", "�����", "����", "�����", "�����", "�����", "������", "�������", "�����", "������"]; // Non-Leap year Month days.. Calendar.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; // Leap year Month days.. Calendar.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; function Calendar(p_item, p_WinCal, p_month, p_year, p_format) { if ((p_month == null) && (p_year == null)) return; if (p_WinCal == null) this.gWinCal = ggWinCal; else this.gWinCal = p_WinCal; if (p_month == null) { this.gMonthName = null; this.gMonth = null; this.gYearly = true; } else { this.gMonthName = Calendar.get_month(p_month); this.gMonth = new Number(p_month); this.gYearly = false; } this.gYear = p_year; this.gFormat = p_format; this.gBGColor = "white"; this.gFGColor = "black"; this.gTextColor = "black"; this.gHeaderColor = "black"; this.gReturnItem = p_item; } Calendar.get_month = Calendar_get_month; Calendar.get_daysofmonth = Calendar_get_daysofmonth; Calendar.calc_month_year = Calendar_calc_month_year; Calendar.print = Calendar_print; function Calendar_get_month(monthNo) { return Calendar.Months[monthNo]; } function Calendar_get_daysofmonth(monthNo, p_year) { /* Check for leap year .. 1.Years evenly divisible by four are normally leap years, except for... 2.Years also evenly divisible by 100 are not leap years, except for... 3.Years also evenly divisible by 400 are leap years. */ if ((p_year % 4) == 0) { if ((p_year % 100) == 0 && (p_year % 400) != 0) return Calendar.DOMonth[monthNo]; return Calendar.lDOMonth[monthNo]; } else return Calendar.DOMonth[monthNo]; } function Calendar_calc_month_year(p_Month, p_Year, incr) { /* Will return an 1-D array with 1st element being the calculated month and second being the calculated year after applying the month increment/decrement as specified by 'incr' parameter. 'incr' will normally have 1/-1 to navigate thru the months. */ var ret_arr = new Array(); if (incr == -1) { // B A C K W A R D if (p_Month == 0) { ret_arr[0] = 11; ret_arr[1] = parseInt(p_Year) - 1; } else { ret_arr[0] = parseInt(p_Month) - 1; ret_arr[1] = parseInt(p_Year); } } else if (incr == 1) { // F O R W A R D if (p_Month == 11) { ret_arr[0] = 0; ret_arr[1] = parseInt(p_Year) + 1; } else { ret_arr[0] = parseInt(p_Month) + 1; ret_arr[1] = parseInt(p_Year); } } return ret_arr; } function Calendar_print() { ggWinCal.print(); } function Calendar_calc_month_year(p_Month, p_Year, incr) { /* Will return an 1-D array with 1st element being the calculated month and second being the calculated year after applying the month increment/decrement as specified by 'incr' parameter. 'incr' will normally have 1/-1 to navigate thru the months. */ var ret_arr = new Array(); if (incr == -1) { // B A C K W A R D if (p_Month == 0) { ret_arr[0] = 11; ret_arr[1] = parseInt(p_Year) - 1; } else { ret_arr[0] = parseInt(p_Month) - 1; ret_arr[1] = parseInt(p_Year); } } else if (incr == 1) { // F O R W A R D if (p_Month == 11) { ret_arr[0] = 0; ret_arr[1] = parseInt(p_Year) + 1; } else { ret_arr[0] = parseInt(p_Month) + 1; ret_arr[1] = parseInt(p_Year); } } return ret_arr; } // This is for compatibility with Navigator 3, we have to create and discard one object before the prototype object exists. new Calendar(); Calendar.prototype.getMonthlyCalendarCode = function() { var vCode = ""; var vHeader_Code = ""; var vData_Code = ""; // Begin Table Drawing code here.. vCode = vCode + "<TABLE BORDER=1 WIDTH='100%' BGCOLOR=\"" + this.gBGColor + "\">"; vHeader_Code = this.cal_header(); vData_Code = this.cal_data(); vCode = vCode + vHeader_Code + vData_Code; vCode = vCode + "</TABLE>"; return vCode; } Calendar.prototype.show = function() { var vCode = ""; this.gWinCal.document.open(); // Setup the page... this.wwrite("<html>"); this.wwrite("<head><title>������� ��������</title>"); this.wwrite("</head>"); this.wwrite("<body dir=\"rtl\"" + "link=\"" + this.gLinkColor + "\" " + "vlink=\"" + this.gLinkColor + "\" " + "alink=\"" + this.gLinkColor + "\" " + "text=\"" + this.gTextColor + "\">"); this.wwriteA("<FONT FACE='" + fontface + "' SIZE=1 COLOR='#914848'><B>"); this.wwriteA(this.gMonthName + " " + this.gYear); this.wwriteA("</B><BR>"); // Show navigation buttons var prevMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, -1); var prevMM = prevMMYYYY[0]; var prevYYYY = prevMMYYYY[1]; var nextMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, 1); var nextMM = nextMMYYYY[0]; var nextYYYY = nextMMYYYY[1]; this.wwrite("<TABLE width='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#EAF4D6'><TR><TD BGCOLOR='#EAF4D6' ALIGN=center><FONT FACE='Verdana' SIZE='1'>"); this.wwrite("[<A HREF=\"" + "javascript:window.opener.Build(" + "'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)-1) + "', '" + this.gFormat + "'" + ");" + "\"><<<\/A>]</B></FONT></TD><TD BGCOLOR='#EAF4D6' ALIGN=center><FONT FACE='Verdana' SIZE='1'>"); this.wwrite("[<A HREF=\"" + "javascript:window.opener.Build(" + "'" + this.gReturnItem + "', '" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "'" + ");" + "\"><<\/A>]</FONT></TD><TD BGCOLOR='#EAF4D6' ALIGN=center><FONT FACE='Verdana' SIZE='1'>"); this.wwrite("[<A HREF=\"javascript:window.print();\">Print</A>]</FONT></TD><TD BGCOLOR='#EAF4D6' ALIGN=center><FONT FACE='Verdana' SIZE='1'>"); this.wwrite("[<A HREF=\"" + "javascript:window.opener.Build(" + "'" + this.gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "'" + ");" + "\">><\/A>]</FONT></TD><TD BGCOLOR='#EAF4D6' ALIGN=center><FONT FACE='Verdana' SIZE='1'>"); this.wwrite("[<A HREF=\"" + "javascript:window.opener.Build(" + "'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)+1) + "', '" + this.gFormat + "'" + ");" + "\">>><\/A>]</FONT></TD></TR></TABLE><BR>"); // Get the complete calendar code for the month.. vCode = this.getMonthlyCalendarCode(); this.wwrite(vCode); this.wwrite("</font></body></html>"); this.gWinCal.document.close(); } Calendar.prototype.showY = function() { var vCode = ""; var i; var vr, vc, vx, vy; // Row, Column, X-coord, Y-coord var vxf = 285; // X-Factor var vyf = 200; // Y-Factor var vxm = 10; // X-margin var vym; // Y-margin if (isIE) vym = 75; else if (isNav) vym = 25; this.gWinCal.document.open(); this.wwrite("<html>"); this.wwrite("<head><title>������� ��������</title>"); this.wwrite("<style type='text/css'>\n<!--"); for (i=0; i<12; i++) { vc = i % 3; if (i>=0 && i<= 2) vr = 0; if (i>=3 && i<= 5) vr = 1; if (i>=6 && i<= 8) vr = 2; if (i>=9 && i<= 11) vr = 3; vx = parseInt(vxf * vc) + vxm; vy = parseInt(vyf * vr) + vym; this.wwrite(".lclass" + i + " {position:absolute;top:" + vy + ";left:" + vx + ";}"); } this.wwrite("-->\n</style>"); this.wwrite("</head>"); this.wwrite("<body " + "link=\"" + this.gLinkColor + "\" " + "vlink=\"" + this.gLinkColor + "\" " + "alink=\"" + this.gLinkColor + "\" " + "text=\"" + this.gTextColor + "\">"); this.wwrite("<FONT FACE='" + fontface + "' SIZE=2><B>"); this.wwrite("Year : " + this.gYear); this.wwrite("</B><BR>"); // Show navigation buttons var prevYYYY = parseInt(this.gYear) - 1; var nextYYYY = parseInt(this.gYear) + 1; //Here this.wwrite("<TABLE width='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#B6DADA'><TR BGCOLOR='#B6DADA'><TD BGCOLOR='#B6DADA' ALIGN=center>"); this.wwrite("[<A HREF=\"" + "javascript:window.opener.Build(" + "'" + this.gReturnItem + "', null, '" + prevYYYY + "', '" + this.gFormat + "'" + ");" + "\" alt='Prev Year'><<<\/A>]</TD><TD ALIGN=center>"); this.wwrite("[<A HREF=\"javascript:window.print();\">Print</A>]</TD><TD ALIGN=center>"); this.wwrite("[<A HREF=\"" + "javascript:window.opener.Build(" + "'" + this.gReturnItem + "', null, '" + nextYYYY + "', '" + this.gFormat + "'" + ");" + "\">>><\/A>]</TD></TR></TABLE><BR>"); // Get the complete calendar code for each month.. var j; for (i=11; i>=0; i--) { if (isIE) this.wwrite("<DIV ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">"); else if (isNav) this.wwrite("<LAYER ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">"); this.gMonth = i; this.gMonthName = Calendar.get_month(this.gMonth); vCode = this.getMonthlyCalendarCode(); this.wwrite(this.gMonthName + "/" + this.gYear + "<BR>"); this.wwrite(vCode); if (isIE) this.wwrite("</DIV>"); else if (isNav) this.wwrite("</LAYER>"); } this.wwrite("</font><BR></body></html>"); this.gWinCal.document.close(); } Calendar.prototype.wwrite = function(wtext) { this.gWinCal.document.writeln(wtext); } Calendar.prototype.wwriteA = function(wtext) { this.gWinCal.document.write(wtext); } Calendar.prototype.cal_header = function() { var vCode = ""; vCode = vCode + "<TR>"; vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='1' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>���</B></FONT></TD>"; vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='1' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>�����</B></FONT></TD>"; vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='1' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>������</B></FONT></TD>"; vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='1' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>������</B></FONT></TD>"; vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='1' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>����</B></FONT></TD>"; vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='1' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>����</B></FONT></TD>"; vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='1' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>���</B></FONT></TD>"; vCode = vCode + "</TR>"; return vCode; } Calendar.prototype.cal_data = function() { var vDate = new Date(); vDate.setDate(1); vDate.setMonth(this.gMonth); vDate.setFullYear(this.gYear); var vFirstDay=vDate.getDay(); var vDay=1; var vLastDay=Calendar.get_daysofmonth(this.gMonth, this.gYear); var vOnLastDay=0; var vCode = ""; /* Get day for the 1st of the requested month/year.. Place as many blank cells before the 1st day of the month as necessary. */ vCode = vCode + "<TR>"; for (i=0; i<vFirstDay; i++) { vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(i) + "><FONT SIZE='1' FACE='" + fontface + "'> </FONT></TD>"; } // Write rest of the 1st week for (j=vFirstDay; j<7; j++) { vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='1' FACE='" + fontface + "'>" + "<A HREF='#' " + "onClick=\"self.opener.document." + this.gReturnItem + ".value='" + this.format_data(vDay) + "';window.close();\">" + this.format_day(vDay) + "</A>" + "</FONT></TD>"; vDay=vDay + 1; } vCode = vCode + "</TR>"; // Write the rest of the weeks for (k=2; k<7; k++) { vCode = vCode + "<TR>"; for (j=0; j<7; j++) { vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='1' FACE='" + fontface + "'>" + "<A HREF='#' " + "onClick=\"self.opener.document." + this.gReturnItem + ".value='" + this.format_data(vDay) + "';window.close();\">" + this.format_day(vDay) + "</A>" + "</FONT></TD>"; vDay=vDay + 1; if (vDay > vLastDay) { vOnLastDay = 1; break; } } if (j == 6) vCode = vCode + "</TR>"; if (vOnLastDay == 1) break; } // Fill up the rest of last week with proper blanks, so that we get proper square blocks for (m=1; m<(7-j); m++) { if (this.gYearly) vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) + "><FONT SIZE='1' FACE='" + fontface + "' COLOR='gray'> </FONT></TD>"; else vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) + "><FONT SIZE='1' FACE='" + fontface + "' COLOR='gray'>" + m + "</FONT></TD>"; } return vCode; } Calendar.prototype.format_day = function(vday) { var vNowDay = gNow.getDate(); var vNowMonth = gNow.getMonth(); var vNowYear = gNow.getFullYear(); var oDay = (vday.toString().length < 2) ? "0" + vday : vday; var oMon = parseInt(this.gMonth)+1; oMon = (oMon.toString().length < 2) ? "0" + oMon : oMon; var oDate = oDay+"/"+oMon+"/"+this.gYear; // if (TYPE ==1) // { if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear) return ("<FONT FACE=\"verdana\" SIZE=\"1\" COLOR=\"#914848\"><B>" + vday + "</B></FONT>"); else return (vday); /* } else { if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear) return ("<FONT FACE=\"verdana\" SIZE=\"1\" COLOR=\"#914848\"><B>" + convDay(oDate) + "</B></FONT>"); else return (convDay(oDate)); } */ } Calendar.prototype.write_weekend_string = function(vday) { var i; // Return special formatting for the weekend day. for (i=0; i<weekend.length; i++) { if (vday == weekend[i]) return (" BGCOLOR=\"" + weekendColor + "\""); } return ""; } Calendar.prototype.format_data = function(p_day) { var vData; var vMonth = 1 + this.gMonth; vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth; var vMon = Calendar.get_month(this.gMonth).substr(0,3).toUpperCase(); var vFMon = Calendar.get_month(this.gMonth).toUpperCase(); var vY4 = new String(this.gYear); var vY2 = new String(this.gYear.substr(2,2)); var vDD = (p_day.toString().length < 2) ? "0" + p_day : p_day; switch (this.gFormat) { case "MM\/DD\/YYYY" : vData = vMonth + "\/" + vDD + "\/" + vY4; break; case "MM\/DD\/YY" : vData = vMonth + "\/" + vDD + "\/" + vY2; break; case "MM-DD-YYYY" : vData = vMonth + "-" + vDD + "-" + vY4; break; case "MM-DD-YY" : vData = vMonth + "-" + vDD + "-" + vY2; break; case "DD\/MON\/YYYY" : vData = vDD + "\/" + vMon + "\/" + vY4; break; case "DD\/MON\/YY" : vData = vDD + "\/" + vMon + "\/" + vY2; break; case "DD-MON-YYYY" : vData = vDD + "-" + vMon + "-" + vY4; break; case "DD-MON-YY" : vData = vDD + "-" + vMon + "-" + vY2; break; case "DD\/MONTH\/YYYY" : vData = vDD + "\/" + vFMon + "\/" + vY4; break; case "DD\/MONTH\/YY" : vData = vDD + "\/" + vFMon + "\/" + vY2; break; case "DD-MONTH-YYYY" : vData = vDD + "-" + vFMon + "-" + vY4; break; case "DD-MONTH-YY" : vData = vDD + "-" + vFMon + "-" + vY2; break; case "DD\/MM\/YYYY" : vData = vDD + "\/" + vMonth + "\/" + vY4; break; case "DD\/MM\/YY" : vData = vDD + "\/" + vMonth + "\/" + vY2; break; case "DD-MM-YYYY" : vData = vDD + "-" + vMonth + "-" + vY4; break; case "DD-MM-YY" : vData = vDD + "-" + vMonth + "-" + vY2; break; default : vData = vDD + "\/" + vMonth + "\/" + vY4; } if (TYPE == 2) { vData = convDate(vData); } return vData; } function Build(p_item, p_month, p_year, p_format,type) { var p_WinCal = ggWinCal; gCal = new Calendar(p_item, p_WinCal, p_month, p_year, p_format,type); // Customize your Calendar here.. gCal.gBGColor="white"; gCal.gLinkColor="#27570E"; gCal.gTextColor="#27570E"; gCal.gHeaderColor="#27570E"; // Choose appropriate show function if (gCal.gYearly) gCal.showY(); else gCal.show(); } function show_calendar() { /* p_month : 0-11 for Jan-Dec; 12 for All Months. p_year : 4-digit year p_format: Date format (mm/dd/yyyy, dd/mm/yy, ...) p_item : Return Item. */ p_item = arguments[0]; if (arguments[1] == null) p_month = new String(gNow.getMonth()); else p_month = arguments[1]; if (arguments[2] == "" || arguments[2] == null) p_year = new String(gNow.getFullYear().toString()); else p_year = arguments[2]; if (arguments[3] == null) p_format = "DD/MM/YYYY"; else p_format = arguments[3]; TYPE = arguments[4]; vWinCal = window.open("", "Calendar", "width=232,height=190,status=no,resizable=no,top=200,left=200"); vWinCal.opener = self; ggWinCal = vWinCal; Build(p_item, p_month, p_year, p_format); } /* Yearly Calendar Code Starts here */ function show_yearly_calendar(p_item, p_year, p_format) { // Load the defaults.. if (p_year == null || p_year == "") p_year = new String(gNow.getFullYear().toString()); if (p_format == null || p_format == "") p_format = "DD/MM/YYYY"; var vWinCal = window.open("", "Calendar", "scrollbars=yes"); vWinCal.opener = self; ggWinCal = vWinCal; Build(p_item, null, p_year, p_format); } |