

var THOMASCOOK = function() { return {wizard: {}} } ();
THOMASCOOK.wizard.Calendar = new function() {

  this.Selected_Month;
  this.Selected_Year;
  
  this.HeuteTag;
	this.HeuteMonat;
	this.HeuteJahr;
	
	this.dt = new Date(2000, 1, 1); //new Date(); - start from today
  this.TagVon   = this.dt.getDate();
  this.MonatVon = this.dt.getMonth()+1;
  this.JahrVon  = this.dt.getFullYear();

  this.TagBis   = 21;
  this.MonatBis = 5;
  this.JahrBis  = 2050;
  
  this.Days_in_Month = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  
  this.dateValue;
  this.inputId;
  this.buttonId;
  
  this.calendarContainerId = "THOMASCOOKCalendarContainer";

  this.OpenCalendar = function(inputId, buttonId)
  {
    this.inputId = inputId;
    this.buttonId = buttonId;
    
    //close another calendar in case it's open
    if (document.getElementById(this.calendarContainerId))
    {
      document.getElementById(this.calendarContainerId).parentNode.style.zIndex = 0;
      document.getElementById(this.calendarContainerId).parentNode.removeChild(
        document.getElementById(this.calendarContainerId));
    }
    
    //create calendar container
    var buttonContainer = document.getElementById(buttonId).parentNode;    
    buttonContainer.style.zIndex = 100; //to make button container div top
    
    var containerDiv = document.createElement("div");
    containerDiv.id = this.calendarContainerId;
    containerDiv.style.position = "absolute";
    containerDiv.style.zIndex = 2;
    containerDiv.style.width = "145px";
    containerDiv.style.height = "162px";
    containerDiv.style.left = "0px";
    containerDiv.style.top = "0px";
    containerDiv.style.top = "0px";
    buttonContainer.appendChild(containerDiv);
       
    this.dateValue=document.getElementById(inputId).value;
    if (!this.dateValue || this.dateValue.length <= 0)
    {
      var now = new Date();
      var day = now.getDate() < 10 ? "0" + now.getDate() : now.getDate();
      var month = (now.getMonth()+1) < 10 ? "0" + (now.getMonth()+1) : (now.getMonth()+1);
      var year = now.getFullYear();
      this.dateValue = day + "." + month + "." + year;
    }

    try
    {
	    this.HeuteTag = this.dateValue.substring(0,2);
	    if (this.HeuteTag.substring(0,1) == "0"){
		    this.HeuteTag = this.HeuteTag.substring(1,2);
	    }
	    this.HeuteMonat = this.dateValue.substring(3,5);
	    this.HeuteJahr  = this.dateValue.substring(6,10);
    }
    catch(e)
    {
	    alert(e)
	    this.HeuteTag   = 1;
	    this.HeuteMonat = 1;
	    this.HeuteJahr  = 2008;
    }
    
    this.HeuteMonat = this.HeuteMonat-1;
    this.MonatVon = this.MonatVon-1;
    this.MonatBis = this.MonatBis-1;
    
    this.Defaults();
  }
  
  this.dfdate = function(d1,m1,y1,sign,d2,m2,y2){var d1 = new Date(y1,m1,d1);var d2 = new Date(y2,m2,d2);d1 = d1.valueOf();d2 = d2.valueOf();switch(sign){case "==":{return (d1==d2)};break;case ">":{return (d1>d2)};break;case "<":{return (d1 < d2)};break;}}

  this.InsertDate = function(dmy) 
  {
	  if(!this.dateValue)return dmy;

	  dmy = dmy.split(".");
	  this.dateValue = (dmy[0]<10?"0"+dmy[0]:dmy[0]) + "." + (dmy[1]<10?"0"+dmy[1]:dmy[1]) + "." + dmy[2];
  	
	  document.getElementById(this.inputId).value = this.dateValue;
	  document.getElementById(this.buttonId).parentNode.removeChild(
	    document.getElementById(this.calendarContainerId));
  }

  this.gmn = function(Year,Month,Day)
  {
  var monthNames = "JANFEBMARAPRMAIJUNJULAUGSEPOKTNOVDEZ";
  var today = new Date(Year,Month,Day);
  var month = monthNames.substring(today.getMonth() * 3, (today.getMonth() + 1) * 3);
  if(month == "MAR")
  {
    month = "M&Auml;R";
  }
  return month + " " + Year;
  }

  this.Make_Calendar = function(Year, Month) 
  {
	  var First_Date = new Date(Year, Month, 1);
	  var Heading = this.gmn(Year, Month, 1);
	  var First_Day_Name = First_Date.getDay();
	  if (First_Day_Name==0){First_Day_Name=7}
	  var Rows = 6;
  	
	  var leftb="<td style='cursor:hand;background-image:url(http://thomascook-3pwizard.pixell.de/img/datepicker/bg_kll.gif);'><img src='http://thomascook-3pwizard.pixell.de/img/datepicker/prev.gif' width=19 height=19 onClick=THOMASCOOK.wizard.Calendar.Skip('-')></td>";
  	
	  var rightb="<td style=cursor:hand; background='http://thomascook-3pwizard.pixell.de/img/datepicker/bg_klr.gif'><img src='http://thomascook-3pwizard.pixell.de/img/datepicker/next.gif' onClick=THOMASCOOK.wizard.Calendar.Skip('+')></td>";
	  var bgc="background='http://thomascook-3pwizard.pixell.de/img/datepicker/bg_c.gif'";
	  var tdbdate="<td height=19 style='cursor:default;font-size:11px;font-family : Arial, Helvetica, sans-serif;color:434A44;font-weight: bold;' background='http://thomascook-3pwizard.pixell.de/img/datepicker/baddate.gif'>";
  	
  	
	  var HTML_String = "<div style='display:none;'>IEhacktoreadfirstscriptcsstag</div>";
	  HTML_String += '<table border=0 cellspacing=0 cellpadding=2 style=\"background-color:black;\"><tr><td valign="top"><table border=0 cellspacing=1 cellpadding=0 FRAME=box style=\"cursor:default;background-color:white;\">';
	  HTML_String += "<tr>"+leftb+"<td width=99 "+bgc +" align=center colspan=5 style='font-size:10px;font-family : Arial, Helvetica, sans-serif;color:#ffffff;letter-spacing : 4px;'>"+Heading+"</td>"+rightb+"</tr>";
	  HTML_String += "<tr align=center><td width=19 style='font-size:11px;font-family : Arial, Helvetica, sans-serif;color:115F70;'>M</td><td width=19 style='font-size:11px;font-family : Arial, Helvetica, sans-serif;color:115F70;'>D</td><td width=19 style='font-size:11px;font-family : Arial, Helvetica, sans-serif;color:115F70;'>M</td>";
	  HTML_String += "<td width=19 style='font-size:11px;font-family : Arial, Helvetica, sans-serif;color:115F70;'>D</td><td width=19 style='font-size:11px;font-family : Arial, Helvetica, sans-serif;color:115F70;'>F</td><td width=19 style='font-size:11px;font-family : Arial, Helvetica, sans-serif;color:E80000;'>S</td><td width=19 style='font-size:11px;font-family : Arial, Helvetica, sans-serif;color:E80000;'>S</td></tr>";
	  HTML_String += "<tr><td colspan=7 bgcolor=000000><img src='http://thomascook-3pwizard.pixell.de//daily/1.gif' width=1 height=1></td></tr>";

	  var Day_Counter = 1;
	  var Loop_Counter = 1;
	  for (var j = 1; j <= Rows; j++) 
	  {
		  HTML_String += "<tr align=center>";
			  for (var i = 1; i < 8; i++) 
			  {
				  if ((Loop_Counter >= First_Day_Name) && (Day_Counter <= this.Days_in_Month[Month])) 
				  {
  					
					  if(this.dfdate(Day_Counter,Month,Year,"<",this.TagVon,this.MonatVon,this.JahrVon)) 
					  {
						  HTML_String += tdbdate + Day_Counter + "</td>";
					  }
					  else if (this.dfdate(Day_Counter,Month,Year,">",this.TagBis,this.MonatBis,this.JahrBis)) 
					  {
						  HTML_String += tdbdate + Day_Counter + "</td>";
					  }
  					
					  else
					  {
						  HTML_String += "<td "+ this.CheckIfHeute(Year+""+(Month*1+1)+""+Day_Counter) +" onclick=THOMASCOOK.wizard.Calendar.InsertDate('"+Day_Counter+"."+(Month+1)+"."+Year+"') height=19 style='cursor:hand;font-size:11px;font-family : Arial, Helvetica, sans-serif;color:434A44;font-weight: bold;'>" + Day_Counter + "</td>";
					  }
					  Day_Counter++; 
				  }
				  else 
				  {
					  HTML_String += "<td height=19 style='font-size:11px;font-family : Arial, Helvetica, sans-serif;color:434A44;font-weight: bold;'>&nbsp;</td>";
				  }
  		

			  Loop_Counter++;
  			
			  }
	  HTML_String += "</tr>";
	  }
  HTML_String += "</table></td></tr></table>";
  HTML_String += this.GetCloseButtonHtml();
  document.getElementById(this.calendarContainerId).innerHTML = 
    "<div style='position:relative;z-index:1;background-color:white;'>" + HTML_String + "</div>";
    
  //IE 'select overlay' hack
  var containerIframe = document.createElement("iframe");
  containerIframe.style.position = "absolute";
  containerIframe.style.zIndex = 0;
  containerIframe.style.width = "145px";
  containerIframe.style.height = "160px";
  containerIframe.style.left = "0px";
  containerIframe.style.top = "0px";
  containerIframe.frameBorder = 0;
  document.getElementById(this.calendarContainerId).appendChild(containerIframe);
  }

  this.Defaults = function() {
  this.Selected_Month = this.HeuteMonat;
  this.Selected_Year = this.HeuteJahr;
  this.Make_Calendar(this.HeuteJahr, this.HeuteMonat);
  }
  
  this.GetCloseButtonHtml = function(){
    var html;
    html = "<div style='position:absolute;bottom:1px;right:1px;'>" + 
      "<img src=" + 
      "'http://thomascook-3pwizard.pixell.de/img/datepicker/btn_close.gif'" + 
      "onclick='" + 
      "document.getElementById(THOMASCOOK.wizard.Calendar.buttonId).parentNode.style.zIndex=0;" +
      "document.getElementById(THOMASCOOK.wizard.Calendar.buttonId).parentNode.removeChild(document.getElementById(THOMASCOOK.wizard.Calendar.calendarContainerId));" + 
      "'" +
      " /></div>";
    return html;
  }

  this.Skip = function(Direction) 
  {
	  if (Direction == '+') 
	  {
		  if (this.Selected_Month == 11) 
		  {
			  this.Selected_Month = 0;
			  this.Selected_Year++;
		  }
		  else 
		  {
			  this.Selected_Month++;
		  }
	  }
	  else 
	  {
		  if (this.Selected_Month == 0) 
		  {
			  this.Selected_Month = 11;
			  this.Selected_Year--;
		  }
		  else 
		  {
			  this.Selected_Month--;
		  }
	  }
  this.Make_Calendar(this.Selected_Year, this.Selected_Month);
  }

  this.CheckIfHeute = function(sdatum)
  {
  var sm=new Date();
  simera=sm.getFullYear()+""+(sm.getMonth()+1)+sm.getDate();
  usersel = this.HeuteJahr +""+ (this.HeuteMonat*1+1) +""+ this.HeuteTag

  if((sdatum==usersel)&&(sdatum==simera)){return "background='http://thomascook-3pwizard.pixell.de/img/datepicker/ringsel.gif'";}
  if(sdatum==usersel){return "background='http://thomascook-3pwizard.pixell.de/img/datepicker/seldate.gif'";}
  if(sdatum==simera){return "background='http://thomascook-3pwizard.pixell.de/img/datepicker/ring.gif'";}
  }

}
document.write("<div style=\"position:relative;width:300px;height:250px;background-image:url(http://thomascook-3pwizard.pixell.de/data/bgimages/defaultbg300x250.jpg);background-repeat:no-repeat;background-position:bottom left;\">"
+"<form  action='http://www.thomascook.de/index.php' method='get' style='display:inline;' target='_blank' onsubmit='if (!document.getElementById(\"frmTrTWizard_64_ziel\") || document.getElementById(\"frmTrTWizard_64_ziel\").selectedIndex <= 0){document.getElementById(\"frmTrTWizard_64_detail\").value = \"zielgebiet\";} else {document.getElementById(\"frmTrTWizard_64_detail\").value = document.getElementById(\"frmTrTWizard_64_detailDefault\").value;if (document.getElementById(\"frmTrTWizard_64_detail\").value == \"hotel\"){document.getElementById(\"frmTrTWizard_64_ziel\").name = \"topRegion\";} else {document.getElementById(\"frmTrTWizard_64_ziel\").name = \"ziel\";}}var form = this;var queryString = \"\"; var amp = \"\"; var zielName = \"\"; var zielId = \"\"; var startDate = \"\"; var endDate = \"\"; for(i=0; i<form.elements.length; i++){     if (form.elements[i].name == \"\") continue;    if ((form.elements[i].type == \"radio\" || form.elements[i].type == \"checkbox\") &&        !form.elements[i].checked) continue;    queryString += amp+form.elements[i].name+\"=\"+encodeURIComponent(form.elements[i].value);     amp = \"&\";    if (form.elements[i].name == \"ziel\" && form.elements[i].selectedIndex > 0){       zielName=form.elements[i].options[form.elements[i].selectedIndex].text;       zielId=form.elements[i].options[form.elements[i].selectedIndex].value;    }    if (form.elements[i].name == \"von\" && form.elements[i].value != \"\"){       startDate=form.elements[i].value;    }    if (form.elements[i].name == \"bis\" && form.elements[i].value != \"\"){       endDate=form.elements[i].value;    }}var targetUrl = \"http://www.thomascook.de/index.php\";targetUrl += \"?\" + queryString;for(i=1; i<=1; i++){targetUrl=encodeURIComponent(targetUrl);}window.open(\"http://ad.zanox.com/ppc/?14682512C1297511280&ULP=http://asn.advolution.de/00001f795F0002694/\" + targetUrl, \"_blank\");return false;'>"
+"<input id='frmTrTWizard_64_detail' type='hidden' name='detail' value='zielgebiet' /><input id='frmTrTWizard_64_detailDefault' type='hidden' value='zielgebiet' />"
+""
+""
+"<input type=\"hidden\" name=\"KID\" value=\"620020\" /><input type=\"hidden\" name=\"engine\" value=\"lastminute\" /><input type=\"hidden\" name=\"formular\" value=\"4\" /><input type=\"hidden\" name=\"showresult\" value=\"1\" /><input type=\"hidden\" name=\"id\" value=\"18\" /><input type=\"hidden\" name=\"region\" value=\"-1\" /><input id=\"frmTrTWizard_64_topRegion\" type=\"hidden\" name=\"topRegion\" value=\"\" />"
+"<div style=\"position:absolute;width:250px;height:20px;left:10px;top:60px;          font-family:Verdana,Arial,Tahoma;          font-size:19px;          font-weight:normal;          color:#18B6C2;          line-height:27px;\">Lastminute in die Sonne</div>"
+"<div style=\"position:absolute;width:85px;height:20px;left:10px;top:100px;          font-family:Verdana,Arial,'Times New Roman',Tahoma;          font-size:13px;          font-weight:normal;          color:#5A5A5A;        \">Wohin?</div>"
+"<select style=\"position:absolute;width:150px;height:20px;left:105px;top:100px;border:solid 1px #7494B2;          font-family:Verdana,Arial,'Times New Roman',Tahoma;          font-size:11px;          color:#5A5A5A;        \" id='frmTrTWizard_64_ziel' name='ziel'><option value='' selected=\"selected\" >beliebig</option><option value='10010'>Aegypten</option><option value='10011'>Afrika</option><option value='10017'>Asien</option><option value='10018'>Australien</option><option value='10000'>Balearen</option><option value='10029'>Deutschland</option><option value='10013'>Dom. Republik</option><option value='10020'>Dubai, Arabische Halbinsel</option><option value='10035'>Fly & Drive</option><option value='10021'>Frankreich</option><option value='10032'>Gl&uuml;ckshotels</option><option value='10006'>Griechenland</option><option value='10005'>Griechische Inseln</option><option value='10036'>Indischer Ozean</option><option value='10007'>Italien, Malta</option><option value='10024'>Kanada</option><option value='10001'>Kanaren</option><option value='10014'>Karibik</option><option value='10034'>Kreuzfahrten</option><option value='10030'>Kroatien, Bulgarien, Osteuropa</option><option value='10012'>Kuba</option><option value='10000'>Mallorca, Ibiza, Menorca</option><option value='10016'>Mexiko</option><option value='10037'>Mittelamerika</option><option value='10028'>Mitteleuropa</option><option value='10026'>Naher Osten</option><option value='10022'>Nordeuropa</option><option value='10002'>Portugal</option><option value='10033'>Rundreisen</option><option value='10003'>Spanisches Festland</option><option value='10023'>S&uuml;damerika</option><option value='10025'>S&uuml;dsee</option><option value='10008'>Tunesien, Marokko</option><option value='10004'>T&uuml;rkei</option><option value='10015'>USA</option><option value='10019'>Zypern</option></select>"
+"<div style=\"position:absolute;width:85px;height:20px;left:10px;top:140px;          font-family:Verdana,Arial,'Times New Roman',Tahoma;          font-size:13px;          font-weight:normal;          color:#5A5A5A;        \">Wann?</div>"
+"<input style=\"position:absolute;width:132px;height:18px;left:105px;top:140px;border:solid 1px #7494B2;          font-family:Verdana,Arial,'Times New Roman',Tahoma;          font-size:11px;          color:#5A5A5A;          margin:0px;          padding:0px;        \" id='frmTrTWizard_64_termin' type='text' name='termin' value='' /><div style=\"position:absolute;width:18px;height:18px;left:241px;top:140px;background-image:url(http://thomascook-3pwizard.pixell.de/img/builder/input_date.gif);background-repeat:no-repeat;background-position:left center;\"><img id='frmTrTWizard_64_terminDatePickerButton' style=\"width:18px;height:18px;\" src='http://thomascook-3pwizard.pixell.de/img/x.gif' onclick=\"javascript:THOMASCOOK.wizard.Calendar.OpenCalendar('frmTrTWizard_64_termin', 'frmTrTWizard_64_terminDatePickerButton');return false;\" /></div>"
+"<div style=\"position:absolute;width:85px;height:20px;left:10px;top:180px;          font-family:Verdana,Arial,'Times New Roman',Tahoma;          font-size:13px;          font-weight:normal;          color:#5A5A5A;        \">Wie lange?</div>"
+"<select style=\"position:absolute;width:150px;height:20px;left:105px;top:180px;border:solid 1px #7494B2;          font-family:Verdana,Arial,'Times New Roman',Tahoma;          font-size:11px;          color:#5A5A5A;        \" id='frmTrTWizard_64_dauer' name='dauer'><option value='-1'>beliebig</option><option value='9'>1 - 4 Tage</option><option value='10'>5 - 8 Tage</option><option value='6_7'>1 Woche</option><option value='7'>9 - 12 Tage</option><option value='3'>13 - 15 Tage</option><option value='6_14'>2 Wochen</option><option value='12'>16 - 22 Tage</option><option value='6_21'>3 Wochen</option><option value='13'>&gt; 22 Tage</option></select>"
+"<input style=\"position:absolute;width:111px;height:23px;left:165px;top:215px;background-image:url(http://thomascook-3pwizard.pixell.de/data/bgimages/btn_submit.jpg);          font-family:Verdana,Arial,'Times New Roman',Tahoma;          font-size:12px;          font-weight:bold;          color:#5A5A5A;          border:0px;          background-color:transparent;          background-repeat:no-repeat;          background-position:left center;          text-align:right;          cursor:pointer;        \" value='' type='submit' />"
+"</form>"
+"</div>"
);