/*Optimized script for faster performance, Peter at Opodo */
var now=new Date(),ymdd,ddd,dow,tp,lt,left,top,cl,calDate;var mDays=new Array(31,28,31,30,31,30,31,31,30,31,30,31);function findPosY(obj){var curtop=0;if(obj.offsetParent)
while(1){curtop+=obj.offsetTop;if(!obj.offsetParent)
break;obj=obj.offsetParent;}
else if(obj.y)
curtop+=obj.y;tp=curtop;return curtop;}
function findPosX(obj){var curleft=0;if(obj.offsetParent)
while(1){curleft+=obj.offsetLeft;if(!obj.offsetParent)
break;obj=obj.offsetParent;}
else if(obj.x)
curleft+=obj.x;lt=curleft;return curleft;}
function Calendar(ym,d,ddow,left,top,pod,where){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;}
for(xxx=0;xxx<2;xxx++){calDate=new Date();calDate.setDate(1);calDate.setYear(ym.substring(0,4));calStr+='<td valign="top"><table width="175" border="0" cellspacing="0" cellpadding="0" class="bdrBurgundy whiteBG"><tr>';calDate.setMonth(parseInt(ym.substring(4,6)-1)+xxx);var fontStr='style="font-family: verdana,arial,sans-serif; font-size: 11px; line-height: 150%;"';leapYear(calDate.getFullYear())
var borderL='style="border:0px;background:#FFF;"';if(xxx==0){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+'\','+tp+','+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+'\','+tp+','+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+'\','+tp+','+left+',\''+pod+'\')"></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);}}else if(xxx==1){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+'\','+tp+','+left+',\''+pod+'\')"></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+'\','+tp+','+left+',\''+pod+'\')"></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()):(calDate.getMonth()))+'\','+calDate.getDate()+',\''+dow.id+'\','+tp+','+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></table>'
if(xxx==0){calStr+='</td><td class="e" style="width:1px; border-left: 1px solid #990033;">&nbsp;</td>';}}
calStr+='</tr><tr></td><td style="height:1px; border-top: 1px solid #990033;" class="e" colspan="4">&nbsp;</td></tr><tr>';calStr+='<td '+fontStr+' colspan="14" valign="bottom" align="right" class="b2 r5"><a href="#" onclick="closeit(); return false;" style="color:#900">'+calClose+'</a></td>';calStr+='</tr></table></td></tr></table>';cl=document.getElementById("opodoCal");c2=document.getElementById("opodoCal2");if(where){setTop=findPosY(where)+top;setLeft=/*findPosX(where)*/0+left;cl.style.top=setTop+"px";cl.style.left=setLeft+"px";c2.style.top=setTop+"px";c2.style.left=setLeft+"px";}
cl.style.display='';cl.innerHTML=calStr;var calStr2='<iframe width="351" 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 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;}

//jalva@CHG-207ˇRetain original search dates when using back buttonˇ
function calcDay(tch){
	var nom = navigator.appName;
	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;

	var inMonthVal;
	var outMonthVal;
	var ie6 = parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6;
	var ie7 = parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==7;
	//if (ie6 ){
	//		outMonthVal=document.getElementById(outmy).options[document.getElementById(outmy).selectedIndex+1].value;
	//		inMonthVal=document.getElementById(inmy).options[document.getElementById(inmy).selectedIndex+1].value;
	//		bb=false; 
	//}else{
			outMonthVal=document.getElementById(outmy).options[document.getElementById(outmy).selectedIndex].value;
			inMonthVal=document.getElementById(inmy).options[document.getElementById(inmy).selectedIndex].value;
	//}	
	
	if(!isNaN(tch)){
		touched=true;
	}
	var lDay=new Date();
	var rDay=new Date();
	lDay.setDate(1);
	//alert(inMonthVal);
	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(typeof initoffSet!="undefined")
		var minInitRDay=new Date(serverTime.getTime()+parseInt(getDayAsMilli(initoffSet)));
	else 
		var minInitRDay=minRDay;
	if(touched==false&&minRDay.getTime()>rDay.getTime()){
		rDay.setDate(minInitRDay.getDate());
		rDay.setFullYear(minInitRDay.getFullYear());
		rDay.setMonth(minInitRDay.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());
	if(ind!=outd){
		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);
	if(ind!=outd){
		setDates(outd,outmy,odow);
	}
}
