function findPosition( oLink , left , top) {
var which;
 which = oLink.id;
  if( oLink.offsetParent ) {
    for( var posX = 0, posY = 15; oLink.offsetParent; oLink = oLink.offsetParent ) {
      posX += oLink.offsetLeft;
	  posY += oLink.offsetTop;
  }
	left = left-=0; posX = posX -=0; iSleft = posX //+= posX;	 
	top = top-=0; 	posY = posY -=0; iStop = posY// += posY;	 
		document.getElementById('opodoCal').style.left = iSleft + "px";
		document.getElementById('opodoCal').style.top = iStop +"px";
		document.getElementById('opodoCal2').style.left = iSleft + "px";
		document.getElementById('opodoCal2').style.top = iStop +"px";

	 }
}
function findPositionAcourding( oLink , left , top) {
var which;
 which = oLink.id;
  if( oLink.offsetParent ) {
    for( var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
      posX += oLink.offsetLeft;
	  posY += oLink.offsetTop;
  }
	left = left-=0; posX = posX -=0; iSleft = left += posX;	 
	top = top-=0; 	posY = posY -=0; iStop = top += posY;	 
		document.getElementById('opodoCal').style.left = iSleft + "px";
		document.getElementById('opodoCal').style.top = iStop +"px";
		document.getElementById('opodoCal2').style.left = iSleft + "px";
		document.getElementById('opodoCal2').style.top = iStop +"px";

	 }
}
var now = new Date(),ymdd,ddd,dow,top,left,cl,calDate;
var mDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
function Calendar(ym,d,ddow,top,left,pod){
	var calStr = '<table width="175" border="0" cellspacing="0" cellpadding="0" class="bdr1 bdrBurgundy whiteBG"><tr>';
	if(isNaN(ym)){
		ymdd = document.getElementById(ym);
		ddd = document.getElementById(d);
		if(document.getElementById(ddow)){dow = document.getElementById(ddow);}
		ym = document.getElementById(ym).options[document.getElementById(ym).selectedIndex].value;
		d = document.getElementById(d).value;
	}
	calDate = new Date();
	calDate.setDate(1);
	calDate.setYear(ym.substring(0,4));
	calDate.setMonth(parseInt(ym.substring(4,6)-1));
	var fontStr='style="font-family: verdana,arial,sans-serif; font-size: 11px; line-height: 150%;"';
	leapYear(calDate.getFullYear())
	calStr +="<tr>";
	//alert(calDate.getMonth());
	var borderL='style="border:0px;background:#FFF;"';
	if(calDate.getMonth()==0){
	calStr += (calDate>firstDate)?'<td class="center" colspan="2" width="45"><a href="javascript:Calendar(\''+(calDate.getFullYear()-1)+''+12+'\','+calDate.getDate()+',\''+dow.id+'\','+top+','+left+',\''+pod+'\')"><img src="'+imgpath+'arrow_onwhiteleft.gif" alt='+prevMonth+' width="11" height="11" border="0"></td>':'<td colspan="2" class="e" width="45">&nbsp;</td>';
	}else{
	calStr += (calDate>firstDate)?'<td class="center" colspan="2" width="45"><a href="javascript:Calendar(\''+calDate.getFullYear()+''+(((calDate.getMonth())<10)?0+''+(calDate.getMonth()):(calDate.getMonth()))+'\','+calDate.getDate()+',\''+dow.id+'\','+top+','+left+',\''+pod+'\')"><img src="'+imgpath+'arrow_onwhiteleft.gif" alt='+prevMonth+' width="11" height="11" border="0"></td>':'<td colspan="2" class="e" width="45">&nbsp;</td>';
	}
	if(now.getMonth()!=0){now.setMonth(now.getMonth()-1);}else{now.setMonth(11);now.setFullYear(now.getFullYear()-1);}
	calStr +='<td valign="top" colspan="3" class="emp text center b">'+mNames[calDate.getMonth()]+'<br>'+calDate.getFullYear()+'</td>'
	if(calDate.getMonth()!=11){calDate.setMonth(calDate.getMonth()+1);}else{calDate.setMonth(0);calDate.setFullYear(calDate.getFullYear()+1);}
	calStr += (calDate<lastDate)?'<td colspan="2" class="center"><a href="javascript:Calendar(\''+calDate.getFullYear()+''+(((calDate.getMonth()+1)<10)?0+''+(calDate.getMonth()+1):(calDate.getMonth()+1))+'\','+calDate.getDate()+',\''+dow.id+'\','+top+','+left+',\''+pod+'\')"><img src="'+imgpath+'arrow_onwhite.gif" alt='+nextMonth+' width="11" height="11" border="0"></a></td></tr><tr>':'<td colspan="2" class="whiteBG e" width="45">&nbsp;</td></tr><tr>';
	if(calDate.getMonth()!=0){calDate.setMonth(calDate.getMonth()-1);}else{calDate.setMonth(11);calDate.setFullYear(calDate.getFullYear()-1);}
	for(var x=0;x<daysLong.length-1;x++){
		calStr += (x==0)?'<td  '+fontStr+borderL+' class="center whiteBG">'+daysLong[x+1].substr(0,1)+'</td>':'<td '+fontStr+' class="center whiteBG">'+daysLong[x+1].substr(0,1)+'</td>'
	}
	calStr+='</tr>';
	var cnt = 0,clDate = (calDate.getDay()==0)?6:calDate.getDay()-1;
	for(var x=0;x<clDate;x++){
		calStr +=(cnt==0)?'<tr><td '+fontStr+borderL+' class="fsmall e" width="24">&nbsp;</td>':'<td '+fontStr+' class="fsmall e">&nbsp;</td>';
		cnt++;
	}
	for(var x=0;x<mDays[calDate.getMonth()];x++){if(cnt > 4){
			calStr+=(cnt==0)?'<tr><td '+fontStr+' line-height: 150%;" width="24" '+borderL+' class="center">':'<td '+fontStr+' width="24" class="mmushroomBG center">';
		}else{calStr+=(cnt==0)?'<tr><td '+fontStr+' width="24" '+borderL+' class="center">':'<td '+fontStr+' width="24" class="center">';}
		calDate.setDate(x+1);
		if(calDate>=firstDate && calDate.getTime()< lastDate.getTime()+getDayAsMilli(1)){
			calStr +='<a style="color:#900" href="javascript:setDay('+calDate.getFullYear()+''+(((calDate.getMonth()+1)<10)?0+''+(calDate.getMonth()+1):(calDate.getMonth()+1))+',\''+(((x+1)<10)?0+''+(x+1):(x+1))+'\')">'+(x+1)+'</a></td>';
		}else{
			calStr +="<span style='text-decoration: line-through;'>"+(x+1)+"</span></td>"
		}
		cnt++;
		if(cnt == 7){calStr +='</tr>';cnt=0;}
	}
	if(cnt<7 && cnt!=0){calStr+='<td class="e" valign="top" colspan="'+(7-cnt)+'">&nbsp;</td></tr>'}
	calStr +='<tr>';
	calStr+='<td '+fontStr+' colspan="7" valign="bottom" align="right" class="b2 r5"><a href="#" onclick="closeit(); return false;" style="color:#900">'+calClose+'</a></td>';
	calStr+='</tr></table>';
	cl = document.getElementById("opodoCal");
	c2 = document.getElementById("opodoCal2");
if(top == null && left == null){
		findPosition(document.getElementById(ddow),left,top);
}else if(pod == 'true'){
		findPositionAcourding(document.getElementById(ddow),left,top,pod);
}else{
	cl.style.top=''+top+"px";
	cl.style.left=left+"px";
	c2.style.top=''+top+"px";
	c2.style.left=left+"px";
}
	cl.style.display='';
	cl.innerHTML=calStr;
var calStr2 = '<iframe width="175" height="'+cl.offsetHeight+'" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" border="0" src=""></iframe>';
	c2.style.display='';
	c2.innerHTML=calStr2;
}
function setTch(){
	touched=true;
	}
function swapDate(item,doIt){
 if(doIt){
	item.innerHTML=item.title;
}
else{if(String(document.location.href).indexOf(".de")!=-1){item.innerHTML=item.innerHTML.substr(0,2)}else{item.innerHTML=item.innerHTML.substr(0,3)}}
}
var touched = false;
function calcDay(tch){
var inDateVal = document.getElementById(ind).options[document.getElementById(ind).selectedIndex].value;
	var inMonthVal = document.getElementById(inmy).options[document.getElementById(inmy).selectedIndex].value;
	var outDateVal = document.getElementById(outd).options[document.getElementById(outd).selectedIndex].value;
	var outMonthVal = document.getElementById(outmy).options[document.getElementById(outmy).selectedIndex].value;
	if(!isNaN(tch)){touched = true;}
	var lDay = new Date();
	var rDay = new Date();
	lDay.setDate(1);
	lDay.setMonth(parseInt(inMonthVal.substring(4,6)-1));
	lDay.setFullYear(inMonthVal.substring(0,4));
	leapYear(lDay.getFullYear());
	(mDays[lDay.getMonth()]<=inDateVal)?lDay.setDate(mDays[lDay.getMonth()]):lDay.setDate(inDateVal);
	rDay.setDate(1);
	rDay.setMonth(parseInt(outMonthVal.substring(4,6)-1));
	rDay.setFullYear(outMonthVal.substring(0,4));
	leapYear(rDay.getFullYear());
	(mDays[rDay.getMonth()]<=outDateVal)?rDay.setDate(mDays[rDay.getMonth()]):rDay.setDate(outDateVal);
	var minRDay = new Date(serverTime.getTime()+parseInt(getDayAsMilli(offSet)));
	if(touched == false && minRDay.getTime()>rDay.getTime()){
		rDay.setDate(minRDay.getDate());
		rDay.setFullYear(minRDay.getFullYear());
		rDay.setMonth(minRDay.getMonth());
	}
		if(serverTime.getTime()>rDay.getTime()){
			if(serverTime.getDate()<rDay.getDate()){
				rDay.setTime(serverTime.getTime()+parseInt(getDayAsMilli(first)));
			}else{
				if(serverTime.getMonth()!=11){
					rDay.setMonth(serverTime.getMonth()+1)
				}else{
					rDay.setMonth(0);rDay.setFullYear(rDay.getFullYear()+1)
				}
		}
	}
	if(serverTime.getTime()>lDay.getTime()){
		if(serverTime.getDate()<lDay.getDate()){
			lDay.setTime(serverTime.getTime()+parseInt(getDayAsMilli(first)));
		}else{
			if(serverTime.getMonth()!=11){
				lDay.setMonth(serverTime.getMonth()+1)
			}else{
				lDay.setMonth(0);lDay.setFullYear(lDay.getFullYear()+1)
			}
		}
	}
	if(touched == false && lDay.getTime()>=rDay.getTime()){
		rDay.setTime(lDay.getTime()+parseInt(getDayAsMilli(offSet)));
	}
	if(rDay.getTime()>parseInt(serverTime.getTime()+parseInt(getDayAsMilli(last)))){
		rDay.setTime(serverTime.getTime()+parseInt(getDayAsMilli(last)));
	}
	if(lDay.getTime()>parseInt(serverTime.getTime()+parseInt(getDayAsMilli(last)))){
		lDay.setTime(serverTime.getTime()+parseInt(getDayAsMilli(last-1)));
	}

	setDDValue(document.getElementById(inmy),String(lDay.getFullYear()+''+(((lDay.getMonth()+1)<10)?0+''+(lDay.getMonth()+1):(lDay.getMonth()+1))));
	setDDValue(document.getElementById(ind),lDay.getDate());
	setDDValue(document.getElementById(outmy),String(rDay.getFullYear()+''+(((rDay.getMonth()+1)<10)?0+''+(rDay.getMonth()+1):(rDay.getMonth()+1))));
	setDDValue(document.getElementById(outd),rDay.getDate());
	setDates(ind,inmy,idow);
	setDates(outd,outmy,odow);
}
function setDDValue(oDropDown, sValue){
 for(var i=0; i<oDropDown.options.length; ++i){
  if(oDropDown.options[i].value == sValue){oDropDown.selectedIndex = i;break;}
 }
}
function closeit(){cl.style.display='none';c2.style.display='none';}
function leapYear(cyear){
	var isLeapYear = (((cyear % 4 == 0) && (cyear % 100 != 0)) || (cyear % 400 == 0));
	mDays[1] = (isLeapYear)?29:28;
}
