Click here to Skip to main content
15,875,568 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
<html>
<head>
<title>Trial</title>

<script type="text/javascript"> var DefaultDateFormat = 'MM/DD/YYYY';
var HideWait = 3;
var Y2kPivotPoint = 76;
var UnselectedMonthText = '';
var FontSize = 11;
var FontFamily = 'Tahoma';
var CellWidth = 18;
var CellHeight = 16;
var ImageURL = '/img/calendar.jpg';
var NextURL = '/img/next.gif';
var PrevURL = '/img/prev.gif';
var CalBGColor = 'white';
var TopRowBGColor = 'buttonface';
var DayBGColor = 'lightgrey';

var ZCounter = 100;
var Today = new Date();
var WeekDays = new Array('S','M','T','W','T','F','S');
var MonthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var MonthNames = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

with(document){writeln("");writeln("td.calendarDateInput {letter-spacing:normal;line-height:normal;font-family:"+FontFamily+",Sans-Serif;font-size:"+FontSize+"px;}");writeln("select.calendarDateInput {letter-spacing:.06em;font-family:Verdana,Sans-Serif;font-size:11px;}");writeln("input.calendarDateInput {letter-spacing:.06em;font-family:Verdana,Sans-Serif;font-size:11px;}");writeln("")}function YearDigitsOnly(B){var A=(B.keyCode)?B.keyCode:B.which;return((A==8)||(A==9)||(A==37)||(A==39)||(A==46)||((A>47)&&(A<58)))}function GetTagPixels(A,C){var B=(C=="LEFT")?A.offsetLeft:A.offsetTop;while((A.tagName!="BODY")&&(A.tagName!="HTML")){A=A.offsetParent;B+=(C=="LEFT")?A.offsetLeft:A.offsetTop}return B}function BehindCal(C,E,F,B,I,G){var A=GetTagPixels(C,"LEFT");var D=A+C.offsetWidth;var H=G+C.offsetHeight;return(((GB))&&((AE)))}function FixSelectLists(I){if(navigator.appName=="Microsoft Internet Explorer"){var G=this.getCalendar();var E=G.offsetLeft;var F=E+G.offsetWidth;var A=G.offsetTop;var H=A+(CellHeight*9);var B=false;formLoop:for(var C=this.formNumber;C4))||((this.displayed.dayCount==30)&&(this.displayed.firstDay==6))){C=6}else{if((this.displayed.dayCount==28)&&(this.displayed.firstDay==0)){C=4}}var D='';for(var A=0;A";for(var B=1;B<=7;B++){Day=(A*7)+(B-this.displayed.firstDay);if((Day>=1)&&(Day<=this.displayed.dayCount)){if((this.displayed.yearValue==this.picked.yearValue)&&(this.displayed.monthIndex==this.picked.monthIndex)&&(Day==this.picked.day)){TextStyle="color:white;font-weight:bold;";BackColor=DayBGColor}else{TextStyle="color:black;";BackColor=CalBGColor}if((this.displayed.yearValue==Today.getFullYear())&&(this.displayed.monthIndex==Today.getMonth())&&(Day==Today.getDate())){TextStyle+="border:1px solid darkred;padding:0px;"}D+='"}else{D+=''}}D+=""}return D+=""+Day+" "}function GetGoodYear(B){if(B.length==4){return B}else{var A=(B=E)?C.options[E]=null:C.options[B]=new Option(B+1,B+1)}A=Math.min(A,E);C.options[A-1].selected=true}return A}function FixYearInput(A){var B=new RegExp("\\d{"+A.defaultValue.length+"}");if(!B.test(A.value)){A.value=A.defaultValue}}function CalIconHover(B){var A=(this.isShowing())?"hide":"show";self.status=(B)?"Click to "+A+" the calendar":"";return true}function CalTimerReset(){eval("clearTimeout("+this.timerID+")");eval(this.timerID+"=setTimeout('"+this.objName+".show()',"+(HideWait*1000)+")")}function DoTimer(CancelTimer){if(CancelTimer){eval("clearTimeout("+this.timerID+")")}else{eval(this.timerID+"=null");this.resetTimer()}}function ShowCalendar(){if(this.isShowing()){var A=true;this.getCalendar().style.zIndex=--ZCounter;this.getCalendar().style.visibility="hidden";this.fixSelects(false)}else{var A=false;this.fixSelects(true);this.getCalendar().style.zIndex=++ZCounter;this.getCalendar().style.visibility="visible"}this.handleTimer(A);self.status=""}function SetElementStatus(A){this.getDayList().style.visibility=(A)?"hidden":"visible";this.getYearField().style.visibility=(A)?"hidden":"visible";this.getCalendarLink().style.visibility=(A)?"hidden":"visible"}function CheckMonthChange(C){var B=this.getDayList();if(C.options[C.selectedIndex].value==""){B.selectedIndex=0;this.hideElements(true);this.setHidden("")}else{this.hideElements(false);if(this.isShowing()){this.resetTimer();this.getCalendar().style.zIndex=++ZCounter}var A=FixDayList(B,GetDayCount(this.picked.yearValue,C.options[C.selectedIndex].value));this.setPicked(this.picked.yearValue,C.options[C.selectedIndex].value,A)}}function CheckDayChange(A){if(this.isShowing()){this.show()}this.setPicked(this.picked.yearValue,this.picked.monthIndex,A.selectedIndex+1)}function CheckYearInput(A){if((A.value.length==A.defaultValue.length)&&(A.defaultValue!=A.value)){if(this.isShowing()){this.resetTimer();this.getCalendar().style.zIndex=++ZCounter}var B=GetGoodYear(A.value);var C=this.getMonthList();var D=FixDayList(this.getDayList(),GetDayCount(B,this.picked.monthIndex));this.setPicked(B,this.picked.monthIndex,D);A.defaultValue=A.value}}function dateObject(){if(Function.call){var C=this;var B=0}else{var C=arguments[0];var B=1}C.date=(arguments.length==(B+1))?new Date(arguments[B+0]):new Date(arguments[B+0],arguments[B+1],arguments[B+2]);C.yearValue=C.date.getFullYear();C.monthIndex=C.date.getMonth();C.monthName=MonthNames[C.monthIndex];C.fullName=C.monthName+" "+C.yearValue;C.day=C.date.getDate();C.dayCount=GetDayCount(C.yearValue,C.monthIndex);var A=new Date(C.yearValue,C.monthIndex,1);C.firstDay=A.getDay()}function storedMonthObject(E,D,C,B){(Function.call)?dateObject.call(this,D,C,B):dateObject(this,D,C,B);this.yearPad=this.yearValue.toString();this.monthPad=(this.monthIndex<9)?"0"+String(this.monthIndex+1):this.monthIndex+1;this.dayPad=(this.day<10)?"0"+this.day.toString():this.day;this.monthShort=this.monthName.substr(0,3).toUpperCase();if(E.indexOf("YYYY")==-1){this.yearPad=this.yearPad.substr(2)}if(E.indexOf("/")>=0){var A="/"}else{if(E.indexOf("-")>=0){var A="-"}else{var A=""}}if(/DD?.?((MON)|(MM?M?))/.test(E)){this.formatted=this.dayPad+A;this.formatted+=(RegExp.$1.length==3)?this.monthShort:this.monthPad}else{if(/((MON)|(MM?M?))?.?DD?/.test(E)){this.formatted=(RegExp.$1.length==3)?this.monthShort:this.monthPad;this.formatted+=A+this.dayPad}}this.formatted=(E.substr(0,2)=="YY")?this.yearPad+A+this.formatted:this.formatted+A+this.yearPad}function displayMonthObject(D,C,B,A){(Function.call)?dateObject.call(this,C,B,A):dateObject(this,C,B,A);this.displayID=D.hiddenFieldName+"_Current_ID";this.getDisplay=new Function("return document.getElementById(this.displayID)");this.dayHover=DayCellHover;this.goCurrent=new Function(D.objName+".getCalendar().style.zIndex=++ZCounter;"+D.objName+".setDisplayed(Today.getFullYear(),Today.getMonth());");if(D.formNumber>=0){this.getDisplay().innerHTML=this.fullName}}function neighborMonthObject(B,A,C){(Function.call)?dateObject.call(this,C):dateObject(this,C);this.buttonID=B.hiddenFieldName+"_"+A+"_ID";this.hover=new Function("C","O","NeighborHover(C,O,this)");this.getButton=new Function("return document.getElementById(this.buttonID)");this.go=new Function(B.objName+".getCalendar().style.zIndex=++ZCounter;"+B.objName+".setDisplayed(this.yearValue,this.monthIndex);");if(B.formNumber>=0){this.getButton().title=this.monthName}}function SetDisplayedMonth(B,A){this.displayed=new displayMonthObject(this,B,A,1);this.previous=new neighborMonthObject(this,"Previous",this.displayed.date.getTime()-86400000);this.next=new neighborMonthObject(this,"Next",this.displayed.date.getTime()+(86400000*(this.displayed.dayCount+1)));if(this.formNumber>=0){this.getDayTable().innerHTML=this.buildCalendar()}}function SetPickedMonth(B,C,A){this.picked=new storedMonthObject(this.format,B,C,A);this.setHidden(this.picked.formatted);this.setDisplayed(B,C)}function calendarObject(F,J,E){this.hiddenFieldName=F;this.monthListID=F+"_Month_ID";this.dayListID=F+"_Day_ID";this.yearFieldID=F+"_Year_ID";this.monthDisplayID=F+"_Current_ID";this.calendarID=F+"_ID";this.dayTableID=F+"_DayTable_ID";this.calendarLinkID=this.calendarID+"_Link";this.timerID=this.calendarID+"_Timer";this.objName=F+"_Object";this.format=J;this.formNumber=-1;this.picked=null;this.displayed=null;this.previous=null;this.next=null;this.setPicked=SetPickedMonth;this.setDisplayed=SetDisplayedMonth;this.checkYear=CheckYearInput;this.fixYear=FixYearInput;this.changeMonth=CheckMonthChange;this.changeDay=CheckDayChange;this.resetTimer=CalTimerReset;this.hideElements=SetElementStatus;this.show=ShowCalendar;this.handleTimer=DoTimer;this.iconHover=CalIconHover;this.buildCalendar=BuildCalendarDays;this.pickDay=PickDisplayDay;this.fixSelects=FixSelectLists;this.setHidden=new Function("D","if (this.formNumber >= 0) this.getHiddenField().value=D");this.getHiddenField=new Function("return document.forms[this.formNumber].elements[this.hiddenFieldName]");this.getMonthList=new Function("return document.getElementById(this.monthListID)");this.getDayList=new Function("return document.getElementById(this.dayListID)");this.getYearField=new Function("return document.getElementById(this.yearFieldID)");this.getCalendar=new Function("return document.getElementById(this.calendarID)");this.getDayTable=new Function("return document.getElementById(this.dayTableID)");this.getCalendarLink=new Function("return document.getElementById(this.calendarLinkID)");this.getMonthDisplay=new Function("return document.getElementById(this.monthDisplayID)");this.isShowing=new Function("return !(this.getCalendar().style.visibility != 'visible')");function H(K){for(var L=0;LERROR: Missing required parameter in call to 'DateInput': [name of hidden date field].")}else{if(arguments.length<3){DateFormat=DefaultDateFormat;if(arguments.length<2){Required=false}}else{if(/^(Y{2,4}(-|\/)?)?((MON)|(MM?M?)|(DD?))(-|\/)?((MON)|(MM?M?)|(DD?))((-|\/)Y{2,4})?$/i.test(DateFormat)){DateFormat=DateFormat.toUpperCase()}else{var AlertMessage="WARNING: The supplied date format for the '"+DateName+"' field is not valid: "+DateFormat+"\nTherefore, the default date format will be used instead: "+DefaultDateFormat;DateFormat=DefaultDateFormat;if(arguments.length==4){var CurrentDate=new storedMonthObject(DateFormat,Today.getFullYear(),Today.getMonth(),Today.getDate());AlertMessage+="\n\nThe supplied date ("+DefaultDate+") cannot be interpreted with the invalid format.\nTherefore, the current system date will be used instead: "+CurrentDate.formatted;DefaultDate=CurrentDate.formatted}alert(AlertMessage)}}if(!CurrentDate){var CurrentDate=new storedMonthObject(DateFormat,Today.getFullYear(),Today.getMonth(),Today.getDate())}if(arguments.length<4){DefaultDate=(Required)?CurrentDate.formatted:""}eval(DateName+"_Object=new calendarObject('"+DateName+"','"+DateFormat+"','"+DefaultDate+"')");if((Required)||(arguments.length==4)){var InitialStatus="";var InitialDate=eval(DateName+"_Object.picked.formatted")}else{var InitialStatus=' style="visibility:hidden"';var InitialDate="";eval(DateName+"_Object.setPicked("+Today.getFullYear()+","+Today.getMonth()+","+Today.getDate()+")")}with(document){writeln('<input type="hidden" name="'+DateName+'" value="'+InitialDate+'">');for(var f=0;f<forms.length;f++){for(var e=0;e<forms[f].elements.length;e++){if(typeof>');if(!Required){var NoneSelected=(DefaultDate=="")?" selected":"";writeln('<option value=""'+NoneSelected+">"+UnselectedMonthText+"</option>")}for(var i=0;i<12;i++){MonthSelected=((DefaultDate!="")&&(eval(DateName+"_Object.picked.monthIndex")==i))?" selected":"";writeln('<option value="'+i+'"'+MonthSelected+">"+MonthNames[i].substr(0,3)+"</option>")}writeln("</select>"+String.fromCharCode(13)+"');writeln("<select"+InitialStatus+' class="calendarDateInput" id="'+DateName+'_Day_ID" önChange="'+DateName+'_Object.changeDay(this)">');for(var j=1;j<=eval(DateName+"_Object.picked.dayCount");j++){DaySelected=((DefaultDate!="")&&(eval(DateName+"_Object.picked.day")==j))?" selected":"";writeln("<option"+DaySelected+">"+j+"</option>")}writeln("</select>"+String.fromCharCode(13)+"');writeln("<input"+InitialStatus+' class="calendarDateInput" type="text" id="'+DateName+'_Year_ID" size="'+eval(DateName+"_Object.picked.yearPad.length")+'" maxlength="'+eval(DateName+"_Object.picked.yearPad.length")+'" title="Year" value="'+eval(DateName+"_Object.picked.yearPad")+'" onKeyPress="return YearDigitsOnly(window.event)" onKeyUp="'+DateName+'_Object.checkYear(this)" önBlur="'+DateName+'_Object.fixYear(this)">');write(''+String.fromCharCode(13)+" ');writeln('');writeln(''+String.fromCharCode(13)+'');writeln('');writeln('");writeln(''+String.fromCharCode(13)+"");for(var w=0;w<7;w++){writeln('")}writeln(""+String.fromCharCode(13)+"'+eval(DateName+"_Object.displayed.fullName")+"'+WeekDays[w]+""+String.fromCharCode(13)+''+eval(DateName+"_Object.buildCalendar()")+""+String.fromCharCode(13)+""+String.fromCharCode(13)+"")}}};
</script>

Date Calculator
Number of years, months, weeks, and days between two dates
ResultDate Difference:0 years 0 months 0 daysor 0 months 0 daysor 0 weeks 0 daysor 0 days
<form name="calcf">

</form>

Start Date

<script>DateInput('today', true, 'MM/DD/YYYY', '09/05/2014')</script>


End Date

<script>DateInput('ageat', true, 'MM/DD/YYYY', '09/05/2014')</script>


<input type="hidden" name="calctype" value="diff">

<label for="addendday"><input type="checkbox" name="addendday" id="addendday" value="1" >include end day (add 1 day)</label>
<input type="image" src="C:\Users\ganel123\Desktop\alok\calculate.png" value="Calculate" alt="Calculate">



Add to or subtract from a date


<form name="calcf2">

</form>

Start Date

<script>DateInput('today2', true)</script>


 




<select name="c2op" id="c2op" class="bigtext">
<option value="+" selected>+</option>
<option value="-" >-</option>
</select>




<input type="text" name="c2year" size="6" id="c2year" value="0" style="text-align: right;">
years


<input type="text" name="c2month" size="6" id="c2month" value="0" style="text-align: right;">
months


<input type="text" name="c2week" size="6" id="c2week" value="0" style="text-align: right;">
weeks


<input type="text" name="c2day" size="6" id="c2day" value="0" style="text-align: right;">
days



= ?





<input type="hidden" name="calctype" value="op">
<input type="image" src="C:\Users\ganel123\Desktop\alok\calculate.png" value="Calculate" alt="Calculate">
</body>
</html>
Posted
Comments
Sergey Alexandrovich Kryukov 16-Sep-14 1:02am    
Are you serious? Who will volunteer to dig into this unreadable code?
And do yourself a big favor: stop working without some revision control system. At least then you will stop loosing working solutions.
—SA
George Jonsson 16-Sep-14 1:21am    
I second that.
Impossible to read.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900