
									/* JavaScript sourcefile for cgPopCal */
									/************************************
									* cgPopCal ColdFusion Custom Tag    *
									* Version 3.0                       *
									* by C. Gross & Mindlend AG         *
									* www.mindlend.com                  *
									************************************/
									// create JS-class
									var cgPopCal=function() {
										/************************************************** properties **************************************************/
											this.initOk=false;
											this.monDayArr=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
											this.monArr = new Array('Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember');
											this.oTargetField=null;
											this.oOuterDiv=null;
											this.maxDate = new Date(2107,8,23,00,00,00,000);
											this.minDate = new Date(1753,1,1,00,00,00,000);
										
										/************************************************** functions **************************************************/
										// init
											this.init=function(){
												this.now = new Date();
												this.selY=this.now.getYear();
												this.selM=this.now.getMonth();
												this.selD=this.now.getDate();
												this.setDays(this.now);
												this.writeMonth();
												this.writeYear();
												this.fillDayGrid();
												this.initOk=true;
											}
										// open
											this.open=function(pFieldName_s,pEvent_o){
												var tmpPosArr=this.clacPosition(pEvent_o);
												this.oTargetField=window.document.getElementById(pFieldName_s);
												this.oOuterDiv=window.document.getElementById('cgPopCalOuter');
												this.selDat=this.checkDate(this.oTargetField.value,'') ? this.parseDate(this.oTargetField.value) : new Date();
												this.setDays(this.selDat);
												this.selY=this.newY;
												this.selM=this.newM;
												this.selD=this.newD;
												this.writeMonth();
												this.writeYear();
												this.fillDayGrid();
												this.setPosition(tmpPosArr[0],tmpPosArr[1]);
												this.show();
											}
										// writeBackDate
											this.writeBackDate=function(){
												this.newM=parseInt(this.newM)+1;
												this.oTargetField.value=this.convertDate(this.newY+'-'+this.newM+'-'+this.newD,'dd.mm.yyyy','Invalid date');
												this.close();
												this.oTargetField.fireEvent('onchange');
											}
										// close
											this.close=function(){
												this.hide();
											}
										// getLayerObject
											this.getLayerObject=function(){
												return document.getElementById('cgPopCalOuter');
											}
										// show
											this.show=function(){
												var dummy;
												try{this.replaceSelect('hide');}
												catch(dummy){/* do nothing */}
												this.getLayerObject().style.display='block';
											}
										// hide
											this.hide=function(){
												var dummy;
												try{this.replaceSelect('show');}
												catch(dummy){/* do nothing */}
												this.getLayerObject().style.display='none';
											}
										// replaceSelect
											this.replaceSelect=function(pMode_s){
												var i,o;
												if(document.all){
													for(i=0;i<document.all.length;i++){
														o = document.all(i);
														if(o.type && o.type.indexOf('select')>-1)
															if(o.style)
																pMode_s=='hide' ? o.style.display='none' : o.style.display='block';
													}
												}
											}
										// fillDayGrid
											this.fillDayGrid=function(){
												var i,oTd,day;
												for(i=0;i<=41;i++){
													oTd=document.getElementById('cgPopCalDayTd_'+i);
													if(i<this.firstDayInMonth-1 || i>this.daysInMonth+this.firstDayInMonth-2) oTd.innerHTML='&nbsp;';
													else{
														day=i-this.firstDayInMonth+2;
														oTd.innerHTML=day;
														oTd.className=day==this.selD && this.newM==this.selM && this.newY==this.selY ? 'cgPopCalDaySelTd' : 'cgPopCalDayGridTd';
													}
												}
											}
										// setTdHoverClass
											this.setTdHoverClass=function(pTdObj_o){if(isFinite(pTdObj_o.innerHTML)) pTdObj_o.className='cgPopCalDayHoverTd'}
										// setTdDefClass
											this.setTdDefClass=function(pTdObj_o){if(isFinite(pTdObj_o.innerHTML)) pTdObj_o.className=pTdObj_o.innerHTML==this.selD && this.newM==this.selM && this.newY==this.selY ? 'cgPopCalDaySelTd' : 'cgPopCalDayGridTd'}
										// writeMonth
											this.writeMonth=function(){document.getElementById('cgPopCalMonthBox').innerHTML=this.monArr[this.newM];}
										// writeYear
											this.writeYear=function(){document.getElementById('cgPopCalYearBox').innerHTML=this.newY;}
										// setDays
											this.setDays=function(){
												if(this.setDays.arguments.length==1){
													var refDat=new Date(2000,01,01,00,00,00,000);
													var dat=this.setDays.arguments[0];
													this.newY= dat.getYear()<100 || refDat.getYear()==100 ? dat.getYear()+1900 : dat.getYear();
													this.newM=dat.getMonth();
													this.newD=dat.getDate();
												}
												this.firstDate = new Date(this.newY,this.newM,01,00,00,00,000);
												this.daysInMonth=this.getDaysInMonth(this.firstDate);
												this.lastDate = new Date(this.newY,this.newM,this.daysInMonth,00,00,00,000);
												this.firstDayInMonth = this.firstDate.getDay()==0 ? 7 : this.firstDate.getDay();
												this.lastDayInMonth = this.lastDate.getDay()==0 ? 7 : this.lastDate.getDay();
											}
										// setNewDay
											this.setNewDay=function(pDay_i){
												if(isFinite(pDay_i)) {
													this.newD=parseInt(pDay_i);
													this.writeBackDate();
												}
											}
										// skipMonth
											this.skipMonth=function(pVal_i){
												if((this.newM >= 1 && this.newM <= 10 && pVal_i > 0) 
													 || (this.newM <= 11 && this.newM >= 2 && pVal_i < 0)){this.newM=this.newM+pVal_i;}
												else if(this.newM == 11 && pVal_i > 0){
													this.newM=0;
													this.newY+=1;
												}
												else if(this.newM == 0 && pVal_i < 0){
													this.newM=11;
													this.newY-=1;
												}
												else if(this.newM == 0 && pVal_i > 0){this.newM=1;}
												else if(this.newM == 1 && pVal_i < 0) {this.newM=0;}
												else return;
												this.setDays();
												this.writeMonth();
												this.writeYear();
												this.fillDayGrid();
											}
										// skipYear
											this.skipYear=function(pVal_i){
												this.newY=this.newY+pVal_i;
												this.writeYear();
												this.setDays();
												this.fillDayGrid();
											}
										// clacPosition
											this.clacPosition=function(pEvent_o){
												if(document.body.offsetHeight){
													this.windowHeight = isFinite(parseInt(document.body.offsetHeight)) ? parseInt(document.body.offsetHeight) : 0;
													this.windowWidth = isFinite(parseInt(document.body.offsetWidth)) ? parseInt(document.body.offsetWidth) : 0;
												}
												else{
														this.windowHeight = isFinite(parseInt(window.innerHeight)) ? parseInt(window.innerHeight) : 0;
														this.windowWidth = isFinite(parseInt(window.innerWidth)) ? parseInt(window.innerWidth) : 0;
												}
												if(pEvent_o.x){
														this.eventX = isFinite(parseInt(pEvent_o.x)) ? parseInt(pEvent_o.x) : 0;
														this.eventY = isFinite(parseInt(pEvent_o.y)) ? parseInt(pEvent_o.y) : 0;
												}
												else{
														this.eventX = isFinite(parseInt(pEvent_o.pageX)) ? parseInt(pEvent_o.pageX) : 0;
														this.eventY = isFinite(parseInt(pEvent_o.pageY)) ? parseInt(pEvent_o.pageY) : 0;
												}
												if(document.body.scrollLeft){
														this.scrollX = isFinite(parseInt(document.body.scrollLeft)) ? parseInt(document.body.scrollLeft) : 0;
														this.scrollY = isFinite(parseInt(document.body.scrollTop)) ? parseInt(document.body.scrollTop) : 0;
												}
												else{
														this.scrollX = isFinite(parseInt(window.pageXOffset)) ? parseInt(window.pageXOffset) : 0;
														this.scrollY = isFinite(parseInt(window.pageYOffset)) ? parseInt(window.pageYOffset) : 0;
												}
												this.topPos = this.eventY+this.scrollY;
												this.leftPos = this.eventX+this.scrollX-50;
												this.bottomPos = this.eventY+160;
												this.rightPos = this.eventX+200;
												if(this.bottomPos > this.windowHeight) this.topPos = this.topPos-this.bottomPos+this.windowHeight;
												if(this.rightPos > this.windowWidth) this.leftPos = this.leftPos-this.rightPos+this.windowWidth;
												if(this.topPos < 0) this.topPos=0;
												if(this.leftPos < 0) this.leftPos=0;
												this.calPosArr = new Array(this.leftPos,this.topPos);
												return this.calPosArr;
											}
										// setPosition
											this.setPosition=function(pLeft_i,pTop_i){
												this.oOuterDiv.style.left=pLeft_i;
												this.oOuterDiv.style.top=pTop_i;
											}
										
										/************************************************** Date functions **************************************************/
										// isLeapYear
											this.isLeapYear=function(pYear_i) {
												if(((pYear_i % 4) == 0) 
													 && (((pYear_i % 100) != 0) 
															 || (((pYear_i % 100) == 0)
																	 && ((pYear_i % 400) == 0)))) {
													return true;
												}
												return false;
											}
										// getDaysInMonth
											this.getDaysInMonth=function(pDate_s) {
												if(pDate_s.getMonth() == 1 && this.isLeapYear(pDate_s.getYear())) return 29;
												else return this.monDayArr[pDate_s.getMonth()];
											}
										// checkDate
											this.checkDate=function(pDate_s,pErrorMsg_s) {
												var dummy,tmpDat;
												if(pDate_s.length==0) return false;
												var invDat=false;
												try{
													tmpDat=this.parseDate(pDate_s);
													if(!tmpDat) invDat=true;
												}
												catch(dummy){invDat=true;}
												
												if(tmpDat > this.maxDate || tmpDat < this.minDate) invDat=true;
												
												if(invDat){
													if(pErrorMsg_s.length>0) alert(pErrorMsg_s);
													return false;
												}
												return true;
											}
										// parseDate
											this.parseDate=function(pDate_s){
												var i,deli,deliPos,rposY,posM,posD,dummy;
												try{
													datArr=pDate_s.match(/\d+/g);
													deliPos=pDate_s.search(/\D+/g);
													deli=pDate_s.substr(deliPos,1);
													posY = datArr[2].length > 2 ? 2 : 0;
													posM = deli=='/' && posY==2 && datArr[0]<=12 ? 0 : 1;
													if(posM==0) posD=1;
													else posD = posY==2 ? 0 : 2;
												}
												catch(dummy){return false;}
												return new Date(datArr[posY],datArr[posM]-1,datArr[posD],00,00,00,000);
											}
										// convertDate
											this.convertDate=function(pDate_d,pDateMask_s,pErrorMsg_s) {
												var i,pattArr,deli,argDat,tmpVar,refDat,dummy,retVal;
												refDat=new Date(2000,01,01,00,00,00,000);
												argDat=pDate_d;
												try{pDate_d.getDate()}
												catch(dummy){
													pDate_d=this.parseDate(pDate_d);
													if(!pDate_d) {
														if(pErrorMsg_s.length > 0) alert(pErrorMsg_s);
														return argDat;
													}
												}
												
												try{
													retVal='';
													pattArr=pDateMask_s.match(/[ymd]+/g);
													deli=pDateMask_s.substr(pDateMask_s.search(/[^ymd]+/g),1);
													for(i=0;i<pattArr.length;i++){
														switch(pattArr[i].substr(0,1)){
															case 'y':{
																tmpVar=refDat.getYear()==100 ? pDate_d.getYear()+1900 : pDate_d.getYear();
																if(pattArr[i].length==2) tmpVar=tmpVar.substr(2,2);
																retVal=retVal.length>0 ? retVal+deli+tmpVar : retVal+tmpVar;
																break;
															}
															case 'm':{
																tmpVar=pDate_d.getMonth()+1;
																if(pattArr[i].length==2 && parseInt(tmpVar)<10) tmpVar='0'+tmpVar;
																retVal=retVal.length>0 ? retVal+deli+tmpVar : retVal+tmpVar;
																break;
															}
															case 'd':{
																tmpVar=pDate_d.getDate();
																if(pattArr[i].length==2 && parseInt(tmpVar)<10) tmpVar='0'+tmpVar;
																retVal=retVal.length>0 ? retVal+deli+tmpVar : retVal+tmpVar;
																break;
															}
														}
													}
												}
												catch(dummy){alert('Could not convert date.');return argDat;}
												return retVal;
											}
										
									}				// end class definition
									
									cgPopCal=new cgPopCal();
	

