function F() {
var E=parseFloat(navigator.appVersion);
if(E>=2.0&&E<2.1&&navigator.appName.indexOf("Netscape")!=-1) 
 return false;
else return true;
}
function R(Q) {
var c=parseInt(Q,10);
return!(c%4)&&(!(c%400)||(c%100));
}
function P(b,c) {
if(b==2) 
 return R(c)?29:28;
if(b==4||b==6||b==9||b==11)
 return 30;
else return 31;
}
function D(c,C) {
 for(var d=0;d<C.length;d++)
  if(c==C.options[d].text)
    return d;
  return 0;
}
function m(b,u) {
 return((b+11+u)%12)+1;
}
function k(b,c,u) {
 return c+((b+11+u)-(b+11+u)%12)/12-1;
}
function CalCreate(b,c,h,p) {
 if(!F()) {
   alert("Feature not supported.");
   return;
 }
 var l;
 var B=new Date();
 if(parseInt(b.options.selectedIndex)==B.getMonth()&&parseInt(c.options[c.options.selectedIndex].text)==B.getYear()) {
 j=0;
 g=2;
 }
 else {
 j=-1;
 g=1;
 }
 f=g-j+1;
 if(navigator.appVersion.indexOf("Mac",0)!=-1) 
   l=window.open("","Calendar"+h,"width="+(78+f*200)+",height=255,resizable=yes,scrollbars=no");
 else 
   l=window.open("","Calendar"+h,"width="+(78+f*200)+",height=235,resizable=yes,scrollbars=no");
 l.focus();
 if(h=="A") 
   winA=l;
 else 
   winD=l;
 CalCalc(l,b.options.selectedIndex+1,c.options[c.options.selectedIndex].text,c.options[0].text,c.options[c.options.length-1].text,h,p);
 }
function CalCalc(y,O,N,t,s,h,p) {
 if(!F())
  return;
 var x=new Array("Januar","Februar","Mars","April","Mai","Juni","Juli","August","September","Oktober","November","Desember");
 var b=parseInt(O);
 var c=parseInt(N,10);
 while(k(b,c,j)<t)
   b++;
 while(k(b,c,g)>s)
   b--;
 var a="";
 var r=0;
 var e,d;
 y.document.open();
 a+="<html><head>";
 a+='<style type="text/css">';
 a+='td {font-family: Verdana, Arial, Geneva; font-size: 12px} ';
 a+='.submit {FONT-SIZE: 11px; FONT-FAMILY: Verdana, Arial, Geneva;}';
 a+='</style>';
 a+="<title>"+p+"</title></head><body bgcolor=ffffff link='#000000'>"+"<center></center>";
 a+="<table border=0 cellspacing=0 cellpadding=3 width="+200*f+">";
 a+="<tr valign=top>";
 for(e=j;e<=g;e++) {
  a+="<td colspan=7 align=center bgcolor=#3E91D5>"+"<b><font color=white>"+x[m(b,e)-1]+" "+k(b,c,e)+"</font></b></td>";
  a+="<td></td>";
 }
 a+="</tr>";
 var M=new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
 a+="<tr align=right>";
 for(e=j;e<=g;e++) { 
  for(d=1;d<=7;d++)
   a+="<td><font color='"+(((d+r)%7||6)==6?"#FF9900":"#295181")+"'><b>"+M[(d+r)%7]+"</b></font></td>";
  if(e<g) 
   a+="<td></td>";
  }
 a+="</tr>";
 var A=0,q,i,z;
 var o=0;var n,w;
 while(A<f&&o<10) { 
  a+="<tr>";
  for(e=j;e<=g;e++) { 
   i=m(b,e);
   q=k(b,c,e);
   z=new Date(i+"/01/"+q);
   n=(z.getDay()+13-r)%7;
   w=P(i,q)+n;
   for(d=o*7+1;d<(o+1)*7+1;d++) { 
    if(d<=n||d>w) 
     a+="<td>&nbsp;</td>";
    else { 
     if(d==w)
      A++;
     a+="<td "+(((d+r)%7||6)==6?"bgcolor='#EBECF0'":"")+" align=right>&nbsp;<a href='JavaScript:self.close();opener.C"+h+"("+(d-n)+","+i+","+q+")'>"+(d-n)+"</a></td>";
    }
   }
   if(e<g)
    a+="<td></td>";
  }
  o++;
  a+="</tr>";
 }
 if(o<6)
  a+="<tr><td>&nbsp;</td></tr>";
 var L=m(b,-1);
 var K=m(b,+1);
 var J=k(b,c,1);
 var I=k(b,c,-1);
 var H=k(b,c,g+1);
 var G=k(b,c,j-1);
 a+="<form action='javascript:return;'><tr><td align=left colspan="+((f==1)?3:7)+" bgcolor=#3E91D5>";
 if(G<t)
  a+="&nbsp;";
 else 
  a+="<input type='button' class='submit' value=' < "+((f==1)?"":x[m(b,j-1)-1]+" ")+"'"+"onClick='document.clear();opener.CalCalc(opener.win"+h+","+L+","+I+","+t+","+s+",\""+h+"\",\""+p+"\")'>";
 a+="</td>"+"<td align=center colspan="+((f==1)?8*f-7:8*f-15)+" bgcolor=#3E91D5>&nbsp;</td><td align=right colspan="+((f==1)?3:7)+" bgcolor=#3E91D5>";
 if(H>s)
  a+="&nbsp;";
 else 
  a+="<input type='button' class='submit' value='"+((f==1)?"":x[m(b,g+1)-1])+" > '"+"onClick='document.clear();opener.CalCalc(opener.win"+h+","+K+","+J+","+t+","+s+",\""+h+"\",\""+p+"\")'>";
 a+="</td></tr></form>";
 a+="</table></body></html>";
 y.document.write(a);y.document.close();
}

function CA(v,i,c) { 
 document.rf.day_a.options.selectedIndex=parseInt(v)-1;
 document.rf.month_a.options.selectedIndex=parseInt(i)-1;
 document.rf.year_a.options.selectedIndex=D(c,document.rf.year_a);
 calcDate(4);
}

function CD(v,i,c){ 
 document.rf.day_d.options.selectedIndex=parseInt(v)-1;
 document.rf.month_d.options.selectedIndex=parseInt(i)-1;
 document.rf.year_d.options.selectedIndex=D(c,document.rf.year_d);
 calcDate(14);
}

function openWindow(k,j,i){
	var f="width="+j+",height="+i+",";
	f+="resizable=yes,scrollbars=yes,status=yes,";
	f+="menubar=yes,toolbar=yes,location=no,directories=no";
	var h=window.open(k,'newWin',f);h.focus();
}
function moDa(e){
	if(typeof arrival=="undefined")calcDate();
	arrival.setDate(arrival.getDate()+e);
	depart.setDate(depart.getDate()+e);
	changeDate();calcDate();
}
function moNi(e){
	if(typeof arrival=="undefined")calcDate();
	document.rf.nights.value=parseInt(document.rf.nights.value)+e;
	calcDepart();
}

dow=new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");

function calcDate(g){
	var nights=document.rf.nights.value;
	arrival=new Date(document.rf.year_a.options[document.rf.year_a.selectedIndex].value,document.rf.month_a.selectedIndex,document.rf.day_a.selectedIndex+1);
	document.rf.month_a.selectedIndex=arrival.getMonth();document.rf.day_a.selectedIndex=arrival.getDate()-1;
	document.rf.dow_a.value=dow[arrival.getDay()];
	depart=new Date(document.rf.year_d.options[document.rf.year_d.selectedIndex].value,document.rf.month_d.selectedIndex,document.rf.day_d.selectedIndex+1);
	document.rf.month_d.selectedIndex=depart.getMonth();
	document.rf.day_d.selectedIndex=depart.getDate()-1;
	document.rf.dow_d.value=dow[depart.getDay()];
	document.rf.nights.value=Math.round((depart-arrival)/86400000);
	if(g>0&&nights>0){if(g<10)document.rf.nights.value=nights;else if(document.rf.nights.value<=0)document.rf.nights.value=1;calcDepart();}
}

function changeDate(){
	var b,a;
	var d,c;
	d=new Date(document.rf.year_a.options[0].text,0,1);
	c=new Date(document.rf.year_a.options[document.rf.year_a.length-1].text,11,31);
	if(arrival<d)arrival=d;else if(arrival>c)arrival=c;if(depart<d)depart=d;else if(depart>c)depart=c;
	if(depart<arrival)depart=arrival;document.rf.month_a.selectedIndex=arrival.getMonth();
	document.rf.day_a.selectedIndex=arrival.getDate()-1;
	b=arrival.getYear();
	if(b<1000)b=b+1900;
	for(a=0;a<document.rf.year_a.length;a++)if(b==document.rf.year_a.options[a].value)document.rf.year_a.options[a].selected=true;
	document.rf.month_d.selectedIndex=depart.getMonth();
	document.rf.day_d.selectedIndex=depart.getDate()-1;
	b=depart.getYear();
	if(b<1000)b=b+1900;
	for(a=0;a<document.rf.year_d.length;a++)if(b==document.rf.year_d.options[a].value)document.rf.year_d.options[a].selected=true;
}

function calcDepart(){
	arrival=new Date(document.rf.year_a.options[document.rf.year_a.selectedIndex].value,document.rf.month_a.selectedIndex,document.rf.day_a.selectedIndex+1);
	depart=new Date(document.rf.year_a.options[document.rf.year_a.selectedIndex].value,document.rf.month_a.selectedIndex,document.rf.day_a.selectedIndex+1);
	depart.setDate(depart.getDate()+parseInt(document.rf.nights.value));changeDate();calcDate(0);
}

 function createNights() {
   document.write('<tr><td  class="label_booknow">Ant. netter:</td>'+
'<td colspan="3" class="right_booknow">'+
'<input type="text" style="padding-left:4px; width:30px;" size="5" maxlength="5" class="input_booknow" name="nights" value=1 '+
'onChange="calcDepart()">&nbsp;<input type="button" class="submit" value="+1 Natt" onClick="moNi(1);this.blur()">'+
'<input type="button" class="submit" value="-1 Natt" onClick="moNi(-1);this.blur()">'+
'</td></tr>');
 }
 function validateForm() {
   if(document.rf.city.value=="NONE") {
     alert("Please select a city.");
     document.rf.city.focus();
     return false;
   }
 }
 function validateForm2() {
   if(document.rf.house.value=="NONE") {
     alert("Please select a hostel.");
     document.rf.house.focus();
     return false;
   }
 }

function openInfoWin(url) {
	window.open(url, "popup", "toolbar=0, scrollbars=1, location=0, statusbar=0, menubar=0, resizable=1, width=440, height=400");
}

 function makeFields(fld) {
  var idx, org;
  if(1==2) {
  if(parseInt(document.rf.male.value)>0)
    document.getElementById("agem").className = "label_booknow";
  else
    document.getElementById("agem").className = "hide";
  if(parseInt(document.rf.female.value)>0)
    document.getElementById("agef").className = "label_booknow";
  else
    document.getElementById("agef").className = "hide";
  for(idx=1;idx<10;idx++) {
    if(parseInt(document.rf.male.value)>=idx)
      document.getElementById("agem" + String(idx)).className = "input_booknow";
    else
      document.getElementById("agem"+ String(idx)).className = "hide";
    if(parseInt(document.rf.female.value)>=idx)
      document.getElementById("agef" + String(idx)).className = "input_booknow";
    else
      document.getElementById("agef"+ String(idx)).className = "hide";
  }
  }
  if(fld=="M") {
   org = parseInt(document.rf.female.value);
   document.rf.female.length = 0;
   for(idx=0;idx<=(9-parseInt(document.rf.male.value));idx++) {
     document.rf.female.options[idx] = new Option(String(idx),String(idx),false,false);
     if(org==idx)
       document.rf.female.options[idx].selected = true;
   }
  }
  if(fld=="F") {
   org = parseInt(document.rf.male.value);
   document.rf.male.length = 0;
   for(idx=0;idx<=(9-parseInt(document.rf.female.value));idx++) {
     document.rf.male.options[idx] = new Option(String(idx),String(idx),false,false);
     if(org==idx)
       document.rf.male.options[idx].selected = true;
   }
  }


  if(fld=="C"||fld=="X") {
   /*
   if(fld=="X") {
     var w_city;
     w_city = document.rf.city.selectedIndex;
   }
   */
 //  while (document.rf.city.length > 0) {
 //   document.rf.city.options[document.rf.city.length - 1] = null;
 //  }
   /*
   document.rf.city.length = 0;
   i = 0;
   for(idx=0;idx<citiesvalue.length;idx++) {
     if((citiesvalue[idx] >= document.rf.country.value+"|" && citiesvalue[idx] <= document.rf.country.value+"|z") || document.rf.country.value=="NONE") {
       document.rf.city.length = i+1;
       document.rf.city.options[i] = new Option(citiestext[idx],citiesvalue[idx],false,false);
       i++;
     }
   }
   if(fld=="X") document.rf.city.selectedIndex  = w_city; 
   */
 }
}

function lz(str) {
	if( str.toString().substring(1,2) == '') {
		return '0'+str;
	} else {
		return str;
	}
}